| OLD | NEW |
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 | 2 |
| 3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2009 The Chromium OS 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 # Script to enter the chroot environment | 7 # Script to enter the chroot environment |
| 8 | 8 |
| 9 # Load common constants. This should be the first executable line. | 9 # Load common constants. This should be the first executable line. |
| 10 # The path to common.sh should be relative to your script's location. | 10 # The path to common.sh should be relative to your script's location. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 CHROMEOS_OFFICIAL=1 | 56 CHROMEOS_OFFICIAL=1 |
| 57 fi | 57 fi |
| 58 | 58 |
| 59 # Only now can we die on error. shflags functions leak non-zero error codes, | 59 # Only now can we die on error. shflags functions leak non-zero error codes, |
| 60 # so will die prematurely if 'set -e' is specified before now. | 60 # so will die prematurely if 'set -e' is specified before now. |
| 61 # TODO: replace shflags with something less error-prone, or contribute a fix. | 61 # TODO: replace shflags with something less error-prone, or contribute a fix. |
| 62 set -e | 62 set -e |
| 63 | 63 |
| 64 INNER_CHROME_ROOT="/home/$USER/chrome_root" # inside chroot | 64 INNER_CHROME_ROOT="/home/$USER/chrome_root" # inside chroot |
| 65 CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot | 65 CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot |
| 66 INNER_DEPOT_TOOLS_ROOT="/home/$USER/depot_tools" # inside chroot |
| 66 | 67 |
| 67 sudo chmod 0777 "$FLAGS_chroot/var/lock" | 68 sudo chmod 0777 "$FLAGS_chroot/var/lock" |
| 68 | 69 |
| 69 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" | 70 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" |
| 70 | 71 |
| 71 function setup_env { | 72 function setup_env { |
| 72 ( | 73 ( |
| 73 flock 200 | 74 flock 200 |
| 74 echo $$ >> "$LOCKFILE" | 75 echo $$ >> "$LOCKFILE" |
| 75 | 76 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 106 echo "Not mounting chrome source" | 107 echo "Not mounting chrome source" |
| 107 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" | 108 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" |
| 108 else | 109 else |
| 109 echo "Mounting chrome source at: $INNER_CHROME_ROOT" | 110 echo "Mounting chrome source at: $INNER_CHROME_ROOT" |
| 110 echo "$CHROME_ROOT" | \ | 111 echo "$CHROME_ROOT" | \ |
| 111 sudo dd of="${FLAGS_chroot}${CHROME_ROOT_CONFIG}" | 112 sudo dd of="${FLAGS_chroot}${CHROME_ROOT_CONFIG}" |
| 112 mkdir -p "$MOUNTED_PATH" | 113 mkdir -p "$MOUNTED_PATH" |
| 113 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" | 114 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" |
| 114 fi | 115 fi |
| 115 fi | 116 fi |
| 117 |
| 118 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")" |
| 119 if [ -z "$(mount | grep -F "on $MOUNTED_PATH")" ] |
| 120 then |
| 121 if [ $(which gclient 2>/dev/null) ]; then |
| 122 echo "Mounting depot_tools" |
| 123 DEPOT_TOOLS=$(dirname $(which gclient) ) |
| 124 mkdir -p "$MOUNTED_PATH" |
| 125 sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH" |
| 126 fi |
| 127 fi |
| 116 ) 200>>"$LOCKFILE" | 128 ) 200>>"$LOCKFILE" |
| 117 } | 129 } |
| 118 | 130 |
| 119 function teardown_env { | 131 function teardown_env { |
| 120 # Only teardown if we're the last enter_chroot to die | 132 # Only teardown if we're the last enter_chroot to die |
| 121 | 133 |
| 122 ( | 134 ( |
| 123 flock 200 | 135 flock 200 |
| 124 | 136 |
| 125 # check each pid in $LOCKFILE to see if it's died unexpectedly | 137 # check each pid in $LOCKFILE to see if it's died unexpectedly |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 215 |
| 204 # Run command or interactive shell. Also include the non-chrooted path to | 216 # Run command or interactive shell. Also include the non-chrooted path to |
| 205 # the source trunk for scripts that may need to print it (e.g. | 217 # the source trunk for scripts that may need to print it (e.g. |
| 206 # build_image.sh). | 218 # build_image.sh). |
| 207 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ | 219 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ |
| 208 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C "$@" | 220 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C "$@" |
| 209 | 221 |
| 210 # Remove trap and explicitly unmount | 222 # Remove trap and explicitly unmount |
| 211 trap - EXIT | 223 trap - EXIT |
| 212 teardown_env | 224 teardown_env |
| OLD | NEW |