]> rtime.felk.cvut.cz Git - novaboot.git/commitdiff
server: Document how to use shell function for console_cmd
authorMichal Sojka <michal.sojka@cvut.cz>
Tue, 26 Jan 2021 08:39:45 +0000 (09:39 +0100)
committerMichal Sojka <michal.sojka@cvut.cz>
Tue, 26 Jan 2021 08:40:13 +0000 (09:40 +0100)
server/novaboot-shell
tests/server.wv

index 188df5a15d4f2b024b1b8ed09866584efbd4dc47..c8d0043e9021a089ed99eedf585389d9e0539a6a 100755 (executable)
@@ -319,6 +319,12 @@ variables in the SH syntax.
 
 Command to C<exec> that connects to target's console.
 
+Note that if you need more complex behaviour of the console command,
+e.g., different behaviour for different users (distinguished by the
+value of C<$NB_USER> variable), you can set this variable to a name of
+a shell function, which you define in the configuration file and
+implement the complex behaviour there.
+
 =item reset_cmd
 
 Command to C<exec> that resets the Target.
index 86bea7cef577a688f373686a4d0eda3bb6b30710..942425376ed5fd1ffa0dc2b3e2fde75d89fbd552 100755 (executable)
@@ -112,6 +112,17 @@ WVSTART "Config variables can depend on user name"
     username=qwer WVPASS run_server console | tee /dev/stderr | WVPASS grep -F "Hello qwer"
 )
 
+WVSTART "Missing console_cmd results in failure"
+NOVABOOT_SHELL_CONFIG="/dev/null" WVFAIL run_server console
+
+WVSTART "console_cmd may contain a shell function name"
+(
+    export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
+    WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'console_cmd () { echo Hello user; }
+console_cmd=console_cmd'
+    WVPASS run_server console | tee /dev/stderr | WVPASS grep -F "Hello user"
+)
+
 SHELLRC="$NBT_HOME/.novaboot-shell"
 TFTPROOT="$NBT_HOME/tftproot"
 AUTH="$NBT_HOME/.ssh/authorized_keys"