| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 AUTOMOUNT_PREF="/apps/nautilus/preferences/media_automount" | 120 AUTOMOUNT_PREF="/apps/nautilus/preferences/media_automount" |
| 121 SAVED_AUTOMOUNT_PREF_FILE="/tmp/.automount_pref" | 121 SAVED_AUTOMOUNT_PREF_FILE="/tmp/.automount_pref" |
| 122 | 122 |
| 123 sudo chmod 0777 "$FLAGS_chroot/var/lock" | 123 sudo chmod 0777 "$FLAGS_chroot/var/lock" |
| 124 | 124 |
| 125 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" | 125 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" |
| 126 | 126 |
| 127 function setup_env { | 127 function setup_env { |
| 128 # Validate sudo timestamp before entering the critical section so that we | 128 # Validate sudo timestamp before entering the critical section so that we |
| 129 # don't stall for a password while we have the lockfile. | 129 # don't stall for a password while we have the lockfile. |
| 130 sudo -v | 130 # Don't use sudo -v since that has issues on machines w/ no password. |
| 131 sudo echo "" > /dev/null |
| 131 | 132 |
| 132 ( | 133 ( |
| 133 flock 200 | 134 flock 200 |
| 134 echo $$ >> "$LOCKFILE" | 135 echo $$ >> "$LOCKFILE" |
| 135 | 136 |
| 136 info "Mounting chroot environment." | 137 info "Mounting chroot environment." |
| 137 | 138 |
| 138 # Mount only if not already mounted | 139 # Mount only if not already mounted |
| 139 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" | 140 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" |
| 140 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then | 141 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 warn "-- Note: outside the chroot." | 232 warn "-- Note: outside the chroot." |
| 232 fi | 233 fi |
| 233 fi | 234 fi |
| 234 | 235 |
| 235 ) 200>>"$LOCKFILE" || die "setup_env failed" | 236 ) 200>>"$LOCKFILE" || die "setup_env failed" |
| 236 } | 237 } |
| 237 | 238 |
| 238 function teardown_env { | 239 function teardown_env { |
| 239 # Validate sudo timestamp before entering the critical section so that we | 240 # Validate sudo timestamp before entering the critical section so that we |
| 240 # don't stall for a password while we have the lockfile. | 241 # don't stall for a password while we have the lockfile. |
| 241 sudo -v | 242 # Don't use sudo -v since that has issues on machines w/ no password. |
| 243 sudo echo "" > /dev/null |
| 242 | 244 |
| 243 # Only teardown if we're the last enter_chroot to die | 245 # Only teardown if we're the last enter_chroot to die |
| 244 ( | 246 ( |
| 245 flock 200 | 247 flock 200 |
| 246 | 248 |
| 247 # check each pid in $LOCKFILE to see if it's died unexpectedly | 249 # check each pid in $LOCKFILE to see if it's died unexpectedly |
| 248 TMP_LOCKFILE="$LOCKFILE.tmp" | 250 TMP_LOCKFILE="$LOCKFILE.tmp" |
| 249 | 251 |
| 250 echo -n > "$TMP_LOCKFILE" # Erase/reset temp file | 252 echo -n > "$TMP_LOCKFILE" # Erase/reset temp file |
| 251 cat "$LOCKFILE" | while read PID; do | 253 cat "$LOCKFILE" | while read PID; do |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 # Run command or interactive shell. Also include the non-chrooted path to | 354 # Run command or interactive shell. Also include the non-chrooted path to |
| 353 # the source trunk for scripts that may need to print it (e.g. | 355 # the source trunk for scripts that may need to print it (e.g. |
| 354 # build_image.sh). | 356 # build_image.sh). |
| 355 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ | 357 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ |
| 356 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ | 358 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ |
| 357 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" | 359 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" |
| 358 | 360 |
| 359 # Remove trap and explicitly unmount | 361 # Remove trap and explicitly unmount |
| 360 trap - EXIT | 362 trap - EXIT |
| 361 teardown_env | 363 teardown_env |
| OLD | NEW |