Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: src/scripts/enter_chroot.sh

Issue 2029009: disable automounting when inside the chroot (Closed) Base URL: ssh://git@chromiumos-git//chromeos
Patch Set: add check for existence of gconftool-2 Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "" \ 25 DEFINE_string chrome_root "" \
26 "The root of your chrome browser source. Should contain a 'src' subdir." 26 "The root of your chrome browser source. Should contain a 'src' subdir."
27 DEFINE_string automount_dir "/media" \
28 "The directory in which your host OS creates mountpoints for external media."
29 27
30 DEFINE_boolean official_build $FLAGS_FALSE \ 28 DEFINE_boolean official_build $FLAGS_FALSE \
31 "Set CHROMEOS_OFFICIAL=1 for release builds." 29 "Set CHROMEOS_OFFICIAL=1 for release builds."
32 DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts." 30 DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts."
33 DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts." 31 DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts."
34 32
35 # More useful help 33 # More useful help
36 FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- \"command\"] 34 FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- \"command\"]
37 35
38 One or more VAR=value pairs can be specified to export variables into 36 One or more VAR=value pairs can be specified to export variables into
(...skipping 22 matching lines...) Expand all
61 59
62 # Only now can we die on error. shflags functions leak non-zero error codes, 60 # Only now can we die on error. shflags functions leak non-zero error codes,
63 # so will die prematurely if 'set -e' is specified before now. 61 # so will die prematurely if 'set -e' is specified before now.
64 # TODO: replace shflags with something less error-prone, or contribute a fix. 62 # TODO: replace shflags with something less error-prone, or contribute a fix.
65 set -e 63 set -e
66 64
67 INNER_CHROME_ROOT="/home/$USER/chrome_root" # inside chroot 65 INNER_CHROME_ROOT="/home/$USER/chrome_root" # inside chroot
68 CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot 66 CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot
69 INNER_DEPOT_TOOLS_ROOT="/home/$USER/depot_tools" # inside chroot 67 INNER_DEPOT_TOOLS_ROOT="/home/$USER/depot_tools" # inside chroot
70 FUSE_DEVICE="/dev/fuse" 68 FUSE_DEVICE="/dev/fuse"
69 AUTOMOUNT_PREF="/apps/nautilus/preferences/media_automount"
70 SAVED_AUTOMOUNT_PREF_FILE="/tmp/.automount_pref"
71 71
72 sudo chmod 0777 "$FLAGS_chroot/var/lock" 72 sudo chmod 0777 "$FLAGS_chroot/var/lock"
73 73
74 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" 74 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot"
75 75
76 function setup_env { 76 function setup_env {
77 ( 77 (
78 flock 200 78 flock 200
79 echo $$ >> "$LOCKFILE" 79 echo $$ >> "$LOCKFILE"
80 80
(...skipping 14 matching lines...) Expand all
95 die "Could not mount $MOUNTED_PATH" 95 die "Could not mount $MOUNTED_PATH"
96 fi 96 fi
97 97
98 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev")" 98 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev")"
99 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] 99 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]
100 then 100 then
101 sudo mount --bind /dev "$MOUNTED_PATH" || \ 101 sudo mount --bind /dev "$MOUNTED_PATH" || \
102 die "Could not mount $MOUNTED_PATH" 102 die "Could not mount $MOUNTED_PATH"
103 fi 103 fi
104 104
105 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${FLAGS_automount_dir}")"
106 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]
107 then
108 sudo mount --bind "${FLAGS_automount_dir}" "$MOUNTED_PATH" || \
109 die "Could not mount $MOUNTED_PATH"
110 fi
111
112 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}$CHROOT_TRUNK_DIR")" 105 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}$CHROOT_TRUNK_DIR")"
113 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] 106 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]
114 then 107 then
115 sudo mount --bind "$FLAGS_trunk" "$MOUNTED_PATH" || \ 108 sudo mount --bind "$FLAGS_trunk" "$MOUNTED_PATH" || \
116 die "Could not mount $MOUNTED_PATH" 109 die "Could not mount $MOUNTED_PATH"
117 fi 110 fi
118 111
119 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" 112 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")"
120 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] 113 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]
121 then 114 then
(...skipping 28 matching lines...) Expand all
150 fi 143 fi
151 fi 144 fi
152 fi 145 fi
153 146
154 # Install fuse module. 147 # Install fuse module.
155 if [ -c "${FUSE_DEVICE}" ] ; then 148 if [ -c "${FUSE_DEVICE}" ] ; then
156 sudo modprobe fuse 2> /dev/null ||\ 149 sudo modprobe fuse 2> /dev/null ||\
157 echo "-- Note: modprobe fuse failed. gmergefs will not work" 150 echo "-- Note: modprobe fuse failed. gmergefs will not work"
158 fi 151 fi
159 152
153 # Turn off automounting of external media when we enter the
154 # chroot; thus we don't have to worry about being able to unmount
155 # from inside.
156 if [ $(which gconftool-2 2>/dev/null) ]; then
157 gconftool-2 -g ${AUTOMOUNT_PREF} > \
158 "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}"
159 if [ $(gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} false) ]; then
160 echo "-- Note: USB sticks may be automounted by your host OS."
161 echo "-- Note: If you plan to burn bootable media, you may need to"
162 echo "-- Note: unmount these devices manually, or run image_to_usb.sh"
163 echo "-- Note: outside the chroot."
164 fi
165 fi
166
160 ) 200>>"$LOCKFILE" || die "setup_env failed" 167 ) 200>>"$LOCKFILE" || die "setup_env failed"
161 } 168 }
162 169
163 function teardown_env { 170 function teardown_env {
164 # Only teardown if we're the last enter_chroot to die 171 # Only teardown if we're the last enter_chroot to die
165 ( 172 (
166 flock 200 173 flock 200
167 174
168 # check each pid in $LOCKFILE to see if it's died unexpectedly 175 # check each pid in $LOCKFILE to see if it's died unexpectedly
169 TMP_LOCKFILE="$LOCKFILE.tmp" 176 TMP_LOCKFILE="$LOCKFILE.tmp"
170 177
171 echo -n > "$TMP_LOCKFILE" # Erase/reset temp file 178 echo -n > "$TMP_LOCKFILE" # Erase/reset temp file
172 cat "$LOCKFILE" | while read PID; do 179 cat "$LOCKFILE" | while read PID; do
173 if [ "$PID" = "$$" ]; then 180 if [ "$PID" = "$$" ]; then
174 # ourself, leave PROC_NAME empty 181 # ourself, leave PROC_NAME empty
175 PROC_NAME="" 182 PROC_NAME=""
176 else 183 else
177 PROC_NAME=$(ps --pid $PID -o comm=) 184 PROC_NAME=$(ps --pid $PID -o comm=)
178 fi 185 fi
179 186
180 if [ ! -z "$PROC_NAME" ]; then 187 if [ ! -z "$PROC_NAME" ]; then
181 # All good, keep going 188 # All good, keep going
182 echo "$PID" >> "$TMP_LOCKFILE" 189 echo "$PID" >> "$TMP_LOCKFILE"
183 fi 190 fi
184 done 191 done
185 # Remove any dups from lock file while installing new one 192 # Remove any dups from lock file while installing new one
186 sort -n "$TMP_LOCKFILE" | uniq > "$LOCKFILE" 193 sort -n "$TMP_LOCKFILE" | uniq > "$LOCKFILE"
187 194
195 if [ $(which gconftool-2 2>/dev/null) ]; then
196 SAVED_PREF=$(cat "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}")
197 gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \
198 echo "could not re-set your automount preference."
199 fi
200
188 if [ -s "$LOCKFILE" ]; then 201 if [ -s "$LOCKFILE" ]; then
189 echo "At least one other pid is running in the chroot, so not" 202 echo "At least one other pid is running in the chroot, so not"
190 echo "tearing down env." 203 echo "tearing down env."
191 else 204 else
192 MOUNTED_PATH=$(readlink -f "$FLAGS_chroot") 205 MOUNTED_PATH=$(readlink -f "$FLAGS_chroot")
193 echo "Unmounting chroot environment." 206 echo "Unmounting chroot environment."
194 for i in $(mount | grep -F "on $MOUNTED_PATH/" | awk '{print $3}'); do 207 for i in $(mount | grep -F "on $MOUNTED_PATH/" | awk '{print $3}'); do
195 safe_umount "$i" 208 safe_umount "$i"
196 done 209 done
197 fi 210 fi
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 261
249 # Run command or interactive shell. Also include the non-chrooted path to 262 # Run command or interactive shell. Also include the non-chrooted path to
250 # the source trunk for scripts that may need to print it (e.g. 263 # the source trunk for scripts that may need to print it (e.g.
251 # build_image.sh). 264 # build_image.sh).
252 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ 265 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \
253 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C "$@" 266 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C "$@"
254 267
255 # Remove trap and explicitly unmount 268 # Remove trap and explicitly unmount
256 trap - EXIT 269 trap - EXIT
257 teardown_env 270 teardown_env
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698