OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # Script to enter the chroot environment | 7 # Script to enter the chroot environment |
8 | 8 |
9 # --- BEGIN COMMON.SH BOILERPLATE --- | 9 # --- BEGIN COMMON.SH BOILERPLATE --- |
10 # Load common CrOS utilities. Inside the chroot this file is installed in | 10 # Load common CrOS utilities. Inside the chroot this file is installed in |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 the command nor args should include single quotes. For example: | 66 the command nor args should include single quotes. For example: |
67 | 67 |
68 $0 -- ./build_platform_packages.sh | 68 $0 -- ./build_platform_packages.sh |
69 | 69 |
70 Otherwise, provides an interactive shell. | 70 Otherwise, provides an interactive shell. |
71 " | 71 " |
72 | 72 |
73 # Version of info from common.sh that only echos if --verbose is set. | 73 # Version of info from common.sh that only echos if --verbose is set. |
74 function debug { | 74 function debug { |
75 if [ $FLAGS_verbose -eq $FLAGS_TRUE ]; then | 75 if [ $FLAGS_verbose -eq $FLAGS_TRUE ]; then |
76 info "$*" | 76 info "$1" |
77 fi | 77 fi |
78 } | 78 } |
79 | 79 |
80 # Double up on the first '--' argument. Why? For enter_chroot, we want to | 80 # 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: | 81 # emulate the behavior of sudo for setting environment vars. That is, we want: |
82 # ./enter_chroot [flags] [VAR=val] [-- command] | 82 # ./enter_chroot [flags] [VAR=val] [-- command] |
83 # ...but shflags ends up eating the '--' out of the command line and gives | 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 | 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. | 85 # end up getting what we want back from shflags. |
86 # | 86 # |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot | 125 CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot |
126 INNER_DEPOT_TOOLS_ROOT="/home/$USER/depot_tools" # inside chroot | 126 INNER_DEPOT_TOOLS_ROOT="/home/$USER/depot_tools" # inside chroot |
127 FUSE_DEVICE="/dev/fuse" | 127 FUSE_DEVICE="/dev/fuse" |
128 AUTOMOUNT_PREF="/apps/nautilus/preferences/media_automount" | 128 AUTOMOUNT_PREF="/apps/nautilus/preferences/media_automount" |
129 SAVED_AUTOMOUNT_PREF_FILE="/tmp/.automount_pref" | 129 SAVED_AUTOMOUNT_PREF_FILE="/tmp/.automount_pref" |
130 | 130 |
131 sudo chmod 0777 "$FLAGS_chroot/var/lock" | 131 sudo chmod 0777 "$FLAGS_chroot/var/lock" |
132 | 132 |
133 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" | 133 LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" |
134 | 134 |
135 | |
136 function 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 | |
153 function setup_env { | 135 function setup_env { |
154 # Validate sudo timestamp before entering the critical section so that we | 136 # Validate sudo timestamp before entering the critical section so that we |
155 # don't stall for a password while we have the lockfile. | 137 # don't stall for a password while we have the lockfile. |
156 # Don't use sudo -v since that has issues on machines w/ no password. | 138 # Don't use sudo -v since that has issues on machines w/ no password. |
157 sudo echo "" > /dev/null | 139 sudo echo "" > /dev/null |
158 | 140 |
159 ( | 141 ( |
160 flock 200 | 142 flock 200 |
161 echo $$ >> "$LOCKFILE" | 143 echo $$ >> "$LOCKFILE" |
162 | 144 |
163 debug "Mounting chroot environment." | 145 debug "Mounting chroot environment." |
164 ensure_mounted none "-t proc" /proc | 146 |
165 ensure_mounted none "-t sysfs" /sys | 147 # Mount only if not already mounted |
166 ensure_mounted /dev "--bind" /dev | 148 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" |
167 ensure_mounted none "-t devpts" /dev/pts | 149 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
168 ensure_mounted "${FLAGS_trunk}" "--bind" "${CHROOT_TRUNK_DIR}" | 150 sudo mount none -t proc "$MOUNTED_PATH" || \ |
| 151 die "Could not mount $MOUNTED_PATH" |
| 152 fi |
| 153 |
| 154 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/sys")" |
| 155 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
| 156 sudo mount none -t sysfs "$MOUNTED_PATH" || \ |
| 157 die "Could not mount $MOUNTED_PATH" |
| 158 fi |
| 159 |
| 160 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev")" |
| 161 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
| 162 sudo mount --bind /dev "$MOUNTED_PATH" || \ |
| 163 die "Could not mount $MOUNTED_PATH" |
| 164 fi |
169 | 165 |
170 if [ $FLAGS_ssh_agent -eq $FLAGS_TRUE ]; then | 166 if [ $FLAGS_ssh_agent -eq $FLAGS_TRUE ]; then |
171 TARGET_DIR="$(readlink -f "${FLAGS_chroot}/home/${USER}/.ssh")" | 167 TARGET_DIR="$(readlink -f "${FLAGS_chroot}/home/${USER}/.ssh")" |
172 if [ -n "${SSH_AUTH_SOCK}" -a -d "${HOME}/.ssh" ]; then | 168 if [ -n "${SSH_AUTH_SOCK}" -a -d "${HOME}/.ssh" ]; then |
173 mkdir -p "${TARGET_DIR}" | 169 mkdir -p "${TARGET_DIR}" |
174 cp -r "${HOME}/.ssh/known_hosts" "${TARGET_DIR}" | 170 cp -r "${HOME}/.ssh/known_hosts" "${TARGET_DIR}" |
175 cp -r "${HOME}/.ssh/config" "${TARGET_DIR}" | 171 cp -r "${HOME}/.ssh/config" "${TARGET_DIR}" |
176 ASOCK="$(dirname "${SSH_AUTH_SOCK}")" | 172 ASOCK="$(dirname "${SSH_AUTH_SOCK}")" |
177 ensure_mounted "${ASOCK}" "--bind" "${ASOCK}" | 173 mkdir -p "${FLAGS_chroot}/${ASOCK}" |
| 174 sudo mount --bind "${ASOCK}" "${FLAGS_chroot}/${ASOCK}" || \ |
| 175 die "Count not mount ${ASOCK}" |
178 fi | 176 fi |
179 fi | 177 fi |
180 | 178 |
| 179 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev/pts")" |
| 180 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
| 181 sudo mount none -t devpts "$MOUNTED_PATH" || \ |
| 182 die "Could not mount $MOUNTED_PATH" |
| 183 fi |
| 184 |
| 185 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}$CHROOT_TRUNK_DIR")" |
| 186 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
| 187 sudo mount --bind "$FLAGS_trunk" "$MOUNTED_PATH" || \ |
| 188 die "Could not mount $MOUNTED_PATH" |
| 189 fi |
| 190 |
181 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" | 191 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" |
182 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then | 192 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
183 ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")" | 193 ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")" |
184 if [ -z "$CHROME_ROOT" ]; then | 194 if [ -z "$CHROME_ROOT" ]; then |
185 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \ | 195 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \ |
186 2>/dev/null)" | 196 2>/dev/null)" |
187 CHROME_ROOT_AUTO=1 | 197 CHROME_ROOT_AUTO=1 |
188 fi | 198 fi |
189 if [[ ( -n "$CHROME_ROOT" ) ]]; then | 199 if [[ ( -n "$CHROME_ROOT" ) ]]; then |
190 if [[ ( ! -d "${CHROME_ROOT}/src" ) ]]; then | 200 if [[ ( ! -d "${CHROME_ROOT}/src" ) ]]; then |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 # Use git:8 chars of sha1 | 372 # Use git:8 chars of sha1 |
363 REVISION=$(cd ${FLAGS_trunk}/src/scripts ; git rev-parse --short=8 HEAD) | 373 REVISION=$(cd ${FLAGS_trunk}/src/scripts ; git rev-parse --short=8 HEAD) |
364 CHROOT_PASSTHRU="CHROMEOS_REVISION=$REVISION BUILDBOT_BUILD=$FLAGS_build_number
CHROMEOS_OFFICIAL=$CHROMEOS_OFFICIAL" | 374 CHROOT_PASSTHRU="CHROMEOS_REVISION=$REVISION BUILDBOT_BUILD=$FLAGS_build_number
CHROMEOS_OFFICIAL=$CHROMEOS_OFFICIAL" |
365 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ | 375 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ |
366 CHROMEOS_RELEASE_APPID=${CHROMEOS_RELEASE_APPID:-"{DEV-BUILD}"}" | 376 CHROMEOS_RELEASE_APPID=${CHROMEOS_RELEASE_APPID:-"{DEV-BUILD}"}" |
367 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ | 377 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ |
368 CHROMEOS_VERSION_TRACK=$CHROMEOS_VERSION_TRACK CHROMEOS_VERSION_AUSERVER=$CHROME
OS_VERSION_AUSERVER CHROMEOS_VERSION_DEVSERVER=$CHROMEOS_VERSION_DEVSERVER" | 378 CHROMEOS_VERSION_TRACK=$CHROMEOS_VERSION_TRACK CHROMEOS_VERSION_AUSERVER=$CHROME
OS_VERSION_AUSERVER CHROMEOS_VERSION_DEVSERVER=$CHROMEOS_VERSION_DEVSERVER" |
369 | 379 |
370 if [ -d "$HOME/.subversion" ]; then | 380 if [ -d "$HOME/.subversion" ]; then |
371 # Bind mounting .subversion into chroot | 381 # Bind mounting .subversion into chroot |
372 ensure_mounted "${HOME}/.subversion" "--bind" "/home/${USER}/.subversion" | 382 debug "mounting ~/.subversion into chroot" |
| 383 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/home/${USER}/.subversion")" |
| 384 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
| 385 mkdir -p "$MOUNTED_PATH" |
| 386 sudo mount --bind "$HOME/.subversion" "$MOUNTED_PATH" || \ |
| 387 die "Could not mount $MOUNTED_PATH" |
| 388 fi |
373 fi | 389 fi |
374 | 390 |
375 # Configure committer username and email in chroot .gitconfig | 391 # Configure committer username and email in chroot .gitconfig |
376 if [ $FLAGS_git_config -eq $FLAGS_TRUE ]; then | 392 if [ $FLAGS_git_config -eq $FLAGS_TRUE ]; then |
377 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ | 393 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ |
378 user.name "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/ *<.*//')" | 394 user.name "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/ *<.*//')" |
379 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ | 395 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ |
380 user.email "$(cd /tmp; git var GIT_COMMITTER_IDENT | \ | 396 user.email "$(cd /tmp; git var GIT_COMMITTER_IDENT | \ |
381 sed -e 's/.*<\([^>]*\)>.*/\1/')" | 397 sed -e 's/.*<\([^>]*\)>.*/\1/')" |
382 fi | 398 fi |
383 | 399 |
384 # Run command or interactive shell. Also include the non-chrooted path to | 400 # Run command or interactive shell. Also include the non-chrooted path to |
385 # the source trunk for scripts that may need to print it (e.g. | 401 # the source trunk for scripts that may need to print it (e.g. |
386 # build_image.sh). | 402 # build_image.sh). |
387 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ | 403 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ |
388 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ | 404 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ |
389 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" | 405 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" |
390 | 406 |
391 # Remove trap and explicitly unmount | 407 # Remove trap and explicitly unmount |
392 trap - EXIT | 408 trap - EXIT |
393 teardown_env | 409 teardown_env |
OLD | NEW |