Sunday, 5 February 2012

Autostart Synergy on Debian

If, like me, you use multiple computers, chances are you've come across Synergy - probably the best application for controlling multiple PCs from one keyboard and mouse. (For the uninitiated, throw away your KVM switches - a superior solution exists!)
To get the synergy client to autostart on Debian, you'll need to modify three files. The first will start synergyc as root for the gdm login screen. The second stops synergyc after you've logged in, and the third starts synergyc as your user.
# vim /etc/gdm3/Init/Default
Add the following almost at the end, just above the "exit 0":
/usr/bin/killall synergyc
while [ $(pgrep -x synergyc) ]; do sleep 0.1; done
/usr/bin/synergyc <synergy server IP address>
The second file can be based on the sample which Debian provides:
# mv /etc/gdm3/PostLogin/Default.sample /etc/gdm3/PostLogin/Default
# vim /etc/gdm3/PostLogin/Default 
Add the following at the end:

/usr/bin/killall synergyc
while [ $(pgrep -x synergyc) ]; do sleep 0.1; done

For the final file:
# vim /etc/X11/Xsession.d/80synergyc

Add the following:
/usr/bin/killall synergyc
while [ $(pgrep -x synergyc) ]; do sleep 0.1; done
/usr/bin/synergyc <synergy server IP address>
Modifying gdm's scripts and duplicating server IP addresses all over the place is obviously a terrible means to an end. Better implementations are left as an exercise for the reader.