rspangler@google.com | d74220d | 2009-10-09 20:56:14 +0000 | [diff] [blame] | 1 | #!/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 | |
| 9 | # Load common constants. This should be the first executable line. |
| 10 | # The path to common.sh should be relative to your script's location. |
| 11 | . "$(dirname "$0")/common.sh" |
| 12 | |
derat@google.com | 86dcc8e | 2009-11-21 19:49:49 +0000 | [diff] [blame] | 13 | # Script must be run outside the chroot and as a regular user. |
rspangler@google.com | d74220d | 2009-10-09 20:56:14 +0000 | [diff] [blame] | 14 | assert_outside_chroot |
derat@google.com | 86dcc8e | 2009-11-21 19:49:49 +0000 | [diff] [blame] | 15 | assert_not_root_user |
rspangler@google.com | d74220d | 2009-10-09 20:56:14 +0000 | [diff] [blame] | 16 | |
| 17 | # Define command line flags |
| 18 | # See http://code.google.com/p/shflags/wiki/Documentation10x |
| 19 | DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \ |
| 20 | "The destination dir for the chroot environment." "d" |
| 21 | DEFINE_string trunk "$GCLIENT_ROOT" \ |
| 22 | "The source trunk to bind mount within the chroot." "s" |
David McMahon | 03aeb20 | 2009-12-08 12:47:08 -0800 | [diff] [blame] | 23 | DEFINE_string build_number "" \ |
| 24 | "The build-bot build number (when called by buildbot only)." "b" |
Andrew de los Reyes | 6d0ca16 | 2010-02-12 14:36:08 -0800 | [diff] [blame] | 25 | DEFINE_string chrome_root "" \ |
| 26 | "The root of your chrome browser source. Should contain a 'src' subdir." |
Sean Parent | 2898f75 | 2010-05-25 15:06:33 -0700 | [diff] [blame] | 27 | DEFINE_string chrome_root_mount "/home/$USER/chrome_root" \ |
| 28 | "The mount point of the chrome broswer source in the chroot." |
rspangler@google.com | d74220d | 2009-10-09 20:56:14 +0000 | [diff] [blame] | 29 | |
Chris Sosa | aa1a7fd | 2010-04-02 14:06:29 -0700 | [diff] [blame] | 30 | DEFINE_boolean official_build $FLAGS_FALSE \ |
| 31 | "Set CHROMEOS_OFFICIAL=1 for release builds." |
rspangler@google.com | d74220d | 2009-10-09 20:56:14 +0000 | [diff] [blame] | 32 | DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts." |
| 33 | DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts." |
Elly Jones | 7990a06 | 2010-09-02 09:23:23 -0400 | [diff] [blame^] | 34 | DEFINE_boolean ssh_agent $FLAGS_TRUE "Import ssh agent." |
rspangler@google.com | d74220d | 2009-10-09 20:56:14 +0000 | [diff] [blame] | 35 | |
| 36 | # More useful help |
| 37 | FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- \"command\"] |
| 38 | |
| 39 | One or more VAR=value pairs can be specified to export variables into |
| 40 | the chroot environment. For example: |
| 41 | |
| 42 | $0 FOO=bar BAZ=bel |
| 43 | |
| 44 | If [-- \"command\"] is present, runs the command inside the chroot, |
| 45 | after changing directory to /$USER/trunk/src/scripts. Note that the |
| 46 | command should be enclosed in quotes to prevent interpretation by the |
| 47 | shell before getting into the chroot. For example: |
| 48 | |
| 49 | $0 -- \"./build_platform_packages.sh\" |
| 50 | |
| 51 | Otherwise, provides an interactive shell. |
| 52 | " |
| 53 | |
| 54 | # Parse command line flags |
| 55 | FLAGS "$@" || exit 1 |
| 56 | eval set -- "${FLAGS_ARGV}" |
| 57 | |
David McMahon | 857dbb5 | 2009-12-09 18:21:05 -0800 | [diff] [blame] | 58 | if [ $FLAGS_official_build -eq $FLAGS_TRUE ] |
| 59 | then |
| 60 | CHROMEOS_OFFICIAL=1 |
| 61 | fi |
| 62 | |
rspangler@google.com | d74220d | 2009-10-09 20:56:14 +0000 | [diff] [blame] | 63 | # Only now can we die on error. shflags functions leak non-zero error codes, |
| 64 | # so will die prematurely if 'set -e' is specified before now. |
| 65 | # TODO: replace shflags with something less error-prone, or contribute a fix. |
| 66 | set -e |
| 67 | |
Sean Parent | 2898f75 | 2010-05-25 15:06:33 -0700 | [diff] [blame] | 68 | INNER_CHROME_ROOT=$FLAGS_chrome_root_mount # inside chroot |
Andrew de los Reyes | 6d0ca16 | 2010-02-12 14:36:08 -0800 | [diff] [blame] | 69 | CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot |
Andrew de los Reyes | 5d0248f | 2010-02-12 16:12:31 -0800 | [diff] [blame] | 70 | INNER_DEPOT_TOOLS_ROOT="/home/$USER/depot_tools" # inside chroot |
Chris Sosa | aa1a7fd | 2010-04-02 14:06:29 -0700 | [diff] [blame] | 71 | FUSE_DEVICE="/dev/fuse" |
Chris Masone | 162f654 | 2010-05-12 14:58:37 -0700 | [diff] [blame] | 72 | AUTOMOUNT_PREF="/apps/nautilus/preferences/media_automount" |
| 73 | SAVED_AUTOMOUNT_PREF_FILE="/tmp/.automount_pref" |
Andrew de los Reyes | 6d0ca16 | 2010-02-12 14:36:08 -0800 | [diff] [blame] | 74 | |
Andrew de los Reyes | c9317ea | 2010-02-10 13:16:36 -0800 | [diff] [blame] | 75 | sudo chmod 0777 "$FLAGS_chroot/var/lock" |
| 76 | |
| 77 | LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" |
| 78 | |
rspangler@google.com | d74220d | 2009-10-09 20:56:14 +0000 | [diff] [blame] | 79 | function setup_env { |
Andrew de los Reyes | c9317ea | 2010-02-10 13:16:36 -0800 | [diff] [blame] | 80 | ( |
| 81 | flock 200 |
| 82 | echo $$ >> "$LOCKFILE" |
rspangler@google.com | d74220d | 2009-10-09 20:56:14 +0000 | [diff] [blame] | 83 | |
Sean O'Connor | d52c5ea | 2010-08-18 21:18:23 +0200 | [diff] [blame] | 84 | echo >&2 "Mounting chroot environment." |
rspangler@google.com | d74220d | 2009-10-09 20:56:14 +0000 | [diff] [blame] | 85 | |
Andrew de los Reyes | c9317ea | 2010-02-10 13:16:36 -0800 | [diff] [blame] | 86 | # Mount only if not already mounted |
| 87 | MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" |
David James | 546747b | 2010-03-23 15:19:43 -0700 | [diff] [blame] | 88 | if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
Andrew de los Reyes | c9317ea | 2010-02-10 13:16:36 -0800 | [diff] [blame] | 89 | then |
David James | 546747b | 2010-03-23 15:19:43 -0700 | [diff] [blame] | 90 | sudo mount none -t proc "$MOUNTED_PATH" || \ |
| 91 | die "Could not mount $MOUNTED_PATH" |
Andrew de los Reyes | c9317ea | 2010-02-10 13:16:36 -0800 | [diff] [blame] | 92 | fi |
rspangler@google.com | d74220d | 2009-10-09 20:56:14 +0000 | [diff] [blame] | 93 | |
Antoine Labour | e9e585f | 2010-04-01 15:57:57 -0700 | [diff] [blame] | 94 | MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/sys")" |
| 95 | if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
| 96 | then |
| 97 | sudo mount none -t sysfs "$MOUNTED_PATH" || \ |
| 98 | die "Could not mount $MOUNTED_PATH" |
| 99 | fi |
| 100 | |
robotboy | 152a1ab | 2010-04-26 14:07:27 -0700 | [diff] [blame] | 101 | MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev")" |
David James | 546747b | 2010-03-23 15:19:43 -0700 | [diff] [blame] | 102 | if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
Andrew de los Reyes | c9317ea | 2010-02-10 13:16:36 -0800 | [diff] [blame] | 103 | then |
robotboy | 152a1ab | 2010-04-26 14:07:27 -0700 | [diff] [blame] | 104 | sudo mount --bind /dev "$MOUNTED_PATH" || \ |
David James | 546747b | 2010-03-23 15:19:43 -0700 | [diff] [blame] | 105 | die "Could not mount $MOUNTED_PATH" |
Andrew de los Reyes | c9317ea | 2010-02-10 13:16:36 -0800 | [diff] [blame] | 106 | fi |
| 107 | |
Elly Jones | 7990a06 | 2010-09-02 09:23:23 -0400 | [diff] [blame^] | 108 | if [ $FLAGS_ssh_agent -eq $FLAGS_TRUE ]; then |
| 109 | TARGET_DIR="$(readlink -f "${FLAGS_chroot}/home/${USER}/.ssh")" |
| 110 | if [ -n "${SSH_AUTH_SOCK}" \ |
| 111 | -a -d "${HOME}/.ssh" ] |
| 112 | then |
| 113 | mkdir -p "${TARGET_DIR}" |
| 114 | cp -r "${HOME}/.ssh/known_hosts" "${TARGET_DIR}" |
| 115 | ASOCK="$(dirname "${SSH_AUTH_SOCK}")" |
| 116 | mkdir -p "${FLAGS_chroot}/${ASOCK}" |
| 117 | sudo mount --bind "${ASOCK}" "${FLAGS_chroot}/${ASOCK}" || \ |
| 118 | die "Count not mount ${ASOCK}" |
| 119 | fi |
| 120 | fi |
| 121 | |
Zdenek Behan | 6f17b5e | 2010-06-10 16:50:52 -0700 | [diff] [blame] | 122 | MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev/pts")" |
| 123 | if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
| 124 | then |
| 125 | sudo mount none -t devpts "$MOUNTED_PATH" || \ |
| 126 | die "Could not mount $MOUNTED_PATH" |
| 127 | fi |
| 128 | |
Andrew de los Reyes | c9317ea | 2010-02-10 13:16:36 -0800 | [diff] [blame] | 129 | MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}$CHROOT_TRUNK_DIR")" |
David James | 546747b | 2010-03-23 15:19:43 -0700 | [diff] [blame] | 130 | if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
Andrew de los Reyes | c9317ea | 2010-02-10 13:16:36 -0800 | [diff] [blame] | 131 | then |
David James | 546747b | 2010-03-23 15:19:43 -0700 | [diff] [blame] | 132 | sudo mount --bind "$FLAGS_trunk" "$MOUNTED_PATH" || \ |
| 133 | die "Could not mount $MOUNTED_PATH" |
Andrew de los Reyes | c9317ea | 2010-02-10 13:16:36 -0800 | [diff] [blame] | 134 | fi |
Andrew de los Reyes | 6d0ca16 | 2010-02-12 14:36:08 -0800 | [diff] [blame] | 135 | |
| 136 | MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" |
David James | 546747b | 2010-03-23 15:19:43 -0700 | [diff] [blame] | 137 | if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
Andrew de los Reyes | 6d0ca16 | 2010-02-12 14:36:08 -0800 | [diff] [blame] | 138 | then |
Andrew de los Reyes | c1e8d27 | 2010-02-13 12:39:21 -0800 | [diff] [blame] | 139 | ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")" |
Andrew de los Reyes | 6d0ca16 | 2010-02-12 14:36:08 -0800 | [diff] [blame] | 140 | if [ -z "$CHROME_ROOT" ]; then |
| 141 | ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \ |
| 142 | 2>/dev/null)" |
| 143 | fi |
| 144 | if [[ ( -z "$CHROME_ROOT" ) || ( ! -d "${CHROME_ROOT}/src" ) ]]; then |
Sean O'Connor | d52c5ea | 2010-08-18 21:18:23 +0200 | [diff] [blame] | 145 | echo >&2 "Not mounting chrome source" |
Andrew de los Reyes | 6d0ca16 | 2010-02-12 14:36:08 -0800 | [diff] [blame] | 146 | sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" |
| 147 | else |
Sean O'Connor | d52c5ea | 2010-08-18 21:18:23 +0200 | [diff] [blame] | 148 | echo >&2 "Mounting chrome source at: $INNER_CHROME_ROOT" |
Andrew de los Reyes | 6d0ca16 | 2010-02-12 14:36:08 -0800 | [diff] [blame] | 149 | echo "$CHROME_ROOT" | \ |
| 150 | sudo dd of="${FLAGS_chroot}${CHROME_ROOT_CONFIG}" |
| 151 | mkdir -p "$MOUNTED_PATH" |
David James | 546747b | 2010-03-23 15:19:43 -0700 | [diff] [blame] | 152 | sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \ |
| 153 | die "Could not mount $MOUNTED_PATH" |
Andrew de los Reyes | 6d0ca16 | 2010-02-12 14:36:08 -0800 | [diff] [blame] | 154 | fi |
| 155 | fi |
Andrew de los Reyes | 5d0248f | 2010-02-12 16:12:31 -0800 | [diff] [blame] | 156 | |
| 157 | MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")" |
David James | 546747b | 2010-03-23 15:19:43 -0700 | [diff] [blame] | 158 | if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
Andrew de los Reyes | 5d0248f | 2010-02-12 16:12:31 -0800 | [diff] [blame] | 159 | then |
| 160 | if [ $(which gclient 2>/dev/null) ]; then |
Sean O'Connor | d52c5ea | 2010-08-18 21:18:23 +0200 | [diff] [blame] | 161 | echo >&2 "Mounting depot_tools" |
Andrew de los Reyes | 5d0248f | 2010-02-12 16:12:31 -0800 | [diff] [blame] | 162 | DEPOT_TOOLS=$(dirname $(which gclient) ) |
| 163 | mkdir -p "$MOUNTED_PATH" |
Andrew de los Reyes | e8b6315 | 2010-02-16 14:18:34 -0800 | [diff] [blame] | 164 | if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then |
Sean O'Connor | d52c5ea | 2010-08-18 21:18:23 +0200 | [diff] [blame] | 165 | echo >&2 "depot_tools failed to mount; perhaps it's on NFS?" |
| 166 | echo >&2 "This may impact chromium build." |
Andrew de los Reyes | e8b6315 | 2010-02-16 14:18:34 -0800 | [diff] [blame] | 167 | fi |
Andrew de los Reyes | 5d0248f | 2010-02-12 16:12:31 -0800 | [diff] [blame] | 168 | fi |
Chris Sosa | 317d8eb | 2010-04-05 15:45:28 -0700 | [diff] [blame] | 169 | fi |
| 170 | |
robotboy | 152a1ab | 2010-04-26 14:07:27 -0700 | [diff] [blame] | 171 | # Install fuse module. |
| 172 | if [ -c "${FUSE_DEVICE}" ] ; then |
Chris Sosa | 317d8eb | 2010-04-05 15:45:28 -0700 | [diff] [blame] | 173 | sudo modprobe fuse 2> /dev/null ||\ |
Sean O'Connor | d52c5ea | 2010-08-18 21:18:23 +0200 | [diff] [blame] | 174 | echo >&2 "-- Note: modprobe fuse failed. gmergefs will not work" |
Chris Sosa | 317d8eb | 2010-04-05 15:45:28 -0700 | [diff] [blame] | 175 | fi |
| 176 | |
Chris Masone | 162f654 | 2010-05-12 14:58:37 -0700 | [diff] [blame] | 177 | # Turn off automounting of external media when we enter the |
| 178 | # chroot; thus we don't have to worry about being able to unmount |
| 179 | # from inside. |
| 180 | if [ $(which gconftool-2 2>/dev/null) ]; then |
| 181 | gconftool-2 -g ${AUTOMOUNT_PREF} > \ |
| 182 | "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}" |
| 183 | if [ $(gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} false) ]; then |
Sean O'Connor | d52c5ea | 2010-08-18 21:18:23 +0200 | [diff] [blame] | 184 | echo >&2 "-- Note: USB sticks may be automounted by your host OS." |
| 185 | echo >&2 "-- Note: If you plan to burn bootable media, you may need to" |
| 186 | echo >&2 "-- Note: unmount these devices manually, or run image_to_usb.sh" |
| 187 | echo >&2 "-- Note: outside the chroot." |
Chris Masone | 162f654 | 2010-05-12 14:58:37 -0700 | [diff] [blame] | 188 | fi |
| 189 | fi |
| 190 | |
David James | 546747b | 2010-03-23 15:19:43 -0700 | [diff] [blame] | 191 | ) 200>>"$LOCKFILE" || die "setup_env failed" |
rspangler@google.com | d74220d | 2009-10-09 20:56:14 +0000 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | function teardown_env { |
Andrew de los Reyes | c9317ea | 2010-02-10 13:16:36 -0800 | [diff] [blame] | 195 | # Only teardown if we're the last enter_chroot to die |
Andrew de los Reyes | c9317ea | 2010-02-10 13:16:36 -0800 | [diff] [blame] | 196 | ( |
| 197 | flock 200 |
| 198 | |
| 199 | # check each pid in $LOCKFILE to see if it's died unexpectedly |
| 200 | TMP_LOCKFILE="$LOCKFILE.tmp" |
| 201 | |
| 202 | echo -n > "$TMP_LOCKFILE" # Erase/reset temp file |
| 203 | cat "$LOCKFILE" | while read PID; do |
| 204 | if [ "$PID" = "$$" ]; then |
| 205 | # ourself, leave PROC_NAME empty |
| 206 | PROC_NAME="" |
| 207 | else |
| 208 | PROC_NAME=$(ps --pid $PID -o comm=) |
| 209 | fi |
| 210 | |
| 211 | if [ ! -z "$PROC_NAME" ]; then |
| 212 | # All good, keep going |
| 213 | echo "$PID" >> "$TMP_LOCKFILE" |
| 214 | fi |
| 215 | done |
| 216 | # Remove any dups from lock file while installing new one |
| 217 | sort -n "$TMP_LOCKFILE" | uniq > "$LOCKFILE" |
| 218 | |
Chris Masone | 162f654 | 2010-05-12 14:58:37 -0700 | [diff] [blame] | 219 | if [ $(which gconftool-2 2>/dev/null) ]; then |
| 220 | SAVED_PREF=$(cat "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}") |
| 221 | gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \ |
Sean O'Connor | d52c5ea | 2010-08-18 21:18:23 +0200 | [diff] [blame] | 222 | echo >&2 "could not re-set your automount preference." |
Chris Masone | 162f654 | 2010-05-12 14:58:37 -0700 | [diff] [blame] | 223 | fi |
| 224 | |
Andrew de los Reyes | c9317ea | 2010-02-10 13:16:36 -0800 | [diff] [blame] | 225 | if [ -s "$LOCKFILE" ]; then |
Sean O'Connor | d52c5ea | 2010-08-18 21:18:23 +0200 | [diff] [blame] | 226 | echo >&2 "At least one other pid is running in the chroot, so not" |
| 227 | echo >&2 "tearing down env." |
Andrew de los Reyes | c9317ea | 2010-02-10 13:16:36 -0800 | [diff] [blame] | 228 | else |
David James | 546747b | 2010-03-23 15:19:43 -0700 | [diff] [blame] | 229 | MOUNTED_PATH=$(readlink -f "$FLAGS_chroot") |
Sean O'Connor | d52c5ea | 2010-08-18 21:18:23 +0200 | [diff] [blame] | 230 | echo >&2 "Unmounting chroot environment." |
Zdenek Behan | 6f17b5e | 2010-06-10 16:50:52 -0700 | [diff] [blame] | 231 | # sort the list of mounts in reverse order, to ensure umount of |
| 232 | # cascading mounts in proper order |
| 233 | for i in \ |
| 234 | $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do |
robotboy | 9891221 | 2010-04-12 14:08:14 -0700 | [diff] [blame] | 235 | safe_umount "$i" |
David James | 546747b | 2010-03-23 15:19:43 -0700 | [diff] [blame] | 236 | done |
Andrew de los Reyes | c9317ea | 2010-02-10 13:16:36 -0800 | [diff] [blame] | 237 | fi |
David James | 546747b | 2010-03-23 15:19:43 -0700 | [diff] [blame] | 238 | ) 200>>"$LOCKFILE" || die "teardown_env failed" |
rspangler@google.com | d74220d | 2009-10-09 20:56:14 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | if [ $FLAGS_mount -eq $FLAGS_TRUE ] |
| 242 | then |
| 243 | setup_env |
Sean O'Connor | d52c5ea | 2010-08-18 21:18:23 +0200 | [diff] [blame] | 244 | echo >&2 "Make sure you run" |
| 245 | echo >&2 " $0 --unmount" |
| 246 | echo >&2 "before deleting $FLAGS_chroot" |
| 247 | echo >&2 "or you'll end up deleting $FLAGS_trunk too!" |
rspangler@google.com | d74220d | 2009-10-09 20:56:14 +0000 | [diff] [blame] | 248 | exit 0 |
| 249 | fi |
| 250 | |
| 251 | if [ $FLAGS_unmount -eq $FLAGS_TRUE ] |
| 252 | then |
| 253 | teardown_env |
| 254 | exit 0 |
| 255 | fi |
| 256 | |
| 257 | # Make sure we unmount before exiting |
| 258 | trap teardown_env EXIT |
| 259 | setup_env |
| 260 | |
David McMahon | 03aeb20 | 2009-12-08 12:47:08 -0800 | [diff] [blame] | 261 | # Get the git revision to pass into the chroot. |
| 262 | # |
| 263 | # This must be determined outside the chroot because (1) there is no |
| 264 | # git inside the chroot, and (2) if there were it would likely be |
| 265 | # the wrong version, which would mess up the .git directories. |
| 266 | # |
| 267 | # Note that this fixes $CHROMEOS_REVISION at the time the chroot is |
| 268 | # entered. That's ok for the main use case of automated builds, |
| 269 | # which pass each command line into a separate call to enter_chroot |
David McMahon | 857dbb5 | 2009-12-09 18:21:05 -0800 | [diff] [blame] | 270 | # so always have up-to-date info. For developer builds, there may not |
| 271 | # be a single revision, since the developer may have |
David McMahon | 03aeb20 | 2009-12-08 12:47:08 -0800 | [diff] [blame] | 272 | # hand-sync'd some subdirs and edited files in others. |
David McMahon | 857dbb5 | 2009-12-09 18:21:05 -0800 | [diff] [blame] | 273 | # In that case, check against origin/HEAD and mark** revision. |
David McMahon | 03aeb20 | 2009-12-08 12:47:08 -0800 | [diff] [blame] | 274 | # Use git:8 chars of sha1 |
Anush Elangovan | 587d749 | 2010-06-10 15:39:19 -0700 | [diff] [blame] | 275 | REVISION=$(git rev-parse --short=8 HEAD) |
David McMahon | 857dbb5 | 2009-12-09 18:21:05 -0800 | [diff] [blame] | 276 | CHROOT_PASSTHRU="CHROMEOS_REVISION=$REVISION BUILDBOT_BUILD=$FLAGS_build_number CHROMEOS_OFFICIAL=$CHROMEOS_OFFICIAL" |
Raja Aluri | 32759cf | 2010-08-30 18:44:39 -0700 | [diff] [blame] | 277 | if [ -d "$HOME/.subversion" ]; then |
| 278 | # Bind mounting .subversion into chroot |
| 279 | echo "mounting ~/.subversion into chroot" |
| 280 | MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/home/${USER}/.subversion")" |
| 281 | if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
| 282 | mkdir -p "$MOUNTED_PATH" |
| 283 | sudo mount --bind "$HOME/.subversion" "$MOUNTED_PATH" || \ |
| 284 | die "Could not mount $MOUNTED_PATH" |
| 285 | fi |
| 286 | fi |
rspangler@google.com | d74220d | 2009-10-09 20:56:14 +0000 | [diff] [blame] | 287 | |
derat@google.com | 4e7a92b | 2009-11-21 23:44:14 +0000 | [diff] [blame] | 288 | # Run command or interactive shell. Also include the non-chrooted path to |
| 289 | # the source trunk for scripts that may need to print it (e.g. |
| 290 | # build_image.sh). |
David McMahon | 857dbb5 | 2009-12-09 18:21:05 -0800 | [diff] [blame] | 291 | sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ |
Elly Jones | 7990a06 | 2010-09-02 09:23:23 -0400 | [diff] [blame^] | 292 | EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ |
| 293 | SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" -- "$@" |
rspangler@google.com | d74220d | 2009-10-09 20:56:14 +0000 | [diff] [blame] | 294 | |
| 295 | # Remove trap and explicitly unmount |
| 296 | trap - EXIT |
| 297 | teardown_env |