]> git.wh0rd.org Git - home.git/commitdiff
use unshare if available
authorMike Frysinger <vapier@gentoo.org>
Mon, 5 Nov 2012 07:34:47 +0000 (02:34 -0500)
committerMike Frysinger <vapier@gentoo.org>
Mon, 5 Nov 2012 07:34:47 +0000 (02:34 -0500)
.bin/custom-chroot

index ae525ed588ab464f1aec03e9bfd151e0f3f3be1c..7c576bb0109d991863791249022402c655c458c0 100755 (executable)
@@ -2,6 +2,16 @@
 
 [[ -w / ]] || exec sudo env HOME="$HOME" "$0" "$@"
 
+if [[ -z ${UNSHARE} ]] ; then
+       mount_args=
+       if type -P unshare >&/dev/null ; then
+               UNSHARE=true exec unshare -m -- "$0" "$@"
+       fi
+else
+       mount_args='-n'
+fi
+unset UNSHARE
+
 mounts="proc sys dev dev/pts usr/portage usr/portage/distfiles"
 
 chroot=${0%/*}
@@ -35,7 +45,7 @@ maybe_mount() {
        local src=/$1 dst=${chroot}/${2:-$1}
        [[ -d ${src} ]] || return 0
        mkdir -p "${dst}"
-       grep -sq "${dst}" /proc/mounts || mount --bind "${src}" "${dst}"
+       grep -sq "${dst}" /proc/mounts || mount ${mount_args} --bind "${src}" "${dst}"
 }
 for m in ${mounts} ; do
        maybe_mount ${m}
@@ -50,6 +60,7 @@ get_type() {
        esac
 }
 bin_dst=$(get_type bin/bash)
+setarch=
 if [[ -n ${bin_dst} ]] && type -P setarch &>/dev/null ; then
        setarch="setarch ${bin_dst}"
 fi