freedombone-app-syncthing 21KB

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