freedombone-app-tox 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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 reconfigure_tox {
  47. echo -n ''
  48. }
  49. function upgrade_tox {
  50. if ! grep -Fxq "install_tox" $COMPLETION_FILE; then
  51. return
  52. fi
  53. function_check set_repo_commit
  54. set_repo_commit $INSTALL_DIR/toxcore "toxcore commit" "$TOXCORE_COMMIT" $TOXCORE_REPO
  55. function_check set_repo_commit
  56. set_repo_commit $INSTALL_DIR/toxic "Toxic commit" "$TOXIC_COMMIT" $TOXIC_REPO
  57. }
  58. function backup_local_tox {
  59. if [ -d /var/lib/tox-bootstrapd ]; then
  60. echo $"Backing up Tox"
  61. if [ -d /var/lib/tox-bootstrapd ]; then
  62. cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
  63. if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
  64. rm -rf /var/lib/tox-bootstrapd/Maildir
  65. fi
  66. fi
  67. function_check backup_directory_to_usb
  68. backup_directory_to_usb /var/lib/tox-bootstrapd tox
  69. echo $"Backup of Tox complete"
  70. fi
  71. }
  72. function restore_local_tox {
  73. if [ -d $USB_MOUNT/backup/tox ]; then
  74. echo $"Restoring Tox node settings"
  75. function_check restore_directory_from_usb
  76. restore_directory_from_usb / tox
  77. if [ ! "$?" = "0" ]; then
  78. function_check set_user_permissions
  79. set_user_permissions
  80. function_check backup_unmount_drive
  81. backup_unmount_drive
  82. exit 6393
  83. fi
  84. cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
  85. systemctl restart tox-bootstrapd.service
  86. if [ ! "$?" = "0" ]; then
  87. systemctl status tox-bootstrapd.service
  88. function_check set_user_permissions
  89. set_user_permissions
  90. function_check backup_unmount_drive
  91. backup_unmount_drive
  92. exit 59369
  93. fi
  94. fi
  95. }
  96. function backup_remote_tox {
  97. echo -n ''
  98. }
  99. function restore_remote_tox {
  100. echo -n ''
  101. }
  102. function remove_tox_node {
  103. if ! grep -Fxq "install_tox_node" $COMPLETION_FILE; then
  104. return
  105. fi
  106. iptables -D INPUT -p tcp --dport $TOX_PORT -j ACCEPT
  107. function_check save_firewall_settings
  108. save_firewall_settings
  109. function_check remove_onion_service
  110. remove_onion_service tox ${TOX_PORT}
  111. ${PROJECT_NAME}-mesh-install -f tox_node --remove yes
  112. if [ ! "$?" = "0" ]; then
  113. echo $'Failed to remove tox node'
  114. exit 763836
  115. fi
  116. sed -i '/install_tox_node/d' $COMPLETION_FILE
  117. sed -i '/configure_firewall_for_tox/d' $COMPLETION_FILE
  118. }
  119. function remove_tox_avahi {
  120. if ! grep -Fxq "tox_avahi" $COMPLETION_FILE; then
  121. return
  122. fi
  123. cd $INSTALL_DIR/toxid
  124. make uninstall
  125. rm -rf $INSTALL_DIR/toxid
  126. sed -i '/toxavahi/d' /etc/crontab
  127. systemctl restart cron
  128. sed -i '/tox_avahi/d' $COMPLETION_FILE
  129. }
  130. function remove_tox_client {
  131. if ! grep -Fxq "install_tox_client" $COMPLETION_FILE; then
  132. return
  133. fi
  134. ${PROJECT_NAME}-mesh-install -f tox_client --remove yes
  135. if [ ! "$?" = "0" ]; then
  136. echo $'Could not remove Tox client'
  137. exit 737253
  138. fi
  139. sed -i '/install_tox_client/d' $COMPLETION_FILE
  140. sed -i '/Tox /d' $COMPLETION_FILE
  141. sed -i '/Toxic /d' $COMPLETION_FILE
  142. }
  143. function remove_tox {
  144. remove_tox_client
  145. remove_tox_avahi
  146. remove_tox_node
  147. }
  148. function configure_firewall_for_tox {
  149. if grep -Fxq "configure_firewall_for_tox" $COMPLETION_FILE; then
  150. return
  151. fi
  152. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  153. # docker does its own firewalling
  154. return
  155. fi
  156. if [[ $ONION_ONLY != "no" ]]; then
  157. return
  158. fi
  159. iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT
  160. function_check save_firewall_settings
  161. save_firewall_settings
  162. OPEN_PORTS+=("Tox $TOX_PORT")
  163. echo 'configure_firewall_for_tox' >> $COMPLETION_FILE
  164. }
  165. function tox_avahi {
  166. if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
  167. return
  168. fi
  169. if grep -Fxq "tox_avahi" $COMPLETION_FILE; then
  170. return
  171. fi
  172. if [ ! -d /etc/avahi ]; then
  173. echo $'tox_avahi: avahi is not installed'
  174. exit 87359
  175. fi
  176. # install a command to obtain the Tox ID
  177. cd $INSTALL_DIR
  178. function_check git_clone
  179. git_clone $TOXID_REPO $INSTALL_DIR/toxid
  180. if [ ! -d $INSTALL_DIR/toxid ]; then
  181. exit 63921
  182. fi
  183. cd $INSTALL_DIR/toxid
  184. make
  185. if [ ! "$?" = "0" ]; then
  186. exit 58432
  187. fi
  188. make install
  189. toxavahi
  190. # publish regularly
  191. function_check cron_add_mins
  192. cron_add_mins 1 'toxavahi > /dev/null'
  193. systemctl restart avahi-daemon
  194. echo 'tox_avahi' >> $COMPLETION_FILE
  195. }
  196. function install_tox_node {
  197. if grep -Fxq "install_tox_node" $COMPLETION_FILE; then
  198. return
  199. fi
  200. ${PROJECT_NAME}-mesh-install -f tox_node
  201. if [ ! "$?" = "0" ]; then
  202. echo $'Failed to install tox node'
  203. exit 26778
  204. fi
  205. TOX_ONION_HOSTNAME=$(add_onion_service tox ${TOX_PORT} ${TOX_PORT})
  206. if ! grep -q "tox onion domain" $COMPLETION_FILE; then
  207. echo "tox onion domain:${TOX_ONION_HOSTNAME}" >> $COMPLETION_FILE
  208. else
  209. sed -i "s|tox onion domain.*|tox onion domain:${TOX_ONION_HOSTNAME}|g" $COMPLETION_FILE
  210. fi
  211. systemctl restart tox-bootstrapd.service
  212. TOX_PUBLIC_KEY=$(cat /var/log/syslog | grep tox | grep "Public Key" | awk -F ' ' '{print $8}' | tail -1)
  213. if [ ${#TOX_PUBLIC_KEY} -lt 30 ]; then
  214. echo $'Could not obtain the tox node public key'
  215. exit 6529
  216. fi
  217. # save the public key for later reference
  218. echo "$TOX_PUBLIC_KEY" > $TOX_BOOTSTRAP_ID_FILE
  219. function_check configure_firewall_for_tox
  220. configure_firewall_for_tox
  221. if ! grep -q $"Your Tox node public key is" /home/$MY_USERNAME/README; then
  222. echo '' >> /home/$MY_USERNAME/README
  223. echo '' >> /home/$MY_USERNAME/README
  224. echo 'Tox' >> /home/$MY_USERNAME/README
  225. echo '===' >> /home/$MY_USERNAME/README
  226. echo $"tox onion domain: ${TOX_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
  227. echo $"Your Tox node public key is: $TOX_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  228. echo $'In the Toxic client you can connect to it with:' >> /home/$MY_USERNAME/README
  229. echo " /connect $DEFAULT_DOMAIN_NAME.local $TOX_PORT $TOX_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  230. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
  231. chmod 600 /home/$MY_USERNAME/README
  232. fi
  233. function_check configure_firewall_for_tox
  234. configure_firewall_for_tox
  235. echo 'install_tox_node' >> $COMPLETION_FILE
  236. }
  237. function install_tox_client {
  238. if grep -Fxq "install_tox_client" $COMPLETION_FILE; then
  239. return
  240. fi
  241. ${PROJECT_NAME}-mesh-install -f tox_client
  242. if [ ! "$?" = "0" ]; then
  243. echo $'Could not install Tox client'
  244. exit 67248
  245. fi
  246. # initial setup of username
  247. #su -c "echo 'n
  248. #/nick $MY_USERNAME
  249. #/exit
  250. #' | $TOXIC_FILE -d" - $MY_USERNAME
  251. echo 'install_tox_client' >> $COMPLETION_FILE
  252. }
  253. function install_tox {
  254. if grep -Fxq "install_tox" $COMPLETION_FILE; then
  255. return
  256. fi
  257. configure_firewall_for_tox
  258. install_tox_node
  259. tox_avahi
  260. install_tox_client
  261. echo 'install_tox' >> $COMPLETION_FILE
  262. }
  263. # NOTE: deliberately no exit 0