freedombone-mesh-install 46KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Installs mesh applications. This avoids duplicated functions
  12. # within freedombone and freedombone-image-customize and also
  13. # for client installs
  14. #
  15. # License
  16. # =======
  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. PROJECT_NAME='freedombone'
  31. COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
  32. export TEXTDOMAIN=${PROJECT_NAME}-mesh-install
  33. export TEXTDOMAINDIR="/usr/share/locale"
  34. # for mesh installs
  35. TRACKER_PORT=6969
  36. WIFI_CHANNEL=2
  37. WIFI_INTERFACE='wlan0'
  38. # B.A.T.M.A.N settings
  39. BATMAN_CELLID='02:BA:00:00:03:01'
  40. WIFI_SSID='mesh'
  41. # Babel
  42. BABEL_PORT=6696
  43. rootdir=''
  44. FN=
  45. CHROOT_PREFIX=''
  46. FRIENDS_MIRRORS_SERVER=
  47. # To avoid confusions these are obtained from the main project file
  48. TOXID_REPO=
  49. TOX_PORT=
  50. TOXCORE_REPO=
  51. TOXIC_REPO=
  52. TOXCORE_COMMIT=
  53. TOXIC_COMMIT=
  54. # These are some default nodes, but you can replace them with trusted nodes
  55. # as you prefer. See https://wiki.tox.im/Nodes
  56. TOX_NODES=
  57. #TOX_NODES=(
  58. # '192.254.75.102,2607:5600:284::2,33445,951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F,Tox RELENG,US'
  59. # '144.76.60.215,2a01:4f8:191:64d6::1,33445,04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F,sonOfRa,DE'
  60. #)
  61. # To avoid confusions these are obtained from the main project file
  62. ZERONET_REPO=
  63. ZERONET_COMMIT=
  64. ZERONET_PORT=
  65. # Directory where source code is downloaded and compiled
  66. INSTALL_DIR=$HOME/build
  67. MESH_INSTALL_DIR=/var/lib
  68. REMOVE='no'
  69. source /usr/local/bin/${PROJECT_NAME}-utils-git
  70. if [ -f /usr/bin/${PROJECT_NAME}-utils-git ]; then
  71. source /usr/bin/${PROJECT_NAME}-utils-git
  72. fi
  73. function show_help {
  74. echo ''
  75. echo $"${PROJECT_NAME}-mesh-install -f [function] -r [rootdir]"
  76. echo ''
  77. echo $'Runs a mesh network install function'
  78. echo ''
  79. echo $' -h --help Show help'
  80. echo $' -f --function [name] Name of the function to be run'
  81. echo $' -r --rootdir [directory] Root directory'
  82. echo $' -w --wifi [interface] e.g. wlan0'
  83. echo ''
  84. exit 0
  85. }
  86. function mesh_babel {
  87. $CHROOT_PREFIX apt-get -y install babeld
  88. babel_script=${rootdir}/var/lib/babel
  89. echo '#!/bin/bash' > $babel_script
  90. echo '' >> $babel_script
  91. echo 'if [[ $1 == "ls" || $1 == "list" ]]; then' >> $babel_script
  92. echo ' avahi-browse -atl' >> $babel_script
  93. echo ' exit 0' >> $babel_script
  94. echo 'fi' >> $babel_script
  95. echo '' >> $babel_script
  96. echo 'if [[ $1 == "start" ]]; then' >> $babel_script
  97. echo ' sed -i "s|#host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
  98. echo ' sed -i "s|host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
  99. echo ' sed -i "s|use-ipv4=.*|use-ipv4=yes|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
  100. echo ' sed -i "s|use-ipv6=.*|use-ipv6=no|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
  101. echo ' sed -i "s|hosts:.*|hosts: files mdns4_minimal dns mdns4 mdns|g" /etc/nsswitch.conf' >> $babel_script
  102. echo ' systemctl restart avahi-daemon' >> $babel_script
  103. echo 'fi' >> $babel_script
  104. echo '' >> $babel_script
  105. echo "IFACE=$WIFI_INTERFACE" >> $babel_script
  106. echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
  107. echo ' if grep -q "wlan1" /proc/net/dev; then' >> $babel_script
  108. echo ' IFACE=wlan1' >> $babel_script
  109. echo ' fi' >> $babel_script
  110. echo 'fi' >> $babel_script
  111. echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
  112. echo ' if grep -q "wlan2" /proc/net/dev; then' >> $babel_script
  113. echo ' IFACE=wlan2' >> $babel_script
  114. echo ' fi' >> $babel_script
  115. echo 'fi' >> $babel_script
  116. echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
  117. echo ' if grep -q "wlan3" /proc/net/dev; then' >> $babel_script
  118. echo ' IFACE=wlan3' >> $babel_script
  119. echo ' fi' >> $babel_script
  120. echo 'fi' >> $babel_script
  121. echo '' >> $babel_script
  122. echo 'if [[ ! grep -q "$IFACE" /proc/net/dev || $1 == "stop" ]]; then' >> $babel_script
  123. echo ' if ! grep -q "$IFACE" /proc/net/dev; then' >> $babel_script
  124. echo ' echo "Interface $IFACE was not found"' >> $babel_script
  125. echo ' else' >> $babel_script
  126. echo ' echo "Stopping"' >> $babel_script
  127. echo ' fi' >> $babel_script
  128. echo ' ifconfig $IFACE down' >> $babel_script
  129. echo ' pkill babeld' >> $babel_script
  130. echo ' systemctl restart network-manager' >> $babel_script
  131. echo ' exit 1' >> $babel_script
  132. echo 'fi' >> $babel_script
  133. echo '' >> $babel_script
  134. echo 'systemctl stop network-manager' >> $babel_script
  135. echo 'ifconfig $IFACE down' >> $babel_script
  136. echo -n 'iwconfig $IFACE mode ad-hoc channel ' >> $babel_script
  137. echo "$WIFI_CHANNEL essid \"$WIFI_SSID\"" >> $babel_script
  138. echo 'ifconfig $IFACE up' >> $babel_script
  139. echo -n 'ifconfig $IFACE:avahi ' >> $babel_script
  140. echo -n "$LOCAL_NETWORK_STATIC_IP_ADDRESS netmask " >> $babel_script
  141. echo '255.255.255.0 broadcast 192.168.13.255' >> $babel_script
  142. echo -n 'babeld -D $IFACE:avahi -p ' >> $babel_script
  143. echo -n "$BABEL_PORT -d 5 " >> $babel_script
  144. echo '$IFACE' >> $babel_script
  145. echo 'exit 0' >> $babel_script
  146. chmod +x $babel_script
  147. echo '[Unit]' > ${rootdir}/etc/systemd/system/babel.service
  148. echo 'Description=Babel Mesh' >> ${rootdir}/etc/systemd/system/babel.service
  149. echo '' >> ${rootdir}/etc/systemd/system/babel.service
  150. echo '[Service]' >> ${rootdir}/etc/systemd/system/babel.service
  151. echo 'Type=oneshot' >> ${rootdir}/etc/systemd/system/babel.service
  152. echo "ExecStart=$babel_script start" >> ${rootdir}/etc/systemd/system/babel.service
  153. echo "ExecStop=$babel_script stop" >> ${rootdir}/etc/systemd/system/babel.service
  154. echo 'RemainAfterExit=yes' >> ${rootdir}/etc/systemd/system/babel.service
  155. echo '' >> ${rootdir}/etc/systemd/system/babel.service
  156. echo '# Allow time for the server to start/stop' >> ${rootdir}/etc/systemd/system/babel.service
  157. echo 'TimeoutSec=300' >> ${rootdir}/etc/systemd/system/babel.service
  158. echo '' >> ${rootdir}/etc/systemd/system/babel.service
  159. echo '[Install]' >> /etc/systemd/system/babel.service
  160. echo 'WantedBy=multi-user.target' >> ${rootdir}/etc/systemd/system/babel.service
  161. $CHROOT_PREFIX systemctl enable babel
  162. }
  163. function mesh_babel_remove {
  164. $CHROOT_PREFIX systemctl stop babel
  165. $CHROOT_PREFIX apt-get -y remove --purge babeld
  166. rm ${rootdir}/var/lib/babel
  167. rm ${rootdir}/etc/systemd/system/babel.service
  168. }
  169. function mesh_avahi {
  170. $CHROOT_PREFIX apt-get -y install avahi-utils avahi-autoipd avahi-dnsconfd
  171. decarray=( 1 2 3 4 5 6 7 8 9 0 )
  172. PEER_ID=${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}
  173. sed -i "s|#host-name=.*|host-name=P$PEER_ID|g" $rootdir/etc/avahi/avahi-daemon.conf
  174. if [ ! -d $rootdir/etc/avahi/services ]; then
  175. mkdir -p $rootdir/etc/avahi/services
  176. fi
  177. # remove an avahi service which isn't used
  178. if [ -f $rootdir/etc/avahi/services/udisks.service ]; then
  179. rm $rootdir/etc/avahi/services/udisks.service
  180. fi
  181. # Add an ssh service
  182. echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > $rootdir/etc/avahi/services/ssh.service
  183. echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> $rootdir/etc/avahi/services/ssh.service
  184. echo '<service-group>' >> $rootdir/etc/avahi/services/ssh.service
  185. echo ' <name replace-wildcards="yes">%h SSH</name>' >> $rootdir/etc/avahi/services/ssh.service
  186. echo ' <service>' >> $rootdir/etc/avahi/services/ssh.service
  187. echo ' <type>_ssh._tcp</type>' >> $rootdir/etc/avahi/services/ssh.service
  188. echo " <port>$SSH_PORT</port>" >> $rootdir/etc/avahi/services/ssh.service
  189. echo ' </service>' >> $rootdir/etc/avahi/services/ssh.service
  190. echo '</service-group>' >> $rootdir/etc/avahi/services/ssh.service
  191. # keep the daemon running
  192. WATCHDOG_SCRIPT_NAME="keepon"
  193. echo '' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  194. echo '# keep avahi daemon running' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  195. echo 'AVAHI_RUNNING=$(pgrep avahi-daemon > /dev/null && echo Running)' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  196. echo 'if [ ! $AVAHI_RUNNING ]; then' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  197. echo ' systemctl start avahi-daemon' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  198. echo ' echo -n $CURRENT_DATE >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  199. echo ' echo " Avahi daemon restarted" >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  200. echo 'fi' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  201. chmod +x $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
  202. }
  203. function mesh_babel_client {
  204. # TODO to be fixed
  205. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  206. TOXIC_FILE=$(cat /usr/local/bin/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  207. else
  208. TOXIC_FILE=$(cat /usr/bin/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  209. fi
  210. if [ ! -f ${rootdir}/tmp/meshtype ]; then
  211. $CHROOT_PREFIX sudo apt-get -y install babeld
  212. if [ ! -f $TOXIC_FILE ]; then
  213. $CHROOT_PREFIX sudo apt-get -y install toxic
  214. fi
  215. CURR_DIR=$(pwd)
  216. if [ ! -f ~/develop/toxid ]; then
  217. if [ ! -f ~/develop ]; then
  218. mkdir ~/develop
  219. fi
  220. cd ~/develop
  221. git_clone $TOXID_REPO ~/develop/toxid
  222. fi
  223. cd ~/develop/toxid
  224. sudo make install
  225. cd $CURR_DIR
  226. fi
  227. babel_script=${rootdir}/tmp/babel
  228. echo '#!/bin/bash' > $babel_script
  229. echo '' >> $babel_script
  230. echo 'if [[ $1 == "ls" || $1 == "list" ]]; then' >> $babel_script
  231. echo ' avahi-browse -atl' >> $babel_script
  232. echo ' exit 0' >> $babel_script
  233. echo 'fi' >> $babel_script
  234. echo '' >> $babel_script
  235. echo 'if [[ $1 == "start" ]]; then' >> $babel_script
  236. echo ' if [ -f /tmp/meshtype ] ; then' >> $babel_script
  237. echo ' echo "Mesh already running"' >> $babel_script
  238. echo ' return' >> $babel_script
  239. echo ' fi' >> $batman_script
  240. echo ' # install avahi' >> $babel_script
  241. echo ' apt-get -y install avahi-utils avahi-autoipd avahi-daemon avahi-dnsconfd bittornado' >> $babel_script
  242. echo ' sed -i "s|#host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
  243. echo ' sed -i "s|host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
  244. echo ' if [ -f /bin/systemctl ]; then' >> $babel_script
  245. echo ' systemctl restart avahi-daemon' >> $babel_script
  246. echo ' else' >> $babel_script
  247. echo ' service avahi-daemon restart' >> $babel_script
  248. echo ' fi' >> $babel_script
  249. echo ' echo "babel" > /tmp/meshtype' >> $babel_script
  250. echo 'fi' >> $babel_script
  251. echo '' >> $babel_script
  252. echo "IFACE=$WIFI_INTERFACE" >> $babel_script
  253. echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
  254. echo ' if grep -q "wlan1" /proc/net/dev; then' >> $babel_script
  255. echo ' IFACE=wlan1' >> $babel_script
  256. echo ' fi' >> $babel_script
  257. echo 'fi' >> $babel_script
  258. echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
  259. echo ' if grep -q "wlan2" /proc/net/dev; then' >> $babel_script
  260. echo ' IFACE=wlan2' >> $babel_script
  261. echo ' fi' >> $babel_script
  262. echo 'fi' >> $babel_script
  263. echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
  264. echo ' if grep -q "wlan3" /proc/net/dev; then' >> $babel_script
  265. echo ' IFACE=wlan3' >> $babel_script
  266. echo ' fi' >> $babel_script
  267. echo 'fi' >> $babel_script
  268. echo '' >> $babel_script
  269. echo 'if [[ ! grep -q "$IFACE" /proc/net/dev || $1 == "stop" ]]; then' >> $babel_script
  270. echo ' if ! grep -q "$IFACE" /proc/net/dev; then' >> $babel_script
  271. echo ' echo "Interface $IFACE was not found"' >> $babel_script
  272. echo ' else' >> $babel_script
  273. echo ' echo "Stopping"' >> $babel_script
  274. echo ' fi' >> $babel_script
  275. echo ' ifconfig $IFACE down' >> $babel_script
  276. echo ' pkill babeld' >> $babel_script
  277. echo ' if [ -f /bin/systemctl ]; then' >> $babel_script
  278. echo ' systemctl restart network-manager' >> $babel_script
  279. echo ' else' >> $babel_script
  280. echo ' service network-manager restart' >> $babel_script
  281. echo ' fi' >> $babel_script
  282. echo ' exit 1' >> $babel_script
  283. echo 'fi' >> $babel_script
  284. echo '' >> $babel_script
  285. echo 'if [ -f /bin/systemctl ]; then' >> $babel_script
  286. echo ' systemctl stop network-manager' >> $babel_script
  287. echo 'else' >> $babel_script
  288. echo ' service network-manager stop' >> $babel_script
  289. echo 'fi' >> $babel_script
  290. echo 'ifconfig $IFACE down' >> $babel_script
  291. echo -n 'iwconfig $IFACE mode ad-hoc channel ' >> $babel_script
  292. echo "$WIFI_CHANNEL essid \"$WIFI_SSID\"" >> $babel_script
  293. echo 'ifconfig $IFACE up' >> $babel_script
  294. echo -n 'ifconfig $IFACE:avahi ' >> $babel_script
  295. echo -n "$LOCAL_NETWORK_STATIC_IP_ADDRESS netmask " >> $babel_script
  296. echo '255.255.255.0 broadcast 192.168.13.255' >> $babel_script
  297. echo -n 'babeld -D $IFACE:avahi -p ' >> $babel_script
  298. echo -n "$BABEL_PORT -d 5 " >> $babel_script
  299. echo '$IFACE' >> $babel_script
  300. echo 'exit 0' >> $babel_script
  301. chmod +x $babel_script
  302. sudo mv $babel_script ${rootdir}/usr/bin/babel
  303. }
  304. function mesh_batman_remove {
  305. systemctl stop batman
  306. rm $rootdir/var/lib/batman
  307. rm $rootdir/etc/systemd/system/batman.service
  308. }
  309. function mesh_batman {
  310. $CHROOT_PREFIX apt-get -y install iproute bridge-utils libnetfilter-conntrack3 batctl
  311. $CHROOT_PREFIX apt-get -y install python-dev libevent-dev ebtables python-pip git
  312. $CHROOT_PREFIX apt-get -y install wireless-tools rfkill
  313. if ! grep -q "batman_adv" $rootdir/etc/modules; then
  314. echo 'batman_adv' >> $rootdir/etc/modules
  315. fi
  316. BATMAN_SCRIPT=$rootdir/var/lib/batman
  317. if [ -f /usr/local/bin/${PROJECT_NAME}-mesh-batman ]; then
  318. cp /usr/local/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
  319. else
  320. cp /usr/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
  321. fi
  322. BATMAN_DAEMON=$rootdir/etc/systemd/system/batman.service
  323. echo '[Unit]' > $BATMAN_DAEMON
  324. echo 'Description=B.A.T.M.A.N. Advanced' >> $BATMAN_DAEMON
  325. echo 'After=network.target' >> $BATMAN_DAEMON
  326. echo '' >> $BATMAN_DAEMON
  327. echo '[Service]' >> $BATMAN_DAEMON
  328. echo 'RemainAfterExit=yes' >> $BATMAN_DAEMON
  329. echo "ExecStart=/var/lib/batman start" >> $BATMAN_DAEMON
  330. echo "ExecStop=/var/lib/batman stop" >> $BATMAN_DAEMON
  331. echo 'Restart=on-failure' >> $BATMAN_DAEMON
  332. echo 'SuccessExitStatus=3 4' >> $BATMAN_DAEMON
  333. echo 'RestartForceExitStatus=3 4' >> $BATMAN_DAEMON
  334. echo '' >> $BATMAN_DAEMON
  335. echo '# Allow time for the server to start/stop' >> $BATMAN_DAEMON
  336. echo 'TimeoutSec=300' >> $BATMAN_DAEMON
  337. echo '' >> $BATMAN_DAEMON
  338. echo '[Install]' >> $BATMAN_DAEMON
  339. echo 'WantedBy=multi-user.target' >> $BATMAN_DAEMON
  340. $CHROOT_PREFIX systemctl enable batman
  341. }
  342. function mesh_firewall {
  343. FIREWALL_FILENAME=${rootdir}/etc/systemd/system/meshfirewall.service
  344. MESH_FIREWALL_SCRIPT=${rootdir}/usr/bin/mesh-firewall
  345. echo '#!/bin/bash' > $MESH_FIREWALL_SCRIPT
  346. echo 'iptables -P INPUT ACCEPT' >> $MESH_FIREWALL_SCRIPT
  347. echo 'ip6tables -P INPUT ACCEPT' >> $MESH_FIREWALL_SCRIPT
  348. echo 'iptables -F' >> $MESH_FIREWALL_SCRIPT
  349. echo 'ip6tables -F' >> $MESH_FIREWALL_SCRIPT
  350. echo 'iptables -t nat -F' >> $MESH_FIREWALL_SCRIPT
  351. echo 'ip6tables -t nat -F' >> $MESH_FIREWALL_SCRIPT
  352. echo 'iptables -X' >> $MESH_FIREWALL_SCRIPT
  353. echo 'ip6tables -X' >> $MESH_FIREWALL_SCRIPT
  354. echo 'iptables -P INPUT DROP' >> $MESH_FIREWALL_SCRIPT
  355. echo 'ip6tables -P INPUT DROP' >> $MESH_FIREWALL_SCRIPT
  356. echo 'iptables -A INPUT -i lo -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
  357. echo 'iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
  358. echo '' >> $MESH_FIREWALL_SCRIPT
  359. echo '# Make sure incoming tcp connections are SYN packets' >> $MESH_FIREWALL_SCRIPT
  360. echo 'iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP' >> $MESH_FIREWALL_SCRIPT
  361. echo '' >> $MESH_FIREWALL_SCRIPT
  362. echo '# Drop packets with incoming fragments' >> $MESH_FIREWALL_SCRIPT
  363. echo 'iptables -A INPUT -f -j DROP' >> $MESH_FIREWALL_SCRIPT
  364. echo '' >> $MESH_FIREWALL_SCRIPT
  365. echo '# Drop bogons' >> $MESH_FIREWALL_SCRIPT
  366. echo 'iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP' >> $MESH_FIREWALL_SCRIPT
  367. echo 'iptables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP' >> $MESH_FIREWALL_SCRIPT
  368. echo 'iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP' >> $MESH_FIREWALL_SCRIPT
  369. echo '' >> $MESH_FIREWALL_SCRIPT
  370. echo '# Incoming malformed NULL packets:' >> $MESH_FIREWALL_SCRIPT
  371. echo 'iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP' >> $MESH_FIREWALL_SCRIPT
  372. echo '' >> $MESH_FIREWALL_SCRIPT
  373. echo "iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
  374. echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
  375. echo "iptables -A INPUT -i $WIFI_INTERFACE -p tcp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
  376. echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
  377. echo "iptables -A INPUT -i $WIFI_INTERFACE -p tcp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
  378. echo "iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport 1900 -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
  379. chmod +x $MESH_FIREWALL_SCRIPT
  380. echo '[Unit]' > $FIREWALL_FILENAME
  381. echo 'Description=Mesh Firewall' >> $FIREWALL_FILENAME
  382. echo '' >> $FIREWALL_FILENAME
  383. echo '[Service]' >> $FIREWALL_FILENAME
  384. echo 'Type=oneshot' >> $FIREWALL_FILENAME
  385. echo 'ExecStart=/usr/bin/mesh-firewall' >> $FIREWALL_FILENAME
  386. echo 'RemainAfterExit=no' >> $FIREWALL_FILENAME
  387. echo '' >> $FIREWALL_FILENAME
  388. echo 'TimeoutSec=30' >> $FIREWALL_FILENAME
  389. echo '' >> $FIREWALL_FILENAME
  390. echo '[Install]' >> $FIREWALL_FILENAME
  391. echo 'WantedBy=multi-user.target' >> $FIREWALL_FILENAME
  392. $CHROOT_PREFIX systemctl enable meshfirewall
  393. }
  394. function mesh_tox_node {
  395. # obtain commits from the main file
  396. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  397. TOXCORE_COMMIT_MAIN=$(cat /usr/local/bin/${PROJECT_NAME}-app-tox | grep "TOXCORE_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  398. else
  399. TOXCORE_COMMIT_MAIN=$(cat /usr/bin/${PROJECT_NAME}-app-tox | grep "TOXCORE_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  400. fi
  401. if [ ${#TOXCORE_COMMIT_MAIN} -gt 10 ]; then
  402. TOXCORE_COMMIT=$TOXCORE_COMMIT_MAIN
  403. fi
  404. if [ ! $TOXCORE_COMMIT ]; then
  405. echo $'No Tox commit was specified'
  406. exit 76325
  407. fi
  408. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  409. TOXID_REPO_MAIN=$(cat /usr/local/bin/${PROJECT_NAME}-app-tox | grep "TOXID_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  410. else
  411. TOXID_REPO_MAIN=$(cat /usr/bin/${PROJECT_NAME}-app-tox | grep "TOXID_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  412. fi
  413. if [ ${#TOXID_REPO_MAIN} -gt 5 ]; then
  414. TOXID_REPO=$TOXID_REPO_MAIN
  415. fi
  416. if [ ! $TOXID_REPO ]; then
  417. echo $'No ToxID repo was specified'
  418. exit 78252
  419. fi
  420. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  421. TOX_PORT_MAIN=$(cat /usr/local/bin/${PROJECT_NAME}-app-tox | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}')
  422. else
  423. TOX_PORT_MAIN=$(cat /usr/bin/${PROJECT_NAME}-app-tox | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}')
  424. fi
  425. if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
  426. TOX_PORT=$TOX_PORT_MAIN
  427. fi
  428. if [ ! $TOX_PORT ]; then
  429. echo $'No Tox port was specified'
  430. exit 32856
  431. fi
  432. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  433. TOXCORE_REPO_MAIN=$(cat /usr/local/bin/${PROJECT_NAME}-app-tox | grep "TOXCORE_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  434. else
  435. TOXCORE_REPO_MAIN=$(cat /usr/bin/${PROJECT_NAME}-app-tox | grep "TOXCORE_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  436. fi
  437. if [ ${#TOXCORE_REPO_MAIN} -gt 10 ]; then
  438. TOXCORE_REPO=$TOXCORE_REPO_MAIN
  439. fi
  440. if [ ! $TOXCORE_REPO ]; then
  441. echo $'No Tox repo was specified'
  442. exit 16865
  443. fi
  444. $CHROOT_PREFIX apt-get -y install build-essential libtool autotools-dev
  445. $CHROOT_PREFIX apt-get -y install automake checkinstall check git yasm
  446. $CHROOT_PREFIX apt-get -y install libsodium13 libsodium-dev libcap2-bin
  447. $CHROOT_PREFIX apt-get -y install libconfig9 libconfig-dev
  448. $CHROOT_PREFIX mkdir -p $INSTALL_DIR
  449. $CHROOT_PREFIX git_clone $TOXCORE_REPO $INSTALL_DIR/toxcore
  450. $CHROOT_PREFIX cd $INSTALL_DIR/toxcore
  451. $CHROOT_PREFIX git checkout $TOXCORE_COMMIT -b $TOXCORE_COMMIT
  452. $CHROOT_PREFIX autoreconf -i
  453. $CHROOT_PREFIX ./configure --enable-daemon --disable-av
  454. $CHROOT_PREFIX make clean
  455. $CHROOT_PREFIX make -k
  456. if [ ! "$?" = "0" ]; then
  457. return
  458. fi
  459. $CHROOT_PREFIX make install
  460. $CHROOT_PREFIX cp /usr/local/lib/libtoxcore* /usr/lib/
  461. if [ ! -f $rootdir/usr/local/bin/tox-bootstrapd ]; then
  462. echo $"File not found /usr/local/bin/tox-bootstrapd"
  463. return
  464. fi
  465. $CHROOT_PREFIX 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
  466. $CHROOT_PREFIX chmod 700 /var/lib/tox-bootstrapd
  467. if [ ! -f $rootdir/$INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.conf ]; then
  468. echo $"File not found $INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.conf"
  469. fi
  470. # remove Maildir
  471. if [ -d $rootdir/var/lib/tox-bootstrapd/Maildir ]; then
  472. rm -rf $rootdir/var/lib/tox-bootstrapd/Maildir
  473. fi
  474. # create configuration file
  475. TOX_BOOTSTRAP_CONFIG=${rootdir}/etc/tox-bootstrapd.conf
  476. echo "port = $TOX_PORT" > $TOX_BOOTSTRAP_CONFIG
  477. echo 'keys_file_path = "/var/lib/tox-bootstrapd/keys"' >> $TOX_BOOTSTRAP_CONFIG
  478. echo 'pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"' >> $TOX_BOOTSTRAP_CONFIG
  479. echo 'enable_ipv6 = true' >> $TOX_BOOTSTRAP_CONFIG
  480. echo 'enable_ipv4_fallback = true' >> $TOX_BOOTSTRAP_CONFIG
  481. echo 'enable_lan_discovery = true' >> $TOX_BOOTSTRAP_CONFIG
  482. echo 'enable_tcp_relay = true' >> $TOX_BOOTSTRAP_CONFIG
  483. echo "tcp_relay_ports = [443, 3389, $TOX_PORT]" >> $TOX_BOOTSTRAP_CONFIG
  484. echo 'enable_motd = true' >> $TOX_BOOTSTRAP_CONFIG
  485. echo 'motd = "tox-bootstrapd"' >> $TOX_BOOTSTRAP_CONFIG
  486. if [ $TOX_NODES ]; then
  487. echo 'bootstrap_nodes = (' >> $TOX_BOOTSTRAP_CONFIG
  488. toxcount=0
  489. while [ "x${TOX_NODES[toxcount]}" != "x" ]
  490. do
  491. toxval_ipv4=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $1}')
  492. toxval_ipv6=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $2}')
  493. toxval_port=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $3}')
  494. toxval_pubkey=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $4}')
  495. toxval_maintainer=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $5}')
  496. echo "{ // $toxval_maintainer" >> $TOX_BOOTSTRAP_CONFIG
  497. if [[ $toxval_ipv6 != 'NONE' ]]; then
  498. echo " address = \"$toxval_ipv6\"" >> $TOX_BOOTSTRAP_CONFIG
  499. else
  500. echo " address = \"$toxval_ipv4\"" >> $TOX_BOOTSTRAP_CONFIG
  501. fi
  502. echo " port = $toxval_port" >> $TOX_BOOTSTRAP_CONFIG
  503. echo " public_key = \"$toxval_pubkey\"" >> $TOX_BOOTSTRAP_CONFIG
  504. toxcount=$(( $toxcount + 1 ))
  505. if [ "x${TOX_NODES[toxcount]}" != "x" ]; then
  506. echo "}," >> $TOX_BOOTSTRAP_CONFIG
  507. else
  508. echo "}" >> $TOX_BOOTSTRAP_CONFIG
  509. fi
  510. done
  511. echo ')' >> $TOX_BOOTSTRAP_CONFIG
  512. fi
  513. if [ ! -f $rootdir/$INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.service ]; then
  514. echo $"File not found $INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.service"
  515. return
  516. fi
  517. cp $rootdir/$INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.service $rootdir/etc/systemd/system/
  518. sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' $rootdir/etc/systemd/system/tox-bootstrapd.service
  519. $CHROOT_PREFIX systemctl daemon-reload
  520. $CHROOT_PREFIX systemctl enable tox-bootstrapd.service
  521. }
  522. function mesh_tox_client {
  523. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  524. TOXIC_FILE=$(cat /usr/local/bin/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  525. else
  526. TOXIC_FILE=$(cat /usr/bin/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  527. fi
  528. # obtain commits from the main file
  529. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  530. TOXIC_COMMIT_MAIN=$(cat /usr/local/bin/${PROJECT_NAME}-app-tox | grep "TOXIC_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  531. else
  532. TOXIC_COMMIT_MAIN=$(cat /usr/bin/${PROJECT_NAME}-app-tox | grep "TOXIC_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  533. fi
  534. if [ ${#TOXIC_COMMIT_MAIN} -gt 10 ]; then
  535. TOXIC_COMMIT=$TOXIC_COMMIT_MAIN
  536. fi
  537. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  538. TOXIC_REPO_MAIN=$(cat /usr/local/bin/${PROJECT_NAME}-app-tox | grep "TOXIC_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  539. else
  540. TOXIC_REPO_MAIN=$(cat /usr/bin/${PROJECT_NAME}-app-tox | grep "TOXIC_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  541. fi
  542. if [ ${#TOXIC_REPO_MAIN} -gt 5 ]; then
  543. TOXIC_REPO=$TOXIC_REPO_MAIN
  544. fi
  545. $CHROOT_PREFIX apt-get -y install libncursesw5-dev libconfig-dev libqrencode-dev
  546. $CHROOT_PREFIX apt-get -y install libcurl4-openssl-dev libvpx-dev libopenal-dev
  547. $CHROOT_PREFIX git_clone $TOXIC_REPO $INSTALL_DIR/toxic
  548. $CHROOT_PREFIX cd $INSTALL_DIR/toxic
  549. $CHROOT_PREFIX git checkout $TOXIC_COMMIT -b $TOXIC_COMMIT
  550. if ! grep -q "Toxic commit" $rootdir$COMPLETION_FILE; then
  551. echo "Toxic commit:$TOXIC_COMMIT" >> $rootdir$COMPLETION_FILE
  552. else
  553. sed -i "s|Toxic commit.*|Toxic commit:$TOXIC_COMMIT|g" $rootdir$COMPLETION_FILE
  554. fi
  555. $CHROOT_PREFIX make clean
  556. $CHROOT_PREFIX make -k
  557. if [ ! -f $INSTALL_DIR/toxic/build/toxic ]; then
  558. exit 74872
  559. fi
  560. $CHROOT_PREFIX make install
  561. if [ ! -f $TOXIC_FILE ]; then
  562. echo $'Tox client was not installed'
  563. exit 63278
  564. fi
  565. }
  566. function enable_tox_repo {
  567. sudo sh -c "echo 'deb http://download.opensuse.org/repositories/home:/antonbatenev:/tox/Debian_8.0/ /' > /etc/apt/sources.list.d/tox.list"
  568. wget http://download.opensuse.org/repositories/home:antonbatenev:tox/Debian_8.0/Release.key
  569. sudo sh -c "apt-key add - < Release.key"
  570. sudo apt-get update
  571. echo "Tox Repository Installed."
  572. }
  573. function mesh_tox_client_qtox {
  574. enable_tox_repo
  575. sudo apt-get -y install qtox
  576. echo "qTox Installed."
  577. }
  578. function mesh_tox_client_toxic_from_repo {
  579. enable_tox_repo
  580. sudo apt-get -y install toxic
  581. echo "Toxic Installed."
  582. }
  583. function mesh_zeronet {
  584. # obtain commits from the main file
  585. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  586. ZERONET_COMMIT_MAIN=$(cat /usr/local/bin/${PROJECT_NAME}-app-zeronet | grep "ZERONET_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  587. else
  588. ZERONET_COMMIT_MAIN=$(cat /usr/bin/${PROJECT_NAME}-app-zeronet | grep "ZERONET_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
  589. fi
  590. if [ ${#ZERONET_COMMIT_MAIN} -gt 10 ]; then
  591. ZERONET_COMMIT=$ZERONET_COMMIT_MAIN
  592. fi
  593. if [ ! $ZERONET_COMMIT ]; then
  594. echo $'No Tox commit was specified'
  595. exit 37046
  596. fi
  597. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  598. ZERONET_REPO_MAIN=$(cat /usr/local/bin/${PROJECT_NAME}-app-zeronet | grep "ZERONET_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  599. else
  600. ZERONET_REPO_MAIN=$(cat /usr/bin/${PROJECT_NAME}-app-zeronet | grep "ZERONET_REPO=" | head -n 1 | awk -F '"' '{print $2}')
  601. fi
  602. if [ ${#ZERONET_REPO_MAIN} -gt 5 ]; then
  603. ZERONET_REPO=$ZERONET_REPO_MAIN
  604. fi
  605. if [ ! $ZERONET_REPO ]; then
  606. echo $'No Tox commit was specified'
  607. exit 37046
  608. fi
  609. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  610. ZERONET_PORT_MAIN=$(cat /usr/local/bin/${PROJECT_NAME}-app-zeronet | grep "ZERONET_PORT=" | head -n 1 | awk -F '=' '{print $2}')
  611. else
  612. ZERONET_PORT_MAIN=$(cat /usr/bin/${PROJECT_NAME}-app-zeronet | grep "ZERONET_PORT=" | head -n 1 | awk -F '=' '{print $2}')
  613. fi
  614. if [ ${#ZERONET_PORT_MAIN} -gt 1 ]; then
  615. ZERONET_PORT=$ZERONET_PORT_MAIN
  616. fi
  617. if [ ! $ZERONET_PORT ]; then
  618. echo $'No zeronet port was specified'
  619. exit 67433
  620. fi
  621. $CHROOT_PREFIX apt-get -y install python python-msgpack python-gevent
  622. $CHROOT_PREFIX apt-get -y install python-pip bittornado
  623. $CHROOT_PREFIX pip install msgpack-python --upgrade
  624. $CHROOT_PREFIX pip install gevent --upgrade
  625. $CHROOT_PREFIX useradd -d $MESH_INSTALL_DIR/zeronet/ -s /bin/false zeronet
  626. git_clone $ZERONET_REPO $rootdir$MESH_INSTALL_DIR/zeronet
  627. if [ ! -d $rootdir$MESH_INSTALL_DIR/zeronet ]; then
  628. echo 'WARNING: Unable to clone zeronet'
  629. return
  630. fi
  631. cd $rootdir$MESH_INSTALL_DIR/zeronet
  632. git checkout $ZERONET_COMMIT -b $ZERONET_COMMIT
  633. if ! grep -q "ZeroNet commit" $COMPLETION_FILE; then
  634. echo "ZeroNet commit:$ZERONET_COMMIT" >> $rootdir$COMPLETION_FILE
  635. else
  636. sed -i "s/ZeroNet commit.*/ZeroNet commit:$ZERONET_COMMIT/g" $COMPLETION_FILE
  637. fi
  638. chown -R zeronet:zeronet $rootdir$MESH_INSTALL_DIR/zeronet
  639. # Hack to ensure that the file access port is opened
  640. # This is because zeronet normally relies on an internet site
  641. # to do this, but on a purely local mesh the internet isn't available
  642. sed -i 's|fileserver_port = 0|fileserver_port = config.fileserver_port\n sys.modules["main"].file_server.port_opened = True|g' $rootdir$MESH_INSTALL_DIR/zeronet/src/Site/Site.py
  643. ZERPNET_DAEMON=$rootdir/etc/systemd/system/zeronet.service
  644. echo '[Unit]' > $ZERONET_DAEMON
  645. echo 'Description=Zeronet Server' >> $ZERONET_DAEMON
  646. echo 'After=syslog.target' >> $ZERONET_DAEMON
  647. echo 'After=network.target' >> $ZERONET_DAEMON
  648. echo '[Service]' >> $ZERONET_DAEMON
  649. echo 'Type=simple' >> $ZERONET_DAEMON
  650. echo 'User=zeronet' >> $ZERONET_DAEMON
  651. echo 'Group=zeronet' >> $ZERONET_DAEMON
  652. echo "WorkingDirectory=$MESH_INSTALL_DIR/zeronet" >> $ZERONET_DAEMON
  653. echo "ExecStart=/usr/bin/python zeronet.py --ip_external replace.local --trackers_file $MESH_INSTALL_DIR/zeronet/bootstrap" >> $ZERONET_DAEMON
  654. echo '' >> $ZERONET_DAEMON
  655. echo 'TimeoutSec=300' >> $ZERONET_DAEMON
  656. echo '' >> $ZERONET_DAEMON
  657. echo '[Install]' >> $ZERONET_DAEMON
  658. echo 'WantedBy=multi-user.target' >> $ZERONET_DAEMON
  659. TRACKER_DAEMON=$rootdir/etc/systemd/system/tracker.service
  660. echo '[Unit]' > $TRACKER_DAEMON
  661. echo 'Description=Torrent Tracker' >> $TRACKER_DAEMON
  662. echo 'After=syslog.target' >> $TRACKER_DAEMON
  663. echo 'After=network.target' >> $TRACKER_DAEMON
  664. echo '[Service]' >> $TRACKER_DAEMON
  665. echo 'Type=simple' >> $TRACKER_DAEMON
  666. echo 'User=tracker' >> $TRACKER_DAEMON
  667. echo 'Group=tracker' >> $TRACKER_DAEMON
  668. echo "WorkingDirectory=$MESH_INSTALL_DIR/tracker" >> $TRACKER_DAEMON
  669. echo "ExecStart=/usr/bin/bttrack --port $TRACKER_PORT --dfile $MESH_INSTALL_DIR/tracker/dstate --logfile $MESH_INSTALL_DIR/tracker/tracker.log --nat_check 0 --scrape_allowed full --ipv6_enabled 0" >> $TRACKER_DAEMON
  670. echo '' >> $TRACKER_DAEMON
  671. echo 'TimeoutSec=300' >> $TRACKER_DAEMON
  672. echo '' >> $TRACKER_DAEMON
  673. echo '[Install]' >> $TRACKER_DAEMON
  674. echo 'WantedBy=multi-user.target' >> $TRACKER_DAEMON
  675. $CHROOT_PREFIX useradd -d $MESH_INSTALL_DIR/tracker/ -s /bin/false tracker
  676. if [ ! -d $rootdir$MESH_INSTALL_DIR/tracker ]; then
  677. mkdir $rootdir$MESH_INSTALL_DIR/tracker
  678. fi
  679. chown -R tracker:tracker $rootdir$MESH_INSTALL_DIR/tracker
  680. # publish regularly
  681. echo "* * * * * root zeronetavahi > /dev/null" >> $rootdir/etc/crontab
  682. $CHROOT_PREFIX systemctl enable tracker.service
  683. $CHROOT_PREFIX systemctl enable zeronet.service
  684. }
  685. function mesh_batman_client {
  686. if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
  687. TOXIC_FILE=$(cat /usr/local/bin/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  688. else
  689. TOXIC_FILE=$(cat /usr/bin/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
  690. fi
  691. if [ ! -f ${rootdir}/tmp/meshtype ]; then
  692. $CHROOT_PREFIX sudo apt-get -y install iproute bridge-utils libnetfilter-conntrack3 batctl
  693. $CHROOT_PREFIX sudo apt-get -y install python-dev libevent-dev ebtables python-pip
  694. $CHROOT_PREFIX sudo apt-get -y install wireless-tools rfkill
  695. if [ ! -f $TOXIC_FILE ]; then
  696. $CHROOT_PREFIX sudo apt-get -y install toxic
  697. fi
  698. fi
  699. BATMAN_SCRIPT=${rootdir}/tmp/batman
  700. echo '#!/bin/bash' > $BATMAN_SCRIPT
  701. echo '' >> $BATMAN_SCRIPT
  702. echo 'if [[ $1 == "start" ]]; then' >> $BATMAN_SCRIPT
  703. echo ' # install avahi' >> $BATMAN_SCRIPT
  704. echo ' apt-get -y install avahi-utils avahi-autoipd avahi-daemon avahi-dnsconfd bittornado' >> $BATMAN_SCRIPT
  705. echo ' sed -i "s|#host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $BATMAN_SCRIPT
  706. echo ' sed -i "s|host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $BATMAN_SCRIPT
  707. echo ' sed -i "s|use-ipv4=.*|use-ipv4=yes|g" /etc/avahi/avahi-daemon.conf' >> $BATMAN_SCRIPT
  708. echo ' sed -i "s|use-ipv6=.*|use-ipv6=no|g" /etc/avahi/avahi-daemon.conf' >> $BATMAN_SCRIPT
  709. echo ' sed -i "s|#disallow-other-stacks=.*|disallow-other-stacks=yes|g" /etc/avahi/avahi-daemon.conf' >> $BATMAN_SCRIPT
  710. echo ' sed -i "s|hosts:.*|hosts: files mdns4_minimal dns mdns4 mdns|g" /etc/nsswitch.conf' >> $BATMAN_SCRIPT
  711. echo ' if [ -f /bin/systemctl ]; then' >> $BATMAN_SCRIPT
  712. echo ' systemctl restart avahi-daemon' >> $BATMAN_SCRIPT
  713. echo ' else' >> $BATMAN_SCRIPT
  714. echo ' service avahi-daemon restart' >> $BATMAN_SCRIPT
  715. echo ' fi' >> $BATMAN_SCRIPT
  716. echo 'fi' >> $BATMAN_SCRIPT
  717. echo '' >> $BATMAN_SCRIPT
  718. echo '# Mesh definition' >> $BATMAN_SCRIPT
  719. echo "WIFI_SSID=$WIFI_SSID" >> $BATMAN_SCRIPT
  720. echo "CELLID=$BATMAN_CELLID" >> $BATMAN_SCRIPT
  721. echo "CHANNEL=$WIFI_CHANNEL" >> $BATMAN_SCRIPT
  722. echo '' >> $BATMAN_SCRIPT
  723. echo '# Ethernet bridge definition (bridged to bat0)' >> $BATMAN_SCRIPT
  724. echo 'BRIDGE=br-mesh' >> $BATMAN_SCRIPT
  725. echo "IFACE=$WIFI_INTERFACE" >> $BATMAN_SCRIPT
  726. echo 'EIFACE=eth0' >> $BATMAN_SCRIPT
  727. echo '' >> $BATMAN_SCRIPT
  728. echo 'if [[ $IFACE == "wlan0" ]]; then' >> $BATMAN_SCRIPT
  729. echo ' if grep -q "wlan1" /proc/net/dev; then' >> $BATMAN_SCRIPT
  730. echo ' IFACE=wlan1' >> $BATMAN_SCRIPT
  731. echo ' fi' >> $BATMAN_SCRIPT
  732. echo 'fi' >> $BATMAN_SCRIPT
  733. echo 'if [[ $IFACE == "wlan0" ]]; then' >> $BATMAN_SCRIPT
  734. echo ' if grep -q "wlan2" /proc/net/dev; then' >> $BATMAN_SCRIPT
  735. echo ' IFACE=wlan2' >> $BATMAN_SCRIPT
  736. echo ' fi' >> $BATMAN_SCRIPT
  737. echo 'fi' >> $BATMAN_SCRIPT
  738. echo 'if [[ $IFACE == "wlan0" ]]; then' >> $BATMAN_SCRIPT
  739. echo ' if grep -q "wlan3" /proc/net/dev; then' >> $BATMAN_SCRIPT
  740. echo ' IFACE=wlan3' >> $BATMAN_SCRIPT
  741. echo ' fi' >> $BATMAN_SCRIPT
  742. echo 'fi' >> $BATMAN_SCRIPT
  743. echo '' >> $BATMAN_SCRIPT
  744. echo 'if [ -e /etc/default/batctl ]; then' >> $BATMAN_SCRIPT
  745. echo ' . /etc/default/batctl' >> $BATMAN_SCRIPT
  746. echo 'fi' >> $BATMAN_SCRIPT
  747. echo '' >> $BATMAN_SCRIPT
  748. echo 'start() {' >> $BATMAN_SCRIPT
  749. echo ' if [ -f /tmp/meshtype ] ; then' >> $BATMAN_SCRIPT
  750. echo ' echo "Mesh already running"' >> $BATMAN_SCRIPT
  751. echo ' return' >> $BATMAN_SCRIPT
  752. echo ' fi' >> $BATMAN_SCRIPT
  753. echo ' if [ -z "$IFACE" ] ; then' >> $BATMAN_SCRIPT
  754. echo ' echo "error: unable to find wifi interface, not enabling batman-adv mesh"' >> $BATMAN_SCRIPT
  755. echo ' return' >> $BATMAN_SCRIPT
  756. echo ' fi' >> $BATMAN_SCRIPT
  757. echo ' echo "info: enabling batman-adv mesh network $WIFI_SSID on $IFACE"' >> $BATMAN_SCRIPT
  758. echo ' if [ -f /bin/systemctl ]; then' >> $BATMAN_SCRIPT
  759. echo ' systemctl stop network-manager' >> $BATMAN_SCRIPT
  760. echo ' else' >> $BATMAN_SCRIPT
  761. echo ' service network-manager stop' >> $BATMAN_SCRIPT
  762. echo ' fi' >> $BATMAN_SCRIPT
  763. echo ' sleep 5' >> $BATMAN_SCRIPT
  764. echo '' >> $BATMAN_SCRIPT
  765. echo " # remove an avahi service which isn't used" >> $BATMAN_SCRIPT
  766. echo ' if [ -f /etc/avahi/services/udisks.service ]; then' >> $BATMAN_SCRIPT
  767. echo ' sudo rm /etc/avahi/services/udisks.service' >> $BATMAN_SCRIPT
  768. echo ' fi' >> $BATMAN_SCRIPT
  769. echo '' >> $BATMAN_SCRIPT
  770. echo ' # Might have to re-enable wifi' >> $BATMAN_SCRIPT
  771. echo ' rfkill unblock $(rfkill list|awk -F: "/phy/ {print $1}") || true' >> $BATMAN_SCRIPT
  772. echo '' >> $BATMAN_SCRIPT
  773. echo ' ifconfig $IFACE down' >> $BATMAN_SCRIPT
  774. echo ' ifconfig $IFACE mtu 1532' >> $BATMAN_SCRIPT
  775. echo ' iwconfig $IFACE enc off' >> $BATMAN_SCRIPT
  776. echo ' iwconfig $IFACE mode ad-hoc essid $WIFI_SSID channel $CHANNEL' >> $BATMAN_SCRIPT
  777. echo ' sleep 1' >> $BATMAN_SCRIPT
  778. echo ' iwconfig $IFACE ap $CELLID' >> $BATMAN_SCRIPT
  779. echo '' >> $BATMAN_SCRIPT
  780. echo ' modprobe batman-adv' >> $BATMAN_SCRIPT
  781. echo ' batctl if add $IFACE' >> $BATMAN_SCRIPT
  782. echo ' ifconfig $IFACE up' >> $BATMAN_SCRIPT
  783. echo ' avahi-autoipd --force-bind --daemonize --wait $BRIDGE' >> $BATMAN_SCRIPT
  784. echo ' avahi-autoipd --force-bind --daemonize --wait $IFACE' >> $BATMAN_SCRIPT
  785. echo ' ifconfig bat0 up promisc' >> $BATMAN_SCRIPT
  786. echo '' >> $BATMAN_SCRIPT
  787. echo ' #Use persistent HWAddr' >> $BATMAN_SCRIPT
  788. echo ' ether_new=$(ifconfig eth0 | grep HWaddr | sed -e "s/.*HWaddr //")' >> $BATMAN_SCRIPT
  789. echo ' if [ ! -f /var/lib/mesh-node/bat0 ]; then' >> $BATMAN_SCRIPT
  790. echo ' mkdir /var/lib/mesh-node' >> $BATMAN_SCRIPT
  791. echo ' echo "${ether_new}" > /var/lib/mesh-node/bat0' >> $BATMAN_SCRIPT
  792. echo ' else' >> $BATMAN_SCRIPT
  793. echo ' ether=$(cat /var/lib/mesh-node/bat0)' >> $BATMAN_SCRIPT
  794. echo ' ifconfig bat0 hw ether ${ether}' >> $BATMAN_SCRIPT
  795. echo ' fi' >> $BATMAN_SCRIPT
  796. echo '' >> $BATMAN_SCRIPT
  797. echo ' if [ "$EIFACE" ] ; then' >> $BATMAN_SCRIPT
  798. echo ' brctl addbr $BRIDGE' >> $BATMAN_SCRIPT
  799. echo ' brctl addif $BRIDGE bat0' >> $BATMAN_SCRIPT
  800. echo ' brctl addif $BRIDGE $EIFACE' >> $BATMAN_SCRIPT
  801. echo ' ifconfig bat0 0.0.0.0' >> $BATMAN_SCRIPT
  802. echo ' ifconfig $EIFACE 0.0.0.0' >> $BATMAN_SCRIPT
  803. echo ' ifconfig $EIFACE up promisc' >> $BATMAN_SCRIPT
  804. echo ' ifconfig $BRIDGE up' >> $BATMAN_SCRIPT
  805. echo ' fi' >> $BATMAN_SCRIPT
  806. echo '' >> $BATMAN_SCRIPT
  807. echo ' iptables -A INPUT -p tcp --dport 548 -j ACCEPT' >> $BATMAN_SCRIPT
  808. echo ' iptables -A INPUT -p udp --dport 548 -j ACCEPT' >> $BATMAN_SCRIPT
  809. echo ' iptables -A INPUT -p tcp --dport 5353 -j ACCEPT' >> $BATMAN_SCRIPT
  810. echo ' iptables -A INPUT -p udp --dport 5353 -j ACCEPT' >> $BATMAN_SCRIPT
  811. echo ' iptables -A INPUT -p tcp --dport 5354 -j ACCEPT' >> $BATMAN_SCRIPT
  812. echo ' iptables -A INPUT -p udp --dport 5354 -j ACCEPT' >> $BATMAN_SCRIPT
  813. echo " iptables -A INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT" >> $BATMAN_SCRIPT
  814. echo " iptables -A INPUT -p udp --dport $ZERONET_PORT -j ACCEPT" >> $BATMAN_SCRIPT
  815. echo " iptables -A INPUT -p udp --dport $TRACKER_PORT -j ACCEPT" >> $BATMAN_SCRIPT
  816. echo " iptables -A INPUT -p tcp --dport $TRACKER_PORT -j ACCEPT" >> $BATMAN_SCRIPT
  817. echo " iptables -A INPUT -p tcp --dport $IPFS_PORT -j ACCEPT" >> $BATMAN_SCRIPT
  818. echo " iptables -A INPUT -p udp --dport 1900 -j ACCEPT" >> $BATMAN_SCRIPT
  819. echo " iptables -A INPUT -p tcp --dport 80 -j ACCEPT" >> $BATMAN_SCRIPT
  820. echo " iptables -A INPUT -p udp -m udp -j ACCEPT" >> $BATMAN_SCRIPT
  821. echo '' >> $BATMAN_SCRIPT
  822. echo ' if [ -f /bin/systemctl ]; then' >> $BATMAN_SCRIPT
  823. echo ' systemctl restart avahi-daemon' >> $BATMAN_SCRIPT
  824. echo ' else' >> $BATMAN_SCRIPT
  825. echo ' service avahi-daemon restart' >> $BATMAN_SCRIPT
  826. echo ' fi' >> $BATMAN_SCRIPT
  827. echo ' echo "batman" > /tmp/meshtype' >> $BATMAN_SCRIPT
  828. echo '}' >> $BATMAN_SCRIPT
  829. echo '' >> $BATMAN_SCRIPT
  830. echo 'stop() {' >> $BATMAN_SCRIPT
  831. echo ' if [ -z "$IFACE" ]; then' >> $BATMAN_SCRIPT
  832. echo ' echo "error: unable to find wifi interface, not enabling batman-adv mesh"' >> $BATMAN_SCRIPT
  833. echo ' return' >> $BATMAN_SCRIPT
  834. echo ' fi' >> $BATMAN_SCRIPT
  835. echo ' if [ "$EIFACE" ]; then' >> $BATMAN_SCRIPT
  836. echo ' brctl delif $BRIDGE bat0' >> $BATMAN_SCRIPT
  837. echo ' brctl delif $BRIDGE $EIFACE' >> $BATMAN_SCRIPT
  838. echo ' ifconfig $BRIDGE down || true' >> $BATMAN_SCRIPT
  839. echo ' brctl delbr $BRIDGE' >> $BATMAN_SCRIPT
  840. echo ' ifconfig $EIFACE down -promisc' >> $BATMAN_SCRIPT
  841. echo ' fi' >> $BATMAN_SCRIPT
  842. echo '' >> $BATMAN_SCRIPT
  843. echo ' avahi-autoipd -k $BRIDGE' >> $BATMAN_SCRIPT
  844. echo ' avahi-autoipd -k $IFACE' >> $BATMAN_SCRIPT
  845. echo ' ifconfig bat0 down -promisc' >> $BATMAN_SCRIPT
  846. echo '' >> $BATMAN_SCRIPT
  847. echo ' batctl if del $IFACE' >> $BATMAN_SCRIPT
  848. echo ' rmmod batman-adv' >> $BATMAN_SCRIPT
  849. echo ' ifconfig $IFACE mtu 1500' >> $BATMAN_SCRIPT
  850. echo ' ifconfig $IFACE down' >> $BATMAN_SCRIPT
  851. echo ' iwconfig $IFACE mode managed' >> $BATMAN_SCRIPT
  852. echo '' >> $BATMAN_SCRIPT
  853. echo ' iptables -D INPUT -p tcp --dport 548 -j ACCEPT' >> $BATMAN_SCRIPT
  854. echo ' iptables -D INPUT -p udp --dport 548 -j ACCEPT' >> $BATMAN_SCRIPT
  855. echo ' iptables -D INPUT -p tcp --dport 5353 -j ACCEPT' >> $BATMAN_SCRIPT
  856. echo ' iptables -D INPUT -p udp --dport 5353 -j ACCEPT' >> $BATMAN_SCRIPT
  857. echo ' iptables -D INPUT -p tcp --dport 5354 -j ACCEPT' >> $BATMAN_SCRIPT
  858. echo ' iptables -D INPUT -p udp --dport 5354 -j ACCEPT' >> $BATMAN_SCRIPT
  859. echo " iptables -D INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT" >> $BATMAN_SCRIPT
  860. echo " iptables -D INPUT -p udp --dport $ZERONET_PORT -j ACCEPT" >> $BATMAN_SCRIPT
  861. echo " iptables -D INPUT -p udp --dport $TRACKER_PORT -j ACCEPT" >> $BATMAN_SCRIPT
  862. echo " iptables -D INPUT -p tcp --dport $TRACKER_PORT -j ACCEPT" >> $BATMAN_SCRIPT
  863. echo " iptables -D INPUT -p tcp --dport $IPFS_PORT -j ACCEPT" >> $BATMAN_SCRIPT
  864. echo " iptables -D INPUT -p udp --dport 1900 -j ACCEPT" >> $BATMAN_SCRIPT
  865. echo " iptables -D INPUT -p tcp --dport 80 -j ACCEPT" >> $BATMAN_SCRIPT
  866. echo " iptables -D INPUT -p udp -m udp -j ACCEPT" >> $BATMAN_SCRIPT
  867. echo '' >> $BATMAN_SCRIPT
  868. echo ' if [ -f /bin/systemctl ]; then' >> $BATMAN_SCRIPT
  869. echo ' systemctl restart network-manager' >> $BATMAN_SCRIPT
  870. echo ' else' >> $BATMAN_SCRIPT
  871. echo ' service network-manager restart' >> $BATMAN_SCRIPT
  872. echo ' fi' >> $BATMAN_SCRIPT
  873. echo ' ' >> $BATMAN_SCRIPT
  874. echo ' # restore tox bootstrap nodes for the internet' >> $BATMAN_SCRIPT
  875. echo ' if [ -f /usr/share/toxic/DHTnodes.internet ]; then' >> $BATMAN_SCRIPT
  876. echo ' mv /usr/share/toxic/DHTnodes.internet /usr/share/toxic/DHTnodes' >> $BATMAN_SCRIPT
  877. echo ' fi' >> $BATMAN_SCRIPT
  878. echo ' if [ -f /usr/local/share/toxic/DHTnodes.internet ]; then' >> $BATMAN_SCRIPT
  879. echo ' mv /usr/local/share/toxic/DHTnodes.internet /usr/local/share/toxic/DHTnodes' >> $BATMAN_SCRIPT
  880. echo ' fi' >> $BATMAN_SCRIPT
  881. echo '' >> $BATMAN_SCRIPT
  882. echo ' if [ -f /bin/systemctl ]; then' >> $BATMAN_SCRIPT
  883. echo ' systemctl stop avahi-daemon' >> $BATMAN_SCRIPT
  884. echo ' else' >> $BATMAN_SCRIPT
  885. echo ' service avahi-daemon stop' >> $BATMAN_SCRIPT
  886. echo ' fi' >> $BATMAN_SCRIPT
  887. echo '' >> $BATMAN_SCRIPT
  888. echo ' sudo rm -f /tmp/meshtype' >> $BATMAN_SCRIPT
  889. echo '' >> $BATMAN_SCRIPT
  890. echo ' # kill processes' >> $BATMAN_SCRIPT
  891. echo ' zeronet_proc=$(ps aux | grep zeronet | grep -v grep | awk -F " " "{print $2}" | head -n1)' >> $BATMAN_SCRIPT
  892. echo ' if [ "$zeronet_proc" ]; then' >> $BATMAN_SCRIPT
  893. echo ' kill -9 $zeronet_proc 2> /dev/null' >> $BATMAN_SCRIPT
  894. echo ' fi' >> $BATMAN_SCRIPT
  895. echo ' tracker_proc=$(ps aux | grep bttrack | grep -v grep | awk -F " " "{print $2}" | head -n1)' >> $BATMAN_SCRIPT
  896. echo ' if [ "$tracker_proc" ]; then' >> $BATMAN_SCRIPT
  897. echo ' kill -9 $tracker_proc 2> /dev/null' >> $BATMAN_SCRIPT
  898. echo ' fi' >> $BATMAN_SCRIPT
  899. echo ' if [ ! -f /etc/systemd/system/ipfs.service ]; then' >> $BATMAN_SCRIPT
  900. echo ' ipfs_proc=$(ps aux | grep ipfs | grep -v grep | awk -F " " "{print $2}" | head -n1)' >> $BATMAN_SCRIPT
  901. echo ' if [ "$ipfs_proc" ]; then' >> $BATMAN_SCRIPT
  902. echo ' kill -9 $ipfs_proc 2> /dev/null' >> $BATMAN_SCRIPT
  903. echo ' fi' >> $BATMAN_SCRIPT
  904. echo ' fi' >> $BATMAN_SCRIPT
  905. echo '}' >> $BATMAN_SCRIPT
  906. echo '' >> $BATMAN_SCRIPT
  907. echo 'if ! grep -q "$IFACE" /proc/net/dev; then' >> $BATMAN_SCRIPT
  908. echo ' echo "Interface $IFACE was not found"' >> $BATMAN_SCRIPT
  909. echo ' stop' >> $BATMAN_SCRIPT
  910. echo ' exit 1' >> $BATMAN_SCRIPT
  911. echo 'fi' >> $BATMAN_SCRIPT
  912. echo '' >> $BATMAN_SCRIPT
  913. echo 'case "$1" in' >> $BATMAN_SCRIPT
  914. echo ' start|stop)' >> $BATMAN_SCRIPT
  915. echo ' $1' >> $BATMAN_SCRIPT
  916. echo ' ;;' >> $BATMAN_SCRIPT
  917. echo ' restart)' >> $BATMAN_SCRIPT
  918. echo ' stop' >> $BATMAN_SCRIPT
  919. echo ' sleep 10' >> $BATMAN_SCRIPT
  920. echo ' start' >> $BATMAN_SCRIPT
  921. echo ' ;;' >> $BATMAN_SCRIPT
  922. echo ' status)' >> $BATMAN_SCRIPT
  923. echo ' batctl o' >> $BATMAN_SCRIPT
  924. echo ' ;;' >> $BATMAN_SCRIPT
  925. echo ' ping)' >> $BATMAN_SCRIPT
  926. echo ' batctl ping $2' >> $BATMAN_SCRIPT
  927. echo ' ;;' >> $BATMAN_SCRIPT
  928. echo ' ls|list)' >> $BATMAN_SCRIPT
  929. echo ' avahi-browse -atl' >> $BATMAN_SCRIPT
  930. echo ' ;;' >> $BATMAN_SCRIPT
  931. echo ' *)' >> $BATMAN_SCRIPT
  932. echo ' echo "error: invalid parameter $1"' >> $BATMAN_SCRIPT
  933. echo ' echo "usage: $0 {start|stop|restart|status|ping|ls|list}"' >> $BATMAN_SCRIPT
  934. echo ' exit 2' >> $BATMAN_SCRIPT
  935. echo ' ;;' >> $BATMAN_SCRIPT
  936. echo 'esac' >> $BATMAN_SCRIPT
  937. echo 'exit 0' >> $BATMAN_SCRIPT
  938. chmod +x $BATMAN_SCRIPT
  939. sudo cp -f $BATMAN_SCRIPT /usr/bin/batman
  940. rm $BATMAN_SCRIPT
  941. }
  942. while [[ $# > 1 ]]
  943. do
  944. key="$1"
  945. case $key in
  946. -h|--help)
  947. show_help
  948. ;;
  949. -f|--function)
  950. shift
  951. FN="$1"
  952. ;;
  953. -r|--rootdir)
  954. shift
  955. rootdir="$1"
  956. CHROOT_PREFIX='chroot "${rootdir}"'
  957. ;;
  958. -w|--wifi|--interface)
  959. shift
  960. WIFI_INTERFACE="$1"
  961. ;;
  962. -m|--mirror)
  963. shift
  964. FRIENDS_MIRRORS_SERVER="$1"
  965. ;;
  966. --remove)
  967. shift
  968. REMOVE="$1"
  969. ;;
  970. *)
  971. # unknown option
  972. ;;
  973. esac
  974. shift
  975. done
  976. if [[ $FN == 'babel' ]]; then
  977. if [[ $REMOVE != 'yes' ]]; then
  978. mesh_babel
  979. else
  980. mesh_babel_remove
  981. fi
  982. fi
  983. if [[ $FN == 'babel_client' ]]; then
  984. mesh_babel_client
  985. fi
  986. if [[ $FN == 'avahi' ]]; then
  987. mesh_avahi
  988. fi
  989. if [[ $FN == 'firewall' ]]; then
  990. mesh_firewall
  991. fi
  992. if [[ $FN == 'batman' ]]; then
  993. if [[ $REMOVE != 'yes' ]]; then
  994. mesh_batman
  995. else
  996. mesh_batman_remove
  997. fi
  998. fi
  999. if [[ $FN == 'batman_client' ]]; then
  1000. mesh_batman_client
  1001. fi
  1002. if [[ $FN == 'tox_node' ]]; then
  1003. mesh_tox_node
  1004. fi
  1005. if [[ $FN == 'tox_client' ]]; then
  1006. mesh_tox_client
  1007. fi
  1008. if [[ $FN == 'zeronet' ]]; then
  1009. mesh_zeronet
  1010. fi
  1011. if [[ $FN == 'qtox' ]]; then
  1012. mesh_tox_client_qtox
  1013. fi
  1014. if [[ $FN == 'toxic' ]]; then
  1015. mesh_tox_client_toxic_from_repo
  1016. fi
  1017. exit 0