screenify

This commit is contained in:
Gordon Grant-Stuart 2023-01-30 11:18:56 +00:00
parent 8348e58edb
commit 254be9abef
2 changed files with 28 additions and 1 deletions

View File

@ -14,3 +14,8 @@ debug 0
# Hostname 123.45.67.90
# User ubuntu
# LocalForward 10002 127.0.0.1:22
[passwords]
# Use this section at your own risk, because the passwords are stored in plaintext.
#server1 p@$$w0rd

View File

@ -12,6 +12,7 @@ fi
SSHCONF="$BASEDIR/var/[ssh].conf"
TKCONF="$BASEDIR/var/[settings].conf"
PWCONF="$BASEDIR/var/[passwords].conf"
function ruroot () {
if [[ $UID -ne 0 ]]; then
@ -34,9 +35,29 @@ function dbg () {
case "$1" in
FORKSTART )
echo -n $$ > "$BASEDIR/var/${2}.connected"
if [[ grep -c "^$2" $PWCONF ]]; then
pass=$(awk "/^$2/ {print \$2}" ${PWCONF})
screen -d -m -S "tk${2}" "$0 FORKSCREEN $2"
while [[ -e "$BASEDIR/var/${2}.connected" ]]; do
sleep 5
if [[ -f "$BASEDIR/var/${2}.screen" ]]; then
screen -S "tk${2}" -X stuff "$pass
"
rm -f "$BASEDIR/var/${2}.screen"
fi
done
else
while [[ -e "$BASEDIR/var/${2}.connected" ]]; do
# passwordless auth
ssh -F "${SSHCONF}" $dbgopt -N $2 2>&1 | dbg
sleep 5
done
fi
;;
FORKSCREEN )
while [[ -e "$BASEDIR/var/${2}.connected" ]]; do
echo $$ > "$BASEDIR/var/${2}.screen"
ssh -F "${SSHCONF}" $dbgopt -N $2 2>&1 | dbg
sleep 5
done
;;
FORKKILL ) kill $(sudo netstat -tnlp | grep "127[0-9\.]*:${2}" | grep -o '[0-9]*/ssh' | grep -o '[0-9]*') &>/dev/null ;;
@ -60,6 +81,7 @@ case "$1" in
;;
install )
ruroot
which screen &>/dev/null || yum install -y screen || apt install -y screen
mkdir -p /opt/tunnelkeeper/var
mkdir -p /opt/tunnelkeeper/etc
if [[ "$BASEDIR" != '/opt/tunnelkeeper/' ]]; then