Last active
August 29, 2015 14:19
-
-
Save hipikat/4e8b88729a0943098d64 to your computer and use it in GitHub Desktop.
Launch a Synergy client or server, over SSH tunnels, on a Mac
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 | |
# | |
# This is part of my 'At Work' Automator app. | |
# Requires a standard Synergy installation. | |
OFFICE_LOCATION='My Office (Ethernet)' | |
SERVER_HOSTNAME='my-computer' | |
SERVER_IP='10.11.12.13' | |
SERVER_CONF='/Users/hipikat/.synergy_at_work.conf' | |
CLIENT_PRIVATE_KEY='/Users/hipikat/.ssh/id_rsa' | |
# Change to the Weboffice Network Location | |
scselect "$OFFICE_LOCATION" | |
# Disable Wi-Fi | |
networksetup -setairportpower en0 off | |
# If we're on our main work computer | |
# (i.e. whatever has the mouse and keyboard, etc.) | |
if [ `hostname` = "$SERVER_HOSTNAME" ]; then | |
# We're the Synergy server - kill current server | |
killall synergys | |
sleep 1 | |
# Launch a new server | |
/Applications/Synergy.app/Contents/MacOS/synergys \ | |
--address :24800 --daemon --no-tray --debug FATAL \ | |
--name is-m-00068 --enable-drag-drop \ | |
-c "$SERVER_CONF" | |
else | |
# We're a client - kill old client processes | |
killall synergyc | |
# Kill old ssh tunnels if they're present | |
tunnel_pids=`ps aux | grep '\d ssh -fNL 24800' | tr -s " " | cut -f 2 -d ' '` | |
if [ -n "$tunnel_pids" ]; then | |
for pid in $tunnel_pids; do | |
kill -9 "$pid" | |
done | |
fi | |
sleep 1 | |
# Create an ssh tunnel to the server on the standard Synergy port | |
ssh -fNL 24800:localhost:24800 \ | |
-i "$CLIENT_PRIVATE_KEY" \ | |
"$SERVER_IP" &>/dev/null | |
sleep 1 | |
# Launch the Synergy client | |
/Applications/Synergy.app/Contents/MacOS/synergyc \ | |
--daemon --no-tray --debug INFO --enable-drag-drop \ | |
127.0.0.1:24800 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment