myssh: Allow override for target port

This commit is contained in:
Kevin Baensch 2022-11-18 11:58:18 +01:00
parent f6e126dfcc
commit 8a896cda42

View file

@ -1,6 +1,7 @@
#!/usr/bin/env bash
[ -z $SQL_PROXY_HOST ] && SQL_PROXY_HOST="localhost"
[ -z $SQL_PROXY_DB_PORT ] && SQL_PROXY_DB_PORT="3306"
CONNECTION_CACHE="$HOME/.cache/sqlproxy_$SQL_PROXY_HOST"
HELP="Usage: myssh [ls|connect]\n
@ -36,15 +37,16 @@ disconnect() {
port_forward() {
ACTIVE_HOST=$(cat $CONNECTION_CACHE)
if [ -z $ACTIVE_HOST ] || [ $ACTIVE_HOST != $1 ]
if [ -z $ACTIVE_HOST ] || [ $ACTIVE_HOST != $1:$SQL_PROXY_DB_PORT ]
then
echo "Reconnect"
if [ ! -z $ACTIVE_HOST ]
then
ssh -O cancel -L 3306:$ACTIVE_HOST:3306 -S $HOME/.ssh/controlmasters/%r@%h:%p $SQL_PROXY_HOST q
ssh -O cancel -L 3306:$ACTIVE_HOST -S $HOME/.ssh/controlmasters/%r@%h:%p $SQL_PROXY_HOST q
fi
ssh -O forward -L 3306:$1:3306 -S $HOME/.ssh/controlmasters/%r@%h:%p $SQL_PROXY_HOST
ssh -O forward -L 3306:$1:$SQL_PROXY_DB_PORT -S $HOME/.ssh/controlmasters/%r@%h:%p $SQL_PROXY_HOST
fi
echo $1 > $CONNECTION_CACHE
echo $1:$SQL_PROXY_DB_PORT > $CONNECTION_CACHE
}
ls_hosts() {