qemush : réécriture de la fonction attach

This commit is contained in:
Ahurac 2024-03-25 15:37:56 +01:00
parent 31557740d4
commit c35664f775

View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# version=0.9.0 # version=0.10.0
# Re-exec the script as qemu via sudo (only if needed) # Re-exec the script as qemu via sudo (only if needed)
[ "$(whoami)" != qemu ] && exec sudo -E -H -u qemu -- "$0" "$@" [ "$(whoami)" != qemu ] && exec sudo -E -H -u qemu -- "$0" "$@"
@ -68,9 +68,19 @@ public_start() {
# Attach to a running virtual machine output, the latest opened if no # Attach to a running virtual machine output, the latest opened if no
# argument is provided # argument is provided
public_attach() { public_attach() {
export QEMUSH_NAME="$1" export QEMUSH_NAME
exec socat -,rawer,escape=15 "UNIX-CONNECT:$(pathof socket)" if [ -n "$1" ]; then
QEMUSH_NAME=$1
socket_path=$(pathof socket)
else
socket_path=$(find ~/sockets/monitors -type s -printf '%T@ %p\n' | sort -r -n | head -1 | cut -d \ -f 2-)
QEMUSH_NAME=$(basename "$socket_path")
fi
printf 'Attaching to \033[1m%s\033[0m, escape with C-d (EOF)\n' "$QEMUSH_NAME"
socat -,rawer,escape=4 "UNIX-CONNECT:${socket_path}"
echo
} }
# List running virtual machines # List running virtual machines