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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 echo "executing \"${target%bit} -c\"." | 213 echo "executing \"${target%bit} -c\"." |
214 exit 1 | 214 exit 1 |
215 fi | 215 fi |
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}"; exit 0;; | 223 d|D) sudo rm -rf "/var/lib/chroot/${target}" \ |
| 224 "/usr/local/bin/${target%bit}" \ |
| 225 "/etc/schroot/mount-${target}" \ |
| 226 "/etc/schroot/script-${target}" |
| 227 sudo sed -ni '/^[[]'"${target%bit}"']$/,${ |
| 228 :1;n;/^[[]/b2;b1;:2;p;n;b2};p' \ |
| 229 "/etc/schroot/schroot.conf" |
| 230 trap '' INT TERM QUIT HUP |
| 231 trap '' EXIT |
| 232 echo "Deleted!" |
| 233 exit 0;; |
224 esac | 234 esac |
225 done | 235 done |
226 echo | 236 echo |
227 } | 237 } |
228 sudo mkdir -p /var/lib/chroot/"${target}" | 238 sudo mkdir -p /var/lib/chroot/"${target}" |
229 | 239 |
230 # Offer to include additional standard repositories for Ubuntu-based chroots. | 240 # Offer to include additional standard repositories for Ubuntu-based chroots. |
231 alt_repos= | 241 alt_repos= |
232 grep -qs ubuntu.com /usr/share/debootstrap/scripts/"${distname}" && { | 242 grep -qs ubuntu.com /usr/share/debootstrap/scripts/"${distname}" && { |
233 while :; do | 243 while :; do |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 if [ -n "$1" ]; then | 454 if [ -n "$1" ]; then |
445 t="${s#session:}" | 455 t="${s#session:}" |
446 [ "${t#${chroot}-}" == "${t}" ] && continue | 456 [ "${t#${chroot}-}" == "${t}" ] && continue |
447 fi | 457 fi |
448 if ls -l /proc/*/{cwd,fd} 2>/dev/null | | 458 if ls -l /proc/*/{cwd,fd} 2>/dev/null | |
449 fgrep -qs "/var/lib/schroot/mount/${t}"; then | 459 fgrep -qs "/var/lib/schroot/mount/${t}"; then |
450 echo "Session \"${t}\" still has active users, not cleaning up" | wrap | 460 echo "Session \"${t}\" still has active users, not cleaning up" | wrap |
451 rc=1 | 461 rc=1 |
452 continue | 462 continue |
453 fi | 463 fi |
454 schroot -c "${s}" -e || rc=1 | 464 sudo schroot -c "${s}" -e || rc=1 |
455 done | 465 done |
456 exit ${rc} | 466 exit ${rc} |
457 } | 467 } |
458 | 468 |
459 list() { | 469 list() { |
460 for e in $(schroot -l); do | 470 for e in $(schroot -l); do |
461 e="${e#chroot:}" | 471 e="${e#chroot:}" |
462 [ -x "/usr/local/bin/${e}" ] || continue | 472 [ -x "/usr/local/bin/${e}" ] || continue |
463 if schroot -l --all-sessions 2>/dev/null | | 473 if schroot -l --all-sessions 2>/dev/null | |
464 sed 's/^session://' | | 474 sed 's/^session://' | |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 echo | 648 echo |
639 # We prefer running the script in-place, but this might not be | 649 # We prefer running the script in-place, but this might not be |
640 # possible, if it lives on a network filesystem that denies | 650 # possible, if it lives on a network filesystem that denies |
641 # access to root. | 651 # access to root. |
642 tmp_script= | 652 tmp_script= |
643 if ! sudo "${target%bit}" sh -c "[ -x '${script}' ]" >&/dev/null; then | 653 if ! sudo "${target%bit}" sh -c "[ -x '${script}' ]" >&/dev/null; then |
644 tmp_script="/tmp/${script##*/}" | 654 tmp_script="/tmp/${script##*/}" |
645 cp "${script}" "${tmp_script}" | 655 cp "${script}" "${tmp_script}" |
646 fi | 656 fi |
647 # Some distributions automatically start an instance of the system- | 657 # Some distributions automatically start an instance of the system- |
648 # wide dbus daemon, when installing the Chrome build depencies. This | 658 # wide dbus daemon or of the logging daemon, when installing the Chrome |
649 # prevents the chroot session from being closed. So, we always try | 659 # build depencies. This prevents the chroot session from being closed. |
650 # to shut down any running instance of dbus. | 660 # So, we always try to shut down any running instance of dbus and |
| 661 # rsyslog. |
651 sudo "${target%bit}" sh -c "${script} --no-lib32; | 662 sudo "${target%bit}" sh -c "${script} --no-lib32; |
652 rc=$?; | 663 rc=$?; |
| 664 /etc/init.d/rsyslog stop >/dev/null 2>&1 || :; |
653 /etc/init.d/dbus stop >/dev/null 2>&1 || :; | 665 /etc/init.d/dbus stop >/dev/null 2>&1 || :; |
654 exit $rc" | 666 exit $rc" |
655 rc=$? | 667 rc=$? |
656 [ -n "${tmp_script}" ] && rm -f "${tmp_script}" | 668 [ -n "${tmp_script}" ] && rm -f "${tmp_script}" |
657 [ $rc -ne 0 ] && exit $rc | 669 [ $rc -ne 0 ] && exit $rc |
658 break | 670 break |
659 ;; | 671 ;; |
660 n|N) | 672 n|N) |
661 break | 673 break |
662 ;; | 674 ;; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 | 790 |
779 For Chrome, this probably means you want to make your "out" directory a | 791 For Chrome, this probably means you want to make your "out" directory a |
780 symbolic link that points somewhere inside of "${HOME}/chroot". | 792 symbolic link that points somewhere inside of "${HOME}/chroot". |
781 | 793 |
782 You still need to run "gclient runhooks" whenever you switch from building | 794 You still need to run "gclient runhooks" whenever you switch from building |
783 outside of the chroot to inside of the chroot. But you will find that you | 795 outside of the chroot to inside of the chroot. But you will find that you |
784 don't have to repeatedly erase and then completely rebuild all your object | 796 don't have to repeatedly erase and then completely rebuild all your object |
785 and binary files. | 797 and binary files. |
786 | 798 |
787 EOF | 799 EOF |
OLD | NEW |