freedombone-app-tox 8.4KB

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