Follow changes in removal script

This commit is contained in:
Nicolas Jeannerod 2025-02-20 11:19:30 +01:00
parent 9611e4ff9a
commit df182d5a67
Signed by: Niols
GPG key ID: 35DB9EC8886E1CB8

View file

@ -11,7 +11,7 @@ readonly api_url=https://192.168.51.81:8006/api2/json
## now, let us just use `node051` everywhere.
readonly node=node051
readonly tmpdir=/tmp/proxmox-provision-$RANDOM
readonly tmpdir=/tmp/proxmox-remove-$RANDOM
mkdir $tmpdir
################################################################################
@ -23,18 +23,22 @@ vm_ids=
help () {
cat <<EOF
Usage: $0 [OPTION...] [ID...]
Usage: $0 [OPTION...] ID [ID...]
Authentication options:
Options:
--username STR Username, with provider (eg. niols@pve)
--password STR Password
If not provided via the command line, username and password will be looked for
in a '.proxmox' file in the current working directory, the username on the
first line, and the password on the second.
Others:
-h|-?|--help Show this help and exit
Options can also be provided by adding assignments to a '.proxmox' file in the
current working directory. For instance, it could contain:
cores=7
username=mireille@pve
debug=true
Command line options take precedence over options found in the '.proxmox' file.
EOF
}
@ -43,6 +47,10 @@ die () { printf '\033[31m'; printf "$@"; printf '\033[0m\n'; exit 2; }
# shellcheck disable=SC2059
die_with_help () { printf '\033[31m'; printf "$@"; printf '\033[0m\n'; help; exit 2; }
if [ -f .proxmox ]; then
. "$PWD"/.proxmox
fi
while [ $# -gt 0 ]; do
argument=$1
shift
@ -58,12 +66,12 @@ while [ $# -gt 0 ]; do
esac
done
if [ -z "$vm_ids" ]; then
die_with_help "Required: at least one VM id.\n"
fi
if [ -z "$username" ] || [ -z "$password" ]; then
if [ -f .proxmox ]; then
{ read -r username; read -r password; } < .proxmox
else
die_with_help "Required: '--username' and '--password'.\n"
fi
die_with_help "Required: '--username' and '--password'.\n"
fi
################################################################################