freedombone-app-tox 24KB

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