78 lines
2 KiB
Bash
Executable file
78 lines
2 KiB
Bash
Executable file
#!/bin/sh
|
|
#
|
|
# Description: Remove jail and all dated copies (incs)
|
|
# Usage: remove <jailname>|all
|
|
# Return codes:
|
|
# * 101 : jail removal aborted
|
|
#
|
|
|
|
# shellcheck source=./includes
|
|
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
|
|
|
|
jail_name="${1:?}"
|
|
if [ -z "${jail_name}" ]; then
|
|
show_help && exit 1
|
|
fi
|
|
jail_path=$(jail_path "${jail_name}")
|
|
incs_path=$(incs_path "${jail_name}")
|
|
|
|
if ! test -d "${jail_path}"; then
|
|
if [ "${FORCE}" = "1" ]; then
|
|
warning "${jail_name}: jail not found (ignore in FORCE mode)"
|
|
exit 0
|
|
else
|
|
error "${jail_name}: jail not found" 2
|
|
fi
|
|
fi
|
|
|
|
if [ "${FORCE}" != "1" ]; then
|
|
answer=""
|
|
while :; do
|
|
printf "> Are you sure you want to delete jail \`%s'? [Y,n,?] " "${jail_name}"
|
|
read -r answer
|
|
case $answer in
|
|
[Yy]|"" )
|
|
break
|
|
;;
|
|
[Nn] )
|
|
tty -s && echo "Abort." >&2
|
|
exit 101
|
|
;;
|
|
* )
|
|
printf "y - yes, execute actions and exit\n"
|
|
printf "n - no, don't execute actions and exit\n"
|
|
printf "? - print this help\n"
|
|
;;
|
|
esac
|
|
done
|
|
fi
|
|
|
|
"${LIBDIR}/bkctld-is-on" "${jail_name}" && "${LIBDIR}/bkctld-stop" "${jail_name}"
|
|
|
|
rm -f "${CONFDIR}/${jail_name}"
|
|
rm -rf "$(jail_config_dir "${jail_name}")"
|
|
|
|
jail_inode=$(stat --format=%i "${jail_path}")
|
|
if [ "${jail_inode}" -eq 256 ]; then
|
|
/bin/btrfs subvolume delete "${jail_path}" | debug
|
|
else
|
|
rm -rf "${jail_path:?}" | debug
|
|
fi
|
|
|
|
# TODO: use functions here
|
|
if [ -d "${incs_path}" ]; then
|
|
incs=$(ls "${incs_path}")
|
|
for inc in ${incs}; do
|
|
inc_inode=$(stat --format=%i "${incs_path}/${inc}")
|
|
if [ "${inc_inode}" -eq 256 ]; then
|
|
/bin/btrfs subvolume delete "${incs_path}/${inc}" | debug
|
|
else
|
|
warning "You need to purge \`${incs_path}/${inc}' manually"
|
|
fi
|
|
done
|
|
rmdir --ignore-fail-on-non-empty "${incs_path}" | debug
|
|
fi
|
|
|
|
"${LIBDIR}/bkctld-firewall" "${jail_name}"
|
|
notice "Delete jail \`${jail_name}' : OK"
|