freedombone-app-tox 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 tox_avahi {
  46. if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
  47. return
  48. fi
  49. if grep -Fxq "tox_avahi" $COMPLETION_FILE; then
  50. return
  51. fi
  52. if [ ! -d /etc/avahi ]; then
  53. echo $'tox_avahi: avahi is not installed'
  54. exit 87359
  55. fi
  56. # install a command to obtain the Tox ID
  57. cd $INSTALL_DIR
  58. function_check git_clone
  59. git_clone $TOXID_REPO $INSTALL_DIR/toxid
  60. if [ ! -d $INSTALL_DIR/toxid ]; then
  61. exit 63921
  62. fi
  63. cd $INSTALL_DIR/toxid
  64. make
  65. if [ ! "$?" = "0" ]; then
  66. exit 58432
  67. fi
  68. make install
  69. toxavahi
  70. # publish regularly
  71. function_check cron_add_mins
  72. cron_add_mins 1 'toxavahi > /dev/null'
  73. systemctl restart avahi-daemon
  74. echo 'tox_avahi' >> $COMPLETION_FILE
  75. }
  76. function install_tox_node {
  77. 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
  78. return
  79. fi
  80. # update to the next commit
  81. function_check set_repo_commit
  82. set_repo_commit $INSTALL_DIR/toxcore "toxcore commit" "$TOXCORE_COMMIT" $TOXCORE_REPO
  83. if grep -Fxq "install_tox_node" $COMPLETION_FILE; then
  84. return
  85. fi
  86. ${PROJECT_NAME}-mesh-install -f tox_node
  87. if [ ! "$?" = "0" ]; then
  88. echo $'Failed to install tox node'
  89. exit 26778
  90. fi
  91. TOX_ONION_HOSTNAME=$(add_onion_service tox ${TOX_PORT} ${TOX_PORT})
  92. if ! grep -q "tox onion domain" $COMPLETION_FILE; then
  93. echo "tox onion domain:${TOX_ONION_HOSTNAME}" >> $COMPLETION_FILE
  94. else
  95. sed -i "s|tox onion domain.*|tox onion domain:${TOX_ONION_HOSTNAME}|g" $COMPLETION_FILE
  96. fi
  97. systemctl restart tox-bootstrapd.service
  98. TOX_PUBLIC_KEY=$(cat /var/log/syslog | grep tox | grep "Public Key" | awk -F ' ' '{print $8}' | tail -1)
  99. if [ ${#TOX_PUBLIC_KEY} -lt 30 ]; then
  100. echo $'Could not obtain the tox node public key'
  101. exit 6529
  102. fi
  103. # save the public key for later reference
  104. echo "$TOX_PUBLIC_KEY" > $TOX_BOOTSTRAP_ID_FILE
  105. function_check configure_firewall_for_tox
  106. configure_firewall_for_tox
  107. if ! grep -q $"Your Tox node public key is" /home/$MY_USERNAME/README; then
  108. echo '' >> /home/$MY_USERNAME/README
  109. echo '' >> /home/$MY_USERNAME/README
  110. echo 'Tox' >> /home/$MY_USERNAME/README
  111. echo '===' >> /home/$MY_USERNAME/README
  112. echo $"tox onion domain: ${TOX_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
  113. echo $"Your Tox node public key is: $TOX_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  114. echo $'In the Toxic client you can connect to it with:' >> /home/$MY_USERNAME/README
  115. echo " /connect $DEFAULT_DOMAIN_NAME.local $TOX_PORT $TOX_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  116. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
  117. chmod 600 /home/$MY_USERNAME/README
  118. fi
  119. function_check configure_firewall_for_tox
  120. configure_firewall_for_tox
  121. echo 'install_tox_node' >> $COMPLETION_FILE
  122. }
  123. function install_tox_client {
  124. 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
  125. return
  126. fi
  127. # update to the next commit
  128. function_check set_repo_commit
  129. set_repo_commit $INSTALL_DIR/toxic "Toxic commit" "$TOXIC_COMMIT" $TOXIC_REPO
  130. if grep -Fxq "install_tox_client" $COMPLETION_FILE; then
  131. return
  132. fi
  133. ${PROJECT_NAME}-mesh-install -f tox_client
  134. if [ ! "$?" = "0" ]; then
  135. echo $'Could not install Tox client'
  136. exit 67248
  137. fi
  138. # initial setup of username
  139. #su -c "echo 'n
  140. #/nick $MY_USERNAME
  141. #/exit
  142. #' | $TOXIC_FILE -d" - $MY_USERNAME
  143. echo 'install_tox_client' >> $COMPLETION_FILE
  144. }
  145. # NOTE: deliberately no exit 0