diff options
author | wiz <wiz@pkgsrc.org> | 2012-08-26 10:31:23 +0000 |
---|---|---|
committer | wiz <wiz@pkgsrc.org> | 2012-08-26 10:31:23 +0000 |
commit | fb7a43c3637a229f4a61eaf9e18f12929e9e2e79 (patch) | |
tree | c573f52e3ea60b031e4036d895486c0590d0afd4 /pkgtools/mksandbox | |
parent | 60df8bd1e585799615997856f0231ebe9c4fb750 (diff) | |
download | pkgsrc-fb7a43c3637a229f4a61eaf9e18f12929e9e2e79.tar.gz |
Import mksandbox-1.0 as pkgtools/mksandbox.
A small shell script to set up a sandbox (usually for a pkgsrc bulk
build), using null mounts.
The file lived in pkgsrc/mk/bulk/mksandbox, but is worthy of its own
package IMHO. New: with manpage.
Diffstat (limited to 'pkgtools/mksandbox')
-rw-r--r-- | pkgtools/mksandbox/DESCR | 2 | ||||
-rw-r--r-- | pkgtools/mksandbox/Makefile | 34 | ||||
-rw-r--r-- | pkgtools/mksandbox/PLIST | 3 | ||||
-rwxr-xr-x | pkgtools/mksandbox/files/mksandbox | 438 | ||||
-rw-r--r-- | pkgtools/mksandbox/files/mksandbox.8 | 84 |
5 files changed, 561 insertions, 0 deletions
diff --git a/pkgtools/mksandbox/DESCR b/pkgtools/mksandbox/DESCR new file mode 100644 index 00000000000..8316b79eb2e --- /dev/null +++ b/pkgtools/mksandbox/DESCR @@ -0,0 +1,2 @@ +A small shell script to set up a sandbox (usually for a pkgsrc bulk +build), using null mounts. diff --git a/pkgtools/mksandbox/Makefile b/pkgtools/mksandbox/Makefile new file mode 100644 index 00000000000..bd384dab19a --- /dev/null +++ b/pkgtools/mksandbox/Makefile @@ -0,0 +1,34 @@ +# $NetBSD: Makefile,v 1.1 2012/08/26 10:31:23 wiz Exp $ + +DISTNAME= mksandbox-1.0 +CATEGORIES= pkgtools +MASTER_SITES= # none +DISTFILES= # none + +MAINTAINER= pkgsrc-users@NetBSD.org +HOMEPAGE= http://www.NetBSD.org/docs/pkgsrc/bulk.html#setting-up-a-sandbox +COMMENT= Tool for creating sandboxes +LICENSE= original-bsd + +PKG_DESTDIR_SUPPORT= user-destdir + +WRKSRC= ${WRKDIR} +NO_BUILD= yes +USE_LANGUAGES= # none +INSTALLATION_DIRS= sbin ${PKGMANDIR}/man8 + +do-extract: + cd ${FILESDIR} && cp mksandbox mksandbox.8 ${WRKSRC}/ + +.include "../../mk/bsd.prefs.mk" + +SUBST_CLASSES+= up +SUBST_STAGE.up= do-configure +SUBST_FILES.up= mksandbox mksandbox.8 +SUBST_SED.up+= -e 's,/usr/pkgsrc,${PKGSRCDIR},g' + +do-install: + ${INSTALL_SCRIPT} ${WRKSRC}/mksandbox ${DESTDIR}${PREFIX}/sbin/ + ${INSTALL_MAN} ${WRKSRC}/mksandbox.8 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man8 + +.include "../../mk/bsd.pkg.mk" diff --git a/pkgtools/mksandbox/PLIST b/pkgtools/mksandbox/PLIST new file mode 100644 index 00000000000..a871cf10da6 --- /dev/null +++ b/pkgtools/mksandbox/PLIST @@ -0,0 +1,3 @@ +@comment $NetBSD: PLIST,v 1.1 2012/08/26 10:31:23 wiz Exp $ +sbin/mksandbox +man/man8/mksandbox.8 diff --git a/pkgtools/mksandbox/files/mksandbox b/pkgtools/mksandbox/files/mksandbox new file mode 100755 index 00000000000..add0f48df30 --- /dev/null +++ b/pkgtools/mksandbox/files/mksandbox @@ -0,0 +1,438 @@ +#! /bin/sh + +# $NetBSD: mksandbox,v 1.1 2012/08/26 10:31:23 wiz 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] [--xsrc=xsrcdir] [--without-x] [--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 +xsrc=/usr/xsrc +with_x=yes + +kernel="" +sandboxWriteDirs="" +sandboxMountDirs="/bin /sbin /lib /libexec /usr/X11R7 /usr/bin /usr/games /usr/include /usr/lib /usr/libdata /usr/libexec /usr/lkm /usr/share /usr/sbin /var/mail" +sandboxEmptyDirs="/var/run /var/log /var/spool/lock /var/spool/mqueue" +sandboxEmptyFiles="/var/run/utmp /var/run/utmpx /var/log/wtmp /var/log/wtmpx /var/log/lastlog /var/log/lastlogx" + +usage() +{ + echo "Usage: mksandbox [--mounthost=host] [--pkgsrc=dir] [--src=srcdir] [--xsrc=xsrcdir] [--without-x] [--verbose] sandbox-dir" + exit 1 +} + +err() +{ + echo "error: $1" + exit 1 +} + +# by default, don't require src and xsrc to be available +need_src=no +need_xsrc=no + +opsys=`uname -s` +case "$opsys" in +Darwin) + bmakeprog=bmake + chmodprog=/bin/chmod + chownprog=/usr/sbin/chown + cpprog=/bin/cp + gtarprog=/usr/bin/gnutar + idprog=/usr/bin/id + kernel=/mach_kernel + mkdirprog="/bin/mkdir -p" + mountflags="-t nfs" + mounthost="localhost" + mountprog=/sbin/mount + paxprog=/bin/pax + sedprog=/usr/bin/sed + sandboxEmptyDirs="$sandboxEmptyDirs /var/root" + sandboxMountDirs="$sandboxMountDirs /usr/llvm-gcc-4.2 /usr/X11 /System/Library /Library" + sandboxWriteDirs="$sandboxWriteDirs /Library/Server/Mail/Data" + ;; +FreeBSD) + bmakeprog=bmake + chmodprog=/bin/chmod + chownprog=/usr/sbin/chown + cpprog=/bin/cp + gtarprog=/usr/bin/tar + idprog=/usr/bin/id + mkdirprog="/bin/mkdir -p" + mountflags="-t nullfs" + mountprog=/sbin/mount + paxprog=/bin/pax + sedprog=/usr/bin/sed + ;; +Interix) + echo >&2 "This script cannot be used on Interix; a different procedure is required." + echo >&2 "(To be documented.)" + exit 1 + ;; +Linux) + bmakeprog=bmake + chmodprog=/bin/chmod + chownprog=/bin/chown + cpprog=/bin/cp + gtarprog=/bin/tar + idprog=/usr/bin/id + mkdirprog="/bin/mkdir -p" + mountflags="--bind" + if [ -f /bin/mount ]; then + mountprog=/bin/mount + else + mountprog=/sbin/mount + fi + paxprog="" + sedprog=/bin/sed + sandboxMountDirs="$sandboxMountDirs /proc /usr/kerberos" + ;; +NetBSD) + bmakeprog=make + chmodprog=/bin/chmod + chownprog=/usr/sbin/chown + cpprog=/bin/cp + gtarprog=/usr/bin/tar + idprog=/usr/bin/id + kernel=/netbsd + mkdirprog="/bin/mkdir -p" + mountflags="-t null" + mountprog=/sbin/mount + paxprog=/bin/pax + sedprog=/usr/bin/sed + need_src=yes + need_xsrc=yes + ;; +SunOS) + bmakeprog=bmake + chmodprog=/usr/bin/chmod + chownprog=/usr/bin/chown + cpprog=/usr/bin/cp + gtarprog="" + idprog=/usr/xpg4/bin/id + mkdirprog="/usr/bin/mkdir -p" + mountflags="-F lofs" + mountprog=/sbin/mount + paxprog=/bin/pax + sedprog=/usr/xpg4/bin/sed + sandboxMountDirs="/bin /sbin /kernel /lib /proc /opt/SUNWspro /usr/X11R6 /usr/5bin /usr/bin /usr/ccs /usr/dt /usr/games /usr/include /usr/lib /usr/openwin /usr/share /usr/sbin /usr/sadm /usr/ucb /usr/ucblib /usr/xpg4 /var/mail /var/sadm" + sandboxEmptyDirs="$sandboxEmptyDirs /usr/tmp /var/tmp" + ;; +*) + echo "Unknown Operating System ($opsys) - good luck" + bmakeprog=bmake + chmodprog=chmod + chownprog=chown + cpprog=cp + gtarprog="tar" + idprog="id" + mkdirprog="mkdir -p" + mountflags="-t null" + mountprog=mount + paxprog=pax + sedprog=sed + ;; +esac + +while [ $# -gt 0 ]; do + case "$1" in + --mounthost=*) mounthost=`echo $1 | $sedprog -e 's|^--mounthost=||'` ;; + --pkgsrc=*) pkgsrc=`echo $1 | $sedprog -e 's|^--pkgsrc=||'` ;; + --src=*) src=`echo $1 | $sedprog -e 's|^--src=||'` ;; + --xsrc=*) xsrc=`echo $1 | $sedprog -e 's|^--xsrc=||'` ;; + --without-x) with_x=no ;; + --verbose) set -x ;; + -*) usage ;; + *) break ;; + esac + shift +done + +if [ $# -ne 1 ]; then + usage +fi + +if [ "$with_x" = "no" ]; then + need_xsrc=no +fi + +if [ `$idprog -u` -ne 0 ]; then + err "You must be root to run this script." +fi + +if [ -n "$mounthost" ]; then + mounthost="$mounthost:" +fi + +if [ ! -d $pkgsrc ]; then + err "pkgsrc directory $pkgsrc does not exist." +fi + +if [ ! -d $src -a "$need_src" = "yes" ]; then + err "source directory $src does not exist." +fi + +if [ ! -d $xsrc -a "$need_xsrc" = "yes" ]; then + err "xsrc directory $xsrc does not exist." +fi + +sandbox=$1 +sandbox_script="$sandbox/sandbox" + +packages=`(cd $pkgsrc/pkgtools/lintpkgsrc; $bmakeprog show-var VARNAME=PACKAGES)` +distfiles=`(cd $pkgsrc/pkgtools/lintpkgsrc; $bmakeprog show-var VARNAME=DISTDIR)` +localbase=`(cd $pkgsrc/pkgtools/lintpkgsrc; $bmakeprog show-var VARNAME=LOCALBASE)` +pkg_dbdir=`(cd $pkgsrc/pkgtools/lintpkgsrc; $bmakeprog show-var VARNAME=PKG_DBDIR)` +localpatches=`(cd $pkgsrc/pkgtools/lintpkgsrc; $bmakeprog show-var VARNAME=LOCALPATCHES)` + +test -d "$localpatches" || echo "WARNING: LOCALPATCHES directory does not exist - ignoring" + +$mkdirprog $sandbox +cat > $sandbox_script <<EOS +#! /bin/sh - +mounthost=$mounthost +opsys=$opsys +sandbox=$sandbox + +r3() { + _R= + while [ \$# -ge 3 ] + do + _R="\$1 \$2 \$3 \$_R" + shift; shift; shift + done + echo "\$_R" +} + +fses="\\ +EOS + +if [ ! -z "$kernel" ]; then + echo "Copying the kernel" + $cpprog $kernel $sandbox +fi + +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 + +case "$opsys" in +Darwin|FreeBSD) + $mountprog -t devfs devfs $sandbox/dev + ;; +SunOS) + /usr/sbin/devfsadm -r $sandbox + if [ -f /usr/ucblib/ucblinks.awk -a -x /usr/ucb/ucblinks ]; then + /usr/ucb/ucblinks -r $sandbox + fi + ;; +Linux) + $mountprog $mountflags /dev $sandbox/dev + ;; +*) + $cpprog /dev/MAKEDEV* $sandbox/dev + (cd $sandbox/dev; ./MAKEDEV all) +esac + +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 +rm -f $sandbox/etc/localtime + +case "$opsys" in +SunOS) + $cpprog /etc/TIMEZONE $sandbox/etc/TIMEZONE + ;; +*) + $cpprog /usr/share/zoneinfo/GMT $sandbox/etc/localtime + ;; +esac + +echo "Make empty dirs upon which to mount the null mounts" +for d in $sandboxMountDirs; do + test -d $d || continue; + case $d in + *X11*) test "$with_x" = "yes" || continue ;; + esac + $mkdirprog $sandbox$d; + $mountprog $mountflags -r $mounthost$d $sandbox$d; + echo "$mounthost$d $d ro \\" >> $sandbox_script +done +for d in $sandboxWriteDirs; do + test -d $d || continue; + $mkdirprog $sandbox$d; + $mountprog $mountflags $mounthost$d $sandbox$d; + echo "$mounthost$d $d rw \\" >> $sandbox_script +done + +echo "Making /tmp in $sandbox" +$mkdirprog $sandbox/tmp $sandbox/var/tmp +$chmodprog 1777 $sandbox/tmp $sandbox/var/tmp + +echo "Making /var/games in $sandbox" +$mkdirprog $sandbox/var/games +$chownprog games:games $sandbox/var/games +$chmodprog 2775 $sandbox/var/games + +for d in $sandboxEmptyDirs; do + test -d $d || continue + echo "Making $d in $sandbox" + $mkdirprog $sandbox$d +done + +for f in $sandboxEmptyFiles; do + test -f $f || continue + echo "Making $f in $sandbox" + $cpprog /dev/null $sandbox$f +done + +if [ "$need_src" = "yes" ]; then + echo "Mount $src from $sandbox" + $mkdirprog $sandbox/usr/src + $mountprog $mountflags -r $mounthost$src $sandbox/usr/src + echo "$mounthost$src /usr/src ro \\" >> $sandbox_script +fi + +echo "Mount $pkgsrc from $sandbox" +$mkdirprog $sandbox/usr/pkgsrc +$mountprog $mountflags $mounthost$pkgsrc $sandbox/usr/pkgsrc +echo "$mounthost$pkgsrc /usr/pkgsrc rw \\" >> $sandbox_script + +if [ "$need_xsrc" = "yes" ]; then + echo "Mount $xsrc from $sandbox" + $mkdirprog $sandbox/usr/xsrc + $mountprog $mountflags -r $mounthost$xsrc $sandbox/usr/xsrc + echo "$mounthost$xsrc /usr/xsrc ro \\" >> $sandbox_script +fi + +echo "Mounting $packages and $distfiles from $sandbox" +$mkdirprog $sandbox/$packages $sandbox/$distfiles +$mkdirprog $packages $distfiles +$mountprog $mountflags $mounthost$packages $sandbox/$packages +$mountprog $mountflags $mounthost$distfiles $sandbox/$distfiles +echo "$mounthost$packages $packages rw \\" >> $sandbox_script +echo "$mounthost$distfiles $distfiles rw \\" >> $sandbox_script + +if [ -n "$localpatches" ] && [ -d "$localpatches" ]; then + echo "Mounting $localpatches from $sandbox" + $mkdirprog $sandbox/$localpatches + $mountprog $mountflags $mounthost$localpatches $sandbox/$localpatches + echo "$mounthost$localpatches $localpatches rw \\" >> $sandbox_script +fi + +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) $mountprog $mountflags -r \$fs \$sandbox/\$mntpoint || exit 1 ;; + rw) $mountprog $mountflags \$fs \$sandbox/\$mntpoint || exit 1 ;; + esac + done + case \$opsys in + Darwin|FreeBSD) + $mountprog -t devfs devfs \$sandbox/dev + ;; + Linux) + $mountprog $mountflags /dev \$sandbox/dev + ;; + esac + ;; +xumount) + set dummy \`r3 \$fses\` + shift + while [ \$# -ge 3 ]; do + fs=\$1; shift + mntpoint=\$1; shift + dummy=\$1; shift + umount \$sandbox/\$mntpoint + done + case \$opsys in + Darwin|FreeBSD|Linux) + umount \$sandbox/dev + ;; + esac + ;; +xchroot) + case x\$2 in + x) rootshell=/bin/ksh ;; + *) rootshell="\$2" ;; + esac + script="\$sandbox/tmp/script.\$\$" + echo "#!/bin/sh" > \$script + echo "ENV=/etc/shrc \$rootshell" >> \$script + chmod +x \$script + ENV=/etc/shrc chroot \$sandbox /tmp/\`basename \$script\` + rm -f \$script + ;; +*) + if [ \$# -eq 0 ]; then + set dummy /bin/sh + shift + fi + chroot \$sandbox "\$@" + ;; +esac +EOS + +chmod +x $sandbox_script + +case $opsys in +Darwin) + $cpprog /var/run/resolv.conf $sandbox/var/run/resolv.conf + ;; +SunOS) + $cpprog /etc/mnttab $sandbox/etc/mnttab + ;; +*) +esac + +echo "Sandbox creation is now complete" + +exit 0 diff --git a/pkgtools/mksandbox/files/mksandbox.8 b/pkgtools/mksandbox/files/mksandbox.8 new file mode 100644 index 00000000000..4fcd2e9e81f --- /dev/null +++ b/pkgtools/mksandbox/files/mksandbox.8 @@ -0,0 +1,84 @@ +.\" $NetBSD: mksandbox.8,v 1.1 2012/08/26 10:31:23 wiz Exp $ +.\" +.\" Copyright (c) 2012 Thomas Klausner. 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 Thomas Klausner +.\" 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. +.\" +.Dd August 26, 2012 +.Dt MKSANDBOX 8 +.Os +.Sh NAME +.Nm mksandbox +.Nd set up a sandbox +.Sh SYNOPSIS +.Nm +.Op Fl Fl pkgsrc Ns = Ns Ar dir +.Op Fl Fl src Ns = Ns Ar srcdir +.Op Fl Fl verbose +.Op Fl Fl without-x +.Op Fl Fl xsrc Ns = Ns Ar xsrcdir +.Ar sandbox-dir +.Sh DESCRIPTION +.Nm +is a small shell script to set up a sandbox (usually for a pkgsrc bulk +build), using null mounts. +The sandbox is set up for the target directory +.Ar sandbox-dir . +.Pp +The supported options are: +.Bl -tag -width "Xpkgsrc=dirXXX" +.It Fl Fl pkgsrc Ns = Ns Ar dir +Look for the pkgsrc files in +.Ar dir +instead of the default +.Pa /usr/pkgsrc . +.It Fl Fl src Ns = Ns Ar srcdir +Look for the +.Nx +src files in +.Ar dir +instead of the default +.Pa /usr/src +(only needed for some packages that compile kernel modules). +.It Fl Fl verbose +More verbose output. +.It Fl Fl without-x +Do not include X files in the sandbox. +.It Fl Fl xsrc Ns = Ns Ar xsrcdir +Look for the +.Nx +xsrc files in +.Ar dir +instead of the default +.Pa /usr/src +(only needed for some packages). +.El +.Sh AUTHORS +.An Alistair G. Crooks +.Aq agc@NetBSD.org |