freedombone-app-tox 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Tox Application
  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. VARIANTS='full chat'
  31. TOX_PORT=33445
  32. TOXCORE_REPO="git://github.com/irungentoo/toxcore.git"
  33. TOXCORE_COMMIT='532629d486e3361c7d8d95b38293cc7d61dc4ee5'
  34. TOXID_REPO="https://github.com/bashrc/toxid"
  35. TOX_BOOTSTRAP_ID_FILE=/var/lib/tox-bootstrapd/pubkey.txt
  36. # These are some default nodes, but you can replace them with trusted nodes
  37. # as you prefer. See https://wiki.tox.im/Nodes
  38. TOX_NODES=
  39. #TOX_NODES=(
  40. # '192.254.75.102,2607:5600:284::2,33445,951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F,Tox RELENG,US'
  41. # '144.76.60.215,2a01:4f8:191:64d6::1,33445,04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F,sonOfRa,DE'
  42. #)
  43. TOXIC_REPO="https://github.com/Tox/toxic"
  44. TOXIC_COMMIT='cf16849b374e484a33a4dffa3dfb937b59d537f2'
  45. TOXIC_FILE=/usr/local/bin/toxic
  46. function upgrade_tox {
  47. if ! grep -Fxq "install_tox" $COMPLETION_FILE; then
  48. return
  49. fi
  50. function_check set_repo_commit
  51. set_repo_commit $INSTALL_DIR/toxcore "toxcore commit" "$TOXCORE_COMMIT" $TOXCORE_REPO
  52. function_check set_repo_commit
  53. set_repo_commit $INSTALL_DIR/toxic "Toxic commit" "$TOXIC_COMMIT" $TOXIC_REPO
  54. }
  55. function backup_local_tox {
  56. echo ''
  57. }
  58. function backup_remote_tox {
  59. echo ''
  60. }
  61. function remove_tox_node {
  62. if ! grep -Fxq "install_tox_node" $COMPLETION_FILE; then
  63. return
  64. fi
  65. iptables -D INPUT -p tcp --dport $TOX_PORT -j ACCEPT
  66. function_check save_firewall_settings
  67. save_firewall_settings
  68. function_check remove_onion_service
  69. remove_onion_service tox ${TOX_PORT}
  70. ${PROJECT_NAME}-mesh-install -f tox_node --remove yes
  71. if [ ! "$?" = "0" ]; then
  72. echo $'Failed to remove tox node'
  73. exit 763836
  74. fi
  75. sed -i '/install_tox_node/d' $COMPLETION_FILE
  76. sed -i '/configure_firewall_for_tox/d' $COMPLETION_FILE
  77. }
  78. function remove_tox_avahi {
  79. if ! grep -Fxq "tox_avahi" $COMPLETION_FILE; then
  80. return
  81. fi
  82. cd $INSTALL_DIR/toxid
  83. make uninstall
  84. rm -rf $INSTALL_DIR/toxid
  85. sed -i '/toxavahi/d' /etc/crontab
  86. systemctl restart cron
  87. sed -i '/tox_avahi/d' $COMPLETION_FILE
  88. }
  89. function remove_tox_client {
  90. if ! grep -Fxq "install_tox_client" $COMPLETION_FILE; then
  91. return
  92. fi
  93. ${PROJECT_NAME}-mesh-install -f tox_client --remove yes
  94. if [ ! "$?" = "0" ]; then
  95. echo $'Could not remove Tox client'
  96. exit 737253
  97. fi
  98. sed -i '/install_tox_client/d' $COMPLETION_FILE
  99. sed -i '/Tox /d' $COMPLETION_FILE
  100. sed -i '/Toxic /d' $COMPLETION_FILE
  101. }
  102. function remove_tox {
  103. remove_tox_client
  104. remove_tox_avahi
  105. remove_tox_node
  106. }
  107. function configure_firewall_for_tox {
  108. if grep -Fxq "configure_firewall_for_tox" $COMPLETION_FILE; then
  109. return
  110. fi
  111. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  112. # docker does its own firewalling
  113. return
  114. fi
  115. if [[ $ONION_ONLY != "no" ]]; then
  116. return
  117. fi
  118. iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT
  119. function_check save_firewall_settings
  120. save_firewall_settings
  121. OPEN_PORTS+=("Tox $TOX_PORT")
  122. echo 'configure_firewall_for_tox' >> $COMPLETION_FILE
  123. }
  124. function tox_avahi {
  125. if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
  126. return
  127. fi
  128. if grep -Fxq "tox_avahi" $COMPLETION_FILE; then
  129. return
  130. fi
  131. if [ ! -d /etc/avahi ]; then
  132. echo $'tox_avahi: avahi is not installed'
  133. exit 87359
  134. fi
  135. # install a command to obtain the Tox ID
  136. cd $INSTALL_DIR
  137. function_check git_clone
  138. git_clone $TOXID_REPO $INSTALL_DIR/toxid
  139. if [ ! -d $INSTALL_DIR/toxid ]; then
  140. exit 63921
  141. fi
  142. cd $INSTALL_DIR/toxid
  143. make
  144. if [ ! "$?" = "0" ]; then
  145. exit 58432
  146. fi
  147. make install
  148. toxavahi
  149. # publish regularly
  150. function_check cron_add_mins
  151. cron_add_mins 1 'toxavahi > /dev/null'
  152. systemctl restart avahi-daemon
  153. echo 'tox_avahi' >> $COMPLETION_FILE
  154. }
  155. function install_tox_node {
  156. if grep -Fxq "install_tox_node" $COMPLETION_FILE; then
  157. return
  158. fi
  159. ${PROJECT_NAME}-mesh-install -f tox_node
  160. if [ ! "$?" = "0" ]; then
  161. echo $'Failed to install tox node'
  162. exit 26778
  163. fi
  164. TOX_ONION_HOSTNAME=$(add_onion_service tox ${TOX_PORT} ${TOX_PORT})
  165. if ! grep -q "tox onion domain" $COMPLETION_FILE; then
  166. echo "tox onion domain:${TOX_ONION_HOSTNAME}" >> $COMPLETION_FILE
  167. else
  168. sed -i "s|tox onion domain.*|tox onion domain:${TOX_ONION_HOSTNAME}|g" $COMPLETION_FILE
  169. fi
  170. systemctl restart tox-bootstrapd.service
  171. TOX_PUBLIC_KEY=$(cat /var/log/syslog | grep tox | grep "Public Key" | awk -F ' ' '{print $8}' | tail -1)
  172. if [ ${#TOX_PUBLIC_KEY} -lt 30 ]; then
  173. echo $'Could not obtain the tox node public key'
  174. exit 6529
  175. fi
  176. # save the public key for later reference
  177. echo "$TOX_PUBLIC_KEY" > $TOX_BOOTSTRAP_ID_FILE
  178. function_check configure_firewall_for_tox
  179. configure_firewall_for_tox
  180. if ! grep -q $"Your Tox node public key is" /home/$MY_USERNAME/README; then
  181. echo '' >> /home/$MY_USERNAME/README
  182. echo '' >> /home/$MY_USERNAME/README
  183. echo 'Tox' >> /home/$MY_USERNAME/README
  184. echo '===' >> /home/$MY_USERNAME/README
  185. echo $"tox onion domain: ${TOX_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
  186. echo $"Your Tox node public key is: $TOX_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  187. echo $'In the Toxic client you can connect to it with:' >> /home/$MY_USERNAME/README
  188. echo " /connect $DEFAULT_DOMAIN_NAME.local $TOX_PORT $TOX_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  189. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
  190. chmod 600 /home/$MY_USERNAME/README
  191. fi
  192. function_check configure_firewall_for_tox
  193. configure_firewall_for_tox
  194. echo 'install_tox_node' >> $COMPLETION_FILE
  195. }
  196. function install_tox_client {
  197. if grep -Fxq "install_tox_client" $COMPLETION_FILE; then
  198. return
  199. fi
  200. ${PROJECT_NAME}-mesh-install -f tox_client
  201. if [ ! "$?" = "0" ]; then
  202. echo $'Could not install Tox client'
  203. exit 67248
  204. fi
  205. # initial setup of username
  206. #su -c "echo 'n
  207. #/nick $MY_USERNAME
  208. #/exit
  209. #' | $TOXIC_FILE -d" - $MY_USERNAME
  210. echo 'install_tox_client' >> $COMPLETION_FILE
  211. }
  212. function install_tox {
  213. if grep -Fxq "install_tox" $COMPLETION_FILE; then
  214. return
  215. fi
  216. configure_firewall_for_tox
  217. install_tox_node
  218. tox_avahi
  219. install_tox_client
  220. echo 'install_tox' >> $COMPLETION_FILE
  221. }
  222. # NOTE: deliberately no exit 0