Index: enter_chroot.sh |
diff --git a/enter_chroot.sh b/enter_chroot.sh |
index 8e3d5898ece2f8ff028146784b5f1ad7b116d774..ac34ad961f583ffa9807c7462c421af638f0dfe5 100755 |
--- a/enter_chroot.sh |
+++ b/enter_chroot.sh |
@@ -73,7 +73,7 @@ Otherwise, provides an interactive shell. |
# Version of info from common.sh that only echos if --verbose is set. |
function debug { |
if [ $FLAGS_verbose -eq $FLAGS_TRUE ]; then |
- info "$1" |
+ info "$*" |
fi |
} |
@@ -132,6 +132,24 @@ sudo chmod 0777 "$FLAGS_chroot/var/lock" |
LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" |
+ |
+function ensure_mounted { |
+ # If necessary, mount $source in the host FS at $target inside the |
+ # chroot directory with $mount_args. |
+ local source="$1" |
+ local mount_args="$2" |
+ local target="$3" |
+ |
+ local mounted_path="$(readlink -f "${FLAGS_chroot}/$target")" |
+ |
+ if [ -z "$(mount | grep -F "on ${mounted_path} ")" ]; then |
+ # NB: mount_args deliberately left unquoted |
+ debug mount ${mount_args} "${source}" "${mounted_path}" |
+ sudo -- mount ${mount_args} "${source}" "${mounted_path}" || \ |
+ die "Could not mount ${source} on ${mounted_path}" |
+ fi |
+} |
+ |
function setup_env { |
# Validate sudo timestamp before entering the critical section so that we |
# don't stall for a password while we have the lockfile. |
@@ -143,25 +161,11 @@ function setup_env { |
echo $$ >> "$LOCKFILE" |
debug "Mounting chroot environment." |
- |
- # Mount only if not already mounted |
- MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" |
- if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
- sudo mount none -t proc "$MOUNTED_PATH" || \ |
- die "Could not mount $MOUNTED_PATH" |
- fi |
- |
- MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/sys")" |
- if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
- sudo mount none -t sysfs "$MOUNTED_PATH" || \ |
- die "Could not mount $MOUNTED_PATH" |
- fi |
- |
- MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev")" |
- if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
- sudo mount --bind /dev "$MOUNTED_PATH" || \ |
- die "Could not mount $MOUNTED_PATH" |
- fi |
+ ensure_mounted none "-t proc" /proc |
+ ensure_mounted none "-t sysfs" /sys |
+ ensure_mounted /dev "--bind" /dev |
+ ensure_mounted none "-t devpts" /dev/pts |
+ ensure_mounted "${FLAGS_trunk}" "--bind" "${CHROOT_TRUNK_DIR}" |
if [ $FLAGS_ssh_agent -eq $FLAGS_TRUE ]; then |
TARGET_DIR="$(readlink -f "${FLAGS_chroot}/home/${USER}/.ssh")" |
@@ -170,24 +174,10 @@ function setup_env { |
cp -r "${HOME}/.ssh/known_hosts" "${TARGET_DIR}" |
cp -r "${HOME}/.ssh/config" "${TARGET_DIR}" |
ASOCK="$(dirname "${SSH_AUTH_SOCK}")" |
- mkdir -p "${FLAGS_chroot}/${ASOCK}" |
- sudo mount --bind "${ASOCK}" "${FLAGS_chroot}/${ASOCK}" || \ |
- die "Count not mount ${ASOCK}" |
+ ensure_mounted "${ASOCK}" "--bind" "${ASOCK}" |
fi |
fi |
- MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev/pts")" |
- if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
- sudo mount none -t devpts "$MOUNTED_PATH" || \ |
- die "Could not mount $MOUNTED_PATH" |
- fi |
- |
- MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}$CHROOT_TRUNK_DIR")" |
- if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
- sudo mount --bind "$FLAGS_trunk" "$MOUNTED_PATH" || \ |
- die "Could not mount $MOUNTED_PATH" |
- fi |
- |
MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" |
if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
! CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root")" |
@@ -378,14 +368,9 @@ CHROOT_PASSTHRU="${CHROOT_PASSTHRU} \ |
CHROMEOS_VERSION_TRACK=$CHROMEOS_VERSION_TRACK CHROMEOS_VERSION_AUSERVER=$CHROMEOS_VERSION_AUSERVER CHROMEOS_VERSION_DEVSERVER=$CHROMEOS_VERSION_DEVSERVER" |
if [ -d "$HOME/.subversion" ]; then |
- # Bind mounting .subversion into chroot |
- debug "mounting ~/.subversion into chroot" |
- MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/home/${USER}/.subversion")" |
- if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then |
- mkdir -p "$MOUNTED_PATH" |
- sudo mount --bind "$HOME/.subversion" "$MOUNTED_PATH" || \ |
- die "Could not mount $MOUNTED_PATH" |
- fi |
+ TARGET="/home/${USER}/.subversion" |
+ mkdir -p "${FLAGS_chroot}${TARGET}" |
+ ensure_mounted "${HOME}/.subversion" "--bind" "${TARGET}" |
fi |
# Configure committer username and email in chroot .gitconfig |