How to make the spice-example.sh file executable

Mundo Digital

Active Member
Feb 19, 2020
48
0
26
34
Brasil
How to make the Spice-exemple.sh file self-executable

#!/bin/bash

set -e

# needs pve-manager >= 3.1-44

usage() {
echo "Usage: $0 [-u <string>] [-p <string>] vmid [node [proxy]]"
echo
echo "-u username. Default root@pam"
echo "-p password. Default ''"
echo
echo "vmid: id for VM"
echo "node: Proxmox cluster node name"
echo "proxy: DNS or IP (use <node> as default)"
exit 1
}

PASSWORD=""
USERNAME=""

while getopts ":u:p: " o; do
case "${o}" in
u)
USERNAME="${OPTARG}"
;;
p)
PASSWORD="${OPTARG}"
;;
*)
usage
;;
esac
done

shift $((OPTIND-1))

if [[ -z "$PASSWORD" ]]; then
PASSWORD=""
fi
if [[ -z "$USERNAME" ]]; then
USERNAME='root@pam'
fi

DEFAULTHOST="$(hostname -f)"

# select VM
[[ -z "$1" ]] && usage
VMID="$1"

#[[ -z "$2" ]] && usage
NODE="${2:-$DEFAULTHOST}"

if [[ -z "$3" ]]; then
PROXY="$NODE"
else
PROXY="$3"
fi

NODE="${NODE%%\.*}"

DATA="$(curl -f -s -S -k --data-urlencode "username=$USERNAME" --data-urlencode "password=$PASSWORD" "https://$PROXY:8006/api2/json/access/ticket")"

echo "AUTH OK"

TICKET="${DATA//\"/}"
TICKET="${TICKET##*ticket:}"
TICKET="${TICKET%%,*}"
TICKET="${TICKET%%\}*}"

CSRF="${DATA//\"/}"
CSRF="${CSRF##*CSRFPreventionToken:}"
CSRF="${CSRF%%,*}"
CSRF="${CSRF%%\}*}"

curl -f -s -S -k -b "PVEAuthCookie=$TICKET" -H "CSRFPreventionToken: $CSRF" "https://$PROXY:8006/api2/spiceconfig/nodes/$NODE/qemu/$VMID/spiceproxy" -d "proxy=$PROXY" > spiceproxy

exec remote-viewer spiceproxy
 
Two questions which make it easier to find an consume the script (thanks for sharing):
1. What exact is the purpose?
2. Could you please put that into a "code" section so the forum does not try to interpret that as a smily (as example)
Thanks
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!