blob: 89f9a387d5d62182e2de0eb985786040a1fb229b [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
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 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
Doug Anderson9362fa82010-12-16 14:44:12 -080078# Double up on the first '--' argument. Why? For enter_chroot, we want to
79# emulate the behavior of sudo for setting environment vars. That is, we want:
80# ./enter_chroot [flags] [VAR=val] [-- command]
81# ...but shflags ends up eating the '--' out of the command line and gives
82# us back "VAR=val" and "command" together in one chunk. By doubling up, we
83# end up getting what we want back from shflags.
84#
85# Examples of how people might be using enter_chroot:
86# 1. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2 -- cmd arg1 arg2
87# Set env vars and run cmd w/ args
88# 2. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2
89# Set env vars and run shell
90# 3. ./enter_chroot [chroot_flags] -- cmd arg1 arg2
91# Run cmd w/ args
92# 4. ./enter_chroot [chroot_flags] VAR1=val1 VAR2=val2 cmd arg1 arg2
93# Like #1 _if_ args aren't flags (if they are, enter_chroot will claim them)
94# 5. ./enter_chroot [chroot_flags] cmd arg1 arg2
95# Like #3 _if_ args aren't flags (if they are, enter_chroot will claim them)
96_FLAGS_FIXED=''
97_SAW_DASHDASH=0
98while [ $# -gt 0 ]; do
99 _FLAGS_FIXED="${_FLAGS_FIXED:+${_FLAGS_FIXED} }'$1'"
100 if [ $_SAW_DASHDASH -eq 0 ] && [[ "$1" == "--" ]]; then
101 _FLAGS_FIXED="${_FLAGS_FIXED:+${_FLAGS_FIXED} }'--'"
102 _SAW_DASHDASH=1
103 fi
104 shift
105done
106eval set -- "${_FLAGS_FIXED}"
107
108
rspangler@google.comd74220d2009-10-09 20:56:14 +0000109# Parse command line flags
110FLAGS "$@" || exit 1
111eval set -- "${FLAGS_ARGV}"
112
Greg Spencer798d75f2011-02-01 22:04:49 -0800113if [ $FLAGS_official_build -eq $FLAGS_TRUE ]; then
David McMahon857dbb52009-12-09 18:21:05 -0800114 CHROMEOS_OFFICIAL=1
115fi
116
rspangler@google.comd74220d2009-10-09 20:56:14 +0000117# Only now can we die on error. shflags functions leak non-zero error codes,
118# so will die prematurely if 'set -e' is specified before now.
119# TODO: replace shflags with something less error-prone, or contribute a fix.
120set -e
121
Sean Parent2898f752010-05-25 15:06:33 -0700122INNER_CHROME_ROOT=$FLAGS_chrome_root_mount # inside chroot
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800123CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800124INNER_DEPOT_TOOLS_ROOT="/home/$USER/depot_tools" # inside chroot
Chris Sosaaa1a7fd2010-04-02 14:06:29 -0700125FUSE_DEVICE="/dev/fuse"
Chris Masone162f6542010-05-12 14:58:37 -0700126AUTOMOUNT_PREF="/apps/nautilus/preferences/media_automount"
127SAVED_AUTOMOUNT_PREF_FILE="/tmp/.automount_pref"
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800128
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800129sudo chmod 0777 "$FLAGS_chroot/var/lock"
130
131LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot"
Zdenek Behane28239d2011-04-07 00:37:20 +0200132SYNCERPIDFILE="${FLAGS_chroot}/var/tmp/enter_chroot_sync.pid"
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800133
David Rochberg351a76f2011-02-16 11:14:00 -0500134
135function ensure_mounted {
136 # If necessary, mount $source in the host FS at $target inside the
137 # chroot directory with $mount_args.
138 local source="$1"
139 local mount_args="$2"
140 local target="$3"
141
142 local mounted_path="$(readlink -f "${FLAGS_chroot}/$target")"
143
144 if [ -z "$(mount | grep -F "on ${mounted_path} ")" ]; then
David Rochberg33373ef2011-02-16 14:48:27 -0500145 # Attempt to make the mountpoint as the user. This depends on the
146 # fact that all mountpoints that should be owned by root are
147 # already present.
148 mkdir -p "${mounted_path}"
149
David Rochberg351a76f2011-02-16 11:14:00 -0500150 # NB: mount_args deliberately left unquoted
151 debug mount ${mount_args} "${source}" "${mounted_path}"
152 sudo -- mount ${mount_args} "${source}" "${mounted_path}" || \
153 die "Could not mount ${source} on ${mounted_path}"
154 fi
155}
156
Zdenek Behane28239d2011-04-07 00:37:20 +0200157function env_sync_proc {
158 # This function runs and performs periodic updates to the chroot env, if
159 # necessary.
160
161 local poll_interval=10
162 local sync_files="etc/resolv.conf etc/hosts"
163
164 # Make sure the synced files are writable by normal user, so that we
165 # don't have to sudo inside the loop.
166 for file in ${sync_files}; do
167 sudo chown ${USER} ${FLAGS_chroot}/${file} 1>&2
168 done
169
170 while true; do
171 # Sync files
172 for file in ${sync_files}; do
173 if ! cmp /${file} ${FLAGS_chroot}/${file} &> /dev/null; then
174 cp -f /${file} ${FLAGS_chroot}/${file}
175 fi
176 done
177
178 sleep ${poll_interval}
179 done
180}
181
Vadim Bendebury0779f522011-06-12 12:09:16 -0700182function copy_ssh_config {
183 # Copy user .ssh/config into the chroot filtering out strings not supported
184 # by the chroot ssh. The chroot .ssh directory is passed in as the first
185 # parameter.
186
187 # ssh options to filter out. The entire strings containing these substrings
188 # will be deleted before copying.
189 local bad_options=(
190 'UseProxyIf='
191 'GSSAPIAuthentication no'
192 )
193 local sshc="${HOME}/.ssh/config"
194 local chroot_ssh_dir="${1}"
195 local filter
196 local option
197
198 if [ ! -f "${sshc}" ]; then
199 return # Nothing to copy.
200 fi
201
202 for option in "${bad_options[@]}"
203 do
204 if [ -z "${filter}" ]; then
205 filter="${option}"
206 else
207 filter+="\\|${option}"
208 fi
209 done
210
211 sed "/^.*\(${filter}\).*$/d" "${sshc}" > "${chroot_ssh_dir}/config"
212}
213
rspangler@google.comd74220d2009-10-09 20:56:14 +0000214function setup_env {
Doug Andersona8d9cc12011-02-02 15:47:00 -0800215 # Validate sudo timestamp before entering the critical section so that we
216 # don't stall for a password while we have the lockfile.
Doug Anderson3d7fa3a2011-02-02 16:10:34 -0800217 # Don't use sudo -v since that has issues on machines w/ no password.
218 sudo echo "" > /dev/null
Doug Andersona8d9cc12011-02-02 15:47:00 -0800219
Zdenek Behane28239d2011-04-07 00:37:20 +0200220 # Syncer proc, but only the first time
221 if ! [ -f "${SYNCERPIDFILE}" ] || \
222 ! [ -d /proc/$(cat "${SYNCERPIDFILE}") ]; then
223 debug "Starting sync process"
224 env_sync_proc &
225 echo $! > "${SYNCERPIDFILE}"
226 disown $!
227 fi
228
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800229 (
230 flock 200
231 echo $$ >> "$LOCKFILE"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000232
Don Garretta0e7ea12011-02-07 18:39:59 -0800233 debug "Mounting chroot environment."
David Rochberg351a76f2011-02-16 11:14:00 -0500234 ensure_mounted none "-t proc" /proc
235 ensure_mounted none "-t sysfs" /sys
236 ensure_mounted /dev "--bind" /dev
237 ensure_mounted none "-t devpts" /dev/pts
238 ensure_mounted "${FLAGS_trunk}" "--bind" "${CHROOT_TRUNK_DIR}"
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800239
Elly Jones7990a062010-09-02 09:23:23 -0400240 if [ $FLAGS_ssh_agent -eq $FLAGS_TRUE ]; then
241 TARGET_DIR="$(readlink -f "${FLAGS_chroot}/home/${USER}/.ssh")"
Greg Spencer798d75f2011-02-01 22:04:49 -0800242 if [ -n "${SSH_AUTH_SOCK}" -a -d "${HOME}/.ssh" ]; then
Elly Jones7990a062010-09-02 09:23:23 -0400243 mkdir -p "${TARGET_DIR}"
244 cp -r "${HOME}/.ssh/known_hosts" "${TARGET_DIR}"
Elly Jones39ba1e52011-06-30 11:08:28 -0400245 cp -r ${HOME}/.ssh/*.pub "${TARGET_DIR}"
Vadim Bendebury0779f522011-06-12 12:09:16 -0700246 copy_ssh_config "${TARGET_DIR}"
Elly Jones7990a062010-09-02 09:23:23 -0400247 ASOCK="$(dirname "${SSH_AUTH_SOCK}")"
David Rochberg351a76f2011-02-16 11:14:00 -0500248 ensure_mounted "${ASOCK}" "--bind" "${ASOCK}"
Elly Jones7990a062010-09-02 09:23:23 -0400249 fi
250 fi
251
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800252 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")"
Greg Spencer798d75f2011-02-01 22:04:49 -0800253 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
Andrew de los Reyesc1e8d272010-02-13 12:39:21 -0800254 ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")"
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800255 if [ -z "$CHROME_ROOT" ]; then
256 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \
257 2>/dev/null)"
Don Garretta0e7ea12011-02-07 18:39:59 -0800258 CHROME_ROOT_AUTO=1
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800259 fi
Don Garretta0e7ea12011-02-07 18:39:59 -0800260 if [[ ( -n "$CHROME_ROOT" ) ]]; then
261 if [[ ( ! -d "${CHROME_ROOT}/src" ) ]]; then
262 error "Not mounting chrome source"
263 sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}"
264 if [[ ! "$CHROME_ROOT_AUTO" ]]; then
265 exit 1
266 fi
267 else
268 debug "Mounting chrome source at: $INNER_CHROME_ROOT"
269 sudo bash -c "echo '$CHROME_ROOT' > \
270 '${FLAGS_chroot}${CHROME_ROOT_CONFIG}'"
271 mkdir -p "$MOUNTED_PATH"
272 sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \
273 die "Could not mount $MOUNTED_PATH"
274 fi
Andrew de los Reyes6d0ca162010-02-12 14:36:08 -0800275 fi
276 fi
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800277
278 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")"
Greg Spencer798d75f2011-02-01 22:04:49 -0800279 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800280 if [ $(which gclient 2>/dev/null) ]; then
Don Garretta0e7ea12011-02-07 18:39:59 -0800281 debug "Mounting depot_tools"
Greg Spencer798d75f2011-02-01 22:04:49 -0800282 DEPOT_TOOLS=$(dirname "$(which gclient)")
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800283 mkdir -p "$MOUNTED_PATH"
Andrew de los Reyese8b63152010-02-16 14:18:34 -0800284 if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then
Sean Ocd8b1d12010-09-02 17:34:49 +0200285 warn "depot_tools failed to mount; perhaps it's on NFS?"
286 warn "This may impact chromium build."
Andrew de los Reyese8b63152010-02-16 14:18:34 -0800287 fi
Andrew de los Reyes5d0248f2010-02-12 16:12:31 -0800288 fi
Chris Sosa317d8eb2010-04-05 15:45:28 -0700289 fi
290
robotboy152a1ab2010-04-26 14:07:27 -0700291 # Install fuse module.
Greg Spencer798d75f2011-02-01 22:04:49 -0800292 if [ -c "${FUSE_DEVICE}" ]; then
Chris Sosa317d8eb2010-04-05 15:45:28 -0700293 sudo modprobe fuse 2> /dev/null ||\
Sean Ocd8b1d12010-09-02 17:34:49 +0200294 warn "-- Note: modprobe fuse failed. gmergefs will not work"
Chris Sosa317d8eb2010-04-05 15:45:28 -0700295 fi
296
Chris Masone162f6542010-05-12 14:58:37 -0700297 # Turn off automounting of external media when we enter the
298 # chroot; thus we don't have to worry about being able to unmount
299 # from inside.
300 if [ $(which gconftool-2 2>/dev/null) ]; then
301 gconftool-2 -g ${AUTOMOUNT_PREF} > \
302 "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}"
303 if [ $(gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} false) ]; then
Sean Ocd8b1d12010-09-02 17:34:49 +0200304 warn "-- Note: USB sticks may be automounted by your host OS."
305 warn "-- Note: If you plan to burn bootable media, you may need to"
306 warn "-- Note: unmount these devices manually, or run image_to_usb.sh"
307 warn "-- Note: outside the chroot."
Chris Masone162f6542010-05-12 14:58:37 -0700308 fi
309 fi
310
Dale Curtis98631732011-05-05 16:16:59 -0700311 # Fix permissions on shared memory to allow non-root users access to POSIX
312 # semaphores.
313 sudo chmod -R 777 "${FLAGS_chroot}/dev/shm"
David James546747b2010-03-23 15:19:43 -0700314 ) 200>>"$LOCKFILE" || die "setup_env failed"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000315}
316
317function teardown_env {
Doug Andersona8d9cc12011-02-02 15:47:00 -0800318 # Validate sudo timestamp before entering the critical section so that we
319 # don't stall for a password while we have the lockfile.
Doug Anderson3d7fa3a2011-02-02 16:10:34 -0800320 # Don't use sudo -v since that has issues on machines w/ no password.
321 sudo echo "" > /dev/null
Doug Andersona8d9cc12011-02-02 15:47:00 -0800322
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800323 # Only teardown if we're the last enter_chroot to die
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800324 (
325 flock 200
326
327 # check each pid in $LOCKFILE to see if it's died unexpectedly
328 TMP_LOCKFILE="$LOCKFILE.tmp"
329
330 echo -n > "$TMP_LOCKFILE" # Erase/reset temp file
331 cat "$LOCKFILE" | while read PID; do
332 if [ "$PID" = "$$" ]; then
333 # ourself, leave PROC_NAME empty
334 PROC_NAME=""
335 else
336 PROC_NAME=$(ps --pid $PID -o comm=)
337 fi
338
339 if [ ! -z "$PROC_NAME" ]; then
340 # All good, keep going
341 echo "$PID" >> "$TMP_LOCKFILE"
342 fi
343 done
344 # Remove any dups from lock file while installing new one
345 sort -n "$TMP_LOCKFILE" | uniq > "$LOCKFILE"
346
Chris Masone162f6542010-05-12 14:58:37 -0700347 if [ $(which gconftool-2 2>/dev/null) ]; then
348 SAVED_PREF=$(cat "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}")
349 gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \
Sean Ocd8b1d12010-09-02 17:34:49 +0200350 warn "could not re-set your automount preference."
Chris Masone162f6542010-05-12 14:58:37 -0700351 fi
352
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800353 if [ -s "$LOCKFILE" ]; then
Don Garretta0e7ea12011-02-07 18:39:59 -0800354 debug "At least one other pid is running in the chroot, so not"
355 debug "tearing down env."
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800356 else
Zdenek Behane28239d2011-04-07 00:37:20 +0200357 debug "Stopping syncer process"
358 kill $(cat "${SYNCERPIDFILE}")
359
David James546747b2010-03-23 15:19:43 -0700360 MOUNTED_PATH=$(readlink -f "$FLAGS_chroot")
Don Garretta0e7ea12011-02-07 18:39:59 -0800361 debug "Unmounting chroot environment."
Zdenek Behan6f17b5e2010-06-10 16:50:52 -0700362 # sort the list of mounts in reverse order, to ensure umount of
363 # cascading mounts in proper order
364 for i in \
365 $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do
robotboy98912212010-04-12 14:08:14 -0700366 safe_umount "$i"
David James546747b2010-03-23 15:19:43 -0700367 done
Andrew de los Reyesc9317ea2010-02-10 13:16:36 -0800368 fi
David James546747b2010-03-23 15:19:43 -0700369 ) 200>>"$LOCKFILE" || die "teardown_env failed"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000370}
371
Greg Spencer798d75f2011-02-01 22:04:49 -0800372if [ $FLAGS_mount -eq $FLAGS_TRUE ]; then
rspangler@google.comd74220d2009-10-09 20:56:14 +0000373 setup_env
Don Garretta0e7ea12011-02-07 18:39:59 -0800374 info "Make sure you run"
375 info " $0 --unmount"
376 info "before deleting $FLAGS_chroot"
377 info "or you'll end up deleting $FLAGS_trunk too!"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000378 exit 0
379fi
380
Greg Spencer798d75f2011-02-01 22:04:49 -0800381if [ $FLAGS_unmount -eq $FLAGS_TRUE ]; then
rspangler@google.comd74220d2009-10-09 20:56:14 +0000382 teardown_env
383 exit 0
384fi
385
386# Make sure we unmount before exiting
387trap teardown_env EXIT
388setup_env
389
Darin Petkov87dd2be2011-03-01 09:25:09 -0800390CHROOT_PASSTHRU="BUILDBOT_BUILD=$FLAGS_build_number CHROMEOS_OFFICIAL=$CHROMEOS_OFFICIAL"
Raja Aluri8f2a9952010-11-17 15:03:00 -0800391CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \
392CHROMEOS_RELEASE_APPID=${CHROMEOS_RELEASE_APPID:-"{DEV-BUILD}"}"
Raja Alurie891eea2010-11-16 20:12:56 -0800393
Liam McLoughlin3b11b452011-03-14 16:04:07 -0700394# Set CHROMEOS_VERSION_TRACK, CHROMEOS_VERSION_AUSERVER,
395# CHROMEOS_VERSION_DEVSERVER as environment variables to override the default
396# assumptions (local AU server). These are used in cros_set_lsb_release, and
397# are used by external Chromium OS builders.
398CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \
399CHROMEOS_VERSION_TRACK=${CHROMEOS_VERSION_TRACK} \
400CHROMEOS_VERSION_AUSERVER=${CHROMEOS_VERSION_AUSERVER} \
401CHROMEOS_VERSION_DEVSERVER=${CHROMEOS_VERSION_DEVSERVER}"
402
Mario Limonciello7052ae12011-05-05 12:00:49 -0500403# Pass proxy variables into the environment.
404for type in http_proxy ftp_proxy all_proxy GIT_PROXY_COMMAND GIT_SSH; do
405 eval value=\$${type}
406 if [ -n "${value}" ]; then
407 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} ${type}=${value}"
408 fi
409done
410
Raja Aluri32759cf2010-08-30 18:44:39 -0700411if [ -d "$HOME/.subversion" ]; then
David Rochberg351a76f2011-02-16 11:14:00 -0500412 TARGET="/home/${USER}/.subversion"
413 mkdir -p "${FLAGS_chroot}${TARGET}"
414 ensure_mounted "${HOME}/.subversion" "--bind" "${TARGET}"
Raja Aluri32759cf2010-08-30 18:44:39 -0700415fi
rspangler@google.comd74220d2009-10-09 20:56:14 +0000416
David James0fd8af42010-09-27 10:04:57 -0700417# Configure committer username and email in chroot .gitconfig
Chris Sosa9d30ce82011-03-14 15:00:46 -0700418git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \
419 user.name "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/ *<.*//')" ||
420 true
421git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \
422 user.email "$(cd /tmp; git var GIT_COMMITTER_IDENT | \
423 sed -e 's/.*<\([^>]*\)>.*/\1/')" ||
424 true
David James0fd8af42010-09-27 10:04:57 -0700425
derat@google.com4e7a92b2009-11-21 23:44:14 +0000426# Run command or interactive shell. Also include the non-chrooted path to
427# the source trunk for scripts that may need to print it (e.g.
428# build_image.sh).
Doug Anderson9362fa82010-12-16 14:44:12 -0800429sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \
Elly Jones7990a062010-09-02 09:23:23 -0400430 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \
Doug Anderson9362fa82010-12-16 14:44:12 -0800431 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@"
rspangler@google.comd74220d2009-10-09 20:56:14 +0000432
433# Remove trap and explicitly unmount
434trap - EXIT
435teardown_env