Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: enter_chroot.sh

Issue 6498001: enter_chroot: Only mount SSH auth socket when we need to. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 "$1" 76 info "$*"
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
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")"
dgarrett 2011/02/11 21:07:50 Can't this line be redone as: local mounted_path=
rochberg 2011/02/11 22:28:56 The extra level of quoting is necessary if FLAGS_c
dgarrett 2011/02/12 00:39:45 I think what happens to the quotes inside the $()
144
145 if [ -z "$(mount | grep -F "on $mounted_path ")" ]; then
dgarrett 2011/02/11 21:07:50 I believe we are supposed to use ${mounted_path} i
rochberg 2011/02/11 22:28:56 We are. Done.
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
135 function setup_env { 153 function setup_env {
136 # Validate sudo timestamp before entering the critical section so that we 154 # Validate sudo timestamp before entering the critical section so that we
137 # don't stall for a password while we have the lockfile. 155 # don't stall for a password while we have the lockfile.
138 # Don't use sudo -v since that has issues on machines w/ no password. 156 # Don't use sudo -v since that has issues on machines w/ no password.
139 sudo echo "" > /dev/null 157 sudo echo "" > /dev/null
140 158
141 ( 159 (
142 flock 200 160 flock 200
143 echo $$ >> "$LOCKFILE" 161 echo $$ >> "$LOCKFILE"
144 162
145 debug "Mounting chroot environment." 163 debug "Mounting chroot environment."
146 164 ensure_mounted none "-t proc" /proc
147 # Mount only if not already mounted 165 ensure_mounted none "-t sysfs" /sys
148 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" 166 ensure_mounted /dev "--bind" /dev
149 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then 167 ensure_mounted none "-t devpts" /dev/pts
150 sudo mount none -t proc "$MOUNTED_PATH" || \ 168 ensure_mounted "${FLAGS_trunk}" "--bind" "${CHROOT_TRUNK_DIR}"
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
165 169
166 if [ $FLAGS_ssh_agent -eq $FLAGS_TRUE ]; then 170 if [ $FLAGS_ssh_agent -eq $FLAGS_TRUE ]; then
167 TARGET_DIR="$(readlink -f "${FLAGS_chroot}/home/${USER}/.ssh")" 171 TARGET_DIR="$(readlink -f "${FLAGS_chroot}/home/${USER}/.ssh")"
168 if [ -n "${SSH_AUTH_SOCK}" -a -d "${HOME}/.ssh" ]; then 172 if [ -n "${SSH_AUTH_SOCK}" -a -d "${HOME}/.ssh" ]; then
169 mkdir -p "${TARGET_DIR}" 173 mkdir -p "${TARGET_DIR}"
170 cp -r "${HOME}/.ssh/known_hosts" "${TARGET_DIR}" 174 cp -r "${HOME}/.ssh/known_hosts" "${TARGET_DIR}"
171 cp -r "${HOME}/.ssh/config" "${TARGET_DIR}" 175 cp -r "${HOME}/.ssh/config" "${TARGET_DIR}"
172 ASOCK="$(dirname "${SSH_AUTH_SOCK}")" 176 ASOCK="$(dirname "${SSH_AUTH_SOCK}")"
173 mkdir -p "${FLAGS_chroot}/${ASOCK}" 177 ensure_mounted "${ASOCK}" "--bind" "${ASOCK}"
174 sudo mount --bind "${ASOCK}" "${FLAGS_chroot}/${ASOCK}" || \
175 die "Count not mount ${ASOCK}"
176 fi 178 fi
177 fi 179 fi
178 180
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
191 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" 181 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")"
192 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then 182 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
193 ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")" 183 ! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")"
194 if [ -z "$CHROME_ROOT" ]; then 184 if [ -z "$CHROME_ROOT" ]; then
195 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \ 185 ! CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \
196 2>/dev/null)" 186 2>/dev/null)"
197 CHROME_ROOT_AUTO=1 187 CHROME_ROOT_AUTO=1
198 fi 188 fi
199 if [[ ( -n "$CHROME_ROOT" ) ]]; then 189 if [[ ( -n "$CHROME_ROOT" ) ]]; then
200 if [[ ( ! -d "${CHROME_ROOT}/src" ) ]]; then 190 if [[ ( ! -d "${CHROME_ROOT}/src" ) ]]; then
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 # Use git:8 chars of sha1 330 # Use git:8 chars of sha1
341 REVISION=$(cd ${FLAGS_trunk}/src/scripts ; git rev-parse --short=8 HEAD) 331 REVISION=$(cd ${FLAGS_trunk}/src/scripts ; git rev-parse --short=8 HEAD)
342 CHROOT_PASSTHRU="CHROMEOS_REVISION=$REVISION BUILDBOT_BUILD=$FLAGS_build_number CHROMEOS_OFFICIAL=$CHROMEOS_OFFICIAL" 332 CHROOT_PASSTHRU="CHROMEOS_REVISION=$REVISION BUILDBOT_BUILD=$FLAGS_build_number CHROMEOS_OFFICIAL=$CHROMEOS_OFFICIAL"
343 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ 333 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \
344 CHROMEOS_RELEASE_APPID=${CHROMEOS_RELEASE_APPID:-"{DEV-BUILD}"}" 334 CHROMEOS_RELEASE_APPID=${CHROMEOS_RELEASE_APPID:-"{DEV-BUILD}"}"
345 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ 335 CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \
346 CHROMEOS_VERSION_TRACK=$CHROMEOS_VERSION_TRACK CHROMEOS_VERSION_AUSERVER=$CHROME OS_VERSION_AUSERVER CHROMEOS_VERSION_DEVSERVER=$CHROMEOS_VERSION_DEVSERVER" 336 CHROMEOS_VERSION_TRACK=$CHROMEOS_VERSION_TRACK CHROMEOS_VERSION_AUSERVER=$CHROME OS_VERSION_AUSERVER CHROMEOS_VERSION_DEVSERVER=$CHROMEOS_VERSION_DEVSERVER"
347 337
348 if [ -d "$HOME/.subversion" ]; then 338 if [ -d "$HOME/.subversion" ]; then
349 # Bind mounting .subversion into chroot 339 # Bind mounting .subversion into chroot
350 debug "mounting ~/.subversion into chroot" 340 ensure_mounted "${HOME}/.subversion" "--bind" "/home/${USER}/.subversion"
351 MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/home/${USER}/.subversion")"
352 if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
353 mkdir -p "$MOUNTED_PATH"
354 sudo mount --bind "$HOME/.subversion" "$MOUNTED_PATH" || \
355 die "Could not mount $MOUNTED_PATH"
356 fi
357 fi 341 fi
358 342
359 # Configure committer username and email in chroot .gitconfig 343 # Configure committer username and email in chroot .gitconfig
360 if [ $FLAGS_git_config -eq $FLAGS_TRUE ]; then 344 if [ $FLAGS_git_config -eq $FLAGS_TRUE ]; then
361 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ 345 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \
362 user.name "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/ *<.*//')" 346 user.name "$(cd /tmp; git var GIT_COMMITTER_IDENT | sed -e 's/ *<.*//')"
363 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \ 347 git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \
364 user.email "$(cd /tmp; git var GIT_COMMITTER_IDENT | \ 348 user.email "$(cd /tmp; git var GIT_COMMITTER_IDENT | \
365 sed -e 's/.*<\([^>]*\)>.*/\1/')" 349 sed -e 's/.*<\([^>]*\)>.*/\1/')"
366 fi 350 fi
367 351
368 # Run command or interactive shell. Also include the non-chrooted path to 352 # Run command or interactive shell. Also include the non-chrooted path to
369 # the source trunk for scripts that may need to print it (e.g. 353 # the source trunk for scripts that may need to print it (e.g.
370 # build_image.sh). 354 # build_image.sh).
371 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \ 355 sudo -- chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \
372 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \ 356 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" LANG=C SSH_AGENT_PID="${SSH_AGENT_PID}" \
373 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@" 357 SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" "$@"
374 358
375 # Remove trap and explicitly unmount 359 # Remove trap and explicitly unmount
376 trap - EXIT 360 trap - EXIT
377 teardown_env 361 teardown_env
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698