freedombone-app-tox 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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="https://github.com/bashrc/toxcore"
  33. TOXCORE_COMMIT='d3fa9f82bda3a8746917502c525237427ba17d45'
  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. QTOX_REPO="https://github.com/bashrc/qTox"
  47. QTOX_COMMIT='27a628a3789fca4f31516c3982e580052dd3c773'
  48. function change_password_tox {
  49. echo -n ''
  50. }
  51. function mesh_tox_qtox {
  52. if [ ! ${rootdir}$INSTALL_DIR ]; then
  53. INSTALL_DIR=${rootdir}/root/build
  54. fi
  55. if [ ! -d ${rootdir}$INSTALL_DIR ]; then
  56. mkdir -p ${rootdir}$INSTALL_DIR
  57. fi
  58. chroot "${rootdir}" apt-get -y install build-essential libatk1.0-0 libbz2-1.0 libc6 libcairo2 libdbus-1-3 libegl1-mesa libfontconfig1 libfreetype6 libgcc1 libgdk-pixbuf2.0-0 libgl1-mesa-glx libglib2.0-0 libgtk2.0-0 libice6 libicu52 libjpeg62-turbo libmng1 libmtdev1 libopenal1 libopus0 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpng12-0 libqrencode3 libsm6 libsodium13 libsqlite3-0 libssl1.0.0 libstdc++6 libtiff5 libudev1 libvpx1 libwayland-client0 libwayland-cursor0 libwayland-egl1-mesa libwebp5 libx11-6 libx11-xcb1 libxcb-glx0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-render0 libxcb-shape0 libxcb-shm0 libxcb-sync1 libxcb-xfixes0 libxcb-xinerama0 libxcb1 libxext6 libxfixes3 libxi6 libxrender1 libxss1 zlib1g libopus-dev libvpx-dev
  59. chroot "${rootdir}" apt-get -y install build-essential qt5-qmake qt5-default qttools5-dev-tools libqt5opengl5-dev libqt5svg5-dev libopenal-dev libxss-dev qrencode libqrencode-dev libglib2.0-dev libgdk-pixbuf2.0-dev libgtk2.0-dev libsqlcipher-dev libopus-dev libvpx-dev libavformat-dev libavdevice-dev libswscale-dev libavutil-dev libavcodec-dev libavcodec56 libavcodec57 libavfilter-dev libavfilter6
  60. mesh_install_ffmpeg
  61. git clone $QTOX_REPO ${rootdir}$INSTALL_DIR/qtox
  62. if [ ! -d ${rootdir}$INSTALL_DIR/qtox ]; then
  63. exit 72428
  64. fi
  65. cd ${rootdir}${INSTALL_DIR}/qtox
  66. git checkout $QTOX_COMMIT -b $QTOX_COMMIT
  67. chroot ${rootdir} /bin/bash -x <<EOF
  68. cd ${INSTALL_DIR}/qtox
  69. qmake
  70. make
  71. make install
  72. EOF
  73. if [ ! -f ${rootdir}/usr/bin/qtox ]; then
  74. exit 75784
  75. fi
  76. }
  77. function reconfigure_tox {
  78. echo -n ''
  79. }
  80. function upgrade_tox {
  81. if ! grep -Fxq "install_tox" $COMPLETION_FILE; then
  82. return
  83. fi
  84. function_check set_repo_commit
  85. set_repo_commit $INSTALL_DIR/toxcore "toxcore commit" "$TOXCORE_COMMIT" $TOXCORE_REPO
  86. function_check set_repo_commit
  87. set_repo_commit $INSTALL_DIR/toxic "Toxic commit" "$TOXIC_COMMIT" $TOXIC_REPO
  88. }
  89. function backup_local_tox {
  90. if [ -d /var/lib/tox-bootstrapd ]; then
  91. echo $"Backing up Tox"
  92. if [ -d /var/lib/tox-bootstrapd ]; then
  93. cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
  94. if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
  95. rm -rf /var/lib/tox-bootstrapd/Maildir
  96. fi
  97. fi
  98. function_check backup_directory_to_usb
  99. backup_directory_to_usb /var/lib/tox-bootstrapd tox
  100. echo $"Backup of Tox complete"
  101. fi
  102. }
  103. function restore_local_tox {
  104. if [ -d $USB_MOUNT/backup/tox ]; then
  105. echo $"Restoring Tox node settings"
  106. function_check restore_directory_from_usb
  107. restore_directory_from_usb / tox
  108. if [ ! "$?" = "0" ]; then
  109. function_check set_user_permissions
  110. set_user_permissions
  111. function_check backup_unmount_drive
  112. backup_unmount_drive
  113. exit 6393
  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. function_check set_user_permissions
  120. set_user_permissions
  121. function_check backup_unmount_drive
  122. backup_unmount_drive
  123. exit 59369
  124. fi
  125. fi
  126. }
  127. function backup_remote_tox {
  128. if [ -d /var/lib/tox-bootstrapd ]; then
  129. echo "Backing up Tox node settings"
  130. if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
  131. rm -rf /var/lib/tox-bootstrapd/Maildir
  132. fi
  133. cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
  134. backup_directory_to_friend /var/lib/tox-bootstrapd tox
  135. echo "Backup of Tox node settings complete"
  136. fi
  137. }
  138. function restore_remote_tox {
  139. if [ -d $SERVER_DIRECTORY/backup/tox ]; then
  140. echo $"Restoring Tox node settings"
  141. function_check restore_directory_from_friend
  142. restore_directory_from_friend / tox
  143. if [ ! "$?" = "0" ]; then
  144. exit 93653
  145. fi
  146. cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
  147. systemctl restart tox-bootstrapd.service
  148. if [ ! "$?" = "0" ]; then
  149. systemctl status tox-bootstrapd.service
  150. exit 59369
  151. fi
  152. echo $"Restore of Tox node complete"
  153. fi
  154. }
  155. function remove_tox_node {
  156. if ! grep -Fxq "install_tox_node" $COMPLETION_FILE; then
  157. return
  158. fi
  159. iptables -D INPUT -p tcp --dport $TOX_PORT -j ACCEPT
  160. iptables -D INPUT -p udp --dport $TOX_PORT -j ACCEPT
  161. function_check save_firewall_settings
  162. save_firewall_settings
  163. function_check remove_onion_service
  164. remove_onion_service tox ${TOX_PORT}
  165. ${PROJECT_NAME}-mesh-install -f tox_node --remove yes
  166. if [ ! "$?" = "0" ]; then
  167. echo $'Failed to remove tox node'
  168. exit 763836
  169. fi
  170. sed -i '/install_tox_node/d' $COMPLETION_FILE
  171. sed -i '/configure_firewall_for_tox/d' $COMPLETION_FILE
  172. }
  173. function remove_tox_avahi {
  174. if ! grep -Fxq "tox_avahi" $COMPLETION_FILE; then
  175. return
  176. fi
  177. cd $INSTALL_DIR/toxid
  178. make uninstall
  179. rm -rf $INSTALL_DIR/toxid
  180. sed -i '/tox_avahi/d' $COMPLETION_FILE
  181. }
  182. function remove_tox_client {
  183. if ! grep -Fxq "install_tox_client" $COMPLETION_FILE; then
  184. return
  185. fi
  186. ${PROJECT_NAME}-mesh-install -f tox_client --remove yes
  187. if [ ! "$?" = "0" ]; then
  188. echo $'Could not remove Tox client'
  189. exit 737253
  190. fi
  191. sed -i '/install_tox_client/d' $COMPLETION_FILE
  192. sed -i '/Tox /d' $COMPLETION_FILE
  193. sed -i '/Toxic /d' $COMPLETION_FILE
  194. }
  195. function remove_tox {
  196. remove_tox_client
  197. remove_tox_avahi
  198. remove_tox_node
  199. }
  200. function configure_firewall_for_tox {
  201. if [ ! $INSTALLING_MESH ]; then
  202. if [ -f $COMPLETION_FILE ]; then
  203. if grep -Fxq "configure_firewall_for_tox" $COMPLETION_FILE; then
  204. return
  205. fi
  206. fi
  207. fi
  208. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  209. # docker does its own firewalling
  210. return
  211. fi
  212. if [[ $ONION_ONLY != "no" ]]; then
  213. return
  214. fi
  215. TOX_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}')
  216. if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
  217. TOX_PORT=$TOX_PORT_MAIN
  218. fi
  219. if [ ! $TOX_PORT ]; then
  220. echo $'No Tox port was specified'
  221. exit 32856
  222. fi
  223. iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT
  224. iptables -A INPUT -p udp --dport $TOX_PORT -j ACCEPT
  225. function_check save_firewall_settings
  226. save_firewall_settings
  227. OPEN_PORTS+=("Tox $TOX_PORT")
  228. if [ -f $COMPLETION_FILE ]; then
  229. echo 'configure_firewall_for_tox' >> $COMPLETION_FILE
  230. fi
  231. }
  232. function tox_avahi {
  233. if grep -Fxq "tox_avahi" $COMPLETION_FILE; then
  234. return
  235. fi
  236. if [ ! -d /etc/avahi ]; then
  237. echo $'tox_avahi: avahi is not installed'
  238. exit 87359
  239. fi
  240. # install a command to obtain the Tox ID
  241. cd $INSTALL_DIR
  242. function_check git_clone
  243. git_clone $TOXID_REPO $INSTALL_DIR/toxid
  244. if [ ! -d $INSTALL_DIR/toxid ]; then
  245. exit 63921
  246. fi
  247. cd $INSTALL_DIR/toxid
  248. make
  249. if [ ! "$?" = "0" ]; then
  250. exit 58432
  251. fi
  252. make install
  253. if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
  254. toxavahi
  255. # publish regularly
  256. function_check cron_add_mins
  257. cron_add_mins 1 'toxavahi 2> /dev/null'
  258. fi
  259. systemctl restart avahi-daemon
  260. echo 'tox_avahi' >> $COMPLETION_FILE
  261. }
  262. function install_tox_node {
  263. if grep -Fxq "install_tox_node" $COMPLETION_FILE; then
  264. return
  265. fi
  266. function_check mesh_tox_node
  267. mesh_tox_node
  268. # onion address for bootstrapping
  269. TOX_ONION_HOSTNAME=$(add_onion_service tox ${TOX_PORT} ${TOX_PORT})
  270. if ! grep -q "tox onion domain" $COMPLETION_FILE; then
  271. echo "tox onion domain:${TOX_ONION_HOSTNAME}" >> $COMPLETION_FILE
  272. else
  273. sed -i "s|tox onion domain.*|tox onion domain:${TOX_ONION_HOSTNAME}|g" $COMPLETION_FILE
  274. fi
  275. systemctl restart tox-bootstrapd.service
  276. TOX_PUBLIC_KEY=$(cat /var/log/syslog | grep tox | grep "Public Key" | awk -F ' ' '{print $8}' | tail -1)
  277. if [ ${#TOX_PUBLIC_KEY} -lt 30 ]; then
  278. echo $'Could not obtain the tox node public key'
  279. exit 6529
  280. fi
  281. # save the public key for later reference
  282. echo "$TOX_PUBLIC_KEY" > $TOX_BOOTSTRAP_ID_FILE
  283. function_check configure_firewall_for_tox
  284. configure_firewall_for_tox
  285. if ! grep -q $"Your Tox node public key is" /home/$MY_USERNAME/README; then
  286. echo '' >> /home/$MY_USERNAME/README
  287. echo '' >> /home/$MY_USERNAME/README
  288. echo 'Tox' >> /home/$MY_USERNAME/README
  289. echo '===' >> /home/$MY_USERNAME/README
  290. echo $"tox onion domain: ${TOX_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
  291. echo $"Your Tox node public key is: $TOX_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  292. echo $'In the Toxic client you can connect to it with:' >> /home/$MY_USERNAME/README
  293. echo " /connect $DEFAULT_DOMAIN_NAME.local $TOX_PORT $TOX_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  294. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
  295. chmod 600 /home/$MY_USERNAME/README
  296. fi
  297. function_check configure_firewall_for_tox
  298. configure_firewall_for_tox
  299. echo 'install_tox_node' >> $COMPLETION_FILE
  300. }
  301. function install_tox_client {
  302. if grep -Fxq "install_tox_client" $COMPLETION_FILE; then
  303. return
  304. fi
  305. function_check mesh_tox_client
  306. mesh_tox_client
  307. echo 'install_tox_client' >> $COMPLETION_FILE
  308. }
  309. function mesh_tox_node {
  310. # obtain commits from the main file
  311. TOXCORE_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXCORE_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  312. if [ ${#TOXCORE_COMMIT_MAIN} -gt 10 ]; then
  313. TOXCORE_COMMIT=$TOXCORE_COMMIT_MAIN
  314. fi
  315. if [ ! $TOXCORE_COMMIT ]; then
  316. echo $'No Tox commit was specified'
  317. exit 76325
  318. fi
  319. TOXID_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXID_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  320. if [ ${#TOXID_REPO_MAIN} -gt 5 ]; then
  321. TOXID_REPO=$TOXID_REPO_MAIN
  322. fi
  323. if [ ! $TOXID_REPO ]; then
  324. echo $'No ToxID repo was specified'
  325. exit 78252
  326. fi
  327. TOX_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}')
  328. if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
  329. TOX_PORT=$TOX_PORT_MAIN
  330. fi
  331. if [ ! $TOX_PORT ]; then
  332. echo $'No Tox port was specified'
  333. exit 32856
  334. fi
  335. TOXCORE_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXCORE_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  336. if [ ${#TOXCORE_REPO_MAIN} -gt 10 ]; then
  337. TOXCORE_REPO=$TOXCORE_REPO_MAIN
  338. fi
  339. if [ ! $TOXCORE_REPO ]; then
  340. echo $'No Tox repo was specified'
  341. exit 16865
  342. fi
  343. if [ ! $TOXCORE_COMMIT ]; then
  344. echo $'No Tox commit was specified'
  345. exit 76325
  346. fi
  347. if [ ! $TOXCORE_REPO ]; then
  348. echo $'No Tox repo was specified'
  349. exit 16865
  350. fi
  351. if [ $rootdir ]; then
  352. chroot ${rootdir} apt-get -y install build-essential libtool autotools-dev
  353. chroot ${rootdir} apt-get -y install automake checkinstall check git yasm
  354. chroot ${rootdir} apt-get -y install libsodium13 libsodium-dev libcap2-bin
  355. chroot ${rootdir} apt-get -y install libconfig9 libconfig-dev autoconf
  356. chroot ${rootdir} apt-get -y install libopus-dev libvpx-dev
  357. else
  358. apt-get -y install build-essential libtool autotools-dev
  359. apt-get -y install automake checkinstall check git yasm
  360. apt-get -y install libsodium13 libsodium-dev libcap2-bin
  361. apt-get -y install libconfig9 libconfig-dev autoconf
  362. apt-get -y install libopus-dev libvpx-dev
  363. fi
  364. if [ ! -d ${rootdir}${INSTALL_DIR} ]; then
  365. mkdir -p ${rootdir}${INSTALL_DIR}
  366. fi
  367. git clone ${TOXCORE_REPO} ${rootdir}${INSTALL_DIR}/toxcore
  368. if [ ! "$?" = "0" ]; then
  369. exit 429252
  370. fi
  371. cd ${rootdir}$INSTALL_DIR/toxcore
  372. git checkout $TOXCORE_COMMIT -b $TOXCORE_COMMIT
  373. if [ ${rootdir} ]; then
  374. chroot ${rootdir} /bin/bash -x <<EOF
  375. cd ${INSTALL_DIR}/toxcore
  376. autoreconf -i
  377. ./configure --enable-daemon
  378. make
  379. make install
  380. EOF
  381. else
  382. /bin/bash -x <<EOF
  383. cd ${INSTALL_DIR}/toxcore
  384. autoreconf -i
  385. ./configure --enable-daemon
  386. make
  387. make install
  388. EOF
  389. fi
  390. cp $rootdir/usr/local/lib/libtoxcore* $rootdir/usr/lib/
  391. cp ${rootdir}${INSTALL_DIR}/toxcore/other/bootstrap_daemon/tox-bootstrapd.service $rootdir/etc/systemd/system/
  392. sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' $rootdir/etc/systemd/system/tox-bootstrapd.service
  393. if [ ${rootdir} ]; then
  394. chroot ${rootdir} systemctl enable tox-bootstrapd.service
  395. else
  396. systemctl enable tox-bootstrapd.service
  397. fi
  398. SECONDS=0
  399. if [ ! -f $rootdir/usr/local/bin/tox-bootstrapd ]; then
  400. duration=$SECONDS
  401. echo $"Toxcore compile failed at $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  402. echo $'Unable to make toxcore'
  403. exit 73835
  404. fi
  405. duration=$SECONDS
  406. echo $"Toxcore compile $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  407. if [ ${rootdir} ]; then
  408. chroot ${rootdir} /usr/sbin/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
  409. chroot ${rootdir} /bin/chmod 700 /var/lib/tox-bootstrapd
  410. else
  411. 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
  412. chmod 700 /var/lib/tox-bootstrapd
  413. fi
  414. # remove Maildir
  415. if [ -d $rootdir/var/lib/tox-bootstrapd/Maildir ]; then
  416. rm -rf $rootdir/var/lib/tox-bootstrapd/Maildir
  417. fi
  418. # create configuration file
  419. TOX_BOOTSTRAP_CONFIG=$rootdir/etc/tox-bootstrapd.conf
  420. echo "port = $TOX_PORT" > $TOX_BOOTSTRAP_CONFIG
  421. echo 'keys_file_path = "/var/lib/tox-bootstrapd/keys"' >> $TOX_BOOTSTRAP_CONFIG
  422. echo 'pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"' >> $TOX_BOOTSTRAP_CONFIG
  423. echo 'enable_ipv6 = true' >> $TOX_BOOTSTRAP_CONFIG
  424. echo 'enable_ipv4_fallback = true' >> $TOX_BOOTSTRAP_CONFIG
  425. echo 'enable_lan_discovery = true' >> $TOX_BOOTSTRAP_CONFIG
  426. echo 'enable_tcp_relay = true' >> $TOX_BOOTSTRAP_CONFIG
  427. echo "tcp_relay_ports = [443, 3389, $TOX_PORT]" >> $TOX_BOOTSTRAP_CONFIG
  428. echo 'enable_motd = true' >> $TOX_BOOTSTRAP_CONFIG
  429. echo 'motd = "tox-bootstrapd"' >> $TOX_BOOTSTRAP_CONFIG
  430. if [ $TOX_NODES ]; then
  431. echo 'bootstrap_nodes = (' >> $TOX_BOOTSTRAP_CONFIG
  432. toxcount=0
  433. while [ "x${TOX_NODES[toxcount]}" != "x" ]
  434. do
  435. toxval_ipv4=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $1}')
  436. toxval_ipv6=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $2}')
  437. toxval_port=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $3}')
  438. toxval_pubkey=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $4}')
  439. toxval_maintainer=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $5}')
  440. echo "{ // $toxval_maintainer" >> $TOX_BOOTSTRAP_CONFIG
  441. if [[ $toxval_ipv6 != 'NONE' ]]; then
  442. echo " address = \"$toxval_ipv6\"" >> $TOX_BOOTSTRAP_CONFIG
  443. else
  444. echo " address = \"$toxval_ipv4\"" >> $TOX_BOOTSTRAP_CONFIG
  445. fi
  446. echo " port = $toxval_port" >> $TOX_BOOTSTRAP_CONFIG
  447. echo " public_key = \"$toxval_pubkey\"" >> $TOX_BOOTSTRAP_CONFIG
  448. toxcount=$(( $toxcount + 1 ))
  449. if [ "x${TOX_NODES[toxcount]}" != "x" ]; then
  450. echo "}," >> $TOX_BOOTSTRAP_CONFIG
  451. else
  452. echo "}" >> $TOX_BOOTSTRAP_CONFIG
  453. fi
  454. done
  455. echo ')' >> $TOX_BOOTSTRAP_CONFIG
  456. fi
  457. }
  458. function mesh_tox_avahi {
  459. if [ ! -d $rootdir/etc/avahi ]; then
  460. echo $'tox_avahi: avahi is not installed'
  461. exit 87359
  462. fi
  463. if [ ! $TOXID_REPO ]; then
  464. echo $'No ToxID repo was specified'
  465. exit 78252
  466. fi
  467. if [ ! -d ${rootdir}${INSTALL_DIR} ]; then
  468. mkdir -p ${rootdir}${INSTALL_DIR}
  469. fi
  470. git clone ${TOXID_REPO} ${rootdir}${INSTALL_DIR}/toxid
  471. if [ ! -d ${rootdir}${INSTALL_DIR}/toxid ]; then
  472. echo $'Unable to clone toxid repo'
  473. exit 768352
  474. fi
  475. if [ ${rootdir} ]; then
  476. chroot ${rootdir} /bin/bash -x <<EOF
  477. cd ${INSTALL_DIR}/toxid
  478. make
  479. make install
  480. EOF
  481. else
  482. /bin/bash -x <<EOF
  483. cd ${INSTALL_DIR}/toxid
  484. make
  485. make install
  486. EOF
  487. fi
  488. if [ ! -f $rootdir/usr/local/bin/toxid ]; then
  489. echo $'toxid not found'
  490. exit 74370
  491. fi
  492. if [ ! -f $rootdir/usr/local/bin/toxavahi ]; then
  493. exit 3621729
  494. fi
  495. MESH_SYNC_COMMAND=$rootdir/usr/bin/mesh-sync
  496. echo '#!/bin/bash' > $MESH_SYNC_COMMAND
  497. echo '/usr/local/bin/toxavahi 2> /dev/null' >> $MESH_SYNC_COMMAND
  498. echo '/usr/local/bin/meshavahi 2> /dev/null' >> $MESH_SYNC_COMMAND
  499. chmod +x $MESH_SYNC_COMMAND
  500. if ! grep -q "mesh-sync" ${rootdir}/etc/crontab; then
  501. echo "*/1 * * * * root /usr/bin/mesh-sync 2> /dev/null" >> ${rootdir}/etc/crontab
  502. echo "*/1 * * * * root ( sleep 20 ; /usr/bin/mesh-sync 2> /dev/null )" >> ${rootdir}/etc/cro echo "*/1 * * * * root ( sleep 40 ; /usr/bin/mesh-sync 2> /dev/null )" >> ${rootdir}/etc/crontab
  503. fi
  504. }
  505. function mesh_tox_client {
  506. TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  507. # obtain commits from the main file
  508. TOXIC_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  509. if [ ${#TOXIC_COMMIT_MAIN} -gt 10 ]; then
  510. TOXIC_COMMIT=$TOXIC_COMMIT_MAIN
  511. fi
  512. TOXIC_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  513. if [ ${#TOXIC_REPO_MAIN} -gt 5 ]; then
  514. TOXIC_REPO=$TOXIC_REPO_MAIN
  515. fi
  516. if [ ${rootdir} ]; then
  517. chroot ${rootdir} apt-get -y install libncursesw5-dev libconfig-dev libqrencode-dev
  518. chroot ${rootdir} apt-get -y install libcurl4-openssl-dev libvpx-dev libopenal-dev
  519. else
  520. apt-get -y install libncursesw5-dev libconfig-dev libqrencode-dev
  521. apt-get -y install libcurl4-openssl-dev libvpx-dev libopenal-dev
  522. fi
  523. TEMP_SCRIPT_NAME=fbtmp728353.sh
  524. TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
  525. echo '#!/bin/bash' > $TEMP_SCRIPT
  526. echo "mkdir -p $INSTALL_DIR" >> $TEMP_SCRIPT
  527. echo "git clone $TOXIC_REPO $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
  528. echo "cd $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
  529. echo "git checkout $TOXIC_COMMIT -b $TOXIC_COMMIT" >> $TEMP_SCRIPT
  530. echo 'make' >> $TEMP_SCRIPT
  531. echo 'if [ ! "$?" = "0" ]; then' >> $TEMP_SCRIPT
  532. echo ' exit 1' >> $TEMP_SCRIPT
  533. echo 'fi' >> $TEMP_SCRIPT
  534. echo 'make install' >> $TEMP_SCRIPT
  535. echo 'exit 0' >> $TEMP_SCRIPT
  536. chmod +x $TEMP_SCRIPT
  537. cp $TEMP_SCRIPT $rootdir/root/
  538. TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  539. SECONDS=0
  540. if [ ${rootdir} ]; then
  541. chroot ${rootdir} /root/$TEMP_SCRIPT_NAME
  542. else
  543. /root/$TEMP_SCRIPT_NAME
  544. fi
  545. if [ ! "$?" = "0" ]; then
  546. duration=$SECONDS
  547. echo $"Toxic client compile failed at $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  548. echo $'Unable to make tox client'
  549. rm $TEMP_SCRIPT
  550. exit 74872
  551. fi
  552. rm $TEMP_SCRIPT
  553. if [ ! -f $rootdir$TOXIC_FILE ]; then
  554. echo $"Tox client was not installed to $TOXIC_FILE"
  555. exit 63278
  556. fi
  557. duration=$SECONDS
  558. echo $"Toxic client compile $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  559. }
  560. function enable_tox_repo {
  561. echo 'deb http://download.opensuse.org/repositories/home:/antonbatenev:/tox/Debian_8.0/ /' > $rootdir/etc/apt/sources.list.d/tox.list
  562. chroot "$rootdir" /usr/bin/wget -q http://download.opensuse.org/repositories/home:antonbatenev:tox/Debian_8.0/Release.key -O- | apt-key add -
  563. chroot "$rootdir" apt-get update
  564. echo "Tox Repository Installed."
  565. }
  566. function install_tox {
  567. if [ ! $INSTALLING_MESH ]; then
  568. if grep -Fxq "install_tox" $COMPLETION_FILE; then
  569. return
  570. fi
  571. fi
  572. configure_firewall_for_tox
  573. if [ $INSTALLING_MESH ]; then
  574. mesh_tox_node
  575. mesh_tox_avahi
  576. mesh_tox_client
  577. else
  578. install_tox_node
  579. tox_avahi
  580. install_tox_client
  581. fi
  582. echo 'install_tox' >> $COMPLETION_FILE
  583. }
  584. # NOTE: deliberately no exit 0