blob: 832b5e99252ee66e35e87e6aebf48a8575f16735 [file] [log] [blame]
rspangler@google.comd74220d2009-10-09 20:56:14 +00001#!/bin/bash
2
Darin Petkov47974d42011-03-03 15:55:04 -08003# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
rspangler@google.comd74220d2009-10-09 20:56:14 +00004# 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
Brian Harringd5d5dbf2011-07-11 16:36:21 -070027. "${SCRIPT_ROOT}/common.sh" || { echo "Unable to load common.sh"; exit 1; }
Greg Spencer798d75f2011-02-01 22:04:49 -080028# --- 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 Sosaaa1a7fd2010-04-02 14:06:29 -070047DEFINE_boolean official_build $FLAGS_FALSE \
48 "Set CHROMEOS_OFFICIAL=1 for release builds."
rspangler@google.comd74220d2009-10-09 20:56:14 +000049DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts."
50DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts."
Elly Jones7990a062010-09-02 09:23:23 -040051DEFINE_boolean ssh_agent $FLAGS_TRUE "Import ssh agent."
Don Garrettad3f0592011-02-04 14:59:56 -080052DEFINE_boolean verbose $FLAGS_FALSE "Print out actions taken"
rspangler@google.comd74220d2009-10-09 20:56:14 +000053
54# More useful help
Doug Anderson9362fa82010-12-16 14:44:12 -080055FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- command [arg1] [arg2] ...]
rspangler@google.comd74220d2009-10-09 20:56:14 +000056
57One or more VAR=value pairs can be specified to export variables into
58the chroot environment. For example:
59
60 $0 FOO=bar BAZ=bel
61
Doug Anderson9362fa82010-12-16 14:44:12 -080062If [-- command] is present, runs the command inside the chroot,
63after changing directory to /$USER/trunk/src/scripts. Note that neither
64the command nor args should include single quotes. For example:
rspangler@google.comd74220d2009-10-09 20:56:14 +000065
Doug Anderson9362fa82010-12-16 14:44:12 -080066 $0 -- ./build_platform_packages.sh
rspangler@google.comd74220d2009-10-09 20:56:14 +000067
68Otherwise, provides an interactive shell.
69"
70
Don Garrettad3f0592011-02-04 14:59:56 -080071# Version of info from common.sh that only echos if --verbose is set.
Don Garretta0e7ea12011-02-07 18:39:59 -080072function debug {
Don Garrettad3f0592011-02-04 14:59:56 -080073 if [ $FLAGS_verbose -eq $FLAGS_TRUE ]; then
David Rochberg351a76f2011-02-16 11:14:00 -050074 info "$*"
Don Garrettad3f0592011-02-04 14:59:56 -080075 fi
76}
77
rspangler@google.comd74220d2009-10-09 20:56:14 +000078# Parse command line flags
79FLAGS "$@" || exit 1
80eval set -- "${FLAGS_ARGV}"
81
Greg Spencer798d75f2011-02-01 22:04:49 -080082if [ $FLAGS_official_build -eq $FLAGS_TRUE ]; then
David McMahon857dbb52009-12-09 18:21:05 -080083 CHROMEOS_OFFICIAL=1
84fi
85
rspangler@google.comd74220d2009-10-09 20:56:14 +000086# Only now can we die on error. shflags functions leak non-zero error codes,
87# so will die prematurely if 'set -e' is specified before now.
88# TODO: replace shflags with something less error-prone, or contribute a fix.
89set -e
90
Sean Parent2898f752010-05-25 15:06:33 -070091INNER_CHROME_ROOT=$FLAGS_chrome_root_mount # inside chroot
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -080092CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -080093INNER_DEPOT_TOOLS_ROOT="/home/$USER/depot_tools" # inside chroot
Chris Sosaaa1a7fd2010-04-02 14:06:29 -070094FUSE_DEVICE="/dev/fuse"
Chris Masone162f6542010-05-12 14:58:37 -070095AUTOMOUNT_PREF="/apps/nautilus/preferences/media_automount"
96SAVED_AUTOMOUNT_PREF_FILE="/tmp/.automount_pref"
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -080097
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -080098sudo chmod 0777 "$FLAGS_chroot/var/lock"
99
100LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot"
Zdenek Behane28239d2011-04-07 00:37:20 +0200101SYNCERPIDFILE="${FLAGS_chroot}/var/tmp/enter_chroot_sync.pid"
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800102
David Rochberg351a76f2011-02-16 11:14:00 -0500103
104function ensure_mounted {
105 # If necessary, mount $source in the host FS at $target inside the
106 # chroot directory with $mount_args.
107 local source="$1"
108 local mount_args="$2"
109 local target="$3"
110
111 local mounted_path="$(readlink -f "${FLAGS_chroot}/$target")"
112
113 if [ -z "$(mount | grep -F "on ${mounted_path} ")" ]; then
David Rochberg33373ef2011-02-16 14:48:27 -0500114 # Attempt to make the mountpoint as the user. This depends on the
115 # fact that all mountpoints that should be owned by root are
116 # already present.
117 mkdir -p "${mounted_path}"
118
David Rochberg351a76f2011-02-16 11:14:00 -0500119 # NB: mount_args deliberately left unquoted
120 debug mount ${mount_args} "${source}" "${mounted_path}"
121 sudo -- mount ${mount_args} "${source}" "${mounted_path}" || \
122 die "Could not mount ${source} on ${mounted_path}"
123 fi
124}
125
Zdenek Behane28239d2011-04-07 00:37:20 +0200126function env_sync_proc {
127 # This function runs and performs periodic updates to the chroot env, if
128 # necessary.
129
130 local poll_interval=10
131 local sync_files="etc/resolv.conf etc/hosts"
132
133 # Make sure the synced files are writable by normal user, so that we
134 # don't have to sudo inside the loop.
135 for file in ${sync_files}; do
136 sudo chown ${USER} ${FLAGS_chroot}/${file} 1>&2
137 done
138
David James412b9022011-07-15 19:54:16 -0700139 # Drop stdin, stderr, stdout, and chroot lock.
140 # This is needed for properly daemonizing the process.
141 exec 0>&- 1>&- 2>&- 200>&-
142
Zdenek Behane28239d2011-04-07 00:37:20 +0200143 while true; do
144 # Sync files
145 for file in ${sync_files}; do
146 if ! cmp /${file} ${FLAGS_chroot}/${file} &> /dev/null; then
147 cp -f /${file} ${FLAGS_chroot}/${file}
148 fi
149 done
150
151 sleep ${poll_interval}
152 done
153}
154
Vadim Bendebury0779f522011-06-12 12:09:16 -0700155function copy_ssh_config {
156 # Copy user .ssh/config into the chroot filtering out strings not supported
157 # by the chroot ssh. The chroot .ssh directory is passed in as the first
158 # parameter.
159
160 # ssh options to filter out. The entire strings containing these substrings
161 # will be deleted before copying.
162 local bad_options=(
163 'UseProxyIf='
164 'GSSAPIAuthentication no'
165 )
166 local sshc="${HOME}/.ssh/config"
167 local chroot_ssh_dir="${1}"
168 local filter
169 local option
170
171 if [ ! -f "${sshc}" ]; then
172 return # Nothing to copy.
173 fi
174
175 for option in "${bad_options[@]}"
176 do
177 if [ -z "${filter}" ]; then
178 filter="${option}"
179 else
180 filter+="\\|${option}"
181 fi
182 done
183
184 sed "/^.*\(${filter}\).*$/d" "${sshc}" > "${chroot_ssh_dir}/config"
185}
186
rspangler@google.comd74220d2009-10-09 20:56:14 +0000187function setup_env {
Doug Andersona8d9cc12011-02-02 15:47:00 -0800188 # Validate sudo timestamp before entering the critical section so that we
189 # don't stall for a password while we have the lockfile.
Doug Anderson3d7fa3a2011-02-02 16:10:34 -0800190 # Don't use sudo -v since that has issues on machines w/ no password.
191 sudo echo "" > /dev/null
Doug Andersona8d9cc12011-02-02 15:47:00 -0800192
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800193 (
194 flock 200
195 echo $$ >> "$LOCKFILE"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000196
David James412b9022011-07-15 19:54:16 -0700197 # If there isn't a syncer daemon started already, start one. This daemon
198 # is killed by the enter_chroot that exits last.
199 if ! [ -f "${SYNCERPIDFILE}" ] || \
200 ! [ -d /proc/$(cat "${SYNCERPIDFILE}") ]; then
201 debug "Starting sync process"
202 env_sync_proc &
203 echo $! > "${SYNCERPIDFILE}"
204 disown $!
205 fi
206
Don Garretta0e7ea12011-02-07 18:39:59 -0800207 debug "Mounting chroot environment."
David Rochberg351a76f2011-02-16 11:14:00 -0500208 ensure_mounted none "-t proc" /proc
209 ensure_mounted none "-t sysfs" /sys
210 ensure_mounted /dev "--bind" /dev
211 ensure_mounted none "-t devpts" /dev/pts
212 ensure_mounted "${FLAGS_trunk}" "--bind" "${CHROOT_TRUNK_DIR}"
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800213
Elly Jones7990a062010-09-02 09:23:23 -0400214 if [ $FLAGS_ssh_agent -eq $FLAGS_TRUE ]; then
215 TARGET_DIR="$(readlink -f "${FLAGS_chroot}/home/${USER}/.ssh")"
Greg Spencer798d75f2011-02-01 22:04:49 -0800216 if [ -n "${SSH_AUTH_SOCK}" -a -d "${HOME}/.ssh" ]; then
Elly Jones7990a062010-09-02 09:23:23 -0400217 mkdir -p "${TARGET_DIR}"
218 cp -r "${HOME}/.ssh/known_hosts" "${TARGET_DIR}"
Elly Jones39ba1e52011-06-30 11:08:28 -0400219 cp -r ${HOME}/.ssh/*.pub "${TARGET_DIR}"
Vadim Bendebury0779f522011-06-12 12:09:16 -0700220 copy_ssh_config "${TARGET_DIR}"
Elly Jones7990a062010-09-02 09:23:23 -0400221 ASOCK="$(dirname "${SSH_AUTH_SOCK}")"
David Rochberg351a76f2011-02-16 11:14:00 -0500222 ensure_mounted "${ASOCK}" "--bind" "${ASOCK}"
Elly Jones7990a062010-09-02 09:23:23 -0400223 fi
224 fi
225
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800226 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")"
Greg Spencer798d75f2011-02-01 22:04:49 -0800227 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
Andrew de los Reyesc1e8d272010-02-13 12:39:21 -0800228 ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")"
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800229 if [ -z "$CHROME_ROOT" ]; then
230 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \
231 2>/dev/null)"
Don Garretta0e7ea12011-02-07 18:39:59 -0800232 CHROME_ROOT_AUTO=1
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800233 fi
Don Garretta0e7ea12011-02-07 18:39:59 -0800234 if [[ ( -n "$CHROME_ROOT" ) ]]; then
235 if [[ ( ! -d "${CHROME_ROOT}/src" ) ]]; then
236 error "Not mounting chrome source"
237 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}"
238 if [[ ! "$CHROME_ROOT_AUTO" ]]; then
239 exit 1
240 fi
241 else
242 debug "Mounting chrome source at: $INNER_CHROME_ROOT"
243 sudo bash -c "echo '$CHROME_ROOT' > \
244 '${FLAGS_chroot}${CHROME_ROOT_CONFIG}'"
245 mkdir -p "$MOUNTED_PATH"
246 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \
247 die "Could not mount $MOUNTED_PATH"
248 fi
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800249 fi
250 fi
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800251
252 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")"
Greg Spencer798d75f2011-02-01 22:04:49 -0800253 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800254 if [ $(which gclient 2>/dev/null) ]; then
Don Garretta0e7ea12011-02-07 18:39:59 -0800255 debug "Mounting depot_tools"
Greg Spencer798d75f2011-02-01 22:04:49 -0800256 DEPOT_TOOLS=$(dirname "$(which gclient)")
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800257 mkdir -p "$MOUNTED_PATH"
Andrew de los Reyese8b63152010-02-16 14:18:34 -0800258 if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then
Sean Ocd8b1d12010-09-02 17:34:49 +0200259 warn "depot_tools failed to mount; perhaps it's on NFS?"
260 warn "This may impact chromium build."
Andrew de los Reyese8b63152010-02-16 14:18:34 -0800261 fi
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800262 fi
Chris Sosa317d8eb2010-04-05 15:45:28 -0700263 fi
264
robotboy152a1ab2010-04-26 14:07:27 -0700265 # Install fuse module.
Greg Spencer798d75f2011-02-01 22:04:49 -0800266 if [ -c "${FUSE_DEVICE}" ]; then
Chris Sosa317d8eb2010-04-05 15:45:28 -0700267 sudo modprobe fuse 2> /dev/null ||\
Sean Ocd8b1d12010-09-02 17:34:49 +0200268 warn "-- Note: modprobe fuse failed. gmergefs will not work"
Chris Sosa317d8eb2010-04-05 15:45:28 -0700269 fi
270
Chris Masone162f6542010-05-12 14:58:37 -0700271 # Turn off automounting of external media when we enter the
272 # chroot; thus we don't have to worry about being able to unmount
273 # from inside.
274 if [ $(which gconftool-2 2>/dev/null) ]; then
275 gconftool-2 -g ${AUTOMOUNT_PREF} > \
276 "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}"
277 if [ $(gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} false) ]; then
Sean Ocd8b1d12010-09-02 17:34:49 +0200278 warn "-- Note: USB sticks may be automounted by your host OS."
279 warn "-- Note: If you plan to burn bootable media, you may need to"
280 warn "-- Note: unmount these devices manually, or run image_to_usb.sh"
281 warn "-- Note: outside the chroot."
Chris Masone162f6542010-05-12 14:58:37 -0700282 fi
283 fi
284
David James342f1562011-07-15 15:21:18 -0700285 if [ -d "$HOME/.subversion" ]; then
286 TARGET="/home/${USER}/.subversion"
287 mkdir -p "${FLAGS_chroot}${TARGET}"
288 ensure_mounted "${HOME}/.subversion" "--bind" "${TARGET}"
289 fi
290
291 # Configure committer username and email in chroot .gitconfig
292 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \
293 user.name "$(cd /tmp; git var GIT_COMMITTER_IDENT | \
294 sed -e 's/ *<.*//')" || true
295 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \
296 user.email "$(cd /tmp; git var GIT_COMMITTER_IDENT | \
297 sed -e 's/.*<\([^>]*\)>.*/\1/')" || true
298
Dale Curtis98631732011-05-05 16:16:59 -0700299 # Fix permissions on shared memory to allow non-root users access to POSIX
300 # semaphores.
301 sudo chmod -R 777 "${FLAGS_chroot}/dev/shm"
David James546747b2010-03-23 15:19:43 -0700302 ) 200>>"$LOCKFILE" || die "setup_env failed"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000303}
304
305function teardown_env {
Doug Andersona8d9cc12011-02-02 15:47:00 -0800306 # Validate sudo timestamp before entering the critical section so that we
307 # don't stall for a password while we have the lockfile.
Doug Anderson3d7fa3a2011-02-02 16:10:34 -0800308 # Don't use sudo -v since that has issues on machines w/ no password.
309 sudo echo "" > /dev/null
Doug Andersona8d9cc12011-02-02 15:47:00 -0800310
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800311 # Only teardown if we're the last enter_chroot to die
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800312 (
313 flock 200
314
315 # check each pid in $LOCKFILE to see if it's died unexpectedly
316 TMP_LOCKFILE="$LOCKFILE.tmp"
317
318 echo -n > "$TMP_LOCKFILE" # Erase/reset temp file
319 cat "$LOCKFILE" | while read PID; do
320 if [ "$PID" = "$$" ]; then
321 # ourself, leave PROC_NAME empty
322 PROC_NAME=""
323 else
324 PROC_NAME=$(ps --pid $PID -o comm=)
325 fi
326
327 if [ ! -z "$PROC_NAME" ]; then
328 # All good, keep going
329 echo "$PID" >> "$TMP_LOCKFILE"
330 fi
331 done
332 # Remove any dups from lock file while installing new one
333 sort -n "$TMP_LOCKFILE" | uniq > "$LOCKFILE"
334
Chris Masone162f6542010-05-12 14:58:37 -0700335 if [ $(which gconftool-2 2>/dev/null) ]; then
336 SAVED_PREF=$(cat "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}")
337 gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \
Sean Ocd8b1d12010-09-02 17:34:49 +0200338 warn "could not re-set your automount preference."
Chris Masone162f6542010-05-12 14:58:37 -0700339 fi
340
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800341 if [ -s "$LOCKFILE" ]; then
Don Garretta0e7ea12011-02-07 18:39:59 -0800342 debug "At least one other pid is running in the chroot, so not"
343 debug "tearing down env."
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800344 else
Zdenek Behane28239d2011-04-07 00:37:20 +0200345 debug "Stopping syncer process"
346 kill $(cat "${SYNCERPIDFILE}")
347
David James546747b2010-03-23 15:19:43 -0700348 MOUNTED_PATH=$(readlink -f "$FLAGS_chroot")
Don Garretta0e7ea12011-02-07 18:39:59 -0800349 debug "Unmounting chroot environment."
Zdenek Behan6f17b5e2010-06-10 16:50:52 -0700350 # sort the list of mounts in reverse order, to ensure umount of
351 # cascading mounts in proper order
352 for i in \
353 $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do
robotboy98912212010-04-12 14:08:14 -0700354 safe_umount "$i"
David James546747b2010-03-23 15:19:43 -0700355 done
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800356 fi
David James546747b2010-03-23 15:19:43 -0700357 ) 200>>"$LOCKFILE" || die "teardown_env failed"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000358}
359
Greg Spencer798d75f2011-02-01 22:04:49 -0800360if [ $FLAGS_mount -eq $FLAGS_TRUE ]; then
rspangler@google.comd74220d2009-10-09 20:56:14 +0000361 setup_env
Don Garretta0e7ea12011-02-07 18:39:59 -0800362 info "Make sure you run"
363 info " $0 --unmount"
364 info "before deleting $FLAGS_chroot"
365 info "or you'll end up deleting $FLAGS_trunk too!"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000366 exit 0
367fi
368
Greg Spencer798d75f2011-02-01 22:04:49 -0800369if [ $FLAGS_unmount -eq $FLAGS_TRUE ]; then
rspangler@google.comd74220d2009-10-09 20:56:14 +0000370 teardown_env
371 exit 0
372fi
373
374# Make sure we unmount before exiting
375trap teardown_env EXIT
376setup_env
377
Darin Petkov87dd2be2011-03-01 09:25:09 -0800378CHROOT_PASSTHRU="BUILDBOT_BUILD=$FLAGS_build_number CHROMEOS_OFFICIAL=$CHROMEOS_OFFICIAL"
Raja Aluri8f2a9952010-11-17 15:03:00 -0800379CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \
380CHROMEOS_RELEASE_APPID=${CHROMEOS_RELEASE_APPID:-"{DEV-BUILD}"}"
Raja Alurie891eea2010-11-16 20:12:56 -0800381
Liam McLoughlin3b11b452011-03-14 16:04:07 -0700382# Set CHROMEOS_VERSION_TRACK, CHROMEOS_VERSION_AUSERVER,
383# CHROMEOS_VERSION_DEVSERVER as environment variables to override the default
384# assumptions (local AU server). These are used in cros_set_lsb_release, and
385# are used by external Chromium OS builders.
386CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \
387CHROMEOS_VERSION_TRACK=${CHROMEOS_VERSION_TRACK} \
388CHROMEOS_VERSION_AUSERVER=${CHROMEOS_VERSION_AUSERVER} \
389CHROMEOS_VERSION_DEVSERVER=${CHROMEOS_VERSION_DEVSERVER}"
390
Mario Limonciello7052ae12011-05-05 12:00:49 -0500391# Pass proxy variables into the environment.
392for type in http_proxy ftp_proxy all_proxy GIT_PROXY_COMMAND GIT_SSH; do
393 eval value=\$${type}
394 if [ -n "${value}" ]; then
395 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} ${type}=${value}"
396 fi
397done
398
derat@google.com4e7a92b2009-11-21 23:44:14 +0000399# Run command or interactive shell. Also include the non-chrooted path to
400# the source trunk for scripts that may need to print it (e.g.
401# build_image.sh).
Doug Anderson9362fa82010-12-16 14:44:12 -0800402sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \
Elly Jones7990a062010-09-02 09:23:23 -0400403 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \
Doug Anderson9362fa82010-12-16 14:44:12 -0800404 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000405
406# Remove trap and explicitly unmount
407trap - EXIT
408teardown_env