-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathqemush
60 lines (50 loc) · 1.3 KB
/
qemush
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh
# vim: set ts=4:
set -e
SCRIPT_NAME="$(basename "$0")"
VERSION='0.11.1'
HELP_MESSAGE="qemu-openrc $VERSION
Connect to a monitor console of a QEMU virtual machine. It's like virsh from
libvirt, but provided directly by QEMU.
Usage:
$SCRIPT_NAME <VM_NAME | SOCKET_PATH> [command ...]
$SCRIPT_NAME [-h | --help | -V | --version]
VM_NAME Name of the QEMU machine to connect (expects QEMU monitor
socket at /run/qemu/\${VM_NAME}/monitor.sock).
SOCKET_PATH Path of the QEMU's monitor socket to connect.
Project homepage: <https://github.com/jirutka/qemu-openrc>."
socket_path=''
case "$1" in
-h | --help)
echo "$HELP_MESSAGE"
exit 0
;;
-V | --version)
echo "qemu-openrc $VERSION"
exit 0
;;
/*)
socket_path="$1"
break
;;
*)
[ -n "$1" ] || { echo "$HELP_MESSAGE"; exit 1; }
socket_path="/run/qemu/$1/monitor.sock"
break
;;
esac
if [ ! -S "$socket_path" ]; then
echo "ERROR: QEMU monitor socket $socket_path does not exist!" 1>&2
exit 2
fi
if [ -n "$2" ]; then
IFS=$'\n'
shift
printf "%b\n" "$*" | socat - "UNIX-CONNECT:$socket_path"
else
echo 'Connecting to QEMU monitor in interactive mode. Use Ctrl+O to exit.'
echo 'Note: command "quit" does not exit the monitor, but stops VM!'
echo ''
socat -,raw,echo=0,escape=0x0f "UNIX-CONNECT:$socket_path"
fi
printf '\n'