summaryrefslogtreecommitdiff
path: root/mk
diff options
context:
space:
mode:
authoragc <agc@pkgsrc.org>2002-08-07 12:03:00 +0000
committeragc <agc@pkgsrc.org>2002-08-07 12:03:00 +0000
commit742d20ca582ad4bb3547dea23ca2a60230633868 (patch)
tree49e91c2bd5273fcf01257dc80b78e38f6e42c7e4 /mk
parent9a4f22c0ba9162bb3cc79845c58981d57a4580e5 (diff)
downloadpkgsrc-742d20ca582ad4bb3547dea23ca2a60230633868.tar.gz
A small shell script to set up a sandbox (usually for a pkgsrc bulk
build), using null mounts.
Diffstat (limited to 'mk')
-rwxr-xr-xmk/bulk/mksandbox184
1 files changed, 184 insertions, 0 deletions
diff --git a/mk/bulk/mksandbox b/mk/bulk/mksandbox
new file mode 100755
index 00000000000..4681fd884e2
--- /dev/null
+++ b/mk/bulk/mksandbox
@@ -0,0 +1,184 @@
+#! /bin/sh
+
+# $NetBSD: mksandbox,v 1.1 2002/08/07 12:03:00 agc Exp $
+#
+#
+# Copyright (c) 2002 Alistair G. Crooks. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+# must display the following acknowledgement:
+# This product includes software developed by Alistair G. Crooks
+# for the NetBSD project.
+# 4. The name of the author may not be used to endorse or promote
+# products derived from this software without specific prior written
+# permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+# Usage: mksandbox [--pkgsrc=dir] [--src=srcdir] [--verbose] sandbox-dir
+#
+# A small shell script to set up a sandbox (usually for a pkgsrc bulk
+# build, using null mounts).
+
+pkgsrc=/usr/pkgsrc
+src=/usr/src
+
+opsys=`uname -s`
+case "$opsys" in
+Darwin)
+ bmakeprog=bmake
+ chmodprog=/bin/chmod
+ cpprog=/bin/cp
+ gtarprog=/usr/bin/gnutar
+ mkdirprog="/bin/mkdir -p"
+ mountprog=/sbin/mount
+ paxprog=/bin/pax
+ sedprog=/usr/bin/sed
+ ;;
+Linux)
+ bmakeprog=bmake
+ chmodprog=/bin/chmod
+ cpprog=/bin/cp
+ gtarprog=/bin/tar
+ mkdirprog="/bin/mkdir -p"
+ mountprog=/sbin/mount
+ paxprog=""
+ sedprog=/bin/sed
+ ;;
+NetBSD)
+ bmakeprog=make
+ chmodprog=/bin/chmod
+ cpprog=/bin/cp
+ gtarprog=/usr/bin/tar
+ mkdirprog="/bin/mkdir -p"
+ mountprog=/sbin/mount
+ paxprog=/bin/pax
+ sedprog=/usr/bin/sed
+ ;;
+SunOS)
+ bmakeprog=bmake
+ chmodprog=/usr/bin/chmod
+ cpprog=/usr/bin/cp
+ gtarprog=""
+ mkdirprog="/usr/bin/mkdir -p"
+ mountprog=/sbin/mount
+ paxprog=/bin/pax
+ sedprog=/usr/xpg4/bin/sed
+ ;;
+*)
+ echo "Unknown Operating System ($opsys) - good luck"
+ bmakeprog=bmake
+ chmodprog=chmod
+ cpprog=cp
+ gtarprog="tar"
+ mkdirprog="mkdir -p"
+ mountprog=mount
+ paxprog=pax
+ sedprog=sed
+ ;;
+esac
+
+while [ $# -gt 0 ]; do
+ case "$1" in
+ --pkgsrc=*) pkgsrc=`echo $1 | $sedprog -e 's|^--pkgsrc=||'` ;;
+ --src=*) src=`echo $1 | $sedprog -e 's|^--src=||'` ;;
+ --verbose) set -x ;;
+ *) break ;;
+ esac
+ shift
+done
+
+if [ $# -ne 1 ]; then
+ echo "Usage: mksandbox [--pkgsrc=dir] [--src=srcdir] [--verbose] sandbox-dir"
+ exit 1
+fi
+
+if [ `id -u` -ne 0 ]; then
+ echo "You must be root to run this script"
+ exit 1
+fi
+
+sandbox=$1
+
+packages=`(cd $pkgsrc/pkgtools/pkglint; $bmakeprog show-var VARNAME=PACKAGES)`
+distfiles=`(cd $pkgsrc/pkgtools/pkglint; $bmakeprog show-var VARNAME=DISTDIR)`
+localbase=`(cd $pkgsrc/pkgtools/pkglint; $bmakeprog show-var VARNAME=LOCALBASE)`
+pkg_dbdir=`(cd $pkgsrc/pkgtools/pkglint; $bmakeprog show-var VARNAME=PKG_DBDIR)`
+
+$mkdirprog $sandbox
+
+echo "Copying the kernel"
+$cpprog /netbsd $sandbox
+
+echo "Checking package hierarchy in $localbase and package database in $pkg_dbdir exist"
+$mkdirprog $sandbox/$localbase $sandbox/$pkg_dbdir
+
+echo "Make and populate $sandbox/dev"
+$mkdirprog $sandbox/dev
+$cpprog /dev/MAKEDEV* $sandbox/dev
+(cd $sandbox/dev; ./MAKEDEV all)
+
+echo "Make and populate $sandbox/etc"
+$mkdirprog $sandbox/etc
+case "$paxprog" in
+"") (cd /etc; $gtarprog -cf - . | (cd $sandbox/etc; $gtarprog xf - )) ;;
+*) (cd /etc; $paxprog -rwpe . $sandbox/etc) ;;
+esac
+$cpprog /usr/share/zoneinfo/GMT $sandbox/etc/localtime
+
+echo "Make empty dirs upon which to mount the null mounts"
+for d in /bin \
+ /sbin \
+ /usr/X11R6 \
+ /usr/bin \
+ /usr/games \
+ /usr/include \
+ /usr/lib \
+ /usr/libdata \
+ /usr/libexec \
+ /usr/lkm \
+ /usr/share \
+ /usr/sbin; do \
+ $mkdirprog $sandbox$d; \
+ $mountprog -r -t null $d $sandbox$d; \
+done
+
+echo "Making /tmp in $sandbox"
+$mkdirprog $sandbox/tmp $sandbox/var/tmp
+$chmodprog 1777 $sandbox/tmp $sandbox/var/tmp
+
+echo "Mount /usr/src in $sandbox"
+$mkdirprog $sandbox/usr/src
+$mountprog -r -t null $src $sandbox/usr/src
+
+echo "Mount /usr/pkgsrc in $sandbox"
+$mkdirprog $sandbox/usr/pkgsrc
+$mountprog -t null $pkgsrc $sandbox/usr/pkgsrc
+
+echo "Mounting $packages and $distfiles from $sandbox"
+$mkdirprog $packages $distfiles
+$mountprog -t null $packages $sandbox/$packages
+$mountprog -t null $distfiles $sandbox/$distfiles
+
+echo "Sandbox creation is now complete"
+
+exit 0