freedombone-app-syncthing 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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-2018 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. rm -rf ${temp_restore_dir}shared
  279. fi
  280. if [ -d $USB_MOUNT/backup/syncthing ]; then
  281. for d in $USB_MOUNT/backup/syncthing/*/ ; do
  282. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  283. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  284. if [ ! -d /home/$USERNAME ]; then
  285. ${PROJECT_NAME}-adduser $USERNAME
  286. fi
  287. echo $"Restoring syncthing files for $USERNAME"
  288. restore_directory_from_usb ${temp_restore_dir} syncthing/$USERNAME
  289. if [ -d ${temp_restore_dir}/home/$USERNAME/Sync ]; then
  290. cp -r ${temp_restore_dir}/home/$USERNAME/Sync /home/$USERNAME/
  291. else
  292. if [ ! -d /home/$USERNAME/Sync ]; then
  293. mkdir /home/$USERNAME/Sync
  294. fi
  295. cp -r ${temp_restore_dir}/* /home/$USERNAME/Sync/
  296. fi
  297. if [ ! "$?" = "0" ]; then
  298. rm -rf ${temp_restore_dir}
  299. set_user_permissions
  300. backup_unmount_drive
  301. systemctl start syncthing
  302. systemctl start cron
  303. exit 68438
  304. fi
  305. rm -rf ${temp_restore_dir}
  306. # restore device IDs from config settings
  307. if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
  308. cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
  309. chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
  310. fi
  311. if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
  312. cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
  313. chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
  314. fi
  315. fi
  316. done
  317. fi
  318. if [ -f /etc/systemd/system/syncthing.service ]; then
  319. systemctl start syncthing
  320. systemctl start cron
  321. fi
  322. }
  323. function backup_remote_syncthing {
  324. if [ -d $SYNCTHING_CONFIG_PATH ]; then
  325. echo $"Backing up syncthing configuration"
  326. function_check backup_directory_to_friend
  327. backup_directory_to_friend $SYNCTHING_CONFIG_PATH syncthingconfig
  328. echo $"Backup of syncthing configuration complete"
  329. fi
  330. if [ -d $SYNCTHING_SHARED_DATA ]; then
  331. echo $"Backing up syncthing shared files"
  332. function_check backup_directory_to_friend
  333. backup_directory_to_friend $SYNCTHING_SHARED_DATA syncthingshared
  334. echo $"Backup of syncthing shared files complete"
  335. fi
  336. for d in /home/*/ ; do
  337. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  338. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  339. if [ -d /home/$USERNAME/Sync ]; then
  340. echo $"Backing up syncthing files for $USERNAME"
  341. backup_directory_to_friend /home/$USERNAME/Sync syncthing/$USERNAME
  342. # ensure that device IDs will be backed up as part of user config settings
  343. if [ ! -d /home/$USERNAME/.config/syncthing ]; then
  344. mkdir -p /home/$USERNAME/.config/syncthing
  345. chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
  346. fi
  347. if [ -f /home/$USERNAME/.syncthing-server-id ]; then
  348. cp /home/$USERNAME/.syncthing-server-id /home/$USERNAME/.config/syncthing
  349. chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
  350. fi
  351. if [ -f /home/$USERNAME/.syncthingids ]; then
  352. cp /home/$USERNAME/.syncthingids /home/$USERNAME/.config/syncthing
  353. chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
  354. fi
  355. fi
  356. fi
  357. done
  358. }
  359. function restore_remote_syncthing {
  360. if [ -f /etc/systemd/system/syncthing.service ]; then
  361. systemctl stop syncthing
  362. systemctl stop cron
  363. fi
  364. if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then
  365. echo $"Restoring syncthing configuration"
  366. temp_restore_dir=/root/tempsyncthingconfig
  367. function_check restore_directory_from_friend
  368. restore_directory_from_friend $temp_restore_dir syncthingconfig
  369. #cp -r $temp_restore_dir/* /
  370. if [ ! -d $SYNCTHING_CONFIG_PATH ]; then
  371. mkdir -p $SYNCTHING_CONFIG_PATH
  372. fi
  373. cp -r ${temp_restore_dir}/* $SYNCTHING_CONFIG_PATH/
  374. if [ ! "$?" = "0" ]; then
  375. systemctl start syncthing
  376. systemctl start cron
  377. exit 6833
  378. fi
  379. rm -rf $temp_restore_dir
  380. fi
  381. if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
  382. echo $"Restoring syncthing shared files"
  383. temp_restore_dir=/root/tempsyncthingshared
  384. function_check restore_directory_from_friend
  385. restore_directory_from_friend $temp_restore_dir syncthingshared
  386. if [ ! -d $SYNCTHING_SHARED_DATA ]; then
  387. mkdir -p $SYNCTHING_SHARED_DATA
  388. fi
  389. cp -r ${temp_restore_dir}/* $SYNCTHING_SHARED_DATA/
  390. rm -rf ${temp_restore_dir}
  391. fi
  392. if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then
  393. for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do
  394. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  395. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  396. if [ ! -d /home/$USERNAME ]; then
  397. ${PROJECT_NAME}-adduser $USERNAME
  398. fi
  399. echo $"Restoring syncthing files for $USERNAME"
  400. temp_restore_dir=/root/tempsyncthing
  401. function_check restore_directory_from_friend
  402. restore_directory_from_friend $temp_restore_dir syncthing/$USERNAME
  403. if [ -d $temp_restore_dir/home/$USERNAME/Sync ]; then
  404. cp -r $temp_restore_dir/home/$USERNAME/Sync /home/$USERNAME/
  405. else
  406. if [ ! -d /home/$USERNAME/Sync ]; then
  407. mkdir /home/$USERNAME/Sync
  408. fi
  409. cp -r $temp_restore_dir/* /home/$USERNAME/Sync/
  410. fi
  411. if [ ! "$?" = "0" ]; then
  412. rm -rf $temp_restore_dir
  413. systemctl start syncthing
  414. systemctl start cron
  415. exit 68438
  416. fi
  417. rm -rf $temp_restore_dir
  418. # restore device IDs from config settings
  419. if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
  420. cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
  421. chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
  422. fi
  423. if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
  424. cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
  425. chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
  426. fi
  427. echo $"Restore of syncthing files for $USERNAME complete"
  428. fi
  429. done
  430. fi
  431. if [ -f /etc/systemd/system/syncthing.service ]; then
  432. systemctl start syncthing
  433. systemctl start cron
  434. fi
  435. }
  436. function remove_syncthing {
  437. firewall_remove ${SYNCTHING_PORT}
  438. systemctl stop syncthing
  439. systemctl disable syncthing
  440. rm /etc/systemd/system/syncthing.service
  441. systemctl daemon-reload
  442. apt-get -yq remove --purge syncthing
  443. sed -i "/${PROJECT_NAME}-syncthing/d" /etc/crontab
  444. remove_completion_param install_syncthing
  445. remove_completion_param configure_firewall_for_syncthing
  446. systemctl restart cron
  447. }
  448. function configure_firewall_for_syncthing {
  449. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  450. return
  451. fi
  452. firewall_add Syncthing ${SYNCTHING_PORT}
  453. mark_completed $FUNCNAME
  454. }
  455. function install_syncthing_repo {
  456. if [ -f /etc/apt/sources.list.d/syncthing.list ]; then
  457. return
  458. fi
  459. apt-get -yq install curl
  460. curl -s https://syncthing.net/release-key.txt | apt-key add -
  461. echo "deb http://apt.syncthing.net/ syncthing release" | tee /etc/apt/sources.list.d/syncthing.list
  462. apt-get update
  463. }
  464. function install_syncthing {
  465. install_syncthing_repo
  466. apt-get -yq install syncthing
  467. # This probably does need to run as root so that it can access the Sync directories
  468. # in each user's home directory
  469. echo '[Unit]' > /etc/systemd/system/syncthing.service
  470. echo 'Description=Syncthing - Open Source Continuous File Synchronization' >> /etc/systemd/system/syncthing.service
  471. echo 'Documentation=man:syncthing(1)' >> /etc/systemd/system/syncthing.service
  472. echo 'After=network.target' >> /etc/systemd/system/syncthing.service
  473. echo 'Wants=syncthing-inotify@.service' >> /etc/systemd/system/syncthing.service
  474. echo '' >> /etc/systemd/system/syncthing.service
  475. echo '[Service]' >> /etc/systemd/system/syncthing.service
  476. echo 'User=root' >> /etc/systemd/system/syncthing.service
  477. echo "Environment='all_proxy=socks5://localhost:9050'" >> /etc/systemd/system/syncthing.service
  478. echo 'ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0' >> /etc/systemd/system/syncthing.service
  479. echo 'Restart=on-failure' >> /etc/systemd/system/syncthing.service
  480. echo 'SuccessExitStatus=3 4' >> /etc/systemd/system/syncthing.service
  481. echo 'RestartForceExitStatus=3 4' >> /etc/systemd/system/syncthing.service
  482. echo '' >> /etc/systemd/system/syncthing.service
  483. echo '[Install]' >> /etc/systemd/system/syncthing.service
  484. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/syncthing.service
  485. systemctl enable syncthing
  486. systemctl daemon-reload
  487. systemctl start syncthing
  488. function_check cron_add_mins
  489. cron_add_mins 1 "/usr/local/bin/${PROJECT_NAME}-syncthing > /dev/null"
  490. function_check configure_firewall_for_syncthing
  491. configure_firewall_for_syncthing
  492. APP_INSTALLED=1
  493. }
  494. # NOTE: deliberately no exit 0