added uninstall -a option to remove everything and fixed -w again

This commit is contained in:
Thomas von Dein
2021-01-28 20:18:35 +01:00
parent cee8aa66ef
commit 5de4bf1172

41
jaildk
View File

@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
version=1.16 version=1.17
usage_jaildk() { usage_jaildk() {
beg=`tput -T ${TERM:-cons25} md` beg=`tput -T ${TERM:-cons25} md`
@@ -560,12 +560,17 @@ jaildk_install() {
fi fi
fi fi
type="jail"
if test -n "$rw"; then
type="build chroot"
fi
case $mode in case $mode in
start) start)
bold "Installing jail $jail" bold "Installing $type $jail"
;; ;;
stop) stop)
bold "Unstalling jail $jail" bold "Unstalling $type $jail"
;; ;;
esac esac
@@ -577,7 +582,8 @@ jaildk_install() {
usage_uninstall() { usage_uninstall() {
fin "Usage: $0 uninstall <jail> [-w] fin "Usage: $0 uninstall <jail> [-w]
Uninstall <jail>. Options: Uninstall <jail>. Options:
-w Uninstall writable build chroot." -w Uninstall writable build chroot.
-a Uninstall jail and build chroot."
} }
jaildk_uninstall() { jaildk_uninstall() {
@@ -585,10 +591,14 @@ jaildk_uninstall() {
jail=$1 jail=$1
shift shift
rw='' rw=''
all=''
base=''
version=''
while getopts "w" arg; do while getopts "wa" arg; do
case $arg in case $arg in
w) rw="-w";; w) rw="-w";;
a) all=1; rw="-w";;
*) usage_uninstall;; *) usage_uninstall;;
esac esac
done done
@@ -603,7 +613,26 @@ jaildk_uninstall() {
die "Jail $jail($version) is still running, stop it before removing!" die "Jail $jail($version) is still running, stop it before removing!"
fi fi
jaildk_install $jail stop -r all $rw if test -n "$rw"; then
# we need to find out base and version of actually
# mounted jail, but cannot just use the jail config
# since the user might have mounted another version
base=$(mount | egrep "/base/.*/$jail " | cut -d' ' -f1 | sed 's|.*/||')
version=$(mount | egrep "/appl/.*/$jail/" | cut -d' ' -f1 | sed 's/.*\-//')
fi
if test -z "$base"; then
# no base no umount!
rw=''
all=''
fi
if test -n "$all"; then
jaildk_install $jail stop -r all
jaildk_install $jail stop -r all -b $base -v $version -w
else
jaildk_install $jail stop -r all -b $base -v $version $rw
fi
} }