diff --git a/common/chroot-style/proot.sh b/common/chroot-style/proot.sh new file mode 100755 index 00000000000..6597a437b32 --- /dev/null +++ b/common/chroot-style/proot.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# +# This chroot script uses proot (see http://proot.me) +# +readonly MASTERDIR="$1" +readonly DISTDIR="$2" +readonly HOSTDIR="$3" +readonly EXTRA_ARGS="$4" +readonly COMMAND="$5" +shift 5 +readonly COMMAND_ARGS="$@" + +if ! command -v proot >/dev/null 2>&1; then + exit 1 +fi + +if [ -z "$MASTERDIR" -o -z "$DISTDIR" -o -z "$COMMAND" ]; then + echo "$0 MASTERDIR/DISTDIR/COMMAND not set" + exit 1 +fi + +exec proot -r $XBPS_MASTERDIR -w / -b $DISTDIR:/void-packages \ + ${HOSTDIR:+-b $HOSTDIR:/host} -b /proc:/proc -b /dev:/dev \ + -b /sys:/sys $EXTRA_ARGS $COMMAND $COMMAND_ARGS diff --git a/common/chroot-style/uchroot.sh b/common/chroot-style/uchroot.sh new file mode 100755 index 00000000000..aabf84ee27b --- /dev/null +++ b/common/chroot-style/uchroot.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# +# This chroot script uses xbps-uchroot(8). +# +readonly MASTERDIR="$1" +readonly DISTDIR="$2" +readonly HOSTDIR="$3" +readonly EXTRA_ARGS="$4" +readonly COMMAND="$5" +shift 5 +readonly COMMAND_ARGS="$@" + +if ! command -v xbps-uchroot >/dev/null 2>&1; then + exit 1 +fi + +if [ -z "$MASTERDIR" -o -z "$DISTDIR" -o -z "$COMMAND" ]; then + echo "$0 MASTERDIR/DISTDIR/COMMAND not set" + exit 1 +fi + +exec xbps-uchroot $EXTRA_ARGS -D $DISTDIR ${HOSTDIR:+-H $HOSTDIR} $XBPS_MASTERDIR $COMMAND $COMMAND_ARGS diff --git a/common/chroot-style/uunshare.sh b/common/chroot-style/uunshare.sh new file mode 100755 index 00000000000..54351ecabe3 --- /dev/null +++ b/common/chroot-style/uunshare.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# +# This chroot script uses xbps-uunshare(8) with user_namespaces(7). +# +readonly MASTERDIR="$1" +readonly DISTDIR="$2" +readonly HOSTDIR="$3" +readonly EXTRA_ARGS="$4" +readonly COMMAND="$5" +shift 5 +readonly COMMAND_ARGS="$@" + +if ! command -v xbps-uunshare >/dev/null 2>&1; then + exit 1 +fi + +if [ -z "$MASTERDIR" -o -z "$DISTDIR" -o -z "$COMMAND" ]; then + echo "$0 MASTERDIR/DISTDIR/COMMAND not set" + exit 1 +fi + +exec xbps-uunshare $EXTRA_ARGS -D $DISTDIR ${HOSTDIR:+-H $HOSTDIR} $XBPS_MASTERDIR $COMMAND $COMMAND_ARGS diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh index f6801429133..08db9728378 100644 --- a/common/xbps-src/shutils/chroot.sh +++ b/common/xbps-src/shutils/chroot.sh @@ -145,11 +145,9 @@ chroot_sync_repos() { if [ -z "$XBPS_SKIP_REMOTEREPOS" ]; then # Make sure to sync index for remote repositories. - xbps-uunshare $XBPS_MASTERDIR /usr/sbin/xbps-install -S - if [ $? -eq 99 ]; then - # userns not supported, fallback to uchroot - xbps-uchroot $XBPS_MASTERDIR /usr/sbin/xbps-install -S - fi + $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \ + $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" \ + "$XBPS_CHROOT_CMD_ARGS" /usr/sbin/xbps-install -S fi if [ -n "$XBPS_CROSS_BUILD" ]; then @@ -160,13 +158,9 @@ chroot_sync_repos() { # Make sure to sync index for remote repositories. if [ -z "$XBPS_SKIP_REMOTEREPOS" ]; then env XBPS_TARGET_ARCH=$XBPS_TARGET_ARCH \ - xbps-uunshare $XBPS_MASTERDIR /usr/sbin/xbps-install \ - -r $XBPS_CROSS_BASE -S - if [ $? -eq 99 ]; then - env XBPS_TARGET_ARCH=$XBPS_TARGET_ARCH \ - xbps-uchroot $XBPS_MASTERDIR /usr/sbin/xbps-install \ - -r $XBPS_CROSS_BASE -S - fi + $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \ + $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \ + /usr/sbin/xbps-install -r $XBPS_CROSS_BASE -S fi fi @@ -174,27 +168,14 @@ chroot_sync_repos() { } chroot_handler() { - local action="$1" pkg="$2" rv=0 arg= _envargs= _chargs= + local action="$1" pkg="$2" rv=0 arg= _envargs= if [ -n "$IN_CHROOT" -o -z "$CHROOT_READY" ]; then return 0 fi - # Debian uses /run/shm instead... - if [ -d /run/shm ]; then - mkdir -p ${XBPS_MASTERDIR}/run/shm - _chargs+=" -S /run/shm" - elif [ -d /dev/shm ]; then - mkdir -p ${XBPS_MASTERDIR}/dev/shm - _chargs+=" -S /dev/shm" - fi - - if [ -n "$XBPS_HOSTDIR" ]; then - _chargs+=" -H $XBPS_HOSTDIR" - fi if [ ! -d $XBPS_MASTERDIR/void-packages ]; then mkdir -p $XBPS_MASTERDIR/void-packages fi - _chargs+=" -D ${XBPS_DISTDIR}" [ -z "$action" -a -z "$pkg" ] && return 1 @@ -207,13 +188,9 @@ chroot_handler() { esac if [ "$action" = "chroot" ]; then - xbps-uunshare ${_chargs} $XBPS_MASTERDIR /bin/xbps-shell + $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \ + $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell rv=$? - if [ $rv -eq 99 ]; then - # userns not supported, fallback to uchroot - xbps-uchroot ${_chargs} $XBPS_MASTERDIR /bin/xbps-shell - rv=$? - fi else [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD" [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C" @@ -230,14 +207,10 @@ chroot_handler() { action="$arg $action" env -i PATH="/usr/bin:/usr/sbin:$PATH" HOME=/tmp IN_CHROOT=1 LANG=en_US.UTF-8 \ - xbps-uunshare ${_chargs} $XBPS_MASTERDIR /void-packages/xbps-src $action $pkg + $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \ + $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \ + /void-packages/xbps-src $action $pkg rv=$? - if [ $rv -eq 99 ]; then - # userns not supported, fallback to uchroot - env -i PATH="/usr/bin:/usr/sbin:$PATH" HOME=/tmp IN_CHROOT=1 LANG=en_US.UTF-8 \ - xbps-uchroot ${_chargs} $XBPS_MASTERDIR /void-packages/xbps-src $action $pkg - rv=$? - fi fi return $rv diff --git a/etc/defaults.conf b/etc/defaults.conf index 016d319461e..6b0e8b0c18a 100644 --- a/etc/defaults.conf +++ b/etc/defaults.conf @@ -88,3 +88,16 @@ XBPS_SUCMD="sudo /bin/sh -c" # override the global options defined above for the matching package. # #XBPS_PKG_OPTIONS_foo=opt,~opt2,opt3,~opt4 + +# [OPTIONAL] +# Set the preferred chroot style. Available styles at common/chroot-style/*.sh: +# +# - uunshare (uses xbps-uunshare(8), user namespaces) +# - uchroot (uses xbps-uchroot(8), namespaces, setgid) +# - proot (uses proot, external, does not need special permissions) +# +# The order is already set as shown above, but can be overriden below. +# Additional arguments to the chroot style can be passed in via XBPS_CHROOT_CMD_ARGS. +# +#XBPS_CHROOT_CMD=proot +#XBPS_CHROOT_CMD_ARGS=""