From 1dc25e03889ac10f5e740947d841d65ebf42a235 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 3 Apr 2019 14:42:06 +0200 Subject: Improve login-machine script to support -r (reset) and -p (poweroff) options --- login-machine | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'login-machine') 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 -# Execute QEMU 'cont' command in the specified machine monitor UNIX -# socket prior to logging in. +# -c|-r|-p +# Execute QEMU 'cont', 'system_reset', or 'system_powerdown' command on the +# specified machine monitor UNIX socket prior to logging in. # # - build host the machine is running on -# - machine's VNC port on the build host +# - machine's VNC port on the build host (no login if unspecified) # -usage="usage: $0 [-c ] " +usage="usage: $0 [-c|-r|-p ] []" 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 :: @@ -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 -- cgit v1.1