freedombone-app-tox 27KB

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