From e97892fdb95fdee851bcec27c266c0861f7eb811 Mon Sep 17 00:00:00 2001 From: Enno Boland Date: Fri, 10 Apr 2015 00:05:04 +0200 Subject: [PATCH] common/chroot-style: add unshare wrapper script --- common/chroot-style/unshare.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 common/chroot-style/unshare.sh diff --git a/common/chroot-style/unshare.sh b/common/chroot-style/unshare.sh new file mode 100755 index 0000000000..050e8c69eb --- /dev/null +++ b/common/chroot-style/unshare.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# +# This chroot script uses unshare(1) with user_namespaces(7). +# +readonly MASTERDIR="$1" +readonly DISTDIR="$2" +readonly HOSTDIR="$3" +readonly EXTRA_ARGS="$4" + +if ! command -v unshare >/dev/null 2>&1; then + exit 1 +fi + +if [ -z "$XBPS_IS_UNSHARED" ]; then + XBPS_IS_UNSHARED=1 exec unshare $EXTRA_ARGS -m -U -r -- "$0" "$@" + exit 1 +fi + +shift 4 + +if [ -z "$MASTERDIR" -o -z "$DISTDIR" ]; then + echo "$0 MASTERDIR/DISTDIR not set" + exit 1 +fi + +for i in /dev /proc /sys; do + mount --rbind "$i" "$MASTERDIR/$i" || exit 1 +done +mount --rbind "$DISTDIR" "$MASTERDIR/void-packages" || exit 1 +mount --rbind "$HOSTDIR" "$MASTERDIR/host" || exit 1 +exec chroot "$MASTERDIR" "$@"