diff options
-rwxr-xr-x | login-machine | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/login-machine b/login-machine index 18e1f34..1fd6f38 100755 --- a/login-machine +++ b/login-machine @@ -2,14 +2,14 @@ # Login into a machine. # -# -c <monitor> -# Execute QEMU 'cont' command in the specified machine monitor UNIX -# socket prior to logging in. +# -c|-r|-p <monitor> +# Execute QEMU 'cont', 'system_reset', or 'system_powerdown' command on the +# specified machine monitor UNIX socket prior to logging in. # # <host> - build host the machine is running on -# <port> - machine's VNC port on the build host +# <port> - machine's VNC port on the build host (no login if unspecified) # -usage="usage: $0 [-c <monitor>] <host> <port>" +usage="usage: $0 [-c|-r|-p <monitor>] <host> [<port>]" trap "{ exit 1; }" ERR set -o errtrace # Trap in functions. @@ -22,9 +22,13 @@ cmd= while [ "$#" -gt 0 ]; do case "$1" in - -c) + -c|-r|-p) + case "$1" in + -c) cmd=cont ;; + -r) cmd=system_reset ;; + -p) cmd=system_powerdown ;; + esac shift - cmd=cont mon="$1" shift ;; @@ -40,7 +44,11 @@ done host="$1" fport="$2" -if [ -z "$host" -o -z "$fport" ]; then +if [ -z "$host" ]; then + error "$usage" +fi + +if [ -z "$fport" -a -z "$cmd" ]; then error "$usage" fi @@ -90,8 +98,6 @@ function find_unused_port () return 1 } -lport=$(find_unused_port) - # OpenSSH local port forwarding. # # ssh -L <localport>:<fowardhost>:<forwardport> <host> @@ -106,8 +112,15 @@ lport=$(find_unused_port) # csock="$(mktemp -u)" -ssh -f -N -M -S "$csock" -L "$lport:localhost:$fport" \ - -o ExitOnForwardFailure=yes "build@$host" +if [ -n "$fport" ]; then + lport=$(find_unused_port) + + ssh -f -N -M -S "$csock" -o ExitOnForwardFailure=yes \ + -L "$lport:localhost:$fport" "build@$host" +else + ssh -f -N -M -S "$csock" -o ExitOnForwardFailure=yes \ + "build@$host" +fi function exit_trap () { @@ -122,6 +135,9 @@ trap exit_trap EXIT if [ -n "$cmd" ]; then echo "$cmd" | ssh -S "$csock" "build@$host" socat - "UNIX-CONNECT:$mon" + echo # Add newline after QEMU prompt. fi -vinagre "localhost:$lport" +if [ -n "$fport" ]; then + vinagre "localhost:$lport" +fi |