forked from fediversity/fediversity
		
	Add debug mode to provisioning script
This commit is contained in:
		
							parent
							
								
									5f29388776
								
							
						
					
					
						commit
						797ce362bd
					
				
					 1 changed files with 22 additions and 7 deletions
				
			
		|  | @ -24,6 +24,8 @@ cores=1 | |||
| memory=2048 | ||||
| vm_ids= | ||||
| 
 | ||||
| debug=false | ||||
| 
 | ||||
| help () { | ||||
|   cat <<EOF | ||||
| Usage: $0 [OPTION...] [ID...] | ||||
|  | @ -40,6 +42,7 @@ Other options: | |||
|   --sockets INT     Number of sockets (default: $sockets) | ||||
|   --cores INT       Number of cores (default: $cores) | ||||
|   --memory INT      Memory (default: $memory) | ||||
|   --debug           Run this script in debug mode | ||||
| 
 | ||||
| Others: | ||||
|   -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 | ||||
| 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 | ||||
|   argument=$1 | ||||
|   shift | ||||
|  | @ -62,6 +68,8 @@ while [ $# -gt 0 ]; do | |||
|     --cores) cores=$1; shift ;; | ||||
|     --memory) memory=$1; shift ;; | ||||
| 
 | ||||
|     --debug) debug=true ;; | ||||
| 
 | ||||
|     -h|-\?|--help) help; exit 0 ;; | ||||
| 
 | ||||
|     -*) die_with_help "Unknown argument: '%s'." "$argument" ;; | ||||
|  | @ -91,6 +99,8 @@ readonly memory | |||
| # fi | ||||
| # readonly node | ||||
| 
 | ||||
| readonly debug | ||||
| 
 | ||||
| ################################################################################ | ||||
| ## Getting started | ||||
| 
 | ||||
|  | @ -117,14 +127,19 @@ release_lock () { | |||
| 
 | ||||
| proxmox () { | ||||
|   acquire_lock proxmox | ||||
|   http \ | ||||
|     --form \ | ||||
|     --verify no \ | ||||
|     --ignore-stdin \ | ||||
|     "$@" \ | ||||
|     "Cookie:PVEAuthCookie=$ticket" \ | ||||
|     "CSRFPreventionToken:$csrf_token" | ||||
|   debug 'request %s' "$*" | ||||
|   response=$( | ||||
|     http \ | ||||
|       --form \ | ||||
|       --verify no \ | ||||
|       --ignore-stdin \ | ||||
|       "$@" \ | ||||
|       "Cookie:PVEAuthCookie=$ticket" \ | ||||
|       "CSRFPreventionToken:$csrf_token" | ||||
|   ) | ||||
|   debug 'response to request %s:\n  %s' "$*" "$response" | ||||
|   release_lock proxmox | ||||
|   echo "$response" | ||||
| } | ||||
| 
 | ||||
| ## Synchronous variant for when the `proxmox` function would just respond an | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue