freedombone-app-tox 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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='505c5043828cf0fc43ee3f16279a131e50edc057'
  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
  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 /usr/local/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 '/toxavahi/d' /etc/crontab
  195. systemctl restart cron
  196. sed -i '/tox_avahi/d' $COMPLETION_FILE
  197. }
  198. function remove_tox_client {
  199. if ! grep -Fxq "install_tox_client" $COMPLETION_FILE; then
  200. return
  201. fi
  202. ${PROJECT_NAME}-mesh-install -f tox_client --remove yes
  203. if [ ! "$?" = "0" ]; then
  204. echo $'Could not remove Tox client'
  205. exit 737253
  206. fi
  207. sed -i '/install_tox_client/d' $COMPLETION_FILE
  208. sed -i '/Tox /d' $COMPLETION_FILE
  209. sed -i '/Toxic /d' $COMPLETION_FILE
  210. }
  211. function remove_tox {
  212. remove_tox_client
  213. remove_tox_avahi
  214. remove_tox_node
  215. }
  216. function configure_firewall_for_tox {
  217. if [ ! $INSTALLING_MESH ]; then
  218. if [ -f $COMPLETION_FILE ]; then
  219. if grep -Fxq "configure_firewall_for_tox" $COMPLETION_FILE; then
  220. return
  221. fi
  222. fi
  223. fi
  224. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  225. # docker does its own firewalling
  226. return
  227. fi
  228. if [[ $ONION_ONLY != "no" ]]; then
  229. return
  230. fi
  231. TOX_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}')
  232. if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
  233. TOX_PORT=$TOX_PORT_MAIN
  234. fi
  235. if [ ! $TOX_PORT ]; then
  236. echo $'No Tox port was specified'
  237. exit 32856
  238. fi
  239. iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT
  240. function_check save_firewall_settings
  241. save_firewall_settings
  242. OPEN_PORTS+=("Tox $TOX_PORT")
  243. if [ -f $COMPLETION_FILE ]; then
  244. echo 'configure_firewall_for_tox' >> $COMPLETION_FILE
  245. fi
  246. }
  247. function tox_avahi {
  248. if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
  249. return
  250. fi
  251. if grep -Fxq "tox_avahi" $COMPLETION_FILE; then
  252. return
  253. fi
  254. if [ ! -d /etc/avahi ]; then
  255. echo $'tox_avahi: avahi is not installed'
  256. exit 87359
  257. fi
  258. # install a command to obtain the Tox ID
  259. cd $INSTALL_DIR
  260. function_check git_clone
  261. git_clone $TOXID_REPO $INSTALL_DIR/toxid
  262. if [ ! -d $INSTALL_DIR/toxid ]; then
  263. exit 63921
  264. fi
  265. cd $INSTALL_DIR/toxid
  266. make
  267. if [ ! "$?" = "0" ]; then
  268. exit 58432
  269. fi
  270. make install
  271. toxavahi
  272. # publish regularly
  273. function_check cron_add_mins
  274. cron_add_mins 1 'toxavahi > /dev/null'
  275. systemctl restart avahi-daemon
  276. echo 'tox_avahi' >> $COMPLETION_FILE
  277. }
  278. function install_tox_node {
  279. if grep -Fxq "install_tox_node" $COMPLETION_FILE; then
  280. return
  281. fi
  282. function_check mesh_tox_node
  283. mesh_tox_node
  284. TOX_ONION_HOSTNAME=$(add_onion_service tox ${TOX_PORT} ${TOX_PORT})
  285. if ! grep -q "tox onion domain" $COMPLETION_FILE; then
  286. echo "tox onion domain:${TOX_ONION_HOSTNAME}" >> $COMPLETION_FILE
  287. else
  288. sed -i "s|tox onion domain.*|tox onion domain:${TOX_ONION_HOSTNAME}|g" $COMPLETION_FILE
  289. fi
  290. systemctl restart tox-bootstrapd.service
  291. TOX_PUBLIC_KEY=$(cat /var/log/syslog | grep tox | grep "Public Key" | awk -F ' ' '{print $8}' | tail -1)
  292. if [ ${#TOX_PUBLIC_KEY} -lt 30 ]; then
  293. echo $'Could not obtain the tox node public key'
  294. exit 6529
  295. fi
  296. # save the public key for later reference
  297. echo "$TOX_PUBLIC_KEY" > $TOX_BOOTSTRAP_ID_FILE
  298. function_check configure_firewall_for_tox
  299. configure_firewall_for_tox
  300. if ! grep -q $"Your Tox node public key is" /home/$MY_USERNAME/README; then
  301. echo '' >> /home/$MY_USERNAME/README
  302. echo '' >> /home/$MY_USERNAME/README
  303. echo 'Tox' >> /home/$MY_USERNAME/README
  304. echo '===' >> /home/$MY_USERNAME/README
  305. echo $"tox onion domain: ${TOX_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
  306. echo $"Your Tox node public key is: $TOX_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  307. echo $'In the Toxic client you can connect to it with:' >> /home/$MY_USERNAME/README
  308. echo " /connect $DEFAULT_DOMAIN_NAME.local $TOX_PORT $TOX_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  309. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
  310. chmod 600 /home/$MY_USERNAME/README
  311. fi
  312. function_check configure_firewall_for_tox
  313. configure_firewall_for_tox
  314. echo 'install_tox_node' >> $COMPLETION_FILE
  315. }
  316. function install_tox_client {
  317. if grep -Fxq "install_tox_client" $COMPLETION_FILE; then
  318. return
  319. fi
  320. function_check mesh_tox_client
  321. mesh_tox_client
  322. echo 'install_tox_client' >> $COMPLETION_FILE
  323. }
  324. function mesh_tox_node {
  325. # obtain commits from the main file
  326. TOXCORE_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXCORE_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  327. if [ ${#TOXCORE_COMMIT_MAIN} -gt 10 ]; then
  328. TOXCORE_COMMIT=$TOXCORE_COMMIT_MAIN
  329. fi
  330. if [ ! $TOXCORE_COMMIT ]; then
  331. echo $'No Tox commit was specified'
  332. exit 76325
  333. fi
  334. TOXID_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXID_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  335. if [ ${#TOXID_REPO_MAIN} -gt 5 ]; then
  336. TOXID_REPO=$TOXID_REPO_MAIN
  337. fi
  338. if [ ! $TOXID_REPO ]; then
  339. echo $'No ToxID repo was specified'
  340. exit 78252
  341. fi
  342. TOX_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}')
  343. if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
  344. TOX_PORT=$TOX_PORT_MAIN
  345. fi
  346. if [ ! $TOX_PORT ]; then
  347. echo $'No Tox port was specified'
  348. exit 32856
  349. fi
  350. TOXCORE_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXCORE_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  351. if [ ${#TOXCORE_REPO_MAIN} -gt 10 ]; then
  352. TOXCORE_REPO=$TOXCORE_REPO_MAIN
  353. fi
  354. if [ ! $TOXCORE_REPO ]; then
  355. echo $'No Tox repo was specified'
  356. exit 16865
  357. fi
  358. if [ ! $TOXCORE_COMMIT ]; then
  359. echo $'No Tox commit was specified'
  360. exit 76325
  361. fi
  362. if [ ! $TOXCORE_REPO ]; then
  363. echo $'No Tox repo was specified'
  364. exit 16865
  365. fi
  366. if [ $rootdir ]; then
  367. chroot ${rootdir} apt-get -y install build-essential libtool autotools-dev
  368. chroot ${rootdir} apt-get -y install automake checkinstall check git yasm
  369. chroot ${rootdir} apt-get -y install libsodium13 libsodium-dev libcap2-bin
  370. chroot ${rootdir} apt-get -y install libconfig9 libconfig-dev autoconf
  371. chroot ${rootdir} apt-get -y install libopus-dev libvpx-dev
  372. else
  373. apt-get -y install build-essential libtool autotools-dev
  374. apt-get -y install automake checkinstall check git yasm
  375. apt-get -y install libsodium13 libsodium-dev libcap2-bin
  376. apt-get -y install libconfig9 libconfig-dev autoconf
  377. apt-get -y install libopus-dev libvpx-dev
  378. fi
  379. if [ ! -d ${rootdir}${INSTALL_DIR} ]; then
  380. mkdir -p ${rootdir}${INSTALL_DIR}
  381. fi
  382. git clone ${TOXCORE_REPO} ${rootdir}${INSTALL_DIR}/toxcore
  383. if [ ! "$?" = "0" ]; then
  384. exit 429252
  385. fi
  386. cd ${rootdir}$INSTALL_DIR/toxcore
  387. git checkout $TOXCORE_COMMIT -b $TOXCORE_COMMIT
  388. if [ ${rootdir} ]; then
  389. chroot ${rootdir} /bin/bash -x <<EOF
  390. cd ${INSTALL_DIR}/toxcore
  391. autoreconf -i
  392. ./configure --enable-daemon
  393. make
  394. make install
  395. EOF
  396. else
  397. /bin/bash -x <<EOF
  398. cd ${INSTALL_DIR}/toxcore
  399. autoreconf -i
  400. ./configure --enable-daemon
  401. make
  402. make install
  403. EOF
  404. fi
  405. cp $rootdir/usr/local/lib/libtoxcore* $rootdir/usr/lib/
  406. cp ${rootdir}${INSTALL_DIR}/toxcore/other/bootstrap_daemon/tox-bootstrapd.service $rootdir/etc/systemd/system/
  407. sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' $rootdir/etc/systemd/system/tox-bootstrapd.service
  408. if [ ${rootdir} ]; then
  409. chroot ${rootdir} systemctl enable tox-bootstrapd.service
  410. else
  411. systemctl enable tox-bootstrapd.service
  412. fi
  413. SECONDS=0
  414. if [ ! -f $rootdir/usr/local/bin/tox-bootstrapd ]; then
  415. duration=$SECONDS
  416. echo $"Toxcore compile failed at $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  417. echo $'Unable to make toxcore'
  418. exit 73835
  419. fi
  420. duration=$SECONDS
  421. echo $"Toxcore compile $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  422. if [ ${rootdir} ]; then
  423. 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
  424. chroot ${rootdir} chmod 700 /var/lib/tox-bootstrapd
  425. else
  426. 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
  427. chmod 700 /var/lib/tox-bootstrapd
  428. fi
  429. # remove Maildir
  430. if [ -d $rootdir/var/lib/tox-bootstrapd/Maildir ]; then
  431. rm -rf $rootdir/var/lib/tox-bootstrapd/Maildir
  432. fi
  433. # create configuration file
  434. TOX_BOOTSTRAP_CONFIG=$rootdir/etc/tox-bootstrapd.conf
  435. echo "port = $TOX_PORT" > $TOX_BOOTSTRAP_CONFIG
  436. echo 'keys_file_path = "/var/lib/tox-bootstrapd/keys"' >> $TOX_BOOTSTRAP_CONFIG
  437. echo 'pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"' >> $TOX_BOOTSTRAP_CONFIG
  438. echo 'enable_ipv6 = true' >> $TOX_BOOTSTRAP_CONFIG
  439. echo 'enable_ipv4_fallback = true' >> $TOX_BOOTSTRAP_CONFIG
  440. echo 'enable_lan_discovery = true' >> $TOX_BOOTSTRAP_CONFIG
  441. echo 'enable_tcp_relay = true' >> $TOX_BOOTSTRAP_CONFIG
  442. echo "tcp_relay_ports = [443, 3389, $TOX_PORT]" >> $TOX_BOOTSTRAP_CONFIG
  443. echo 'enable_motd = true' >> $TOX_BOOTSTRAP_CONFIG
  444. echo 'motd = "tox-bootstrapd"' >> $TOX_BOOTSTRAP_CONFIG
  445. if [ $TOX_NODES ]; then
  446. echo 'bootstrap_nodes = (' >> $TOX_BOOTSTRAP_CONFIG
  447. toxcount=0
  448. while [ "x${TOX_NODES[toxcount]}" != "x" ]
  449. do
  450. toxval_ipv4=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $1}')
  451. toxval_ipv6=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $2}')
  452. toxval_port=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $3}')
  453. toxval_pubkey=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $4}')
  454. toxval_maintainer=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $5}')
  455. echo "{ // $toxval_maintainer" >> $TOX_BOOTSTRAP_CONFIG
  456. if [[ $toxval_ipv6 != 'NONE' ]]; then
  457. echo " address = \"$toxval_ipv6\"" >> $TOX_BOOTSTRAP_CONFIG
  458. else
  459. echo " address = \"$toxval_ipv4\"" >> $TOX_BOOTSTRAP_CONFIG
  460. fi
  461. echo " port = $toxval_port" >> $TOX_BOOTSTRAP_CONFIG
  462. echo " public_key = \"$toxval_pubkey\"" >> $TOX_BOOTSTRAP_CONFIG
  463. toxcount=$(( $toxcount + 1 ))
  464. if [ "x${TOX_NODES[toxcount]}" != "x" ]; then
  465. echo "}," >> $TOX_BOOTSTRAP_CONFIG
  466. else
  467. echo "}" >> $TOX_BOOTSTRAP_CONFIG
  468. fi
  469. done
  470. echo ')' >> $TOX_BOOTSTRAP_CONFIG
  471. fi
  472. }
  473. function mesh_tox_avahi {
  474. if [ ! -d $rootdir/etc/avahi ]; then
  475. echo $'tox_avahi: avahi is not installed'
  476. exit 87359
  477. fi
  478. if [ ! $TOXID_REPO ]; then
  479. echo $'No ToxID repo was specified'
  480. exit 78252
  481. fi
  482. if [ ! -d ${rootdir}${INSTALL_DIR} ]; then
  483. mkdir -p ${rootdir}${INSTALL_DIR}
  484. fi
  485. git clone ${TOXID_REPO} ${rootdir}${INSTALL_DIR}/toxid
  486. if [ ! -d ${rootdir}${INSTALL_DIR}/toxid ]; then
  487. echo $'Unable to clone toxid repo'
  488. exit 768352
  489. fi
  490. if [ ${rootdir} ]; then
  491. chroot ${rootdir} /bin/bash -x <<EOF
  492. cd ${INSTALL_DIR}/toxid
  493. make
  494. make install
  495. EOF
  496. else
  497. /bin/bash -x <<EOF
  498. cd ${INSTALL_DIR}/toxid
  499. make
  500. make install
  501. EOF
  502. fi
  503. if [ ! -f $rootdir/usr/local/bin/toxid ]; then
  504. echo $'toxid not found'
  505. exit 74370
  506. fi
  507. if [ ! -f $rootdir/usr/local/bin/toxavahi ]; then
  508. exit 3621729
  509. fi
  510. echo "*/1 * * * * root /usr/local/bin/toxavahi > /dev/null" >> $rootdir/etc/crontab
  511. }
  512. function mesh_tox_client {
  513. TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  514. # obtain commits from the main file
  515. TOXIC_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  516. if [ ${#TOXIC_COMMIT_MAIN} -gt 10 ]; then
  517. TOXIC_COMMIT=$TOXIC_COMMIT_MAIN
  518. fi
  519. TOXIC_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  520. if [ ${#TOXIC_REPO_MAIN} -gt 5 ]; then
  521. TOXIC_REPO=$TOXIC_REPO_MAIN
  522. fi
  523. if [ ${rootdir} ]; then
  524. chroot ${rootdir} apt-get -y install libncursesw5-dev libconfig-dev libqrencode-dev
  525. chroot ${rootdir} apt-get -y install libcurl4-openssl-dev libvpx-dev libopenal-dev
  526. else
  527. apt-get -y install libncursesw5-dev libconfig-dev libqrencode-dev
  528. apt-get -y install libcurl4-openssl-dev libvpx-dev libopenal-dev
  529. fi
  530. TEMP_SCRIPT_NAME=fbtmp728353.sh
  531. TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
  532. echo '#!/bin/bash' > $TEMP_SCRIPT
  533. echo "mkdir -p $INSTALL_DIR" >> $TEMP_SCRIPT
  534. echo "git clone $TOXIC_REPO $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
  535. echo "cd $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
  536. echo "git checkout $TOXIC_COMMIT -b $TOXIC_COMMIT" >> $TEMP_SCRIPT
  537. echo 'make' >> $TEMP_SCRIPT
  538. echo 'if [ ! "$?" = "0" ]; then' >> $TEMP_SCRIPT
  539. echo ' exit 1' >> $TEMP_SCRIPT
  540. echo 'fi' >> $TEMP_SCRIPT
  541. echo 'make install' >> $TEMP_SCRIPT
  542. echo 'exit 0' >> $TEMP_SCRIPT
  543. chmod +x $TEMP_SCRIPT
  544. cp $TEMP_SCRIPT $rootdir/root/
  545. TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  546. SECONDS=0
  547. if [ ${rootdir} ]; then
  548. chroot ${rootdir} /root/$TEMP_SCRIPT_NAME
  549. else
  550. /root/$TEMP_SCRIPT_NAME
  551. fi
  552. if [ ! "$?" = "0" ]; then
  553. duration=$SECONDS
  554. echo $"Toxic client compile failed at $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  555. echo $'Unable to make tox client'
  556. rm $TEMP_SCRIPT
  557. exit 74872
  558. fi
  559. rm $TEMP_SCRIPT
  560. if [ ! -f $rootdir$TOXIC_FILE ]; then
  561. echo $"Tox client was not installed to $TOXIC_FILE"
  562. exit 63278
  563. fi
  564. duration=$SECONDS
  565. echo $"Toxic client compile $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
  566. }
  567. function enable_tox_repo {
  568. echo 'deb http://download.opensuse.org/repositories/home:/antonbatenev:/tox/Debian_8.0/ /' > $rootdir/etc/apt/sources.list.d/tox.list
  569. chroot "$rootdir" wget -q http://download.opensuse.org/repositories/home:antonbatenev:tox/Debian_8.0/Release.key -O- | apt-key add -
  570. chroot "$rootdir" apt-get update
  571. echo "Tox Repository Installed."
  572. }
  573. function install_tox {
  574. if [ ! $INSTALLING_MESH ]; then
  575. if grep -Fxq "install_tox" $COMPLETION_FILE; then
  576. return
  577. fi
  578. fi
  579. configure_firewall_for_tox
  580. if [ $INSTALLING_MESH ]; then
  581. mesh_tox_node
  582. mesh_tox_avahi
  583. mesh_tox_client
  584. else
  585. install_tox_node
  586. tox_avahi
  587. install_tox_client
  588. fi
  589. echo 'install_tox' >> $COMPLETION_FILE
  590. }
  591. # NOTE: deliberately no exit 0