82 lines
2.1 KiB
Bash
Executable file
82 lines
2.1 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}")"
|
||
|
||
btrfs_bin=$(command -v btrfs)
|
||
if [ -z ${btrfs_bin} ]; then
|
||
error "btrfs not found. Please install brtfs-progs."
|
||
fi
|
||
|
||
if is_btrfs "${jail_path}"; then
|
||
${btrfs_bin} 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
|
||
${btrfs_bin} 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"
|