#!/bin/sh # # Remove jail or all # Usage: remove |all # # shellcheck source=./includes 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 not found" 2 "${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 "Delete jail \`${jail_name}' : OK"