Index: enter_chroot.sh |
diff --git a/enter_chroot.sh b/enter_chroot.sh |
index 606eaf51a6beef94cbca10047e282e08e2bf81de..d6b599d5e9e66f7908f0d741138098ca9e739cec 100755 |
--- a/enter_chroot.sh |
+++ b/enter_chroot.sh |
@@ -78,31 +78,32 @@ LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" |
function setup_env { |
( |
+ local mounted_path |
flock 200 |
echo $$ >> "$LOCKFILE" |
info "Mounting chroot environment." |
# Mount only if not already mounted |
- MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" |
- if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
+ 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" |
+ 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 ")" ] |
+ 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" |
+ 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 ")" ] |
+ 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" |
+ sudo mount --bind /dev "$mounted_path" || \ |
+ die "Could not mount $mounted_path" |
fi |
if [ $FLAGS_ssh_agent -eq $FLAGS_TRUE ]; then |
@@ -119,22 +120,22 @@ function setup_env { |
fi |
fi |
- MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}/dev/pts")" |
- if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
+ 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" |
+ 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 ")" ] |
+ 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" |
+ 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 ")" ] |
+ 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")" |
if [ -z "$CHROME_ROOT" ]; then |
@@ -148,20 +149,20 @@ function setup_env { |
info "Mounting chrome source at: $INNER_CHROME_ROOT" |
echo "$CHROME_ROOT" | \ |
sudo dd of="${FLAGS_chroot}${CHROME_ROOT_CONFIG}" |
- mkdir -p "$MOUNTED_PATH" |
- sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \ |
- die "Could not mount $MOUNTED_PATH" |
+ mkdir -p "$mounted_path" |
+ sudo mount --bind "$CHROME_ROOT" "$mounted_path" || \ |
+ die "Could not mount $mounted_path" |
fi |
fi |
- MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")" |
- if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ] |
+ mounted_path="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")" |
+ if [ -z "$(mount | grep -F "on $mounted_path ")" ] |
then |
if [ $(which gclient 2>/dev/null) ]; then |
info "Mounting depot_tools" |
DEPOT_TOOLS=$(dirname $(which gclient) ) |
- mkdir -p "$MOUNTED_PATH" |
- if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then |
+ mkdir -p "$mounted_path" |
+ if ! sudo mount --bind "$DEPOT_TOOLS" "$mounted_path"; then |
warn "depot_tools failed to mount; perhaps it's on NFS?" |
warn "This may impact chromium build." |
fi |
@@ -188,12 +189,39 @@ function setup_env { |
fi |
fi |
+ # Mount additional directories |
+ local local_mounts="${FLAGS_trunk}/src/scripts/.local_mounts" |
+ if [ -f "${local_mounts}" ]; then |
+ info "Mounting local folders (read-only for safety concern)" |
+ # format: mount_source |
+ # or mount_source mount_point |
+ # or # comments |
+ local mount_source mount_point |
+ cat "${local_mounts}" | while read mount_source mount_point; do |
+ if [ "$(echo "${mount_source}" | cut -b 1)" = "#" ] || |
+ [ -z "${mount_source}" ]; then |
+ continue |
+ fi |
+ # if only source is assigned, use source as mount point. |
+ mount_point="${mount_point:-$mount_source}" |
+ mounted_path="$(readlink -f "${FLAGS_chroot}${mount_point}")" |
+ if [ -z "$(mount | grep -F "on ${mounted_path} ")" ] |
+ then |
+ # --bind can't be initialized as RO, so we have to use "ro,remount". |
+ (sudo mount --bind "${mount_source}" "${mounted_path}" && |
+ sudo mount -o ro,remount "${mounted_path}") || |
+ die "Failed to mount ${mounted_path} from ${mount_source}." |
+ fi |
+ done |
+ fi |
+ |
) 200>>"$LOCKFILE" || die "setup_env failed" |
} |
function teardown_env { |
# Only teardown if we're the last enter_chroot to die |
( |
+ local mounted_path |
flock 200 |
# check each pid in $LOCKFILE to see if it's died unexpectedly |
@@ -226,12 +254,12 @@ function teardown_env { |
info "At least one other pid is running in the chroot, so not" |
info "tearing down env." |
else |
- MOUNTED_PATH=$(readlink -f "$FLAGS_chroot") |
+ mounted_path=$(readlink -f "$FLAGS_chroot") |
info "Unmounting chroot environment." |
# sort the list of mounts in reverse order, to ensure umount of |
# cascading mounts in proper order |
for i in \ |
- $(mount | grep -F "on $MOUNTED_PATH/" | sort -r | awk '{print $3}'); do |
+ $(mount | grep -F "on $mounted_path/" | sort -r | awk '{print $3}'); do |
safe_umount "$i" |
done |
fi |