freedombone-app-tox 26KB

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