evobackup/lib/bkctld-remove

43 lines
1.2 KiB
Plaintext
Raw Normal View History

2019-01-04 13:51:05 +01:00
#!/bin/sh
#
# Remove jail <jailname> or all
# Usage: remove <jailname>|all
#
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
"${LIBDIR}/bkctld-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
"${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"