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] [-g group,...]" | 14 echo "usage: ${0##*/} [-m mirror] [-g group,...] [-s] [-c]" |
15 echo "-g group,... groups that can use the chroot unauthenticated" | 15 echo "-g group,... groups that can use the chroot unauthenticated" |
16 echo " Default: 'admin' and current user's group ('$(id -gn)')" | 16 echo " Default: 'admin' and current user's group ('$(id -gn)')" |
17 echo "-m mirror an alternate repository mirror for package downloads" | 17 echo "-m mirror an alternate repository mirror for package downloads" |
| 18 echo "-s configure default deb-srcs" |
| 19 echo "-c always copy 64bit helper binaries to 32bit chroot" |
18 echo "-h this help message" | 20 echo "-h this help message" |
19 } | 21 } |
20 | 22 |
21 process_opts() { | 23 process_opts() { |
22 local OPTNAME OPTIND OPTERR OPTARG | 24 local OPTNAME OPTIND OPTERR OPTARG |
23 while getopts ":g:m:h" OPTNAME; do | 25 while getopts ":g:m:sch" OPTNAME; do |
24 case "$OPTNAME" in | 26 case "$OPTNAME" in |
25 g) | 27 g) |
26 [ -n "${OPTARG}" ] && | 28 [ -n "${OPTARG}" ] && |
27 chroot_groups="${chroot_groups}${chroot_groups:+,}${OPTARG}" | 29 chroot_groups="${chroot_groups}${chroot_groups:+,}${OPTARG}" |
28 ;; | 30 ;; |
29 m) | 31 m) |
30 if [ -n "${mirror}" ]; then | 32 if [ -n "${mirror}" ]; then |
31 echo "You can only specify exactly one mirror location" | 33 echo "You can only specify exactly one mirror location" |
32 usage | 34 usage |
33 exit 1 | 35 exit 1 |
34 fi | 36 fi |
35 mirror="$OPTARG" | 37 mirror="$OPTARG" |
36 ;; | 38 ;; |
| 39 s) |
| 40 add_srcs="y" |
| 41 ;; |
| 42 c) |
| 43 copy_64="y" |
| 44 ;; |
37 h) | 45 h) |
38 usage | 46 usage |
39 exit 0 | 47 exit 0 |
40 ;; | 48 ;; |
41 \:) | 49 \:) |
42 echo "'-$OPTARG' needs an argument." | 50 echo "'-$OPTARG' needs an argument." |
43 usage | 51 usage |
44 exit 1 | 52 exit 1 |
45 ;; | 53 ;; |
46 *) | 54 *) |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 else | 216 else |
209 p="\$1"; shift | 217 p="\$1"; shift |
210 exec schroot -c ${target%bit} -p "\$p" -- "\$@" | 218 exec schroot -c ${target%bit} -p "\$p" -- "\$@" |
211 fi | 219 fi |
212 exit 1 | 220 exit 1 |
213 EOF | 221 EOF |
214 sudo chown root:root /usr/local/bin/"${target%bit}" | 222 sudo chown root:root /usr/local/bin/"${target%bit}" |
215 sudo chmod 755 /usr/local/bin/"${target%bit}" | 223 sudo chmod 755 /usr/local/bin/"${target%bit}" |
216 | 224 |
217 # Add the standard Ubuntu update repositories if requested. | 225 # Add the standard Ubuntu update repositories if requested. |
218 [ "${alt_repos}" = "y" -a -r "/var/lib/chroot/${target}/etc/apt/sources.list" ]
&& | 226 [ "${alt_repos}" = "y" -a \ |
| 227 -r "/var/lib/chroot/${target}/etc/apt/sources.list" ] && |
219 sudo sed -i '/^deb .* [^ -]\+ main$/p | 228 sudo sed -i '/^deb .* [^ -]\+ main$/p |
220 s/^\(deb .* [^ -]\+\) main/\1-security main/ | 229 s/^\(deb .* [^ -]\+\) main/\1-security main/ |
221 p | 230 p |
222 t1 | 231 t1 |
223 d | 232 d |
224 :1;s/-security main/-updates main/ | 233 :1;s/-security main/-updates main/ |
225 t | 234 t |
226 d' "/var/lib/chroot/${target}/etc/apt/sources.list" | 235 d' "/var/lib/chroot/${target}/etc/apt/sources.list" |
227 | 236 |
228 # Add a few more repositories to the chroot | 237 # Add a few more repositories to the chroot |
229 [ -r "/var/lib/chroot/${target}/etc/apt/sources.list" ] && | 238 [ "${add_srcs}" = "y" -a \ |
| 239 -r "/var/lib/chroot/${target}/etc/apt/sources.list" ] && |
230 sudo sed -i 's/ main$/ main restricted universe multiverse/ | 240 sudo sed -i 's/ main$/ main restricted universe multiverse/ |
231 p | 241 p |
232 t1 | 242 t1 |
233 d | 243 d |
234 :1;s/^deb/deb-src/ | 244 :1;s/^deb/deb-src/ |
235 t | 245 t |
236 d' "/var/lib/chroot/${target}/etc/apt/sources.list" | 246 d' "/var/lib/chroot/${target}/etc/apt/sources.list" |
237 | 247 |
238 # Update packages | 248 # Update packages |
239 sudo schroot -c "${target%bit}" -p -- /bin/sh -c ' | 249 sudo schroot -c "${target%bit}" -p -- /bin/sh -c ' |
(...skipping 16 matching lines...) Expand all Loading... |
256 sudo schroot -c "${target%bit}" -p -- /bin/sh -c ' | 266 sudo schroot -c "${target%bit}" -p -- /bin/sh -c ' |
257 egrep '"'^$(id -nu) '"' /etc/sudoers >/dev/null 2>&1 || | 267 egrep '"'^$(id -nu) '"' /etc/sudoers >/dev/null 2>&1 || |
258 echo '"'$(id -nu) ALL=(ALL) ALL'"' >>/etc/sudoers' | 268 echo '"'$(id -nu) ALL=(ALL) ALL'"' >>/etc/sudoers' |
259 | 269 |
260 # Install a few more commonly used packages | 270 # Install a few more commonly used packages |
261 sudo schroot -c "${target%bit}" -p -- apt-get -y install \ | 271 sudo schroot -c "${target%bit}" -p -- apt-get -y install \ |
262 autoconf automake1.9 dpkg-dev g++-multilib gcc-multilib gdb less libtool \ | 272 autoconf automake1.9 dpkg-dev g++-multilib gcc-multilib gdb less libtool \ |
263 strace | 273 strace |
264 | 274 |
265 # If running a 32bit environment on a 64bit machine, install a few binaries | 275 # If running a 32bit environment on a 64bit machine, install a few binaries |
266 # as 64bit. | 276 # as 64bit. This is only done automatically if the chroot distro is the same as |
267 if [ "${arch}" = 32bit ] && file /bin/bash 2>/dev/null | grep -q x86-64; then | 277 # the host, otherwise there might be incompatibilities in build settings or |
| 278 # runtime dependencies. The user can force it with the '-c' flag. |
| 279 host_distro=$(grep DISTRIB_CODENAME /etc/lsb-release 2>/dev/null | \ |
| 280 cut -d "=" -f 2) |
| 281 if [ "${copy_64}" = "y" -o \ |
| 282 "${host_distro}" = "${distname}" -a "${arch}" = 32bit ] && \ |
| 283 file /bin/bash 2>/dev/null | grep -q x86-64; then |
268 readlinepkg=$(sudo schroot -c "${target%bit}" -p -- sh -c \ | 284 readlinepkg=$(sudo schroot -c "${target%bit}" -p -- sh -c \ |
269 'apt-cache search "lib64readline.\$" | sort | tail -n 1 | cut -d " " -f 1') | 285 'apt-cache search "lib64readline.\$" | sort | tail -n 1 | cut -d " " -f 1') |
270 sudo schroot -c "${target%bit}" -p -- apt-get -y install \ | 286 sudo schroot -c "${target%bit}" -p -- apt-get -y install \ |
271 lib64expat1 lib64ncurses5 ${readlinepkg} lib64z1 | 287 lib64expat1 lib64ncurses5 ${readlinepkg} lib64z1 |
272 dep= | 288 dep= |
273 for i in binutils gdb strace; do | 289 for i in binutils gdb strace; do |
274 [ -d /usr/share/doc/"$i" ] || dep="$dep $i" | 290 [ -d /usr/share/doc/"$i" ] || dep="$dep $i" |
275 done | 291 done |
276 [ -n "$dep" ] && sudo apt-get -y install $dep | 292 [ -n "$dep" ] && sudo apt-get -y install $dep |
277 sudo cp /usr/bin/gdb "/var/lib/chroot/${target}/usr/local/bin/" | 293 sudo cp /usr/bin/gdb "/var/lib/chroot/${target}/usr/local/bin/" |
(...skipping 22 matching lines...) Expand all Loading... |
300 | 316 |
301 Successfully installed ${distname} ${arch} | 317 Successfully installed ${distname} ${arch} |
302 | 318 |
303 You can run programs inside of the chroot by invoking the "${target%bit}" | 319 You can run programs inside of the chroot by invoking the "${target%bit}" |
304 command. | 320 command. |
305 | 321 |
306 Your home directory is shared between the host and the chroot. But I configured | 322 Your home directory is shared between the host and the chroot. But I configured |
307 $HOME/chroot to be private to the chroot environment. You can use it | 323 $HOME/chroot to be private to the chroot environment. You can use it |
308 for files that need to differ between environments. | 324 for files that need to differ between environments. |
309 EOF | 325 EOF |
OLD | NEW |