#!/bin/bash -e
[[ -w / ]] || exec sudo "$0" "$@"
-[[ $# -eq 0 ]] && set -- env HOME=/root /bin/bash -l
-mounts="proc sys dev dev/pts"
+
+mounts="proc sys dev dev/pts usr/portage usr/portage/distfiles"
chroot=${0%/*}
case ${chroot} in
.) chroot=${PWD} ;;
+ ./*) chroot=${PWD}/${chroot#./} ;;
esac
cd "${chroot}"
+do_umount() {
+ mounts=$(mount | grep ${chroot} | awk '{print $3}' | tac)
+ for m in ${mounts} ; do
+ echo "unmounting $m"
+ umount $m
+ done
+ if [[ -z ${mounts} ]] ; then
+ echo "nothing mounted in ${chroot}"
+ fi
+ exit 0
+}
+
+while [[ -n $1 ]] ; do
+ case $1 in
+ -u) do_umount ;;
+ -*) echo "unknown option $1"; exit 1 ;;
+ *) break ;;
+ esac
+done
+
maybe_mount() {
- local src=$1 dst=${2:-$1}
- mkdir -p $d/$m
- grep -sq "${chroot}/${dst}" /proc/mounts || mount --bind "/${src}" "${chroot}/${dst}"
+ local src=/$1 dst=${chroot}/${2:-$1}
+ [[ -d ${src} ]] || return 0
+ mkdir -p "${dst}"
+ grep -sq "${dst}" /proc/mounts || mount --bind "${src}" "${dst}"
}
for m in ${mounts} ; do
maybe_mount ${m}
done
unset LS_COLORS # format changes over time
+[[ $# -eq 0 ]] && set -- env HOME=/root /bin/bash -l
exec \
${setarch} \
chroot "${chroot}" \