osx aware tunnelier

This commit is contained in:
ville rantanen
2017-08-22 09:26:40 +03:00
parent 161aed8694
commit cc7beeb578

View File

@@ -4,6 +4,13 @@ CONFDIR="$HOME/.config/ssh-tunnelier"
CONF="$CONFDIR/config" CONF="$CONFDIR/config"
MAGIC_TIME=873749328 MAGIC_TIME=873749328
BASE="base64 -w 0"
UNBASE="base64 -d"
if [[ "$OSTYPE" = "darwin"* ]]; then
BASE="base64"
UNBASE="base64 -D"
fi
function _helpexit() { function _helpexit() {
echo "SSH tunnel manager echo "SSH tunnel manager
Runs and monitors preconfigured background ssh tunnels, with the ability Runs and monitors preconfigured background ssh tunnels, with the ability
@@ -48,12 +55,12 @@ function fpgrep() {
} }
function get_id() { function get_id() {
id=$( printf "%s" "$line" | base64 -w 0 ) id=$( printf "%s" "$line" | $BASE )
echo -n $id echo -n $id
} }
function get_command() { function get_command() {
switches=$( echo "$1" | base64 -d ) switches=$( echo "$1" | $UNBASE )
echo -n "ssh -f -n $switches \"sleep $MAGIC_TIME; echo tunneler $1\"" echo -n "ssh -f -n $switches \"sleep $MAGIC_TIME; echo tunneler $1\""
} }
@@ -138,7 +145,7 @@ while true; do
continue continue
} }
printf "\n${colTitle}Tunnel command: %s${colZ}\n" "$( echo "${ids[$j]}" | base64 -d )" printf "\n${colTitle}Tunnel command: %s${colZ}\n" "$( echo "${ids[$j]}" | $UNBASE )"
this_pid="$( get_pid "${ids[$j]}" )" this_pid="$( get_pid "${ids[$j]}" )"
[[ -n "$this_pid" ]] && { [[ -n "$this_pid" ]] && {
# PID exists, ask to kill # PID exists, ask to kill