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 # --- BEGIN COMMON.SH BOILERPLATE --- | 9 # --- BEGIN COMMON.SH BOILERPLATE --- |
10 # Load common CrOS utilities. Inside the chroot this file is installed in | 10 # Load common CrOS utilities. Inside the chroot this file is installed in |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 If [-- command] is present, runs the command inside the chroot, | 64 If [-- command] is present, runs the command inside the chroot, |
65 after changing directory to /$USER/trunk/src/scripts. Note that neither | 65 after changing directory to /$USER/trunk/src/scripts. Note that neither |
66 the command nor args should include single quotes. For example: | 66 the command nor args should include single quotes. For example: |
67 | 67 |
68 $0 -- ./build_platform_packages.sh | 68 $0 -- ./build_platform_packages.sh |
69 | 69 |
70 Otherwise, provides an interactive shell. | 70 Otherwise, provides an interactive shell. |
71 " | 71 " |
72 | 72 |
73 # Version of info from common.sh that only echos if --verbose is set. | 73 # Version of info from common.sh that only echos if --verbose is set. |
74 function v_info { | 74 function debug { |
75 if [ $FLAGS_verbose -eq $FLAGS_TRUE ]; then | 75 if [ $FLAGS_verbose -eq $FLAGS_TRUE ]; then |
76 info "$1" | 76 info "$1" |
77 fi | 77 fi |
78 } | 78 } |
79 | 79 |
80 # Double up on the first '--' argument. Why? For enter_chroot, we want to | 80 # Double up on the first '--' argument. Why? For enter_chroot, we want to |
81 # emulate the behavior of sudo for setting environment vars. That is, we want: | 81 # emulate the behavior of sudo for setting environment vars. That is, we want: |
82 # ./enter_chroot [flags] [VAR=val] [-- command] | 82 # ./enter_chroot [flags] [VAR=val] [-- command] |
83 # ...but shflags ends up eating the '--' out of the command line and gives | 83 # ...but shflags ends up eating the '--' out of the command line and gives |
84 # us back "VAR=val" and "command" together in one chunk. By doubling up, we | 84 # us back "VAR=val" and "command" together in one chunk. By doubling up, we |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 function setup_env { | 135 function setup_env { |
136 # Validate sudo timestamp before entering the critical section so that we | 136 # Validate sudo timestamp before entering the critical section so that we |
137 # don't stall for a password while we have the lockfile. | 137 # don't stall for a password while we have the lockfile. |
138 # Don't use sudo -v since that has issues on machines w/ no password. | 138 # Don't use sudo -v since that has issues on machines w/ no password. |
139 sudo echo "" > /dev/null | 139 sudo echo "" > /dev/null |
140 | 140 |
141 ( | 141 ( |
142 flock 200 | 142 flock 200 |
143 echo $$ >> "$LOCKFILE" | 143 echo $$ >> "$LOCKFILE" |
144 | 144 |
145 v_info "Mounting chroot environment." | 145 debug "Mounting chroot environment." |
146 | 146 |
147 # Mount only if not already mounted | 147 # Mount only if not already mounted |
148 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" | 148 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" |
149 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then | 149 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
150 sudo mount none -t proc "$MOUNTED_PATH" || \ | 150 sudo mount none -t proc "$MOUNTED_PATH" || \ |
151 die "Could not mount $MOUNTED_PATH" | 151 die "Could not mount $MOUNTED_PATH" |
152 fi | 152 fi |
153 | 153 |
154 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/sys")" | 154 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/sys")" |
155 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then | 155 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 sudo mount --bind "$FLAGS_trunk" "$MOUNTED_PATH" || \ | 187 sudo mount --bind "$FLAGS_trunk" "$MOUNTED_PATH" || \ |
188 die "Could not mount $MOUNTED_PATH" | 188 die "Could not mount $MOUNTED_PATH" |
189 fi | 189 fi |
190 | 190 |
191 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" | 191 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" |
192 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then | 192 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
193 ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")" | 193 ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")" |
194 if [ -z "$CHROME_ROOT" ]; then | 194 if [ -z "$CHROME_ROOT" ]; then |
195 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \ | 195 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \ |
196 2>/dev/null)" | 196 2>/dev/null)" |
197 CHROME_ROOT_AUTO=1 | |
197 fi | 198 fi |
198 if [[ ( -z "$CHROME_ROOT" ) || ( ! -d "${CHROME_ROOT}/src" ) ]]; then | 199 if [[ ( -n "$CHROME_ROOT" ) ]]; then |
199 v_info "Not mounting chrome source" | 200 if [[ ( ! -d "${CHROME_ROOT}/src" ) ]]; then |
200 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" | 201 error "Not mounting chrome source" |
201 else | 202 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" |
202 v_info "Mounting chrome source at: $INNER_CHROME_ROOT" | 203 if [[ ! "$CHROME_ROOT_AUTO" ]]; then |
203 echo "$CHROME_ROOT" | \ | 204 exit 1 |
204 sudo dd of="${FLAGS_chroot}${CHROME_ROOT_CONFIG}" | 205 fi |
205 mkdir -p "$MOUNTED_PATH" | 206 else |
206 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \ | 207 debug "Mounting chrome source at: $INNER_CHROME_ROOT" |
207 die "Could not mount $MOUNTED_PATH" | 208 sudo bash -c "echo '$CHROME_ROOT' > \ |
209 '${FLAGS_chroot}${CHROME_ROOT_CONFIG}'" | |
210 mkdir -p "$MOUNTED_PATH" | |
211 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \ | |
212 die "Could not mount $MOUNTED_PATH" | |
213 fi | |
208 fi | 214 fi |
209 fi | 215 fi |
210 | 216 |
211 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")" | 217 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")" |
212 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then | 218 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
213 if [ $(which gclient 2>/dev/null) ]; then | 219 if [ $(which gclient 2>/dev/null) ]; then |
214 v_info "Mounting depot_tools" | 220 debug "Mounting depot_tools" |
215 DEPOT_TOOLS=$(dirname "$(which gclient)") | 221 DEPOT_TOOLS=$(dirname "$(which gclient)") |
216 mkdir -p "$MOUNTED_PATH" | 222 mkdir -p "$MOUNTED_PATH" |
217 if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then | 223 if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then |
218 warn "depot_tools failed to mount; perhaps it's on NFS?" | 224 warn "depot_tools failed to mount; perhaps it's on NFS?" |
219 warn "This may impact chromium build." | 225 warn "This may impact chromium build." |
220 fi | 226 fi |
221 fi | 227 fi |
222 fi | 228 fi |
223 | 229 |
224 # Install fuse module. | 230 # Install fuse module. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 # Remove any dups from lock file while installing new one | 280 # Remove any dups from lock file while installing new one |
275 sort -n "$TMP_LOCKFILE" | uniq > "$LOCKFILE" | 281 sort -n "$TMP_LOCKFILE" | uniq > "$LOCKFILE" |
276 | 282 |
277 if [ $(which gconftool-2 2>/dev/null) ]; then | 283 if [ $(which gconftool-2 2>/dev/null) ]; then |
278 SAVED_PREF=$(cat "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}") | 284 SAVED_PREF=$(cat "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}") |
279 gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \ | 285 gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \ |
280 warn "could not re-set your automount preference." | 286 warn "could not re-set your automount preference." |
281 fi | 287 fi |
282 | 288 |
283 if [ -s "$LOCKFILE" ]; then | 289 if [ -s "$LOCKFILE" ]; then |
284 v_info "At least one other pid is running in the chroot, so not" | 290 debug "At least one other pid is running in the chroot, so not" |
285 v_info "tearing down env." | 291 debug "tearing down env." |
kliegs
2011/02/08 15:48:03
I'd still like to see this remain a warning. Whil
| |
286 else | 292 else |
287 MOUNTED_PATH=$(readlink -f "$FLAGS_chroot") | 293 MOUNTED_PATH=$(readlink -f "$FLAGS_chroot") |
288 v_info "Unmounting chroot environment." | 294 debug "Unmounting chroot environment." |
289 # sort the list of mounts in reverse order, to ensure umount of | 295 # sort the list of mounts in reverse order, to ensure umount of |
290 # cascading mounts in proper order | 296 # cascading mounts in proper order |
291 for i in \ | 297 for i in \ |
292 $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do | 298 $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do |
293 safe_umount "$i" | 299 safe_umount "$i" |
294 done | 300 done |
295 fi | 301 fi |
296 ) 200>>"$LOCKFILE" || die "teardown_env failed" | 302 ) 200>>"$LOCKFILE" || die "teardown_env failed" |
297 } | 303 } |
298 | 304 |
299 if [ $FLAGS_mount -eq $FLAGS_TRUE ]; then | 305 if [ $FLAGS_mount -eq $FLAGS_TRUE ]; then |
300 setup_env | 306 setup_env |
301 v_info "Make sure you run" | 307 info "Make sure you run" |
302 v_info " $0 --unmount" | 308 info " $0 --unmount" |
303 v_info "before deleting $FLAGS_chroot" | 309 info "before deleting $FLAGS_chroot" |
304 v_info "or you'll end up deleting $FLAGS_trunk too!" | 310 info "or you'll end up deleting $FLAGS_trunk too!" |
305 exit 0 | 311 exit 0 |
306 fi | 312 fi |
307 | 313 |
308 if [ $FLAGS_unmount -eq $FLAGS_TRUE ]; then | 314 if [ $FLAGS_unmount -eq $FLAGS_TRUE ]; then |
309 teardown_env | 315 teardown_env |
310 exit 0 | 316 exit 0 |
311 fi | 317 fi |
312 | 318 |
313 # Apply any hacks needed to update the chroot. | 319 # Apply any hacks needed to update the chroot. |
314 chroot_hacks_from_outside "${FLAGS_chroot}" | 320 chroot_hacks_from_outside "${FLAGS_chroot}" |
(...skipping 19 matching lines...) Expand all Loading... | |
334 # Use git:8 chars of sha1 | 340 # Use git:8 chars of sha1 |
335 REVISION=$(cd ${FLAGS_trunk}/src/scripts ; git rev-parse --short=8 HEAD) | 341 REVISION=$(cd ${FLAGS_trunk}/src/scripts ; git rev-parse --short=8 HEAD) |
336 CHROOT_PASSTHRU="CHROMEOS_REVISION=$REVISION BUILDBOT_BUILD=$FLAGS_build_number CHROMEOS_OFFICIAL=$CHROMEOS_OFFICIAL" | 342 CHROOT_PASSTHRU="CHROMEOS_REVISION=$REVISION BUILDBOT_BUILD=$FLAGS_build_number CHROMEOS_OFFICIAL=$CHROMEOS_OFFICIAL" |
337 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ | 343 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ |
338 CHROMEOS_RELEASE_APPID=${CHROMEOS_RELEASE_APPID:-"{DEV-BUILD}"}" | 344 CHROMEOS_RELEASE_APPID=${CHROMEOS_RELEASE_APPID:-"{DEV-BUILD}"}" |
339 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ | 345 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ |
340 CHROMEOS_VERSION_TRACK=$CHROMEOS_VERSION_TRACK CHROMEOS_VERSION_AUSERVER=$CHROME OS_VERSION_AUSERVER CHROMEOS_VERSION_DEVSERVER=$CHROMEOS_VERSION_DEVSERVER" | 346 CHROMEOS_VERSION_TRACK=$CHROMEOS_VERSION_TRACK CHROMEOS_VERSION_AUSERVER=$CHROME OS_VERSION_AUSERVER CHROMEOS_VERSION_DEVSERVER=$CHROMEOS_VERSION_DEVSERVER" |
341 | 347 |
342 if [ -d "$HOME/.subversion" ]; then | 348 if [ -d "$HOME/.subversion" ]; then |
343 # Bind mounting .subversion into chroot | 349 # Bind mounting .subversion into chroot |
344 v_info "mounting ~/.subversion into chroot" | 350 debug "mounting ~/.subversion into chroot" |
345 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/home/${USER}/.subversion")" | 351 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/home/${USER}/.subversion")" |
346 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then | 352 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
347 mkdir -p "$MOUNTED_PATH" | 353 mkdir -p "$MOUNTED_PATH" |
348 sudo mount --bind "$HOME/.subversion" "$MOUNTED_PATH" || \ | 354 sudo mount --bind "$HOME/.subversion" "$MOUNTED_PATH" || \ |
349 die "Could not mount $MOUNTED_PATH" | 355 die "Could not mount $MOUNTED_PATH" |
350 fi | 356 fi |
351 fi | 357 fi |
352 | 358 |
353 # Configure committer username and email in chroot .gitconfig | 359 # Configure committer username and email in chroot .gitconfig |
354 if [ $FLAGS_git_config -eq $FLAGS_TRUE ]; then | 360 if [ $FLAGS_git_config -eq $FLAGS_TRUE ]; then |
355 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ | 361 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ |
356 user.name "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/ *<.*//')" | 362 user.name "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/ *<.*//')" |
357 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ | 363 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ |
358 user.email "$(cd /tmp; git var GIT_COMMITTER_IDENT | \ | 364 user.email "$(cd /tmp; git var GIT_COMMITTER_IDENT | \ |
359 sed -e 's/.*<\([^>]*\)>.*/\1/')" | 365 sed -e 's/.*<\([^>]*\)>.*/\1/')" |
360 fi | 366 fi |
361 | 367 |
362 # Run command or interactive shell. Also include the non-chrooted path to | 368 # Run command or interactive shell. Also include the non-chrooted path to |
363 # the source trunk for scripts that may need to print it (e.g. | 369 # the source trunk for scripts that may need to print it (e.g. |
364 # build_image.sh). | 370 # build_image.sh). |
365 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ | 371 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ |
366 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ | 372 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ |
367 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" | 373 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" |
368 | 374 |
369 # Remove trap and explicitly unmount | 375 # Remove trap and explicitly unmount |
370 trap - EXIT | 376 trap - EXIT |
371 teardown_env | 377 teardown_env |
OLD | NEW |