2016-07-03 17:13:34 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
|
|
|
# Syncthing application
|
|
|
|
#
|
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
|
|
|
# Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-07-06 17:47:55 +02:00
|
|
|
VARIANTS='full cloud'
|
|
|
|
|
2016-07-03 17:13:34 +02:00
|
|
|
SYNCTHING_ID=
|
|
|
|
SYNCTHING_CONFIG_PATH=/root/.config/syncthing
|
|
|
|
SYNCTHING_CONFIG_FILE=$SYNCTHING_CONFIG_PATH/config.xml
|
|
|
|
SYNCTHING_RELAY_SERVER='https://relays.syncthing.net/endpoint'
|
|
|
|
SYNCTHING_RELEASES='https://api.github.com/repos/syncthing/syncthing/releases?per_page=30'
|
|
|
|
SYNCTHING_PORT=22000
|
|
|
|
SYNCTHING_SHARED_DATA=/var/lib/syncthing/SyncShared
|
|
|
|
SYNCTHING_USER_IDS_FILE='.syncthingids'
|
|
|
|
|
2016-07-06 16:01:28 +02:00
|
|
|
function upgrade_syncthing {
|
2016-07-07 18:45:57 +02:00
|
|
|
echo -n ''
|
2016-07-06 16:01:28 +02:00
|
|
|
}
|
|
|
|
|
2016-07-06 15:55:09 +02:00
|
|
|
function backup_local_syncthing {
|
2016-07-07 18:45:57 +02:00
|
|
|
echo -n ''
|
2016-07-06 15:55:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function backup_remote_syncthing {
|
2016-07-07 18:45:57 +02:00
|
|
|
echo -n ''
|
2016-07-04 22:02:22 +02:00
|
|
|
}
|
|
|
|
|
2016-07-04 14:19:05 +02:00
|
|
|
function remove_syncthing {
|
|
|
|
if ! grep -Fxq "install_syncthing" $COMPLETION_FILE; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
iptables -D INPUT -p udp --dport $SYNCTHING_PORT -j ACCEPT
|
|
|
|
iptables -D INPUT -p tcp --dport $SYNCTHING_PORT -j ACCEPT
|
|
|
|
function_check save_firewall_settings
|
|
|
|
save_firewall_settings
|
|
|
|
|
|
|
|
systemctl stop syncthing
|
|
|
|
systemctl disable syncthing
|
|
|
|
apt-get -y remove --purge syncthing
|
|
|
|
rm /etc/systemd/system/syncthing.service
|
2016-07-06 10:31:13 +02:00
|
|
|
sed -i "/${PROJECT_NAME}-syncthing/d" /etc/crontab
|
2016-07-04 14:19:05 +02:00
|
|
|
sed -i '/install_syncthing/d' $COMPLETION_FILE
|
|
|
|
sed -i '/configure_firewall_for_syncthing/d' $COMPLETION_FILE
|
|
|
|
systemctl restart cron
|
|
|
|
}
|
|
|
|
|
2016-07-03 19:52:57 +02:00
|
|
|
function configure_firewall_for_syncthing {
|
|
|
|
if grep -Fxq "configure_firewall_for_syncthing" $COMPLETION_FILE; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
iptables -A INPUT -p udp --dport $SYNCTHING_PORT -j ACCEPT
|
|
|
|
iptables -A INPUT -p tcp --dport $SYNCTHING_PORT -j ACCEPT
|
|
|
|
function_check save_firewall_settings
|
|
|
|
save_firewall_settings
|
|
|
|
|
|
|
|
OPEN_PORTS+=("Syncthing $SYNCTHING_PORT")
|
|
|
|
echo 'configure_firewall_for_syncthing' >> $COMPLETION_FILE
|
|
|
|
}
|
|
|
|
|
2016-07-03 17:13:34 +02:00
|
|
|
function install_syncthing {
|
|
|
|
if grep -Fxq "install_syncthing" $COMPLETION_FILE; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
apt-get -y install curl
|
|
|
|
|
|
|
|
curl -s https://syncthing.net/release-key.txt | apt-key add -
|
|
|
|
echo "deb http://apt.syncthing.net/ syncthing release" | tee /etc/apt/sources.list.d/syncthing.list
|
|
|
|
apt-get update
|
|
|
|
apt-get -y install syncthing
|
|
|
|
|
|
|
|
# This probably does need to run as root so that it can access the Sync directories
|
|
|
|
# in each user's home directory
|
|
|
|
echo '[Unit]' > /etc/systemd/system/syncthing.service
|
|
|
|
echo 'Description=Syncthing - Open Source Continuous File Synchronization' >> /etc/systemd/system/syncthing.service
|
|
|
|
echo 'Documentation=man:syncthing(1)' >> /etc/systemd/system/syncthing.service
|
|
|
|
echo 'After=network.target' >> /etc/systemd/system/syncthing.service
|
|
|
|
echo 'Wants=syncthing-inotify@.service' >> /etc/systemd/system/syncthing.service
|
|
|
|
echo '' >> /etc/systemd/system/syncthing.service
|
|
|
|
echo '[Service]' >> /etc/systemd/system/syncthing.service
|
|
|
|
echo 'User=root' >> /etc/systemd/system/syncthing.service
|
|
|
|
echo "Environment='all_proxy=socks5://localhost:9050'" >> /etc/systemd/system/syncthing.service
|
|
|
|
echo 'ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0' >> /etc/systemd/system/syncthing.service
|
|
|
|
echo 'Restart=on-failure' >> /etc/systemd/system/syncthing.service
|
|
|
|
echo 'SuccessExitStatus=3 4' >> /etc/systemd/system/syncthing.service
|
|
|
|
echo 'RestartForceExitStatus=3 4' >> /etc/systemd/system/syncthing.service
|
|
|
|
echo '' >> /etc/systemd/system/syncthing.service
|
|
|
|
echo '[Install]' >> /etc/systemd/system/syncthing.service
|
|
|
|
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/syncthing.service
|
|
|
|
systemctl enable syncthing
|
|
|
|
systemctl daemon-reload
|
|
|
|
systemctl start syncthing
|
|
|
|
|
|
|
|
function_check cron_add_mins
|
2016-07-06 10:31:13 +02:00
|
|
|
cron_add_mins 1 "/usr/local/bin/${PROJECT_NAME}-syncthing > /dev/null"
|
2016-07-03 17:13:34 +02:00
|
|
|
|
|
|
|
function_check configure_firewall_for_syncthing
|
|
|
|
configure_firewall_for_syncthing
|
|
|
|
echo 'install_syncthing' >> $COMPLETION_FILE
|
|
|
|
}
|
|
|
|
|
|
|
|
# NOTE: deliberately no exit 0
|