freedombone-app-tox 27KB

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