#!/usr/bin/bash if [ "$EUID" -ne 0 ] then echo "Please run as root" exit 1 fi SCRIPT_DIR="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)/" VIEWER="tmuxviewer" SSHD_CONFIG_FOLDER="/etc/ssh/sshd_config.d/" CONFIG_FILE="$VIEWER.conf" CONFIG_FILE_PATH="$SSHD_CONFIG_FOLDER$CONFIG_FILE" BIN_FOLDER="/usr/bin/" VIEWER_BIN="tmux_viewer.sh" BROADCAST_BIN="tmux_broadcast.sh" function install_tmuxviewer () { apt-get install -y tmux openssh-server echo "adding $VIEWER_BIN and $BROADCAST_BIN to $BIN_FOLDER" cp $SCRIPT_DIR$VIEWER_BIN $BIN_FOLDER$VIEWER_BIN cp $SCRIPT_DIR$BROADCAST_BIN $BIN_FOLDER$BROADCAST_BIN echo "adding user $VIEWER" useradd --home /tmp/$VIEWER --shell /usr/bin/tmux_viewer.sh $VIEWER echo "unsetting password for $VIEWER" passwd -d $VIEWER 1> /dev/null mkdir -p $SSHD_CONFIG_FOLDER echo -e "Match User $VIEWER\n\tPermitEmptyPasswords yes" > $CONFIG_FILE_PATH #sudo systemctl restart sshd.service } function uninstall_tmuxviewer () { echo "removing user $VIEWER" userdel $VIEWER rm $CONFIG_FILE_PATH rm $BIN_FOLDER$VIEWER_BIN rm $BIN_FOLDER$BROADCAST_BIN } case $1 in install) uninstall_tmuxviewer 2> /dev/null install_tmuxviewer ;; uninstall) uninstall_tmuxviewer ;; *) echo "usage (as root): $0 [install|uninstall]" ;; esac