Add debug mode to provisioning script

This commit is contained in:
Nicolas Jeannerod 2025-02-19 18:17:59 +01:00
parent 5f29388776
commit 797ce362bd
Signed by untrusted user: Niols
GPG key ID: 35DB9EC8886E1CB8

View file

@ -24,6 +24,8 @@ cores=1
memory=2048 memory=2048
vm_ids= vm_ids=
debug=false
help () { help () {
cat <<EOF cat <<EOF
Usage: $0 [OPTION...] [ID...] Usage: $0 [OPTION...] [ID...]
@ -40,6 +42,7 @@ Other options:
--sockets INT Number of sockets (default: $sockets) --sockets INT Number of sockets (default: $sockets)
--cores INT Number of cores (default: $cores) --cores INT Number of cores (default: $cores)
--memory INT Memory (default: $memory) --memory INT Memory (default: $memory)
--debug Run this script in debug mode
Others: Others:
-h|-?|--help Show this help and exit -h|-?|--help Show this help and exit
@ -51,6 +54,9 @@ die () { printf '\033[31m'; printf "$@"; printf '\033[0m\n'; exit 2; }
# shellcheck disable=SC2059 # shellcheck disable=SC2059
die_with_help () { printf '\033[31m'; printf "$@"; printf '\033[0m\n'; help; exit 2; } die_with_help () { printf '\033[31m'; printf "$@"; printf '\033[0m\n'; help; exit 2; }
# shellcheck disable=SC2059
debug () { if $debug; then printf >&2 '\033[37m'; printf >&2 "$@"; printf >&2 '\033[0m\n'; fi }
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
argument=$1 argument=$1
shift shift
@ -62,6 +68,8 @@ while [ $# -gt 0 ]; do
--cores) cores=$1; shift ;; --cores) cores=$1; shift ;;
--memory) memory=$1; shift ;; --memory) memory=$1; shift ;;
--debug) debug=true ;;
-h|-\?|--help) help; exit 0 ;; -h|-\?|--help) help; exit 0 ;;
-*) die_with_help "Unknown argument: '%s'." "$argument" ;; -*) die_with_help "Unknown argument: '%s'." "$argument" ;;
@ -91,6 +99,8 @@ readonly memory
# fi # fi
# readonly node # readonly node
readonly debug
################################################################################ ################################################################################
## Getting started ## Getting started
@ -117,14 +127,19 @@ release_lock () {
proxmox () { proxmox () {
acquire_lock proxmox acquire_lock proxmox
http \ debug 'request %s' "$*"
--form \ response=$(
--verify no \ http \
--ignore-stdin \ --form \
"$@" \ --verify no \
"Cookie:PVEAuthCookie=$ticket" \ --ignore-stdin \
"CSRFPreventionToken:$csrf_token" "$@" \
"Cookie:PVEAuthCookie=$ticket" \
"CSRFPreventionToken:$csrf_token"
)
debug 'response to request %s:\n %s' "$*" "$response"
release_lock proxmox release_lock proxmox
echo "$response"
} }
## Synchronous variant for when the `proxmox` function would just respond an ## Synchronous variant for when the `proxmox` function would just respond an