]> rtime.felk.cvut.cz Git - novaboot.git/commitdiff
server: Add run_novaboot to be used as default_cmd
authorMichal Sojka <michal.sojka@cvut.cz>
Fri, 22 Oct 2021 08:49:09 +0000 (10:49 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Fri, 22 Oct 2021 12:09:40 +0000 (14:09 +0200)
server/novaboot-shell
server/novaboot-shell.pod
tests/server.wv

index 72d6d1ddd7273bdbe39dd8968febef2f5db14c56..846ea1b659e8c8ad2e16019fcc0c939544271158 100755 (executable)
@@ -113,6 +113,20 @@ run_console() {
     eval "$1"
 }
 
+# Run novaboot with the same configuration as specified in
+# ~/.novaboot-shell, but allow the caller to extend of override them
+# via parameters of this function.
+run_novaboot() {
+    nbscript=$1
+    shift
+    OLD_IFS=$IFS
+    # Split $target_config below by newlines, not by words
+    IFS="
+"
+    novaboot "$nbscript" $target_config --server="$HOME/tftproot" --reset-cmd="${reset_cmd:?}" --remote-cmd="${console_cmd:?}" "$@"
+    IFS=$OLD_IFS
+}
+
 # run_subcommand should be called only after permission checks and/or locking
 run_subcommand() {
     read_config
index 9681f68513e008080ab2484b4fba00354c011093..fa831353c8feac4ea0c372ceb1f79eab37c733c4 100644 (file)
@@ -159,13 +159,37 @@ command line. If not set, C<console_cmd> is executed instead.
 As F<novaboot> (client) always uses the C<console> command to connect
 to the console, C<default_cmd> can be used to boot the target with
 some default configuration for users who do not use F<novaboot> client
-to boot their own configuration. For example, C<default_cmd> can be
-set to execute a novaboot script.
+to boot their own configuration.
 
-In other words, C<ssh board@host> boots the board in the default
-configuration, whereas C<novaboot --ssh=board@host ...> boots the
+In other words, C<ssh board@host> will boot the board in some default
+configuration, whereas C<novaboot --ssh=board@host ...> will boot the
 board as configured in C<...>.
 
+Often, it is desired to run F<novaboot> on the server to boot the
+default configuration. To make this easier to configure, the
+C<default_cmd> can be set to:
+
+  run_novaboot <nbscript> [<extra args>...]
+
+This command will execute C<novaboot> with the F<\<nbscript>> script
+as an argument and passes it a few switches with values from the
+F<$HOME/.novaboot-shell> configuration file. Specifically, it will
+pass all switches from the C<target_config> variable, C<--reset-cmd>
+and C<--remote-cmd> switches with the values of C<reset_cmd> and
+C<console_cmd> variables respectively (see above) and C<--server>
+switch.
+
+Therefore, to boot the default configuration as specified in the
+F<default_boot> script, it is sufficient to set C<default_cmd> to:
+
+  run_novaboot ./default_boot --interactive
+
+To have different default configuration for different users, one can
+use the C<$NB_USER> variable as outlined above. The simplest example
+is perhaps this command:
+
+  run_novaboot ./default_boot-"$NB_USER" --interactive
+
 =back
 
 =head1 AUTHORS
index 2fcbed01e2941f07e398967c8ab67e9a9e07f347..3c74f15b29daf299888455c1bb881c8db007db5f 100755 (executable)
@@ -59,6 +59,29 @@ EOF
     WVPASS run_server console | WVPASS grep -F 'Hello console'
 )
 
+WVSTART "default_cmd can be set to run_novaboot"
+(
+    export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
+    cat <<EOF > default_nb_script
+run echo "Hello default_nb_script"
+EOF
+    cat <<'EOF' > $NOVABOOT_SHELL_CONFIG
+default_cmd='run_novaboot default_nb_script --scriptmod=s/default_nb_script/default_nb_script_mod/'
+console_cmd='while sleep 0.01; do echo "Hello console"; done'
+reset_cmd='echo "Hello reset"'
+target_config="\
+--name=some name with spaces and hash #
+--exiton=Hello console
+"
+EOF
+    WVPASS run_server | (
+        stdout=$(cat)
+        WVPASS grep -F 'Hello default_nb_script' <<<"$stdout"
+        WVPASS grep -F 'Hello default_nb_script_mod' <<<"$stdout"
+        WVPASS grep -F 'Hello console' <<<"$stdout"
+    )
+)
+
 WVSTART 'Second connection to console prints queue'
 coproc console1 { exec_server console; }
 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}