OLD | NEW |
1 #!/bin/bash -e | 1 #!/bin/bash -e |
2 | 2 |
3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # This script installs Debian-derived distributions in a chroot environment. | 7 # This script installs Debian-derived distributions in a chroot environment. |
8 # It can for example be used to have an accurate 32bit build and test | 8 # It can for example be used to have an accurate 32bit build and test |
9 # environment when otherwise working on a 64bit machine. | 9 # environment when otherwise working on a 64bit machine. |
10 # N. B. it is unlikely that this script will ever work on anything other than a | 10 # N. B. it is unlikely that this script will ever work on anything other than a |
11 # Debian-derived system. | 11 # Debian-derived system. |
12 | 12 |
13 usage() { | 13 usage() { |
14 echo "usage: ${0##*/} [-m mirror]" | 14 echo "usage: ${0##*/} [-m mirror] [-g group,...]" |
15 echo "-m mirror an alternate repository mirror for package downloads" | 15 echo "-g group,... groups that can use the chroot unauthenticated" |
16 echo "-h this help message" | 16 echo " Default: 'admin' and current user's group ('$(id -gn)')" |
| 17 echo "-m mirror an alternate repository mirror for package downloads" |
| 18 echo "-h this help message" |
17 } | 19 } |
18 | 20 |
19 process_opts() { | 21 process_opts() { |
20 local OPTNAME OPTIND OPTERR OPTARG | 22 local OPTNAME OPTIND OPTERR OPTARG |
21 while getopts ":m:h" OPTNAME; do | 23 while getopts ":g:m:h" OPTNAME; do |
22 case "$OPTNAME" in | 24 case "$OPTNAME" in |
| 25 g) |
| 26 [ -n "${OPTARG}" ] && |
| 27 chroot_groups="${chroot_groups}${chroot_groups:+,}${OPTARG}" |
| 28 ;; |
23 m) | 29 m) |
24 if [ -n "${mirror}" ]; then | 30 if [ -n "${mirror}" ]; then |
25 echo "You can only specify exactly one mirror location" | 31 echo "You can only specify exactly one mirror location" |
26 usage | 32 usage |
27 exit 1 | 33 exit 1 |
28 fi | 34 fi |
29 mirror="$OPTARG" | 35 mirror="$OPTARG" |
30 ;; | 36 ;; |
31 h) | 37 h) |
32 usage | 38 usage |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 grep ubuntu.com /usr/share/debootstrap/scripts/"${distname}" >&/dev/null && | 166 grep ubuntu.com /usr/share/debootstrap/scripts/"${distname}" >&/dev/null && |
161 mirror="http://archive.ubuntu.com/ubuntu" || | 167 mirror="http://archive.ubuntu.com/ubuntu" || |
162 mirror="http://ftp.us.debian.org/debian" | 168 mirror="http://ftp.us.debian.org/debian" |
163 fi | 169 fi |
164 sudo debootstrap ${archflag} "${distname}" /var/lib/chroot/"${target}" \ | 170 sudo debootstrap ${archflag} "${distname}" /var/lib/chroot/"${target}" \ |
165 "$mirror" | 171 "$mirror" |
166 | 172 |
167 # Add new entry to /etc/schroot/schroot.conf | 173 # Add new entry to /etc/schroot/schroot.conf |
168 grep ubuntu.com /usr/share/debootstrap/scripts/"${distname}" >&/dev/null && | 174 grep ubuntu.com /usr/share/debootstrap/scripts/"${distname}" >&/dev/null && |
169 brand="Ubuntu" || brand="Debian" | 175 brand="Ubuntu" || brand="Debian" |
| 176 if [ -z "${chroot_groups}" ]; then |
| 177 chroot_groups="admin,$(id -gn)" |
| 178 fi |
170 sudo sh -c 'cat >>/etc/schroot/schroot.conf' <<EOF | 179 sudo sh -c 'cat >>/etc/schroot/schroot.conf' <<EOF |
171 [${target%bit}] | 180 [${target%bit}] |
172 description=${brand} ${distname} ${arch} | 181 description=${brand} ${distname} ${arch} |
173 type=directory | 182 type=directory |
174 directory=/var/lib/chroot/${target} | 183 directory=/var/lib/chroot/${target} |
175 priority=3 | 184 priority=3 |
176 users=root | 185 users=root |
177 groups=admin | 186 groups=${chroot_groups} |
178 root-groups=admin | 187 root-groups=${chroot_groups} |
179 personality=linux$([ "${arch}" != 64bit ] && echo 32) | 188 personality=linux$([ "${arch}" != 64bit ] && echo 32) |
180 script-config=script-${target} | 189 script-config=script-${target} |
181 | 190 |
182 EOF | 191 EOF |
183 | 192 |
184 # Set up a special directory that changes contents depending on the target | 193 # Set up a special directory that changes contents depending on the target |
185 # that is executing. | 194 # that is executing. |
186 sed '/^FSTAB=/s,/mount-defaults",/mount-'"${target}"'",' \ | 195 sed '/^FSTAB=/s,/mount-defaults",/mount-'"${target}"'",' \ |
187 /etc/schroot/script-defaults | | 196 /etc/schroot/script-defaults | |
188 sudo sh -c 'cat >/etc/schroot/script-'"${target}" | 197 sudo sh -c 'cat >/etc/schroot/script-'"${target}" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 300 |
292 Successfully installed ${distname} ${arch} | 301 Successfully installed ${distname} ${arch} |
293 | 302 |
294 You can run programs inside of the chroot by invoking the "${target%bit}" | 303 You can run programs inside of the chroot by invoking the "${target%bit}" |
295 command. | 304 command. |
296 | 305 |
297 Your home directory is shared between the host and the chroot. But I configured | 306 Your home directory is shared between the host and the chroot. But I configured |
298 $HOME/chroot to be private to the chroot environment. You can use it | 307 $HOME/chroot to be private to the chroot environment. You can use it |
299 for files that need to differ between environments. | 308 for files that need to differ between environments. |
300 EOF | 309 EOF |
OLD | NEW |