49 lines
1.2 KiB
Bash
Executable File
49 lines
1.2 KiB
Bash
Executable File
#!/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.config"
|
|
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 () {
|
|
echo "adding $VIEWER_BIN and $BROADCAST_BIN to $BIN_FOLDER"
|
|
sudo cp $SCRIPT_DIR$VIEWER_BIN $BIN_FOLDER$VIEWER_BIN
|
|
sudo cp $SCRIPT_DIR$BROADCAST_BIN $BIN_FOLDER$BROADCAST_BIN
|
|
echo "adding user $VIEWER"
|
|
sudo useradd --home /tmp/$VIEWER --shell /usr/bin/tmux_viewer.sh $VIEWER
|
|
echo "unsetting password for $VIEWER"
|
|
sudo passwd -d $VIEWER 1> /dev/null
|
|
sudo mkdir -p $SSHD_CONFIG_FOLDER
|
|
sudo echo "Match User $VIEWER\n\tPermitEmptyPassword yes" > $CONFIG_FILE_PATH
|
|
}
|
|
|
|
function uninstall_tmuxviewer () {
|
|
echo "removing user $VIEWER"
|
|
sudo userdel $VIEWER
|
|
sudo rm $CONFIG_FILE_PATH
|
|
sudo rm $BIN_FOLDER$VIEWER_BIN
|
|
sudo 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
|