freedombone-app-scuttlebot 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # scuttlebot pub application. Enables nat traversal for SSB.
  12. # https://scuttlebot.io
  13. #
  14. # License
  15. # =======
  16. #
  17. # Copyright (C) 2017 Bob Mottram <bob@freedombone.net>
  18. #
  19. # This program is free software: you can redistribute it and/or modify
  20. # it under the terms of the GNU Affero General Public License as published by
  21. # the Free Software Foundation, either version 3 of the License, or
  22. # (at your option) any later version.
  23. #
  24. # This program is distributed in the hope that it will be useful,
  25. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. # GNU Affero General Public License for more details.
  28. #
  29. # You should have received a copy of the GNU Affero General Public License
  30. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. VARIANTS='full full-vim social'
  32. IN_DEFAULT_INSTALL=0
  33. SHOW_ON_ABOUT=0
  34. SHOW_ICANN_ADDRESS_ON_ABOUT=0
  35. SCUTTLEBOT_DOMAIN_NAME=
  36. SCUTTLEBOT_CODE=
  37. SCUTTLEBOT_VERSION='10.4.6'
  38. SCUTTLEBOT_PORT=8010
  39. SCUTTLEBOT_ONION_PORT=8623
  40. GIT_SSB_PORT=7718
  41. NGINX_GIT_SSB_PORT=7719
  42. scuttlebot_variables=(MY_USERNAME
  43. SCUTTLEBOT_DOMAIN_NAME
  44. SCUTTLEBOT_CODE
  45. DEFAULT_DOMAIN_NAME
  46. SYSTEM_TYPE)
  47. function logging_on_scuttlebot {
  48. echo -n ''
  49. }
  50. function logging_off_scuttlebot {
  51. echo -n ''
  52. }
  53. function scuttlebot_create_invite {
  54. invite_string=$(su -c "sbot invite.create 1" - scuttlebot | sed 's/"//g')
  55. clear
  56. echo -e '\n\nYour Scuttlebot invite code is:\n\n'${invite_string}'\n\n'
  57. read -n1 -r -p $"Press any key to continue..." key
  58. }
  59. function configure_interactive_scuttlebot {
  60. while true
  61. do
  62. data=$(tempfile 2>/dev/null)
  63. trap "rm -f $data" 0 1 2 5 15
  64. dialog --backtitle $"Freedombone Control Panel" \
  65. --title $"Scuttlebot" \
  66. --radiolist $"Choose an operation:" 10 50 2 \
  67. 1 $"Create an invite" off \
  68. 2 $"Exit" on 2> $data
  69. sel=$?
  70. case $sel in
  71. 1) return;;
  72. 255) return;;
  73. esac
  74. case $(cat $data) in
  75. 1) scuttlebot_create_invite;;
  76. 2) break;;
  77. esac
  78. done
  79. }
  80. function remove_user_scuttlebot {
  81. remove_username="$1"
  82. }
  83. function add_user_scuttlebot {
  84. new_username="$1"
  85. new_user_password="$2"
  86. echo '0'
  87. }
  88. function install_interactive_scuttlebot {
  89. if [[ $ONION_ONLY != "no" ]]; then
  90. SCUTTLEBOT_DOMAIN_NAME='scuttlebot.local'
  91. write_config_param "SCUTTLEBOT_DOMAIN_NAME" "$SCUTTLEBOT_DOMAIN_NAME"
  92. else
  93. function_check interactive_site_details
  94. interactive_site_details scuttlebot
  95. fi
  96. APP_INSTALLED=1
  97. }
  98. function change_password_scuttlebot {
  99. new_username="$1"
  100. new_user_password="$2"
  101. echo '0'
  102. }
  103. function reconfigure_scuttlebot {
  104. if [ -d /etc/scuttlebot/.ssb ]; then
  105. systemctl stop scuttlebot
  106. rm -rf /etc/scuttlebot/.ssb
  107. systemctl start scuttlebot
  108. fi
  109. }
  110. function upgrade_scuttlebot {
  111. if ! grep -q 'scuttlebot version:' $COMPLETION_FILE; then
  112. return
  113. fi
  114. CURR_SCUTTLEBOT_VERSION=$(get_completion_param "scuttlebot version")
  115. echo "scuttlebot current version: ${CURR_SCUTTLEBOT_VERSION}"
  116. echo "scuttlebot app version: ${SCUTTLEBOT_VERSION}"
  117. if [[ "${CURR_SCUTTLEBOT_VERSION}" == "${SCUTTLEBOT_VERSION}" ]]; then
  118. return
  119. fi
  120. npm upgrade -g scuttlebot@${SCUTTLEBOT_VERSION} --save
  121. if [ ! "$?" = "0" ]; then
  122. return
  123. fi
  124. sed -i "s|scuttlebot version.*|scuttlebot version:${SCUTTLEBOT_VERSION}|g" ${COMPLETION_FILE}
  125. }
  126. function backup_local_scuttlebot {
  127. if [ -d /etc/scuttlebot/.ssb ]; then
  128. systemctl stop scuttlebot
  129. function_check backup_directory_to_usb
  130. backup_directory_to_usb /etc/scuttlebot/.ssb scuttlebot
  131. systemctl start scuttlebot
  132. fi
  133. }
  134. function restore_local_scuttlebot {
  135. if [ -d /etc/scuttlebot ]; then
  136. systemctl stop scuttlebot
  137. temp_restore_dir=/root/tempscuttlebot
  138. function_check restore_directory_from_usb
  139. restore_directory_from_usb $temp_restore_dir scuttlebot
  140. if [ -d $temp_restore_dir/etc/scuttlebot/.ssb ]; then
  141. cp -r $temp_restore_dir/etc/scuttlebot/.ssb /etc/scuttlebot/
  142. else
  143. cp -r $temp_restore_dir/* /etc/scuttlebot/.ssb/*
  144. fi
  145. systemctl start scuttlebot
  146. rm -rf $temp_restore_dir
  147. fi
  148. }
  149. function backup_remote_scuttlebot {
  150. if [ -d /etc/scuttlebot/.ssb ]; then
  151. systemctl stop scuttlebot
  152. function_check backup_directory_to_friend
  153. backup_directory_to_friend /etc/scuttlebot/.ssb scuttlebot
  154. systemctl start scuttlebot
  155. fi
  156. }
  157. function restore_remote_scuttlebot {
  158. if [ -d /etc/scuttlebot ]; then
  159. systemctl stop scuttlebot
  160. temp_restore_dir=/root/tempscuttlebot
  161. function_check restore_directory_from_friend
  162. restore_directory_from_friend $temp_restore_dir scuttlebot
  163. if [ -d $temp_restore_dir/etc/scuttlebot/.ssb ]; then
  164. cp -r $temp_restore_dir/etc/scuttlebot/.ssb /etc/scuttlebot/
  165. else
  166. cp -r $temp_restore_dir/* /etc/scuttlebot/.ssb/*
  167. fi
  168. systemctl start scuttlebot
  169. rm -rf $temp_restore_dir
  170. fi
  171. }
  172. function remove_scuttlebot {
  173. firewall_remove ${SCUTTLEBOT_PORT}
  174. firewall_remove ${GIT_SSB_PORT}
  175. if [ $SCUTTLEBOT_DOMAIN_NAME ]; then
  176. nginx_dissite ${SCUTTLEBOT_DOMAIN_NAME}
  177. rm /etc/nginx/sites-available/${SCUTTLEBOT_DOMAIN_NAME}
  178. fi
  179. systemctl stop git_ssb
  180. systemctl stop scuttlebot
  181. systemctl disable git_ssb
  182. systemctl disable scuttlebot
  183. rm /etc/systemd/system/git_ssb.service
  184. rm /etc/systemd/system/scuttlebot.service
  185. systemctl daemon-reload
  186. userdel -r scuttlebot
  187. if [ -d /etc/scuttlebot ]; then
  188. rm -rf /etc/scuttlebot
  189. fi
  190. if [ -f /usr/bin/git-ssb-create ]; then
  191. rm /usr/bin/git-ssb-create
  192. fi
  193. remove_completion_param install_scuttlebot
  194. sed -i '/scuttlebot /d' $COMPLETION_FILE
  195. }
  196. function git_ssb_script {
  197. if [[ "$1" == "mesh" ]]; then
  198. git_ssb_script_name=$rootdir/usr/bin/git-ssb-create
  199. else
  200. git_ssb_script_name=/usr/bin/git-ssb-create
  201. fi
  202. echo '#!/bin/bash' > $git_ssb_script_name
  203. echo 'reponame="$1"' >> $git_ssb_script_name
  204. echo '' >> $git_ssb_script_name
  205. echo 'if [[ "$reponame" != "" ]]; then' >> $git_ssb_script_name
  206. echo ' mkdir $reponame' >> $git_ssb_script_name
  207. echo ' cd $reponame' >> $git_ssb_script_name
  208. echo ' git init' >> $git_ssb_script_name
  209. echo ' git ssb create ssb $reponame' >> $git_ssb_script_name
  210. echo ' git push --tags ssb master' >> $git_ssb_script_name
  211. echo 'fi' >> $git_ssb_script_name
  212. echo 'exit 0' >> $git_ssb_script_name
  213. chmod +x $git_ssb_script_name
  214. }
  215. function scuttlebot_git_setup {
  216. if [[ "$1" == "mesh" ]]; then
  217. if [ ! -d $rootdir/usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight ]; then
  218. mkdir $rootdir/usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight
  219. fi
  220. if [ ! -f $rootdir/usr/local/lib/node_modules/git-ssb/node_modules/highlight.js/styles/foundation.css ]; then
  221. echo $'Could not find foundation.css'
  222. exit 347687245
  223. fi
  224. cp $rootdir/usr/local/lib/node_modules/git-ssb/node_modules/highlight.js/styles/foundation.css $rootdir/usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight/foundation.css
  225. git_ssb_nginx_site=$rootdir/etc/nginx/sites-available/git_ssb
  226. echo 'server {' > $git_ssb_nginx_site
  227. echo " listen $NGINX_GIT_SSB_PORT default_server;" >> $git_ssb_nginx_site
  228. echo " server_name P${PEER_ID}.local;" >> $git_ssb_nginx_site
  229. echo '' >> $git_ssb_nginx_site
  230. echo ' access_log /dev/null;' >> $git_ssb_nginx_site
  231. echo ' error_log /dev/null;' >> $git_ssb_nginx_site
  232. echo '' >> $git_ssb_nginx_site
  233. echo ' add_header X-XSS-Protection "1; mode=block";' >> $git_ssb_nginx_site
  234. echo ' add_header X-Content-Type-Options nosniff;' >> $git_ssb_nginx_site
  235. echo ' add_header X-Frame-Options SAMEORIGIN;' >> $git_ssb_nginx_site
  236. else
  237. if [ ! $SCUTTLEBOT_DOMAIN_NAME ]; then
  238. exit 7357225
  239. fi
  240. if [ ! -d /usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight ]; then
  241. mkdir /usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight
  242. fi
  243. if [ ! -f /usr/local/lib/node_modules/git-ssb/node_modules/highlight.js/styles/foundation.css ]; then
  244. echo $'Could not find foundation.css'
  245. exit 347687245
  246. fi
  247. cp /usr/local/lib/node_modules/git-ssb/node_modules/highlight.js/styles/foundation.css /usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight/foundation.css
  248. git_ssb_nginx_site=/etc/nginx/sites-available/${SCUTTLEBOT_DOMAIN_NAME}
  249. function_check nginx_http_redirect
  250. nginx_http_redirect $SCUTTLEBOT_DOMAIN_NAME "index index.html"
  251. echo 'server {' >> $git_ssb_nginx_site
  252. echo ' listen 443 ssl;' >> $git_ssb_nginx_site
  253. echo ' listen [::]:443 ssl;' >> $git_ssb_nginx_site
  254. echo " server_name $SCUTTLEBOT_DOMAIN_NAME;" >> $git_ssb_nginx_site
  255. echo '' >> $git_ssb_nginx_site
  256. function_check nginx_compress
  257. nginx_compress $SCUTTLEBOT_DOMAIN_NAME
  258. echo '' >> $git_ssb_nginx_site
  259. echo ' # Security' >> $git_ssb_nginx_site
  260. function_check nginx_ssl
  261. nginx_ssl $SCUTTLEBOT_DOMAIN_NAME
  262. function_check nginx_disable_sniffing
  263. nginx_disable_sniffing $SCUTTLEBOT_DOMAIN_NAME
  264. fi
  265. echo '' >> $git_ssb_nginx_site
  266. echo ' root /usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web;' >> $git_ssb_nginx_site
  267. echo '' >> $git_ssb_nginx_site
  268. echo ' location = / {' >> $git_ssb_nginx_site
  269. echo " proxy_pass http://localhost:${GIT_SSB_PORT};" >> $git_ssb_nginx_site
  270. echo ' proxy_set_header X-Real-IP $remote_addr;' >> $git_ssb_nginx_site
  271. echo ' proxy_set_header Host $host;' >> $git_ssb_nginx_site
  272. echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $git_ssb_nginx_site
  273. echo ' proxy_http_version 1.1;' >> $git_ssb_nginx_site
  274. echo ' proxy_set_header Upgrade $http_upgrade;' >> $git_ssb_nginx_site
  275. echo ' proxy_set_header Connection upgrade;' >> $git_ssb_nginx_site
  276. echo ' }' >> $git_ssb_nginx_site
  277. echo '}' >> $git_ssb_nginx_site
  278. if [ $SCUTTLEBOT_ONION_HOSTNAME ]; then
  279. echo '' >> $git_ssb_nginx_site
  280. echo 'server {' >> $git_ssb_nginx_site
  281. echo " listen 127.0.0.1:${SCUTTLEBOT_ONION_PORT} default_server;" >> $git_ssb_nginx_site
  282. echo " server_name ${SCUTTLEBOT_ONION_HOSTNAME};" >> $git_ssb_nginx_site
  283. echo '' >> $git_ssb_nginx_site
  284. echo ' access_log /dev/null;' >> $git_ssb_nginx_site
  285. echo ' error_log /dev/null;' >> $git_ssb_nginx_site
  286. echo '' >> $git_ssb_nginx_site
  287. echo ' add_header X-XSS-Protection "1; mode=block";' >> $git_ssb_nginx_site
  288. echo ' add_header X-Content-Type-Options nosniff;' >> $git_ssb_nginx_site
  289. echo ' add_header X-Frame-Options SAMEORIGIN;' >> $git_ssb_nginx_site
  290. echo '' >> $git_ssb_nginx_site
  291. echo ' root /usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web;' >> $git_ssb_nginx_site
  292. echo '' >> $git_ssb_nginx_site
  293. echo ' location = / {' >> $git_ssb_nginx_site
  294. echo " proxy_pass http://localhost:${GIT_SSB_PORT};" >> $git_ssb_nginx_site
  295. echo ' proxy_set_header X-Real-IP $remote_addr;' >> $git_ssb_nginx_site
  296. echo ' proxy_set_header Host $host;' >> $git_ssb_nginx_site
  297. echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $git_ssb_nginx_site
  298. echo ' proxy_http_version 1.1;' >> $git_ssb_nginx_site
  299. echo ' proxy_set_header Upgrade $http_upgrade;' >> $git_ssb_nginx_site
  300. echo ' proxy_set_header Connection upgrade;' >> $git_ssb_nginx_site
  301. echo ' }' >> $git_ssb_nginx_site
  302. echo '}' >> $git_ssb_nginx_site
  303. fi
  304. nginx_ensite git_ssb
  305. }
  306. function mesh_install_scuttlebot {
  307. SCUTTLEBOT_ONION_HOSTNAME=
  308. get_npm_arch
  309. cat <<EOF > $rootdir/usr/bin/install_scuttlebot
  310. #!/bin/bash
  311. npm install --arch=$NPM_ARCH -g scuttlebot@${SCUTTLEBOT_VERSION}
  312. npm install --arch=$NPM_ARCH -g git-ssb
  313. npm install --arch=$NPM_ARCH -g git-remote-ssb
  314. EOF
  315. chroot "$rootdir" /bin/chmod +x /usr/bin/install_scuttlebot
  316. chroot "$rootdir" /usr/bin/install_scuttlebot
  317. rm $rootdir/usr/bin/install_scuttlebot
  318. if [ ! -f $rootdir/usr/local/bin/sbot ]; then
  319. echo $'Scuttlebot was not installed'
  320. exit 528253
  321. fi
  322. if [ ! -d $rootdir/etc/scuttlebot ]; then
  323. mkdir -p $rootdir/etc/scuttlebot
  324. fi
  325. # an unprivileged user to run as
  326. chroot "$rootdir" useradd -d /etc/scuttlebot/ scuttlebot
  327. # daemon
  328. echo '[Unit]' > $rootdir/etc/systemd/system/scuttlebot.service
  329. echo 'Description=Scuttlebot (messaging system)' >> $rootdir/etc/systemd/system/scuttlebot.service
  330. echo 'After=syslog.target' >> $rootdir/etc/systemd/system/scuttlebot.service
  331. echo 'After=network.target' >> $rootdir/etc/systemd/system/scuttlebot.service
  332. echo '' >> $rootdir/etc/systemd/system/scuttlebot.service
  333. echo '[Service]' >> $rootdir/etc/systemd/system/scuttlebot.service
  334. echo 'Type=simple' >> $rootdir/etc/systemd/system/scuttlebot.service
  335. echo 'User=scuttlebot' >> $rootdir/etc/systemd/system/scuttlebot.service
  336. echo 'Group=scuttlebot' >> $rootdir/etc/systemd/system/scuttlebot.service
  337. echo "WorkingDirectory=/etc/scuttlebot" >> $rootdir/etc/systemd/system/scuttlebot.service
  338. echo 'ExecStart=/usr/local/bin/sbot server' >> $rootdir/etc/systemd/system/scuttlebot.service
  339. echo 'Restart=always' >> $rootdir/etc/systemd/system/scuttlebot.service
  340. echo 'Environment="USER=scuttlebot"' >> $rootdir/etc/systemd/system/scuttlebot.service
  341. echo '' >> $rootdir/etc/systemd/system/scuttlebot.service
  342. echo '[Install]' >> $rootdir/etc/systemd/system/scuttlebot.service
  343. echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/scuttlebot.service
  344. scuttlebot_git_setup mesh
  345. git_ssb_script mesh
  346. }
  347. function install_scuttlebot {
  348. function_check install_nodejs
  349. install_nodejs scuttlebot
  350. npm install -g scuttlebot@${SCUTTLEBOT_VERSION}
  351. if [ ! -f /usr/local/bin/sbot ]; then
  352. exit 528253
  353. fi
  354. npm install -g git-ssb
  355. npm install -g git-remote-ssb
  356. if [ ! -d /etc/scuttlebot ]; then
  357. mkdir -p /etc/scuttlebot
  358. fi
  359. # an unprivileged user to run as
  360. useradd -d /etc/scuttlebot/ scuttlebot
  361. # daemon
  362. echo '[Unit]' > /etc/systemd/system/scuttlebot.service
  363. echo 'Description=Scuttlebot (messaging system)' >> /etc/systemd/system/scuttlebot.service
  364. echo 'After=syslog.target' >> /etc/systemd/system/scuttlebot.service
  365. echo 'After=network.target' >> /etc/systemd/system/scuttlebot.service
  366. echo '' >> /etc/systemd/system/scuttlebot.service
  367. echo '[Service]' >> /etc/systemd/system/scuttlebot.service
  368. echo 'Type=simple' >> /etc/systemd/system/scuttlebot.service
  369. echo 'User=scuttlebot' >> /etc/systemd/system/scuttlebot.service
  370. echo 'Group=scuttlebot' >> /etc/systemd/system/scuttlebot.service
  371. echo "WorkingDirectory=/etc/scuttlebot" >> /etc/systemd/system/scuttlebot.service
  372. echo 'ExecStart=/usr/local/bin/sbot server' >> /etc/systemd/system/scuttlebot.service
  373. echo 'Restart=always' >> /etc/systemd/system/scuttlebot.service
  374. echo 'Environment="USER=scuttlebot"' >> /etc/systemd/system/scuttlebot.service
  375. echo '' >> /etc/systemd/system/scuttlebot.service
  376. echo '[Install]' >> /etc/systemd/system/scuttlebot.service
  377. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/scuttlebot.service
  378. echo '[Unit]' > /etc/systemd/system/git_ssb.service
  379. echo 'Description=Git SSB (SSB git web interface)' >> /etc/systemd/system/git_ssb.service
  380. echo 'After=syslog.target' >> /etc/systemd/system/git_ssb.service
  381. echo 'After=network.target' >> /etc/systemd/system/git_ssb.service
  382. echo 'After=scuttlebot.target' >> /etc/systemd/system/git_ssb.service
  383. echo '' >> /etc/systemd/system/git_ssb.service
  384. echo '[Service]' >> /etc/systemd/system/git_ssb.service
  385. echo 'Type=simple' >> /etc/systemd/system/git_ssb.service
  386. echo 'User=scuttlebot' >> /etc/systemd/system/git_ssb.service
  387. echo 'Group=scuttlebot' >> /etc/systemd/system/git_ssb.service
  388. echo "WorkingDirectory=/etc/scuttlebot" >> /etc/systemd/system/git_ssb.service
  389. echo "ExecStart=/usr/bin/git ssb web --public localhost:$GIT_SSB_PORT" >> /etc/systemd/system/git_ssb.service
  390. echo 'Restart=always' >> /etc/systemd/system/git_ssb.service
  391. echo 'Environment="USER=scuttlebot"' >> /etc/systemd/system/git_ssb.service
  392. echo '' >> /etc/systemd/system/git_ssb.service
  393. echo '[Install]' >> /etc/systemd/system/git_ssb.service
  394. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/git_ssb.service
  395. chown -R scuttlebot:scuttlebot /etc/scuttlebot
  396. # files gw_name myhostname mdns4_minimal [NOTFOUND=return] dns
  397. sed -i "s|hosts:.*|hosts: files mdns4_minimal dns mdns4 mdns|g" /etc/nsswitch.conf
  398. # start the daemon
  399. systemctl enable scuttlebot.service
  400. systemctl daemon-reload
  401. systemctl start scuttlebot.service
  402. systemctl enable git_ssb.service
  403. systemctl daemon-reload
  404. systemctl start git_ssb.service
  405. sleep 3
  406. if [ ! -d /etc/scuttlebot/.ssb ]; then
  407. echo $'Scuttlebot config not generated'
  408. exit 73528
  409. fi
  410. echo '{' > /etc/scuttlebot/.ssb/config
  411. echo " \"host\": \"${DEFAULT_DOMAIN_NAME}\"," >> /etc/scuttlebot/.ssb/config
  412. echo " \"port\": ${SCUTTLEBOT_PORT}," >> /etc/scuttlebot/.ssb/config
  413. echo ' "timeout": 30000,' >> /etc/scuttlebot/.ssb/config
  414. echo ' "pub": true,' >> /etc/scuttlebot/.ssb/config
  415. echo ' "local": true,' >> /etc/scuttlebot/.ssb/config
  416. echo ' "friends": {' >> /etc/scuttlebot/.ssb/config
  417. echo ' "dunbar": 150,' >> /etc/scuttlebot/.ssb/config
  418. echo ' "hops": 3' >> /etc/scuttlebot/.ssb/config
  419. echo ' },' >> /etc/scuttlebot/.ssb/config
  420. echo ' "gossip": {' >> /etc/scuttlebot/.ssb/config
  421. echo ' "connections": 2' >> /etc/scuttlebot/.ssb/config
  422. echo ' },' >> /etc/scuttlebot/.ssb/config
  423. echo ' "master": [],' >> /etc/scuttlebot/.ssb/config
  424. echo ' "logging": {' >> /etc/scuttlebot/.ssb/config
  425. echo ' "level": "error"' >> /etc/scuttlebot/.ssb/config
  426. echo ' }' >> /etc/scuttlebot/.ssb/config
  427. echo '}' >> /etc/scuttlebot/.ssb/config
  428. chown scuttlebot:scuttlebot /etc/scuttlebot/.ssb/config
  429. systemctl restart scuttlebot.service
  430. firewall_add scuttlebot ${SCUTTLEBOT_PORT}
  431. firewall_add git_ssb ${GIT_SSB_PORT}
  432. SCUTTLEBOT_ONION_HOSTNAME=$(add_onion_service scuttlebot 80 ${SCUTTLEBOT_ONION_PORT})
  433. scuttlebot_git_setup
  434. git_ssb_script
  435. function_check create_site_certificate
  436. create_site_certificate ${SCUTTLEBOT_DOMAIN_NAME} 'yes'
  437. systemctl restart nginx
  438. if ! grep -q "scuttlebot version:" ${COMPLETION_FILE}; then
  439. echo "scuttlebot version:${SCUTTLEBOT_VERSION}" >> ${COMPLETION_FILE}
  440. else
  441. sed -i "s|scuttlebot version.*|scuttlebot version:${SCUTTLEBOT_VERSION}|g" ${COMPLETION_FILE}
  442. fi
  443. APP_INSTALLED=1
  444. }
  445. # NOTE: deliberately no exit 0