freedombone-app-tox 27KB

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