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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 --) shift; break;; | 491 --) shift; break;; |
492 -h|--help) shift; help;; | 492 -h|--help) shift; help;; |
493 -l|--list) shift; list;; | 493 -l|--list) shift; list;; |
494 -c|--clean) shift; clean "${chroot}";; | 494 -c|--clean) shift; clean "${chroot}";; |
495 -C|--clean-all) shift; clean;; | 495 -C|--clean-all) shift; clean;; |
496 *) break;; | 496 *) break;; |
497 esac | 497 esac |
498 done | 498 done |
499 | 499 |
500 session="$(schroot -c "${chroot}" -b)" | 500 session="$(schroot -c "${chroot}" -b)" |
501 export CHROOT_SESSION_ID="${session}" | |
501 | 502 |
502 if [ $# -eq 0 ]; then | 503 if [ $# -eq 0 ]; then |
503 schroot -c "${session}" -r -p | 504 schroot -c "${session}" -r -p |
504 else | 505 else |
505 p="$1"; shift | 506 p="$1"; shift |
506 schroot -c "${session}" -r -p "$p" -- "$@" | 507 schroot -c "${session}" -r -p "$p" -- "$@" |
507 fi | 508 fi |
508 rc=$? | 509 rc=$? |
509 | 510 |
510 i=$(schroot -c "${session}" -r -p ls -- -id /proc/self/root/. | | 511 i=$(schroot -c "${session}" -r -p ls -- -id /proc/self/root/. | |
511 awk '{ print $1 }') 2>/dev/null | 512 awk '{ print $1 }') 2>/dev/null |
513 other_pids= | |
512 while [ -n "$i" ]; do | 514 while [ -n "$i" ]; do |
513 pids=$(ls -id1 /proc/*/root/. 2>/dev/null | | 515 pids=$({ ls -id1 /proc/*/root/. 2>/dev/null | |
jln (very slow on Chromium)
2013/07/23 00:41:20
Add a comment to explain the set substraction magi
| |
514 sed -e 's,^[^0-9]*'$i'.*/\([1-9][0-9]*\)/.*$,\1, | 516 sed -e 's,^[^0-9]*'$i'.*/\([1-9][0-9]*\)/.*$,\1, |
515 t | 517 t |
516 d') >/dev/null 2>&1 | 518 d'; |
517 [ -z "$pids" ] && break | 519 echo "${other_pids}"; |
518 kill -9 $pids | 520 echo "${other_pids}"; } | sort | uniq -u) >/dev/null 2>&1 |
521 # Kill all processes that are still left running in the session. This is | |
522 # typically an assortment of daemon processes that were started | |
523 # automatically. They result in us being unable to tear down the session | |
524 # cleanly. | |
525 [ -z "${pids}" ] && break | |
526 for j in $pids; do | |
527 # Unfortunately, the way that schroot sets up sessions has the | |
528 # side-effect of being unable to tell one session apart from another. | |
529 # This can result in us attempting to kill processes in other sessions. | |
530 # We make a best-effort to avoid doing so. | |
531 k="$( ( xargs -0 -n1 </proc/$j/environ ) 2>/dev/null | | |
532 sed 's/^CHROOT_SESSION_ID=/x/;t1;d;:1;q')" | |
533 if [ -n "${k}" -a "${k#x}" != "${session}" ]; then | |
534 other_pids="${other_pids} | |
535 ${j}" | |
536 continue | |
537 fi | |
538 kill -9 $pids | |
539 done | |
519 done | 540 done |
520 schroot -c "${session}" -e | 541 schroot -c "${session}" -e |
521 exit $rc | 542 exit $rc |
522 EOF | 543 EOF |
523 sudo chown root:root /usr/local/bin/"${target%bit}" | 544 sudo chown root:root /usr/local/bin/"${target%bit}" |
524 sudo chmod 755 /usr/local/bin/"${target%bit}" | 545 sudo chmod 755 /usr/local/bin/"${target%bit}" |
525 | 546 |
526 # Add the standard Ubuntu update repositories if requested. | 547 # Add the standard Ubuntu update repositories if requested. |
527 [ "${alt_repos}" = "y" -a \ | 548 [ "${alt_repos}" = "y" -a \ |
528 -r "/var/lib/chroot/${target}/etc/apt/sources.list" ] && | 549 -r "/var/lib/chroot/${target}/etc/apt/sources.list" ] && |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
807 | 828 |
808 For Chrome, this probably means you want to make your "out" directory a | 829 For Chrome, this probably means you want to make your "out" directory a |
809 symbolic link that points somewhere inside of "${HOME}/chroot". | 830 symbolic link that points somewhere inside of "${HOME}/chroot". |
810 | 831 |
811 You still need to run "gclient runhooks" whenever you switch from building | 832 You still need to run "gclient runhooks" whenever you switch from building |
812 outside of the chroot to inside of the chroot. But you will find that you | 833 outside of the chroot to inside of the chroot. But you will find that you |
813 don't have to repeatedly erase and then completely rebuild all your object | 834 don't have to repeatedly erase and then completely rebuild all your object |
814 and binary files. | 835 and binary files. |
815 | 836 |
816 EOF | 837 EOF |
OLD | NEW |