aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2026-10-08 06:15:55 -0400
committerB. Watson <urchlay@slackware.uk>2026-10-08 06:15:55 -0400
commit60837596f97570601b3111dbd5e098b684fe1032 (patch)
tree9bf190a32527713619d97cf177626d09cd529bad
parentffc19493b7c063ff988d7d1f90b72bba4e511bb9 (diff)
downloadsbo-maintainer-tools-60837596f97570601b3111dbd5e098b684fe1032.tar.gz
sbrun: WIP, works for me, not bulletproof yet.
-rwxr-xr-xsbrun176
1 files changed, 100 insertions, 76 deletions
diff --git a/sbrun b/sbrun
index 90df9e0..fa5fec2 100755
--- a/sbrun
+++ b/sbrun
@@ -117,6 +117,7 @@ cleanup_log() {
}
cleanup_privdir() {
+ [ -e /root/.sbrun_no_chroot ] && return
[ "$PRIVDIR" = "" ] && return
umount $FAKEROOT/$OUTPUT
umount $FAKEROOT/$TMP
@@ -360,36 +361,57 @@ fi
START_TIME="$( date +%s )"
-### 20260923 bkw: mount the overlay here!
-PRIVDIR="$( mktemp -td sbrun.priv.XXXXXXXXXX )"
-UPPERDIR=$PRIVDIR/upperdir
-WORKDIR=$PRIVDIR/workdir
-FAKEROOT=$PRIVDIR/fake_root
-mkdir -p $UPPERDIR $WORKDIR $FAKEROOT
-echo "Private dir for overlay FS: $PRIVDIR" | tee -a $BUILDLOG
-
-if [ "$STRACE" != "" ]; then
- PRECMD="strace -o $PRIVDIR/strace.out $STRACE"
+# 20260927 bkw: chroot32 and chroot64 scripts create this file.
+# If it exists, don't chroot within the chroot.
+if [ -e /root/.sbrun_no_chroot ]; then
+ warn "Not tracking unauthorized writes due to /root/.sbrun_no_chroot"
+ [ "$STRACE" != "" ] && PRECMD="strace -f -ostrace.out"
+ (
+ $NSENTER $PRECMD bash $X $SCRIPT 2>&1; echo "$?" > $TMP/ret.$$
+ ) | tee -a $BUILDLOG
+ RET="$( cat $TMP/ret.$$ )"
+ rm -f $TMP/ret.$$
+else
+ ### 20260923 bkw: mount the overlay here!
+ PRIVDIR="$( mktemp -td sbrun.priv.XXXXXXXXXX )"
+ UPPERDIR=$PRIVDIR/upperdir
+ WORKDIR=$PRIVDIR/workdir
+ FAKEROOT=$PRIVDIR/fake_root
+ mkdir -p $UPPERDIR $WORKDIR $FAKEROOT
+ echo "Private dir for overlay FS: $PRIVDIR" | tee -a $BUILDLOG
+
+ if [ "$STRACE" != "" ]; then
+ PRECMD="strace -o $PRIVDIR/strace.out $STRACE"
+ fi
+
+ # Force-load the module (Slackware >= 15.0 ships the module at least)
+ modprobe overlay &> /dev/null
+ mount -t overlay overlay \
+ -olowerdir=/,upperdir=$UPPERDIR,workdir=$WORKDIR \
+ $FAKEROOT
+ if [ "$?" != 0 ]; then
+ warn "overlay FS support missing, can't continue"
+ exit 1
+ fi
+ # writes to $FAKEROOT/$TMP will pass through to the real $TMP
+ mkdir -p $TMP $OUTPUT # these have to exist to be mounted...
+ mount --bind $TMP $FAKEROOT/$TMP
+ mount --bind $OUTPUT $FAKEROOT/$OUTPUT
+ mount -t proc proc $FAKEROOT/proc
+ mount -t sysfs sysfs $FAKEROOT/sys
+
+ echo cd "'$( pwd )'" > $PRIVDIR/runme
+ echo $PRECMD bash $X $SCRIPT >> $PRIVDIR/runme
+
+ # Actually run the script.
+ (
+ $NSENTER chroot $FAKEROOT bash $PRIVDIR/runme 2>&1; echo "$?" > $PRIVDIR/ret ) | tee -a $BUILDLOG
+ RET="$( cat $PRIVDIR/ret )"
+
+ umount $FAKEROOT/proc
+ umount $FAKEROOT/sys
fi
-# Force-load the module (Slackware >= 15.0 ships the module at least)
-modprobe overlay &> /dev/null
-mount -t overlay overlay \
- -olowerdir=/,upperdir=$UPPERDIR,workdir=$WORKDIR \
- $FAKEROOT
-# writes to $FAKEROOT/$TMP will pass through to the real $TMP
-mkdir -p $TMP $OUTPUT # these have to exist to be mounted...
-mount --bind $TMP $FAKEROOT/$TMP
-mount --bind $OUTPUT $FAKEROOT/$OUTPUT
-
-echo cd "'$( pwd )'" > $PRIVDIR/runme
-echo $PRECMD bash $X $SCRIPT >> $PRIVDIR/runme
-
-# Actually run the script.
-(
- $NSENTER chroot $FAKEROOT bash $PRIVDIR/runme 2>&1; echo "$?" > $PRIVDIR/ret ) | tee -a $BUILDLOG
-RET="$( cat $PRIVDIR/ret )"
-
END_TIME="$( date +%s )"
echo "$SCRIPT exit status: $RET" | tee -a $BUILDLOG
@@ -401,55 +423,57 @@ echo "$SCRIPT exit status: $RET" | tee -a $BUILDLOG
cleanup_nonet
-# This file contains a list of files that were written during
-# the build (and are left over in the upperdir).
-TURDS=$TMP/sbrun.turds.$$
-
-### 20260923 bkw:
-# Anything in $UPPERDIR after umount was written there by the
-# SlackBuild. Not everything there is worth bitching about.
-# After overlay umount, exclude these dirs from complaints:
-# /tmp /proc /var/tmp /root/.ccache /root/.cache /dev/pts /dev/shm
-# also $TMP and $OUTPUT.
-# For some reason, "root" gets created, too.
-# Have to specify each dir by itself *without* trailing slash,
-# then again with \/* to catch files/dirs under that dir.
-( cd $PRIVDIR/upperdir
- find * \
- \! -path root \
- \! -path root/.cache/\* \
- \! -path root/.ccache/\* \
- \! -path tmp/\* \
- \! -path var/tmp/\* \
- \! -path proc/\* \
- \! -path dev/pts/\* \
- \! -path dev/shm/\* \
- \! -path $TMP/\* \
- \! -path $OUTPUT/\* \
- \! -path root/.cache \
- \! -path root/.ccache \
- \! -path tmp \
- \! -path var/tmp \
- \! -path proc \
- \! -path dev/pts \
- \! -path dev/shm \
- \! -path $TMP \
- \! -path $OUTPUT \
- -print0 | xargs -r0 ls -bld > $TURDS
-) 2>/dev/null
-
-if [ -f $PRIVDIR/strace.out ]; then
- mv $PRIVDIR/strace.out .
- chown --reference=$SCRIPT strace.out
-fi
-
-cleanup_privdir
-
-if [ -s $TURDS ]; then
- warn "WARNING: files altered outside the sandbox:"
- tee -a $BUILDLOG < $TURDS
+if [ ! -e /root/.sbrun_no_chroot ]; then
+ # This file contains a list of files that were written during
+ # the build (and are left over in the upperdir).
+ TURDS=$TMP/sbrun.turds.$$
+
+ ### 20260923 bkw:
+ # Anything in $UPPERDIR after umount was written there by the
+ # SlackBuild. Not everything there is worth bitching about.
+ # After overlay umount, exclude these dirs from complaints:
+ # /tmp /proc /var/tmp /root/.ccache /root/.cache /dev/pts /dev/shm
+ # also $TMP and $OUTPUT.
+ # For some reason, "root" gets created, too.
+ # Have to specify each dir by itself *without* trailing slash,
+ # then again with \/* to catch files/dirs under that dir.
+ ( cd $PRIVDIR/upperdir
+ find * \
+ \! -path root \
+ \! -path root/.cache/\* \
+ \! -path root/.ccache/\* \
+ \! -path tmp/\* \
+ \! -path var/tmp/\* \
+ \! -path proc/\* \
+ \! -path dev/pts/\* \
+ \! -path dev/shm/\* \
+ \! -path $TMP/\* \
+ \! -path $OUTPUT/\* \
+ \! -path root/.cache \
+ \! -path root/.ccache \
+ \! -path tmp \
+ \! -path var/tmp \
+ \! -path proc \
+ \! -path dev/pts \
+ \! -path dev/shm \
+ \! -path $TMP \
+ \! -path $OUTPUT \
+ -print0 | xargs -r0 ls -bld > $TURDS
+ ) 2>/dev/null
+
+ if [ -f $PRIVDIR/strace.out ]; then
+ mv $PRIVDIR/strace.out .
+ chown --reference=$SCRIPT strace.out
+ fi
+
+ cleanup_privdir
+
+ if [ -s $TURDS ]; then
+ warn "WARNING: files altered outside the sandbox:"
+ tee -a $BUILDLOG < $TURDS
+ fi
+ rm -f $TURDS
fi
-rm -f $TURDS
# If linting + installation were both requested, don't install
# the package if it fails to lint.