freedombone-app-tox 8.0KB

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