Skip to content

Instantly share code, notes, and snippets.

@lukaszp
Last active December 31, 2015 02:56
Show Gist options
  • Save lukaszp/828e0a7b7108f944da1d to your computer and use it in GitHub Desktop.
Save lukaszp/828e0a7b7108f944da1d to your computer and use it in GitHub Desktop.
synergyctl
#!/bin/bash
OP=${1}
#-------------
# synergyctl
#
# Lots of fixes to roadst4r/synergyctl "a few minor tweaks" by roadst4r/synergyctl to the script provided by roadst4r @ http://synergy-project.org/wiki/Startup
#
# add support for crypto,logs,screenanme,display values
#-------------
# not tested note from fork source NOTE: use an IP for $SYNERGY_SERVER as DNS may not be functioning
# not tested note from fork source NOTE: use the following to generate the crypto-pass value
# echo -n <your password> | md5sum
#-------------
SYNERGY_SERVER="localhost"
#SYNERGY_DIR="~/.synergy"
#OPT_LOGFILE="--log ${SYNERGY_DIR}/synergyc.log"
#OPT_SCREENNAME="--name <your client name>"
OPT_DISPLAY="--display :0"
#OPT_CRYPTO="--crypto-pass <yourpasswdstring>"
OPT_DEBUG="--debug ERROR"
SYNERGY_OPTS="--daemon --restart --no-tray ${OPT_CRYPTO} ${OPT_DEBUG} ${OPT_DISPLAY} ${OPT_LOGFILE} ${OPT_SCREENNAME} ${SYNERGY_SERVER}"
SYNERGYC=/usr/bin/synergyc
PS=/bin/ps
GREP=/bin/grep
WC=/bin/wc
PIDOF=/bin/pidof
SLEEP=/bin/sleep
# check synergyc is running
function sc_check
{
N=1
PIDS=`${PIDOF} "${SYNERGYC}"`
if [ -z "$PIDS" ]
then
N=0
fi
return $N
}
# kill synergyc if running
function sc_kill
{
echo "Stopping synergy"
SIG=""
while true
do
sc_check
if [ $? -eq 1 ]
then
kill ${SIG} ${PIDS}
else
break
fi
${SLEEP} 3
SIG="-9"
done
}
# start synergyc
function sc_start
{
echo "Starting synergy"
while true
do
${SYNERGYC} ${SYNERGY_OPTS}
${SLEEP} 2
sc_check
if [ $? -eq 1 ]
then
break
fi
done
}
function sc_status
{
sc_check
if [ $? -ge 1 ]
then
PIDS=$(${PIDOF} "${SYNERGYC}")
echo "Synergy running, pids: ${PIDS}"
else
echo "Synergy not running"
fi
}
case "${OP}" in
restart)
sc_kill
sc_start
sc_status
;;
start)
sc_start
sc_status
;;
stop)
sc_kill
sc_status
;;
status)
sc_status
;;
*)
echo "Usage: synergyctl [start|stop|restart|status]"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment