tmuxviewer/install.sh

51 lines
1.3 KiB
Bash
Raw Normal View History

2022-01-17 11:33:57 +01:00
#!/usr/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit 1
fi
2022-01-17 11:57:58 +01:00
SCRIPT_DIR="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)/"
2022-01-17 11:33:57 +01:00
VIEWER="tmuxviewer"
SSHD_CONFIG_FOLDER="/etc/ssh/sshd_config.d/"
2022-03-19 11:04:22 +01:00
CONFIG_FILE="$VIEWER.conf"
2022-01-17 11:33:57 +01:00
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 () {
2022-03-19 11:04:22 +01:00
sudo apt install -y tmux openssh-server
2022-01-17 11:33:57 +01:00
echo "adding $VIEWER_BIN and $BROADCAST_BIN to $BIN_FOLDER"
2022-01-17 11:57:58 +01:00
sudo cp $SCRIPT_DIR$VIEWER_BIN $BIN_FOLDER$VIEWER_BIN
sudo cp $SCRIPT_DIR$BROADCAST_BIN $BIN_FOLDER$BROADCAST_BIN
2022-01-17 11:33:57 +01:00
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
2022-03-19 11:04:22 +01:00
sudo echo -e "Match User $VIEWER\n\tPermitEmptyPasswords yes" > $CONFIG_FILE_PATH
sudo systemctl restart sshd.service
2022-01-17 11:33:57 +01:00
}
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