Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gwpl/280e1c6b48247ad958d07ae30c1a595c to your computer and use it in GitHub Desktop.
Save gwpl/280e1c6b48247ad958d07ae30c1a595c to your computer and use it in GitHub Desktop.
How to install Syncthing on Raspberry Pi + start on boot [semi-automatic]

##Run install_syncthing.sh

$ curl -s https://gist.githubusercontent.com/hdml/7b079c114d3e20bf69f1/raw/1cd3647b1db4f80726c145fba725e27993a7fcdb/install_syncthing.sh | sudo bash

Start syncthing

$ syncthing

Wait until you get something like:

INFO: Device 7NNIJMJ-RQ657WA-RI5YH6L-RQ657WA-RQ657WA-VGKSUYP-U6QBJNA-RQ657WA
write down this number or copy it if you SSH'd to your pi.

quit the operation using CTRL + C.

Change the config file so you can access the GUI from any PC within the network

$ nano ~/.config/syncthing/config.xml

Change 127.0.0.1 to 0.0.0.0

<gui enabled="true" tls="false">
    <address>127.0.0.1:8384</address>
</gui>

OPTIONAL: if you forward port 8384 (or any port you would like to use) on your router to you pi, you can access the GUI from anywhere in the world as long as you know you home(public) IP address. Make sure you use https and enable authentication!

Start the syncthing service

$ sudo service syncthing start

on a PC in the same network, go to the GUI and disable automatic updates. GUI -> Settings -> Disable Automatic updates hit save and restart syncthing.

If there's a new version of syncthing, use

$ sudo syncthing -upgrade

Then reboot the system.

$ sudo reboot

To remove syncthing use

$ sudo rm -r /opt/syncthing
$ sudo rm /usr/bin/syncthing
$ sudo rm -r /home/pi/.config/syncthing
$ sudo rm /etc/init.d/syncthing

optionally, delete any folder used with syncthing.

#!/bin/sh
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
mkdir -p /opt/syncthing
cd /opt/syncthing
wget https://github.com/syncthing/syncthing/releases/download/v0.12.19/syncthing-linux-arm-v0.12.19.tar.gz
tar -xzvf *.tar.gz
mv syncthing*/* .
rm *.tar.gz
rm -r syncthing*/
ln -s /opt/syncthing/syncthing /usr/bin/syncthing
cd /etc/init.d/
wget https://gist.githubusercontent.com/hdml/7b079c114d3e20bf69f1/raw/e42d18d8fb966e4ff16135035720d97139867bad/syncthing
chmod +x /etc/init.d/syncthing
update-rc.d syncthing defaults
#!/bin/sh
### BEGIN INIT INFO
# Provides: syncthing
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Multi-user daemonized version of syncthing.
# Description: Starts the syncthing daemon for all registered users.
### END INIT INFO
# Replace with users you want to run syncthing clients for
# syncthing_USERS="<your name here>"
syncthing_USERS="pi"
DAEMON=/opt/syncthing/syncthing
startd() {
for stuser in $syncthing_USERS; do
HOMEDIR=$(getent passwd $stuser | awk -F: '{print $6}')
if [ -f $config ]; then
echo "Starting syncthing for $stuser"
start-stop-daemon -b -o -c $stuser -S -u $stuser -x $DAEMON
else
echo "Couldn't start syncthing for $stuser (no $config found)"
fi
done
}
stopd() {
for stuser in $syncthing_USERS; do
dbpid=$(pgrep -fu $stuser $DAEMON)
if [ ! -z "$dbpid" ]; then
echo "Stopping syncthing for $stuser"
start-stop-daemon -o -c $stuser -K -u $stuser -x $DAEMON
fi
done
}
status() {
for stuser in $syncthing_USERS; do
dbpid=$(pgrep -fu $stuser $DAEMON)
if [ -z "$dbpid" ]; then
echo "syncthing for USER $stuser: not running."
else
echo "syncthing for USER $stuser: running (pid $dbpid)"
fi
done
}
case "$1" in
start) startd
;;
stop) stopd
;;
restart|reload|force-reload) stopd && startd
;;
status) status
;;
*) echo "Usage: /etc/init.d/syncthing {start|stop|reload|force-reload|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