forked from evolix/evobackup
43 lines
1.2 KiB
Bash
Executable file
43 lines
1.2 KiB
Bash
Executable file
#!/bin/sh
|
|
#
|
|
# Remove jail <jailname> or all
|
|
# Usage: remove <jailname>|all
|
|
#
|
|
|
|
# shellcheck source=./config
|
|
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
|
|
|
|
jail_name="${1:-}"
|
|
if [ -z "${jail_name}" ]; then
|
|
"${LIBDIR}/bkctld-help" && exit 1
|
|
fi
|
|
jail_path=$(jail_path "${jail_name}")
|
|
incs_path=$(incs_path "${jail_name}")
|
|
|
|
test -d "${jail_path}" || error "${jail_name}: jail is missing."
|
|
|
|
"${LIBDIR}/bkctld-is-on" "${jail_name}" && "${LIBDIR}/bkctld-stop" "${jail_name}"
|
|
|
|
rm -f "${CONFDIR}/${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 "${jail_name}: jail has been deleted."
|