blob: ac34ad961f583ffa9807c7462c421af638f0dfe5 [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."
Don Garrettad3f0592011-02-04 14:59:56 -080054DEFINE_boolean verbose $FLAGS_FALSE "Print out actions taken"
rspangler@google.comd74220d2009-10-09 20:56:14 +000055
56# More useful help
Doug Anderson9362fa82010-12-16 14:44:12 -080057FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- command [arg1] [arg2] ...]
rspangler@google.comd74220d2009-10-09 20:56:14 +000058
59One or more VAR=value pairs can be specified to export variables into
60the chroot environment. For example:
61
62 $0 FOO=bar BAZ=bel
63
Doug Anderson9362fa82010-12-16 14:44:12 -080064If [-- command] is present, runs the command inside the chroot,
65after changing directory to /$USER/trunk/src/scripts. Note that neither
66the command nor args should include single quotes. For example:
rspangler@google.comd74220d2009-10-09 20:56:14 +000067
Doug Anderson9362fa82010-12-16 14:44:12 -080068 $0 -- ./build_platform_packages.sh
rspangler@google.comd74220d2009-10-09 20:56:14 +000069
70Otherwise, provides an interactive shell.
71"
72
Don Garrettad3f0592011-02-04 14:59:56 -080073# Version of info from common.sh that only echos if --verbose is set.
Don Garretta0e7ea12011-02-07 18:39:59 -080074function debug {
Don Garrettad3f0592011-02-04 14:59:56 -080075 if [ $FLAGS_verbose -eq $FLAGS_TRUE ]; then
David Rochberg351a76f2011-02-16 11:14:00 -050076 info "$*"
Don Garrettad3f0592011-02-04 14:59:56 -080077 fi
78}
79
Doug Anderson9362fa82010-12-16 14:44:12 -080080# 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:
82# ./enter_chroot [flags] [VAR=val] [-- command]
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
85# end up getting what we want back from shflags.
86#
87# Examples of how people might be using enter_chroot:
88# 1. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2 -- cmd arg1 arg2
89# Set env vars and run cmd w/ args
90# 2. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2
91# Set env vars and run shell
92# 3. ./enter_chroot [chroot_flags] -- cmd arg1 arg2
93# Run cmd w/ args
94# 4. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2 cmd arg1 arg2
95# Like #1 _if_ args aren't flags (if they are, enter_chroot will claim them)
96# 5. ./enter_chroot [chroot_flags] cmd arg1 arg2
97# Like #3 _if_ args aren't flags (if they are, enter_chroot will claim them)
98_FLAGS_FIXED=''
99_SAW_DASHDASH=0
100while [ $# -gt 0 ]; do
101 _FLAGS_FIXED="${_FLAGS_FIXED:+${_FLAGS_FIXED} }'$1'"
102 if [ $_SAW_DASHDASH -eq 0 ] && [[ "$1" == "--" ]]; then
103 _FLAGS_FIXED="${_FLAGS_FIXED:+${_FLAGS_FIXED} }'--'"
104 _SAW_DASHDASH=1
105 fi
106 shift
107done
108eval set -- "${_FLAGS_FIXED}"
109
110
rspangler@google.comd74220d2009-10-09 20:56:14 +0000111# Parse command line flags
112FLAGS "$@" || exit 1
113eval set -- "${FLAGS_ARGV}"
114
Greg Spencer798d75f2011-02-01 22:04:49 -0800115if [ $FLAGS_official_build -eq $FLAGS_TRUE ]; then
David McMahon857dbb52009-12-09 18:21:05 -0800116 CHROMEOS_OFFICIAL=1
117fi
118
rspangler@google.comd74220d2009-10-09 20:56:14 +0000119# Only now can we die on error. shflags functions leak non-zero error codes,
120# so will die prematurely if 'set -e' is specified before now.
121# TODO: replace shflags with something less error-prone, or contribute a fix.
122set -e
123
Sean Parent2898f752010-05-25 15:06:33 -0700124INNER_CHROME_ROOT=$FLAGS_chrome_root_mount # inside chroot
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800125CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800126INNER_DEPOT_TOOLS_ROOT="/home/$USER/depot_tools" # inside chroot
Chris Sosaaa1a7fd2010-04-02 14:06:29 -0700127FUSE_DEVICE="/dev/fuse"
Chris Masone162f6542010-05-12 14:58:37 -0700128AUTOMOUNT_PREF="/apps/nautilus/preferences/media_automount"
129SAVED_AUTOMOUNT_PREF_FILE="/tmp/.automount_pref"
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800130
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800131sudo chmod 0777 "$FLAGS_chroot/var/lock"
132
133LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot"
134
David Rochberg351a76f2011-02-16 11:14:00 -0500135
136function ensure_mounted {
137 # If necessary, mount $source in the host FS at $target inside the
138 # chroot directory with $mount_args.
139 local source="$1"
140 local mount_args="$2"
141 local target="$3"
142
143 local mounted_path="$(readlink -f "${FLAGS_chroot}/$target")"
144
145 if [ -z "$(mount | grep -F "on ${mounted_path} ")" ]; then
146 # NB: mount_args deliberately left unquoted
147 debug mount ${mount_args} "${source}" "${mounted_path}"
148 sudo -- mount ${mount_args} "${source}" "${mounted_path}" || \
149 die "Could not mount ${source} on ${mounted_path}"
150 fi
151}
152
rspangler@google.comd74220d2009-10-09 20:56:14 +0000153function setup_env {
Doug Andersona8d9cc12011-02-02 15:47:00 -0800154 # Validate sudo timestamp before entering the critical section so that we
155 # don't stall for a password while we have the lockfile.
Doug Anderson3d7fa3a2011-02-02 16:10:34 -0800156 # Don't use sudo -v since that has issues on machines w/ no password.
157 sudo echo "" > /dev/null
Doug Andersona8d9cc12011-02-02 15:47:00 -0800158
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800159 (
160 flock 200
161 echo $$ >> "$LOCKFILE"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000162
Don Garretta0e7ea12011-02-07 18:39:59 -0800163 debug "Mounting chroot environment."
David Rochberg351a76f2011-02-16 11:14:00 -0500164 ensure_mounted none "-t proc" /proc
165 ensure_mounted none "-t sysfs" /sys
166 ensure_mounted /dev "--bind" /dev
167 ensure_mounted none "-t devpts" /dev/pts
168 ensure_mounted "${FLAGS_trunk}" "--bind" "${CHROOT_TRUNK_DIR}"
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800169
Elly Jones7990a062010-09-02 09:23:23 -0400170 if [ $FLAGS_ssh_agent -eq $FLAGS_TRUE ]; then
171 TARGET_DIR="$(readlink -f "${FLAGS_chroot}/home/${USER}/.ssh")"
Greg Spencer798d75f2011-02-01 22:04:49 -0800172 if [ -n "${SSH_AUTH_SOCK}" -a -d "${HOME}/.ssh" ]; then
Elly Jones7990a062010-09-02 09:23:23 -0400173 mkdir -p "${TARGET_DIR}"
174 cp -r "${HOME}/.ssh/known_hosts" "${TARGET_DIR}"
Zdenek Behan75805712011-01-05 00:56:32 +0100175 cp -r "${HOME}/.ssh/config" "${TARGET_DIR}"
Elly Jones7990a062010-09-02 09:23:23 -0400176 ASOCK="$(dirname "${SSH_AUTH_SOCK}")"
David Rochberg351a76f2011-02-16 11:14:00 -0500177 ensure_mounted "${ASOCK}" "--bind" "${ASOCK}"
Elly Jones7990a062010-09-02 09:23:23 -0400178 fi
179 fi
180
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800181 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")"
Greg Spencer798d75f2011-02-01 22:04:49 -0800182 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
Andrew de los Reyesc1e8d272010-02-13 12:39:21 -0800183 ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")"
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800184 if [ -z "$CHROME_ROOT" ]; then
185 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \
186 2>/dev/null)"
Don Garretta0e7ea12011-02-07 18:39:59 -0800187 CHROME_ROOT_AUTO=1
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800188 fi
Don Garretta0e7ea12011-02-07 18:39:59 -0800189 if [[ ( -n "$CHROME_ROOT" ) ]]; then
190 if [[ ( ! -d "${CHROME_ROOT}/src" ) ]]; then
191 error "Not mounting chrome source"
192 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}"
193 if [[ ! "$CHROME_ROOT_AUTO" ]]; then
194 exit 1
195 fi
196 else
197 debug "Mounting chrome source at: $INNER_CHROME_ROOT"
198 sudo bash -c "echo '$CHROME_ROOT' > \
199 '${FLAGS_chroot}${CHROME_ROOT_CONFIG}'"
200 mkdir -p "$MOUNTED_PATH"
201 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \
202 die "Could not mount $MOUNTED_PATH"
203 fi
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800204 fi
205 fi
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800206
207 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")"
Greg Spencer798d75f2011-02-01 22:04:49 -0800208 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800209 if [ $(which gclient 2>/dev/null) ]; then
Don Garretta0e7ea12011-02-07 18:39:59 -0800210 debug "Mounting depot_tools"
Greg Spencer798d75f2011-02-01 22:04:49 -0800211 DEPOT_TOOLS=$(dirname "$(which gclient)")
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800212 mkdir -p "$MOUNTED_PATH"
Andrew de los Reyese8b63152010-02-16 14:18:34 -0800213 if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then
Sean Ocd8b1d12010-09-02 17:34:49 +0200214 warn "depot_tools failed to mount; perhaps it's on NFS?"
215 warn "This may impact chromium build."
Andrew de los Reyese8b63152010-02-16 14:18:34 -0800216 fi
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800217 fi
Chris Sosa317d8eb2010-04-05 15:45:28 -0700218 fi
219
robotboy152a1ab2010-04-26 14:07:27 -0700220 # Install fuse module.
Greg Spencer798d75f2011-02-01 22:04:49 -0800221 if [ -c "${FUSE_DEVICE}" ]; then
Chris Sosa317d8eb2010-04-05 15:45:28 -0700222 sudo modprobe fuse 2> /dev/null ||\
Sean Ocd8b1d12010-09-02 17:34:49 +0200223 warn "-- Note: modprobe fuse failed. gmergefs will not work"
Chris Sosa317d8eb2010-04-05 15:45:28 -0700224 fi
225
Chris Masone162f6542010-05-12 14:58:37 -0700226 # Turn off automounting of external media when we enter the
227 # chroot; thus we don't have to worry about being able to unmount
228 # from inside.
229 if [ $(which gconftool-2 2>/dev/null) ]; then
230 gconftool-2 -g ${AUTOMOUNT_PREF} > \
231 "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}"
232 if [ $(gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} false) ]; then
Sean Ocd8b1d12010-09-02 17:34:49 +0200233 warn "-- Note: USB sticks may be automounted by your host OS."
234 warn "-- Note: If you plan to burn bootable media, you may need to"
235 warn "-- Note: unmount these devices manually, or run image_to_usb.sh"
236 warn "-- Note: outside the chroot."
Chris Masone162f6542010-05-12 14:58:37 -0700237 fi
238 fi
239
David James546747b2010-03-23 15:19:43 -0700240 ) 200>>"$LOCKFILE" || die "setup_env failed"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000241}
242
243function teardown_env {
Doug Andersona8d9cc12011-02-02 15:47:00 -0800244 # Validate sudo timestamp before entering the critical section so that we
245 # don't stall for a password while we have the lockfile.
Doug Anderson3d7fa3a2011-02-02 16:10:34 -0800246 # Don't use sudo -v since that has issues on machines w/ no password.
247 sudo echo "" > /dev/null
Doug Andersona8d9cc12011-02-02 15:47:00 -0800248
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800249 # Only teardown if we're the last enter_chroot to die
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800250 (
251 flock 200
252
253 # check each pid in $LOCKFILE to see if it's died unexpectedly
254 TMP_LOCKFILE="$LOCKFILE.tmp"
255
256 echo -n > "$TMP_LOCKFILE" # Erase/reset temp file
257 cat "$LOCKFILE" | while read PID; do
258 if [ "$PID" = "$$" ]; then
259 # ourself, leave PROC_NAME empty
260 PROC_NAME=""
261 else
262 PROC_NAME=$(ps --pid $PID -o comm=)
263 fi
264
265 if [ ! -z "$PROC_NAME" ]; then
266 # All good, keep going
267 echo "$PID" >> "$TMP_LOCKFILE"
268 fi
269 done
270 # Remove any dups from lock file while installing new one
271 sort -n "$TMP_LOCKFILE" | uniq > "$LOCKFILE"
272
Chris Masone162f6542010-05-12 14:58:37 -0700273 if [ $(which gconftool-2 2>/dev/null) ]; then
274 SAVED_PREF=$(cat "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}")
275 gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \
Sean Ocd8b1d12010-09-02 17:34:49 +0200276 warn "could not re-set your automount preference."
Chris Masone162f6542010-05-12 14:58:37 -0700277 fi
278
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800279 if [ -s "$LOCKFILE" ]; then
Don Garretta0e7ea12011-02-07 18:39:59 -0800280 debug "At least one other pid is running in the chroot, so not"
281 debug "tearing down env."
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800282 else
David James546747b2010-03-23 15:19:43 -0700283 MOUNTED_PATH=$(readlink -f "$FLAGS_chroot")
Don Garretta0e7ea12011-02-07 18:39:59 -0800284 debug "Unmounting chroot environment."
Zdenek Behan6f17b5e2010-06-10 16:50:52 -0700285 # sort the list of mounts in reverse order, to ensure umount of
286 # cascading mounts in proper order
287 for i in \
288 $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do
robotboy98912212010-04-12 14:08:14 -0700289 safe_umount "$i"
David James546747b2010-03-23 15:19:43 -0700290 done
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800291 fi
David James546747b2010-03-23 15:19:43 -0700292 ) 200>>"$LOCKFILE" || die "teardown_env failed"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000293}
294
Doug Andersonae573e72011-02-11 12:09:02 -0800295# This function does extra "fixups" of the chroot. It's a lot like
296# chroot_hacks_from_outside() in common.sh, except that it is only called
297# from enter_chroot.sh (chroot_hacks_from_outside is also called from
298# make_chroot.sh). This function was created because common.sh is on lockdown
299# and can't be changed.
300#
301# NOTE: the need for this type of "fixup" should be going away. If everything
302# in the chroot is versioned and nothing is generated, there is no need to
303# handle partly fixing up generated files.
304#
305# Please put date information so it's easy to keep track of when
306# old hacks can be retired and so that people can detect when a
307# hack triggered when it shouldn't have.
308function chroot_hacks_too() {
309 local chroot_home="${FLAGS_chroot}/home/${USER}"
310
311 # Add chromite stuff if not already done.
312 if ! grep -q "^PATH=.*/trunk/chromite/bin" "${chroot_home}/.bashrc"; then
313 info "Upgrading old chroot (pre 2011-02-09) - adding chromite to path"
314 echo "PATH=\$PATH:/home/${USER}/trunk/chromite/bin" >> \
315 "${chroot_home}/.bashrc"
316 fi
317 if ! [ -L "${chroot_home}/.local/lib/python2.6/site-packages/chromite" ]; then
318 info "Upgrading old chroot (pre 2011-02-09) - add chromite to site-packages"
319 mkdir -p "${chroot_home}/.local/lib/python2.6/site-packages"
320 ln -s ../../../../trunk/chromite \
321 "${chroot_home}/.local/lib/python2.6/site-packages/"
322 fi
323}
324
325
Greg Spencer798d75f2011-02-01 22:04:49 -0800326if [ $FLAGS_mount -eq $FLAGS_TRUE ]; then
rspangler@google.comd74220d2009-10-09 20:56:14 +0000327 setup_env
Don Garretta0e7ea12011-02-07 18:39:59 -0800328 info "Make sure you run"
329 info " $0 --unmount"
330 info "before deleting $FLAGS_chroot"
331 info "or you'll end up deleting $FLAGS_trunk too!"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000332 exit 0
333fi
334
Greg Spencer798d75f2011-02-01 22:04:49 -0800335if [ $FLAGS_unmount -eq $FLAGS_TRUE ]; then
rspangler@google.comd74220d2009-10-09 20:56:14 +0000336 teardown_env
337 exit 0
338fi
339
Doug Anderson0c9e88d2010-10-19 14:49:39 -0700340# Apply any hacks needed to update the chroot.
341chroot_hacks_from_outside "${FLAGS_chroot}"
Doug Andersonae573e72011-02-11 12:09:02 -0800342chroot_hacks_too
Doug Anderson0c9e88d2010-10-19 14:49:39 -0700343
344
rspangler@google.comd74220d2009-10-09 20:56:14 +0000345# Make sure we unmount before exiting
346trap teardown_env EXIT
347setup_env
348
David McMahon03aeb202009-12-08 12:47:08 -0800349# Get the git revision to pass into the chroot.
350#
351# This must be determined outside the chroot because (1) there is no
352# git inside the chroot, and (2) if there were it would likely be
353# the wrong version, which would mess up the .git directories.
354#
355# Note that this fixes $CHROMEOS_REVISION at the time the chroot is
356# entered. That's ok for the main use case of automated builds,
357# which pass each command line into a separate call to enter_chroot
David McMahon857dbb52009-12-09 18:21:05 -0800358# so always have up-to-date info. For developer builds, there may not
359# be a single revision, since the developer may have
David McMahon03aeb202009-12-08 12:47:08 -0800360# hand-sync'd some subdirs and edited files in others.
David McMahon857dbb52009-12-09 18:21:05 -0800361# In that case, check against origin/HEAD and mark** revision.
David McMahon03aeb202009-12-08 12:47:08 -0800362# Use git:8 chars of sha1
David Rochbergc1a3e562010-10-04 09:44:57 -0400363REVISION=$(cd ${FLAGS_trunk}/src/scripts ; git rev-parse --short=8 HEAD)
David McMahon857dbb52009-12-09 18:21:05 -0800364CHROOT_PASSTHRU="CHROMEOS_REVISION=$REVISION BUILDBOT_BUILD=$FLAGS_build_number CHROMEOS_OFFICIAL=$CHROMEOS_OFFICIAL"
Raja Aluri8f2a9952010-11-17 15:03:00 -0800365CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \
366CHROMEOS_RELEASE_APPID=${CHROMEOS_RELEASE_APPID:-"{DEV-BUILD}"}"
hexxeh72d0b082010-12-15 13:17:37 -0800367CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \
368CHROMEOS_VERSION_TRACK=$CHROMEOS_VERSION_TRACK CHROMEOS_VERSION_AUSERVER=$CHROMEOS_VERSION_AUSERVER CHROMEOS_VERSION_DEVSERVER=$CHROMEOS_VERSION_DEVSERVER"
Raja Alurie891eea2010-11-16 20:12:56 -0800369
Raja Aluri32759cf2010-08-30 18:44:39 -0700370if [ -d "$HOME/.subversion" ]; then
David Rochberg351a76f2011-02-16 11:14:00 -0500371 TARGET="/home/${USER}/.subversion"
372 mkdir -p "${FLAGS_chroot}${TARGET}"
373 ensure_mounted "${HOME}/.subversion" "--bind" "${TARGET}"
Raja Aluri32759cf2010-08-30 18:44:39 -0700374fi
rspangler@google.comd74220d2009-10-09 20:56:14 +0000375
David James0fd8af42010-09-27 10:04:57 -0700376# Configure committer username and email in chroot .gitconfig
Chris Sosa558940d2011-02-01 13:07:55 -0800377if [ $FLAGS_git_config -eq $FLAGS_TRUE ]; then
378 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \
379 user.name "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/ *<.*//')"
380 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \
381 user.email "$(cd /tmp; git var GIT_COMMITTER_IDENT | \
382 sed -e 's/.*<\([^>]*\)>.*/\1/')"
383fi
David James0fd8af42010-09-27 10:04:57 -0700384
derat@google.com4e7a92b2009-11-21 23:44:14 +0000385# Run command or interactive shell. Also include the non-chrooted path to
386# the source trunk for scripts that may need to print it (e.g.
387# build_image.sh).
Doug Anderson9362fa82010-12-16 14:44:12 -0800388sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \
Elly Jones7990a062010-09-02 09:23:23 -0400389 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \
Doug Anderson9362fa82010-12-16 14:44:12 -0800390 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000391
392# Remove trap and explicitly unmount
393trap - EXIT
394teardown_env