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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 fi | 197 fi |
198 if [[ ( -z "$CHROME_ROOT" ) || ( ! -d "${CHROME_ROOT}/src" ) ]]; then | 198 if [[ ( -z "$CHROME_ROOT" ) || ( ! -d "${CHROME_ROOT}/src" ) ]]; then |
diandersAtChromium
2011/02/07 22:29:18
Should probably split into two cases. The "-z" ca
| |
199 v_info "Not mounting chrome source" | 199 debug "Not mounting chrome source" |
200 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" | 200 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" |
201 else | 201 else |
202 v_info "Mounting chrome source at: $INNER_CHROME_ROOT" | 202 debug "Mounting chrome source at: $INNER_CHROME_ROOT" |
203 echo "$CHROME_ROOT" | \ | 203 echo "$CHROME_ROOT" | \ |
204 sudo dd of="${FLAGS_chroot}${CHROME_ROOT_CONFIG}" | 204 sudo dd of="${FLAGS_chroot}${CHROME_ROOT_CONFIG}" |
205 mkdir -p "$MOUNTED_PATH" | 205 mkdir -p "$MOUNTED_PATH" |
206 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \ | 206 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \ |
207 die "Could not mount $MOUNTED_PATH" | 207 die "Could not mount $MOUNTED_PATH" |
208 fi | 208 fi |
209 fi | 209 fi |
210 | 210 |
211 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")" | 211 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")" |
212 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then | 212 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
213 if [ $(which gclient 2>/dev/null) ]; then | 213 if [ $(which gclient 2>/dev/null) ]; then |
214 v_info "Mounting depot_tools" | 214 debug "Mounting depot_tools" |
215 DEPOT_TOOLS=$(dirname "$(which gclient)") | 215 DEPOT_TOOLS=$(dirname "$(which gclient)") |
216 mkdir -p "$MOUNTED_PATH" | 216 mkdir -p "$MOUNTED_PATH" |
217 if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then | 217 if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then |
218 warn "depot_tools failed to mount; perhaps it's on NFS?" | 218 warn "depot_tools failed to mount; perhaps it's on NFS?" |
219 warn "This may impact chromium build." | 219 warn "This may impact chromium build." |
220 fi | 220 fi |
221 fi | 221 fi |
222 fi | 222 fi |
223 | 223 |
224 # Install fuse module. | 224 # 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 | 274 # Remove any dups from lock file while installing new one |
275 sort -n "$TMP_LOCKFILE" | uniq > "$LOCKFILE" | 275 sort -n "$TMP_LOCKFILE" | uniq > "$LOCKFILE" |
276 | 276 |
277 if [ $(which gconftool-2 2>/dev/null) ]; then | 277 if [ $(which gconftool-2 2>/dev/null) ]; then |
278 SAVED_PREF=$(cat "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}") | 278 SAVED_PREF=$(cat "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}") |
279 gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \ | 279 gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \ |
280 warn "could not re-set your automount preference." | 280 warn "could not re-set your automount preference." |
281 fi | 281 fi |
282 | 282 |
283 if [ -s "$LOCKFILE" ]; then | 283 if [ -s "$LOCKFILE" ]; then |
284 v_info "At least one other pid is running in the chroot, so not" | 284 debug "At least one other pid is running in the chroot, so not" |
285 v_info "tearing down env." | 285 debug "tearing down env." |
286 else | 286 else |
287 MOUNTED_PATH=$(readlink -f "$FLAGS_chroot") | 287 MOUNTED_PATH=$(readlink -f "$FLAGS_chroot") |
288 v_info "Unmounting chroot environment." | 288 debug "Unmounting chroot environment." |
289 # sort the list of mounts in reverse order, to ensure umount of | 289 # sort the list of mounts in reverse order, to ensure umount of |
290 # cascading mounts in proper order | 290 # cascading mounts in proper order |
291 for i in \ | 291 for i in \ |
292 $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do | 292 $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do |
293 safe_umount "$i" | 293 safe_umount "$i" |
294 done | 294 done |
295 fi | 295 fi |
296 ) 200>>"$LOCKFILE" || die "teardown_env failed" | 296 ) 200>>"$LOCKFILE" || die "teardown_env failed" |
297 } | 297 } |
298 | 298 |
299 if [ $FLAGS_mount -eq $FLAGS_TRUE ]; then | 299 if [ $FLAGS_mount -eq $FLAGS_TRUE ]; then |
300 setup_env | 300 setup_env |
301 v_info "Make sure you run" | 301 info "Make sure you run" |
302 v_info " $0 --unmount" | 302 info " $0 --unmount" |
303 v_info "before deleting $FLAGS_chroot" | 303 info "before deleting $FLAGS_chroot" |
304 v_info "or you'll end up deleting $FLAGS_trunk too!" | 304 info "or you'll end up deleting $FLAGS_trunk too!" |
305 exit 0 | 305 exit 0 |
306 fi | 306 fi |
307 | 307 |
308 if [ $FLAGS_unmount -eq $FLAGS_TRUE ]; then | 308 if [ $FLAGS_unmount -eq $FLAGS_TRUE ]; then |
309 teardown_env | 309 teardown_env |
310 exit 0 | 310 exit 0 |
311 fi | 311 fi |
312 | 312 |
313 # Apply any hacks needed to update the chroot. | 313 # Apply any hacks needed to update the chroot. |
314 chroot_hacks_from_outside "${FLAGS_chroot}" | 314 chroot_hacks_from_outside "${FLAGS_chroot}" |
(...skipping 19 matching lines...) Expand all Loading... | |
334 # Use git:8 chars of sha1 | 334 # Use git:8 chars of sha1 |
335 REVISION=$(cd ${FLAGS_trunk}/src/scripts ; git rev-parse --short=8 HEAD) | 335 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" | 336 CHROOT_PASSTHRU="CHROMEOS_REVISION=$REVISION BUILDBOT_BUILD=$FLAGS_build_number CHROMEOS_OFFICIAL=$CHROMEOS_OFFICIAL" |
337 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ | 337 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ |
338 CHROMEOS_RELEASE_APPID=${CHROMEOS_RELEASE_APPID:-"{DEV-BUILD}"}" | 338 CHROMEOS_RELEASE_APPID=${CHROMEOS_RELEASE_APPID:-"{DEV-BUILD}"}" |
339 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ | 339 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ |
340 CHROMEOS_VERSION_TRACK=$CHROMEOS_VERSION_TRACK CHROMEOS_VERSION_AUSERVER=$CHROME OS_VERSION_AUSERVER CHROMEOS_VERSION_DEVSERVER=$CHROMEOS_VERSION_DEVSERVER" | 340 CHROMEOS_VERSION_TRACK=$CHROMEOS_VERSION_TRACK CHROMEOS_VERSION_AUSERVER=$CHROME OS_VERSION_AUSERVER CHROMEOS_VERSION_DEVSERVER=$CHROMEOS_VERSION_DEVSERVER" |
341 | 341 |
342 if [ -d "$HOME/.subversion" ]; then | 342 if [ -d "$HOME/.subversion" ]; then |
343 # Bind mounting .subversion into chroot | 343 # Bind mounting .subversion into chroot |
344 v_info "mounting ~/.subversion into chroot" | 344 debug "mounting ~/.subversion into chroot" |
345 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/home/${USER}/.subversion")" | 345 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/home/${USER}/.subversion")" |
346 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then | 346 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
347 mkdir -p "$MOUNTED_PATH" | 347 mkdir -p "$MOUNTED_PATH" |
348 sudo mount --bind "$HOME/.subversion" "$MOUNTED_PATH" || \ | 348 sudo mount --bind "$HOME/.subversion" "$MOUNTED_PATH" || \ |
349 die "Could not mount $MOUNTED_PATH" | 349 die "Could not mount $MOUNTED_PATH" |
350 fi | 350 fi |
351 fi | 351 fi |
352 | 352 |
353 # Configure committer username and email in chroot .gitconfig | 353 # Configure committer username and email in chroot .gitconfig |
354 if [ $FLAGS_git_config -eq $FLAGS_TRUE ]; then | 354 if [ $FLAGS_git_config -eq $FLAGS_TRUE ]; then |
355 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ | 355 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ |
356 user.name "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/ *<.*//')" | 356 user.name "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/ *<.*//')" |
357 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ | 357 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ |
358 user.email "$(cd /tmp; git var GIT_COMMITTER_IDENT | \ | 358 user.email "$(cd /tmp; git var GIT_COMMITTER_IDENT | \ |
359 sed -e 's/.*<\([^>]*\)>.*/\1/')" | 359 sed -e 's/.*<\([^>]*\)>.*/\1/')" |
360 fi | 360 fi |
361 | 361 |
362 # Run command or interactive shell. Also include the non-chrooted path to | 362 # 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. | 363 # the source trunk for scripts that may need to print it (e.g. |
364 # build_image.sh). | 364 # build_image.sh). |
365 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ | 365 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ |
366 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ | 366 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ |
367 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" | 367 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" |
368 | 368 |
369 # Remove trap and explicitly unmount | 369 # Remove trap and explicitly unmount |
370 trap - EXIT | 370 trap - EXIT |
371 teardown_env | 371 teardown_env |
OLD | NEW |