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 # --- BEGIN COMMON.SH BOILERPLATE --- | 9 # --- BEGIN COMMON.SH BOILERPLATE --- |
| 10 # Load common CrOS utilities. Inside the chroot this file is installed in | 10 # Load common CrOS utilities. Inside the chroot this file is installed in |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 DEFINE_string chrome_root_mount "/home/$USER/chrome_root" \ | 44 DEFINE_string chrome_root_mount "/home/$USER/chrome_root" \ |
| 45 "The mount point of the chrome broswer source in the chroot." | 45 "The mount point of the chrome broswer source in the chroot." |
| 46 | 46 |
| 47 DEFINE_boolean git_config $FLAGS_TRUE \ | 47 DEFINE_boolean git_config $FLAGS_TRUE \ |
| 48 "Config git to work with your user/pass in the chroot." | 48 "Config git to work with your user/pass in the chroot." |
| 49 DEFINE_boolean official_build $FLAGS_FALSE \ | 49 DEFINE_boolean official_build $FLAGS_FALSE \ |
| 50 "Set CHROMEOS_OFFICIAL=1 for release builds." | 50 "Set CHROMEOS_OFFICIAL=1 for release builds." |
| 51 DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts." | 51 DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts." |
| 52 DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts." | 52 DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts." |
| 53 DEFINE_boolean ssh_agent $FLAGS_TRUE "Import ssh agent." | 53 DEFINE_boolean ssh_agent $FLAGS_TRUE "Import ssh agent." |
| 54 DEFINE_boolean verbose $FLAGS_FALSE "Print out actions taken" | |
| 54 | 55 |
| 55 # More useful help | 56 # More useful help |
| 56 FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- command [arg1] [arg2] ...] | 57 FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- command [arg1] [arg2] ...] |
| 57 | 58 |
| 58 One or more VAR=value pairs can be specified to export variables into | 59 One or more VAR=value pairs can be specified to export variables into |
| 59 the chroot environment. For example: | 60 the chroot environment. For example: |
| 60 | 61 |
| 61 $0 FOO=bar BAZ=bel | 62 $0 FOO=bar BAZ=bel |
| 62 | 63 |
| 63 If [-- command] is present, runs the command inside the chroot, | 64 If [-- command] is present, runs the command inside the chroot, |
| 64 after changing directory to /$USER/trunk/src/scripts. Note that neither | 65 after changing directory to /$USER/trunk/src/scripts. Note that neither |
| 65 the command nor args should include single quotes. For example: | 66 the command nor args should include single quotes. For example: |
| 66 | 67 |
| 67 $0 -- ./build_platform_packages.sh | 68 $0 -- ./build_platform_packages.sh |
| 68 | 69 |
| 69 Otherwise, provides an interactive shell. | 70 Otherwise, provides an interactive shell. |
| 70 " | 71 " |
| 71 | 72 |
| 73 # Version of info from common.sh that only echos if --verbose is set. | |
| 74 function v_info { | |
|
kliegs
2011/02/04 22:46:50
Would it be better to just shift the output levels
dgarrett
2011/02/04 23:57:43
I just checked, and DEBUG doesn't seem to exist fo
kliegs
2011/02/05 07:55:54
Even if DEBUG doesn't exist I'd rather see you cal
| |
| 75 if [ $FLAGS_verbose -eq $FLAGS_TRUE ]; then | |
| 76 info "$1" | |
| 77 fi | |
| 78 } | |
| 79 | |
| 72 # Double up on the first '--' argument. Why? For enter_chroot, we want to | 80 # Double up on the first '--' argument. Why? For enter_chroot, we want to |
| 73 # emulate the behavior of sudo for setting environment vars. That is, we want: | 81 # emulate the behavior of sudo for setting environment vars. That is, we want: |
| 74 # ./enter_chroot [flags] [VAR=val] [-- command] | 82 # ./enter_chroot [flags] [VAR=val] [-- command] |
| 75 # ...but shflags ends up eating the '--' out of the command line and gives | 83 # ...but shflags ends up eating the '--' out of the command line and gives |
| 76 # us back "VAR=val" and "command" together in one chunk. By doubling up, we | 84 # us back "VAR=val" and "command" together in one chunk. By doubling up, we |
| 77 # end up getting what we want back from shflags. | 85 # end up getting what we want back from shflags. |
| 78 # | 86 # |
| 79 # Examples of how people might be using enter_chroot: | 87 # Examples of how people might be using enter_chroot: |
| 80 # 1. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2 -- cmd arg1 arg2 | 88 # 1. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2 -- cmd arg1 arg2 |
| 81 # Set env vars and run cmd w/ args | 89 # Set env vars and run cmd w/ args |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 function setup_env { | 135 function setup_env { |
| 128 # Validate sudo timestamp before entering the critical section so that we | 136 # Validate sudo timestamp before entering the critical section so that we |
| 129 # don't stall for a password while we have the lockfile. | 137 # don't stall for a password while we have the lockfile. |
| 130 # Don't use sudo -v since that has issues on machines w/ no password. | 138 # Don't use sudo -v since that has issues on machines w/ no password. |
| 131 sudo echo "" > /dev/null | 139 sudo echo "" > /dev/null |
| 132 | 140 |
| 133 ( | 141 ( |
| 134 flock 200 | 142 flock 200 |
| 135 echo $$ >> "$LOCKFILE" | 143 echo $$ >> "$LOCKFILE" |
| 136 | 144 |
| 137 info "Mounting chroot environment." | 145 v_info "Mounting chroot environment." |
| 138 | 146 |
| 139 # Mount only if not already mounted | 147 # Mount only if not already mounted |
| 140 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" | 148 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" |
| 141 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then | 149 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
| 142 sudo mount none -t proc "$MOUNTED_PATH" || \ | 150 sudo mount none -t proc "$MOUNTED_PATH" || \ |
| 143 die "Could not mount $MOUNTED_PATH" | 151 die "Could not mount $MOUNTED_PATH" |
| 144 fi | 152 fi |
| 145 | 153 |
| 146 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/sys")" | 154 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/sys")" |
| 147 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then | 155 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 fi | 189 fi |
| 182 | 190 |
| 183 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" | 191 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" |
| 184 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then | 192 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
| 185 ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")" | 193 ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")" |
| 186 if [ -z "$CHROME_ROOT" ]; then | 194 if [ -z "$CHROME_ROOT" ]; then |
| 187 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \ | 195 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \ |
| 188 2>/dev/null)" | 196 2>/dev/null)" |
| 189 fi | 197 fi |
| 190 if [[ ( -z "$CHROME_ROOT" ) || ( ! -d "${CHROME_ROOT}/src" ) ]]; then | 198 if [[ ( -z "$CHROME_ROOT" ) || ( ! -d "${CHROME_ROOT}/src" ) ]]; then |
| 191 info "Not mounting chrome source" | 199 v_info "Not mounting chrome source" |
|
kliegs
2011/02/04 22:46:50
This can actually be an error if CHROME_ROOT is se
dgarrett
2011/02/04 23:57:43
Currently, this error is displayed every time you
kliegs
2011/02/05 07:55:54
We're not in the chromite world yet. Our entire t
| |
| 192 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" | 200 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" |
| 193 else | 201 else |
| 194 info "Mounting chrome source at: $INNER_CHROME_ROOT" | 202 v_info "Mounting chrome source at: $INNER_CHROME_ROOT" |
| 195 echo "$CHROME_ROOT" | \ | 203 echo "$CHROME_ROOT" | \ |
| 196 sudo dd of="${FLAGS_chroot}${CHROME_ROOT_CONFIG}" | 204 sudo dd of="${FLAGS_chroot}${CHROME_ROOT_CONFIG}" |
| 197 mkdir -p "$MOUNTED_PATH" | 205 mkdir -p "$MOUNTED_PATH" |
| 198 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \ | 206 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \ |
| 199 die "Could not mount $MOUNTED_PATH" | 207 die "Could not mount $MOUNTED_PATH" |
| 200 fi | 208 fi |
| 201 fi | 209 fi |
| 202 | 210 |
| 203 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")" | 211 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")" |
| 204 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then | 212 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
| 205 if [ $(which gclient 2>/dev/null) ]; then | 213 if [ $(which gclient 2>/dev/null) ]; then |
| 206 info "Mounting depot_tools" | 214 v_info "Mounting depot_tools" |
| 207 DEPOT_TOOLS=$(dirname "$(which gclient)") | 215 DEPOT_TOOLS=$(dirname "$(which gclient)") |
| 208 mkdir -p "$MOUNTED_PATH" | 216 mkdir -p "$MOUNTED_PATH" |
| 209 if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then | 217 if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then |
| 210 warn "depot_tools failed to mount; perhaps it's on NFS?" | 218 warn "depot_tools failed to mount; perhaps it's on NFS?" |
| 211 warn "This may impact chromium build." | 219 warn "This may impact chromium build." |
| 212 fi | 220 fi |
| 213 fi | 221 fi |
| 214 fi | 222 fi |
| 215 | 223 |
| 216 # Install fuse module. | 224 # Install fuse module. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 # Remove any dups from lock file while installing new one | 274 # Remove any dups from lock file while installing new one |
| 267 sort -n "$TMP_LOCKFILE" | uniq > "$LOCKFILE" | 275 sort -n "$TMP_LOCKFILE" | uniq > "$LOCKFILE" |
| 268 | 276 |
| 269 if [ $(which gconftool-2 2>/dev/null) ]; then | 277 if [ $(which gconftool-2 2>/dev/null) ]; then |
| 270 SAVED_PREF=$(cat "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}") | 278 SAVED_PREF=$(cat "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}") |
| 271 gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \ | 279 gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \ |
| 272 warn "could not re-set your automount preference." | 280 warn "could not re-set your automount preference." |
| 273 fi | 281 fi |
| 274 | 282 |
| 275 if [ -s "$LOCKFILE" ]; then | 283 if [ -s "$LOCKFILE" ]; then |
| 276 info "At least one other pid is running in the chroot, so not" | 284 v_info "At least one other pid is running in the chroot, so not" |
| 277 info "tearing down env." | 285 v_info "tearing down env." |
|
kliegs
2011/02/04 22:46:50
This feels like a warning to me, not an error. De
dgarrett
2011/02/04 23:57:43
It's an awfully normal case though.
On 2011/02/04
kliegs
2011/02/05 07:55:54
Its a very rare case for me. I almost never see t
| |
| 278 else | 286 else |
| 279 MOUNTED_PATH=$(readlink -f "$FLAGS_chroot") | 287 MOUNTED_PATH=$(readlink -f "$FLAGS_chroot") |
| 280 info "Unmounting chroot environment." | 288 v_info "Unmounting chroot environment." |
| 281 # sort the list of mounts in reverse order, to ensure umount of | 289 # sort the list of mounts in reverse order, to ensure umount of |
| 282 # cascading mounts in proper order | 290 # cascading mounts in proper order |
| 283 for i in \ | 291 for i in \ |
| 284 $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do | 292 $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do |
| 285 safe_umount "$i" | 293 safe_umount "$i" |
| 286 done | 294 done |
| 287 fi | 295 fi |
| 288 ) 200>>"$LOCKFILE" || die "teardown_env failed" | 296 ) 200>>"$LOCKFILE" || die "teardown_env failed" |
| 289 } | 297 } |
| 290 | 298 |
| 291 if [ $FLAGS_mount -eq $FLAGS_TRUE ]; then | 299 if [ $FLAGS_mount -eq $FLAGS_TRUE ]; then |
| 292 setup_env | 300 setup_env |
| 293 info "Make sure you run" | 301 v_info "Make sure you run" |
| 294 info " $0 --unmount" | 302 v_info " $0 --unmount" |
| 295 info "before deleting $FLAGS_chroot" | 303 v_info "before deleting $FLAGS_chroot" |
| 296 info "or you'll end up deleting $FLAGS_trunk too!" | 304 v_info "or you'll end up deleting $FLAGS_trunk too!" |
| 297 exit 0 | 305 exit 0 |
| 298 fi | 306 fi |
| 299 | 307 |
| 300 if [ $FLAGS_unmount -eq $FLAGS_TRUE ]; then | 308 if [ $FLAGS_unmount -eq $FLAGS_TRUE ]; then |
| 301 teardown_env | 309 teardown_env |
| 302 exit 0 | 310 exit 0 |
| 303 fi | 311 fi |
| 304 | 312 |
| 305 # Apply any hacks needed to update the chroot. | 313 # Apply any hacks needed to update the chroot. |
| 306 chroot_hacks_from_outside "${FLAGS_chroot}" | 314 chroot_hacks_from_outside "${FLAGS_chroot}" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 326 # Use git:8 chars of sha1 | 334 # Use git:8 chars of sha1 |
| 327 REVISION=$(cd ${FLAGS_trunk}/src/scripts ; git rev-parse --short=8 HEAD) | 335 REVISION=$(cd ${FLAGS_trunk}/src/scripts ; git rev-parse --short=8 HEAD) |
| 328 CHROOT_PASSTHRU="CHROMEOS_REVISION=$REVISION BUILDBOT_BUILD=$FLAGS_build_number CHROMEOS_OFFICIAL=$CHROMEOS_OFFICIAL" | 336 CHROOT_PASSTHRU="CHROMEOS_REVISION=$REVISION BUILDBOT_BUILD=$FLAGS_build_number CHROMEOS_OFFICIAL=$CHROMEOS_OFFICIAL" |
| 329 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ | 337 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ |
| 330 CHROMEOS_RELEASE_APPID=${CHROMEOS_RELEASE_APPID:-"{DEV-BUILD}"}" | 338 CHROMEOS_RELEASE_APPID=${CHROMEOS_RELEASE_APPID:-"{DEV-BUILD}"}" |
| 331 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ | 339 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ |
| 332 CHROMEOS_VERSION_TRACK=$CHROMEOS_VERSION_TRACK CHROMEOS_VERSION_AUSERVER=$CHROME OS_VERSION_AUSERVER CHROMEOS_VERSION_DEVSERVER=$CHROMEOS_VERSION_DEVSERVER" | 340 CHROMEOS_VERSION_TRACK=$CHROMEOS_VERSION_TRACK CHROMEOS_VERSION_AUSERVER=$CHROME OS_VERSION_AUSERVER CHROMEOS_VERSION_DEVSERVER=$CHROMEOS_VERSION_DEVSERVER" |
| 333 | 341 |
| 334 if [ -d "$HOME/.subversion" ]; then | 342 if [ -d "$HOME/.subversion" ]; then |
| 335 # Bind mounting .subversion into chroot | 343 # Bind mounting .subversion into chroot |
| 336 info "mounting ~/.subversion into chroot" | 344 v_info "mounting ~/.subversion into chroot" |
| 337 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/home/${USER}/.subversion")" | 345 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/home/${USER}/.subversion")" |
| 338 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then | 346 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
| 339 mkdir -p "$MOUNTED_PATH" | 347 mkdir -p "$MOUNTED_PATH" |
| 340 sudo mount --bind "$HOME/.subversion" "$MOUNTED_PATH" || \ | 348 sudo mount --bind "$HOME/.subversion" "$MOUNTED_PATH" || \ |
| 341 die "Could not mount $MOUNTED_PATH" | 349 die "Could not mount $MOUNTED_PATH" |
| 342 fi | 350 fi |
| 343 fi | 351 fi |
| 344 | 352 |
| 345 # Configure committer username and email in chroot .gitconfig | 353 # Configure committer username and email in chroot .gitconfig |
| 346 if [ $FLAGS_git_config -eq $FLAGS_TRUE ]; then | 354 if [ $FLAGS_git_config -eq $FLAGS_TRUE ]; then |
| 347 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ | 355 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ |
| 348 user.name "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/ *<.*//')" | 356 user.name "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/ *<.*//')" |
| 349 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ | 357 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ |
| 350 user.email "$(cd /tmp; git var GIT_COMMITTER_IDENT | \ | 358 user.email "$(cd /tmp; git var GIT_COMMITTER_IDENT | \ |
| 351 sed -e 's/.*<\([^>]*\)>.*/\1/')" | 359 sed -e 's/.*<\([^>]*\)>.*/\1/')" |
| 352 fi | 360 fi |
| 353 | 361 |
| 354 # Run command or interactive shell. Also include the non-chrooted path to | 362 # Run command or interactive shell. Also include the non-chrooted path to |
| 355 # the source trunk for scripts that may need to print it (e.g. | 363 # the source trunk for scripts that may need to print it (e.g. |
| 356 # build_image.sh). | 364 # build_image.sh). |
| 357 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ | 365 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ |
| 358 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ | 366 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ |
| 359 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" | 367 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" |
| 360 | 368 |
| 361 # Remove trap and explicitly unmount | 369 # Remove trap and explicitly unmount |
| 362 trap - EXIT | 370 trap - EXIT |
| 363 teardown_env | 371 teardown_env |
| OLD | NEW |