freedombone-app-tox 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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. iptables -D INPUT -p tcp --dport $TOX_PORT -j ACCEPT
  200. iptables -D INPUT -p udp --dport $TOX_PORT -j ACCEPT
  201. function_check save_firewall_settings
  202. save_firewall_settings
  203. function_check remove_onion_service
  204. remove_onion_service tox ${TOX_PORT}
  205. ${PROJECT_NAME}-mesh-install -f tox_node --remove yes
  206. if [ ! "$?" = "0" ]; then
  207. echo $'Failed to remove tox node'
  208. exit 763836
  209. fi
  210. sed -i '/install_tox_node/d' $COMPLETION_FILE
  211. sed -i '/configure_firewall_for_tox/d' $COMPLETION_FILE
  212. }
  213. function remove_tox_avahi {
  214. cd $INSTALL_DIR/toxid
  215. make uninstall
  216. rm -rf $INSTALL_DIR/toxid
  217. sed -i '/tox_avahi/d' $COMPLETION_FILE
  218. }
  219. function remove_tox_client {
  220. ${PROJECT_NAME}-mesh-install -f tox_client --remove yes
  221. if [ ! "$?" = "0" ]; then
  222. echo $'Could not remove Tox client'
  223. exit 737253
  224. fi
  225. sed -i '/install_tox_client/d' $COMPLETION_FILE
  226. sed -i '/Tox /d' $COMPLETION_FILE
  227. sed -i '/Toxic /d' $COMPLETION_FILE
  228. }
  229. function remove_tox {
  230. remove_tox_client
  231. remove_tox_avahi
  232. remove_tox_node
  233. }
  234. function configure_firewall_for_tox {
  235. if [ ! $INSTALLING_MESH ]; then
  236. if [ -f $COMPLETION_FILE ]; then
  237. if grep -Fxq "configure_firewall_for_tox" $COMPLETION_FILE; then
  238. return
  239. fi
  240. fi
  241. fi
  242. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  243. # docker does its own firewalling
  244. return
  245. fi
  246. if [[ $ONION_ONLY != "no" ]]; then
  247. return
  248. fi
  249. TOX_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}')
  250. if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
  251. TOX_PORT=$TOX_PORT_MAIN
  252. fi
  253. if [ ! $TOX_PORT ]; then
  254. echo $'No Tox port was specified'
  255. exit 32856
  256. fi
  257. iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT
  258. iptables -A INPUT -p udp --dport $TOX_PORT -j ACCEPT
  259. function_check save_firewall_settings
  260. save_firewall_settings
  261. OPEN_PORTS+=("Tox $TOX_PORT")
  262. if [ -f $COMPLETION_FILE ]; then
  263. echo 'configure_firewall_for_tox' >> $COMPLETION_FILE
  264. fi
  265. }
  266. function tox_avahi {
  267. if grep -Fxq "tox_avahi" $COMPLETION_FILE; then
  268. return
  269. fi
  270. if [ ! -d /etc/avahi ]; then
  271. echo $'tox_avahi: avahi is not installed'
  272. exit 87359
  273. fi
  274. # install a command to obtain the Tox ID
  275. cd $INSTALL_DIR
  276. function_check git_clone
  277. git_clone $TOXID_REPO $INSTALL_DIR/toxid
  278. if [ ! -d $INSTALL_DIR/toxid ]; then
  279. exit 63921
  280. fi
  281. cd $INSTALL_DIR/toxid
  282. make
  283. if [ ! "$?" = "0" ]; then
  284. exit 58432
  285. fi
  286. make install
  287. if [[ $SYSTEM_TYPE == "mesh"* ]]; then
  288. toxavahi
  289. # publish regularly
  290. function_check cron_add_mins
  291. cron_add_mins 1 'toxavahi 2> /dev/null'
  292. fi
  293. systemctl restart avahi-daemon
  294. echo 'tox_avahi' >> $COMPLETION_FILE
  295. }
  296. function install_tox_node {
  297. if [[ $(app_is_installed tox_node) == "1" ]]; then
  298. return
  299. fi
  300. function_check mesh_tox_node
  301. mesh_tox_node
  302. # onion address for bootstrapping
  303. TOX_ONION_HOSTNAME=$(add_onion_service tox ${TOX_PORT} ${TOX_PORT})
  304. systemctl restart tox-bootstrapd.service
  305. TOX_PUBLIC_KEY=$(cat /var/log/syslog | grep tox | grep "Public Key" | awk -F ' ' '{print $8}' | tail -1)
  306. if [ ${#TOX_PUBLIC_KEY} -lt 30 ]; then
  307. echo $'Could not obtain the tox node public key'
  308. exit 6529
  309. fi
  310. # save the public key for later reference
  311. echo "$TOX_PUBLIC_KEY" > $TOX_BOOTSTRAP_ID_FILE
  312. function_check configure_firewall_for_tox
  313. configure_firewall_for_tox
  314. if ! grep -q $"Your Tox node public key is" /home/$MY_USERNAME/README; then
  315. echo '' >> /home/$MY_USERNAME/README
  316. echo '' >> /home/$MY_USERNAME/README
  317. echo 'Tox' >> /home/$MY_USERNAME/README
  318. echo '===' >> /home/$MY_USERNAME/README
  319. echo $"tox onion domain: ${TOX_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
  320. echo $"Your Tox node public key is: $TOX_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  321. echo $'In the Toxic client you can connect to it with:' >> /home/$MY_USERNAME/README
  322. echo " /connect $DEFAULT_DOMAIN_NAME.local $TOX_PORT $TOX_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  323. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
  324. chmod 600 /home/$MY_USERNAME/README
  325. fi
  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 -y install build-essential libtool autotools-dev
  382. chroot ${rootdir} apt-get -y install automake checkinstall check git yasm
  383. chroot ${rootdir} apt-get -y install libsodium13 libsodium-dev libcap2-bin
  384. chroot ${rootdir} apt-get -y install libconfig9 libconfig-dev autoconf
  385. chroot ${rootdir} apt-get -y install libopus-dev libvpx-dev
  386. else
  387. apt-get -y install build-essential libtool autotools-dev
  388. apt-get -y install automake checkinstall check git yasm
  389. apt-get -y install libsodium13 libsodium-dev libcap2-bin
  390. apt-get -y install libconfig9 libconfig-dev autoconf
  391. apt-get -y 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 -y install libncursesw5-dev libconfig-dev libqrencode-dev
  549. chroot ${rootdir} apt-get -y install libcurl4-openssl-dev libvpx-dev libopenal-dev
  550. else
  551. apt-get -y install libncursesw5-dev libconfig-dev libqrencode-dev
  552. apt-get -y 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. chroot "$rootdir" /usr/bin/wget -q http://download.opensuse.org/repositories/home:antonbatenev:tox/Debian_8.0/Release.key -O- | apt-key add -
  594. chroot "$rootdir" apt-get update
  595. echo "Tox Repository Installed."
  596. }
  597. function install_tox {
  598. configure_firewall_for_tox
  599. if [ $INSTALLING_MESH ]; then
  600. mesh_tox_node
  601. mesh_tox_avahi
  602. mesh_tox_client
  603. else
  604. install_tox_node
  605. tox_avahi
  606. install_tox_client
  607. fi
  608. APP_INSTALLED=1
  609. }
  610. # NOTE: deliberately no exit 0