From: Michal Sojka Date: Fri, 22 Oct 2021 08:49:09 +0000 (+0200) Subject: server: Add run_novaboot to be used as default_cmd X-Git-Tag: 20211022~4 X-Git-Url: https://rtime.felk.cvut.cz/gitweb/novaboot.git/commitdiff_plain/6dcb21a0b297867324ee581a6a5306afbd965577 server: Add run_novaboot to be used as default_cmd --- diff --git a/server/novaboot-shell b/server/novaboot-shell index 72d6d1d..846ea1b 100755 --- a/server/novaboot-shell +++ b/server/novaboot-shell @@ -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 diff --git a/server/novaboot-shell.pod b/server/novaboot-shell.pod index 9681f68..fa83135 100644 --- a/server/novaboot-shell.pod +++ b/server/novaboot-shell.pod @@ -159,13 +159,37 @@ command line. If not set, C is executed instead. As F (client) always uses the C command to connect to the console, C can be used to boot the target with some default configuration for users who do not use F client -to boot their own configuration. For example, C can be -set to execute a novaboot script. +to boot their own configuration. -In other words, C boots the board in the default -configuration, whereas C boots the +In other words, C will boot the board in some default +configuration, whereas C will boot the board as configured in C<...>. +Often, it is desired to run F on the server to boot the +default configuration. To make this easier to configure, the +C can be set to: + + run_novaboot [...] + +This command will execute C with the F<\> 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 variable, C<--reset-cmd> +and C<--remote-cmd> switches with the values of C and +C variables respectively (see above) and C<--server> +switch. + +Therefore, to boot the default configuration as specified in the +F script, it is sufficient to set C 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 diff --git a/tests/server.wv b/tests/server.wv index 2fcbed0..3c74f15 100755 --- a/tests/server.wv +++ b/tests/server.wv @@ -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 < 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]}