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

Side by Side Diff: enter_chroot.sh

Issue 3160024: Make enter_chroot spew logs to stderr. (Closed) Base URL: ssh://gitrw.chromium.org/crosutils.git
Patch Set: Created 10 years, 4 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 | « common.sh ('k') | 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.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 sudo chmod 0777 "$FLAGS_chroot/var/lock" 74 sudo chmod 0777 "$FLAGS_chroot/var/lock"
75 75
76 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" 76 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot"
77 77
78 function setup_env { 78 function setup_env {
79 ( 79 (
80 flock 200 80 flock 200
81 echo $$ >> "$LOCKFILE" 81 echo $$ >> "$LOCKFILE"
82 82
83 echo "Mounting chroot environment." 83 echo >&2 "Mounting chroot environment."
84 84
85 # Mount only if not already mounted 85 # Mount only if not already mounted
86 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" 86 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")"
87 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] 87 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]
88 then 88 then
89 sudo mount none -t proc "$MOUNTED_PATH" || \ 89 sudo mount none -t proc "$MOUNTED_PATH" || \
90 die "Could not mount $MOUNTED_PATH" 90 die "Could not mount $MOUNTED_PATH"
91 fi 91 fi
92 92
93 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/sys")" 93 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/sys")"
(...skipping 26 matching lines...) Expand all
120 120
121 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" 121 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")"
122 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] 122 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]
123 then 123 then
124 ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")" 124 ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")"
125 if [ -z "$CHROME_ROOT" ]; then 125 if [ -z "$CHROME_ROOT" ]; then
126 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \ 126 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \
127 2>/dev/null)" 127 2>/dev/null)"
128 fi 128 fi
129 if [[ ( -z "$CHROME_ROOT" ) || ( ! -d "${CHROME_ROOT}/src" ) ]]; then 129 if [[ ( -z "$CHROME_ROOT" ) || ( ! -d "${CHROME_ROOT}/src" ) ]]; then
130 echo "Not mounting chrome source" 130 echo >&2 "Not mounting chrome source"
131 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" 131 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}"
132 else 132 else
133 echo "Mounting chrome source at: $INNER_CHROME_ROOT" 133 echo >&2 "Mounting chrome source at: $INNER_CHROME_ROOT"
134 echo "$CHROME_ROOT" | \ 134 echo "$CHROME_ROOT" | \
135 sudo dd of="${FLAGS_chroot}${CHROME_ROOT_CONFIG}" 135 sudo dd of="${FLAGS_chroot}${CHROME_ROOT_CONFIG}"
136 mkdir -p "$MOUNTED_PATH" 136 mkdir -p "$MOUNTED_PATH"
137 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \ 137 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \
138 die "Could not mount $MOUNTED_PATH" 138 die "Could not mount $MOUNTED_PATH"
139 fi 139 fi
140 fi 140 fi
141 141
142 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")" 142 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")"
143 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] 143 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]
144 then 144 then
145 if [ $(which gclient 2>/dev/null) ]; then 145 if [ $(which gclient 2>/dev/null) ]; then
146 echo "Mounting depot_tools" 146 echo >&2 "Mounting depot_tools"
147 DEPOT_TOOLS=$(dirname $(which gclient) ) 147 DEPOT_TOOLS=$(dirname $(which gclient) )
148 mkdir -p "$MOUNTED_PATH" 148 mkdir -p "$MOUNTED_PATH"
149 if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then 149 if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then
150 echo "depot_tools failed to mount; perhaps it's on NFS?" 150 echo >&2 "depot_tools failed to mount; perhaps it's on NFS?"
151 echo "This may impact chromium build." 151 echo >&2 "This may impact chromium build."
152 fi 152 fi
153 fi 153 fi
154 fi 154 fi
155 155
156 # Install fuse module. 156 # Install fuse module.
157 if [ -c "${FUSE_DEVICE}" ] ; then 157 if [ -c "${FUSE_DEVICE}" ] ; then
158 sudo modprobe fuse 2> /dev/null ||\ 158 sudo modprobe fuse 2> /dev/null ||\
159 echo "-- Note: modprobe fuse failed. gmergefs will not work" 159 echo >&2 "-- Note: modprobe fuse failed. gmergefs will not work"
160 fi 160 fi
161 161
162 # Turn off automounting of external media when we enter the 162 # Turn off automounting of external media when we enter the
163 # chroot; thus we don't have to worry about being able to unmount 163 # chroot; thus we don't have to worry about being able to unmount
164 # from inside. 164 # from inside.
165 if [ $(which gconftool-2 2>/dev/null) ]; then 165 if [ $(which gconftool-2 2>/dev/null) ]; then
166 gconftool-2 -g ${AUTOMOUNT_PREF} > \ 166 gconftool-2 -g ${AUTOMOUNT_PREF} > \
167 "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}" 167 "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}"
168 if [ $(gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} false) ]; then 168 if [ $(gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} false) ]; then
169 echo "-- Note: USB sticks may be automounted by your host OS." 169 echo >&2 "-- Note: USB sticks may be automounted by your host OS."
170 echo "-- Note: If you plan to burn bootable media, you may need to" 170 echo >&2 "-- Note: If you plan to burn bootable media, you may need to"
171 echo "-- Note: unmount these devices manually, or run image_to_usb.sh" 171 echo >&2 "-- Note: unmount these devices manually, or run image_to_usb.s h"
172 echo "-- Note: outside the chroot." 172 echo >&2 "-- Note: outside the chroot."
173 fi 173 fi
174 fi 174 fi
175 175
176 ) 200>>"$LOCKFILE" || die "setup_env failed" 176 ) 200>>"$LOCKFILE" || die "setup_env failed"
177 } 177 }
178 178
179 function teardown_env { 179 function teardown_env {
180 # Only teardown if we're the last enter_chroot to die 180 # Only teardown if we're the last enter_chroot to die
181 ( 181 (
182 flock 200 182 flock 200
(...skipping 14 matching lines...) Expand all
197 # All good, keep going 197 # All good, keep going
198 echo "$PID" >> "$TMP_LOCKFILE" 198 echo "$PID" >> "$TMP_LOCKFILE"
199 fi 199 fi
200 done 200 done
201 # Remove any dups from lock file while installing new one 201 # Remove any dups from lock file while installing new one
202 sort -n "$TMP_LOCKFILE" | uniq > "$LOCKFILE" 202 sort -n "$TMP_LOCKFILE" | uniq > "$LOCKFILE"
203 203
204 if [ $(which gconftool-2 2>/dev/null) ]; then 204 if [ $(which gconftool-2 2>/dev/null) ]; then
205 SAVED_PREF=$(cat "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}") 205 SAVED_PREF=$(cat "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}")
206 gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \ 206 gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \
207 echo "could not re-set your automount preference." 207 echo >&2 "could not re-set your automount preference."
208 fi 208 fi
209 209
210 if [ -s "$LOCKFILE" ]; then 210 if [ -s "$LOCKFILE" ]; then
211 echo "At least one other pid is running in the chroot, so not" 211 echo >&2 "At least one other pid is running in the chroot, so not"
212 echo "tearing down env." 212 echo >&2 "tearing down env."
213 else 213 else
214 MOUNTED_PATH=$(readlink -f "$FLAGS_chroot") 214 MOUNTED_PATH=$(readlink -f "$FLAGS_chroot")
215 echo "Unmounting chroot environment." 215 echo >&2 "Unmounting chroot environment."
216 # sort the list of mounts in reverse order, to ensure umount of 216 # sort the list of mounts in reverse order, to ensure umount of
217 # cascading mounts in proper order 217 # cascading mounts in proper order
218 for i in \ 218 for i in \
219 $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do 219 $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do
220 safe_umount "$i" 220 safe_umount "$i"
221 done 221 done
222 fi 222 fi
223 ) 200>>"$LOCKFILE" || die "teardown_env failed" 223 ) 200>>"$LOCKFILE" || die "teardown_env failed"
224 } 224 }
225 225
226 if [ $FLAGS_mount -eq $FLAGS_TRUE ] 226 if [ $FLAGS_mount -eq $FLAGS_TRUE ]
227 then 227 then
228 setup_env 228 setup_env
229 echo "Make sure you run" 229 echo >&2 "Make sure you run"
230 echo " $0 --unmount" 230 echo >&2 " $0 --unmount"
231 echo "before deleting $FLAGS_chroot" 231 echo >&2 "before deleting $FLAGS_chroot"
232 echo "or you'll end up deleting $FLAGS_trunk too!" 232 echo >&2 "or you'll end up deleting $FLAGS_trunk too!"
233 exit 0 233 exit 0
234 fi 234 fi
235 235
236 if [ $FLAGS_unmount -eq $FLAGS_TRUE ] 236 if [ $FLAGS_unmount -eq $FLAGS_TRUE ]
237 then 237 then
238 teardown_env 238 teardown_env
239 exit 0 239 exit 0
240 fi 240 fi
241 241
242 # Make sure we unmount before exiting 242 # Make sure we unmount before exiting
(...skipping 19 matching lines...) Expand all
262 262
263 # 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
264 # 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.
265 # build_image.sh). 265 # build_image.sh).
266 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ 266 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \
267 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C -- "$@" 267 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C -- "$@"
268 268
269 # Remove trap and explicitly unmount 269 # Remove trap and explicitly unmount
270 trap - EXIT 270 trap - EXIT
271 teardown_env 271 teardown_env
OLDNEW
« no previous file with comments | « common.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698