| OLD | NEW |
| 1 #!/bin/bash -e | 1 #!/bin/bash -e |
| 2 | 2 |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 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 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 echo "I can abort installation, I can overwrite the existing chroot," | 216 echo "I can abort installation, I can overwrite the existing chroot," |
| 217 echo "or I can delete the old one and then exit. What would you like to" | 217 echo "or I can delete the old one and then exit. What would you like to" |
| 218 printf "do (a/o/d)? " | 218 printf "do (a/o/d)? " |
| 219 read choice | 219 read choice |
| 220 case "${choice}" in | 220 case "${choice}" in |
| 221 a|A) exit 1;; | 221 a|A) exit 1;; |
| 222 o|O) sudo rm -rf "/var/lib/chroot/${target}"; break;; | 222 o|O) sudo rm -rf "/var/lib/chroot/${target}"; break;; |
| 223 d|D) sudo rm -rf "/var/lib/chroot/${target}" \ | 223 d|D) sudo rm -rf "/var/lib/chroot/${target}" \ |
| 224 "/usr/local/bin/${target%bit}" \ | 224 "/usr/local/bin/${target%bit}" \ |
| 225 "/etc/schroot/mount-${target}" \ | 225 "/etc/schroot/mount-${target}" \ |
| 226 "/etc/schroot/script-${target}" | 226 "/etc/schroot/script-${target}" \ |
| 227 "/etc/schroot/${target}" |
| 227 sudo sed -ni '/^[[]'"${target%bit}"']$/,${ | 228 sudo sed -ni '/^[[]'"${target%bit}"']$/,${ |
| 228 :1;n;/^[[]/b2;b1;:2;p;n;b2};p' \ | 229 :1;n;/^[[]/b2;b1;:2;p;n;b2};p' \ |
| 229 "/etc/schroot/schroot.conf" | 230 "/etc/schroot/schroot.conf" |
| 230 trap '' INT TERM QUIT HUP | 231 trap '' INT TERM QUIT HUP |
| 231 trap '' EXIT | 232 trap '' EXIT |
| 232 echo "Deleted!" | 233 echo "Deleted!" |
| 233 exit 0;; | 234 exit 0;; |
| 234 esac | 235 esac |
| 235 done | 236 done |
| 236 echo | 237 echo |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 | 343 |
| 343 sudo ${http_proxy:+http_proxy="${http_proxy}"} debootstrap ${archflag} \ | 344 sudo ${http_proxy:+http_proxy="${http_proxy}"} debootstrap ${archflag} \ |
| 344 "${distname}" "/var/lib/chroot/${target}" "$mirror" | 345 "${distname}" "/var/lib/chroot/${target}" "$mirror" |
| 345 | 346 |
| 346 # Add new entry to /etc/schroot/schroot.conf | 347 # Add new entry to /etc/schroot/schroot.conf |
| 347 grep -qs ubuntu.com /usr/share/debootstrap/scripts/"${distname}" && | 348 grep -qs ubuntu.com /usr/share/debootstrap/scripts/"${distname}" && |
| 348 brand="Ubuntu" || brand="Debian" | 349 brand="Ubuntu" || brand="Debian" |
| 349 if [ -z "${chroot_groups}" ]; then | 350 if [ -z "${chroot_groups}" ]; then |
| 350 chroot_groups="${admin},$(id -gn)" | 351 chroot_groups="${admin},$(id -gn)" |
| 351 fi | 352 fi |
| 352 # Older versions of schroot wanted a "priority=" line, whereas recent | 353 |
| 353 # versions deprecate "priority=" and warn if they see it. We don't have | 354 if [ -d '/etc/schroot/default' ]; then |
| 354 # a good feature test, but scanning for the string "priority=" in the | 355 new_version=1 |
| 355 # existing "schroot.conf" file is a good indication of what to do. | 356 fstab="/etc/schroot/${target}/fstab" |
| 356 priority=$(grep -qs 'priority=' /etc/schroot/schroot.conf && | 357 else |
| 357 echo 'priority=3' || :) | 358 new_version=0 |
| 358 sudo sh -c 'cat >>/etc/schroot/schroot.conf' <<EOF | 359 fstab="/etc/schroot/mount-${target}" |
| 360 fi |
| 361 |
| 362 if [ "$new_version" = "1" ]; then |
| 363 sudo cp -ar /etc/schroot/default /etc/schroot/${target} |
| 364 |
| 365 sudo sh -c 'cat >>/etc/schroot/schroot.conf' <<EOF |
| 359 [${target%bit}] | 366 [${target%bit}] |
| 360 description=${brand} ${distname} ${arch} | 367 description=${brand} ${distname} ${arch} |
| 361 type=directory | 368 type=directory |
| 369 directory=/var/lib/chroot/${target} |
| 370 users=root |
| 371 groups=${chroot_groups} |
| 372 root-groups=${chroot_groups} |
| 373 personality=linux$([ "${arch}" != 64bit ] && echo 32) |
| 374 profile=${target} |
| 375 |
| 376 EOF |
| 377 [ -n "${bind_mounts}" -a "${bind_mounts}" != "NONE" ] && |
| 378 printf "${bind_mounts}" | |
| 379 sudo sh -c "cat >>${fstab}" |
| 380 else |
| 381 # Older versions of schroot wanted a "priority=" line, whereas recent |
| 382 # versions deprecate "priority=" and warn if they see it. We don't have |
| 383 # a good feature test, but scanning for the string "priority=" in the |
| 384 # existing "schroot.conf" file is a good indication of what to do. |
| 385 priority=$(grep -qs 'priority=' /etc/schroot/schroot.conf && |
| 386 echo 'priority=3' || :) |
| 387 sudo sh -c 'cat >>/etc/schroot/schroot.conf' <<EOF |
| 388 [${target%bit}] |
| 389 description=${brand} ${distname} ${arch} |
| 390 type=directory |
| 362 directory=/var/lib/chroot/${target} | 391 directory=/var/lib/chroot/${target} |
| 363 users=root | 392 users=root |
| 364 groups=${chroot_groups} | 393 groups=${chroot_groups} |
| 365 root-groups=${chroot_groups} | 394 root-groups=${chroot_groups} |
| 366 personality=linux$([ "${arch}" != 64bit ] && echo 32) | 395 personality=linux$([ "${arch}" != 64bit ] && echo 32) |
| 367 script-config=script-${target} | 396 script-config=script-${target} |
| 368 ${priority} | 397 ${priority} |
| 369 | 398 |
| 370 EOF | 399 EOF |
| 371 | 400 |
| 372 # Set up a list of mount points that is specific to this | 401 # Set up a list of mount points that is specific to this |
| 373 # chroot environment. | 402 # chroot environment. |
| 374 sed '/^FSTAB=/s,"[^"]*","/etc/schroot/mount-'"${target}"'",' \ | 403 sed '/^FSTAB=/s,"[^"]*","'"${fstab}"'",' \ |
| 375 /etc/schroot/script-defaults | | 404 /etc/schroot/script-defaults | |
| 376 sudo sh -c 'cat >/etc/schroot/script-'"${target}" | 405 sudo sh -c 'cat >/etc/schroot/script-'"${target}" |
| 377 sed '\,^/home[/[:space:]],s/\([,[:space:]]\)bind[[:space:]]/\1rbind /' \ | 406 sed '\,^/home[/[:space:]],s/\([,[:space:]]\)bind[[:space:]]/\1rbind /' \ |
| 378 /etc/schroot/mount-defaults | | 407 /etc/schroot/mount-defaults | |
| 379 sudo sh -c 'cat > /etc/schroot/mount-'"${target}" | 408 sudo sh -c "cat > ${fstab}" |
| 409 fi |
| 380 | 410 |
| 381 # Add the extra mount points that the user told us about | 411 # Add the extra mount points that the user told us about |
| 382 [ -n "${bind_mounts}" -a "${bind_mounts}" != "NONE" ] && | 412 [ -n "${bind_mounts}" -a "${bind_mounts}" != "NONE" ] && |
| 383 printf "${bind_mounts}" | | 413 printf "${bind_mounts}" | |
| 384 sudo sh -c 'cat >>/etc/schroot/mount-'"${target}" | 414 sudo sh -c 'cat >>'"${fstab}" |
| 385 | 415 |
| 386 # If this system has a "/media" mountpoint, import it into the chroot | 416 # If this system has a "/media" mountpoint, import it into the chroot |
| 387 # environment. Most modern distributions use this mount point to | 417 # environment. Most modern distributions use this mount point to |
| 388 # automatically mount devices such as CDROMs, USB sticks, etc... | 418 # automatically mount devices such as CDROMs, USB sticks, etc... |
| 389 if [ -d /media ] && | 419 if [ -d /media ] && |
| 390 ! grep -qs '^/media' /etc/schroot/mount-"${target}"; then | 420 ! grep -qs '^/media' "${fstab}"; then |
| 391 echo '/media /media none rw,rbind 0 0' | | 421 echo '/media /media none rw,rbind 0 0' | |
| 392 sudo sh -c 'cat >>/etc/schroot/mount-'"${target}" | 422 sudo sh -c 'cat >>'"${fstab}" |
| 393 fi | 423 fi |
| 394 | 424 |
| 395 # Share /dev/shm, /run and /run/shm. | 425 # Share /dev/shm, /run and /run/shm. |
| 396 grep -qs '^/dev/shm' /etc/schroot/mount-"${target}" || | 426 grep -qs '^/dev/shm' "${fstab}" || |
| 397 echo '/dev/shm /dev/shm none rw,bind 0 0' | | 427 echo '/dev/shm /dev/shm none rw,bind 0 0' | |
| 398 sudo sh -c 'cat >>/etc/schroot/mount-'"${target}" | 428 sudo sh -c 'cat >>'"${fstab}" |
| 399 if [ ! -d "/var/lib/chroot/${target}/run" ] && | 429 if [ ! -d "/var/lib/chroot/${target}/run" ] && |
| 400 ! grep -qs '^/run' /etc/schroot/mount-"${target}"; then | 430 ! grep -qs '^/run' "${fstab}"; then |
| 401 echo '/run /run none rw,bind 0 0' | | 431 echo '/run /run none rw,bind 0 0' | |
| 402 sudo sh -c 'cat >>/etc/schroot/mount-'"${target}" | 432 sudo sh -c 'cat >>'"${fstab}" |
| 403 fi | 433 fi |
| 404 if ! grep -qs '^/run/shm' /etc/schroot/mount-"${target}"; then | 434 if ! grep -qs '^/run/shm' "${fstab}"; then |
| 405 { [ -d /run ] && echo '/run/shm /run/shm none rw,bind 0 0' || | 435 { [ -d /run ] && echo '/run/shm /run/shm none rw,bind 0 0' || |
| 406 echo '/dev/shm /run/shm none rw,bind 0 0'; } | | 436 echo '/dev/shm /run/shm none rw,bind 0 0'; } | |
| 407 sudo sh -c 'cat >>/etc/schroot/mount-'"${target}" | 437 sudo sh -c 'cat >>'"${fstab}" |
| 408 fi | 438 fi |
| 409 | 439 |
| 410 # Set up a special directory that changes contents depending on the target | 440 # Set up a special directory that changes contents depending on the target |
| 411 # that is executing. | 441 # that is executing. |
| 412 d="$(readlink -f "${HOME}/chroot" 2>/dev/null || echo "${HOME}/chroot")" | 442 d="$(readlink -f "${HOME}/chroot" 2>/dev/null || echo "${HOME}/chroot")" |
| 413 s="${d}/.${target}" | 443 s="${d}/.${target}" |
| 414 echo "${s} ${d} none rw,bind 0 0" | | 444 echo "${s} ${d} none rw,bind 0 0" | |
| 415 sudo sh -c 'cat >>/etc/schroot/mount-'"${target}" | 445 sudo sh -c 'cat >>'"${target}" |
| 416 mkdir -p "${s}" | 446 mkdir -p "${s}" |
| 417 | 447 |
| 418 # Install a helper script to launch commands in the chroot | 448 # Install a helper script to launch commands in the chroot |
| 419 sudo sh -c 'cat >/usr/local/bin/'"${target%bit}" <<'EOF' | 449 sudo sh -c 'cat >/usr/local/bin/'"${target%bit}" <<'EOF' |
| 420 #!/bin/bash | 450 #!/bin/bash |
| 421 | 451 |
| 422 chroot="${0##*/}" | 452 chroot="${0##*/}" |
| 423 | 453 |
| 424 wrap() { | 454 wrap() { |
| 425 # Word-wrap the text passed-in on stdin. Optionally, on continuation lines | 455 # Word-wrap the text passed-in on stdin. Optionally, on continuation lines |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 if ! sudo /usr/local/bin/"${target%bit}" \ | 740 if ! sudo /usr/local/bin/"${target%bit}" \ |
| 711 sh -c "[ -x '${script}' ]" >&/dev/null; then | 741 sh -c "[ -x '${script}' ]" >&/dev/null; then |
| 712 tmp_script="/tmp/${script##*/}" | 742 tmp_script="/tmp/${script##*/}" |
| 713 cp "${script}" "${tmp_script}" | 743 cp "${script}" "${tmp_script}" |
| 714 fi | 744 fi |
| 715 # Some distributions automatically start an instance of the system- | 745 # Some distributions automatically start an instance of the system- |
| 716 # wide dbus daemon, cron daemon or of the logging daemon, when | 746 # wide dbus daemon, cron daemon or of the logging daemon, when |
| 717 # installing the Chrome build depencies. This prevents the chroot | 747 # installing the Chrome build depencies. This prevents the chroot |
| 718 # session from being closed. So, we always try to shut down any running | 748 # session from being closed. So, we always try to shut down any running |
| 719 # instance of dbus and rsyslog. | 749 # instance of dbus and rsyslog. |
| 720 sudo /usr/local/bin/"${target%bit}" sh -c "${script} --no-lib32; | 750 sudo /usr/local/bin/"${target%bit}" sh -c "${script}; |
| 721 rc=$?; | 751 rc=$?; |
| 722 /etc/init.d/cron stop >/dev/null 2>&1 || :; | 752 /etc/init.d/cron stop >/dev/null 2>&1 || :; |
| 723 /etc/init.d/rsyslog stop >/dev/null 2>&1 || :; | 753 /etc/init.d/rsyslog stop >/dev/null 2>&1 || :; |
| 724 /etc/init.d/dbus stop >/dev/null 2>&1 || :; | 754 /etc/init.d/dbus stop >/dev/null 2>&1 || :; |
| 725 exit $rc" | 755 exit $rc" |
| 726 rc=$? | 756 rc=$? |
| 727 [ -n "${tmp_script}" ] && rm -f "${tmp_script}" | 757 [ -n "${tmp_script}" ] && rm -f "${tmp_script}" |
| 728 [ $rc -ne 0 ] && exit $rc | 758 [ $rc -ne 0 ] && exit $rc |
| 729 break | 759 break |
| 730 ;; | 760 ;; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 | 879 |
| 850 For Chrome, this probably means you want to make your "out" directory a | 880 For Chrome, this probably means you want to make your "out" directory a |
| 851 symbolic link that points somewhere inside of "${HOME}/chroot". | 881 symbolic link that points somewhere inside of "${HOME}/chroot". |
| 852 | 882 |
| 853 You still need to run "gclient runhooks" whenever you switch from building | 883 You still need to run "gclient runhooks" whenever you switch from building |
| 854 outside of the chroot to inside of the chroot. But you will find that you | 884 outside of the chroot to inside of the chroot. But you will find that you |
| 855 don't have to repeatedly erase and then completely rebuild all your object | 885 don't have to repeatedly erase and then completely rebuild all your object |
| 856 and binary files. | 886 and binary files. |
| 857 | 887 |
| 858 EOF | 888 EOF |
| OLD | NEW |