6 echo >&2 "novaboot-shell: $*"
13 - console (default command)
25 if [ "$NB_ADMIN" ]; then
28 - shell (use with ssh -t)
36 [ "$NB_ADMIN" ] || return 1
39 0) die "Usage: ssh ... add-key USERNAME < id_rsa.pub";;
41 *) die "User name must not contain spaces: $*";;
46 tmp=$(mktemp ~/.ssh/authorized_keys.XXXXXXXX)
48 cat ~/.ssh/authorized_keys
49 echo "command=\"user $user\" $key"
52 mv $tmp ~/.ssh/authorized_keys
56 [ "$NB_ADMIN" ] || die "Permission denied"
57 if ! tty > /dev/null; then
58 echo "novaboot-shell: Consider starting the shell with 'ssh -t'"
60 exec /bin/bash || exec /bin/sh
64 lslocks | awk '{ if ($9 == "'"$RUN_DIR"'") { print $2 } }'
71 for pid in $(lock_queue); do
72 echo $pid $(sed --null-data -ne '/^NOVABOOT_ID=/ s///p' /proc/$pid/environ)
75 echo "Target is occupied by:"
76 ( echo "PID USER LOGIN_TIME FROM"; echo "$queue" ) | column -t
82 exec flock --no-fork "$RUN_DIR" "$@"
90 . "${NOVABOOT_SHELL_CONFIG:-$HOME/.novaboot-shell}"
93 # run_subcommand should be called only after permission checks and/or locking
98 trap "rm -f $RUN_DIR/ppid" EXIT
99 echo $NOVABOOT_PPID > $RUN_DIR/ppid
100 echo 'novaboot-shell: Connected'
101 # TODO: $reset_begin_cmd
102 eval exec "${console_cmd:?}";;
104 eval exec "${reset_cmd:?}";;
105 "rsync --server "*" . .")
106 if ! [ $# -eq 5 -o \( $# -eq 6 -a "$4" = '--log-format=X' \) ]; then
107 die "Unexpected rsync invocation: $*"
109 mkdir -p "$HOME/tftproot"
113 eval exec "${on_cmd:?}";;
115 eval exec "${off_cmd:?}";;
118 # TODO: sanitize ssh arguments
119 exec ssh "$@" "${ssh_dest:?}";;
121 die "Unsupported command";;
126 if [ "$1" = "-c" ]; then
128 elif [ $# -gt 0 ]; then
129 die "Permission denied"
133 if [ "$1" = "user" ]; then
134 # Get user name encoded in ~/.ssh/authorized_keys
136 [ "$3" = "admin" ] && NB_ADMIN=1
137 set -- $SSH_ORIGINAL_COMMAND
140 IP=${SSH_CONNECTION%% *}
142 HOST=$(getent hosts $IP) || HOST=$IP
147 DATE=$(LANG=C date +'%F_%T')
148 export NOVABOOT_ID="${NB_USER:-?} $DATE ${REMOTE}"
149 export NOVABOOT_PPID=$PPID
154 # Commands allowed at any time
155 "console"|"") locked $0 console;;
156 "get-config") read_config && echo -n "${target_config}"; exit;;
157 "add-key") shift; add_key "$@"; exit;;
158 "shell") exec_shell; exit;;
161 # Commands allowed only when nobody or the same user is connected
162 # to the console. "The same user" means that we were executed by
163 # the same sshd process that has the lock. This is ensured by
164 # using SSH connection sharing on client side.
165 reset | rsync | on | off | ssh)
166 ALLOWED_PPID=$(cat $RUN_DIR/ppid 2>/dev/null || :)
167 if [ "$PPID" -eq "${ALLOWED_PPID:-0}" ]; then run=unlocked; else run=locked; fi
170 echo >&2 "novaboot-shell: Command not allowed: $*"
171 logger -p error "novaboot-shell: Command not allowed: $*"
178 if [ -z "$NOVABOOT_ID" ]; then
190 novaboot-shell - provides novaboot with unified SSH-based interface for controlling target hardware
194 B<novaboot-shell> -c "[command [arguments...]]"
196 B<novaboot-shell> [command [arguments...]]
198 B<ssh target@server> [command [arguments...]]
202 B<novaboot-shell> provides L<novaboot(1)> with a unified SSH-based
203 interface for controlling the target hardware. This simplifies
204 client-side configuration, because clients typically need only the
205 I<--ssh=...> option. B<novaboot-shell> is typically configured as a
206 login shell of special user accounts associated with the target
207 hardware (as set by L<adduser-novaboot(8)>). It ensures that users can
208 perform only a limited set of actions (see L</COMMANDS> below) with
209 the target and have no shell access on the server.
217 Connect to target console (usually serial line). When somebody is
218 connected to the console, other users are blocked from controlling the
219 target. Blocked users see a message indicating who blocks them.
221 The user connected to the console is able to invoke other commands
222 such as L</reset>, but only when the command is invoked via the same
223 SSH connection. This can be accomplished by using SSH connection
224 sharing, which is what L<novaboot(1)> uses (see I<-M> and I<-S> in
227 This is the default command when no command is specified on command
232 Reset the target hardware.
236 Power on the target hardware.
240 Power off the target hardware.
244 This command is not meant to be invoked directly by the user. It
245 allows using L<rsync(1)> to copy files to the target, perhaps for TFTP
246 server. The rsync command must be invoked as: C<rsync ...
247 target@server:>, i.e. without specifying destination path. The files
248 will be stored into I<$HOME/tftproot>.
250 =item user <uernamename> [admin]
252 User command is meant to be used with C<command=> option in SSH's
253 L<authorized_keys(5)> file. It allows the shell to display
254 human-readable names when printing information about who blocks the
255 target. Then, the real command is taken from SSH_ORIGINAL_COMMAND
256 environment variable.
258 When "admin" is specified after the user name, this user is considered
259 an administrator and is allowed to run L</add-key> and L</shell>
264 Prints novaboot configuration options needed for the target. One
269 =head2 Administration commands
271 Only administrators (see L</user>) are allowed to execute these
276 =item add-key <username>
278 Reads the SSH public key from standard input and adds it into in
279 F<~/.ssh/authorized_keys>.
281 Example: C<ssh target@server add-key johndoe < john_rsa.pub>
285 Runs shell on the server. Useful for editing configuration file. It is
286 better used with allocated pseudo-terminal.
288 Example: C<ssh -t target@server shell>
292 =head1 CONFIGURATION FILE
294 B<novaboot-shell> reads configuration file from
295 F<$HOME/.novaboot-shell>. It should define values for the following
296 variables in the SH syntax.
302 Command to C<exec> that connects to target's console.
306 Command to C<exec> that resets the Target.
310 Command to C<exec> that powers the target on.
314 Command to C<exec> that powers the target off.
318 Novaboot command line options that specify which boot loader is used
319 by the target (L<novaboot(1)> rejects other, possibly dangerous, options).
320 Each option is on its own line and no quoting, escaping or stripping
321 is performed on the values.
327 --uboot-init=setenv serverip 192.168.1.1; setenv ipaddr 192.168.1.10
328 --uboot-addr=kernel=0x8100000
329 --uboot-addr=fdt=0x83000000
330 --uboot-addr=ramdisk=0x83100000
338 Michal Sojka <sojkam1@fel.cvut.cz>
340 Latest version can be found at
341 L<https://github.com/wentasah/novaboot>.