Created
December 30, 2023 11:56
-
-
Save Ethorbit/8c584acd06ca63b0b0a883358779768e to your computer and use it in GitHub Desktop.
proxmox-evsieve-hooks.sh Allows me to switch virtual machines at the press of a button without the need to login to the web ui
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
source /root/.bashrc | |
KEY="$1" | |
if [ -z "$KEY" ]; then | |
key_combo="key:rightshift key:rightalt key:rightctrl" | |
evsieve --input /dev/input/by-id/uinput-persist-z12-keyboard0 \ | |
--hook $key_combo key:f5 exec-shell="$0 f5" \ | |
--hook $key_combo key:f9 exec-shell="$0 f9" \ | |
--hook $key_combo key:f10 exec-shell="$0 f10" \ | |
--hook $key_combo key:f11 exec-shell="$0 f11" \ | |
--hook $key_combo key:f12 exec-shell="$0 f12" | |
else | |
MAX_ATTEMPTS="5" # How many attempts to run command before giving up. (Each attempt is 1 second) | |
attempt() | |
{ | |
command="$1" | |
attempts="${2:-0}" | |
if [ "$attempts" -ge "$MAX_ATTEMPTS" ]; then | |
echo "Failed to run command, giving up.." | |
return | |
fi | |
eval "$command" | |
if [ "$?" -ne 0 ]; then | |
sleep 1 | |
attempt "$command" "$(($attempts+1))" | |
return | |
fi | |
} | |
primary_gpu_vm_1() | |
{ | |
attempt 'qm start 102' | |
} | |
secondary_gpu_vm_1() | |
{ | |
attempt 'qm shutdown 101' | |
sleep 2 | |
attempt 'qm start 100' | |
} | |
secondary_gpu_vm_2() | |
{ | |
attempt 'qm shutdown 100' | |
sleep 2 | |
attempt 'qm start 101' | |
} | |
secondary_gpu_vm_3() | |
{ | |
return | |
} | |
secondary_gpu_vm_4() | |
{ | |
return | |
} | |
case "$KEY" in | |
f5) | |
primary_gpu_vm_1 | |
;; | |
f9) | |
secondary_gpu_vm_1 | |
;; | |
f10) | |
secondary_gpu_vm_2 | |
;; | |
f11) | |
secondary_gpu_vm_3 | |
;; | |
f12) | |
secondary_gpu_vm_4 | |
;; | |
esac | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment