You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.2 KiB

#!/usr/bin/env bash
# CONSTANTS
BASEDIR=$(dirname "$0")
CONTAINERS=()
YES=false
FORCE=false
# FUNCTIONS
function usage {
echo "$(basename "$0") <CONTAINER_NAME>... [--yes|-y] [--force|-f]"
}
function parse_options {
while [[ $# -gt 0 ]]; do
case "$1" in
--help | -h)
usage && exit 0
;;
--yes | -y)
YES=true
;;
--force | -f)
FORCE=true
;;
-*)
echo >&2 "Error: unknown option: $1" && usage && exit 2
;;
*)
CONTAINERS+=("$1")
;;
esac
shift 1 # Move to the next argument
done
[[ ${#CONTAINERS[@]} == 0 ]] && usage && exit 1 || true
}
function confirm_destructive {
local message="${1:-This cannot be undone!}"
echo "⚠️ WARNING: $message"
read -p "Type YES to confirm: " response
case "$response" in
[yY][eE][sS] | [yY]) return 0 ;;
*) echo "canceled!" && return 1 ;;
esac
}
function force_option {
[[ $FORCE == false ]] && return
echo '--force '
}
function destroy {
[[ $YES == false ]] && confirm_destructive "you are about to destroy ${#CONTAINERS[@]} containers <${CONTAINERS[*]}>" $(force_option)
incus delete "${CONTAINERS[@]}" $(force_option)
}
# MAIN
set -Eue
parse_options $*
destroy