6 echo >&2 "novaboot-shell: $*"
23 if [ "$NB_ADMIN" ]; then
26 - shell (use with ssh -t)
34 [ "$NB_ADMIN" ] || return 1
37 0) die "Username argument missing";;
39 *) die "User name must not contain spaces: $*";;
44 tmp=$(mktemp ~/.ssh/authorized_keys.XXXXXXXX)
46 cat ~/.ssh/authorized_keys
47 echo "command=\"user $user\" $key"
50 mv $tmp ~/.ssh/authorized_keys
54 [ "$NB_ADMIN" ] || die "Permission denied"
55 exec /bin/bash || exec /bin/sh
59 lslocks | awk '{ if ($9 == "'"$RUN_DIR"'") { print $2 } }'
66 for pid in $(lock_queue); do
67 echo $pid $(sed --null-data -ne '/^NOVABOOT_ID=/ s///p' /proc/$pid/environ)
70 echo "Target is occupied by:"
71 ( echo "PID USER LOGIN_TIME FROM"; echo "$queue" ) | column -t
79 flock -h 2>&1 | grep -q -e "--no-fork" && no_fork=--no-fork
81 exec flock $no_fork "$RUN_DIR" "$@"
89 if eval [ "\"\$$1\"" ]; then
92 die "$1 variable not defined in $CFG"
96 # run_subcommand should be called only after permission checks and/or locking
100 trap "rm -f $RUN_DIR/ppid" EXIT
101 echo $NOVABOOT_PPID > $RUN_DIR/ppid
102 echo 'novaboot-shell: Connected'
103 # TODO: $reset_begin_cmd
104 check_var console_cmd && eval exec "$console_cmd";;
106 check_var reset_cmd && eval exec "$reset_cmd";;
107 "rsync --server "*" . .")
108 if ! [ $# -eq 5 -o \( $# -eq 6 -a "$4" = '--log-format=X' \) ]; then
109 die "Unexpected rsync invocation: $*"
111 mkdir -p "$HOME/tftproot"
115 check_var on_cmd && eval exec "$on_cmd";;
117 check_var off_cmd && eval exec "$off_cmd";;
122 if [ "$1" = "-c" ]; then shift
123 else die "Permission denied"; fi
126 if [ "${1%% *}" = "user" ]; then
127 # Get user name encoded in ~/.ssh/authorized_keys
130 [ "$3" = "admin" ] && NB_ADMIN=1
131 set -- $SSH_ORIGINAL_COMMAND
134 if [ $# -eq 0 ]; then print_help; fi
136 IP=${SSH_CONNECTION%% *}
137 HOST=$(getent hosts $IP) || HOST=$IP
139 DATE=$(LANG=C date +'%F_%T')
140 export NOVABOOT_ID="${NB_USER:-?} $DATE ${REMOTE}"
141 export NOVABOOT_PPID=$PPID
146 # Commands allowed at any time
147 "console") locked $0 console;;
148 "get-config") target_config; exit;;
149 "add-key") shift; add_key "$@"; exit;;
150 "shell") exec_shell; exit;;
153 # Commands allowed only when nobody or the same user is connected
154 # to the console. "The same user" means that we were executed by
155 # the same sshd process that has the lock. This is ensured by
156 # using SSH connection sharing on cline side.
157 reset | rsync | on | off)
158 ALLOWED_PPID=$(cat $RUN_DIR/ppid 2>/dev/null || :)
159 if [ "$PPID" -eq "${ALLOWED_PPID:-0}" ]; then run=unlocked; else run=locked; fi
162 echo >&2 "novaboot-shell: Command not allowed: $*"
163 logger -p error "novaboot-shell: Command not allowed: $*"
170 if [ "$NOVABOOT_SHELL_CONFIG" ]; then
171 CFG="$NOVABOOT_SHELL_CONFIG"
173 CFG="$HOME/.novaboot-shell"
178 if [ -z "$NOVABOOT_ID" ]; then