freedombone-app-tox 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. TOX_PORT=33445
  31. TOXCORE_REPO="git://github.com/irungentoo/toxcore.git"
  32. TOXCORE_COMMIT='532629d486e3361c7d8d95b38293cc7d61dc4ee5'
  33. TOXID_REPO="https://github.com/bashrc/toxid"
  34. TOX_BOOTSTRAP_ID_FILE=/var/lib/tox-bootstrapd/pubkey.txt
  35. # These are some default nodes, but you can replace them with trusted nodes
  36. # as you prefer. See https://wiki.tox.im/Nodes
  37. TOX_NODES=
  38. #TOX_NODES=(
  39. # '192.254.75.102,2607:5600:284::2,33445,951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F,Tox RELENG,US'
  40. # '144.76.60.215,2a01:4f8:191:64d6::1,33445,04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F,sonOfRa,DE'
  41. #)
  42. TOXIC_REPO="https://github.com/Tox/toxic"
  43. TOXIC_COMMIT='cf16849b374e484a33a4dffa3dfb937b59d537f2'
  44. TOXIC_FILE=/usr/local/bin/toxic
  45. function configure_firewall_for_tox {
  46. if grep -Fxq "configure_firewall_for_tox" $COMPLETION_FILE; then
  47. return
  48. fi
  49. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  50. # docker does its own firewalling
  51. return
  52. fi
  53. if [[ $ONION_ONLY != "no" ]]; then
  54. return
  55. fi
  56. iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT
  57. function_check save_firewall_settings
  58. save_firewall_settings
  59. OPEN_PORTS+=("Tox $TOX_PORT")
  60. echo 'configure_firewall_for_tox' >> $COMPLETION_FILE
  61. }
  62. function tox_avahi {
  63. if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
  64. return
  65. fi
  66. if grep -Fxq "tox_avahi" $COMPLETION_FILE; then
  67. return
  68. fi
  69. if [ ! -d /etc/avahi ]; then
  70. echo $'tox_avahi: avahi is not installed'
  71. exit 87359
  72. fi
  73. # install a command to obtain the Tox ID
  74. cd $INSTALL_DIR
  75. function_check git_clone
  76. git_clone $TOXID_REPO $INSTALL_DIR/toxid
  77. if [ ! -d $INSTALL_DIR/toxid ]; then
  78. exit 63921
  79. fi
  80. cd $INSTALL_DIR/toxid
  81. make
  82. if [ ! "$?" = "0" ]; then
  83. exit 58432
  84. fi
  85. make install
  86. toxavahi
  87. # publish regularly
  88. function_check cron_add_mins
  89. cron_add_mins 1 'toxavahi > /dev/null'
  90. systemctl restart avahi-daemon
  91. echo 'tox_avahi' >> $COMPLETION_FILE
  92. }
  93. function install_tox_node {
  94. if [[ $SYSTEM_TYPE == "$VARIANT_WRITER" || $SYSTEM_TYPE == "$VARIANT_MAILBOX" || $SYSTEM_TYPE == "$VARIANT_CLOUD" || $SYSTEM_TYPE == "$VARIANT_SOCIAL" || $SYSTEM_TYPE == "$VARIANT_MEDIA" || $SYSTEM_TYPE == "$VARIANT_DEVELOPER" ]]; then
  95. return
  96. fi
  97. # update to the next commit
  98. function_check set_repo_commit
  99. set_repo_commit $INSTALL_DIR/toxcore "toxcore commit" "$TOXCORE_COMMIT" $TOXCORE_REPO
  100. if grep -Fxq "install_tox_node" $COMPLETION_FILE; then
  101. return
  102. fi
  103. ${PROJECT_NAME}-mesh-install -f tox_node
  104. if [ ! "$?" = "0" ]; then
  105. echo $'Failed to install tox node'
  106. exit 26778
  107. fi
  108. TOX_ONION_HOSTNAME=$(add_onion_service tox ${TOX_PORT} ${TOX_PORT})
  109. if ! grep -q "tox onion domain" $COMPLETION_FILE; then
  110. echo "tox onion domain:${TOX_ONION_HOSTNAME}" >> $COMPLETION_FILE
  111. else
  112. sed -i "s|tox onion domain.*|tox onion domain:${TOX_ONION_HOSTNAME}|g" $COMPLETION_FILE
  113. fi
  114. systemctl restart tox-bootstrapd.service
  115. TOX_PUBLIC_KEY=$(cat /var/log/syslog | grep tox | grep "Public Key" | awk -F ' ' '{print $8}' | tail -1)
  116. if [ ${#TOX_PUBLIC_KEY} -lt 30 ]; then
  117. echo $'Could not obtain the tox node public key'
  118. exit 6529
  119. fi
  120. # save the public key for later reference
  121. echo "$TOX_PUBLIC_KEY" > $TOX_BOOTSTRAP_ID_FILE
  122. function_check configure_firewall_for_tox
  123. configure_firewall_for_tox
  124. if ! grep -q $"Your Tox node public key is" /home/$MY_USERNAME/README; then
  125. echo '' >> /home/$MY_USERNAME/README
  126. echo '' >> /home/$MY_USERNAME/README
  127. echo 'Tox' >> /home/$MY_USERNAME/README
  128. echo '===' >> /home/$MY_USERNAME/README
  129. echo $"tox onion domain: ${TOX_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
  130. echo $"Your Tox node public key is: $TOX_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  131. echo $'In the Toxic client you can connect to it with:' >> /home/$MY_USERNAME/README
  132. echo " /connect $DEFAULT_DOMAIN_NAME.local $TOX_PORT $TOX_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  133. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
  134. chmod 600 /home/$MY_USERNAME/README
  135. fi
  136. function_check configure_firewall_for_tox
  137. configure_firewall_for_tox
  138. echo 'install_tox_node' >> $COMPLETION_FILE
  139. }
  140. function install_tox_client {
  141. if [[ $SYSTEM_TYPE == "$VARIANT_WRITER" || $SYSTEM_TYPE == "$VARIANT_MAILBOX" || $SYSTEM_TYPE == "$VARIANT_CLOUD" || $SYSTEM_TYPE == "$VARIANT_SOCIAL" || $SYSTEM_TYPE == "$VARIANT_MEDIA" || $SYSTEM_TYPE == "$VARIANT_DEVELOPER" ]]; then
  142. return
  143. fi
  144. # update to the next commit
  145. function_check set_repo_commit
  146. set_repo_commit $INSTALL_DIR/toxic "Toxic commit" "$TOXIC_COMMIT" $TOXIC_REPO
  147. if grep -Fxq "install_tox_client" $COMPLETION_FILE; then
  148. return
  149. fi
  150. ${PROJECT_NAME}-mesh-install -f tox_client
  151. if [ ! "$?" = "0" ]; then
  152. echo $'Could not install Tox client'
  153. exit 67248
  154. fi
  155. # initial setup of username
  156. #su -c "echo 'n
  157. #/nick $MY_USERNAME
  158. #/exit
  159. #' | $TOXIC_FILE -d" - $MY_USERNAME
  160. echo 'install_tox_client' >> $COMPLETION_FILE
  161. }
  162. # NOTE: deliberately no exit 0