freedombone-app-tox 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # Tox Application
  10. #
  11. # License
  12. # =======
  13. #
  14. # Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU Affero General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU Affero General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU Affero General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. VARIANTS='full full-vim chat'
  29. IN_DEFAULT_INSTALL=0
  30. SHOW_ON_ABOUT=1
  31. TOX_PORT=33445
  32. # upstream is https://github.com/TokTok/c-toxcore
  33. TOXCORE_REPO="https://github.com/bashrc/toxcore"
  34. TOXCORE_COMMIT='7d399cedcfd20f0d91a8caf386ae3c63f4dcf285'
  35. TOXID_REPO="https://github.com/bashrc/toxid"
  36. TOX_BOOTSTRAP_ID_FILE=/var/lib/tox-bootstrapd/pubkey.txt
  37. # These are some default nodes, but you can replace them with trusted nodes
  38. # as you prefer. See https://wiki.tox.im/Nodes
  39. TOX_NODES=
  40. #TOX_NODES=(
  41. # '192.254.75.102,2607:5600:284::2,33445,951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F,Tox RELENG,US'
  42. # '144.76.60.215,2a01:4f8:191:64d6::1,33445,04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F,sonOfRa,DE'
  43. #)
  44. TOXIC_REPO="https://github.com/Tox/toxic"
  45. TOXIC_COMMIT='68ce17a57fd05599968a299e5dc516e183ebcf75'
  46. TOXIC_FILE=/usr/local/bin/toxic
  47. QTOX_REPO="https://github.com/bashrc/qTox"
  48. QTOX_COMMIT='origin/bashrc/freedombone'
  49. tox_variables=(SYSTEM_TYPE
  50. TOXCORE_REPO
  51. MY_USERNAME
  52. ONION_ONLY
  53. INSTALLED_WITHIN_DOCKER
  54. TOX_PORT
  55. TOX_NODES)
  56. function logging_on_tox {
  57. echo -n ''
  58. }
  59. function logging_off_tox {
  60. echo -n ''
  61. }
  62. function remove_user_tox {
  63. remove_username="$1"
  64. if [ -d "/home/$remove_username/.config/tox" ]; then
  65. if [ -d "/home/$remove_username/.config/tox/chatlogs" ]; then
  66. shred -zu "/home/$remove_username/.config/tox/chatlogs/"*
  67. rm -rf "/home/$remove_username/.config/tox/chatlogs"
  68. fi
  69. shred -zu "/home/$remove_username/.config/tox/"*
  70. fi
  71. }
  72. function add_user_tox {
  73. new_username="$1"
  74. # Note: password isn't used
  75. #new_user_password="$2"
  76. USER_TOX_FILE=/home/${new_username}/.config/tox/data.tox
  77. if [ ! -f "$USER_TOX_FILE" ]; then
  78. mkdir -p "/home/${new_username}/.config/tox"
  79. chown -R "${new_username}":"${new_username}" "/home/${new_username}/.config"
  80. su -c "toxid -u ${new_username} -n data" - "$new_username"
  81. su -c "toxid --setuser ${new_username}" - "$new_username"
  82. fi
  83. }
  84. function run_client_tox {
  85. # create a tox user
  86. USER_TOX_FILE=/home/${USER}/.config/tox/data.tox
  87. if [ ! -f "$USER_TOX_FILE" ]; then
  88. mkdir -p "/home/${USER}/.config/tox"
  89. chown -R "${USER}":"${USER}" "/home/${USER}/.config"
  90. toxid -u "${USER}" -n data
  91. toxid --setuser "${USER}"
  92. fi
  93. toxic -f "$USER_TOX_FILE" --force-tcp --SOCKS5-proxy 127.0.0.1 9050
  94. }
  95. function install_interactive_tox {
  96. echo -n ''
  97. APP_INSTALLED=1
  98. }
  99. function configure_interactive_tox {
  100. if [ ! -f $TOX_BOOTSTRAP_ID_FILE ]; then
  101. return
  102. fi
  103. bootstrap_id=$(cat $TOX_BOOTSTRAP_ID_FILE)
  104. dialog --title $"Tox Bootstrap Node ID" \
  105. --msgbox $"\\n$bootstrap_id\\n\\nTo copy this hold down the shift key, select the ID and then right click and copy." 10 70
  106. }
  107. function mesh_tox_qtox {
  108. # shellcheck disable=SC2154
  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. chroot "$rootdir" apt-get clean
  118. chroot "$rootdir" /bin/rm -rf /var/lib/apt/lists/*
  119. chroot "$rootdir" apt-get clean
  120. # ffmpeg
  121. chroot "${rootdir}" apt-get -yq install build-essential
  122. chroot "${rootdir}" apt-get -yq install ffmpeg libmp3lame-dev libvorbis-dev libtheora-dev
  123. chroot "${rootdir}" apt-get -yq install libspeex-dev yasm pkg-config libopenjp2-7-dev
  124. chroot "${rootdir}" apt-get -yq install libx264-dev mjpegtools libmjpegtools-dev libav-tools
  125. 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
  126. if [ -d /repos/qtox ]; then
  127. mkdir "${rootdir}$INSTALL_DIR/qtox"
  128. cp -r -p /repos/qtox/. "${rootdir}$INSTALL_DIR/qtox"
  129. cd "${rootdir}$INSTALL_DIR/qtox" || exit 264826826
  130. git pull
  131. else
  132. git clone "$QTOX_REPO" "${rootdir}$INSTALL_DIR/qtox"
  133. fi
  134. if [ ! -d "${rootdir}$INSTALL_DIR/qtox" ]; then
  135. exit 72428
  136. fi
  137. cd "${rootdir}${INSTALL_DIR}/qtox" || exit 235745728
  138. git checkout $QTOX_COMMIT -b $QTOX_COMMIT
  139. chroot "${rootdir}" /bin/bash -x <<EOF
  140. cd ${INSTALL_DIR}/qtox
  141. export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig"
  142. cmake .
  143. make
  144. make install
  145. EOF
  146. if [ ! -f "${rootdir}/usr/local/bin/qtox" ]; then
  147. exit 75784
  148. fi
  149. cp "${rootdir}/usr/local/bin/qtox" "${rootdir}/usr/bin/qtox"
  150. }
  151. function reconfigure_tox {
  152. echo -n ''
  153. }
  154. function upgrade_tox {
  155. function_check set_repo_commit
  156. set_repo_commit "$INSTALL_DIR/toxcore" "toxcore commit" "$TOXCORE_COMMIT" $TOXCORE_REPO
  157. if [[ $(commit_has_changed "$INSTALL_DIR/toxcore" "toxcore commit" "$TOXCORE_COMMIT") == "1" ]]; then
  158. cd "$INSTALL_DIR/toxcore" || exit 53683563
  159. sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' "$rootdir/etc/systemd/system/tox-bootstrapd.service"
  160. ./autogen.sh
  161. if [ ! -d "$INSTALL_DIR/toxcore/_build" ]; then
  162. mkdir "$INSTALL_DIR/toxcore/_build"
  163. fi
  164. cd "$INSTALL_DIR/toxcore/_build" || return
  165. cmake ..
  166. make
  167. make install
  168. systemctl daemon-reload
  169. systemctl restart tox-bootstrapd.service
  170. fi
  171. function_check set_repo_commit
  172. set_repo_commit "$INSTALL_DIR/toxic" "Toxic commit" "$TOXIC_COMMIT" $TOXIC_REPO
  173. if [[ $(commit_has_changed "$INSTALL_DIR/toxic" "Toxic commit" "$TOXIC_COMMIT") == "1" ]]; then
  174. cd "$INSTALL_DIR/toxic" || exit 4684618
  175. make
  176. make install
  177. fi
  178. }
  179. function backup_local_tox {
  180. if [ -d /var/lib/tox-bootstrapd ]; then
  181. echo $"Backing up Tox"
  182. if [ -d /var/lib/tox-bootstrapd ]; then
  183. cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
  184. if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
  185. rm -rf /var/lib/tox-bootstrapd/Maildir
  186. fi
  187. fi
  188. function_check backup_directory_to_usb
  189. backup_directory_to_usb /var/lib/tox-bootstrapd tox
  190. echo $"Backup of Tox complete"
  191. fi
  192. }
  193. function restore_local_tox {
  194. if [ -d "$USB_MOUNT/backup/tox" ]; then
  195. echo $"Restoring Tox node settings"
  196. function_check restore_directory_from_usb
  197. #restore_directory_from_usb / tox
  198. if ! restore_directory_from_usb /var/lib/tox-bootstrapd tox; then
  199. function_check set_user_permissions
  200. set_user_permissions
  201. function_check backup_unmount_drive
  202. backup_unmount_drive
  203. exit 6393
  204. fi
  205. cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
  206. if ! systemctl restart tox-bootstrapd.service; then
  207. systemctl status tox-bootstrapd.service
  208. function_check set_user_permissions
  209. set_user_permissions
  210. function_check backup_unmount_drive
  211. backup_unmount_drive
  212. exit 59369
  213. fi
  214. fi
  215. }
  216. function backup_remote_tox {
  217. if [ -d /var/lib/tox-bootstrapd ]; then
  218. echo "Backing up Tox node settings"
  219. if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
  220. rm -rf /var/lib/tox-bootstrapd/Maildir
  221. fi
  222. cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
  223. backup_directory_to_friend /var/lib/tox-bootstrapd tox
  224. echo "Backup of Tox node settings complete"
  225. fi
  226. }
  227. function restore_remote_tox {
  228. if [ -d "$SERVER_DIRECTORY/backup/tox" ]; then
  229. echo $"Restoring Tox node settings"
  230. function_check restore_directory_from_friend
  231. #restore_directory_from_friend / tox
  232. if ! restore_directory_from_friend /var/lib/tox-bootstrapd tox; then
  233. exit 93653
  234. fi
  235. cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
  236. if ! systemctl restart tox-bootstrapd.service; then
  237. systemctl status tox-bootstrapd.service
  238. exit 59369
  239. fi
  240. echo $"Restore of Tox node complete"
  241. fi
  242. }
  243. function remove_tox_node {
  244. firewall_remove ${TOX_PORT}
  245. function_check remove_onion_service
  246. remove_onion_service tox ${TOX_PORT}
  247. if ! "${PROJECT_NAME}-mesh-install" -f tox_node --remove yes; then
  248. echo $'Failed to remove tox node'
  249. exit 763836
  250. fi
  251. remove_completion_param install_tox_node
  252. remove_completion_param configure_firewall_for_tox
  253. }
  254. function remove_tox_avahi {
  255. cd "$INSTALL_DIR/toxid" || exit 82456275
  256. make uninstall
  257. rm -rf "$INSTALL_DIR/toxid"
  258. sed -i '/tox_avahi/d' "$COMPLETION_FILE"
  259. }
  260. function remove_tox_client {
  261. if ! "${PROJECT_NAME}-mesh-install" -f tox_client --remove yes; 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[0]}") == "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=$(grep "TOX_PORT=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | 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[0]}"
  297. }
  298. function tox_avahi {
  299. if [[ $(is_completed "${FUNCNAME[0]}") == "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" || exit 131497953
  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" || exit 468276424526
  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" || exit 4782462846
  321. if ! make; 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[0]}"
  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. add_onion_service tox "${TOX_PORT}" "${TOX_PORT}"
  342. systemctl restart tox-bootstrapd.service
  343. sleep 3
  344. TOX_PUBLIC_KEY=$(grep tox /var/log/syslog | 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. SECONDS=0
  367. # obtain commits from the main file
  368. TOXCORE_COMMIT_MAIN=$(grep "TOXCORE_COMMIT=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | 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=$(grep "TOXID_REPO=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | 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=$(grep "TOX_PORT=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | 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=$(grep "TOXCORE_REPO=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | 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 cmake
  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 cmake
  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" || exit 2468246284
  429. git pull
  430. else
  431. if ! git clone "${TOXCORE_REPO}" "${rootdir}${INSTALL_DIR}/toxcore"; then
  432. exit 4292521
  433. fi
  434. fi
  435. fi
  436. cd "${rootdir}$INSTALL_DIR/toxcore" || exit 46824624
  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. ./autogen.sh
  442. mkdir _build
  443. cd _build || exit 1
  444. cmake ..
  445. make
  446. make install
  447. EOF
  448. else
  449. /bin/bash -x <<EOF
  450. cd ${INSTALL_DIR}/toxcore
  451. ./autogen.sh
  452. mkdir _build
  453. cd _build || exit 1
  454. cmake ..
  455. make
  456. make install
  457. EOF
  458. fi
  459. # shellcheck disable=SC2086
  460. cp -l $rootdir/usr/local/lib/libtoxcore* "$rootdir/usr/lib/"
  461. cp "${rootdir}${INSTALL_DIR}/toxcore/other/bootstrap_daemon/tox-bootstrapd.service" "$rootdir/etc/systemd/system/"
  462. sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' "$rootdir/etc/systemd/system/tox-bootstrapd.service"
  463. if [ "${rootdir}" ]; then
  464. chroot "${rootdir}" systemctl enable tox-bootstrapd.service
  465. else
  466. systemctl enable tox-bootstrapd.service
  467. fi
  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";
  494. echo 'keys_file_path = "/var/lib/tox-bootstrapd/keys"';
  495. echo 'pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"';
  496. echo 'enable_ipv6 = true';
  497. echo 'enable_ipv4_fallback = true';
  498. echo 'enable_lan_discovery = true';
  499. echo 'enable_tcp_relay = true';
  500. echo "tcp_relay_ports = [443, 3389, $TOX_PORT]";
  501. echo 'enable_motd = true';
  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. # shellcheck disable=SC2102
  509. nodes_str=$(echo $TOX_NODES[toxcount])
  510. toxval_ipv4=$(awk "$nodes_str" -F ',' '{print $1}')
  511. toxval_ipv6=$(awk "$nodes_str" -F ',' '{print $2}')
  512. toxval_port=$(awk "$nodes_str" -F ',' '{print $3}')
  513. toxval_pubkey=$(awk "$nodes_str" -F ',' '{print $4}')
  514. toxval_maintainer=$(awk "$nodes_str" -F ',' '{print $5}')
  515. echo "{ // $toxval_maintainer" >> "$TOX_BOOTSTRAP_CONFIG"
  516. if [[ $toxval_ipv6 != 'NONE' ]]; then
  517. echo " address = \"$toxval_ipv6\"" >> "$TOX_BOOTSTRAP_CONFIG"
  518. else
  519. echo " address = \"$toxval_ipv4\"" >> "$TOX_BOOTSTRAP_CONFIG"
  520. fi
  521. echo " port = $toxval_port" >> "$TOX_BOOTSTRAP_CONFIG"
  522. echo " public_key = \"$toxval_pubkey\"" >> "$TOX_BOOTSTRAP_CONFIG"
  523. toxcount=$((toxcount + 1))
  524. if [ "x${TOX_NODES[toxcount]}" != "x" ]; then
  525. echo "}," >> "$TOX_BOOTSTRAP_CONFIG"
  526. else
  527. echo "}" >> "$TOX_BOOTSTRAP_CONFIG"
  528. fi
  529. done
  530. echo ')' >> "$TOX_BOOTSTRAP_CONFIG"
  531. fi
  532. if [ -f "$rootdir/var/lib/tox-bootstrapd/keys" ]; then
  533. chmod 700 "$rootdir/var/lib/tox-bootstrapd/keys"
  534. fi
  535. }
  536. function mesh_tox_avahi {
  537. if [ ! -d "$rootdir/etc/avahi" ]; then
  538. echo $'tox_avahi: avahi is not installed'
  539. exit 87359
  540. fi
  541. if [ ! "$TOXID_REPO" ]; then
  542. echo $'No ToxID repo was specified'
  543. exit 78252
  544. fi
  545. if [ ! -d "${rootdir}${INSTALL_DIR}" ]; then
  546. mkdir -p "${rootdir}${INSTALL_DIR}"
  547. fi
  548. if [ -d /repos/toxid ]; then
  549. mkdir "${rootdir}${INSTALL_DIR}/toxid"
  550. cp -r -p /repos/toxid/. "${rootdir}${INSTALL_DIR}/toxid"
  551. cd "${rootdir}${INSTALL_DIR}/toxid" || exit 2468246
  552. git pull
  553. else
  554. git clone "${TOXID_REPO}" "${rootdir}${INSTALL_DIR}/toxid"
  555. fi
  556. if [ ! -d "${rootdir}${INSTALL_DIR}/toxid" ]; then
  557. echo $'Unable to clone toxid repo'
  558. exit 768352
  559. fi
  560. if [ "${rootdir}" ]; then
  561. chroot "${rootdir}" /bin/bash -x <<EOF
  562. cd ${INSTALL_DIR}/toxid
  563. make
  564. make install
  565. EOF
  566. else
  567. /bin/bash -x <<EOF
  568. cd ${INSTALL_DIR}/toxid
  569. make
  570. make install
  571. EOF
  572. fi
  573. if [ ! -f "$rootdir/usr/local/bin/toxid" ]; then
  574. echo $'toxid not found'
  575. exit 74370
  576. fi
  577. if [ ! -f "$rootdir/usr/local/bin/toxavahi" ]; then
  578. exit 3621729
  579. fi
  580. MESH_SYNC_COMMAND=$rootdir/usr/bin/mesh-sync
  581. { echo '#!/bin/bash';
  582. echo '/usr/local/bin/toxavahi 2> /dev/null';
  583. echo '/usr/local/bin/meshavahi 2> /dev/null'; } > "$MESH_SYNC_COMMAND"
  584. chmod +x "$MESH_SYNC_COMMAND"
  585. if ! grep -q "mesh-sync" "${rootdir}/etc/crontab"; then
  586. { echo "*/1 * * * * root /usr/bin/mesh-sync 2> /dev/null";
  587. echo "*/1 * * * * root ( sleep 20 ; /usr/bin/mesh-sync 2> /dev/null )";
  588. echo "*/1 * * * * root ( sleep 40 ; /usr/bin/mesh-sync 2> /dev/null )"; } >> "${rootdir}/etc/crontab"
  589. fi
  590. }
  591. function mesh_tox_client {
  592. TOXIC_FILE=$(grep "TOXIC_FILE=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F '=' '{print $2}')
  593. # obtain commits from the main file
  594. TOXIC_COMMIT_MAIN=$(grep "TOXIC_COMMIT=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F "'" '{print $2}')
  595. if [ ${#TOXIC_COMMIT_MAIN} -gt 10 ]; then
  596. TOXIC_COMMIT=$TOXIC_COMMIT_MAIN
  597. fi
  598. TOXIC_REPO_MAIN=$(grep "TOXIC_REPO=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F '"' '{print $2}')
  599. if [ ${#TOXIC_REPO_MAIN} -gt 5 ]; then
  600. TOXIC_REPO=$TOXIC_REPO_MAIN
  601. fi
  602. if [ "${rootdir}" ]; then
  603. chroot "${rootdir}" apt-get -yq install libncursesw5-dev libconfig-dev libqrencode-dev
  604. chroot "${rootdir}" apt-get -yq install libcurl4-openssl-dev libvpx-dev libopenal-dev
  605. chroot "${rootdir}" apt-get -yq install libqrencode-dev libpng-dev libncurses5-dev libalut-dev
  606. chroot "${rootdir}" apt-get -yq install libnotify-dev python3-dev
  607. toxic_disable_notify=0
  608. else
  609. apt-get -yq install libncursesw5-dev libconfig-dev libqrencode-dev
  610. apt-get -yq install libcurl4-openssl-dev libvpx-dev libopenal-dev
  611. apt-get -yq install libqrencode-dev libpng-dev libncurses5-dev libalut-dev python3-dev
  612. toxic_disable_notify=1
  613. fi
  614. TEMP_SCRIPT_NAME=fbtmp728353.sh
  615. TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
  616. { echo '#!/bin/bash';
  617. echo "mkdir -p $INSTALL_DIR";
  618. echo 'if [ -d /repos/toxic ]; then';
  619. echo " mkdir $INSTALL_DIR/toxic";
  620. echo " cp -r -p /repos/toxic/. $INSTALL_DIR/toxic";
  621. echo " cd $INSTALL_DIR/toxic";
  622. echo ' git pull';
  623. echo 'else';
  624. echo " git clone $TOXIC_REPO $INSTALL_DIR/toxic";
  625. echo 'fi';
  626. echo "cd $INSTALL_DIR/toxic";
  627. echo "git checkout $TOXIC_COMMIT -b $TOXIC_COMMIT";
  628. echo "export DISABLE_DESKTOP_NOTIFY=$toxic_disable_notify";
  629. echo "export DISABLE_AV=$toxic_disable_notify";
  630. echo "export DISABLE_X11=$toxic_disable_notify";
  631. echo "export DISABLE_SOUND_NOTIFY=$toxic_disable_notify";
  632. echo 'if ! make; then';
  633. echo ' exit 1';
  634. echo 'fi';
  635. echo 'make install';
  636. echo 'exit 0'; } > "$TEMP_SCRIPT"
  637. chmod +x $TEMP_SCRIPT
  638. cp "$TEMP_SCRIPT" "$rootdir/root/"
  639. TOXIC_FILE=$(grep "TOXIC_FILE=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F '=' '{print $2}')
  640. SECONDS=0
  641. if [ "${rootdir}" ]; then
  642. chroot "${rootdir}" "/root/$TEMP_SCRIPT_NAME"
  643. else
  644. /root/$TEMP_SCRIPT_NAME
  645. fi
  646. # shellcheck disable=SC2181
  647. if [ ! "$?" = "0" ]; then
  648. cat -n /root/fbtmp728353.sh
  649. duration=$SECONDS
  650. echo $"Toxic client compile failed at $((duration / 60)) minutes and $((duration % 60)) seconds elapsed."
  651. echo $'Unable to make tox client'
  652. rm $TEMP_SCRIPT
  653. exit 74872
  654. fi
  655. rm $TEMP_SCRIPT
  656. if [ ! -f "$rootdir$TOXIC_FILE" ]; then
  657. echo $"Tox client was not installed to $TOXIC_FILE"
  658. exit 63278
  659. fi
  660. duration=$SECONDS
  661. echo $"Toxic client compile $((duration / 60)) minutes and $((duration % 60)) seconds elapsed."
  662. }
  663. function enable_tox_repo {
  664. echo 'deb http://download.opensuse.org/repositories/home:/antonbatenev:/tox/Debian_9.0/ /' > "$rootdir/etc/apt/sources.list.d/tox.list"
  665. cat >> "$rootdir/root/gettoxkey.sh" <<EOF
  666. #!/bin/bash
  667. wget -q http://download.opensuse.org/repositories/home:antonbatenev:tox/Debian_9.0/Release.key -O- > /root/tox.key
  668. apt-key add /root/tox.key
  669. rm /root/tox.key
  670. EOF
  671. chroot "$rootdir" chmod +x /root/gettoxkey.sh
  672. chroot "$rootdir" /root/gettoxkey.sh
  673. chroot "$rootdir" apt-get update
  674. echo "Tox Repository Installed."
  675. }
  676. function install_tox {
  677. configure_firewall_for_tox
  678. if [ "$INSTALLING_MESH" ]; then
  679. mesh_tox_node
  680. mesh_tox_avahi
  681. mesh_tox_client
  682. else
  683. avoid_tor_restart=
  684. if [ -f "$IMAGE_PASSWORD_FILE" ]; then
  685. if [[ $ONION_ONLY != 'no' ]]; then
  686. avoid_tor_restart=1
  687. fi
  688. fi
  689. if [ $avoid_tor_restart ]; then
  690. "${PROJECT_NAME}-logging" on --onion
  691. else
  692. "${PROJECT_NAME}-logging" on
  693. fi
  694. install_tox_node
  695. if [ $avoid_tor_restart ]; then
  696. "${PROJECT_NAME}-logging" off --onion
  697. else
  698. "${PROJECT_NAME}-logging" off
  699. fi
  700. tox_avahi
  701. install_tox_client
  702. fi
  703. APP_INSTALLED=1
  704. }
  705. # NOTE: deliberately no exit 0