Compare commits

..

7 commits

3 changed files with 22 additions and 6 deletions

View file

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# version=0.6.1 # version=0.7.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" "$@"
@ -40,6 +40,7 @@ ${name}: usage:
${name} help - show this help ${name} help - show this help
${name} add <path to script> [<VM name>] - add a launching script ${name} add <path to script> [<VM name>] - add a launching script
${name} do <command> - run shell input as user qemu ${name} do <command> - run shell input as user qemu
${name} spice <running VM> [<TCP port>] - expose a SPICE socket to TCP
EOF EOF
} }
@ -166,6 +167,19 @@ public_do() {
exec sh -c "$*" 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 # Retrieve user requested function
function="$1" function="$1"
shift shift

View file

@ -25,5 +25,4 @@ my @command = (
); );
print "+ exec ", join(" ", @command), "\n"; print "+ exec ", join(" ", @command), "\n";
exit;
exec @command; exec @command;

View file

@ -1,16 +1,19 @@
#!/bin/sh -x #!/usr/bin/env sh
export QEMUSH_RAM=4G export QEMUSH_RAM=4G
export QEMUSH_BASE=virtiofs,kvm export QEMUSH_BASE=kvm
[ -z "$QEMUSH_NAME" ] && { [ -z "$QEMUSH_NAME" ] && {
export QEMUSH_NAME export QEMUSH_NAME
QEMUSH_NAME=$(basename "$0") QEMUSH_NAME=$(basename "$0")
} }
# Launch the virtual machine # Launch the virtual machine
exec spice \ set -- spice \
-drive file="$(pathof disk)",if=virtio \ -drive file="$(pathof disk)",if=virtio \
-net nic -net user,hostname="${QEMUSH_NAME}" \ -net nic -net user,hostname="${QEMUSH_NAME}" \
-usbdevice tablet \ -usbdevice tablet \
-name "$QEMUSH_NAME" \
-device intel-hda -device hda-duplex,audiodev=snd0 \ -device intel-hda -device hda-duplex,audiodev=snd0 \
"$@" "$@"
# Execute the machine
set -x
exec "$@"