From: Michal Sojka Date: Tue, 26 Jan 2021 10:38:14 +0000 (+0100) Subject: server: Add support for default_cmd configuration variable X-Git-Tag: 20210126a~11 X-Git-Url: https://rtime.felk.cvut.cz/gitweb/novaboot.git/commitdiff_plain/f5c1bf2d273e2c5d06164b1f6efedc472eac0ea0?ds=sidebyside server: Add support for default_cmd configuration variable --- diff --git a/server/novaboot-shell b/server/novaboot-shell index 6e647a7..e8ddd1d 100755 --- a/server/novaboot-shell +++ b/server/novaboot-shell @@ -117,6 +117,8 @@ run_console() { run_subcommand() { read_config case "$*" in + "default") + run_console "${default_cmd:-${console_cmd:?}}";; "console") run_console "${console_cmd:?}";; "reset") @@ -169,7 +171,8 @@ main() { case "$1" in # Commands allowed at any time - "console"|"") locked $0 console;; + "") locked $0 default;; + "console") locked $0 console;; "get-config") read_config && echo -n "${target_config}"; exit;; "add-key") shift; add_key "$@"; exit;; "shell") exec_shell; exit;; @@ -246,8 +249,8 @@ SSH connection. This can be accomplished by using SSH connection sharing, which is what L uses (see I<-M> and I<-S> in L). -This is the default command when no command is specified on command -line. +This is the default command when no command is specified on the +command line and C is not set in the configuration file. =item reset @@ -314,8 +317,8 @@ Example: C =head1 CONFIGURATION FILE B reads configuration file from -F<$HOME/.novaboot-shell>. It should define values for the following -variables in the SH syntax. +F<$HOME/.novaboot-shell>. It can define values for the following +variables in the shell syntax. =over 8 @@ -358,6 +361,20 @@ Example: --uboot-addr=ramdisk=0x83100000 " +=item default_cmd + +If set, this command is executed when no command is specified on the +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. + +In other words, C boots the board in the default +configuration, whereas C boots the +board as configured in C<...>. =back diff --git a/tests/server.wv b/tests/server.wv index 9f69633..8c85451 100755 --- a/tests/server.wv +++ b/tests/server.wv @@ -7,15 +7,17 @@ NBT_HOME=$(getent passwd novaboot-test|cut -d: -f6) export WV_BASE_DIR export NOVABOOT_SHELL_CONFIG="$WV_BASE_DIR/.novaboot-shell" cat < $NOVABOOT_SHELL_CONFIG -console_cmd="while :; do sleep 0.1; date; done" +console_cmd="echo 'Hello console'; while :; do sleep 0.1; date; done" reset_cmd="touch reset_done" target_config='--prefix=asdf' EOF +# Run server synchronously function run_server() { SSH_ORIGINAL_COMMAND="$*" SSH_CONNECTION="127.0.0.1 1234 127.0.0.1 22" $exec $WV_BASE_DIR/../server/novaboot-shell -c "${account:-user} ${username:-test} ${admin:+admin}" } +# Exec server (for use with coproc - then the server can be easily killed) function exec_server() { local exec exec=exec @@ -40,11 +42,23 @@ coproc exec_server console WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${COPROC[0]} kill $COPROC_PID; wait -WVSTART "Console command is executed without any argument" +WVSTART "Without any argument console_cmd is executed if no default_cmd is configured" coproc exec_server -WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${COPROC[0]} +WVPASS sed -e '/Hello console/q0' -e '3q1' <&${COPROC[0]} kill $COPROC_PID; wait +WVSTART "Without any argument default_cmd is executed if configured" +( + export NOVABOOT_SHELL_CONFIG="./.novaboot-shell" + cat < $NOVABOOT_SHELL_CONFIG +default_cmd='echo "Hello default"' +console_cmd='echo "Hello console"' +EOF + WVPASS run_server | WVPASS grep -F 'Hello default' + + WVPASS run_server console | WVPASS grep -F 'Hello console' +) + WVSTART 'Second connection to console prints queue' coproc console1 { exec_server console; } WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}