blob: 669cdacb78fbe81d4fc0a47ea3b67cadd4e2cdb7 [file] [log] [blame]
rspangler@google.comd74220d2009-10-09 20:56:14 +00001#!/bin/bash
2
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
5# found in the LICENSE file.
6
7# Script to enter the chroot environment
8
Greg Spencer798d75f2011-02-01 22:04:49 -08009# --- BEGIN COMMON.SH BOILERPLATE ---
10# Load common CrOS utilities. Inside the chroot this file is installed in
11# /usr/lib/crosutils. Outside the chroot we find it relative to the script's
12# location.
13find_common_sh() {
14 local common_paths=(/usr/lib/crosutils $(dirname "$(readlink -f "$0")"))
15 local path
16
17 SCRIPT_ROOT=
18 for path in "${common_paths[@]}"; do
19 if [ -r "${path}/common.sh" ]; then
20 SCRIPT_ROOT=${path}
21 break
22 fi
23 done
24}
25
26find_common_sh
27. "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1)
28# --- END COMMON.SH BOILERPLATE ---
rspangler@google.comd74220d2009-10-09 20:56:14 +000029
derat@google.com86dcc8e2009-11-21 19:49:49 +000030# Script must be run outside the chroot and as a regular user.
rspangler@google.comd74220d2009-10-09 20:56:14 +000031assert_outside_chroot
derat@google.com86dcc8e2009-11-21 19:49:49 +000032assert_not_root_user
rspangler@google.comd74220d2009-10-09 20:56:14 +000033
34# Define command line flags
35# See http://code.google.com/p/shflags/wiki/Documentation10x
36DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \
37 "The destination dir for the chroot environment." "d"
38DEFINE_string trunk "$GCLIENT_ROOT" \
39 "The source trunk to bind mount within the chroot." "s"
David McMahon03aeb202009-12-08 12:47:08 -080040DEFINE_string build_number "" \
41 "The build-bot build number (when called by buildbot only)." "b"
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -080042DEFINE_string chrome_root "" \
43 "The root of your chrome browser source. Should contain a 'src' subdir."
Sean Parent2898f752010-05-25 15:06:33 -070044DEFINE_string chrome_root_mount "/home/$USER/chrome_root" \
45 "The mount point of the chrome broswer source in the chroot."
rspangler@google.comd74220d2009-10-09 20:56:14 +000046
Chris Sosa558940d2011-02-01 13:07:55 -080047DEFINE_boolean git_config $FLAGS_TRUE \
48 "Config git to work with your user/pass in the chroot."
Chris Sosaaa1a7fd2010-04-02 14:06:29 -070049DEFINE_boolean official_build $FLAGS_FALSE \
50 "Set CHROMEOS_OFFICIAL=1 for release builds."
rspangler@google.comd74220d2009-10-09 20:56:14 +000051DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts."
52DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts."
Elly Jones7990a062010-09-02 09:23:23 -040053DEFINE_boolean ssh_agent $FLAGS_TRUE "Import ssh agent."
rspangler@google.comd74220d2009-10-09 20:56:14 +000054
55# More useful help
Doug Anderson9362fa82010-12-16 14:44:12 -080056FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- command [arg1] [arg2] ...]
rspangler@google.comd74220d2009-10-09 20:56:14 +000057
58One or more VAR=value pairs can be specified to export variables into
59the chroot environment. For example:
60
61 $0 FOO=bar BAZ=bel
62
Doug Anderson9362fa82010-12-16 14:44:12 -080063If [-- command] is present, runs the command inside the chroot,
64after changing directory to /$USER/trunk/src/scripts. Note that neither
65the command nor args should include single quotes. For example:
rspangler@google.comd74220d2009-10-09 20:56:14 +000066
Doug Anderson9362fa82010-12-16 14:44:12 -080067 $0 -- ./build_platform_packages.sh
rspangler@google.comd74220d2009-10-09 20:56:14 +000068
69Otherwise, provides an interactive shell.
70"
71
Doug Anderson9362fa82010-12-16 14:44:12 -080072# Double up on the first '--' argument. Why? For enter_chroot, we want to
73# emulate the behavior of sudo for setting environment vars. That is, we want:
74# ./enter_chroot [flags] [VAR=val] [-- command]
75# ...but shflags ends up eating the '--' out of the command line and gives
76# us back "VAR=val" and "command" together in one chunk. By doubling up, we
77# end up getting what we want back from shflags.
78#
79# Examples of how people might be using enter_chroot:
80# 1. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2 -- cmd arg1 arg2
81# Set env vars and run cmd w/ args
82# 2. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2
83# Set env vars and run shell
84# 3. ./enter_chroot [chroot_flags] -- cmd arg1 arg2
85# Run cmd w/ args
86# 4. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2 cmd arg1 arg2
87# Like #1 _if_ args aren't flags (if they are, enter_chroot will claim them)
88# 5. ./enter_chroot [chroot_flags] cmd arg1 arg2
89# Like #3 _if_ args aren't flags (if they are, enter_chroot will claim them)
90_FLAGS_FIXED=''
91_SAW_DASHDASH=0
92while [ $# -gt 0 ]; do
93 _FLAGS_FIXED="${_FLAGS_FIXED:+${_FLAGS_FIXED} }'$1'"
94 if [ $_SAW_DASHDASH -eq 0 ] && [[ "$1" == "--" ]]; then
95 _FLAGS_FIXED="${_FLAGS_FIXED:+${_FLAGS_FIXED} }'--'"
96 _SAW_DASHDASH=1
97 fi
98 shift
99done
100eval set -- "${_FLAGS_FIXED}"
101
102
rspangler@google.comd74220d2009-10-09 20:56:14 +0000103# Parse command line flags
104FLAGS "$@" || exit 1
105eval set -- "${FLAGS_ARGV}"
106
Greg Spencer798d75f2011-02-01 22:04:49 -0800107if [ $FLAGS_official_build -eq $FLAGS_TRUE ]; then
David McMahon857dbb52009-12-09 18:21:05 -0800108 CHROMEOS_OFFICIAL=1
109fi
110
rspangler@google.comd74220d2009-10-09 20:56:14 +0000111# Only now can we die on error. shflags functions leak non-zero error codes,
112# so will die prematurely if 'set -e' is specified before now.
113# TODO: replace shflags with something less error-prone, or contribute a fix.
114set -e
115
Sean Parent2898f752010-05-25 15:06:33 -0700116INNER_CHROME_ROOT=$FLAGS_chrome_root_mount # inside chroot
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800117CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800118INNER_DEPOT_TOOLS_ROOT="/home/$USER/depot_tools" # inside chroot
Chris Sosaaa1a7fd2010-04-02 14:06:29 -0700119FUSE_DEVICE="/dev/fuse"
Chris Masone162f6542010-05-12 14:58:37 -0700120AUTOMOUNT_PREF="/apps/nautilus/preferences/media_automount"
121SAVED_AUTOMOUNT_PREF_FILE="/tmp/.automount_pref"
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800122
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800123sudo chmod 0777 "$FLAGS_chroot/var/lock"
124
125LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot"
126
rspangler@google.comd74220d2009-10-09 20:56:14 +0000127function setup_env {
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800128 (
129 flock 200
130 echo $$ >> "$LOCKFILE"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000131
Sean Ocd8b1d12010-09-02 17:34:49 +0200132 info "Mounting chroot environment."
rspangler@google.comd74220d2009-10-09 20:56:14 +0000133
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800134 # Mount only if not already mounted
135 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")"
Greg Spencer798d75f2011-02-01 22:04:49 -0800136 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
David James546747b2010-03-23 15:19:43 -0700137 sudo mount none -t proc "$MOUNTED_PATH" || \
138 die "Could not mount $MOUNTED_PATH"
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800139 fi
rspangler@google.comd74220d2009-10-09 20:56:14 +0000140
Antoine Laboure9e585f2010-04-01 15:57:57 -0700141 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/sys")"
Greg Spencer798d75f2011-02-01 22:04:49 -0800142 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
Antoine Laboure9e585f2010-04-01 15:57:57 -0700143 sudo mount none -t sysfs "$MOUNTED_PATH" || \
144 die "Could not mount $MOUNTED_PATH"
145 fi
146
robotboy152a1ab2010-04-26 14:07:27 -0700147 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev")"
Greg Spencer798d75f2011-02-01 22:04:49 -0800148 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
robotboy152a1ab2010-04-26 14:07:27 -0700149 sudo mount --bind /dev "$MOUNTED_PATH" || \
David James546747b2010-03-23 15:19:43 -0700150 die "Could not mount $MOUNTED_PATH"
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800151 fi
152
Elly Jones7990a062010-09-02 09:23:23 -0400153 if [ $FLAGS_ssh_agent -eq $FLAGS_TRUE ]; then
154 TARGET_DIR="$(readlink -f "${FLAGS_chroot}/home/${USER}/.ssh")"
Greg Spencer798d75f2011-02-01 22:04:49 -0800155 if [ -n "${SSH_AUTH_SOCK}" -a -d "${HOME}/.ssh" ]; then
Elly Jones7990a062010-09-02 09:23:23 -0400156 mkdir -p "${TARGET_DIR}"
157 cp -r "${HOME}/.ssh/known_hosts" "${TARGET_DIR}"
Zdenek Behan75805712011-01-05 00:56:32 +0100158 cp -r "${HOME}/.ssh/config" "${TARGET_DIR}"
Elly Jones7990a062010-09-02 09:23:23 -0400159 ASOCK="$(dirname "${SSH_AUTH_SOCK}")"
160 mkdir -p "${FLAGS_chroot}/${ASOCK}"
161 sudo mount --bind "${ASOCK}" "${FLAGS_chroot}/${ASOCK}" || \
162 die "Count not mount ${ASOCK}"
163 fi
164 fi
165
Zdenek Behan6f17b5e2010-06-10 16:50:52 -0700166 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev/pts")"
Greg Spencer798d75f2011-02-01 22:04:49 -0800167 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
Zdenek Behan6f17b5e2010-06-10 16:50:52 -0700168 sudo mount none -t devpts "$MOUNTED_PATH" || \
169 die "Could not mount $MOUNTED_PATH"
170 fi
171
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800172 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}$CHROOT_TRUNK_DIR")"
Greg Spencer798d75f2011-02-01 22:04:49 -0800173 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
David James546747b2010-03-23 15:19:43 -0700174 sudo mount --bind "$FLAGS_trunk" "$MOUNTED_PATH" || \
175 die "Could not mount $MOUNTED_PATH"
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800176 fi
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800177
178 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")"
Greg Spencer798d75f2011-02-01 22:04:49 -0800179 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
Andrew de los Reyesc1e8d272010-02-13 12:39:21 -0800180 ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")"
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800181 if [ -z "$CHROME_ROOT" ]; then
182 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \
183 2>/dev/null)"
184 fi
185 if [[ ( -z "$CHROME_ROOT" ) || ( ! -d "${CHROME_ROOT}/src" ) ]]; then
Sean Ocd8b1d12010-09-02 17:34:49 +0200186 info "Not mounting chrome source"
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800187 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}"
188 else
Sean Ocd8b1d12010-09-02 17:34:49 +0200189 info "Mounting chrome source at: $INNER_CHROME_ROOT"
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800190 echo "$CHROME_ROOT" | \
191 sudo dd of="${FLAGS_chroot}${CHROME_ROOT_CONFIG}"
192 mkdir -p "$MOUNTED_PATH"
David James546747b2010-03-23 15:19:43 -0700193 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \
194 die "Could not mount $MOUNTED_PATH"
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800195 fi
196 fi
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800197
198 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")"
Greg Spencer798d75f2011-02-01 22:04:49 -0800199 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800200 if [ $(which gclient 2>/dev/null) ]; then
Sean Ocd8b1d12010-09-02 17:34:49 +0200201 info "Mounting depot_tools"
Greg Spencer798d75f2011-02-01 22:04:49 -0800202 DEPOT_TOOLS=$(dirname "$(which gclient)")
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800203 mkdir -p "$MOUNTED_PATH"
Andrew de los Reyese8b63152010-02-16 14:18:34 -0800204 if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then
Sean Ocd8b1d12010-09-02 17:34:49 +0200205 warn "depot_tools failed to mount; perhaps it's on NFS?"
206 warn "This may impact chromium build."
Andrew de los Reyese8b63152010-02-16 14:18:34 -0800207 fi
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800208 fi
Chris Sosa317d8eb2010-04-05 15:45:28 -0700209 fi
210
robotboy152a1ab2010-04-26 14:07:27 -0700211 # Install fuse module.
Greg Spencer798d75f2011-02-01 22:04:49 -0800212 if [ -c "${FUSE_DEVICE}" ]; then
Chris Sosa317d8eb2010-04-05 15:45:28 -0700213 sudo modprobe fuse 2> /dev/null ||\
Sean Ocd8b1d12010-09-02 17:34:49 +0200214 warn "-- Note: modprobe fuse failed. gmergefs will not work"
Chris Sosa317d8eb2010-04-05 15:45:28 -0700215 fi
216
Chris Masone162f6542010-05-12 14:58:37 -0700217 # Turn off automounting of external media when we enter the
218 # chroot; thus we don't have to worry about being able to unmount
219 # from inside.
220 if [ $(which gconftool-2 2>/dev/null) ]; then
221 gconftool-2 -g ${AUTOMOUNT_PREF} > \
222 "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}"
223 if [ $(gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} false) ]; then
Sean Ocd8b1d12010-09-02 17:34:49 +0200224 warn "-- Note: USB sticks may be automounted by your host OS."
225 warn "-- Note: If you plan to burn bootable media, you may need to"
226 warn "-- Note: unmount these devices manually, or run image_to_usb.sh"
227 warn "-- Note: outside the chroot."
Chris Masone162f6542010-05-12 14:58:37 -0700228 fi
229 fi
230
David James546747b2010-03-23 15:19:43 -0700231 ) 200>>"$LOCKFILE" || die "setup_env failed"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000232}
233
234function teardown_env {
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800235 # Only teardown if we're the last enter_chroot to die
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800236 (
237 flock 200
238
239 # check each pid in $LOCKFILE to see if it's died unexpectedly
240 TMP_LOCKFILE="$LOCKFILE.tmp"
241
242 echo -n > "$TMP_LOCKFILE" # Erase/reset temp file
243 cat "$LOCKFILE" | while read PID; do
244 if [ "$PID" = "$$" ]; then
245 # ourself, leave PROC_NAME empty
246 PROC_NAME=""
247 else
248 PROC_NAME=$(ps --pid $PID -o comm=)
249 fi
250
251 if [ ! -z "$PROC_NAME" ]; then
252 # All good, keep going
253 echo "$PID" >> "$TMP_LOCKFILE"
254 fi
255 done
256 # Remove any dups from lock file while installing new one
257 sort -n "$TMP_LOCKFILE" | uniq > "$LOCKFILE"
258
Chris Masone162f6542010-05-12 14:58:37 -0700259 if [ $(which gconftool-2 2>/dev/null) ]; then
260 SAVED_PREF=$(cat "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}")
261 gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \
Sean Ocd8b1d12010-09-02 17:34:49 +0200262 warn "could not re-set your automount preference."
Chris Masone162f6542010-05-12 14:58:37 -0700263 fi
264
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800265 if [ -s "$LOCKFILE" ]; then
Sean Ocd8b1d12010-09-02 17:34:49 +0200266 info "At least one other pid is running in the chroot, so not"
267 info "tearing down env."
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800268 else
David James546747b2010-03-23 15:19:43 -0700269 MOUNTED_PATH=$(readlink -f "$FLAGS_chroot")
Sean Ocd8b1d12010-09-02 17:34:49 +0200270 info "Unmounting chroot environment."
Zdenek Behan6f17b5e2010-06-10 16:50:52 -0700271 # sort the list of mounts in reverse order, to ensure umount of
272 # cascading mounts in proper order
273 for i in \
274 $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do
robotboy98912212010-04-12 14:08:14 -0700275 safe_umount "$i"
David James546747b2010-03-23 15:19:43 -0700276 done
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800277 fi
David James546747b2010-03-23 15:19:43 -0700278 ) 200>>"$LOCKFILE" || die "teardown_env failed"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000279}
280
Greg Spencer798d75f2011-02-01 22:04:49 -0800281if [ $FLAGS_mount -eq $FLAGS_TRUE ]; then
rspangler@google.comd74220d2009-10-09 20:56:14 +0000282 setup_env
Sean Ocd8b1d12010-09-02 17:34:49 +0200283 info "Make sure you run"
284 info " $0 --unmount"
285 info "before deleting $FLAGS_chroot"
286 info "or you'll end up deleting $FLAGS_trunk too!"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000287 exit 0
288fi
289
Greg Spencer798d75f2011-02-01 22:04:49 -0800290if [ $FLAGS_unmount -eq $FLAGS_TRUE ]; then
rspangler@google.comd74220d2009-10-09 20:56:14 +0000291 teardown_env
292 exit 0
293fi
294
Doug Anderson0c9e88d2010-10-19 14:49:39 -0700295# Apply any hacks needed to update the chroot.
296chroot_hacks_from_outside "${FLAGS_chroot}"
297
298
rspangler@google.comd74220d2009-10-09 20:56:14 +0000299# Make sure we unmount before exiting
300trap teardown_env EXIT
301setup_env
302
David McMahon03aeb202009-12-08 12:47:08 -0800303# Get the git revision to pass into the chroot.
304#
305# This must be determined outside the chroot because (1) there is no
306# git inside the chroot, and (2) if there were it would likely be
307# the wrong version, which would mess up the .git directories.
308#
309# Note that this fixes $CHROMEOS_REVISION at the time the chroot is
310# entered. That's ok for the main use case of automated builds,
311# which pass each command line into a separate call to enter_chroot
David McMahon857dbb52009-12-09 18:21:05 -0800312# so always have up-to-date info. For developer builds, there may not
313# be a single revision, since the developer may have
David McMahon03aeb202009-12-08 12:47:08 -0800314# hand-sync'd some subdirs and edited files in others.
David McMahon857dbb52009-12-09 18:21:05 -0800315# In that case, check against origin/HEAD and mark** revision.
David McMahon03aeb202009-12-08 12:47:08 -0800316# Use git:8 chars of sha1
David Rochbergc1a3e562010-10-04 09:44:57 -0400317REVISION=$(cd ${FLAGS_trunk}/src/scripts ; git rev-parse --short=8 HEAD)
David McMahon857dbb52009-12-09 18:21:05 -0800318CHROOT_PASSTHRU="CHROMEOS_REVISION=$REVISION BUILDBOT_BUILD=$FLAGS_build_number CHROMEOS_OFFICIAL=$CHROMEOS_OFFICIAL"
Raja Aluri8f2a9952010-11-17 15:03:00 -0800319CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \
320CHROMEOS_RELEASE_APPID=${CHROMEOS_RELEASE_APPID:-"{DEV-BUILD}"}"
hexxeh72d0b082010-12-15 13:17:37 -0800321CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \
322CHROMEOS_VERSION_TRACK=$CHROMEOS_VERSION_TRACK CHROMEOS_VERSION_AUSERVER=$CHROMEOS_VERSION_AUSERVER CHROMEOS_VERSION_DEVSERVER=$CHROMEOS_VERSION_DEVSERVER"
Raja Alurie891eea2010-11-16 20:12:56 -0800323
Raja Aluri32759cf2010-08-30 18:44:39 -0700324if [ -d "$HOME/.subversion" ]; then
325 # Bind mounting .subversion into chroot
Sean Ocd8b1d12010-09-02 17:34:49 +0200326 info "mounting ~/.subversion into chroot"
Raja Aluri32759cf2010-08-30 18:44:39 -0700327 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/home/${USER}/.subversion")"
328 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
329 mkdir -p "$MOUNTED_PATH"
330 sudo mount --bind "$HOME/.subversion" "$MOUNTED_PATH" || \
331 die "Could not mount $MOUNTED_PATH"
332 fi
333fi
rspangler@google.comd74220d2009-10-09 20:56:14 +0000334
David James0fd8af42010-09-27 10:04:57 -0700335# Configure committer username and email in chroot .gitconfig
Chris Sosa558940d2011-02-01 13:07:55 -0800336if [ $FLAGS_git_config -eq $FLAGS_TRUE ]; then
337 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \
338 user.name "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/ *<.*//')"
339 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \
340 user.email "$(cd /tmp; git var GIT_COMMITTER_IDENT | \
341 sed -e 's/.*<\([^>]*\)>.*/\1/')"
342fi
David James0fd8af42010-09-27 10:04:57 -0700343
derat@google.com4e7a92b2009-11-21 23:44:14 +0000344# Run command or interactive shell. Also include the non-chrooted path to
345# the source trunk for scripts that may need to print it (e.g.
346# build_image.sh).
Doug Anderson9362fa82010-12-16 14:44:12 -0800347sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \
Elly Jones7990a062010-09-02 09:23:23 -0400348 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \
Doug Anderson9362fa82010-12-16 14:44:12 -0800349 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000350
351# Remove trap and explicitly unmount
352trap - EXIT
353teardown_env