35 lines
748 B
Bash
35 lines
748 B
Bash
|
#!/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
|