freedombone-app-tox 24KB

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