| 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. |
| 11 . "$(dirname "$0")/common.sh" | 11 . "$(dirname "$0")/common.sh" |
| 12 | 12 |
| 13 # Script must be run outside the chroot and as a regular user. | 13 # Script must be run outside the chroot and as a regular user. |
| 14 assert_outside_chroot | 14 assert_outside_chroot |
| 15 assert_not_root_user | 15 assert_not_root_user |
| 16 | 16 |
| 17 # Define command line flags | 17 # Define command line flags |
| 18 # See http://code.google.com/p/shflags/wiki/Documentation10x | 18 # See http://code.google.com/p/shflags/wiki/Documentation10x |
| 19 DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \ | 19 DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \ |
| 20 "The destination dir for the chroot environment." "d" | 20 "The destination dir for the chroot environment." "d" |
| 21 DEFINE_string trunk "$GCLIENT_ROOT" \ | 21 DEFINE_string trunk "$GCLIENT_ROOT" \ |
| 22 "The source trunk to bind mount within the chroot." "s" | 22 "The source trunk to bind mount within the chroot." "s" |
| 23 DEFINE_string build_number "" \ | 23 DEFINE_string build_number "" \ |
| 24 "The build-bot build number (when called by buildbot only)." "b" | 24 "The build-bot build number (when called by buildbot only)." "b" |
| 25 DEFINE_string chrome_root "" \ | 25 DEFINE_string chrome_root "" \ |
| 26 "The root of your chrome browser source. Should contain a 'src' subdir." | 26 "The root of your chrome browser source. Should contain a 'src' subdir." |
| 27 | 27 |
| 28 DEFINE_boolean official_build $FLAGS_FALSE "Set CHROMEOS_OFFICIAL=1 for release
builds." | 28 DEFINE_boolean official_build $FLAGS_FALSE \ |
| 29 "Set CHROMEOS_OFFICIAL=1 for release builds." |
| 29 DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts." | 30 DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts." |
| 30 DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts." | 31 DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts." |
| 31 | 32 |
| 32 # More useful help | 33 # More useful help |
| 33 FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- \"command\"] | 34 FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- \"command\"] |
| 34 | 35 |
| 35 One or more VAR=value pairs can be specified to export variables into | 36 One or more VAR=value pairs can be specified to export variables into |
| 36 the chroot environment. For example: | 37 the chroot environment. For example: |
| 37 | 38 |
| 38 $0 FOO=bar BAZ=bel | 39 $0 FOO=bar BAZ=bel |
| (...skipping 18 matching lines...) Expand all Loading... |
| 57 fi | 58 fi |
| 58 | 59 |
| 59 # Only now can we die on error. shflags functions leak non-zero error codes, | 60 # 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. | 61 # so will die prematurely if 'set -e' is specified before now. |
| 61 # TODO: replace shflags with something less error-prone, or contribute a fix. | 62 # TODO: replace shflags with something less error-prone, or contribute a fix. |
| 62 set -e | 63 set -e |
| 63 | 64 |
| 64 INNER_CHROME_ROOT="/home/$USER/chrome_root" # inside chroot | 65 INNER_CHROME_ROOT="/home/$USER/chrome_root" # inside chroot |
| 65 CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot | 66 CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot |
| 66 INNER_DEPOT_TOOLS_ROOT="/home/$USER/depot_tools" # inside chroot | 67 INNER_DEPOT_TOOLS_ROOT="/home/$USER/depot_tools" # inside chroot |
| 68 KERNEL_MODULES_ROOT="/lib/modules/$( uname -r )" # inside and outside chroot |
| 69 FUSE_DEVICE="/dev/fuse" |
| 67 | 70 |
| 68 sudo chmod 0777 "$FLAGS_chroot/var/lock" | 71 sudo chmod 0777 "$FLAGS_chroot/var/lock" |
| 69 | 72 |
| 70 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" | 73 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" |
| 71 | 74 |
| 72 function setup_env { | 75 function setup_env { |
| 73 ( | 76 ( |
| 74 flock 200 | 77 flock 200 |
| 75 echo $$ >> "$LOCKFILE" | 78 echo $$ >> "$LOCKFILE" |
| 76 | 79 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 then | 134 then |
| 132 if [ $(which gclient 2>/dev/null) ]; then | 135 if [ $(which gclient 2>/dev/null) ]; then |
| 133 echo "Mounting depot_tools" | 136 echo "Mounting depot_tools" |
| 134 DEPOT_TOOLS=$(dirname $(which gclient) ) | 137 DEPOT_TOOLS=$(dirname $(which gclient) ) |
| 135 mkdir -p "$MOUNTED_PATH" | 138 mkdir -p "$MOUNTED_PATH" |
| 136 if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then | 139 if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then |
| 137 echo "depot_tools failed to mount; perhaps it's on NFS?" | 140 echo "depot_tools failed to mount; perhaps it's on NFS?" |
| 138 echo "This may impact chromium build." | 141 echo "This may impact chromium build." |
| 139 fi | 142 fi |
| 140 fi | 143 fi |
| 141 fi | 144 fi |
| 145 |
| 146 # Mount fuse device from host machine into chroot and copy over |
| 147 # corresponding kernel modules. |
| 148 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${FUSE_DEVICE}")" |
| 149 if [ -z "$(mount | grep -F "on ${MOUNTED_PATH} ")" ] |
| 150 then |
| 151 if [ -c "${FUSE_DEVICE}" ] ; then |
| 152 echo "Mounting fuse device" |
| 153 sudo touch "${MOUNTED_PATH}" |
| 154 sudo mount --bind "${FUSE_DEVICE}" "${MOUNTED_PATH}" |
| 155 INNER_MOD_PATH="$(readlink -f "${FLAGS_chroot}${KERNEL_MODULES_ROOT}")"
|
| 156 if [ ! -f "${INNER_MOD_PATH}/modules.dep" ] ; then |
| 157 sudo mkdir -p "${INNER_MOD_PATH}/kernel/fs/fuse" |
| 158 sudo cp -fu "${KERNEL_MODULES_ROOT}/modules.dep" "${INNER_MOD_PATH}" |
| 159 sudo cp -fu "${KERNEL_MODULES_ROOT}/kernel/fs/fuse/fuse.ko" \ |
| 160 "${INNER_MOD_PATH}/kernel/fs/fuse" |
| 161 fi |
| 162 else |
| 163 echo "Warning: Fuse device not found. gmergefs will not work" |
| 164 fi |
| 165 fi |
| 166 |
| 142 ) 200>>"$LOCKFILE" || die "setup_env failed" | 167 ) 200>>"$LOCKFILE" || die "setup_env failed" |
| 143 } | 168 } |
| 144 | 169 |
| 145 function teardown_env { | 170 function teardown_env { |
| 146 # Only teardown if we're the last enter_chroot to die | 171 # Only teardown if we're the last enter_chroot to die |
| 147 ( | 172 ( |
| 148 flock 200 | 173 flock 200 |
| 149 | 174 |
| 150 # check each pid in $LOCKFILE to see if it's died unexpectedly | 175 # check each pid in $LOCKFILE to see if it's died unexpectedly |
| 151 TMP_LOCKFILE="$LOCKFILE.tmp" | 176 TMP_LOCKFILE="$LOCKFILE.tmp" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 255 |
| 231 # Run command or interactive shell. Also include the non-chrooted path to | 256 # Run command or interactive shell. Also include the non-chrooted path to |
| 232 # the source trunk for scripts that may need to print it (e.g. | 257 # the source trunk for scripts that may need to print it (e.g. |
| 233 # build_image.sh). | 258 # build_image.sh). |
| 234 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ | 259 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ |
| 235 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C "$@" | 260 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C "$@" |
| 236 | 261 |
| 237 # Remove trap and explicitly unmount | 262 # Remove trap and explicitly unmount |
| 238 trap - EXIT | 263 trap - EXIT |
| 239 teardown_env | 264 teardown_env |
| OLD | NEW |