aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rwxr-xr-xutils/syncthing99
1 files changed, 99 insertions, 0 deletions
diff --git a/utils/syncthing b/utils/syncthing
new file mode 100755
index 0000000..fe23586
--- /dev/null
+++ b/utils/syncthing
@@ -0,0 +1,99 @@
+#!/bin/sh
+set -e
+
+[ -d syncthing ] || (echo "There is no configuration directory" >&2; exit 1)
+HOST="$(hostname)"
+[ -f syncthing/"$HOST" ] || (echo "Host $HOST seems to be unconfigured" >&2; exit 1)
+
+TMPCNF="/tmp/syncthing.conf.xml"
+[ -f $TMPCNF ] && rm $TMPCNF
+
+# Begin configuration
+echo "<configuration version=\"17\">" >$TMPCNF
+
+for h in syncthing/*; do
+ # Source host
+ . "$h"
+
+ # Set to configuration
+ echo " <device id=\"$ID\" name=\"$NAME\" compression=\"metadata\" introducer=\"false\">" >>$TMPCNF
+ echo " <address>$ADDRESS</address>" >>$TMPCNF
+ echo " </device>" >>$TMPCNF
+
+ # Parse DIRS of this host
+ eval `echo "$DIRS" | sed -ne 's/^\([^:]*\):.*$/ST_DIR_HOSTS_\1="$ST_DIR_HOSTS_\1 $ID"/p'`
+done
+
+# Now again source target host
+. syncthing/"$HOST"
+
+
+while read -r d; do
+ # Get name of the directory
+ NM="$(echo "$d" | sed 's/:.*$//')"
+ # Get target path
+ PTH="$(echo "$d" | sed 's/^[^:]*://')"
+ # Write folder init
+ echo " <folder id=\"$NM\" label=\"$NM\" path=\"$PTH\" type=\"readwrite\" rescanIntervalS=\"300\" ignorePerms=\"false\" autoNormalize=\"true\">" >>$TMPCNF
+ # Specify every all devices
+ for dev in eval `echo \$ST_DIR_HOSTS_$NM`; do
+ echo " <device id=\"$dev\"></device>" >>$TMPCNF
+ done
+ # Write common configs (TODO do we want to have chance to change it?)
+ echo " <minDiskFreePct>1</minDiskFreePct>
+ <versioning></versioning>
+ <copiers>0</copiers>
+ <pullers>0</pullers>
+ <hashers>0</hashers>
+ <order>random</order>
+ <ignoreDelete>false</ignoreDelete>
+ <scanProgressIntervalS>0</scanProgressIntervalS>
+ <pullerSleepS>0</pullerSleepS>
+ <pullerPauseS>0</pullerPauseS>
+ <maxConflicts>10</maxConflicts>
+ <disableSparseFiles>false</disableSparseFiles>
+ <disableTempIndexes>false</disableTempIndexes>
+ <fsync>true</fsync>" >>$TMPCNF
+ # Write folder end
+ echo " </folder>" >>$TMPCNF
+done <<<"$DIRS"
+
+# Some defaults (TODO again do we care about those on various hosts)
+echo " <gui enabled="true" tls="false" debugging="false">
+ <address>127.0.0.1:8384</address>
+ <apikey>$APIKEY</apikey>
+ <theme>dark</theme>
+ </gui>
+ <options>
+ <listenAddress>default</listenAddress>
+ <globalAnnounceServer>default</globalAnnounceServer>
+ <globalAnnounceEnabled>true</globalAnnounceEnabled>
+ <localAnnounceEnabled>true</localAnnounceEnabled>
+ <localAnnouncePort>21027</localAnnouncePort>
+ <localAnnounceMCAddr>[ff12::8384]:21027</localAnnounceMCAddr>
+ <maxSendKbps>0</maxSendKbps>
+ <maxRecvKbps>0</maxRecvKbps>
+ <reconnectionIntervalS>60</reconnectionIntervalS>
+ <relaysEnabled>true</relaysEnabled>
+ <relayReconnectIntervalM>10</relayReconnectIntervalM>
+ <startBrowser>true</startBrowser>
+ <natEnabled>true</natEnabled>
+ <natLeaseMinutes>60</natLeaseMinutes>
+ <natRenewalMinutes>30</natRenewalMinutes>
+ <natTimeoutSeconds>10</natTimeoutSeconds>
+ <urInitialDelayS>1800</urInitialDelayS>
+ <restartOnWakeup>true</restartOnWakeup>
+ <autoUpgradeIntervalH>12</autoUpgradeIntervalH>
+ <keepTemporariesH>24</keepTemporariesH>
+ <cacheIgnoredFiles>false</cacheIgnoredFiles>
+ <progressUpdateIntervalS>5</progressUpdateIntervalS>
+ <symlinksEnabled>true</symlinksEnabled>
+ <limitBandwidthInLan>false</limitBandwidthInLan>
+ <minHomeDiskFreePct>1</minHomeDiskFreePct>
+ <releasesURL>https://upgrades.syncthing.net/meta.json</releasesURL>
+ <overwriteRemoteDeviceNamesOnConnect>false</overwriteRemoteDeviceNamesOnConnect>
+ <tempIndexMinBlocks>10</tempIndexMinBlocks>
+ </options>" >>$TMPCNF
+
+# End configuration
+echo "</configuration>" >>$TMPCNF