X-Git-Url: https://rtime.felk.cvut.cz/gitweb/novaboot.git/blobdiff_plain/ea34d7e35f0feddb80d6af54a8b80d10b5fec772..9dffa510a832c399ef3920530ed1225addb8cd96:/server/novaboot-shell diff --git a/server/novaboot-shell b/server/novaboot-shell index bf1d4ba..e9c60f7 100755 --- a/server/novaboot-shell +++ b/server/novaboot-shell @@ -15,6 +15,7 @@ Target commands: - on - off - rsync ... +- get-config Management commands: - help @@ -77,9 +78,7 @@ print_queue() { locked() { print_queue - no_fork= - flock -h 2>&1 | grep -q -e "--no-fork" && no_fork=--no-fork - exec flock $no_fork "$RUN_DIR" "$@" + exec flock --no-fork "$RUN_DIR" "$@" } unlocked() { @@ -90,6 +89,21 @@ read_config() { . "${NOVABOOT_SHELL_CONFIG:-$HOME/.novaboot-shell}" } +power() { + local cmd + case "$1" in + "on") cmd="${on_cmd:?}";; + "off") cmd="${off_cmd:?}";; + *) die "Unexpected power parameter";; + esac + + if [ "$PPID" -ne 1 ] && systemctl --user is-enabled novaboot-power-off.service; then + sudo novaboot-power "$1" + else + eval "$cmd" + fi +} + # run_subcommand should be called only after permission checks and/or locking run_subcommand() { read_config @@ -99,6 +113,7 @@ run_subcommand() { echo $NOVABOOT_PPID > $RUN_DIR/ppid echo 'novaboot-shell: Connected' # TODO: $reset_begin_cmd + [ -n "${on_cmd}" ] && power on eval exec "${console_cmd:?}";; "reset") eval exec "${reset_cmd:?}";; @@ -110,9 +125,13 @@ run_subcommand() { cd "$HOME/tftproot" exec "$@";; "on") - eval exec "${on_cmd:?}";; + power on + exit;; "off") - eval exec "${off_cmd:?}";; + power off + exit;; + *) + die "Unknown command: $*";; esac } @@ -126,7 +145,7 @@ main() { NB_ADMIN= if [ "$1" = "user" ]; then # Get user name encoded in ~/.ssh/authorized_keys - NB_USER="$2"; + export NB_USER="$2"; [ "$3" = "admin" ] && NB_ADMIN=1 set -- $SSH_ORIGINAL_COMMAND fi @@ -167,9 +186,14 @@ main() { esac } -RUN_DIR="$HOME" +if [ -d "$HOME" ]; then + RUN_DIR="$HOME" +else + RUN_DIR="/tmp/novaboot-shell@$USER" + mkdir -p "$RUN_DIR" +fi -if [ -z "$NOVABOOT_ID" ]; then +if [ -z "$NOVABOOT_ID" ] && [ "$PPID" -ne 1 ]; then main "$@" else run_subcommand "$@" @@ -193,14 +217,14 @@ B [command [arguments...]] =head1 DESCRIPTION -B provides L with unified SSH-based -interface for controlling target hardware. This simplifies client-side -configuration, because typically only I<-ssh=...> option is needed on -the client side. B is typically configured as a login -shell of special user accounts associated with target hardware. It -ensures that users are able to perform only a limited set of action -(see L below) with the target and have no shell access on -the server. +B provides L with a unified SSH-based +interface for controlling the target hardware. This simplifies +client-side configuration, because clients typically need only the +I<--ssh=...> option. B is typically configured as a +login shell of special user accounts associated with the target +hardware (as set by L). It ensures that users can +perform only a limited set of actions (see L below) with +the target and have no shell access on the server. =head1 COMMANDS @@ -253,6 +277,11 @@ When "admin" is specified after the user name, this user is considered an administrator and is allowed to run L and L commands. +=item get-config + +Prints novaboot configuration options needed for the target. One +option per line. + =back =head2 Administration commands