freedombone-app-tox 17KB

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