| 1 | #!/bin/sh
|
|---|
| 2 | v=/path/to/VirtualBox/bin
|
|---|
| 3 | VirtualBox="$v"/VirtualBox
|
|---|
| 4 | VBoxManage="$v"/VBoxManage
|
|---|
| 5 |
|
|---|
| 6 | arg="$1"
|
|---|
| 7 | if [ "$arg" != "--child" ]; then
|
|---|
| 8 | vmname="$arg"
|
|---|
| 9 | if [ -z "$vmname" ]; then
|
|---|
| 10 | echo usage: $0 vmname [...] 1>&2
|
|---|
| 11 | exit 1
|
|---|
| 12 | fi
|
|---|
| 13 |
|
|---|
| 14 | shflags=
|
|---|
| 15 | if [ -n "$-" ]; then
|
|---|
| 16 | shflags=-$-
|
|---|
| 17 | fi
|
|---|
| 18 |
|
|---|
| 19 | exec screen -ln -t "$vmname" /bin/sh $shflags "$0" --child "$@"
|
|---|
| 20 | else
|
|---|
| 21 | shift # that "--child" away
|
|---|
| 22 | fi
|
|---|
| 23 |
|
|---|
| 24 | fail() {
|
|---|
| 25 | echo -n 'Press <ENTER> to continue...'
|
|---|
| 26 | read input
|
|---|
| 27 | exit 1
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | vmname="$1"
|
|---|
| 31 | if [ -z "$vmname" ]; then
|
|---|
| 32 | echo usage: $0 vmname [...] 1>&2
|
|---|
| 33 | fail
|
|---|
| 34 | fi
|
|---|
| 35 |
|
|---|
| 36 | if [ ! -t 0 ]; then
|
|---|
| 37 | echo not a tty 1>&2
|
|---|
| 38 | fail
|
|---|
| 39 | fi
|
|---|
| 40 |
|
|---|
| 41 | tty=$(tty)
|
|---|
| 42 | if [ -z "$tty" ]; then
|
|---|
| 43 | echo unable to determine the name of the terminal 1>&2
|
|---|
| 44 | fail
|
|---|
| 45 | fi
|
|---|
| 46 |
|
|---|
| 47 | "$VBoxManage" modifyvm "$vmname" --uartmode1 "$tty" || fail
|
|---|
| 48 | echo VBoxManage modifyvm \""$vmname"\" --uartmode1 \""$tty"\"
|
|---|
| 49 |
|
|---|
| 50 | exec < /dev/null > /dev/null # but leave stderr open
|
|---|
| 51 |
|
|---|
| 52 | exec "$VirtualBox" --startvm "$@"
|
|---|