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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 | 74 |
75 sudo chmod 0777 "$FLAGS_chroot/var/lock" | 75 sudo chmod 0777 "$FLAGS_chroot/var/lock" |
76 | 76 |
77 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" | 77 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" |
78 | 78 |
79 function setup_env { | 79 function setup_env { |
80 ( | 80 ( |
81 flock 200 | 81 flock 200 |
82 echo $$ >> "$LOCKFILE" | 82 echo $$ >> "$LOCKFILE" |
83 | 83 |
84 echo >&2 "Mounting chroot environment." | 84 info "Mounting chroot environment." |
85 | 85 |
86 # Mount only if not already mounted | 86 # Mount only if not already mounted |
87 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" | 87 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" |
88 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] | 88 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
89 then | 89 then |
90 sudo mount none -t proc "$MOUNTED_PATH" || \ | 90 sudo mount none -t proc "$MOUNTED_PATH" || \ |
91 die "Could not mount $MOUNTED_PATH" | 91 die "Could not mount $MOUNTED_PATH" |
92 fi | 92 fi |
93 | 93 |
94 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/sys")" | 94 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/sys")" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 | 135 |
136 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" | 136 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" |
137 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] | 137 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
138 then | 138 then |
139 ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")" | 139 ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")" |
140 if [ -z "$CHROME_ROOT" ]; then | 140 if [ -z "$CHROME_ROOT" ]; then |
141 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \ | 141 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \ |
142 2>/dev/null)" | 142 2>/dev/null)" |
143 fi | 143 fi |
144 if [[ ( -z "$CHROME_ROOT" ) || ( ! -d "${CHROME_ROOT}/src" ) ]]; then | 144 if [[ ( -z "$CHROME_ROOT" ) || ( ! -d "${CHROME_ROOT}/src" ) ]]; then |
145 echo >&2 "Not mounting chrome source" | 145 info "Not mounting chrome source" |
kliegs
2010/09/02 15:34:30
NIT: This should be switched to conditional and be
| |
146 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" | 146 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" |
147 else | 147 else |
148 echo >&2 "Mounting chrome source at: $INNER_CHROME_ROOT" | 148 info "Mounting chrome source at: $INNER_CHROME_ROOT" |
149 echo "$CHROME_ROOT" | \ | 149 echo "$CHROME_ROOT" | \ |
150 sudo dd of="${FLAGS_chroot}${CHROME_ROOT_CONFIG}" | 150 sudo dd of="${FLAGS_chroot}${CHROME_ROOT_CONFIG}" |
151 mkdir -p "$MOUNTED_PATH" | 151 mkdir -p "$MOUNTED_PATH" |
152 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \ | 152 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \ |
153 die "Could not mount $MOUNTED_PATH" | 153 die "Could not mount $MOUNTED_PATH" |
154 fi | 154 fi |
155 fi | 155 fi |
156 | 156 |
157 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")" | 157 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")" |
158 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] | 158 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
159 then | 159 then |
160 if [ $(which gclient 2>/dev/null) ]; then | 160 if [ $(which gclient 2>/dev/null) ]; then |
161 echo >&2 "Mounting depot_tools" | 161 info "Mounting depot_tools" |
162 DEPOT_TOOLS=$(dirname $(which gclient) ) | 162 DEPOT_TOOLS=$(dirname $(which gclient) ) |
163 mkdir -p "$MOUNTED_PATH" | 163 mkdir -p "$MOUNTED_PATH" |
164 if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then | 164 if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then |
165 echo >&2 "depot_tools failed to mount; perhaps it's on NFS?" | 165 warn "depot_tools failed to mount; perhaps it's on NFS?" |
166 echo >&2 "This may impact chromium build." | 166 warn "This may impact chromium build." |
167 fi | 167 fi |
168 fi | 168 fi |
169 fi | 169 fi |
170 | 170 |
171 # Install fuse module. | 171 # Install fuse module. |
172 if [ -c "${FUSE_DEVICE}" ] ; then | 172 if [ -c "${FUSE_DEVICE}" ] ; then |
173 sudo modprobe fuse 2> /dev/null ||\ | 173 sudo modprobe fuse 2> /dev/null ||\ |
174 echo >&2 "-- Note: modprobe fuse failed. gmergefs will not work" | 174 warn "-- Note: modprobe fuse failed. gmergefs will not work" |
175 fi | 175 fi |
176 | 176 |
177 # Turn off automounting of external media when we enter the | 177 # Turn off automounting of external media when we enter the |
178 # chroot; thus we don't have to worry about being able to unmount | 178 # chroot; thus we don't have to worry about being able to unmount |
179 # from inside. | 179 # from inside. |
180 if [ $(which gconftool-2 2>/dev/null) ]; then | 180 if [ $(which gconftool-2 2>/dev/null) ]; then |
181 gconftool-2 -g ${AUTOMOUNT_PREF} > \ | 181 gconftool-2 -g ${AUTOMOUNT_PREF} > \ |
182 "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}" | 182 "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}" |
183 if [ $(gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} false) ]; then | 183 if [ $(gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} false) ]; then |
184 echo >&2 "-- Note: USB sticks may be automounted by your host OS." | 184 warn "-- Note: USB sticks may be automounted by your host OS." |
185 echo >&2 "-- Note: If you plan to burn bootable media, you may need to" | 185 warn "-- Note: If you plan to burn bootable media, you may need to" |
186 echo >&2 "-- Note: unmount these devices manually, or run image_to_usb.s h" | 186 warn "-- Note: unmount these devices manually, or run image_to_usb.sh" |
187 echo >&2 "-- Note: outside the chroot." | 187 warn "-- Note: outside the chroot." |
188 fi | 188 fi |
189 fi | 189 fi |
190 | 190 |
191 ) 200>>"$LOCKFILE" || die "setup_env failed" | 191 ) 200>>"$LOCKFILE" || die "setup_env failed" |
192 } | 192 } |
193 | 193 |
194 function teardown_env { | 194 function teardown_env { |
195 # Only teardown if we're the last enter_chroot to die | 195 # Only teardown if we're the last enter_chroot to die |
196 ( | 196 ( |
197 flock 200 | 197 flock 200 |
(...skipping 14 matching lines...) Expand all Loading... | |
212 # All good, keep going | 212 # All good, keep going |
213 echo "$PID" >> "$TMP_LOCKFILE" | 213 echo "$PID" >> "$TMP_LOCKFILE" |
214 fi | 214 fi |
215 done | 215 done |
216 # Remove any dups from lock file while installing new one | 216 # Remove any dups from lock file while installing new one |
217 sort -n "$TMP_LOCKFILE" | uniq > "$LOCKFILE" | 217 sort -n "$TMP_LOCKFILE" | uniq > "$LOCKFILE" |
218 | 218 |
219 if [ $(which gconftool-2 2>/dev/null) ]; then | 219 if [ $(which gconftool-2 2>/dev/null) ]; then |
220 SAVED_PREF=$(cat "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}") | 220 SAVED_PREF=$(cat "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}") |
221 gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \ | 221 gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \ |
222 echo >&2 "could not re-set your automount preference." | 222 warn "could not re-set your automount preference." |
223 fi | 223 fi |
224 | 224 |
225 if [ -s "$LOCKFILE" ]; then | 225 if [ -s "$LOCKFILE" ]; then |
226 echo >&2 "At least one other pid is running in the chroot, so not" | 226 info "At least one other pid is running in the chroot, so not" |
227 echo >&2 "tearing down env." | 227 info "tearing down env." |
228 else | 228 else |
229 MOUNTED_PATH=$(readlink -f "$FLAGS_chroot") | 229 MOUNTED_PATH=$(readlink -f "$FLAGS_chroot") |
230 echo >&2 "Unmounting chroot environment." | 230 info "Unmounting chroot environment." |
231 # sort the list of mounts in reverse order, to ensure umount of | 231 # sort the list of mounts in reverse order, to ensure umount of |
232 # cascading mounts in proper order | 232 # cascading mounts in proper order |
233 for i in \ | 233 for i in \ |
234 $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do | 234 $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do |
235 safe_umount "$i" | 235 safe_umount "$i" |
236 done | 236 done |
237 fi | 237 fi |
238 ) 200>>"$LOCKFILE" || die "teardown_env failed" | 238 ) 200>>"$LOCKFILE" || die "teardown_env failed" |
239 } | 239 } |
240 | 240 |
241 if [ $FLAGS_mount -eq $FLAGS_TRUE ] | 241 if [ $FLAGS_mount -eq $FLAGS_TRUE ] |
242 then | 242 then |
243 setup_env | 243 setup_env |
244 echo >&2 "Make sure you run" | 244 info "Make sure you run" |
245 echo >&2 " $0 --unmount" | 245 info " $0 --unmount" |
246 echo >&2 "before deleting $FLAGS_chroot" | 246 info "before deleting $FLAGS_chroot" |
247 echo >&2 "or you'll end up deleting $FLAGS_trunk too!" | 247 info "or you'll end up deleting $FLAGS_trunk too!" |
248 exit 0 | 248 exit 0 |
249 fi | 249 fi |
250 | 250 |
251 if [ $FLAGS_unmount -eq $FLAGS_TRUE ] | 251 if [ $FLAGS_unmount -eq $FLAGS_TRUE ] |
252 then | 252 then |
253 teardown_env | 253 teardown_env |
254 exit 0 | 254 exit 0 |
255 fi | 255 fi |
256 | 256 |
257 # Make sure we unmount before exiting | 257 # Make sure we unmount before exiting |
(...skipping 11 matching lines...) Expand all Loading... | |
269 # which pass each command line into a separate call to enter_chroot | 269 # which pass each command line into a separate call to enter_chroot |
270 # so always have up-to-date info. For developer builds, there may not | 270 # so always have up-to-date info. For developer builds, there may not |
271 # be a single revision, since the developer may have | 271 # be a single revision, since the developer may have |
272 # hand-sync'd some subdirs and edited files in others. | 272 # hand-sync'd some subdirs and edited files in others. |
273 # In that case, check against origin/HEAD and mark** revision. | 273 # In that case, check against origin/HEAD and mark** revision. |
274 # Use git:8 chars of sha1 | 274 # Use git:8 chars of sha1 |
275 REVISION=$(git rev-parse --short=8 HEAD) | 275 REVISION=$(git rev-parse --short=8 HEAD) |
276 CHROOT_PASSTHRU="CHROMEOS_REVISION=$REVISION BUILDBOT_BUILD=$FLAGS_build_number CHROMEOS_OFFICIAL=$CHROMEOS_OFFICIAL" | 276 CHROOT_PASSTHRU="CHROMEOS_REVISION=$REVISION BUILDBOT_BUILD=$FLAGS_build_number CHROMEOS_OFFICIAL=$CHROMEOS_OFFICIAL" |
277 if [ -d "$HOME/.subversion" ]; then | 277 if [ -d "$HOME/.subversion" ]; then |
278 # Bind mounting .subversion into chroot | 278 # Bind mounting .subversion into chroot |
279 echo >&2 "mounting ~/.subversion into chroot" | 279 info "mounting ~/.subversion into chroot" |
280 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/home/${USER}/.subversion")" | 280 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/home/${USER}/.subversion")" |
281 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then | 281 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
282 mkdir -p "$MOUNTED_PATH" | 282 mkdir -p "$MOUNTED_PATH" |
283 sudo mount --bind "$HOME/.subversion" "$MOUNTED_PATH" || \ | 283 sudo mount --bind "$HOME/.subversion" "$MOUNTED_PATH" || \ |
284 die "Could not mount $MOUNTED_PATH" | 284 die "Could not mount $MOUNTED_PATH" |
285 fi | 285 fi |
286 fi | 286 fi |
287 | 287 |
288 # Run command or interactive shell. Also include the non-chrooted path to | 288 # Run command or interactive shell. Also include the non-chrooted path to |
289 # the source trunk for scripts that may need to print it (e.g. | 289 # the source trunk for scripts that may need to print it (e.g. |
290 # build_image.sh). | 290 # build_image.sh). |
291 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ | 291 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ |
292 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ | 292 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ |
293 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" -- "$@" | 293 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" -- "$@" |
294 | 294 |
295 # Remove trap and explicitly unmount | 295 # Remove trap and explicitly unmount |
296 trap - EXIT | 296 trap - EXIT |
297 teardown_env | 297 teardown_env |
OLD | NEW |