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'
80 check_var target_console && eval exec $target_console;;
82 check_var target_reset && eval exec $target_reset;;
83 "rsync --server "*" . .")
84 if [ $# -ne 5 ]; then die "Unexpected rsync invocation: $*"; fi
85 mkdir -p "$HOME/tftproot"
87 exec rsync --server $3 . . ;;
89 check_var target_on && eval exec $target_on;;
91 check_var target_off && eval exec $target_off;;
96 if [ "$1" = "-c" ]; then shift
97 else die "Permission denied"; fi
100 if [ "${1%% *}" = "user" ]; then
101 # Get user name encoded in ~/.ssh/authorized_keys
104 [ "$3" = "admin" ] && NB_ADMIN=1
105 set -- $SSH_ORIGINAL_COMMAND
108 if [ $# -eq 0 ]; then print_help; fi
110 IP=${SSH_CONNECTION%% *}
111 HOST=$(getent hosts $IP) || HOST=$IP
113 DATE=$(LANG=C date +'%F_%T')
114 export NOVABOOT_ID="${NB_USER:-?} $DATE ${REMOTE}"
115 export NOVABOOT_PPID=$PPID
120 # Commands allowed at any time
121 "console") locked $0 console;;
122 "add-key") shift; add_key "$@"; exit $?;;
125 # Commands allowed only when nobody or the same user is connected
126 # to the console. "The same user" means that we were executed by
127 # the same sshd process that has the lock. This is ensured by
128 # using SSH connection sharing on cline side.
129 console | reset | rsync | on | off)
130 ALLOWED_PPID=$(cat $RUN_DIR/ppid 2>/dev/null || :)
131 if [ "$PPID" -eq "${ALLOWED_PPID:-0}" ]; then run=unlocked; else run=locked; fi
134 echo >&2 "novaboot-shell: Command not allowed: $*"
135 logger -p error "novaboot-shell: Command not allowed: $*"
140 RUN_DIR="$XDG_RUNTIME_DIR/novaboot"
142 if [ -z "$NOVABOOT_ID" ]; then
145 if [ "$NOVABOOT_SHELL_CONFIG" ]; then
146 CFG="$NOVABOOT_SHELL_CONFIG"
148 CFG="$HOME/.novaboot-shell"