Chromium Code Reviews| 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 "" \ | |
| 26 "The root of your chrome browser source. Should contain a 'src' subdir." | |
| 25 | 27 |
| 26 DEFINE_boolean official_build $FLAGS_FALSE "Set CHROMEOS_OFFICIAL=1 for release builds." | 28 DEFINE_boolean official_build $FLAGS_FALSE "Set CHROMEOS_OFFICIAL=1 for release builds." |
| 27 DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts." | 29 DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts." |
| 28 DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts." | 30 DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts." |
| 29 | 31 |
| 30 # More useful help | 32 # More useful help |
| 31 FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- \"command\"] | 33 FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- \"command\"] |
| 32 | 34 |
| 33 One or more VAR=value pairs can be specified to export variables into | 35 One or more VAR=value pairs can be specified to export variables into |
| 34 the chroot environment. For example: | 36 the chroot environment. For example: |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 52 if [ $FLAGS_official_build -eq $FLAGS_TRUE ] | 54 if [ $FLAGS_official_build -eq $FLAGS_TRUE ] |
| 53 then | 55 then |
| 54 CHROMEOS_OFFICIAL=1 | 56 CHROMEOS_OFFICIAL=1 |
| 55 fi | 57 fi |
| 56 | 58 |
| 57 # 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, |
| 58 # so will die prematurely if 'set -e' is specified before now. | 60 # so will die prematurely if 'set -e' is specified before now. |
| 59 # 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. |
| 60 set -e | 62 set -e |
| 61 | 63 |
| 64 INNER_CHROME_ROOT="/home/$USER/chrome_root" # inside chroot | |
| 65 CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot | |
| 66 | |
| 62 sudo chmod 0777 "$FLAGS_chroot/var/lock" | 67 sudo chmod 0777 "$FLAGS_chroot/var/lock" |
| 63 | 68 |
| 64 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" | 69 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" |
| 65 | 70 |
| 66 function setup_env { | 71 function setup_env { |
| 67 ( | 72 ( |
| 68 flock 200 | 73 flock 200 |
| 69 echo $$ >> "$LOCKFILE" | 74 echo $$ >> "$LOCKFILE" |
| 70 | 75 |
| 71 echo "Mounting chroot environment." | 76 echo "Mounting chroot environment." |
| 72 | 77 |
| 73 # Mount only if not already mounted | 78 # Mount only if not already mounted |
| 74 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" | 79 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" |
| 75 if [ -z "$(mount | grep -F "on $MOUNTED_PATH")" ] | 80 if [ -z "$(mount | grep -F "on $MOUNTED_PATH")" ] |
| 76 then | 81 then |
| 77 sudo mount none -t proc "$MOUNTED_PATH" | 82 sudo mount none -t proc "$MOUNTED_PATH" |
| 78 fi | 83 fi |
| 79 | 84 |
| 80 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/dev/pts")" | 85 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/dev/pts")" |
| 81 if [ -z "$(mount | grep -F "on $MOUNTED_PATH")" ] | 86 if [ -z "$(mount | grep -F "on $MOUNTED_PATH")" ] |
| 82 then | 87 then |
| 83 sudo mount none -t devpts "$MOUNTED_PATH" | 88 sudo mount none -t devpts "$MOUNTED_PATH" |
| 84 fi | 89 fi |
| 85 | 90 |
| 86 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}$CHROOT_TRUNK_DIR")" | 91 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}$CHROOT_TRUNK_DIR")" |
| 87 if [ -z "$(mount | grep -F "on $MOUNTED_PATH")" ] | 92 if [ -z "$(mount | grep -F "on $MOUNTED_PATH")" ] |
| 88 then | 93 then |
| 89 sudo mount --bind "$FLAGS_trunk" "$MOUNTED_PATH" | 94 sudo mount --bind "$FLAGS_trunk" "$MOUNTED_PATH" |
| 90 fi | 95 fi |
| 96 | |
| 97 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" | |
| 98 if [ -z "$(mount | grep -F "on $MOUNTED_PATH")" ] | |
| 99 then | |
| 100 CHROME_ROOT="$FLAGS_chrome_root" | |
| 101 if [ -z "$CHROME_ROOT" ]; then | |
| 102 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \ | |
| 103 2>/dev/null)" | |
| 104 fi | |
| 105 if [[ ( -z "$CHROME_ROOT" ) || ( ! -d "${CHROME_ROOT}/src" ) ]]; then | |
| 106 echo "Not mounting chrome source" | |
| 107 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" | |
| 108 else | |
| 109 echo "Mouting chrome source at: $INNER_CHROME_ROOT" | |
|
DaveMoore
2010/02/12 22:31:12
nit: spelling
| |
| 110 echo "$CHROME_ROOT" | \ | |
| 111 sudo dd of="${FLAGS_chroot}${CHROME_ROOT_CONFIG}" | |
| 112 mkdir -p "$MOUNTED_PATH" | |
| 113 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" | |
| 114 fi | |
| 115 fi | |
| 91 ) 200>>"$LOCKFILE" | 116 ) 200>>"$LOCKFILE" |
| 92 } | 117 } |
| 93 | 118 |
| 94 function teardown_env { | 119 function teardown_env { |
| 95 # Only teardown if we're the last enter_chroot to die | 120 # Only teardown if we're the last enter_chroot to die |
| 96 | 121 |
| 97 ( | 122 ( |
| 98 flock 200 | 123 flock 200 |
| 99 | 124 |
| 100 # check each pid in $LOCKFILE to see if it's died unexpectedly | 125 # 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... | |
| 178 | 203 |
| 179 # Run command or interactive shell. Also include the non-chrooted path to | 204 # Run command or interactive shell. Also include the non-chrooted path to |
| 180 # the source trunk for scripts that may need to print it (e.g. | 205 # the source trunk for scripts that may need to print it (e.g. |
| 181 # build_image.sh). | 206 # build_image.sh). |
| 182 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ | 207 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ |
| 183 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C "$@" | 208 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C "$@" |
| 184 | 209 |
| 185 # Remove trap and explicitly unmount | 210 # Remove trap and explicitly unmount |
| 186 trap - EXIT | 211 trap - EXIT |
| 187 teardown_env | 212 teardown_env |
| OLD | NEW |