xbps-src: introduce support for multiple chroot implementations.

Available implementations at common/chroot-style/*.sh. Each .sh
script there implements a chroot style to be able to chroot and bind
mount with multiple utilities. The current supported list:

 - uunshare (uses xbps-uunshare(8))
 - uchroot (uses xbps-uchroot(8))
 - proot (uses proot, see http://proot.me)

The XBPS_CHROOT_CMD can be set in etc/conf to use a specific implementation,
and XBPS_CHROOT_CMD_ARGS to pass in additional arguments to the cmd.
This commit is contained in:
Juan RP 2015-04-09 18:57:41 +02:00
parent d99b4f720d
commit c7f21fd595
5 changed files with 93 additions and 39 deletions

24
common/chroot-style/proot.sh Executable file
View file

@ -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

22
common/chroot-style/uchroot.sh Executable file
View file

@ -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

22
common/chroot-style/uunshare.sh Executable file
View file

@ -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

View file

@ -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

View file

@ -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=""