From a5307b942eed4936a747b6f1eef2e2850dae7744 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 17 Aug 2009 18:38:41 +0000 Subject: [PATCH] update chroot more --- .bin/custom-chroot | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/.bin/custom-chroot b/.bin/custom-chroot index 60da7af..ab69e92 100755 --- a/.bin/custom-chroot +++ b/.bin/custom-chroot @@ -1,19 +1,41 @@ #!/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} @@ -57,6 +79,7 @@ for f in ${home} ; do done unset LS_COLORS # format changes over time +[[ $# -eq 0 ]] && set -- env HOME=/root /bin/bash -l exec \ ${setarch} \ chroot "${chroot}" \ -- 2.39.5