summaryrefslogtreecommitdiff
path: root/mk
diff options
context:
space:
mode:
authorseb <seb@pkgsrc.org>2002-08-12 15:19:49 +0000
committerseb <seb@pkgsrc.org>2002-08-12 15:19:49 +0000
commit9ddc0ee2a999b24c1b7606a7331d0aaf32cac62b (patch)
tree36c0e8dc45ce581acabff1f2c261a0726d58282e /mk
parent5670256c19c06a00052829571fd05caa251e1e82 (diff)
downloadpkgsrc-9ddc0ee2a999b24c1b7606a7331d0aaf32cac62b.tar.gz
New feature: this script now create $sandbox/sandbox, a shell script
to ease the use of the sandbox. $sandbox/sandbox umount Umount the null mounts from the sandbox $sandbox/sandbox mount Mount the null mounts required by the sandbox (useful across reboots, ...). $sandbox/sandbox whatever Runs the command passed as arguments, chrooted into the sandbox. Typical usage would be `$sandbox/sandbox /my/favourite/shell'. $sandbox/sandbox Same as `$sandbox/sandbox /bin/sh' Approved by agc.
Diffstat (limited to 'mk')
-rwxr-xr-xmk/bulk/mksandbox51
1 files changed, 50 insertions, 1 deletions
diff --git a/mk/bulk/mksandbox b/mk/bulk/mksandbox
index a45d938b6a5..88c9847d9f9 100755
--- a/mk/bulk/mksandbox
+++ b/mk/bulk/mksandbox
@@ -1,6 +1,6 @@
#! /bin/sh
-# $NetBSD: mksandbox,v 1.5 2002/08/12 14:47:07 seb Exp $
+# $NetBSD: mksandbox,v 1.6 2002/08/12 15:19:49 seb Exp $
#
#
# Copyright (c) 2002 Alistair G. Crooks. All rights reserved.
@@ -118,6 +118,7 @@ if [ `id -u` -ne 0 ]; then
fi
sandbox=$1
+sandbox_script="$sandbox/sandbox"
packages=`(cd $pkgsrc/pkgtools/pkglint; $bmakeprog show-var VARNAME=PACKAGES)`
distfiles=`(cd $pkgsrc/pkgtools/pkglint; $bmakeprog show-var VARNAME=DISTDIR)`
@@ -125,6 +126,11 @@ localbase=`(cd $pkgsrc/pkgtools/pkglint; $bmakeprog show-var VARNAME=LOCALBASE)`
pkg_dbdir=`(cd $pkgsrc/pkgtools/pkglint; $bmakeprog show-var VARNAME=PKG_DBDIR)`
$mkdirprog $sandbox
+cat > $sandbox_script <<EOS
+#! /bin/sh -
+sandbox=$sandbox
+fses="\\
+EOS
echo "Copying the kernel"
$cpprog /netbsd $sandbox
@@ -162,6 +168,7 @@ for d in /bin \
/var/mail; do \
$mkdirprog $sandbox$d; \
$mountprog -r -t null $d $sandbox$d; \
+ echo "$d $d ro \\" >> $sandbox_script
done
echo "Making /tmp in $sandbox"
@@ -171,15 +178,57 @@ $chmodprog 1777 $sandbox/tmp $sandbox/var/tmp
echo "Mount $src from $sandbox"
$mkdirprog $sandbox/usr/src
$mountprog -r -t null $src $sandbox/usr/src
+echo "$src /usr/src ro \\" >> $sandbox_script
echo "Mount $pkgsrc from $sandbox"
$mkdirprog $sandbox/usr/pkgsrc
$mountprog -t null $pkgsrc $sandbox/usr/pkgsrc
+echo "$pkgsrc /usr/pkgsrc rw \\" >> $sandbox_script
echo "Mounting $packages and $distfiles from $sandbox"
$mkdirprog $sandbox/$packages $sandbox/$distfiles
$mountprog -t null $packages $sandbox/$packages
$mountprog -t null $distfiles $sandbox/$distfiles
+echo "$packages $packages rw \\" >> $sandbox_script
+echo "$distfiles $distfiles rw \\" >> $sandbox_script
+
+cat >> $sandbox_script <<EOS
+"
+case x\$1 in
+ xmount)
+ set dummy \$fses
+ shift
+ while [ \$# -ge 3 ]; do
+ fs=\$1; shift
+ mntpoint=\$1; shift
+ rwro=\$1; shift
+ case \$rwro in
+ ro) mount -r -t null \$fs \$sandbox/\$mntpoint || exit 1 ;;
+ rw) mount -t null \$fs \$sandbox/\$mntpoint || exit 1 ;;
+ esac
+ done
+ ;;
+ xumount)
+ set dummy \$fses
+ shift
+ while [ \$# -ge 3 ]; do
+ fs=\$1; shift
+ mntpoint=\$1; shift
+ dummy=\$1; shift
+ umount \$sandbox/\$mntpoint
+ done
+ ;;
+ *)
+ if [ \$# -eq 0 ]; then
+ set dummy /bin/sh
+ shift
+ fi
+ chroot \$sandbox "\$@"
+ ;;
+esac
+EOS
+
+chmod +x $sandbox_script
echo "Sandbox creation is now complete"