evobackup/lib/bkctld-remove

67 lines
1.8 KiB
Plaintext
Raw Normal View History

2019-01-04 13:51:05 +01:00
#!/bin/sh
#
# Description: Remove jail and all dated copies (incs)
# Usage: remove <jailname>|all
# Return codes:
# * 101 : jail removal aborted
#
2019-01-04 13:51:05 +01:00
2020-04-02 13:44:13 +02:00
# shellcheck source=./includes
2020-04-02 00:31:57 +02:00
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
2019-01-04 13:51:05 +01:00
2020-04-02 13:44:13 +02:00
jail_name="${1:?}"
2020-04-02 01:07:12 +02:00
if [ -z "${jail_name}" ]; then
show_help && exit 1
fi
2020-04-02 01:07:12 +02:00
jail_path=$(jail_path "${jail_name}")
incs_path=$(incs_path "${jail_name}")
2019-01-04 13:51:05 +01:00
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
2020-04-02 01:07:12 +02:00
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
2020-04-02 01:07:12 +02:00
"${LIBDIR}/bkctld-is-on" "${jail_name}" && "${LIBDIR}/bkctld-stop" "${jail_name}"
rm -f "${CONFDIR}/${jail_name}"
jail_inode=$(stat --format=%i "${jail_path}")
2019-01-04 13:51:05 +01:00
if [ "${jail_inode}" -eq 256 ]; then
2020-04-02 01:07:12 +02:00
/bin/btrfs subvolume delete "${jail_path}" | debug
2019-01-04 13:51:05 +01:00
else
2020-04-02 13:44:13 +02:00
rm -rf "${jail_path:?}" | debug
2019-01-04 13:51:05 +01:00
fi
2020-04-02 01:07:12 +02:00
# TODO: use functions here
if [ -d "${incs_path}" ]; then
incs=$(ls "${incs_path}")
2019-01-04 13:51:05 +01:00
for inc in ${incs}; do
2020-04-02 01:07:12 +02:00
inc_inode=$(stat --format=%i "${incs_path}/${inc}")
2019-01-04 13:51:05 +01:00
if [ "${inc_inode}" -eq 256 ]; then
2020-04-02 01:07:12 +02:00
/bin/btrfs subvolume delete "${incs_path}/${inc}" | debug
2019-01-04 13:51:05 +01:00
else
2020-04-20 08:29:21 +02:00
warning "You need to purge \`${incs_path}/${inc}' manually"
2019-01-04 13:51:05 +01:00
fi
done
2020-04-02 01:07:12 +02:00
rmdir --ignore-fail-on-non-empty "${incs_path}" | debug
2019-01-04 13:51:05 +01:00
fi
2020-04-02 01:07:12 +02:00
"${LIBDIR}/bkctld-firewall" "${jail_name}"
2020-04-20 08:29:21 +02:00
notice "Delete jail \`${jail_name}' : OK"