freedombone-app-syncthing 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Syncthing application
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2017 Bob Mottram <bob@freedombone.net>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. VARIANTS='full full-vim cloud'
  31. IN_DEFAULT_INSTALL=0
  32. SHOW_ON_ABOUT=0
  33. SYNCTHING_ID=
  34. SYNCTHING_CONFIG_PATH=/root/.config/syncthing
  35. SYNCTHING_CONFIG_FILE=$SYNCTHING_CONFIG_PATH/config.xml
  36. SYNCTHING_RELAY_SERVER='https://relays.syncthing.net/endpoint'
  37. SYNCTHING_RELEASES='https://api.github.com/repos/syncthing/syncthing/releases?per_page=30'
  38. SYNCTHING_PORT=22000
  39. SYNCTHING_SHARED_DATA=/var/lib/syncthing/SyncShared
  40. SYNCTHING_USER_IDS_FILE='.syncthingids'
  41. syncthing_variables=(SYNCTHING_ID
  42. SYNCTHING_CONFIG_PATH
  43. SYNCTHING_CONFIG_FILE
  44. SYNCTHING_RELAY_SERVER
  45. SYNCTHING_RELEASES
  46. SYNCTHING_PORT
  47. SYNCTHING_SHARED_DATA
  48. USB_MOUNT)
  49. function logging_on_syncthing {
  50. echo -n ''
  51. }
  52. function logging_off_syncthing {
  53. echo -n ''
  54. }
  55. function syncthing_create_ids_file {
  56. if [ ! -f ~/.syncthing-server-id ]; then
  57. return
  58. fi
  59. SYNCTHING_ID=$(cat ~/.syncthing-server-id)
  60. if [ ! -f $SYNCTHING_CONFIG_FILE ]; then
  61. echo $'# Your syncthing configuration file' > $SYNCTHING_CONFIG_FILE
  62. echo '#' >> $SYNCTHING_CONFIG_FILE
  63. echo $"# The ${PROJECT_NAME} syncthing ID is: $SYNCTHING_ID" >> $SYNCTHING_CONFIG_FILE
  64. echo '#' >> $SYNCTHING_CONFIG_FILE
  65. echo '# Paste the IDs of your devices below' >> $SYNCTHING_CONFIG_FILE
  66. echo '#' >> $SYNCTHING_CONFIG_FILE
  67. fi
  68. }
  69. function syncthing_manual_edit {
  70. if [ ! -f ~/.syncthing-server-id ]; then
  71. return
  72. fi
  73. syncthing_create_ids_file
  74. editor $SYNCTHING_CONFIG_FILE
  75. # force an update of the configuration
  76. touch ~/.syncthing-update
  77. }
  78. function syncthing_show_id {
  79. if [ ! -f ~/.syncthing-server-id ]; then
  80. return
  81. fi
  82. SYNCTHING_ID=$(cat ~/.syncthing-server-id)
  83. dialog --title $"Device ID for ${PROJECT_NAME}" \
  84. --backtitle $"Freedombone User Control Panel" \
  85. --msgbox $"In a desktop terminal press shift and select the ID below,\nthen right click and copy.\n\nWithin Connectbot select Menu/Copy and then highlight the ID below\n\n$SYNCTHING_ID\n\nAlternatively press Enter to display a QR code which can be scanned." 13 78
  86. clear
  87. echo $'Your Syncthing ID code'
  88. echo ''
  89. echo -n "$SYNCTHING_ID" | qrencode -t UTF8
  90. echo ''
  91. read -n1 -rsp $"Press any key to continue..." key
  92. }
  93. function syncthing_add_id {
  94. if [ ! -f ~/.syncthing-server-id ]; then
  95. return
  96. fi
  97. syncthing_create_ids_file
  98. data=$(tempfile 2>/dev/null)
  99. trap "rm -f $data" 0 1 2 5 15
  100. dialog --backtitle $"Freedombone User Control Panel" \
  101. --title $"Add a Syncthing device ID" \
  102. --form $"Paste the device ID for your laptop/desktop/netbook/phone/tablet below" 9 80 2 \
  103. $"Device ID:" 1 1 "" 1 26 80 80 \
  104. $"Description (optional):" 2 1 "" 2 26 80 80 \
  105. 2> $data
  106. sel=$?
  107. case $sel in
  108. 1) return;;
  109. 255) return;;
  110. esac
  111. SYNCTHING_DEVICE_ID=$(cat $data | sed -n 1p)
  112. SYNCTHING_DESCRIPTION=$(cat $data | sed -n 2p)
  113. if [ ${#SYNCTHING_DEVICE_ID} -lt 10 ]; then
  114. return
  115. fi
  116. if [[ $SYNCTHING_DEVICE_ID == *"#"* || $SYNCTHING_DEVICE_ID == *"*"* || $SYNCTHING_DEVICE_ID == *'/'* || $SYNCTHING_DEVICE_ID != *"-"* ]]; then
  117. dialog --title $"Add a Syncthing device ID" \
  118. --backtitle $"Freedombone User Control Panel" \
  119. --msgbox $"That doesn't look like a device ID" 6 50
  120. return
  121. fi
  122. if grep -q "$SYNCTHING_DEVICE_ID" $SYNCTHING_CONFIG_FILE; then
  123. dialog --title $"Add a Syncthing device ID" \
  124. --backtitle $"Freedombone User Control Panel" \
  125. --msgbox $"That ID has already been added" 6 50
  126. return
  127. fi
  128. if [ ${#SYNCTHING_DESCRIPTION} -gt 0 ]; then
  129. echo "# $SYNCTHING_DESCRIPTION" >> $SYNCTHING_CONFIG_FILE
  130. fi
  131. echo "$SYNCTHING_DEVICE_ID" >> $SYNCTHING_CONFIG_FILE
  132. # force an update of the configuration
  133. touch ~/.syncthing-update
  134. dialog --title $"Add a Syncthing device ID" \
  135. --backtitle $"Freedombone User Control Panel" \
  136. --msgbox $"The ID was added" 6 50
  137. }
  138. function syncthing_remove_id {
  139. if [ ! -f ~/.syncthing-server-id ]; then
  140. return
  141. fi
  142. syncthing_create_ids_file
  143. data=$(tempfile 2>/dev/null)
  144. trap "rm -f $data" 0 1 2 5 15
  145. dialog --backtitle $"Freedombone User Control Panel" \
  146. --title $"Remove a Syncthing device ID" \
  147. --form $"Paste the device ID which is to be removed below" 8 80 1 \
  148. $"Device ID:" 1 1 "" 1 14 80 80 \
  149. 2> $data
  150. sel=$?
  151. case $sel in
  152. 1) return;;
  153. 255) return;;
  154. esac
  155. SYNCTHING_DEVICE_ID=$(cat $data | sed -n 1p)
  156. if [ ${#SYNCTHING_DEVICE_ID} -lt 10 ]; then
  157. return
  158. fi
  159. if [[ $SYNCTHING_DEVICE_ID == *"#"* || $SYNCTHING_DEVICE_ID == *"*"* || $SYNCTHING_DEVICE_ID == *'/'* || $SYNCTHING_DEVICE_ID != *"-"* ]]; then
  160. dialog --title $"Remove a Syncthing device ID" \
  161. --backtitle $"Freedombone User Control Panel" \
  162. --msgbox $"That doesn't look like a device ID" 6 50
  163. return
  164. fi
  165. if ! grep -q "$SYNCTHING_DEVICE_ID" $SYNCTHING_CONFIG_FILE; then
  166. dialog --title $"Remove a Syncthing device ID" \
  167. --backtitle $"Freedombone User Control Panel" \
  168. --msgbox $"That ID wasn't registered anyway" 6 50
  169. return
  170. fi
  171. sed -i "/$SYNCTHING_DEVICE_ID/d" $SYNCTHING_CONFIG_FILE
  172. # force an update of the configuration
  173. touch ~/.syncthing-update
  174. dialog --title $"Remove a Syncthing device ID" \
  175. --backtitle $"Freedombone User Control Panel" \
  176. --msgbox $"The ID was removed" 6 50
  177. }
  178. function run_client_syncthing {
  179. SYNCTHING_CONFIG_FILE=~/.syncthingids
  180. SYNCTHING_ID=$(cat ~/.syncthing-server-id)
  181. while true
  182. do
  183. data=$(tempfile 2>/dev/null)
  184. trap "rm -f $data" 0 1 2 5 15
  185. dialog --backtitle $"Freedombone User Control Panel" \
  186. --title $"File Synchronization" \
  187. --radiolist $"Choose an operation:" 12 70 6 \
  188. 1 $"Show device ID for ${PROJECT_NAME}" off \
  189. 2 $"Add an ID for another machine or device" off \
  190. 3 $"Remove an ID for another machine or device" off \
  191. 4 $"Manually edit device IDs" off \
  192. 5 $"Back to main menu" on 2> $data
  193. sel=$?
  194. case $sel in
  195. 1) break;;
  196. 255) break;;
  197. esac
  198. case $(cat $data) in
  199. 1) syncthing_show_id;;
  200. 2) syncthing_add_id;;
  201. 3) syncthing_remove_id;;
  202. 4) syncthing_manual_edit;;
  203. 5) break;;
  204. esac
  205. done
  206. }
  207. function install_interactive_syncthing {
  208. echo -n ''
  209. APP_INSTALLED=1
  210. }
  211. function reconfigure_syncthing {
  212. echo -n ''
  213. }
  214. function upgrade_syncthing {
  215. echo -n ''
  216. }
  217. function backup_local_syncthing {
  218. if [ -d $SYNCTHING_SHARED_DATA ]; then
  219. function_check backup_directory_to_usb
  220. backup_directory_to_usb $SYNCTHING_SHARED_DATA syncthingshared
  221. backup_directory_to_usb $SYNCTHING_CONFIG_PATH syncthingconfig
  222. fi
  223. for d in /home/*/ ; do
  224. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  225. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  226. if [ -d /home/$USERNAME/Sync ]; then
  227. echo $"Backing up syncthing files for $USERNAME"
  228. backup_directory_to_usb /home/$USERNAME/Sync syncthing/$USERNAME
  229. # ensure that device IDs will be backed up as part of user config settings
  230. if [ ! -d /home/$USERNAME/.config/syncthing ]; then
  231. mkdir -p /home/$USERNAME/.config/syncthing
  232. chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
  233. fi
  234. if [ -f /home/$USERNAME/.syncthing-server-id ]; then
  235. cp /home/$USERNAME/.syncthing-server-id /home/$USERNAME/.config/syncthing
  236. chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
  237. fi
  238. if [ -f /home/$USERNAME/.syncthingids ]; then
  239. cp /home/$USERNAME/.syncthingids /home/$USERNAME/.config/syncthing
  240. chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
  241. fi
  242. fi
  243. fi
  244. done
  245. }
  246. function restore_local_syncthing {
  247. if [ -f /etc/systemd/system/syncthing.service ]; then
  248. systemctl stop syncthing
  249. systemctl stop cron
  250. fi
  251. temp_restore_dir=/root/tempsyncthing
  252. if [ -d $USB_MOUNT/backup/syncthingconfig ]; then
  253. echo $"Restoring syncthing configuration"
  254. function_check restore_directory_from_usb
  255. restore_directory_from_usb ${temp_restore_dir}config syncthingconfig
  256. #cp -r ${temp_restore_dir}config/* /
  257. if [ ! -d $SYNCTHING_CONFIG_PATH ]; then
  258. mkdir -p $SYNCTHING_CONFIG_PATH
  259. fi
  260. cp -r ${temp_restore_dir}config/* $SYNCTHING_CONFIG_PATH/
  261. if [ ! "$?" = "0" ]; then
  262. set_user_permissions
  263. backup_unmount_drive
  264. systemctl start syncthing
  265. systemctl start cron
  266. exit 6833
  267. fi
  268. rm -rf ${temp_restore_dir}config
  269. fi
  270. if [ -d $USB_MOUNT/backup/syncthingshared ]; then
  271. echo $"Restoring syncthing shared files"
  272. restore_directory_from_usb ${temp_restore_dir}shared syncthingshared
  273. #cp -r ${temp_restore_dir}shared/* /
  274. if [ ! -d $SYNCTHING_SHARED_DATA ]; then
  275. mkdir -p $SYNCTHING_SHARED_DATA
  276. fi
  277. cp -r ${temp_restore_dir}shared/* $SYNCTHING_SHARED_DATA/
  278. if [ ! "$?" = "0" ]; then
  279. set_user_permissions
  280. backup_unmount_drive
  281. systemctl start syncthing
  282. systemctl start cron
  283. exit 37904
  284. fi
  285. rm -rf ${temp_restore_dir}shared
  286. fi
  287. if [ -d $USB_MOUNT/backup/syncthing ]; then
  288. for d in $USB_MOUNT/backup/syncthing/*/ ; do
  289. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  290. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  291. if [ ! -d /home/$USERNAME ]; then
  292. ${PROJECT_NAME}-adduser $USERNAME
  293. fi
  294. echo $"Restoring syncthing files for $USERNAME"
  295. restore_directory_from_usb ${temp_restore_dir} syncthing/$USERNAME
  296. if [ -d ${temp_restore_dir}/home/$USERNAME/Sync ]; then
  297. cp -r ${temp_restore_dir}/home/$USERNAME/Sync /home/$USERNAME/
  298. else
  299. cp -r ${temp_restore_dir}/* /home/$USERNAME/Sync/
  300. fi
  301. if [ ! "$?" = "0" ]; then
  302. rm -rf ${temp_restore_dir}
  303. set_user_permissions
  304. backup_unmount_drive
  305. systemctl start syncthing
  306. systemctl start cron
  307. exit 68438
  308. fi
  309. rm -rf ${temp_restore_dir}
  310. # restore device IDs from config settings
  311. if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
  312. cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
  313. chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
  314. fi
  315. if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
  316. cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
  317. chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
  318. fi
  319. fi
  320. done
  321. fi
  322. if [ -f /etc/systemd/system/syncthing.service ]; then
  323. systemctl start syncthing
  324. systemctl start cron
  325. fi
  326. }
  327. function backup_remote_syncthing {
  328. if [ -d $SYNCTHING_CONFIG_PATH ]; then
  329. echo $"Backing up syncthing configuration"
  330. function_check backup_directory_to_friend
  331. backup_directory_to_friend $SYNCTHING_CONFIG_PATH syncthingconfig
  332. echo $"Backup of syncthing configuration complete"
  333. fi
  334. if [ -d $SYNCTHING_SHARED_DATA ]; then
  335. echo $"Backing up syncthing shared files"
  336. function_check backup_directory_to_friend
  337. backup_directory_to_friend $SYNCTHING_SHARED_DATA syncthingshared
  338. echo $"Backup of syncthing shared files complete"
  339. fi
  340. for d in /home/*/ ; do
  341. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  342. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  343. if [ -d /home/$USERNAME/Sync ]; then
  344. echo $"Backing up syncthing files for $USERNAME"
  345. backup_directory_to_friend /home/$USERNAME/Sync syncthing/$USERNAME
  346. # ensure that device IDs will be backed up as part of user config settings
  347. if [ ! -d /home/$USERNAME/.config/syncthing ]; then
  348. mkdir -p /home/$USERNAME/.config/syncthing
  349. chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
  350. fi
  351. if [ -f /home/$USERNAME/.syncthing-server-id ]; then
  352. cp /home/$USERNAME/.syncthing-server-id /home/$USERNAME/.config/syncthing
  353. chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
  354. fi
  355. if [ -f /home/$USERNAME/.syncthingids ]; then
  356. cp /home/$USERNAME/.syncthingids /home/$USERNAME/.config/syncthing
  357. chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
  358. fi
  359. fi
  360. fi
  361. done
  362. }
  363. function restore_remote_syncthing {
  364. if [ -f /etc/systemd/system/syncthing.service ]; then
  365. systemctl stop syncthing
  366. systemctl stop cron
  367. fi
  368. if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then
  369. echo $"Restoring syncthing configuration"
  370. temp_restore_dir=/root/tempsyncthingconfig
  371. function_check restore_directory_from_friend
  372. restore_directory_from_friend $temp_restore_dir syncthingconfig
  373. #cp -r $temp_restore_dir/* /
  374. if [ ! -d $SYNCTHING_CONFIG_PATH ]; then
  375. mkdir -p $SYNCTHING_CONFIG_PATH
  376. fi
  377. cp -r ${temp_restore_dir}config/* $SYNCTHING_CONFIG_PATH/
  378. if [ ! "$?" = "0" ]; then
  379. systemctl start syncthing
  380. systemctl start cron
  381. exit 6833
  382. fi
  383. rm -rf $temp_restore_dir
  384. fi
  385. if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
  386. echo $"Restoring syncthing shared files"
  387. temp_restore_dir=/root/tempsyncthingshared
  388. function_check restore_directory_from_friend
  389. restore_directory_from_friend $temp_restore_dir syncthingshared
  390. #cp -r $temp_restore_dir/* /
  391. if [ ! -d $SYNCTHING_SHARED_DATA ]; then
  392. mkdir -p $SYNCTHING_SHARED_DATA
  393. fi
  394. cp -r ${temp_restore_dir}shared/* $SYNCTHING_SHARED_DATA/
  395. if [ ! "$?" = "0" ]; then
  396. systemctl start syncthing
  397. systemctl start cron
  398. exit 37904
  399. fi
  400. rm -rf $temp_restore_dir
  401. fi
  402. if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then
  403. for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do
  404. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  405. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  406. if [ ! -d /home/$USERNAME ]; then
  407. ${PROJECT_NAME}-adduser $USERNAME
  408. fi
  409. echo $"Restoring syncthing files for $USERNAME"
  410. temp_restore_dir=/root/tempsyncthing
  411. function_check restore_directory_from_friend
  412. restore_directory_from_friend $temp_restore_dir syncthing/$USERNAME
  413. if [ -d $temp_restore_dir/home/$USERNAME/Sync ]; then
  414. cp -r $temp_restore_dir/home/$USERNAME/Sync /home/$USERNAME/
  415. else
  416. cp -r $temp_restore_dir/* /home/$USERNAME/Sync/
  417. fi
  418. if [ ! "$?" = "0" ]; then
  419. rm -rf $temp_restore_dir
  420. systemctl start syncthing
  421. systemctl start cron
  422. exit 68438
  423. fi
  424. rm -rf $temp_restore_dir
  425. # restore device IDs from config settings
  426. if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
  427. cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
  428. chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
  429. fi
  430. if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
  431. cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
  432. chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
  433. fi
  434. echo $"Restore of syncthing files for $USERNAME complete"
  435. fi
  436. done
  437. fi
  438. if [ -f /etc/systemd/system/syncthing.service ]; then
  439. systemctl start syncthing
  440. systemctl start cron
  441. fi
  442. }
  443. function remove_syncthing {
  444. firewall_remove ${SYNCTHING_PORT}
  445. systemctl stop syncthing
  446. systemctl disable syncthing
  447. rm /etc/systemd/system/syncthing.service
  448. systemctl daemon-reload
  449. apt-get -yq remove --purge syncthing
  450. sed -i "/${PROJECT_NAME}-syncthing/d" /etc/crontab
  451. remove_completion_param install_syncthing
  452. remove_completion_param configure_firewall_for_syncthing
  453. systemctl restart cron
  454. }
  455. function configure_firewall_for_syncthing {
  456. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  457. return
  458. fi
  459. firewall_add Syncthing ${SYNCTHING_PORT}
  460. mark_completed $FUNCNAME
  461. }
  462. function install_syncthing_repo {
  463. if [ -f /etc/apt/sources.list.d/syncthing.list ]; then
  464. return
  465. fi
  466. apt-get -yq install curl
  467. curl -s https://syncthing.net/release-key.txt | apt-key add -
  468. echo "deb http://apt.syncthing.net/ syncthing release" | tee /etc/apt/sources.list.d/syncthing.list
  469. apt-get update
  470. }
  471. function install_syncthing {
  472. install_syncthing_repo
  473. apt-get -yq install syncthing
  474. # This probably does need to run as root so that it can access the Sync directories
  475. # in each user's home directory
  476. echo '[Unit]' > /etc/systemd/system/syncthing.service
  477. echo 'Description=Syncthing - Open Source Continuous File Synchronization' >> /etc/systemd/system/syncthing.service
  478. echo 'Documentation=man:syncthing(1)' >> /etc/systemd/system/syncthing.service
  479. echo 'After=network.target' >> /etc/systemd/system/syncthing.service
  480. echo 'Wants=syncthing-inotify@.service' >> /etc/systemd/system/syncthing.service
  481. echo '' >> /etc/systemd/system/syncthing.service
  482. echo '[Service]' >> /etc/systemd/system/syncthing.service
  483. echo 'User=root' >> /etc/systemd/system/syncthing.service
  484. echo "Environment='all_proxy=socks5://localhost:9050'" >> /etc/systemd/system/syncthing.service
  485. echo 'ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0' >> /etc/systemd/system/syncthing.service
  486. echo 'Restart=on-failure' >> /etc/systemd/system/syncthing.service
  487. echo 'SuccessExitStatus=3 4' >> /etc/systemd/system/syncthing.service
  488. echo 'RestartForceExitStatus=3 4' >> /etc/systemd/system/syncthing.service
  489. echo '' >> /etc/systemd/system/syncthing.service
  490. echo '[Install]' >> /etc/systemd/system/syncthing.service
  491. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/syncthing.service
  492. systemctl enable syncthing
  493. systemctl daemon-reload
  494. systemctl start syncthing
  495. function_check cron_add_mins
  496. cron_add_mins 1 "/usr/local/bin/${PROJECT_NAME}-syncthing > /dev/null"
  497. function_check configure_firewall_for_syncthing
  498. configure_firewall_for_syncthing
  499. APP_INSTALLED=1
  500. }
  501. # NOTE: deliberately no exit 0