Last active
April 26, 2025 17:42
-
-
Save Ethorbit/1060ec0ad41b71a4e59b5a90e96a4311 to your computer and use it in GitHub Desktop.
My Proxmox evsieve hooks for controlling custom events on the host while inside a GPU-passthrough VM. Allows switching between passthrough VMs.
This file contains hidden or 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
[Unit] | |
Description=Run custom evsieve hooks. | |
[Service] | |
Type=simple | |
ExecStart=bash -c '/usr/local/sbin/evsieve-hooks.sh' | |
Restart=always | |
RestartSec=1s | |
[Install] | |
WantedBy=multi-user.target |
This file contains hidden or 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-redragon-K580-keyboard0 \ | |
--hook $key_combo key:delete exec-shell="$0 delete" \ | |
--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 | |
} | |
shutdown_proxmox() | |
{ | |
systemctl poweroff | |
} | |
primary_gpu_vm_1() | |
{ | |
attempt 'qm shutdown 101' | |
attempt 'qm shutdown 111' | |
sleep 2 | |
attempt 'qm start 105' | |
} | |
primary_gpu_vm_2() | |
{ | |
attempt 'qm shutdown 105' | |
attempt 'qm shutdown 111' | |
sleep 2 | |
attempt 'qm start 101' | |
} | |
primary_gpu_vm_3() | |
{ | |
return | |
} | |
primary_gpu_vm_4() | |
{ | |
attempt 'qm shutdown 101' | |
attempt 'qm shutdown 105' | |
sleep 2 | |
attempt 'qm start 111' | |
} | |
secondary_gpu_vm_1() | |
{ | |
attempt 'qm start 103' | |
} | |
case "$KEY" in | |
delete) | |
shutdown_proxmox | |
;; | |
f5) | |
secondary_gpu_vm_1 | |
;; | |
f9) | |
primary_gpu_vm_1 | |
;; | |
f10) | |
primary_gpu_vm_2 | |
;; | |
f11) | |
primary_gpu_vm_3 | |
;; | |
f12) | |
primary_gpu_vm_4 | |
;; | |
esac | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment