/
vbconnect
executable file
·58 lines (53 loc) · 1.31 KB
/
vbconnect
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
#!/bin/sh
case $TERM in
*xterm*)
_XTERM_Title() { /bin/echo -en "\e]0;$1\a"; } ;;
*)
_XTERM_Title() { true; } ;;
esac
Telnet() {
socat -,cfmakeraw,echo=0,escape=15 TCP4:localhost:$1
}
VBoxManage() {
if [ "$1" = "-x" ]; then
shift
/bin/echo "# VBoxManage $*" >&2
fi
LC_ALL=en_US.UTF-8 /usr/bin/VBoxManage "$@"
}
VBoxList() { # [class]
VBoxManage list ${1:-runningvms} --long | sed -En "
/^Name:/{s/[^:]*:[[:space:]]*(.*)/\1/;h}
/^UART [0-9]:.*tcp.*server/{s/.*'([^']*)'.*/\1/;G;s/\n/ /;p}
"
}
Machine="$1"
if [ "$Machine" = "STOP!" ]; then
VBoxList | { while read Port Name; do
VBoxManage -x controlvm "$Name" acpipowerbutton
done }
exit 0
fi
if [ -z "$(VBoxList)$1" -o "$Machine" = "-" ]; then
/bin/echo -e "\tAll VMs:"
VBoxList vms
else
VBoxList | {
while read Port Name; do
case "$Machine" in
"") /bin/echo "$Name: $Port" ;;
"$Name"|"$Port") # tabbed bug — need to do it thrice ((
_XTERM_Title "::: $Name"
_XTERM_Title ":: $Name"
_XTERM_Title ": $Name"
Telnet $Port < /dev/tty
exit 0
;;
*) ;;
esac
done
test "$#" = 1 && VBoxManage -x startvm "$Machine" --type headless &&
sleep 1 &&
vbconnect "$Machine" final
}
fi