From: Mike Frysinger Date: Mon, 5 Nov 2012 07:34:47 +0000 (-0500) Subject: use unshare if available X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=f2ff891e6eb173ea0ffc4fed185af8ca1b2e15bd;p=home.git use unshare if available --- diff --git a/.bin/custom-chroot b/.bin/custom-chroot index ae525ed..7c576bb 100755 --- a/.bin/custom-chroot +++ b/.bin/custom-chroot @@ -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