summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominique Martinet <asmadeus@codewreck.org>2016-01-11 13:04:37 +0100
committerDominique Martinet <asmadeus@codewreck.org>2016-01-11 13:04:37 +0100
commit03e20919a1bebef06bd10a07ea4e881972b83151 (patch)
treef80cab38086535ef572afe0208e5a748c32b1d8c
parent31e7dc0e0d1b307d7905f579ee3d65ac026bbc11 (diff)
host_config: conman kvm-wrapper script
-rwxr-xr-xhost_config/conman-kvm-wrapper.exp67
1 files changed, 67 insertions, 0 deletions
diff --git a/host_config/conman-kvm-wrapper.exp b/host_config/conman-kvm-wrapper.exp
new file mode 100755
index 0000000..5719d48
--- /dev/null
+++ b/host_config/conman-kvm-wrapper.exp
@@ -0,0 +1,67 @@
+#!/usr/bin/expect -f
+
+##
+# Set "exp_internal" to 1 to print diagnostics describing internal operations.
+# This is helpful in diagnosing pattern-match failures.
+##
+ exp_internal 0
+
+##
+# Set "log_user" to 1 to show the underlying dialogue establishing a connection
+# to the console.
+##
+ log_user 0
+
+##
+# The "timeout" specifies the number of seconds before the connection attempt
+# times-out and terminates the connection.
+##
+ set timeout 10
+
+set env(PATH) "/usr/bin:/bin"
+
+if {! $argc} {
+ set prog [lindex [split $argv0 "/"] end]
+ send_user "Usage: $prog <host>\r\n"
+ exit 1
+}
+if {$argc > 0} {
+ set host [lindex $argv 0]
+}
+
+if {! [info exists host]} {
+ send_user "Error: Unspecified hostname.\r\n"
+ exit 1
+}
+if {[catch "spawn kvm-wrapper serial $host" spawn_result]} {
+ send_user "Error: $spawn_result.\r\n"
+ exit 1
+}
+expect {
+ -gl "Permission denied" {
+ send_user "Error: Permission denied.\r\n"
+ exit 1
+ }
+ eof {
+ send_user "Error: Connection closed by remote host.\r\n"
+ exit 1
+ }
+ timeout {
+ send_user "Error: Timed-out.\r\n"
+ }
+ -nocase -gl "Are you sure you want to continue connecting (yes/no)? \$" {
+ send "yes\r"
+ exp_continue -continue_timer
+ }
+ -re "(:|#|%|\\\$) \$" {
+ ;
+ }
+ -re "\[^\r]*\r+\n" {
+ exp_continue -continue_timer
+ }
+}
+send_user "Connection established via kvm-wrapper (pid $spawn_result).\r\n"
+
+interact
+# Since the default ssh escape character was changed from "~" to "&",
+# "&B" will generate a serial-break.