freedombone-app-tox 23KB

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