6 echo >&2 "novaboot-shell: $*"
23 if [ "$NB_ADMIN" ]; then
39 lslocks | awk '{ if ($9 == "'"$RUN_DIR"'") { print $2 } }'
46 for pid in $(lock_queue); do
47 echo $pid $(sed --null-data -ne '/^NOVABOOT_ID=/ s///p' /proc/$pid/environ)
50 echo "Target is occupied by:"
51 ( echo "PID USER LOGIN_TIME FROM"; echo "$queue" ) | column -t
57 exec flock --no-fork "$RUN_DIR" "$@"
65 if eval [ "\"\$$1\"" ]; then
68 die "$1 variable not defined in $CFG"
72 # run_subcommand should be called only after permission checks and/or locking
76 trap "rm -f $RUN_DIR/ppid" EXIT
77 echo $NOVABOOT_PPID > $RUN_DIR/ppid
78 echo 'novaboot-shell: Connected'
79 # TODO: $target_reset_begin
80 check_var target_console && eval exec $target_console;;
82 check_var target_reset && eval exec $target_reset;;
83 "rsync --server "*" . .")
84 if ! [ $# -eq 5 -o \( $# -eq 6 -a "$4" = '--log-format=X' \) ]; then
85 die "Unexpected rsync invocation: $*"
87 mkdir -p "$HOME/tftproot"
91 check_var target_on && eval exec $target_on;;
93 check_var target_off && eval exec $target_off;;
98 if [ "$1" = "-c" ]; then shift
99 else die "Permission denied"; fi
102 if [ "${1%% *}" = "user" ]; then
103 # Get user name encoded in ~/.ssh/authorized_keys
106 [ "$3" = "admin" ] && NB_ADMIN=1
107 set -- $SSH_ORIGINAL_COMMAND
110 if [ $# -eq 0 ]; then print_help; fi
112 IP=${SSH_CONNECTION%% *}
113 HOST=$(getent hosts $IP) || HOST=$IP
115 DATE=$(LANG=C date +'%F_%T')
116 export NOVABOOT_ID="${NB_USER:-?} $DATE ${REMOTE}"
117 export NOVABOOT_PPID=$PPID
122 # Commands allowed at any time
123 "console") locked $0 console;;
124 "get-config") target_config; exit;;
125 "add-key") shift; add_key "$@"; exit;;
128 # Commands allowed only when nobody or the same user is connected
129 # to the console. "The same user" means that we were executed by
130 # the same sshd process that has the lock. This is ensured by
131 # using SSH connection sharing on cline side.
132 reset | rsync | on | off)
133 ALLOWED_PPID=$(cat $RUN_DIR/ppid 2>/dev/null || :)
134 if [ "$PPID" -eq "${ALLOWED_PPID:-0}" ]; then run=unlocked; else run=locked; fi
137 echo >&2 "novaboot-shell: Command not allowed: $*"
138 logger -p error "novaboot-shell: Command not allowed: $*"
143 RUN_DIR="$XDG_RUNTIME_DIR/novaboot"
145 if [ "$NOVABOOT_SHELL_CONFIG" ]; then
146 CFG="$NOVABOOT_SHELL_CONFIG"
148 CFG="$HOME/.novaboot-shell"
153 if [ -z "$NOVABOOT_ID" ]; then