freedombone-app-tox 24KB

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