freedombone-app-tox 26KB

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