]> rtime.felk.cvut.cz Git - novaboot.git/commitdiff
server: Add support for default_cmd configuration variable
authorMichal Sojka <michal.sojka@cvut.cz>
Tue, 26 Jan 2021 10:38:14 +0000 (11:38 +0100)
committerMichal Sojka <michal.sojka@cvut.cz>
Tue, 26 Jan 2021 10:38:14 +0000 (11:38 +0100)
server/novaboot-shell
tests/server.wv

index 6e647a7e78eae85ccf3bc9433686265a0e2f862d..e8ddd1d2018290357489f7dcccef9572030e803e 100755 (executable)
@@ -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<novaboot(1)> uses (see I<-M> and I<-S> in
 L<ssh(1)>).
 
-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<default_cmd> is not set in the configuration file.
 
 =item reset
 
@@ -314,8 +317,8 @@ Example: C<ssh -t target@server shell>
 =head1 CONFIGURATION FILE
 
 B<novaboot-shell> 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<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.
+
+In other words, C<ssh board@host> boots the board in the default
+configuration, whereas C<novaboot --ssh=board@host ...> boots the
+board as configured in C<...>.
 
 =back
 
index 9f69633b77c0d17c4a6a8d945d6fa1eb98aa3671..8c8545101c34fefeff1b91a9bab38bbef25202a5 100755 (executable)
@@ -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 <<EOF > $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 <<EOF > $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]}