freedombone-app-tox 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  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. if [ -d $SERVER_DIRECTORY/backup/tox ]; then
  109. echo $"Restoring Tox node settings"
  110. function_check restore_directory_from_friend
  111. restore_directory_from_friend / tox
  112. if [ ! "$?" = "0" ]; then
  113. exit 93653
  114. fi
  115. cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
  116. systemctl restart tox-bootstrapd.service
  117. if [ ! "$?" = "0" ]; then
  118. systemctl status tox-bootstrapd.service
  119. exit 59369
  120. fi
  121. echo $"Restore of Tox node complete"
  122. fi
  123. }
  124. function remove_tox_node {
  125. if ! grep -Fxq "install_tox_node" $COMPLETION_FILE; then
  126. return
  127. fi
  128. iptables -D INPUT -p tcp --dport $TOX_PORT -j ACCEPT
  129. function_check save_firewall_settings
  130. save_firewall_settings
  131. function_check remove_onion_service
  132. remove_onion_service tox ${TOX_PORT}
  133. ${PROJECT_NAME}-mesh-install -f tox_node --remove yes
  134. if [ ! "$?" = "0" ]; then
  135. echo $'Failed to remove tox node'
  136. exit 763836
  137. fi
  138. sed -i '/install_tox_node/d' $COMPLETION_FILE
  139. sed -i '/configure_firewall_for_tox/d' $COMPLETION_FILE
  140. }
  141. function remove_tox_avahi {
  142. if ! grep -Fxq "tox_avahi" $COMPLETION_FILE; then
  143. return
  144. fi
  145. cd $INSTALL_DIR/toxid
  146. make uninstall
  147. rm -rf $INSTALL_DIR/toxid
  148. sed -i '/toxavahi/d' /etc/crontab
  149. systemctl restart cron
  150. sed -i '/tox_avahi/d' $COMPLETION_FILE
  151. }
  152. function remove_tox_client {
  153. if ! grep -Fxq "install_tox_client" $COMPLETION_FILE; then
  154. return
  155. fi
  156. ${PROJECT_NAME}-mesh-install -f tox_client --remove yes
  157. if [ ! "$?" = "0" ]; then
  158. echo $'Could not remove Tox client'
  159. exit 737253
  160. fi
  161. sed -i '/install_tox_client/d' $COMPLETION_FILE
  162. sed -i '/Tox /d' $COMPLETION_FILE
  163. sed -i '/Toxic /d' $COMPLETION_FILE
  164. }
  165. function remove_tox {
  166. remove_tox_client
  167. remove_tox_avahi
  168. remove_tox_node
  169. }
  170. function configure_firewall_for_tox {
  171. if [ -f $COMPLETION_FILE ]; then
  172. if grep -Fxq "configure_firewall_for_tox" $COMPLETION_FILE; then
  173. return
  174. fi
  175. fi
  176. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  177. # docker does its own firewalling
  178. return
  179. fi
  180. if [[ $ONION_ONLY != "no" ]]; then
  181. return
  182. fi
  183. iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT
  184. function_check save_firewall_settings
  185. save_firewall_settings
  186. OPEN_PORTS+=("Tox $TOX_PORT")
  187. if [ -f $COMPLETION_FILE ]; then
  188. echo 'configure_firewall_for_tox' >> $COMPLETION_FILE
  189. fi
  190. }
  191. function tox_avahi {
  192. if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
  193. return
  194. fi
  195. if grep -Fxq "tox_avahi" $COMPLETION_FILE; then
  196. return
  197. fi
  198. if [ ! -d /etc/avahi ]; then
  199. echo $'tox_avahi: avahi is not installed'
  200. exit 87359
  201. fi
  202. # install a command to obtain the Tox ID
  203. cd $INSTALL_DIR
  204. function_check git_clone
  205. git_clone $TOXID_REPO $INSTALL_DIR/toxid
  206. if [ ! -d $INSTALL_DIR/toxid ]; then
  207. exit 63921
  208. fi
  209. cd $INSTALL_DIR/toxid
  210. make
  211. if [ ! "$?" = "0" ]; then
  212. exit 58432
  213. fi
  214. make install
  215. toxavahi
  216. # publish regularly
  217. function_check cron_add_mins
  218. cron_add_mins 1 'toxavahi > /dev/null'
  219. systemctl restart avahi-daemon
  220. echo 'tox_avahi' >> $COMPLETION_FILE
  221. }
  222. function install_tox_node {
  223. if grep -Fxq "install_tox_node" $COMPLETION_FILE; then
  224. return
  225. fi
  226. ${PROJECT_NAME}-mesh-install -f tox_node
  227. if [ ! "$?" = "0" ]; then
  228. echo $'Failed to install tox node'
  229. exit 26778
  230. fi
  231. TOX_ONION_HOSTNAME=$(add_onion_service tox ${TOX_PORT} ${TOX_PORT})
  232. if ! grep -q "tox onion domain" $COMPLETION_FILE; then
  233. echo "tox onion domain:${TOX_ONION_HOSTNAME}" >> $COMPLETION_FILE
  234. else
  235. sed -i "s|tox onion domain.*|tox onion domain:${TOX_ONION_HOSTNAME}|g" $COMPLETION_FILE
  236. fi
  237. systemctl restart tox-bootstrapd.service
  238. TOX_PUBLIC_KEY=$(cat /var/log/syslog | grep tox | grep "Public Key" | awk -F ' ' '{print $8}' | tail -1)
  239. if [ ${#TOX_PUBLIC_KEY} -lt 30 ]; then
  240. echo $'Could not obtain the tox node public key'
  241. exit 6529
  242. fi
  243. # save the public key for later reference
  244. echo "$TOX_PUBLIC_KEY" > $TOX_BOOTSTRAP_ID_FILE
  245. function_check configure_firewall_for_tox
  246. configure_firewall_for_tox
  247. if ! grep -q $"Your Tox node public key is" /home/$MY_USERNAME/README; then
  248. echo '' >> /home/$MY_USERNAME/README
  249. echo '' >> /home/$MY_USERNAME/README
  250. echo 'Tox' >> /home/$MY_USERNAME/README
  251. echo '===' >> /home/$MY_USERNAME/README
  252. echo $"tox onion domain: ${TOX_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
  253. echo $"Your Tox node public key is: $TOX_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  254. echo $'In the Toxic client you can connect to it with:' >> /home/$MY_USERNAME/README
  255. echo " /connect $DEFAULT_DOMAIN_NAME.local $TOX_PORT $TOX_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  256. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
  257. chmod 600 /home/$MY_USERNAME/README
  258. fi
  259. function_check configure_firewall_for_tox
  260. configure_firewall_for_tox
  261. echo 'install_tox_node' >> $COMPLETION_FILE
  262. }
  263. function install_tox_client {
  264. if grep -Fxq "install_tox_client" $COMPLETION_FILE; then
  265. return
  266. fi
  267. ${PROJECT_NAME}-mesh-install -f tox_client
  268. if [ ! "$?" = "0" ]; then
  269. echo $'Could not install Tox client'
  270. exit 67248
  271. fi
  272. # initial setup of username
  273. #su -c "echo 'n
  274. #/nick $MY_USERNAME
  275. #/exit
  276. #' | $TOXIC_FILE -d" - $MY_USERNAME
  277. echo 'install_tox_client' >> $COMPLETION_FILE
  278. }
  279. function mesh_tox_node {
  280. # obtain commits from the main file
  281. TOXCORE_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXCORE_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  282. if [ ${#TOXCORE_COMMIT_MAIN} -gt 10 ]; then
  283. TOXCORE_COMMIT=$TOXCORE_COMMIT_MAIN
  284. fi
  285. if [ ! $TOXCORE_COMMIT ]; then
  286. echo $'No Tox commit was specified'
  287. exit 76325
  288. fi
  289. TOX_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}')
  290. if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
  291. TOX_PORT=$TOX_PORT_MAIN
  292. fi
  293. if [ ! $TOX_PORT ]; then
  294. echo $'No Tox port was specified'
  295. exit 32856
  296. fi
  297. TOXCORE_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXCORE_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  298. if [ ${#TOXCORE_REPO_MAIN} -gt 10 ]; then
  299. TOXCORE_REPO=$TOXCORE_REPO_MAIN
  300. fi
  301. if [ ! $TOXCORE_REPO ]; then
  302. echo $'No Tox repo was specified'
  303. exit 16865
  304. fi
  305. chroot "$rootdir" apt-get -y install build-essential libtool autotools-dev
  306. chroot "$rootdir" apt-get -y install automake checkinstall check git yasm
  307. chroot "$rootdir" apt-get -y install libsodium13 libsodium-dev libcap2-bin
  308. chroot "$rootdir" apt-get -y install libconfig9 libconfig-dev
  309. TEMP_SCRIPT_NAME=fbtmp37272.sh
  310. TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
  311. echo '#!/bin/bash' > $TEMP_SCRIPT
  312. echo "mkdir -p $INSTALL_DIR" >> $TEMP_SCRIPT
  313. echo "git clone $TOXCORE_REPO $INSTALL_DIR/toxcore" >> $TEMP_SCRIPT
  314. echo "cd $INSTALL_DIR/toxcore" >> $TEMP_SCRIPT
  315. echo "git checkout $TOXCORE_COMMIT -b $TOXCORE_COMMIT" >> $TEMP_SCRIPT
  316. echo 'autoreconf -i' >> $TEMP_SCRIPT
  317. echo './configure --enable-daemon --disable-av' >> $TEMP_SCRIPT
  318. echo 'make' >> $TEMP_SCRIPT
  319. echo 'if [ ! "$?" = "0" ]; then' >> $TEMP_SCRIPT
  320. echo ' exit 1' >> $TEMP_SCRIPT
  321. echo 'fi' >> $TEMP_SCRIPT
  322. echo 'make install' >> $TEMP_SCRIPT
  323. echo 'cp /usr/local/lib/libtoxcore* /usr/lib/' >> $TEMP_SCRIPT
  324. echo "cp $INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.service /etc/systemd/system/" >> $TEMP_SCRIPT
  325. echo "sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' /etc/systemd/system/tox-bootstrapd.service" >> $TEMP_SCRIPT
  326. echo 'systemctl enable tox-bootstrapd.service' >> $TEMP_SCRIPT
  327. echo 'exit 0' >> $TEMP_SCRIPT
  328. chmod +x $TEMP_SCRIPT
  329. cp $TEMP_SCRIPT $rootdir/root/
  330. SECONDS=0
  331. chroot "$rootdir" /root/$TEMP_SCRIPT_NAME
  332. if [ ! "$?" = "0" ]; then
  333. duration=$SECONDS
  334. echo $"Toxcore compile failed at $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  335. echo $'Unable to make toxcore'
  336. rm $TEMP_SCRIPT
  337. exit 73835
  338. fi
  339. duration=$SECONDS
  340. echo $"Toxcore compile $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  341. rm $TEMP_SCRIPT
  342. if [ ! -f $rootdir/usr/local/bin/tox-bootstrapd ]; then
  343. echo $"File not found /usr/local/bin/tox-bootstrapd"
  344. exit 37825
  345. fi
  346. chroot "$rootdir" useradd --home-dir /var/lib/tox-bootstrapd --create-home --system --shell /sbin/nologin --comment $"Account to run Tox's DHT bootstrap daemon" --user-group tox-bootstrapd
  347. chroot "$rootdir" chmod 700 /var/lib/tox-bootstrapd
  348. # remove Maildir
  349. if [ -d $rootdir/var/lib/tox-bootstrapd/Maildir ]; then
  350. rm -rf $rootdir/var/lib/tox-bootstrapd/Maildir
  351. fi
  352. # create configuration file
  353. TOX_BOOTSTRAP_CONFIG=$rootdir/etc/tox-bootstrapd.conf
  354. echo "port = $TOX_PORT" > $TOX_BOOTSTRAP_CONFIG
  355. echo 'keys_file_path = "/var/lib/tox-bootstrapd/keys"' >> $TOX_BOOTSTRAP_CONFIG
  356. echo 'pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"' >> $TOX_BOOTSTRAP_CONFIG
  357. echo 'enable_ipv6 = true' >> $TOX_BOOTSTRAP_CONFIG
  358. echo 'enable_ipv4_fallback = true' >> $TOX_BOOTSTRAP_CONFIG
  359. echo 'enable_lan_discovery = true' >> $TOX_BOOTSTRAP_CONFIG
  360. echo 'enable_tcp_relay = true' >> $TOX_BOOTSTRAP_CONFIG
  361. echo "tcp_relay_ports = [443, 3389, $TOX_PORT]" >> $TOX_BOOTSTRAP_CONFIG
  362. echo 'enable_motd = true' >> $TOX_BOOTSTRAP_CONFIG
  363. echo 'motd = "tox-bootstrapd"' >> $TOX_BOOTSTRAP_CONFIG
  364. if [ $TOX_NODES ]; then
  365. echo 'bootstrap_nodes = (' >> $TOX_BOOTSTRAP_CONFIG
  366. toxcount=0
  367. while [ "x${TOX_NODES[toxcount]}" != "x" ]
  368. do
  369. toxval_ipv4=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $1}')
  370. toxval_ipv6=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $2}')
  371. toxval_port=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $3}')
  372. toxval_pubkey=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $4}')
  373. toxval_maintainer=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $5}')
  374. echo "{ // $toxval_maintainer" >> $TOX_BOOTSTRAP_CONFIG
  375. if [[ $toxval_ipv6 != 'NONE' ]]; then
  376. echo " address = \"$toxval_ipv6\"" >> $TOX_BOOTSTRAP_CONFIG
  377. else
  378. echo " address = \"$toxval_ipv4\"" >> $TOX_BOOTSTRAP_CONFIG
  379. fi
  380. echo " port = $toxval_port" >> $TOX_BOOTSTRAP_CONFIG
  381. echo " public_key = \"$toxval_pubkey\"" >> $TOX_BOOTSTRAP_CONFIG
  382. toxcount=$(( $toxcount + 1 ))
  383. if [ "x${TOX_NODES[toxcount]}" != "x" ]; then
  384. echo "}," >> $TOX_BOOTSTRAP_CONFIG
  385. else
  386. echo "}" >> $TOX_BOOTSTRAP_CONFIG
  387. fi
  388. done
  389. echo ')' >> $TOX_BOOTSTRAP_CONFIG
  390. fi
  391. }
  392. function mesh_tox_avahi {
  393. if [ ! -d $rootdir/etc/avahi ]; then
  394. echo $'tox_avahi: avahi is not installed'
  395. exit 87359
  396. fi
  397. TOXID_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXID_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  398. if [ ${#TOXID_REPO_MAIN} -gt 5 ]; then
  399. TOXID_REPO=$TOXID_REPO_MAIN
  400. fi
  401. if [ ! $TOXID_REPO ]; then
  402. echo $'No ToxID repo was specified'
  403. exit 78252
  404. fi
  405. TEMP_SCRIPT_NAME=fbtmp5328252.sh
  406. TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
  407. echo '#!/bin/bash' > $TEMP_SCRIPT
  408. echo "mkdir -p $INSTALL_DIR" >> $TEMP_SCRIPT
  409. echo "git clone $TOXID_REPO $INSTALL_DIR/toxid" >> $TEMP_SCRIPT
  410. echo "if [ ! -d $INSTALL_DIR/toxid ]; then" >> $TEMP_SCRIPT
  411. echo ' exit 1' >> $TEMP_SCRIPT
  412. echo 'fi' >> $TEMP_SCRIPT
  413. echo "cd $INSTALL_DIR/toxid" >> $TEMP_SCRIPT
  414. echo "make" >> $TEMP_SCRIPT
  415. echo 'if [ ! "$?" = "0" ]; then' >> $TEMP_SCRIPT
  416. echo ' exit 2' >> $TEMP_SCRIPT
  417. echo 'fi' >> $TEMP_SCRIPT
  418. echo 'make install' >> $TEMP_SCRIPT
  419. echo 'if [ ! -f /usr/local/bin/toxavahi ]; then' >> $TEMP_SCRIPT
  420. echo ' exit 3' >> $TEMP_SCRIPT
  421. echo 'fi' >> $TEMP_SCRIPT
  422. echo 'toxavahi' >> $TEMP_SCRIPT
  423. echo 'echo "* * * * * root /usr/local/bin/toxavahi > /dev/null" >> /etc/crontab' >> $TEMP_SCRIPT
  424. echo 'systemctl restart avahi-daemon' >> $TEMP_SCRIPT
  425. echo 'exit 0' >> $TEMP_SCRIPT
  426. chmod +x $TEMP_SCRIPT
  427. cp $TEMP_SCRIPT $rootdir/root/
  428. chroot "$rootdir" /root/$TEMP_SCRIPT_NAME
  429. if [ ! "$?" = "0" ]; then
  430. echo $"Unable to install toxid, returned $?"
  431. rm $TEMP_SCRIPT
  432. exit 62835
  433. fi
  434. rm $TEMP_SCRIPT
  435. }
  436. function mesh_tox_client {
  437. TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  438. # obtain commits from the main file
  439. TOXIC_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  440. if [ ${#TOXIC_COMMIT_MAIN} -gt 10 ]; then
  441. TOXIC_COMMIT=$TOXIC_COMMIT_MAIN
  442. fi
  443. TOXIC_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  444. if [ ${#TOXIC_REPO_MAIN} -gt 5 ]; then
  445. TOXIC_REPO=$TOXIC_REPO_MAIN
  446. fi
  447. chroot "$rootdir" apt-get -y install libncursesw5-dev libconfig-dev libqrencode-dev
  448. chroot "$rootdir" apt-get -y install libcurl4-openssl-dev libvpx-dev libopenal-dev
  449. TEMP_SCRIPT_NAME=fbtmp728353.sh
  450. TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
  451. echo '#!/bin/bash' > $TEMP_SCRIPT
  452. echo "mkdir -p $INSTALL_DIR" >> $TEMP_SCRIPT
  453. echo "git clone $TOXIC_REPO $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
  454. echo "cd $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
  455. echo "git checkout $TOXIC_COMMIT -b $TOXIC_COMMIT" >> $TEMP_SCRIPT
  456. echo 'make' >> $TEMP_SCRIPT
  457. echo 'if [ ! "$?" = "0" ]; then' >> $TEMP_SCRIPT
  458. echo ' exit 1' >> $TEMP_SCRIPT
  459. echo 'fi' >> $TEMP_SCRIPT
  460. echo 'make install' >> $TEMP_SCRIPT
  461. echo 'exit 0' >> $TEMP_SCRIPT
  462. chmod +x $TEMP_SCRIPT
  463. cp $TEMP_SCRIPT $rootdir/root/
  464. TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  465. SECONDS=0
  466. chroot "$rootdir" /root/$TEMP_SCRIPT_NAME
  467. if [ ! "$?" = "0" ]; then
  468. duration=$SECONDS
  469. echo $"Toxic client compile failed at $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  470. echo $'Unable to make tox client'
  471. rm $TEMP_SCRIPT
  472. exit 74872
  473. fi
  474. rm $TEMP_SCRIPT
  475. if [ ! -f $rootdir$TOXIC_FILE ]; then
  476. echo $"Tox client was not installed to $TOXIC_FILE"
  477. exit 63278
  478. fi
  479. duration=$SECONDS
  480. echo $"Toxic client compile $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  481. }
  482. function enable_tox_repo {
  483. echo 'deb http://download.opensuse.org/repositories/home:/antonbatenev:/tox/Debian_8.0/ /' > $rootdir/etc/apt/sources.list.d/tox.list
  484. chroot "$rootdir" wget -q http://download.opensuse.org/repositories/home:antonbatenev:tox/Debian_8.0/Release.key -O- | apt-key add -
  485. chroot "$rootdir" apt-get update
  486. echo "Tox Repository Installed."
  487. }
  488. function install_tox {
  489. if grep -Fxq "install_tox" $COMPLETION_FILE; then
  490. return
  491. fi
  492. configure_firewall_for_tox
  493. if [ $INSTALLING_MESH ]; then
  494. mesh_tox_node
  495. mesh_tox_avahi
  496. mesh_tox_client
  497. else
  498. install_tox_node
  499. tox_avahi
  500. install_tox_client
  501. fi
  502. echo 'install_tox' >> $COMPLETION_FILE
  503. }
  504. # NOTE: deliberately no exit 0