initial commit

This commit is contained in:
waldek 2022-01-17 11:33:57 +01:00
commit bd10cd17c2
4 changed files with 147 additions and 0 deletions

47
install.sh Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit 1
fi
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 $VIEWER_BIN $BIN_FOLDER$VIEWER_BIN
sudo cp $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

16
readme.md Normal file
View File

@ -0,0 +1,16 @@
# Tmux Viewer
Simple script combo to allow people to see what you're doing in a specific tmux session.
## Dependencies
```sudo apt install tmux```
## Install
```sudo bash install.sh install```
## Uninstall
```sudo bash install.sh uninstall```

34
tmux_broadcast.sh Executable file
View File

@ -0,0 +1,34 @@
#!/bin/bash
USER="$(whoami)"
VIEWER="tmuxviewer"
SOCKET="/tmp/$VIEWER/$USER"
if groups $USER | grep -q "sudo"; then
mkdir -p /tmp/$VIEWER/
sudo chown $VIEWER:$VIEWER "/tmp/$VIEWER"
sudo chmod 777 /tmp/$VIEWER/ 2> /dev/null
sudo chown $USER:$VIEWER $SOCKET
sudo chmod 770 $SOCKET
else
echo "sorry, you're not allowed to broadcast.."
exit 1
fi
tmux -S $SOCKET has-session -t shared 2> /dev/null
if [ $? != 0 ]; then
if groups $USER | grep -q "sudo"; then
echo "no shared session running, creating one..."
tmux -S $SOCKET new-session -A -s shared -d
sudo chown $USER:$VIEWER $SOCKET
chmod 770 $SOCKET
else
echo "you are not allowed to take over..."
exit 1
fi
fi
echo "attaching to $SOCKET"
tmux -S $SOCKET attach -t shared

50
tmux_viewer.sh Executable file
View File

@ -0,0 +1,50 @@
#!/bin/bash
VIEWER="tmuxviewer"
SOCKETS="/tmp/$VIEWER/"
SESSIONS="$(ls $SOCKETS)"
HOSTNAME="$(hostname).$(grep domain /etc/resolv.conf | cut -d " " -f 2)"
function select_session () {
if [ $(echo $SESSIONS | wc -w) == 1 ]; then
SOCKET=$SOCKETS$SESSIONS
echo $SOCKET
else
echo "please choose a session to view: (or exit to quit)"
select session in $(echo $SESSIONS); do
if [ -n "$session" ]; then
SOCKET=$SOCKETS$session
echo "connection to $session at $SOCKET"
view_session
else
case $REPLY in
exit)
echo "will quit now"
break;;
*)
echo "refreshing list..."
select_session
;;
esac
fi
done
fi
}
function view_session () {
clear
while :
do
tmux -S $SOCKET attach -t shared -r 2>/dev/null
clear
echo "$HOSTNAME is not broadcasting at $SOCKET..."
sleep 1
done
}
function main () {
select_session
}
main