qemush : nouvelle commande spice

This commit is contained in:
Ahurac 2024-03-12 11:55:50 +01:00
parent bbf59bab0b
commit c23eedd9e4

View file

@ -1,5 +1,5 @@
#!/usr/bin/env bash
# version=0.6.1
# version=0.7.0
# Re-exec the script as qemu via sudo (only if needed)
[ "$(whoami)" != qemu ] && exec sudo -E -H -u qemu -- "$0" "$@"
@ -40,6 +40,7 @@ ${name}: usage:
${name} help - show this help
${name} add <path to script> [<VM name>] - add a launching script
${name} do <command> - run shell input as user qemu
${name} spice <running VM> [<TCP port>] - expose a SPICE socket to TCP
EOF
}
@ -166,6 +167,19 @@ public_do() {
exec sh -c "$*"
}
# Expose SPICE via TCP
public_spice() {
QEMUSH_NAME="$1"
if [ -n "$2" ]; then
port=$2
else
port=$(first-free-port 5900)
fi
exec tmux new -d -s "TCP port ${port} -> ${QEMUSH_NAME}" \
socat TCP-LISTEN:"${port},reuseaddr,fork" UNIX-CLIENT:"$(pathof spice)"
}
# Retrieve user requested function
function="$1"
shift