Created
January 26, 2015 04:31
-
-
Save ryo1kato/7b7d694f21c10ca58b80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## You need 'flock' from util-linux. | |
set -eu | |
SYNERGY_CLIENT='/Applications/Synergy.app/Contents/MacOS/synergyc' | |
SYNERGY_LOG=${HOME}/.synergy-tunnel.log | |
SYNERGY_SERVER='ryoichi-ubuntu.aka" | |
SSH_TUNNEL_OPT="localhost:24800:$SYNERGY_SERVER:24800" | |
MSG () { echo "$0: $*"; } | |
DIE () { MSG "ERROR: $*"; } | |
start_tunnel () { | |
MSG "Starting SSH tunneling for Cynergy" | |
( | |
if flock -n 9 | |
then | |
( | |
while true | |
do | |
if ping -c 1 -t 1 "$SYNERGY_SERVER" | |
then | |
ssh -N -L "$SSH_TUNNEL_OPT" "$SYNERGY_SERVER" || true | |
else | |
sleep 1 | |
fi | |
done | |
) & | |
else | |
MSG "start_tunnel() is already running, skipp starting ssh" | |
fi | |
) 9> "$HOME/.synergy-tunnel.lock" | |
} | |
start_synergyc () { | |
MSG "Starting Synergy Client daemon" | |
if flock -n "$HOME/.synergyc.lock" "$SYNERGY_CLIENT" localhost | |
then | |
: | |
else | |
MSG "synergyc is already running." | |
fi | |
} | |
start_tunnel > $SYNERGY_LOG 2>&1 | |
sleep 2 | |
start_synergyc >> $SYNERGY_LOG 2>&1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment