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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 INNER_DEPOT_TOOLS_ROOT="/home/$USER/depot_tools" # inside chroot | 100 INNER_DEPOT_TOOLS_ROOT="/home/$USER/depot_tools" # inside chroot |
101 FUSE_DEVICE="/dev/fuse" | 101 FUSE_DEVICE="/dev/fuse" |
102 AUTOMOUNT_PREF="/apps/nautilus/preferences/media_automount" | 102 AUTOMOUNT_PREF="/apps/nautilus/preferences/media_automount" |
103 SAVED_AUTOMOUNT_PREF_FILE="/tmp/.automount_pref" | 103 SAVED_AUTOMOUNT_PREF_FILE="/tmp/.automount_pref" |
104 | 104 |
105 sudo chmod 0777 "$FLAGS_chroot/var/lock" | 105 sudo chmod 0777 "$FLAGS_chroot/var/lock" |
106 | 106 |
107 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" | 107 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" |
108 | 108 |
109 function setup_env { | 109 function setup_env { |
| 110 # Validate sudo timestamp before entering the critical section so that we |
| 111 # don't stall for a password while we have the lockfile. |
| 112 sudo -v |
| 113 |
110 ( | 114 ( |
111 flock 200 | 115 flock 200 |
112 echo $$ >> "$LOCKFILE" | 116 echo $$ >> "$LOCKFILE" |
113 | 117 |
114 info "Mounting chroot environment." | 118 info "Mounting chroot environment." |
115 | 119 |
116 # Mount only if not already mounted | 120 # Mount only if not already mounted |
117 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" | 121 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" |
118 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] | 122 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
119 then | 123 then |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 warn "-- Note: If you plan to burn bootable media, you may need to" | 220 warn "-- Note: If you plan to burn bootable media, you may need to" |
217 warn "-- Note: unmount these devices manually, or run image_to_usb.sh" | 221 warn "-- Note: unmount these devices manually, or run image_to_usb.sh" |
218 warn "-- Note: outside the chroot." | 222 warn "-- Note: outside the chroot." |
219 fi | 223 fi |
220 fi | 224 fi |
221 | 225 |
222 ) 200>>"$LOCKFILE" || die "setup_env failed" | 226 ) 200>>"$LOCKFILE" || die "setup_env failed" |
223 } | 227 } |
224 | 228 |
225 function teardown_env { | 229 function teardown_env { |
| 230 # Validate sudo timestamp before entering the critical section so that we |
| 231 # don't stall for a password while we have the lockfile. |
| 232 sudo -v |
| 233 |
226 # Only teardown if we're the last enter_chroot to die | 234 # Only teardown if we're the last enter_chroot to die |
227 ( | 235 ( |
228 flock 200 | 236 flock 200 |
229 | 237 |
230 # check each pid in $LOCKFILE to see if it's died unexpectedly | 238 # check each pid in $LOCKFILE to see if it's died unexpectedly |
231 TMP_LOCKFILE="$LOCKFILE.tmp" | 239 TMP_LOCKFILE="$LOCKFILE.tmp" |
232 | 240 |
233 echo -n > "$TMP_LOCKFILE" # Erase/reset temp file | 241 echo -n > "$TMP_LOCKFILE" # Erase/reset temp file |
234 cat "$LOCKFILE" | while read PID; do | 242 cat "$LOCKFILE" | while read PID; do |
235 if [ "$PID" = "$$" ]; then | 243 if [ "$PID" = "$$" ]; then |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 # Run command or interactive shell. Also include the non-chrooted path to | 342 # Run command or interactive shell. Also include the non-chrooted path to |
335 # the source trunk for scripts that may need to print it (e.g. | 343 # the source trunk for scripts that may need to print it (e.g. |
336 # build_image.sh). | 344 # build_image.sh). |
337 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ | 345 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ |
338 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ | 346 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ |
339 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" | 347 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" |
340 | 348 |
341 # Remove trap and explicitly unmount | 349 # Remove trap and explicitly unmount |
342 trap - EXIT | 350 trap - EXIT |
343 teardown_env | 351 teardown_env |
OLD | NEW |