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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 die "Could not mount $MOUNTED_PATH" | 97 die "Could not mount $MOUNTED_PATH" |
98 fi | 98 fi |
99 | 99 |
100 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev")" | 100 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev")" |
101 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] | 101 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
102 then | 102 then |
103 sudo mount --bind /dev "$MOUNTED_PATH" || \ | 103 sudo mount --bind /dev "$MOUNTED_PATH" || \ |
104 die "Could not mount $MOUNTED_PATH" | 104 die "Could not mount $MOUNTED_PATH" |
105 fi | 105 fi |
106 | 106 |
| 107 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev/pts")" |
| 108 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
| 109 then |
| 110 sudo mount none -t devpts "$MOUNTED_PATH" || \ |
| 111 die "Could not mount $MOUNTED_PATH" |
| 112 fi |
| 113 |
107 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}$CHROOT_TRUNK_DIR")" | 114 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}$CHROOT_TRUNK_DIR")" |
108 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] | 115 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
109 then | 116 then |
110 sudo mount --bind "$FLAGS_trunk" "$MOUNTED_PATH" || \ | 117 sudo mount --bind "$FLAGS_trunk" "$MOUNTED_PATH" || \ |
111 die "Could not mount $MOUNTED_PATH" | 118 die "Could not mount $MOUNTED_PATH" |
112 fi | 119 fi |
113 | 120 |
114 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" | 121 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" |
115 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] | 122 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
116 then | 123 then |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \ | 206 gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \ |
200 echo "could not re-set your automount preference." | 207 echo "could not re-set your automount preference." |
201 fi | 208 fi |
202 | 209 |
203 if [ -s "$LOCKFILE" ]; then | 210 if [ -s "$LOCKFILE" ]; then |
204 echo "At least one other pid is running in the chroot, so not" | 211 echo "At least one other pid is running in the chroot, so not" |
205 echo "tearing down env." | 212 echo "tearing down env." |
206 else | 213 else |
207 MOUNTED_PATH=$(readlink -f "$FLAGS_chroot") | 214 MOUNTED_PATH=$(readlink -f "$FLAGS_chroot") |
208 echo "Unmounting chroot environment." | 215 echo "Unmounting chroot environment." |
209 for i in $(mount | grep -F "on $MOUNTED_PATH/" | awk '{print $3}'); do | 216 # sort the list of mounts in reverse order, to ensure umount of |
| 217 # cascading mounts in proper order |
| 218 for i in \ |
| 219 $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do |
210 safe_umount "$i" | 220 safe_umount "$i" |
211 done | 221 done |
212 fi | 222 fi |
213 ) 200>>"$LOCKFILE" || die "teardown_env failed" | 223 ) 200>>"$LOCKFILE" || die "teardown_env failed" |
214 } | 224 } |
215 | 225 |
216 if [ $FLAGS_mount -eq $FLAGS_TRUE ] | 226 if [ $FLAGS_mount -eq $FLAGS_TRUE ] |
217 then | 227 then |
218 setup_env | 228 setup_env |
219 echo "Make sure you run" | 229 echo "Make sure you run" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 262 |
253 # Run command or interactive shell. Also include the non-chrooted path to | 263 # Run command or interactive shell. Also include the non-chrooted path to |
254 # the source trunk for scripts that may need to print it (e.g. | 264 # the source trunk for scripts that may need to print it (e.g. |
255 # build_image.sh). | 265 # build_image.sh). |
256 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ | 266 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ |
257 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C "$@" | 267 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C "$@" |
258 | 268 |
259 # Remove trap and explicitly unmount | 269 # Remove trap and explicitly unmount |
260 trap - EXIT | 270 trap - EXIT |
261 teardown_env | 271 teardown_env |
OLD | NEW |