]> git.wh0rd.org - home.git/blobdiff - .bin/gentoo-sync
git-rb-all: handle more edge cases
[home.git] / .bin / gentoo-sync
index 11bd717b9370a9c0943ad65951738a95d8bf06bd..c41f04dcacbec059e7b261e9ad7ec0c3a51b1706 100755 (executable)
@@ -10,6 +10,28 @@ GS_DEBUG=false
 conf="/etc/gentoo-sync.conf"
 [[ -e ${conf} ]] && . "${conf}"
 
+bootstrap() {
+       [[ "${FLOCKER}" != "$0" ]] && exec env FLOCKER="$0" flock -en "$0" "$0" "$@"
+       [[ $(id -u) -eq 0 ]] || exec sudo env -uUNSHARE FLOCKER="${FLOCKER}" 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 +80,6 @@ for x ; do
        esac
 done
 
-[ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -en "$0" "$0" "$@" || :
 ${GS_DEBUG} && set -x
 
 logdir="/var/log"
@@ -131,4 +152,5 @@ if ${GS_UPWORLD} ; then
        emerge -upq --cols \
                $(printf '%s\n' ${good_pkgs[*]} | grep -v '^cross-')
        ) >& ${up_log}
+       :
 fi