freedombone-app-tox 27KB

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