freedombone-app-tox 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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@robotics.uk.to>
  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 chat'
  31. TOX_PORT=33445
  32. TOXCORE_REPO="https://github.com/bashrc/toxcore"
  33. TOXCORE_COMMIT='d3fa9f82bda3a8746917502c525237427ba17d45'
  34. TOXID_REPO="https://github.com/bashrc/toxid"
  35. TOX_BOOTSTRAP_ID_FILE=/var/lib/tox-bootstrapd/pubkey.txt
  36. # These are some default nodes, but you can replace them with trusted nodes
  37. # as you prefer. See https://wiki.tox.im/Nodes
  38. TOX_NODES=
  39. #TOX_NODES=(
  40. # '192.254.75.102,2607:5600:284::2,33445,951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F,Tox RELENG,US'
  41. # '144.76.60.215,2a01:4f8:191:64d6::1,33445,04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F,sonOfRa,DE'
  42. #)
  43. TOXIC_REPO="https://github.com/Tox/toxic"
  44. TOXIC_COMMIT='cf16849b374e484a33a4dffa3dfb937b59d537f2'
  45. TOXIC_FILE=/usr/local/bin/toxic
  46. QTOX_REPO="https://github.com/bashrc/qTox"
  47. QTOX_COMMIT='7d951802d0106c17c76460b7011b3fa90cab1485'
  48. function mesh_install_ffmpeg
  49. {
  50. chroot "${rootdir}" apt-get -y remove ffmpeg libav-tools
  51. chroot "${rootdir}" apt-get -y install build-essential
  52. chroot "${rootdir}" apt-get -y install --reinstall libmp3lame-dev libvorbis-dev libtheora-dev libspeex-dev yasm pkg-config libopenjpeg-dev libx264-dev
  53. mkdir -p ${rootdir}$INSTALL_DIR/ffmpeg-release
  54. cd ${rootdir}$INSTALL_DIR
  55. wget http://ffmpeg.org/releases/ffmpeg-3.1.tar.bz2
  56. tar xvjf ffmpeg-3.1.tar.bz2
  57. chroot ${rootdir} /bin/bash -x <<EOF
  58. cd ${INSTALL_DIR}/ffmpeg-3.1
  59. ./configure --enable-gpl --enable-postproc --enable-swscale --enable-avfilter --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libx264 --enable-libspeex --enable-shared --enable-pthreads --enable-libopenjpeg
  60. make
  61. make install
  62. EOF
  63. chroot "${rootdir}" apt-get install libav-tools
  64. }
  65. function mesh_tox_qtox {
  66. if [ ! ${rootdir}$INSTALL_DIR ]; then
  67. INSTALL_DIR=${rootdir}/root/build
  68. fi
  69. if [ ! -d ${rootdir}$INSTALL_DIR ]; then
  70. mkdir -p ${rootdir}$INSTALL_DIR
  71. fi
  72. chroot "${rootdir}" apt-get -y 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 libicu52 libjpeg62-turbo libmng1 libmtdev1 libopenal1 libopus0 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpng12-0 libqrencode3 libsm6 libsodium13 libsqlite3-0 libssl1.0.0 libstdc++6 libtiff5 libudev1 libvpx1 libwayland-client0 libwayland-cursor0 libwayland-egl1-mesa libwebp5 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
  73. chroot "${rootdir}" apt-get -y 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 libavcodec56 libavcodec57 libavfilter-dev libavfilter6
  74. #chroot "${rootdir}" apt-get -y install --force-yes tox-ffmpeg-dev
  75. mesh_install_ffmpeg
  76. git clone $QTOX_REPO ${rootdir}$INSTALL_DIR/qtox
  77. if [ ! -d ${rootdir}$INSTALL_DIR/qtox ]; then
  78. exit 72428
  79. fi
  80. cd ${rootdir}${INSTALL_DIR}/qtox
  81. git checkout $QTOX_COMMIT -b $QTOX_COMMIT
  82. chroot ${rootdir} /bin/bash -x <<EOF
  83. cd ${INSTALL_DIR}/qtox
  84. qmake
  85. make
  86. make install
  87. EOF
  88. if [ ! -f ${rootdir}/usr/bin/qtox ]; then
  89. exit 75784
  90. fi
  91. }
  92. function reconfigure_tox {
  93. echo -n ''
  94. }
  95. function upgrade_tox {
  96. if ! grep -Fxq "install_tox" $COMPLETION_FILE; then
  97. return
  98. fi
  99. function_check set_repo_commit
  100. set_repo_commit $INSTALL_DIR/toxcore "toxcore commit" "$TOXCORE_COMMIT" $TOXCORE_REPO
  101. function_check set_repo_commit
  102. set_repo_commit $INSTALL_DIR/toxic "Toxic commit" "$TOXIC_COMMIT" $TOXIC_REPO
  103. }
  104. function backup_local_tox {
  105. if [ -d /var/lib/tox-bootstrapd ]; then
  106. echo $"Backing up Tox"
  107. if [ -d /var/lib/tox-bootstrapd ]; then
  108. cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
  109. if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
  110. rm -rf /var/lib/tox-bootstrapd/Maildir
  111. fi
  112. fi
  113. function_check backup_directory_to_usb
  114. backup_directory_to_usb /var/lib/tox-bootstrapd tox
  115. echo $"Backup of Tox complete"
  116. fi
  117. }
  118. function restore_local_tox {
  119. if [ -d $USB_MOUNT/backup/tox ]; then
  120. echo $"Restoring Tox node settings"
  121. function_check restore_directory_from_usb
  122. restore_directory_from_usb / tox
  123. if [ ! "$?" = "0" ]; then
  124. function_check set_user_permissions
  125. set_user_permissions
  126. function_check backup_unmount_drive
  127. backup_unmount_drive
  128. exit 6393
  129. fi
  130. cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
  131. systemctl restart tox-bootstrapd.service
  132. if [ ! "$?" = "0" ]; then
  133. systemctl status tox-bootstrapd.service
  134. function_check set_user_permissions
  135. set_user_permissions
  136. function_check backup_unmount_drive
  137. backup_unmount_drive
  138. exit 59369
  139. fi
  140. fi
  141. }
  142. function backup_remote_tox {
  143. if [ -d /var/lib/tox-bootstrapd ]; then
  144. echo "Backing up Tox node settings"
  145. if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
  146. rm -rf /var/lib/tox-bootstrapd/Maildir
  147. fi
  148. cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
  149. backup_directory_to_friend /var/lib/tox-bootstrapd tox
  150. echo "Backup of Tox node settings complete"
  151. fi
  152. }
  153. function restore_remote_tox {
  154. if [ -d $SERVER_DIRECTORY/backup/tox ]; then
  155. echo $"Restoring Tox node settings"
  156. function_check restore_directory_from_friend
  157. restore_directory_from_friend / tox
  158. if [ ! "$?" = "0" ]; then
  159. exit 93653
  160. fi
  161. cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
  162. systemctl restart tox-bootstrapd.service
  163. if [ ! "$?" = "0" ]; then
  164. systemctl status tox-bootstrapd.service
  165. exit 59369
  166. fi
  167. echo $"Restore of Tox node complete"
  168. fi
  169. }
  170. function remove_tox_node {
  171. if ! grep -Fxq "install_tox_node" $COMPLETION_FILE; then
  172. return
  173. fi
  174. iptables -D INPUT -p tcp --dport $TOX_PORT -j ACCEPT
  175. function_check save_firewall_settings
  176. save_firewall_settings
  177. function_check remove_onion_service
  178. remove_onion_service tox ${TOX_PORT}
  179. ${PROJECT_NAME}-mesh-install -f tox_node --remove yes
  180. if [ ! "$?" = "0" ]; then
  181. echo $'Failed to remove tox node'
  182. exit 763836
  183. fi
  184. sed -i '/install_tox_node/d' $COMPLETION_FILE
  185. sed -i '/configure_firewall_for_tox/d' $COMPLETION_FILE
  186. }
  187. function remove_tox_avahi {
  188. if ! grep -Fxq "tox_avahi" $COMPLETION_FILE; then
  189. return
  190. fi
  191. cd $INSTALL_DIR/toxid
  192. make uninstall
  193. rm -rf $INSTALL_DIR/toxid
  194. sed -i '/tox_avahi/d' $COMPLETION_FILE
  195. if [ -f /etc/systemd/system/mesh-sync.service ]; then
  196. systemctl stop mesh-sync
  197. systemctl disable mesh-sync
  198. rm -f /etc/systemd/system/mesh-sync.service
  199. systemctl daemon-reload
  200. fi
  201. }
  202. function remove_tox_client {
  203. if ! grep -Fxq "install_tox_client" $COMPLETION_FILE; then
  204. return
  205. fi
  206. ${PROJECT_NAME}-mesh-install -f tox_client --remove yes
  207. if [ ! "$?" = "0" ]; then
  208. echo $'Could not remove Tox client'
  209. exit 737253
  210. fi
  211. sed -i '/install_tox_client/d' $COMPLETION_FILE
  212. sed -i '/Tox /d' $COMPLETION_FILE
  213. sed -i '/Toxic /d' $COMPLETION_FILE
  214. }
  215. function remove_tox {
  216. remove_tox_client
  217. remove_tox_avahi
  218. remove_tox_node
  219. }
  220. function configure_firewall_for_tox {
  221. if [ ! $INSTALLING_MESH ]; then
  222. if [ -f $COMPLETION_FILE ]; then
  223. if grep -Fxq "configure_firewall_for_tox" $COMPLETION_FILE; then
  224. return
  225. fi
  226. fi
  227. fi
  228. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  229. # docker does its own firewalling
  230. return
  231. fi
  232. if [[ $ONION_ONLY != "no" ]]; then
  233. return
  234. fi
  235. TOX_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}')
  236. if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
  237. TOX_PORT=$TOX_PORT_MAIN
  238. fi
  239. if [ ! $TOX_PORT ]; then
  240. echo $'No Tox port was specified'
  241. exit 32856
  242. fi
  243. iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT
  244. function_check save_firewall_settings
  245. save_firewall_settings
  246. OPEN_PORTS+=("Tox $TOX_PORT")
  247. if [ -f $COMPLETION_FILE ]; then
  248. echo 'configure_firewall_for_tox' >> $COMPLETION_FILE
  249. fi
  250. }
  251. function tox_avahi {
  252. if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
  253. return
  254. fi
  255. if grep -Fxq "tox_avahi" $COMPLETION_FILE; then
  256. return
  257. fi
  258. if [ ! -d /etc/avahi ]; then
  259. echo $'tox_avahi: avahi is not installed'
  260. exit 87359
  261. fi
  262. # install a command to obtain the Tox ID
  263. cd $INSTALL_DIR
  264. function_check git_clone
  265. git_clone $TOXID_REPO $INSTALL_DIR/toxid
  266. if [ ! -d $INSTALL_DIR/toxid ]; then
  267. exit 63921
  268. fi
  269. cd $INSTALL_DIR/toxid
  270. make
  271. if [ ! "$?" = "0" ]; then
  272. exit 58432
  273. fi
  274. make install
  275. toxavahi
  276. # publish regularly
  277. function_check cron_add_mins
  278. cron_add_mins 1 'toxavahi > /dev/null'
  279. systemctl restart avahi-daemon
  280. echo 'tox_avahi' >> $COMPLETION_FILE
  281. }
  282. function install_tox_node {
  283. if grep -Fxq "install_tox_node" $COMPLETION_FILE; then
  284. return
  285. fi
  286. function_check mesh_tox_node
  287. mesh_tox_node
  288. TOX_ONION_HOSTNAME=$(add_onion_service tox ${TOX_PORT} ${TOX_PORT})
  289. if ! grep -q "tox onion domain" $COMPLETION_FILE; then
  290. echo "tox onion domain:${TOX_ONION_HOSTNAME}" >> $COMPLETION_FILE
  291. else
  292. sed -i "s|tox onion domain.*|tox onion domain:${TOX_ONION_HOSTNAME}|g" $COMPLETION_FILE
  293. fi
  294. systemctl restart tox-bootstrapd.service
  295. TOX_PUBLIC_KEY=$(cat /var/log/syslog | grep tox | grep "Public Key" | awk -F ' ' '{print $8}' | tail -1)
  296. if [ ${#TOX_PUBLIC_KEY} -lt 30 ]; then
  297. echo $'Could not obtain the tox node public key'
  298. exit 6529
  299. fi
  300. # save the public key for later reference
  301. echo "$TOX_PUBLIC_KEY" > $TOX_BOOTSTRAP_ID_FILE
  302. function_check configure_firewall_for_tox
  303. configure_firewall_for_tox
  304. if ! grep -q $"Your Tox node public key is" /home/$MY_USERNAME/README; then
  305. echo '' >> /home/$MY_USERNAME/README
  306. echo '' >> /home/$MY_USERNAME/README
  307. echo 'Tox' >> /home/$MY_USERNAME/README
  308. echo '===' >> /home/$MY_USERNAME/README
  309. echo $"tox onion domain: ${TOX_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
  310. echo $"Your Tox node public key is: $TOX_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  311. echo $'In the Toxic client you can connect to it with:' >> /home/$MY_USERNAME/README
  312. echo " /connect $DEFAULT_DOMAIN_NAME.local $TOX_PORT $TOX_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  313. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
  314. chmod 600 /home/$MY_USERNAME/README
  315. fi
  316. function_check configure_firewall_for_tox
  317. configure_firewall_for_tox
  318. echo 'install_tox_node' >> $COMPLETION_FILE
  319. }
  320. function install_tox_client {
  321. if grep -Fxq "install_tox_client" $COMPLETION_FILE; then
  322. return
  323. fi
  324. function_check mesh_tox_client
  325. mesh_tox_client
  326. echo 'install_tox_client' >> $COMPLETION_FILE
  327. }
  328. function mesh_tox_node {
  329. # obtain commits from the main file
  330. TOXCORE_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXCORE_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  331. if [ ${#TOXCORE_COMMIT_MAIN} -gt 10 ]; then
  332. TOXCORE_COMMIT=$TOXCORE_COMMIT_MAIN
  333. fi
  334. if [ ! $TOXCORE_COMMIT ]; then
  335. echo $'No Tox commit was specified'
  336. exit 76325
  337. fi
  338. TOXID_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXID_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  339. if [ ${#TOXID_REPO_MAIN} -gt 5 ]; then
  340. TOXID_REPO=$TOXID_REPO_MAIN
  341. fi
  342. if [ ! $TOXID_REPO ]; then
  343. echo $'No ToxID repo was specified'
  344. exit 78252
  345. fi
  346. TOX_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}')
  347. if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
  348. TOX_PORT=$TOX_PORT_MAIN
  349. fi
  350. if [ ! $TOX_PORT ]; then
  351. echo $'No Tox port was specified'
  352. exit 32856
  353. fi
  354. TOXCORE_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXCORE_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  355. if [ ${#TOXCORE_REPO_MAIN} -gt 10 ]; then
  356. TOXCORE_REPO=$TOXCORE_REPO_MAIN
  357. fi
  358. if [ ! $TOXCORE_REPO ]; then
  359. echo $'No Tox repo was specified'
  360. exit 16865
  361. fi
  362. if [ ! $TOXCORE_COMMIT ]; then
  363. echo $'No Tox commit was specified'
  364. exit 76325
  365. fi
  366. if [ ! $TOXCORE_REPO ]; then
  367. echo $'No Tox repo was specified'
  368. exit 16865
  369. fi
  370. if [ $rootdir ]; then
  371. chroot ${rootdir} apt-get -y install build-essential libtool autotools-dev
  372. chroot ${rootdir} apt-get -y install automake checkinstall check git yasm
  373. chroot ${rootdir} apt-get -y install libsodium13 libsodium-dev libcap2-bin
  374. chroot ${rootdir} apt-get -y install libconfig9 libconfig-dev autoconf
  375. chroot ${rootdir} apt-get -y install libopus-dev libvpx-dev
  376. else
  377. apt-get -y install build-essential libtool autotools-dev
  378. apt-get -y install automake checkinstall check git yasm
  379. apt-get -y install libsodium13 libsodium-dev libcap2-bin
  380. apt-get -y install libconfig9 libconfig-dev autoconf
  381. apt-get -y install libopus-dev libvpx-dev
  382. fi
  383. if [ ! -d ${rootdir}${INSTALL_DIR} ]; then
  384. mkdir -p ${rootdir}${INSTALL_DIR}
  385. fi
  386. git clone ${TOXCORE_REPO} ${rootdir}${INSTALL_DIR}/toxcore
  387. if [ ! "$?" = "0" ]; then
  388. exit 429252
  389. fi
  390. cd ${rootdir}$INSTALL_DIR/toxcore
  391. git checkout $TOXCORE_COMMIT -b $TOXCORE_COMMIT
  392. if [ ${rootdir} ]; then
  393. chroot ${rootdir} /bin/bash -x <<EOF
  394. cd ${INSTALL_DIR}/toxcore
  395. autoreconf -i
  396. ./configure --enable-daemon
  397. make
  398. make install
  399. EOF
  400. else
  401. /bin/bash -x <<EOF
  402. cd ${INSTALL_DIR}/toxcore
  403. autoreconf -i
  404. ./configure --enable-daemon
  405. make
  406. make install
  407. EOF
  408. fi
  409. cp $rootdir/usr/local/lib/libtoxcore* $rootdir/usr/lib/
  410. cp ${rootdir}${INSTALL_DIR}/toxcore/other/bootstrap_daemon/tox-bootstrapd.service $rootdir/etc/systemd/system/
  411. sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' $rootdir/etc/systemd/system/tox-bootstrapd.service
  412. if [ ${rootdir} ]; then
  413. chroot ${rootdir} systemctl enable tox-bootstrapd.service
  414. else
  415. systemctl enable tox-bootstrapd.service
  416. fi
  417. SECONDS=0
  418. if [ ! -f $rootdir/usr/local/bin/tox-bootstrapd ]; then
  419. duration=$SECONDS
  420. echo $"Toxcore compile failed at $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  421. echo $'Unable to make toxcore'
  422. exit 73835
  423. fi
  424. duration=$SECONDS
  425. echo $"Toxcore compile $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  426. if [ ${rootdir} ]; then
  427. chroot ${rootdir} 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
  428. chroot ${rootdir} chmod 700 /var/lib/tox-bootstrapd
  429. else
  430. 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
  431. chmod 700 /var/lib/tox-bootstrapd
  432. fi
  433. # remove Maildir
  434. if [ -d $rootdir/var/lib/tox-bootstrapd/Maildir ]; then
  435. rm -rf $rootdir/var/lib/tox-bootstrapd/Maildir
  436. fi
  437. # create configuration file
  438. TOX_BOOTSTRAP_CONFIG=$rootdir/etc/tox-bootstrapd.conf
  439. echo "port = $TOX_PORT" > $TOX_BOOTSTRAP_CONFIG
  440. echo 'keys_file_path = "/var/lib/tox-bootstrapd/keys"' >> $TOX_BOOTSTRAP_CONFIG
  441. echo 'pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"' >> $TOX_BOOTSTRAP_CONFIG
  442. echo 'enable_ipv6 = true' >> $TOX_BOOTSTRAP_CONFIG
  443. echo 'enable_ipv4_fallback = true' >> $TOX_BOOTSTRAP_CONFIG
  444. echo 'enable_lan_discovery = true' >> $TOX_BOOTSTRAP_CONFIG
  445. echo 'enable_tcp_relay = true' >> $TOX_BOOTSTRAP_CONFIG
  446. echo "tcp_relay_ports = [443, 3389, $TOX_PORT]" >> $TOX_BOOTSTRAP_CONFIG
  447. echo 'enable_motd = true' >> $TOX_BOOTSTRAP_CONFIG
  448. echo 'motd = "tox-bootstrapd"' >> $TOX_BOOTSTRAP_CONFIG
  449. if [ $TOX_NODES ]; then
  450. echo 'bootstrap_nodes = (' >> $TOX_BOOTSTRAP_CONFIG
  451. toxcount=0
  452. while [ "x${TOX_NODES[toxcount]}" != "x" ]
  453. do
  454. toxval_ipv4=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $1}')
  455. toxval_ipv6=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $2}')
  456. toxval_port=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $3}')
  457. toxval_pubkey=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $4}')
  458. toxval_maintainer=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $5}')
  459. echo "{ // $toxval_maintainer" >> $TOX_BOOTSTRAP_CONFIG
  460. if [[ $toxval_ipv6 != 'NONE' ]]; then
  461. echo " address = \"$toxval_ipv6\"" >> $TOX_BOOTSTRAP_CONFIG
  462. else
  463. echo " address = \"$toxval_ipv4\"" >> $TOX_BOOTSTRAP_CONFIG
  464. fi
  465. echo " port = $toxval_port" >> $TOX_BOOTSTRAP_CONFIG
  466. echo " public_key = \"$toxval_pubkey\"" >> $TOX_BOOTSTRAP_CONFIG
  467. toxcount=$(( $toxcount + 1 ))
  468. if [ "x${TOX_NODES[toxcount]}" != "x" ]; then
  469. echo "}," >> $TOX_BOOTSTRAP_CONFIG
  470. else
  471. echo "}" >> $TOX_BOOTSTRAP_CONFIG
  472. fi
  473. done
  474. echo ')' >> $TOX_BOOTSTRAP_CONFIG
  475. fi
  476. }
  477. function mesh_tox_avahi {
  478. if [ ! -d $rootdir/etc/avahi ]; then
  479. echo $'tox_avahi: avahi is not installed'
  480. exit 87359
  481. fi
  482. if [ ! $TOXID_REPO ]; then
  483. echo $'No ToxID repo was specified'
  484. exit 78252
  485. fi
  486. if [ ! -d ${rootdir}${INSTALL_DIR} ]; then
  487. mkdir -p ${rootdir}${INSTALL_DIR}
  488. fi
  489. git clone ${TOXID_REPO} ${rootdir}${INSTALL_DIR}/toxid
  490. if [ ! -d ${rootdir}${INSTALL_DIR}/toxid ]; then
  491. echo $'Unable to clone toxid repo'
  492. exit 768352
  493. fi
  494. if [ ${rootdir} ]; then
  495. chroot ${rootdir} /bin/bash -x <<EOF
  496. cd ${INSTALL_DIR}/toxid
  497. make
  498. make install
  499. EOF
  500. else
  501. /bin/bash -x <<EOF
  502. cd ${INSTALL_DIR}/toxid
  503. make
  504. make install
  505. EOF
  506. fi
  507. if [ ! -f $rootdir/usr/local/bin/toxid ]; then
  508. echo $'toxid not found'
  509. exit 74370
  510. fi
  511. if [ ! -f $rootdir/usr/local/bin/toxavahi ]; then
  512. exit 3621729
  513. fi
  514. MESH_SYNC_COMMAND=$rootdir/usr/bin/mesh-sync
  515. echo '#!/bin/bash' > $MESH_SYNC_COMMAND
  516. echo 'while true' >> $MESH_SYNC_COMMAND
  517. echo 'do' >> $MESH_SYNC_COMMAND
  518. echo ' /usr/bin/timeout 20 /usr/local/bin/toxavahi' >> $MESH_SYNC_COMMAND
  519. echo ' /usr/bin/timeout 20 /usr/local/bin/zeronetavahi' >> $MESH_SYNC_COMMAND
  520. echo ' sleep 5' >> $MESH_SYNC_COMMAND
  521. echo 'done' >> $MESH_SYNC_COMMAND
  522. chmod +x $MESH_SYNC_COMMAND
  523. if [ ! -f $rootdir/etc/systemd/system/mesh-sync.service ]; then
  524. MESH_SYNC_FILENAME=$rootdir/etc/systemd/system/mesh-sync.service
  525. echo '[Unit]' > $MESH_SYNC_FILENAME
  526. echo 'Description=mesh-sync - Service publications over avahi' >> $MESH_SYNC_FILENAME
  527. echo 'After=network.target' >> $MESH_SYNC_FILENAME
  528. echo '' >> $MESH_SYNC_FILENAME
  529. echo '[Service]' >> $MESH_SYNC_FILENAME
  530. echo 'User=root' >> $MESH_SYNC_FILENAME
  531. echo 'ExecStart=/usr/bin/mesh-sync' >> $MESH_SYNC_FILENAME
  532. echo 'Restart=on-failure' >> $MESH_SYNC_FILENAME
  533. echo 'SuccessExitStatus=3 4' >> $MESH_SYNC_FILENAME
  534. echo 'RestartForceExitStatus=3 4' >> $MESH_SYNC_FILENAME
  535. echo '' >> $MESH_SYNC_FILENAME
  536. echo '[Install]' >> $MESH_SYNC_FILENAME
  537. echo 'WantedBy=multi-user.target' >> $MESH_SYNC_FILENAME
  538. chroot "$rootdir" systemctl enable mesh-sync.service
  539. fi
  540. }
  541. function mesh_tox_client {
  542. TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  543. # obtain commits from the main file
  544. TOXIC_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  545. if [ ${#TOXIC_COMMIT_MAIN} -gt 10 ]; then
  546. TOXIC_COMMIT=$TOXIC_COMMIT_MAIN
  547. fi
  548. TOXIC_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  549. if [ ${#TOXIC_REPO_MAIN} -gt 5 ]; then
  550. TOXIC_REPO=$TOXIC_REPO_MAIN
  551. fi
  552. if [ ${rootdir} ]; then
  553. chroot ${rootdir} apt-get -y install libncursesw5-dev libconfig-dev libqrencode-dev
  554. chroot ${rootdir} apt-get -y install libcurl4-openssl-dev libvpx-dev libopenal-dev
  555. else
  556. apt-get -y install libncursesw5-dev libconfig-dev libqrencode-dev
  557. apt-get -y install libcurl4-openssl-dev libvpx-dev libopenal-dev
  558. fi
  559. TEMP_SCRIPT_NAME=fbtmp728353.sh
  560. TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
  561. echo '#!/bin/bash' > $TEMP_SCRIPT
  562. echo "mkdir -p $INSTALL_DIR" >> $TEMP_SCRIPT
  563. echo "git clone $TOXIC_REPO $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
  564. echo "cd $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
  565. echo "git checkout $TOXIC_COMMIT -b $TOXIC_COMMIT" >> $TEMP_SCRIPT
  566. echo 'make' >> $TEMP_SCRIPT
  567. echo 'if [ ! "$?" = "0" ]; then' >> $TEMP_SCRIPT
  568. echo ' exit 1' >> $TEMP_SCRIPT
  569. echo 'fi' >> $TEMP_SCRIPT
  570. echo 'make install' >> $TEMP_SCRIPT
  571. echo 'exit 0' >> $TEMP_SCRIPT
  572. chmod +x $TEMP_SCRIPT
  573. cp $TEMP_SCRIPT $rootdir/root/
  574. TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  575. SECONDS=0
  576. if [ ${rootdir} ]; then
  577. chroot ${rootdir} /root/$TEMP_SCRIPT_NAME
  578. else
  579. /root/$TEMP_SCRIPT_NAME
  580. fi
  581. if [ ! "$?" = "0" ]; then
  582. duration=$SECONDS
  583. echo $"Toxic client compile failed at $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  584. echo $'Unable to make tox client'
  585. rm $TEMP_SCRIPT
  586. exit 74872
  587. fi
  588. rm $TEMP_SCRIPT
  589. if [ ! -f $rootdir$TOXIC_FILE ]; then
  590. echo $"Tox client was not installed to $TOXIC_FILE"
  591. exit 63278
  592. fi
  593. duration=$SECONDS
  594. echo $"Toxic client compile $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  595. }
  596. function enable_tox_repo {
  597. echo 'deb http://download.opensuse.org/repositories/home:/antonbatenev:/tox/Debian_8.0/ /' > $rootdir/etc/apt/sources.list.d/tox.list
  598. chroot "$rootdir" wget -q http://download.opensuse.org/repositories/home:antonbatenev:tox/Debian_8.0/Release.key -O- | apt-key add -
  599. chroot "$rootdir" apt-get update
  600. echo "Tox Repository Installed."
  601. }
  602. function install_tox {
  603. if [ ! $INSTALLING_MESH ]; then
  604. if grep -Fxq "install_tox" $COMPLETION_FILE; then
  605. return
  606. fi
  607. fi
  608. configure_firewall_for_tox
  609. if [ $INSTALLING_MESH ]; then
  610. mesh_tox_node
  611. mesh_tox_avahi
  612. mesh_tox_client
  613. else
  614. install_tox_node
  615. tox_avahi
  616. install_tox_client
  617. fi
  618. echo 'install_tox' >> $COMPLETION_FILE
  619. }
  620. # NOTE: deliberately no exit 0