freedombone-app-tox 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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='532629d486e3361c7d8d95b38293cc7d61dc4ee5'
  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. 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 configure_interactive_tox {
  95. if [ ! -f $TOX_BOOTSTRAP_ID_FILE ]; then
  96. return
  97. fi
  98. bootstrap_id=$(cat $TOX_BOOTSTRAP_ID_FILE)
  99. dialog --title $"Tox Bootstrap Node ID" \
  100. --msgbox $"\n$bootstrap_id\n\nTo copy this hold down the shift key, select the ID and then right click and copy." 10 70
  101. }
  102. function mesh_tox_qtox {
  103. if [ ! ${rootdir}$INSTALL_DIR ]; then
  104. INSTALL_DIR=${rootdir}/root/build
  105. fi
  106. if [ ! -d ${rootdir}$INSTALL_DIR ]; then
  107. mkdir -p ${rootdir}$INSTALL_DIR
  108. fi
  109. 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 libicu57 libjpeg62-turbo libmng1 libmtdev1 libopenal1 libopus0 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpng16-16 libqrencode3 libsm6 libsodium18 libsqlite3-0 libssl1.1 libstdc++6 libtiff5 libudev1 libvpx4 libwayland-client0 libwayland-cursor0 libwayland-egl1-mesa libwebp6 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
  110. 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 libavcodec57 libavfilter-dev libavfilter6
  111. # ffmpeg
  112. chroot "${rootdir}" apt-get -yq install build-essential
  113. chroot "${rootdir}" apt-get -yq install ffmpeg libmp3lame-dev libvorbis-dev libtheora-dev
  114. chroot "${rootdir}" apt-get -yq install libspeex-dev yasm pkg-config libopenjp2-7-dev
  115. chroot "${rootdir}" apt-get -yq install libx264-dev mjpegtools libmjpegtools-dev libav-tools
  116. if [ -d /repos/qtox ]; then
  117. mkdir ${rootdir}$INSTALL_DIR/qtox
  118. cp -r -p /repos/qtox/. ${rootdir}$INSTALL_DIR/qtox
  119. cd ${rootdir}$INSTALL_DIR/qtox
  120. git pull
  121. else
  122. git clone $QTOX_REPO ${rootdir}$INSTALL_DIR/qtox
  123. fi
  124. if [ ! -d ${rootdir}$INSTALL_DIR/qtox ]; then
  125. exit 72428
  126. fi
  127. cd ${rootdir}${INSTALL_DIR}/qtox
  128. git checkout $QTOX_COMMIT -b $QTOX_COMMIT
  129. chroot ${rootdir} /bin/bash -x <<EOF
  130. cd ${INSTALL_DIR}/qtox
  131. qmake
  132. make
  133. make install
  134. EOF
  135. if [ ! -f ${rootdir}/usr/bin/qtox ]; then
  136. exit 75784
  137. fi
  138. }
  139. function reconfigure_tox {
  140. echo -n ''
  141. }
  142. function upgrade_tox {
  143. function_check set_repo_commit
  144. set_repo_commit $INSTALL_DIR/toxcore "toxcore commit" "$TOXCORE_COMMIT" $TOXCORE_REPO
  145. if [[ $(commit_has_changed $INSTALL_DIR/toxcore "toxcore commit" "$TOXCORE_COMMIT") == "1" ]]; then
  146. cd $INSTALL_DIR/toxcore
  147. sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' $rootdir/etc/systemd/system/tox-bootstrapd.service
  148. autoreconf -i
  149. ./configure --enable-daemon
  150. make
  151. make install
  152. systemctl daemon-reload
  153. systemctl restart tox-bootstrapd.service
  154. fi
  155. function_check set_repo_commit
  156. set_repo_commit $INSTALL_DIR/toxic "Toxic commit" "$TOXIC_COMMIT" $TOXIC_REPO
  157. if [[ $(commit_has_changed $INSTALL_DIR/toxic "Toxic commit" "$TOXIC_COMMIT") == "1" ]]; then
  158. cd $INSTALL_DIR/toxic
  159. make
  160. make install
  161. fi
  162. }
  163. function backup_local_tox {
  164. if [ -d /var/lib/tox-bootstrapd ]; then
  165. echo $"Backing up Tox"
  166. if [ -d /var/lib/tox-bootstrapd ]; then
  167. cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
  168. if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
  169. rm -rf /var/lib/tox-bootstrapd/Maildir
  170. fi
  171. fi
  172. function_check backup_directory_to_usb
  173. backup_directory_to_usb /var/lib/tox-bootstrapd tox
  174. echo $"Backup of Tox complete"
  175. fi
  176. }
  177. function restore_local_tox {
  178. if [ -d $USB_MOUNT/backup/tox ]; then
  179. echo $"Restoring Tox node settings"
  180. function_check restore_directory_from_usb
  181. restore_directory_from_usb / tox
  182. if [ ! "$?" = "0" ]; then
  183. function_check set_user_permissions
  184. set_user_permissions
  185. function_check backup_unmount_drive
  186. backup_unmount_drive
  187. exit 6393
  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. function_check set_user_permissions
  194. set_user_permissions
  195. function_check backup_unmount_drive
  196. backup_unmount_drive
  197. exit 59369
  198. fi
  199. fi
  200. }
  201. function backup_remote_tox {
  202. if [ -d /var/lib/tox-bootstrapd ]; then
  203. echo "Backing up Tox node settings"
  204. if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
  205. rm -rf /var/lib/tox-bootstrapd/Maildir
  206. fi
  207. cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
  208. backup_directory_to_friend /var/lib/tox-bootstrapd tox
  209. echo "Backup of Tox node settings complete"
  210. fi
  211. }
  212. function restore_remote_tox {
  213. if [ -d $SERVER_DIRECTORY/backup/tox ]; then
  214. echo $"Restoring Tox node settings"
  215. function_check restore_directory_from_friend
  216. restore_directory_from_friend / tox
  217. if [ ! "$?" = "0" ]; then
  218. exit 93653
  219. fi
  220. cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
  221. systemctl restart tox-bootstrapd.service
  222. if [ ! "$?" = "0" ]; then
  223. systemctl status tox-bootstrapd.service
  224. exit 59369
  225. fi
  226. echo $"Restore of Tox node complete"
  227. fi
  228. }
  229. function remove_tox_node {
  230. firewall_remove ${TOX_PORT}
  231. function_check remove_onion_service
  232. remove_onion_service tox ${TOX_PORT}
  233. ${PROJECT_NAME}-mesh-install -f tox_node --remove yes
  234. if [ ! "$?" = "0" ]; then
  235. echo $'Failed to remove tox node'
  236. exit 763836
  237. fi
  238. remove_completion_param install_tox_node
  239. remove_completion_param configure_firewall_for_tox
  240. }
  241. function remove_tox_avahi {
  242. cd $INSTALL_DIR/toxid
  243. make uninstall
  244. rm -rf $INSTALL_DIR/toxid
  245. sed -i '/tox_avahi/d' $COMPLETION_FILE
  246. }
  247. function remove_tox_client {
  248. ${PROJECT_NAME}-mesh-install -f tox_client --remove yes
  249. if [ ! "$?" = "0" ]; then
  250. echo $'Could not remove Tox client'
  251. exit 737253
  252. fi
  253. sed -i '/install_tox_client/d' $COMPLETION_FILE
  254. sed -i '/Tox /d' $COMPLETION_FILE
  255. sed -i '/Toxic /d' $COMPLETION_FILE
  256. }
  257. function remove_tox {
  258. remove_tox_client
  259. remove_tox_avahi
  260. remove_tox_node
  261. }
  262. function configure_firewall_for_tox {
  263. if [ ! $INSTALLING_MESH ]; then
  264. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  265. return
  266. fi
  267. fi
  268. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  269. # docker does its own firewalling
  270. return
  271. fi
  272. if [[ $ONION_ONLY != "no" ]]; then
  273. return
  274. fi
  275. TOX_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}')
  276. if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
  277. TOX_PORT=$TOX_PORT_MAIN
  278. fi
  279. if [ ! $TOX_PORT ]; then
  280. echo $'No Tox port was specified'
  281. exit 32856
  282. fi
  283. firewall_add Tox ${TOX_PORT}
  284. mark_completed $FUNCNAME
  285. }
  286. function tox_avahi {
  287. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  288. return
  289. fi
  290. if [ ! -d /etc/avahi ]; then
  291. echo $'tox_avahi: avahi is not installed'
  292. exit 87359
  293. fi
  294. # install a command to obtain the Tox ID
  295. cd $INSTALL_DIR
  296. if [ -d /repos/toxid ]; then
  297. mkdir $INSTALL_DIR/toxid
  298. cp -r -p /repos/toxid/. $INSTALL_DIR/toxid
  299. cd $INSTALL_DIR/toxid
  300. git pull
  301. else
  302. function_check git_clone
  303. git_clone $TOXID_REPO $INSTALL_DIR/toxid
  304. fi
  305. if [ ! -d $INSTALL_DIR/toxid ]; then
  306. exit 63921
  307. fi
  308. cd $INSTALL_DIR/toxid
  309. make
  310. if [ ! "$?" = "0" ]; then
  311. exit 58432
  312. fi
  313. make install
  314. if [[ $SYSTEM_TYPE == "mesh"* ]]; then
  315. toxavahi
  316. # publish regularly
  317. function_check cron_add_mins
  318. cron_add_mins 1 'toxavahi 2> /dev/null'
  319. fi
  320. systemctl restart avahi-daemon
  321. mark_completed $FUNCNAME
  322. }
  323. function install_tox_node {
  324. if [[ $(app_is_installed tox_node) == "1" ]]; then
  325. return
  326. fi
  327. function_check mesh_tox_node
  328. mesh_tox_node
  329. # onion address for bootstrapping
  330. TOX_ONION_HOSTNAME=$(add_onion_service tox ${TOX_PORT} ${TOX_PORT})
  331. systemctl restart tox-bootstrapd.service
  332. sleep 3
  333. TOX_PUBLIC_KEY=$(cat /var/log/syslog | grep tox | grep "Public Key" | tail -n 1 | awk -F ' ' '{print $8}')
  334. if [ ${#TOX_PUBLIC_KEY} -lt 30 ]; then
  335. echo $'Could not obtain the tox node public key'
  336. exit 6529
  337. fi
  338. # save the public key for later reference
  339. echo "$TOX_PUBLIC_KEY" > $TOX_BOOTSTRAP_ID_FILE
  340. function_check configure_firewall_for_tox
  341. configure_firewall_for_tox
  342. function_check configure_firewall_for_tox
  343. configure_firewall_for_tox
  344. install_completed tox_node
  345. }
  346. function install_tox_client {
  347. if [[ $(app_is_installed tox_client) == "1" ]]; then
  348. return
  349. fi
  350. function_check mesh_tox_client
  351. mesh_tox_client
  352. install_completed tox_client
  353. }
  354. function mesh_tox_node {
  355. # obtain commits from the main file
  356. TOXCORE_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXCORE_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  357. if [ ${#TOXCORE_COMMIT_MAIN} -gt 10 ]; then
  358. TOXCORE_COMMIT=$TOXCORE_COMMIT_MAIN
  359. fi
  360. if [ ! $TOXCORE_COMMIT ]; then
  361. echo $'No Tox commit was specified'
  362. exit 76325
  363. fi
  364. TOXID_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXID_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  365. if [ ${#TOXID_REPO_MAIN} -gt 5 ]; then
  366. TOXID_REPO=$TOXID_REPO_MAIN
  367. fi
  368. if [ ! $TOXID_REPO ]; then
  369. echo $'No ToxID repo was specified'
  370. exit 78252
  371. fi
  372. TOX_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}')
  373. if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
  374. TOX_PORT=$TOX_PORT_MAIN
  375. fi
  376. if [ ! $TOX_PORT ]; then
  377. echo $'No Tox port was specified'
  378. exit 32856
  379. fi
  380. TOXCORE_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXCORE_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  381. if [ ${#TOXCORE_REPO_MAIN} -gt 10 ]; then
  382. TOXCORE_REPO=$TOXCORE_REPO_MAIN
  383. fi
  384. if [ ! $TOXCORE_REPO ]; then
  385. echo $'No Tox repo was specified'
  386. exit 16865
  387. fi
  388. if [ ! $TOXCORE_COMMIT ]; then
  389. echo $'No Tox commit was specified'
  390. exit 76325
  391. fi
  392. if [ ! $TOXCORE_REPO ]; then
  393. echo $'No Tox repo was specified'
  394. exit 16865
  395. fi
  396. if [ $rootdir ]; then
  397. chroot ${rootdir} apt-get -yq install build-essential libtool autotools-dev
  398. chroot ${rootdir} apt-get -yq install automake checkinstall check git yasm
  399. chroot ${rootdir} apt-get -yq install libsodium18 libsodium-dev libcap2-bin
  400. chroot ${rootdir} apt-get -yq install libconfig9 libconfig-dev autoconf
  401. chroot ${rootdir} apt-get -yq install libopus-dev libvpx-dev
  402. else
  403. apt-get -yq install build-essential libtool autotools-dev
  404. apt-get -yq install automake checkinstall check git yasm
  405. apt-get -yq install libsodium18 libsodium-dev libcap2-bin
  406. apt-get -yq install libconfig9 libconfig-dev autoconf
  407. apt-get -yq install libopus-dev libvpx-dev
  408. fi
  409. if [ ! -d ${rootdir}${INSTALL_DIR} ]; then
  410. mkdir -p ${rootdir}${INSTALL_DIR}
  411. fi
  412. if [ ! -d ${rootdir}${INSTALL_DIR}/toxcore ]; then
  413. if [ -d /repos/toxcore ]; then
  414. mkdir ${rootdir}${INSTALL_DIR}/toxcore
  415. cp -r -p /repos/toxcore/. ${rootdir}${INSTALL_DIR}/toxcore
  416. cd ${rootdir}${INSTALL_DIR}/toxcore
  417. git pull
  418. else
  419. git clone ${TOXCORE_REPO} ${rootdir}${INSTALL_DIR}/toxcore
  420. if [ ! "$?" = "0" ]; then
  421. exit 429252
  422. fi
  423. fi
  424. fi
  425. cd ${rootdir}$INSTALL_DIR/toxcore
  426. git checkout $TOXCORE_COMMIT -b $TOXCORE_COMMIT
  427. if [ ${rootdir} ]; then
  428. chroot ${rootdir} /bin/bash -x <<EOF
  429. cd ${INSTALL_DIR}/toxcore
  430. autoreconf -i
  431. ./configure --enable-daemon
  432. make
  433. make install
  434. EOF
  435. else
  436. /bin/bash -x <<EOF
  437. cd ${INSTALL_DIR}/toxcore
  438. autoreconf -i
  439. ./configure --enable-daemon
  440. make
  441. make install
  442. EOF
  443. fi
  444. cp $rootdir/usr/local/lib/libtoxcore* $rootdir/usr/lib/
  445. cp ${rootdir}${INSTALL_DIR}/toxcore/other/bootstrap_daemon/tox-bootstrapd.service $rootdir/etc/systemd/system/
  446. sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' $rootdir/etc/systemd/system/tox-bootstrapd.service
  447. if [ ${rootdir} ]; then
  448. chroot ${rootdir} systemctl enable tox-bootstrapd.service
  449. else
  450. systemctl enable tox-bootstrapd.service
  451. fi
  452. SECONDS=0
  453. if [ ! -f $rootdir/usr/local/bin/tox-bootstrapd ]; then
  454. duration=$SECONDS
  455. echo $"Toxcore compile failed at $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  456. echo $'Unable to make toxcore'
  457. exit 73835
  458. fi
  459. duration=$SECONDS
  460. echo $"Toxcore compile $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  461. if [ ${rootdir} ]; then
  462. 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
  463. chroot ${rootdir} /bin/chmod 700 /var/lib/tox-bootstrapd
  464. else
  465. chmod 600 /etc/shadow
  466. chmod 600 /etc/gshadow
  467. 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
  468. chmod 0000 /etc/shadow
  469. chmod 0000 /etc/gshadow
  470. chmod 700 /var/lib/tox-bootstrapd
  471. fi
  472. # remove Maildir
  473. if [ -d $rootdir/var/lib/tox-bootstrapd/Maildir ]; then
  474. rm -rf $rootdir/var/lib/tox-bootstrapd/Maildir
  475. fi
  476. # create configuration file
  477. TOX_BOOTSTRAP_CONFIG=$rootdir/etc/tox-bootstrapd.conf
  478. echo "port = $TOX_PORT" > $TOX_BOOTSTRAP_CONFIG
  479. echo 'keys_file_path = "/var/lib/tox-bootstrapd/keys"' >> $TOX_BOOTSTRAP_CONFIG
  480. echo 'pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"' >> $TOX_BOOTSTRAP_CONFIG
  481. echo 'enable_ipv6 = true' >> $TOX_BOOTSTRAP_CONFIG
  482. echo 'enable_ipv4_fallback = true' >> $TOX_BOOTSTRAP_CONFIG
  483. echo 'enable_lan_discovery = true' >> $TOX_BOOTSTRAP_CONFIG
  484. echo 'enable_tcp_relay = true' >> $TOX_BOOTSTRAP_CONFIG
  485. echo "tcp_relay_ports = [443, 3389, $TOX_PORT]" >> $TOX_BOOTSTRAP_CONFIG
  486. echo 'enable_motd = true' >> $TOX_BOOTSTRAP_CONFIG
  487. echo 'motd = "tox-bootstrapd"' >> $TOX_BOOTSTRAP_CONFIG
  488. if [ $TOX_NODES ]; then
  489. echo 'bootstrap_nodes = (' >> $TOX_BOOTSTRAP_CONFIG
  490. toxcount=0
  491. while [ "x${TOX_NODES[toxcount]}" != "x" ]
  492. do
  493. toxval_ipv4=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $1}')
  494. toxval_ipv6=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $2}')
  495. toxval_port=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $3}')
  496. toxval_pubkey=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $4}')
  497. toxval_maintainer=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $5}')
  498. echo "{ // $toxval_maintainer" >> $TOX_BOOTSTRAP_CONFIG
  499. if [[ $toxval_ipv6 != 'NONE' ]]; then
  500. echo " address = \"$toxval_ipv6\"" >> $TOX_BOOTSTRAP_CONFIG
  501. else
  502. echo " address = \"$toxval_ipv4\"" >> $TOX_BOOTSTRAP_CONFIG
  503. fi
  504. echo " port = $toxval_port" >> $TOX_BOOTSTRAP_CONFIG
  505. echo " public_key = \"$toxval_pubkey\"" >> $TOX_BOOTSTRAP_CONFIG
  506. toxcount=$(( $toxcount + 1 ))
  507. if [ "x${TOX_NODES[toxcount]}" != "x" ]; then
  508. echo "}," >> $TOX_BOOTSTRAP_CONFIG
  509. else
  510. echo "}" >> $TOX_BOOTSTRAP_CONFIG
  511. fi
  512. done
  513. echo ')' >> $TOX_BOOTSTRAP_CONFIG
  514. fi
  515. if [ -f $rootdir/var/lib/tox-bootstrapd/keys ]; then
  516. chmod 700 $rootdir/var/lib/tox-bootstrapd/keys
  517. fi
  518. }
  519. function mesh_tox_avahi {
  520. if [ ! -d $rootdir/etc/avahi ]; then
  521. echo $'tox_avahi: avahi is not installed'
  522. exit 87359
  523. fi
  524. if [ ! $TOXID_REPO ]; then
  525. echo $'No ToxID repo was specified'
  526. exit 78252
  527. fi
  528. if [ ! -d ${rootdir}${INSTALL_DIR} ]; then
  529. mkdir -p ${rootdir}${INSTALL_DIR}
  530. fi
  531. if [ -d /repos/toxid ]; then
  532. mkdir ${rootdir}${INSTALL_DIR}/toxid
  533. cp -r -p /repos/toxid/. ${rootdir}${INSTALL_DIR}/toxid
  534. cd ${rootdir}${INSTALL_DIR}/toxid
  535. git pull
  536. else
  537. git clone ${TOXID_REPO} ${rootdir}${INSTALL_DIR}/toxid
  538. fi
  539. if [ ! -d ${rootdir}${INSTALL_DIR}/toxid ]; then
  540. echo $'Unable to clone toxid repo'
  541. exit 768352
  542. fi
  543. if [ ${rootdir} ]; then
  544. chroot ${rootdir} /bin/bash -x <<EOF
  545. cd ${INSTALL_DIR}/toxid
  546. make
  547. make install
  548. EOF
  549. else
  550. /bin/bash -x <<EOF
  551. cd ${INSTALL_DIR}/toxid
  552. make
  553. make install
  554. EOF
  555. fi
  556. if [ ! -f $rootdir/usr/local/bin/toxid ]; then
  557. echo $'toxid not found'
  558. exit 74370
  559. fi
  560. if [ ! -f $rootdir/usr/local/bin/toxavahi ]; then
  561. exit 3621729
  562. fi
  563. MESH_SYNC_COMMAND=$rootdir/usr/bin/mesh-sync
  564. echo '#!/bin/bash' > $MESH_SYNC_COMMAND
  565. echo '/usr/local/bin/toxavahi 2> /dev/null' >> $MESH_SYNC_COMMAND
  566. echo '/usr/local/bin/meshavahi 2> /dev/null' >> $MESH_SYNC_COMMAND
  567. chmod +x $MESH_SYNC_COMMAND
  568. if ! grep -q "mesh-sync" ${rootdir}/etc/crontab; then
  569. echo "*/1 * * * * root /usr/bin/mesh-sync 2> /dev/null" >> ${rootdir}/etc/crontab
  570. 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
  571. fi
  572. }
  573. function mesh_tox_client {
  574. TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  575. # obtain commits from the main file
  576. TOXIC_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  577. if [ ${#TOXIC_COMMIT_MAIN} -gt 10 ]; then
  578. TOXIC_COMMIT=$TOXIC_COMMIT_MAIN
  579. fi
  580. TOXIC_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  581. if [ ${#TOXIC_REPO_MAIN} -gt 5 ]; then
  582. TOXIC_REPO=$TOXIC_REPO_MAIN
  583. fi
  584. if [ ${rootdir} ]; then
  585. chroot ${rootdir} apt-get -yq install libncursesw5-dev libconfig-dev libqrencode-dev
  586. chroot ${rootdir} apt-get -yq install libcurl4-openssl-dev libvpx-dev libopenal-dev
  587. else
  588. apt-get -yq install libncursesw5-dev libconfig-dev libqrencode-dev
  589. apt-get -yq install libcurl4-openssl-dev libvpx-dev libopenal-dev
  590. fi
  591. TEMP_SCRIPT_NAME=fbtmp728353.sh
  592. TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
  593. echo '#!/bin/bash' > $TEMP_SCRIPT
  594. echo "mkdir -p $INSTALL_DIR" >> $TEMP_SCRIPT
  595. echo 'if [ -d /repos/toxic ]; then' >> $TEMP_SCRIPT
  596. echo " mkdir $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
  597. echo " cp -r -p /repos/toxic/. $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
  598. echo " cd $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
  599. echo ' git pull' >> $TEMP_SCRIPT
  600. echo 'else' >> $TEMP_SCRIPT
  601. echo " git clone $TOXIC_REPO $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
  602. echo 'fi' >> $TEMP_SCRIPT
  603. echo "cd $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
  604. echo "git checkout $TOXIC_COMMIT -b $TOXIC_COMMIT" >> $TEMP_SCRIPT
  605. echo 'make' >> $TEMP_SCRIPT
  606. echo 'if [ ! "$?" = "0" ]; then' >> $TEMP_SCRIPT
  607. echo ' exit 1' >> $TEMP_SCRIPT
  608. echo 'fi' >> $TEMP_SCRIPT
  609. echo 'make install' >> $TEMP_SCRIPT
  610. echo 'exit 0' >> $TEMP_SCRIPT
  611. chmod +x $TEMP_SCRIPT
  612. cp $TEMP_SCRIPT $rootdir/root/
  613. TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  614. SECONDS=0
  615. if [ ${rootdir} ]; then
  616. chroot ${rootdir} /root/$TEMP_SCRIPT_NAME
  617. else
  618. /root/$TEMP_SCRIPT_NAME
  619. fi
  620. if [ ! "$?" = "0" ]; then
  621. cat -n /root/fbtmp728353.sh
  622. duration=$SECONDS
  623. echo $"Toxic client compile failed at $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  624. echo $'Unable to make tox client'
  625. rm $TEMP_SCRIPT
  626. exit 74872
  627. fi
  628. rm $TEMP_SCRIPT
  629. if [ ! -f $rootdir$TOXIC_FILE ]; then
  630. echo $"Tox client was not installed to $TOXIC_FILE"
  631. exit 63278
  632. fi
  633. duration=$SECONDS
  634. echo $"Toxic client compile $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  635. }
  636. function enable_tox_repo {
  637. echo 'deb http://download.opensuse.org/repositories/home:/antonbatenev:/tox/Debian_9.0/ /' > $rootdir/etc/apt/sources.list.d/tox.list
  638. cat >> $rootdir/root/gettoxkey.sh <<EOF
  639. #!/bin/bash
  640. wget -q http://download.opensuse.org/repositories/home:antonbatenev:tox/Debian_9.0/Release.key -O- > /root/tox.key
  641. apt-key add /root/tox.key
  642. rm /root/tox.key
  643. EOF
  644. chroot "$rootdir" chmod +x /root/gettoxkey.sh
  645. chroot "$rootdir" /root/gettoxkey.sh
  646. chroot "$rootdir" apt-get update
  647. echo "Tox Repository Installed."
  648. }
  649. function install_tox {
  650. configure_firewall_for_tox
  651. if [ $INSTALLING_MESH ]; then
  652. mesh_tox_node
  653. mesh_tox_avahi
  654. mesh_tox_client
  655. else
  656. avoid_tor_restart=
  657. if [ -f $IMAGE_PASSWORD_FILE ]; then
  658. if [[ $ONION_ONLY != 'no' ]]; then
  659. avoid_tor_restart=1
  660. fi
  661. fi
  662. if [ $avoid_tor_restart ]; then
  663. ${PROJECT_NAME}-logging on --onion
  664. else
  665. ${PROJECT_NAME}-logging on
  666. fi
  667. install_tox_node
  668. if [ $avoid_tor_restart ]; then
  669. ${PROJECT_NAME}-logging off --onion
  670. else
  671. ${PROJECT_NAME}-logging off
  672. fi
  673. tox_avahi
  674. install_tox_client
  675. fi
  676. APP_INSTALLED=1
  677. }
  678. # NOTE: deliberately no exit 0