ns-tools

Namespace utilities to reuse Open Source packaging efforts.
git clone git://r-36.net/ns-tools
Log | Files | Refs | LICENSE

commit 4f5ae8cc592b947f0674fc849a2fab2df422b966
parent 84ab05a787db5488718d87a11897e5204e4a0416
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sun, 11 May 2014 15:40:57 +0200

Ns-chroot symlinks and root checks.

1.) ns-chroot can now be linked with the namespace name to automatically run
    it.

	% ln -s /bin/ns-chroot $HOME/bin/gentoo
	% gentoo

    This will run the /ns/gentoo namespace when calling »gentoo«.
2.) ns-prepare and ns-unprepare now check for root and bail if they need to be
    invoked but do not have root rights.

Diffstat:
bin/ns-chroot | 28++++++++++++++++++++++------
bin/ns-prepare | 6++++++
bin/ns-unprepare | 6++++++
3 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/bin/ns-chroot b/bin/ns-chroot @@ -1,17 +1,33 @@ #!/bin/sh -curdir="$(pwd)" - +basen="$(basename "$0")" dounprepare=0 -[ "$1" = "-u" ] && dounprepare=1 && shift 1 -if [ $# -lt 1 ]; +if [ "$basen" != "ns-chroot" ]; then - printf "usage: [-u] %s ns [cmd]\n" "$(basename $0)" >&2 + nsrootn="$basen" + [ "$1" = "-u" ] && dounprepare=1 && shift 1 +else + if [ $# -lt 1 ]; + then + printf "usage: %s [-u] ns [cmd]\n" "$(basename $0)" >&2 + exit 1 + fi + [ "$1" = "-u" ] && dounprepare=1 && shift 1 + + nsrootn="$1" + shift 1 +fi + +if [ -z "$nsrootn" ]; +then + printf "usage: %s [-u] ns [cmd]\n" "$(basename $0)" >&2 exit 1 fi -nsroot="$(ns-root "$1")" +curdir="$(pwd)" + +nsroot="$(ns-root "$nsrootn")" [ $? -gt 0 ] && exit $? [ -e "$nsroot/.ns/rc.conf" ] && . "$nsroot/.ns/rc.conf" diff --git a/bin/ns-prepare b/bin/ns-prepare @@ -20,6 +20,12 @@ shift 1 -a $doforce -eq 0 \ -a $doforceonboot -eq 0 ] && exit 0 +if [ $(id -u) -ne 0 ]; +then + printf "ns-prepare needs to be run with root rights.\n" 2>&1 + exit 1 +fi + MOUNTFS="" UMOUNTFS="" TOUCHFILES="" diff --git a/bin/ns-unprepare b/bin/ns-unprepare @@ -15,6 +15,12 @@ nsroot="$(ns-root "$1")" [ -e "$nsroot/.ns/preparedonboot" -a $doforce -eq 0 ] && exit 0 [ ! -e "$nsroot/.ns/prepared" -a $doforce -eq 0 ] && exit 0 +if [ $(uid -u) -ne 0 ]; +then + printf "ns-unprepare needs to be run with root rights.\n" 2>&1 + exit 1 +fi + MOUNTFS="" UMOUNTFS="" TOUCHFILES=""