Tue Dec 5 20:45:27 2023 UTC ()
pkgtools/mksandbox - update to version 1.11

+ Don't allow mounting of already mounted sandboxes, or unmounting of
unmounted sandboxes.

+ Also, add an extra "ismounted" case label to be able to tell if a
sandbox is mounted. A df(1) invocation should continue to work just
as well :)

No objections on tech-pkg@

Addresses the first part of PR pkg/51992 from Paul Goyette


(agc)
diff -r1.18 -r1.19 pkgsrc/pkgtools/mksandbox/Makefile
diff -r1.18 -r1.19 pkgsrc/pkgtools/mksandbox/files/mksandbox

cvs diff -r1.18 -r1.19 pkgsrc/pkgtools/mksandbox/Makefile (expand / switch to unified diff)

--- pkgsrc/pkgtools/mksandbox/Makefile 2023/08/31 20:14:35 1.18
+++ pkgsrc/pkgtools/mksandbox/Makefile 2023/12/05 20:45:27 1.19
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1# $NetBSD: Makefile,v 1.18 2023/08/31 20:14:35 triaxx Exp $ 1# $NetBSD: Makefile,v 1.19 2023/12/05 20:45:27 agc Exp $
2 2
3PKGNAME= mksandbox-1.10 3PKGNAME= mksandbox-1.11
4CATEGORIES= pkgtools 4CATEGORIES= pkgtools
5 5
6MAINTAINER= agc@NetBSD.org 6MAINTAINER= agc@NetBSD.org
7HOMEPAGE= https://www.NetBSD.org/docs/pkgsrc/bulk.html#setting-up-a-sandbox 7HOMEPAGE= https://www.NetBSD.org/docs/pkgsrc/bulk.html#setting-up-a-sandbox
8COMMENT= Tool for creating sandboxes 8COMMENT= Tool for creating sandboxes
9LICENSE= 2-clause-bsd 9LICENSE= 2-clause-bsd
10 10
11NOT_FOR_PLATFORM= Darwin-*-* 11NOT_FOR_PLATFORM= Darwin-*-*
12 12
13WRKSRC= ${WRKDIR} 13WRKSRC= ${WRKDIR}
14NO_BUILD= yes 14NO_BUILD= yes
15NO_CHECKSUM= yes 15NO_CHECKSUM= yes
16USE_LANGUAGES= # none 16USE_LANGUAGES= # none

cvs diff -r1.18 -r1.19 pkgsrc/pkgtools/mksandbox/files/mksandbox (expand / switch to unified diff)

--- pkgsrc/pkgtools/mksandbox/files/mksandbox 2021/01/22 11:59:52 1.18
+++ pkgsrc/pkgtools/mksandbox/files/mksandbox 2023/12/05 20:45:27 1.19
@@ -1,43 +1,44 @@ @@ -1,43 +1,44 @@
1#! /bin/sh 1#! /bin/sh
2 2
3# $NetBSD: mksandbox,v 1.18 2021/01/22 11:59:52 jperkin Exp $ 3# $NetBSD: mksandbox,v 1.19 2023/12/05 20:45:27 agc Exp $
4 4
5# Copyright (c) 2002,2012 Alistair Crooks <agc@NetBSD.org> 5# Copyright (c) 2002,2012 Alistair Crooks <agc@NetBSD.org>
6# All rights reserved. 6# All rights reserved.
7# 7#
8# Redistribution and use in source and binary forms, with or without 8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions 9# modification, are permitted provided that the following conditions
10# are met: 10# are met:
11# 1. Redistributions of source code must retain the above copyright 11# 1. Redistributions of source code must retain the above copyright
12# notice, this list of conditions and the following disclaimer. 12# notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright 13# 2. Redistributions in binary form must reproduce the above copyright
14# notice, this list of conditions and the following disclaimer in the 14# notice, this list of conditions and the following disclaimer in the
15# documentation and/or other materials provided with the distribution. 15# documentation and/or other materials provided with the distribution.
16# 16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27# 27#
28 28
29# Usage: mksandbox [--mounthost=host] [--rodirs=dir1,...] [--rwdirs=dir1,...] 29# Usage: mksandbox [--mounthost=host] [--pkgsrc=dir]
30# [--pkgsrc=dir] [--src=srcdir] [--xsrc=xsrcdir] 30# [--rodirs=dir1,...] [--rwdirs=dir1,...]
 31# [--src=srcdir] [--xsrc=xsrcdir]
31# [--without-src] [--without-pkgsrc] [--without-xsrc] 32# [--without-src] [--without-pkgsrc] [--without-xsrc]
32# [--without-x] [--verbose] sandbox-dir 33# [--without-x] [--verbose] sandbox-dir
33# 34#
34# A small shell script to set up a sandbox (usually for a pkgsrc bulk 35# A small shell script to set up a sandbox (usually for a pkgsrc bulk
35# build), using null mounts. 36# build), using null mounts.
36 37
37pkgsrc=/usr/pkgsrc 38pkgsrc=/usr/pkgsrc
38src=/usr/src 39src=/usr/src
39xsrc=/usr/xsrc 40xsrc=/usr/xsrc
40rodirs= 41rodirs=
41rwdirs= 42rwdirs=
42with_pkgsrc=yes 43with_pkgsrc=yes
43with_x=yes 44with_x=yes
@@ -408,90 +409,110 @@ if [ -n "$rodirs" ]; then @@ -408,90 +409,110 @@ if [ -n "$rodirs" ]; then
408 echo "$mounthost$dir $dir ro \\" >> $sandbox_script 409 echo "$mounthost$dir $dir ro \\" >> $sandbox_script
409 done 410 done
410fi 411fi
411 412
412if [ -n "$rwdirs" ]; then 413if [ -n "$rwdirs" ]; then
413 for dir in `echo $rwdirs | $sedprog -e 's/,/ /g'`; do 414 for dir in `echo $rwdirs | $sedprog -e 's/,/ /g'`; do
414 echo "Mount $dir from $sandbox" 415 echo "Mount $dir from $sandbox"
415 $mkdirprog $sandbox$dir 416 $mkdirprog $sandbox$dir
416 $mountprog $mountflags $mounthost$dir $sandbox$dir 417 $mountprog $mountflags $mounthost$dir $sandbox$dir
417 echo "$mounthost$dir $dir rw \\" >> $sandbox_script 418 echo "$mounthost$dir $dir rw \\" >> $sandbox_script
418 done 419 done
419fi 420fi
420 421
 422date > $sandbox/.sandbox_mounted
 423
421cat >> $sandbox_script <<EOS 424cat >> $sandbox_script <<EOS
422" 425"
423case x\$1 in 426case x\$1 in
424xmount) 427xmount)
 428 if [ -s \$sandbox/.sandbox_mounted ]; then
 429 echo \$sandbox already mounted && exit 1
 430 fi
425 set dummy \$fses 431 set dummy \$fses
426 shift 432 shift
427 while [ \$# -ge 3 ]; do 433 while [ \$# -ge 3 ]; do
428 fs=\$1; shift 434 fs=\$1; shift
429 mntpoint=\$1; shift 435 mntpoint=\$1; shift
430 rwro=\$1; shift 436 rwro=\$1; shift
431 case \$rwro in 437 case \$rwro in
432 ro) $mountprog $mountflags -r \$fs \$sandbox/\$mntpoint || exit 1 ;; 438 ro) $mountprog $mountflags -r \$fs \$sandbox/\$mntpoint || exit 1 ;;
433 rw) $mountprog $mountflags \$fs \$sandbox/\$mntpoint || exit 1 ;; 439 rw) $mountprog $mountflags \$fs \$sandbox/\$mntpoint || exit 1 ;;
434 esac 440 esac
435 done 441 done
436 case \$opsys in 442 case \$opsys in
437 Darwin|DragonFly|FreeBSD) 443 Darwin|DragonFly|FreeBSD)
438 $mountprog -t devfs devfs \$sandbox/dev 444 $mountprog -t devfs devfs \$sandbox/dev
439 ;; 445 ;;
440 Linux) 446 Linux)
441 $mountprog $mountflags /dev \$sandbox/dev 447 $mountprog $mountflags /dev \$sandbox/dev
442 $mountprog -t tmpfs tmpfs \$sandbox/dev/shm 448 $mountprog -t tmpfs tmpfs \$sandbox/dev/shm
443 ;; 449 ;;
444 SunOS) 450 SunOS)
445 $mountprog -F lofs -r /dev \$sandbox/dev 451 $mountprog -F lofs -r /dev \$sandbox/dev
446 $mountprog -F fd fd \$sandbox/dev/fd 452 $mountprog -F fd fd \$sandbox/dev/fd
447 ;; 453 ;;
448 esac 454 esac
 455 date > \$sandbox/.sandbox_mounted
449 ;; 456 ;;
450xumount) 457xumount)
 458 if [ ! -s \$sandbox/.sandbox_mounted ]; then
 459 echo \$sandbox not mounted && exit 1
 460 fi
451 set dummy \`r3 \$fses\` 461 set dummy \`r3 \$fses\`
452 shift 462 shift
453 while [ \$# -ge 3 ]; do 463 while [ \$# -ge 3 ]; do
454 fs=\$1; shift 464 fs=\$1; shift
455 mntpoint=\$1; shift 465 mntpoint=\$1; shift
456 dummy=\$1; shift 466 dummy=\$1; shift
457 umount \$sandbox/\$mntpoint 467 umount \$sandbox/\$mntpoint
458 done 468 done
459 case \$opsys in 469 case \$opsys in
460 Linux) 470 Linux)
461 umount \$sandbox/dev/shm 471 umount \$sandbox/dev/shm
462 umount \$sandbox/dev 472 umount \$sandbox/dev
463 ;; 473 ;;
464 Darwin|DragonFly|FreeBSD) 474 Darwin|DragonFly|FreeBSD)
465 umount \$sandbox/dev 475 umount \$sandbox/dev
466 ;; 476 ;;
467 SunOS) 477 SunOS)
468 umount \$sandbox/dev/fd 478 umount \$sandbox/dev/fd
469 umount \$sandbox/dev 479 umount \$sandbox/dev
470 ;; 480 ;;
471 esac 481 esac
 482 rm -f \$sandbox/.sandbox_mounted
472 ;; 483 ;;
473xchroot) 484xchroot)
 485 if [ ! -s \$sandbox/.sandbox_mounted ]; then
 486 echo \$sandbox not mounted && exit 1
 487 fi
474 case x\$2 in 488 case x\$2 in
475 x) rootshell=/bin/ksh ;; 489 x) rootshell=/bin/ksh ;;
476 *) rootshell="\$2" ;; 490 *) rootshell="\$2" ;;
477 esac 491 esac
478 script="\$sandbox/tmp/script.\$\$" 492 script="\$sandbox/tmp/script.\$\$"
479 echo "#!/bin/sh" > \$script 493 echo "#!/bin/sh" > \$script
480 echo "ENV=/etc/shrc \$rootshell" >> \$script 494 echo "ENV=/etc/shrc \$rootshell" >> \$script
481 chmod +x \$script 495 chmod +x \$script
482 ENV=/etc/shrc chroot \$sandbox /tmp/\`basename \$script\` 496 ENV=/etc/shrc chroot \$sandbox /tmp/\`basename \$script\`
483 rm -f \$script 497 rm -f \$script
484 ;; 498 ;;
 499xismounted)
 500 if [ -s \$sandbox/.sandbox_mounted ]; then
 501 echo \$sandbox is mounted && exit 0
 502 else
 503 echo \$sandbox is not mounted && exit 1
 504 fi
 505 ;;
485*) 506*)
486 if [ \$# -eq 0 ]; then 507 if [ \$# -eq 0 ]; then
487 set dummy /bin/sh 508 set dummy /bin/sh
488 shift 509 shift
489 fi 510 fi
490 chroot \$sandbox "\$@" 511 chroot \$sandbox "\$@"
491 ;; 512 ;;
492esac 513esac
493EOS 514EOS
494 515
495chmod +x $sandbox_script 516chmod +x $sandbox_script
496 517
497case $opsys in 518case $opsys in