]> git.wh0rd.org - home.git/commitdiff
gentoo-sync: use namespaces
authorMike Frysinger <vapier@gentoo.org>
Mon, 4 Apr 2016 03:33:46 +0000 (23:33 -0400)
committerMike Frysinger <vapier@gentoo.org>
Mon, 4 Apr 2016 03:33:46 +0000 (23:33 -0400)
.bin/gentoo-sync

index 11bd717b9370a9c0943ad65951738a95d8bf06bd..ed2c071e77395908815c5f09aa7c1436daaa8460 100755 (executable)
@@ -10,6 +10,27 @@ GS_DEBUG=false
 conf="/etc/gentoo-sync.conf"
 [[ -e ${conf} ]] && . "${conf}"
 
+bootstrap() {
+       [[ $(id -u) -eq 0 ]] || exec sudo env -uUNSHARE HOME="$HOME" "$0" "$@"
+
+       if [[ -z ${UNSHARE} ]] ; then
+               mount_args=
+               if type -P unshare >&/dev/null ; then
+                       test_arg() { unshare "$@" -- true >&/dev/null && uargs+=( "$@" ) || :; }
+                       uargs=( -m )
+                       test_arg -u
+                       test_arg -i
+                       test_arg -p -f --mount-proc
+                       test_arg --propagation=private
+                       UNSHARE=true exec unshare "${uargs[@]}" -- "$0" "$@"
+               fi
+       else
+               mount_args='-n'
+       fi
+       unset UNSHARE
+}
+bootstrap "$@"
+
 usage() {
        cat <<-EOF
        Usage: ${0##*/} [options]
@@ -58,7 +79,6 @@ for x ; do
        esac
 done
 
-[ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -en "$0" "$0" "$@" || :
 ${GS_DEBUG} && set -x
 
 logdir="/var/log"