]> rtime.felk.cvut.cz Git - novaboot.git/commitdiff
Add initial implementation of --ssh option to connect to novaboot-shell
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 25 Aug 2017 06:16:14 +0000 (08:16 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 25 Aug 2017 06:18:28 +0000 (08:18 +0200)
README.pod
novaboot
tests/server.wv

index 83ea88ea6cd63fd0e3957cd5373358f4c3e7b542..f686d8b912327f8a47d91c6d7b225a3054708334 100644 (file)
@@ -193,6 +193,18 @@ When this option is not given, novaboot tries to determine the target
 to use from either B<NOVABOOT_TARGET> environment variable or
 B<$default_target> configuration file variable.
 
+=item --ssh=I<user@hostname>
+
+Configures novaboot to control the target via C<novaboot-shell>
+running remotely via SSH.
+
+Using this option is the same as specifying B<--remote-cmd>,
+B<--remote-expect>, B<--server> B<--rsync-flags>, B<--prefix> and
+B<--reset-cmd> manually in a way compatible with V<novaboot-shell>.
+
+Currently, this in an initial experimental implementation. We plan to
+change/extend this feature soon!
+
 =back
 
 =head2 Script preprocessing phase
@@ -519,8 +531,8 @@ B<--iprelay>, B<--reset-cmd> and B<--reset-send>.
 =item --on, --off
 
 Switch on/off the target machine and exit. The script (if any) is
-completely ignored. Currently, it works only with B<--iprelay> or
-B<--amt>.
+completely ignored. Currently, it works only with the following
+options: B<--iprelay>, B<--amt>, B<--ssh>.
 
 =item -Q, --qemu[=I<qemu-binary>]
 
index b06971cf2fc0e4e5cc039cc7deef076de149b73a..5426f2ed40c3e678dcac61791fa55b7fa9365cf5 100755 (executable)
--- a/novaboot
+++ b/novaboot
@@ -120,8 +120,11 @@ read_config($_) foreach $cfg or @cfgs;
 my $explicit_target = $ENV{'NOVABOOT_TARGET'};
 GetOptions ("target|t=s" => \$explicit_target);
 
+# Variables for command line options
 my ($amt, @append, $bender, @chainloaders, $concat, $config_name_opt, $dhcp_tftp, $dump_opt, $dump_config, @exiton, $exiton_timeout, @expect_raw, $final_eol, $gen_only, $grub_config, $grub_prefix, $grub_preamble, $grub2_prolog, $grub2_config, $help, $ider, $interaction, $iprelay, $iprelay_cmd, $iso_image, $interactive, $kernel_opt, $make, $man, $netif, $no_file_gen, $off_opt, $on_opt, $pulsar, $pulsar_root, $qemu, $qemu_append, $qemu_flags_cmd, $remote_cmd, $remote_expect, $remote_expect_silent, $remote_expect_timeout, $reset, $reset_cmd, $reset_send, $rom_prefix, $rsync_flags, @scriptmod, $scons, $serial, $server, $stty, $tftp, $tftp_port, $uboot, %uboot_addr, $uboot_cmd, @uboot_init);
 
+my ($target_reset, $target_power_on, $target_power_off);
+
 # Default values of certain command line options
 %uboot_addr = (
     'kernel'  => '${kernel_addr_r}',
@@ -155,6 +158,23 @@ sub handle_send
     @expect_seen = ();
 }
 
+sub handle_novaboot_server
+{
+    my ($n, $val) = @_;
+    my $xdg_runtime_dir = $ENV{XDG_RUNTIME_DIR} || '/var/run';
+    my $ssh_ctl_path = "${xdg_runtime_dir}/novaboot-%r@%h%p";
+
+    $remote_cmd = "ssh -tt -M -S '${ssh_ctl_path}' '${val}' console";
+    $remote_expect = "novaboot-shell: Connected";
+    $server = "$val:";
+    $rsync_flags = "--rsh='ssh -S \'${ssh_ctl_path}\''";
+    ($grub_prefix = $val) =~ s/@.*// if index($val, '@') != -1;
+    $reset_cmd = "ssh -tt -S '${ssh_ctl_path}' '${val}' reset";
+
+    $target_power_off = sub { system_verbose("ssh -tt -S '${ssh_ctl_path}' '${val}' off"); };
+    $target_power_on  = sub { system_verbose("ssh -tt -S '${ssh_ctl_path}' '${val}' on"); };
+}
+
 my %opt_spec;
 %opt_spec = (
     "amt=s"         => \$amt,
@@ -211,6 +231,7 @@ my %opt_spec;
     "sendcont=s"     => \&handle_send,
     "serial|s:s"     => \$serial,
     "server:s"              => \$server,
+    "ssh:s"         => \&handle_novaboot_server,
     "strip-rom"             => sub { $rom_prefix = ''; },
     "stty=s"        => \$stty,
     "tftp"          => \$tftp,
@@ -618,7 +639,6 @@ if (exists $variables->{WVDESC}) {
 
 my $exp; # Expect object to communicate with the target over serial line
 
-my ($target_reset, $target_power_on, $target_power_off);
 my ($amt_user, $amt_password, $amt_host, $amt_port);
 
 if (defined $iprelay || defined $iprelay_cmd) {
@@ -1449,6 +1469,18 @@ When this option is not given, novaboot tries to determine the target
 to use from either B<NOVABOOT_TARGET> environment variable or
 B<$default_target> configuration file variable.
 
+=item --ssh=I<user@hostname>
+
+Configures novaboot to control the target via C<novaboot-shell>
+running remotely via SSH.
+
+Using this option is the same as specifying B<--remote-cmd>,
+B<--remote-expect>, B<--server> B<--rsync-flags>, B<--prefix> and
+B<--reset-cmd> manually in a way compatible with V<novaboot-shell>.
+
+Currently, this in an initial experimental implementation. We plan to
+change/extend this feature soon!
+
 =back
 
 =head2 Script preprocessing phase
@@ -1775,8 +1807,8 @@ B<--iprelay>, B<--reset-cmd> and B<--reset-send>.
 =item --on, --off
 
 Switch on/off the target machine and exit. The script (if any) is
-completely ignored. Currently, it works only with B<--iprelay> or
-B<--amt>.
+completely ignored. Currently, it works only with the following
+options: B<--iprelay>, B<--amt>, B<--ssh>.
 
 =item -Q, --qemu[=I<qemu-binary>]
 
index 034f56d1b5faeb3e5a6870e4c08796f9a0e27fdf..2342d5b78dcf1bd1c1b1f10614c2d5f8b6d62aa2 100755 (executable)
@@ -69,4 +69,11 @@ WVPASS run_server reset
 WVPASS test -e reset
 WVPASS kill $COPROC_PID
 
+WVSTART "Novaboot --ssh option"
+date > file
+WVPASS novaboot --ssh novaboot-test@localhost <<EOF
+copy file
+EOF
+WVPASS diff -u file /home/novaboot-test/tftproot/file
+
 trap - EXIT