freedombone-app-tox 24KB

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