diff --git a/CHANGELOG.md b/CHANGELOG.md index b59c51a..179315d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added * bkctld: add a [-f|--force] option to remove confirmation on some commands +* bkctld-remove: confirmation before removal of jails if not in force mode ### Changed diff --git a/lib/bkctld-remove b/lib/bkctld-remove index 30d2594..94d6b19 100755 --- a/lib/bkctld-remove +++ b/lib/bkctld-remove @@ -2,6 +2,8 @@ # # Description: Remove jail and all dated copies (incs) # Usage: remove |all +# Return codes: +# * 101 : jail removal aborted # # shellcheck source=./includes @@ -16,6 +18,28 @@ incs_path=$(incs_path "${jail_name}") test -d "${jail_path}" || error "${jail_name}: jail not found" 2 +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}"