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.
51 lines
758 B
51 lines
758 B
#!/usr/bin/env bash
|
|
|
|
# CONSTANTS
|
|
|
|
BASEDIR=$(dirname "$0")
|
|
CONTAINER_NAME=''
|
|
FORCE=false
|
|
|
|
# FUNCTIONS
|
|
|
|
function usage {
|
|
echo "$(basename "$0") <CONTAINER_NAME> [--force|-f]"
|
|
}
|
|
|
|
function parse_options {
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--help | -h)
|
|
usage && exit 0
|
|
;;
|
|
--force | -f)
|
|
FORCE=true
|
|
;;
|
|
*)
|
|
if [[ -z $CONTAINER_NAME ]]; then
|
|
CONTAINER_NAME=$1
|
|
else
|
|
echo >&2 "Unknown option: $1" && usage && exit 2
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
shift 1 # Move to the next argument
|
|
done
|
|
[[ -n $CONTAINER_NAME ]] || (usage && exit 1)
|
|
}
|
|
|
|
function destroy {
|
|
if vmid=$($BASEDIR/pct-lookup "$CONTAINER_NAME"); then
|
|
[[ $FORCE == true ]] && pct stop $vmid
|
|
pct destroy $vmid
|
|
else
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# MAIN
|
|
|
|
set -Eue
|
|
parse_options $*
|
|
destroy
|