freedombone-app-zeronet 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Zeronet functions
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
  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. ZERONET_REPO="https://github.com/HelloZeroNet/ZeroNet.git"
  31. ZERONET_COMMIT='675bd462556c541d65e2d95f91f899146a373aad'
  32. ZERONET_BLOG_REPO="https://github.com/HelloZeroNet/ZeroBlog"
  33. ZERONET_BLOG_COMMIT='bbb0d6c36465fed2e6df71f1aab45fcc9c6ad609'
  34. ZERONET_MAIL_REPO="https://github.com/HelloZeroNet/ZeroMail"
  35. ZERONET_MAIL_COMMIT='955af09d643c72b02e4983d71eca5c0c93a6c131'
  36. ZERONET_FORUM_REPO="https://github.com/HelloZeroNet/ZeroTalk"
  37. ZERONET_FORUM_COMMIT='e2d2c9cb1cfbfef91b244935efb5c14c2ad95faa'
  38. ZERONET_URL=http://127.0.0.1:43110
  39. ZERONET_PORT=15441
  40. TRACKER_PORT=6969
  41. ZERONET_DEFAULT_BLOG_TAGLINE="Blogging on the Mesh"
  42. ZERONET_DEFAULT_FORUM_TAGLINE="A decentralized discussion group"
  43. ZERONET_DEFAULT_MAIL_TAGLINE="Mail for the Mesh"
  44. ZERONET_ID_REPO="https://github.com/HelloZeroNet/ZeroID"
  45. ZERONET_ID_COMMIT='ccf14fdc96fa9cdb2ddd8a7ab283a8e17a4f234b'
  46. function backup_zeronet {
  47. echo ''
  48. }
  49. function remove_zeronet_blog {
  50. if ! grep -Fxq "install_zeronet_blog" $COMPLETION_FILE; then
  51. return
  52. fi
  53. if [ -d $MESH_INSTALL_DIR/zeronet/ZeroBlog ]; then
  54. rm -rf $MESH_INSTALL_DIR/zeronet/ZeroBlog
  55. fi
  56. sed -i '/install_zeronet_blog/d' $COMPLETION_FILE
  57. sed -i '/ZeroNet Blog/d' $COMPLETION_FILE
  58. }
  59. function remove_zeronet_mail {
  60. if ! grep -Fxq "install_zeronet_mail" $COMPLETION_FILE; then
  61. return
  62. fi
  63. if [ -d $MESH_INSTALL_DIR/zeronet/ZeroMail ]; then
  64. rm -rf $MESH_INSTALL_DIR/zeronet/ZeroMail
  65. fi
  66. sed -i '/install_zeronet_mail/d' $COMPLETION_FILE
  67. sed -i '/ZeroNet Mail/d' $COMPLETION_FILE
  68. }
  69. function remove_zeronet_forum {
  70. if ! grep -Fxq "install_zeronet_forum" $COMPLETION_FILE; then
  71. return
  72. fi
  73. if [ -d $MESH_INSTALL_DIR/zeronet/ZeroTalk ]; then
  74. rm -rf $MESH_INSTALL_DIR/zeronet/ZeroTalk
  75. fi
  76. sed -i '/install_zeronet_forum/d' $COMPLETION_FILE
  77. sed -i '/ZeroNet Forum/d' $COMPLETION_FILE
  78. }
  79. function remove_zeronet {
  80. remove_zeronet_blog
  81. remove_zeronet_mail
  82. remove_zeronet_forum
  83. if ! grep -Fxq "install_zeronet" $COMPLETION_FILE; then
  84. return
  85. fi
  86. iptables -D INPUT -i $WIFI_INTERFACE -p udp --dport $ZERONET_PORT -j ACCEPT
  87. iptables -D INPUT -i $WIFI_INTERFACE -p tcp --dport $ZERONET_PORT -j ACCEPT
  88. iptables -D INPUT -i $WIFI_INTERFACE -p udp --dport $TRACKER_PORT -j ACCEPT
  89. iptables -D INPUT -i $WIFI_INTERFACE -p tcp --dport $TRACKER_PORT -j ACCEPT
  90. iptables -D INPUT -i $WIFI_INTERFACE -p udp --dport 1900 -j ACCEPT
  91. function_check save_firewall_settings
  92. save_firewall_settings
  93. ${PROJECT_NAME}-mesh-install -f zeronet --remove yes
  94. sed -i '/install_zeronet/d' $COMPLETION_FILE
  95. sed -i '/ZeroNet /d' $COMPLETION_FILE
  96. sed -i '/configure_firewall_for_zeronet/d' $COMPLETION_FILE
  97. }
  98. function configure_firewall_for_zeronet {
  99. if grep -Fxq "configure_firewall_for_zeronet" $COMPLETION_FILE; then
  100. return
  101. fi
  102. if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
  103. return
  104. fi
  105. iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $ZERONET_PORT -j ACCEPT
  106. iptables -A INPUT -i $WIFI_INTERFACE -p tcp --dport $ZERONET_PORT -j ACCEPT
  107. iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $TRACKER_PORT -j ACCEPT
  108. iptables -A INPUT -i $WIFI_INTERFACE -p tcp --dport $TRACKER_PORT -j ACCEPT
  109. iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport 1900 -j ACCEPT
  110. function_check save_firewall_settings
  111. save_firewall_settings
  112. OPEN_PORTS+=("ZeroNet $ZERONET_PORT")
  113. OPEN_PORTS+=("Tracker $TRACKER_PORT")
  114. echo 'configure_firewall_for_zeronet' >> $COMPLETION_FILE
  115. }
  116. function install_zeronet_blog {
  117. if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
  118. return
  119. fi
  120. function_check set_repo_commit
  121. set_repo_commit $MESH_INSTALL_DIR/zeronet/ZeroBlog "ZeroNet Blog commit" "$ZERONET_BLOG_COMMIT" $ZERONET_BLOG_REPO
  122. if grep -Fxq "install_zeronet_blog" $COMPLETION_FILE; then
  123. return
  124. fi
  125. if [ ! -f /home/$MY_USERNAME/README ]; then
  126. touch /home/$MY_USERNAME/README
  127. fi
  128. if grep -q "ZeroNet Blog address" /home/$MY_USERNAME/README; then
  129. return
  130. fi
  131. if [ ! -d /etc/avahi ]; then
  132. echo $'Avahi is not installed'
  133. exit 736
  134. fi
  135. ZERONET_DEFAULT_BLOG_TITLE="${MY_USERNAME}'s Blog"
  136. cd $MESH_INSTALL_DIR/zeronet
  137. python zeronet.py --batch siteCreate 2> $MESH_INSTALL_DIR/zeronet/blog.txt
  138. if [ ! -f $MESH_INSTALL_DIR/zeronet/blog.txt ]; then
  139. echo $'Unable to create blog'
  140. exit 479
  141. fi
  142. blog_address=$(cat blog.txt | grep "Site address" | awk -F ':' '{print $2}')
  143. blog_private_key=$(cat blog.txt | grep "Site private key" | awk -F ':' '{print $2}')
  144. ZERONET_BLOG_ADDRESS=${blog_address//[[:blank:]]/}
  145. ZERONET_BLOG_PRIVATE_KEY=${blog_private_key//[[:blank:]]/}
  146. if [ ${#ZERONET_BLOG_ADDRESS} -lt 20 ]; then
  147. echo $"Address: $ZERONET_BLOG_ADDRESS"
  148. echo $"Public key: $ZERONET_BLOG_PRIVATE_KEY"
  149. echo $'Unable to create zeronet blog address'
  150. exit 7358
  151. fi
  152. if [ ${#ZERONET_BLOG_PRIVATE_KEY} -lt 20 ]; then
  153. echo $"Address: $ZERONET_BLOG_ADDRESS"
  154. echo $"Public key: $ZERONET_BLOG_PRIVATE_KEY"
  155. echo $'Unable to create zeronet blog private key'
  156. exit 1639
  157. fi
  158. if [ ! -d "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS" ]; then
  159. echo $"Unable to find site directory: $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS"
  160. exit 7638
  161. fi
  162. function_check git_clone
  163. git_clone $ZERONET_BLOG_REPO ZeroBlog
  164. if [ ! -d $MESH_INSTALL_DIR/zeronet/ZeroBlog ]; then
  165. echo $'ZeroBlog repo could not be cloned'
  166. exit 6739
  167. fi
  168. cd $MESH_INSTALL_DIR/zeronet/ZeroBlog
  169. git checkout $ZERONET_BLOG_COMMIT -b $ZERONET_BLOG_COMMIT
  170. if ! grep -q "ZeroNet Blog commit" $COMPLETION_FILE; then
  171. echo "ZeroNet Blog commit:$ZERONET_BLOG_COMMIT" >> $COMPLETION_FILE
  172. else
  173. sed -i "s/ZeroNet Blog commit.*/ZeroNet Blog commit:$ZERONET_BLOG_COMMIT/g" $COMPLETION_FILE
  174. fi
  175. echo $"ZeroNet Blog address: $ZERONET_BLOG_ADDRESS"
  176. echo $"ZeroNet Blog private key: $ZERONET_BLOG_PRIVATE_KEY"
  177. cp -r $MESH_INSTALL_DIR/zeronet/ZeroBlog/* $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS
  178. if [ ! -d $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data ]; then
  179. mkdir $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data
  180. fi
  181. cp $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data-default/data.json $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data
  182. sed -i "s/MyZeroBlog/$ZERONET_DEFAULT_BLOG_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data/data.json
  183. sed -i "s/My ZeroBlog./$ZERONET_DEFAULT_BLOG_TAGLINE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data/data.json
  184. sed -i "s/ZeroBlog Demo/$ZERONET_DEFAULT_BLOG_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/index.html
  185. sed -i "s|<h3 class=\"description\">.*|<h3 class=\"description\">$ZERONET_DEFAULT_BLOG_TAGLINE</h3>|g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/index.html
  186. sed -i "s/Blogging platform Demo/Blogging platform/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/content.json
  187. python zeronet.py siteSign $ZERONET_BLOG_ADDRESS $ZERONET_BLOG_PRIVATE_KEY
  188. # Add an avahi service
  189. function_check create_avahi_service
  190. create_avahi_service zeronet-blog "zeronet-blog" udp $ZERONET_PORT "$ZERONET_URL/$ZERONET_BLOG_ADDRESS"
  191. cp /tmp/zeronet-blog.service /etc/avahi/services/zeronet-blog.service
  192. if [ ! -d /home/$MY_USERNAME/.config/zeronet ]; then
  193. mkdir -p /home/$MY_USERNAME/.config/zeronet
  194. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
  195. fi
  196. echo "$ZERONET_URL/$ZERONET_BLOG_ADDRESS" > /home/$MY_USERNAME/.config/zeronet/myblog
  197. if ! grep -q "ZeroNet Blog address" /home/$MY_USERNAME/README; then
  198. echo '' >> /home/$MY_USERNAME/README
  199. echo "ZeroNet Blog address: $ZERONET_BLOG_ADDRESS" >> /home/$MY_USERNAME/README
  200. echo "ZeroNet Blog private key: $ZERONET_BLOG_PRIVATE_KEY" >> /home/$MY_USERNAME/README
  201. fi
  202. echo 'install_zeronet_blog' >> $COMPLETION_FILE
  203. }
  204. function install_zeronet_mail {
  205. if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
  206. return
  207. fi
  208. function_check set_repo_commit
  209. set_repo_commit $MESH_INSTALL_DIR/zeronet/ZeroMail "ZeroNet Mail commit" "$ZERONET_MAIL_COMMIT" $ZERONET_MAIL_REPO
  210. if grep -Fxq "install_zeronet_mail" $COMPLETION_FILE; then
  211. return
  212. fi
  213. if [ ! -f /home/$MY_USERNAME/README ]; then
  214. touch /home/$MY_USERNAME/README
  215. fi
  216. if grep -q "ZeroNet Mail address" /home/$MY_USERNAME/README; then
  217. return
  218. fi
  219. if [ ! -d /etc/avahi ]; then
  220. echo 'Avahi is not installed'
  221. exit 736
  222. fi
  223. ZERONET_DEFAULT_MAIL_TITLE="${MY_USERNAME}'s Mail"
  224. cd $MESH_INSTALL_DIR/zeronet
  225. python zeronet.py --batch siteCreate 2> $MESH_INSTALL_DIR/zeronet/mail.txt
  226. if [ ! -f $MESH_INSTALL_DIR/zeronet/mail.txt ]; then
  227. echo $'Unable to create mail'
  228. exit 479
  229. fi
  230. mail_address=$(cat mail.txt | grep "Site address" | awk -F ':' '{print $2}')
  231. mail_private_key=$(cat mail.txt | grep "Site private key" | awk -F ':' '{print $2}')
  232. ZERONET_MAIL_ADDRESS=${mail_address//[[:blank:]]/}
  233. ZERONET_MAIL_PRIVATE_KEY=${mail_private_key//[[:blank:]]/}
  234. if [ ${#ZERONET_MAIL_ADDRESS} -lt 20 ]; then
  235. echo $"Address: $ZERONET_MAIL_ADDRESS"
  236. echo $"Public key: $ZERONET_MAIL_PRIVATE_KEY"
  237. echo $'Unable to create zeronet mail address'
  238. exit 7358
  239. fi
  240. if [ ${#ZERONET_MAIL_PRIVATE_KEY} -lt 20 ]; then
  241. echo $"Address: $ZERONET_MAIL_ADDRESS"
  242. echo $"Public key: $ZERONET_MAIL_PRIVATE_KEY"
  243. echo $'Unable to create zeronet mail private key'
  244. exit 1639
  245. fi
  246. if [ ! -d "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS" ]; then
  247. echo $"Unable to find site directory: $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS"
  248. exit 7638
  249. fi
  250. function_check git_clone
  251. git_clone $ZERONET_MAIL_REPO ZeroMail
  252. if [ ! -d $MESH_INSTALL_DIR/zeronet/ZeroMail ]; then
  253. echo $'ZeroMail repo could not be cloned'
  254. exit 6739
  255. fi
  256. cd $MESH_INSTALL_DIR/zeronet/ZeroMail
  257. git checkout $ZERONET_MAIL_COMMIT -b $ZERONET_MAIL_COMMIT
  258. if ! grep -q "ZeroNet Mail commit" $COMPLETION_FILE; then
  259. echo "ZeroNet Mail commit:$ZERONET_MAIL_COMMIT" >> $COMPLETION_FILE
  260. else
  261. sed -i "s/ZeroNet Mail commit.*/ZeroNet Mail commit:$ZERONET_MAIL_COMMIT/g" $COMPLETION_FILE
  262. fi
  263. echo $"ZeroNet Mail address: $ZERONET_MAIL_ADDRESS"
  264. echo $"ZeroNet Mail private key: $ZERONET_MAIL_PRIVATE_KEY"
  265. cp -r $MESH_INSTALL_DIR/zeronet/ZeroMail/* $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS
  266. if [ ! -d $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data ]; then
  267. mkdir $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data
  268. fi
  269. cp $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data-default/data.json $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data
  270. sed -i "s/MyZeroMail/$ZERONET_DEFAULT_MAIL_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data/data.json
  271. sed -i "s/My ZeroMail./$ZERONET_DEFAULT_MAIL_TAGLINE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data/data.json
  272. sed -i "s/ZeroMail Demo/$ZERONET_DEFAULT_MAIL_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/index.html
  273. sed -i "s|<h3 class=\"description\">.*|<h3 class=\"description\">$ZERONET_DEFAULT_MAIL_TAGLINE</h3>|g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/index.html
  274. sed -i "s/Mailging platform Demo/Mailging platform/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/content.json
  275. python zeronet.py siteSign $ZERONET_MAIL_ADDRESS $ZERONET_MAIL_PRIVATE_KEY
  276. # Add an avahi service
  277. function_check create_avahi_service
  278. create_avahi_service zeronet-mail "zeronet-mail" udp $ZERONET_PORT "$ZERONET_URL/$ZERONET_MAIL_ADDRESS"
  279. cp /tmp/zeronet-mail.service /etc/avahi/services/zeronet-mail.service
  280. if [ ! -d /home/$MY_USERNAME/.config/zeronet ]; then
  281. mkdir -p /home/$MY_USERNAME/.config/zeronet
  282. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
  283. fi
  284. echo "$ZERONET_URL/$ZERONET_MAIL_ADDRESS" > /home/$MY_USERNAME/.config/zeronet/mymail
  285. if ! grep -q $"ZeroNet Mail address" /home/$MY_USERNAME/README; then
  286. echo '' >> /home/$MY_USERNAME/README
  287. echo $"ZeroNet Mail address: $ZERONET_MAIL_ADDRESS" >> /home/$MY_USERNAME/README
  288. echo $"ZeroNet Mail private key: $ZERONET_MAIL_PRIVATE_KEY" >> /home/$MY_USERNAME/README
  289. fi
  290. echo 'install_zeronet_mail' >> $COMPLETION_FILE
  291. }
  292. function install_zeronet_forum {
  293. if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
  294. return
  295. fi
  296. # update to the next commit
  297. function_check set_repo_commit
  298. set_repo_commit $MESH_INSTALL_DIR/zeronet/ZeroTalk "ZeroNet Forum commit" "$ZERONET_FORUM_COMMIT" $ZERONET_FORUM_REPO
  299. if grep -Fxq "install_zeronet_forum" $COMPLETION_FILE; then
  300. return
  301. fi
  302. if [ ! -f /home/$MY_USERNAME/README ]; then
  303. touch /home/$MY_USERNAME/README
  304. fi
  305. if grep -q "ZeroNet Forum address" /home/$MY_USERNAME/README; then
  306. return
  307. fi
  308. if [ ! -d /etc/avahi ]; then
  309. echo $'Avahi is not installed'
  310. exit 736
  311. fi
  312. ZERONET_DEFAULT_FORUM_TITLE=$"${MY_USERNAME}'s Forum"
  313. cd $MESH_INSTALL_DIR/zeronet
  314. python zeronet.py --batch siteCreate 2> $MESH_INSTALL_DIR/zeronet/forum.txt
  315. if [ ! -f $MESH_INSTALL_DIR/zeronet/forum.txt ]; then
  316. echo $'Unable to create forum'
  317. exit 479
  318. fi
  319. forum_address=$(cat forum.txt | grep "Site address" | awk -F ':' '{print $2}')
  320. forum_private_key=$(cat forum.txt | grep "Site private key" | awk -F ':' '{print $2}')
  321. ZERONET_FORUM_ADDRESS=${forum_address//[[:blank:]]/}
  322. ZERONET_FORUM_PRIVATE_KEY=${forum_private_key//[[:blank:]]/}
  323. if [ ${#ZERONET_FORUM_ADDRESS} -lt 20 ]; then
  324. echo $"Address: $ZERONET_FORUM_ADDRESS"
  325. echo $"Public key: $ZERONET_FORUM_PRIVATE_KEY"
  326. echo $'Unable to create zeronet forum address'
  327. exit 76352
  328. fi
  329. if [ ${#ZERONET_FORUM_PRIVATE_KEY} -lt 20 ]; then
  330. echo $"Address: $ZERONET_FORUM_ADDRESS"
  331. echo $"Public key: $ZERONET_FORUM_PRIVATE_KEY"
  332. echo $'Unable to create zeronet forum private key'
  333. exit 87356
  334. fi
  335. if [ ! -d "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS" ]; then
  336. echo $"Unable to find site directory: $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS"
  337. exit 7638
  338. fi
  339. function_check git_clone
  340. git_clone $ZERONET_FORUM_REPO ZeroTalk
  341. if [ ! -d $MESH_INSTALL_DIR/zeronet/ZeroTalk ]; then
  342. echo $'ZeroTalk repo could not be cloned'
  343. exit 6739
  344. fi
  345. git checkout $ZERONET_FORUM_COMMIT -b $ZERONET_FORUM_COMMIT
  346. if ! grep -q "ZeroNet Forum commit" $COMPLETION_FILE; then
  347. echo "ZeroNet Forum commit:$ZERONET_FORUM_COMMIT" >> $COMPLETION_FILE
  348. else
  349. sed -i "s/ZeroNet Forum commit.*/ZeroNet Forum commit:$ZERONET_FORUM_COMMIT/g" $COMPLETION_FILE
  350. fi
  351. echo $"Forum address: $ZERONET_FORUM_ADDRESS"
  352. echo $"Forum private key: $ZERONET_FORUM_PRIVATE_KEY"
  353. cp -r $MESH_INSTALL_DIR/zeronet/ZeroTalk/* $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS
  354. sed -i "s/ZeroBoard/$ZERONET_DEFAULT_FORUM_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/index.html
  355. sed -i "s/ZeroTalk/$ZERONET_DEFAULT_FORUM_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/index.html
  356. sed -i "s|Demo for dynamic, decentralized content publishing.|$ZERONET_DEFAULT_FORUM_TAGLINE|g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/index.html
  357. sed -i 's/Messaging Board Demo/Messaging Board/g' $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/content.json
  358. sed -i "s/ZeroBoard/$ZERONET_DEFAULT_FORUM_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/content.json
  359. python zeronet.py siteSign $ZERONET_FORUM_ADDRESS $ZERONET_FORUM_PRIVATE_KEY --inner_path data/users/content.json
  360. # Add an avahi service
  361. function_check create_avahi_service
  362. create_avahi_service zeronet-forum "zeronet-forum" udp $ZERONET_PORT "$ZERONET_URL/$ZERONET_FORUM_ADDRESS"
  363. sudo cp /tmp/zeronet-forum.service /etc/avahi/services/zeronet-forum.service
  364. if [ ! -d /home/$MY_USERNAME/.config/zeronet ]; then
  365. mkdir -p /home/$MY_USERNAME/.config/zeronet
  366. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
  367. fi
  368. echo "$ZERONET_URL/$ZERONET_FORUM_ADDRESS" > /home/$MY_USERNAME/.config/zeronet/myforum
  369. if ! grep -q $"ZeroNet Forum address" /home/$MY_USERNAME/README; then
  370. echo '' >> /home/$MY_USERNAME/README
  371. echo $"ZeroNet Forum address: $ZERONET_FORUM_ADDRESS" >> /home/$MY_USERNAME/README
  372. echo $"ZeroNet Forum private key: $ZERONET_FORUM_PRIVATE_KEY" >> /home/$MY_USERNAME/README
  373. fi
  374. echo 'install_zeronet_forum' >> $COMPLETION_FILE
  375. }
  376. function install_zeronet {
  377. if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
  378. return
  379. fi
  380. # update to the next commit
  381. function_check set_repo_commit
  382. set_repo_commit $MESH_INSTALL_DIR/zeronet "ZeroNet commit" "$ZERONET_COMMIT" $ZERONET_REPO
  383. if grep -Fxq "install_zeronet" $COMPLETION_FILE; then
  384. return
  385. fi
  386. ${PROJECT_NAME}-mesh-install -f zeronet
  387. systemctl daemon-reload
  388. systemctl start tracker.service
  389. systemctl start zeronet.service
  390. function_check configure_firewall_for_zeronet
  391. configure_firewall_for_zeronet
  392. echo 'install_zeronet' >> $COMPLETION_FILE
  393. }
  394. # NOTE: deliberately no exit 0