aboutsummaryrefslogtreecommitdiff
path: root/utils/syncthing
blob: fe2358676c0618e0ffbd9a521a16fc46ae2245f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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