freedombone-client 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # License
  12. # =======
  13. #
  14. # Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. CURR_USER=$USER
  29. # Version number of this script
  30. VERSION="1.01"
  31. WIFI_CHANNEL=2
  32. WIFI_INTERFACE=wlan0
  33. # B.A.T.M.A.N settings
  34. BATMAN_CELLID='02:BA:00:00:03:01'
  35. ESSID='mesh'
  36. # Babel
  37. BABEL_PORT=6696
  38. # ssh (from https://stribika.github.io/2015/01/04/secure-secure-shell.html)
  39. SSH_CIPHERS="chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr"
  40. SSH_MACS="hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-ripemd160-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,umac-128@openssh.com"
  41. SSH_KEX="curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256"
  42. SSH_HOST_KEY_ALGORITHMS="ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-ed25519,ssh-rsa"
  43. ZERONET_PORT=15441
  44. IPFS_PORT=4001
  45. TRACKER_PORT=6969
  46. # see https://stribika.github.io/2015/01/04/secure-secure-shell.html
  47. function ssh_remove_small_moduli {
  48. sudo awk '$5 > 2000' /etc/ssh/moduli > /home/$CURR_USER/moduli
  49. sudo mv /home/$CURR_USER/moduli /etc/ssh/moduli
  50. }
  51. function configure_ssh_client {
  52. #sudo sed -i 's/# PasswordAuthentication.*/ PasswordAuthentication no/g' /etc/ssh/ssh_config
  53. #sudo sed -i 's/# ChallengeResponseAuthentication.*/ ChallengeResponseAuthentication no/g' /etc/ssh/ssh_config
  54. sudo sed -i "s/# HostKeyAlgorithms.*/ HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS/g" /etc/ssh/ssh_config
  55. sudo sed -i "s/# Ciphers.*/ Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
  56. sudo sed -i "s/# MACs.*/ MACs $SSH_MACS/g" /etc/ssh/ssh_config
  57. if ! grep -q "HostKeyAlgorithms" /etc/ssh/ssh_config; then
  58. sudo cp /etc/ssh/ssh_config ~/ssh_config
  59. sudo chown $CURR_USER:$CURR_USER ~/ssh_config
  60. echo " HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS" >> ~/ssh_config
  61. sudo mv ~/ssh_config /etc/ssh/ssh_config
  62. sudo chown root:root /etc/ssh/ssh_config
  63. fi
  64. sudo sed -i "s/Ciphers.*/Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
  65. if ! grep -q "Ciphers " /etc/ssh/ssh_config; then
  66. sudo cp /etc/ssh/ssh_config ~/ssh_config
  67. sudo chown $CURR_USER:$CURR_USER ~/ssh_config
  68. echo " Ciphers $SSH_CIPHERS" >> ~/ssh_config
  69. sudo mv ~/ssh_config /etc/ssh/ssh_config
  70. sudo chown root:root /etc/ssh/ssh_config
  71. fi
  72. sudo sed -i "s/MACs.*/MACs $SSH_MACS/g" /etc/ssh/ssh_config
  73. if ! grep -q "MACs " /etc/ssh/ssh_config; then
  74. sudo cp /etc/ssh/ssh_config ~/ssh_config
  75. sudo chown $CURR_USER:$CURR_USER ~/ssh_config
  76. echo " MACs $SSH_MACS" >> ~/ssh_config
  77. sudo mv ~/ssh_config /etc/ssh/ssh_config
  78. sudo chown root:root /etc/ssh/ssh_config
  79. fi
  80. # Create ssh keys
  81. if [ ! -f /home/$CURR_USER/.ssh/id_ed25519 ]; then
  82. ssh-keygen -t ed25519 -o -a 100
  83. fi
  84. if [ ! -f /home/$CURR_USER/.ssh/id_rsa ]; then
  85. ssh-keygen -t rsa -b 4096 -o -a 100
  86. fi
  87. ssh_remove_small_moduli
  88. echo ''
  89. echo 'Copy the following into a file called /home/username/.ssh/authorized_keys on the Freedombone server'
  90. echo ''
  91. echo $(cat /home/$CURR_USER/.ssh/id_rsa.pub)
  92. echo $(cat /home/$CURR_USER/.ssh/id_ed25519.pub)
  93. echo ''
  94. }
  95. function mesh_babel {
  96. if [ ! -f /tmp/meshtype ]; then
  97. sudo apt-get -y install babeld
  98. sudo apt-get -y install irssi mumble
  99. if [ ! -f /usr/bin/toxic ]; then
  100. sudo apt-get -y install toxic
  101. echo "n
  102. /nick $USER
  103. /exit
  104. " | /usr/bin/toxic -d
  105. fi
  106. CURR_DIR=$(pwd)
  107. if [ ! -f ~/develop/toxid ]; then
  108. if [ ! -f ~/develop ]; then
  109. mkdir ~/develop
  110. fi
  111. cd ~/develop
  112. git clone https://github.com/bashrc/toxid
  113. fi
  114. cd ~/develop/toxid
  115. sudo make install
  116. cd $CURR_DIR
  117. fi
  118. babel_script=/tmp/babel
  119. echo '#!/bin/bash' > $babel_script
  120. echo '' >> $babel_script
  121. echo 'if [[ $1 == "ls" || $1 == "list" ]]; then' >> $babel_script
  122. echo ' avahi-browse -atl' >> $babel_script
  123. echo ' exit 0' >> $babel_script
  124. echo 'fi' >> $babel_script
  125. echo '' >> $babel_script
  126. echo 'if [[ $1 == "start" ]]; then' >> $babel_script
  127. echo ' if [ -f /tmp/meshtype ] ; then' >> $babel_script
  128. echo ' echo "Mesh already running"' >> $babel_script
  129. echo ' return' >> $babel_script
  130. echo ' fi' >> $batman_script
  131. echo ' # install avahi' >> $babel_script
  132. echo ' apt-get -y install avahi-utils avahi-autoipd avahi-daemon avahi-dnsconfd bittornado' >> $babel_script
  133. echo ' sed -i "s|#host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
  134. echo ' sed -i "s|host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
  135. echo ' if [ -f /bin/systemctl ]; then' >> $babel_script
  136. echo ' systemctl restart avahi-daemon' >> $babel_script
  137. echo ' else' >> $babel_script
  138. echo ' service avahi-daemon restart' >> $babel_script
  139. echo ' fi' >> $babel_script
  140. echo ' echo "babel" > /tmp/meshtype' >> $babel_script
  141. echo 'fi' >> $babel_script
  142. echo '' >> $babel_script
  143. echo "IFACE=$WIFI_INTERFACE" >> $babel_script
  144. echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
  145. echo ' if grep -q "wlan1" /proc/net/dev; then' >> $babel_script
  146. echo ' IFACE=wlan1' >> $babel_script
  147. echo ' fi' >> $babel_script
  148. echo 'fi' >> $babel_script
  149. echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
  150. echo ' if grep -q "wlan2" /proc/net/dev; then' >> $babel_script
  151. echo ' IFACE=wlan2' >> $babel_script
  152. echo ' fi' >> $babel_script
  153. echo 'fi' >> $babel_script
  154. echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
  155. echo ' if grep -q "wlan3" /proc/net/dev; then' >> $babel_script
  156. echo ' IFACE=wlan3' >> $babel_script
  157. echo ' fi' >> $babel_script
  158. echo 'fi' >> $babel_script
  159. echo '' >> $babel_script
  160. echo 'if [[ ! grep -q "$IFACE" /proc/net/dev || $1 == "stop" ]]; then' >> $babel_script
  161. echo ' if ! grep -q "$IFACE" /proc/net/dev; then' >> $babel_script
  162. echo ' echo "Interface $IFACE was not found"' >> $babel_script
  163. echo ' else' >> $babel_script
  164. echo ' echo "Stopping"' >> $babel_script
  165. echo ' fi' >> $babel_script
  166. echo ' ifconfig $IFACE down' >> $babel_script
  167. echo ' pkill babeld' >> $babel_script
  168. echo ' if [ -f /bin/systemctl ]; then' >> $babel_script
  169. echo ' systemctl restart network-manager' >> $babel_script
  170. echo ' else' >> $babel_script
  171. echo ' service network-manager restart' >> $babel_script
  172. echo ' fi' >> $babel_script
  173. echo ' exit 1' >> $babel_script
  174. echo 'fi' >> $babel_script
  175. echo '' >> $babel_script
  176. echo 'if [ -f /bin/systemctl ]; then' >> $babel_script
  177. echo ' systemctl stop network-manager' >> $babel_script
  178. echo 'else' >> $babel_script
  179. echo ' service network-manager stop' >> $babel_script
  180. echo 'fi' >> $babel_script
  181. echo 'ifconfig $IFACE down' >> $babel_script
  182. echo -n 'iwconfig $IFACE mode ad-hoc channel ' >> $babel_script
  183. echo "$WIFI_CHANNEL essid \"$ESSID\"" >> $babel_script
  184. echo 'ifconfig $IFACE up' >> $babel_script
  185. echo -n 'ifconfig $IFACE:avahi ' >> $babel_script
  186. echo -n "$LOCAL_NETWORK_STATIC_IP_ADDRESS netmask " >> $babel_script
  187. echo '255.255.255.0 broadcast 192.168.13.255' >> $babel_script
  188. echo -n 'babeld -D $IFACE:avahi -p ' >> $babel_script
  189. echo -n "$BABEL_PORT -d 5 " >> $babel_script
  190. echo '$IFACE' >> $babel_script
  191. echo 'exit 0' >> $babel_script
  192. chmod +x $babel_script
  193. sudo mv $babel_script /usr/bin/babel
  194. }
  195. function mesh_batman {
  196. if [ ! -f /tmp/meshtype ]; then
  197. sudo apt-get -y install iproute bridge-utils libnetfilter-conntrack3 batctl
  198. sudo apt-get -y install python-dev libevent-dev ebtables python-pip
  199. sudo apt-get -y install wireless-tools rfkill
  200. sudo apt-get -y install irssi mumble
  201. if [ ! -f /usr/bin/toxic ]; then
  202. sudo apt-get -y install toxic
  203. echo "n
  204. /nick $USER
  205. /exit
  206. " | /usr/bin/toxic -d
  207. fi
  208. fi
  209. batman_script=/tmp/batman
  210. echo '#!/bin/bash' > $batman_script
  211. echo '' >> $batman_script
  212. echo 'if [[ $1 == "start" ]]; then' >> $batman_script
  213. echo ' # install avahi' >> $batman_script
  214. echo ' apt-get -y install avahi-utils avahi-autoipd avahi-daemon avahi-dnsconfd bittornado' >> $batman_script
  215. echo ' sed -i "s|#host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $batman_script
  216. echo ' sed -i "s|host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $batman_script
  217. echo ' sed -i "s|use-ipv4=.*|use-ipv4=yes|g" /etc/avahi/avahi-daemon.conf' >> $batman_script
  218. echo ' sed -i "s|use-ipv6=.*|use-ipv6=no|g" /etc/avahi/avahi-daemon.conf' >> $batman_script
  219. echo ' sed -i "s|#disallow-other-stacks=.*|disallow-other-stacks=yes|g" /etc/avahi/avahi-daemon.conf' >> $batman_script
  220. echo ' sed -i "s|hosts:.*|hosts: files mdns4_minimal dns mdns4 mdns|g" /etc/nsswitch.conf' >> $batman_script
  221. echo ' if [ -f /bin/systemctl ]; then' >> $batman_script
  222. echo ' systemctl restart avahi-daemon' >> $batman_script
  223. echo ' else' >> $batman_script
  224. echo ' service avahi-daemon restart' >> $batman_script
  225. echo ' fi' >> $batman_script
  226. echo 'fi' >> $batman_script
  227. echo '' >> $batman_script
  228. echo '# Mesh definition' >> $batman_script
  229. echo "ESSID=$ESSID" >> $batman_script
  230. echo "CELLID=$BATMAN_CELLID" >> $batman_script
  231. echo "CHANNEL=$WIFI_CHANNEL" >> $batman_script
  232. echo '' >> $batman_script
  233. echo '# Ethernet bridge definition (bridged to bat0)' >> $batman_script
  234. echo 'BRIDGE=br-mesh' >> $batman_script
  235. echo "IFACE=$WIFI_INTERFACE" >> $batman_script
  236. echo 'EIFACE=eth0' >> $batman_script
  237. echo '' >> $batman_script
  238. echo 'if [[ $IFACE == "wlan0" ]]; then' >> $batman_script
  239. echo ' if grep -q "wlan1" /proc/net/dev; then' >> $batman_script
  240. echo ' IFACE=wlan1' >> $batman_script
  241. echo ' fi' >> $batman_script
  242. echo 'fi' >> $batman_script
  243. echo 'if [[ $IFACE == "wlan0" ]]; then' >> $batman_script
  244. echo ' if grep -q "wlan2" /proc/net/dev; then' >> $batman_script
  245. echo ' IFACE=wlan2' >> $batman_script
  246. echo ' fi' >> $batman_script
  247. echo 'fi' >> $batman_script
  248. echo 'if [[ $IFACE == "wlan0" ]]; then' >> $batman_script
  249. echo ' if grep -q "wlan3" /proc/net/dev; then' >> $batman_script
  250. echo ' IFACE=wlan3' >> $batman_script
  251. echo ' fi' >> $batman_script
  252. echo 'fi' >> $batman_script
  253. echo '' >> $batman_script
  254. echo 'if [ -e /etc/default/batctl ]; then' >> $batman_script
  255. echo ' . /etc/default/batctl' >> $batman_script
  256. echo 'fi' >> $batman_script
  257. echo '' >> $batman_script
  258. echo 'start() {' >> $batman_script
  259. echo ' if [ -f /tmp/meshtype ] ; then' >> $batman_script
  260. echo ' echo "Mesh already running"' >> $batman_script
  261. echo ' return' >> $batman_script
  262. echo ' fi' >> $batman_script
  263. echo ' if [ -z "$IFACE" ] ; then' >> $batman_script
  264. echo ' echo "error: unable to find wifi interface, not enabling batman-adv mesh"' >> $batman_script
  265. echo ' return' >> $batman_script
  266. echo ' fi' >> $batman_script
  267. echo ' echo "info: enabling batman-adv mesh network $ESSID on $IFACE"' >> $batman_script
  268. echo ' if [ -f /bin/systemctl ]; then' >> $batman_script
  269. echo ' systemctl stop network-manager' >> $batman_script
  270. echo ' else' >> $batman_script
  271. echo ' service network-manager stop' >> $batman_script
  272. echo ' fi' >> $batman_script
  273. echo ' sleep 5' >> $batman_script
  274. echo '' >> $batman_script
  275. echo " # remove an avahi service which isn't used" >> $batman_script
  276. echo ' if [ -f /etc/avahi/services/udisks.service ]; then' >> $batman_script
  277. echo ' sudo rm /etc/avahi/services/udisks.service' >> $batman_script
  278. echo ' fi' >> $batman_script
  279. echo '' >> $batman_script
  280. echo ' # Might have to re-enable wifi' >> $batman_script
  281. echo ' rfkill unblock $(rfkill list|awk -F: "/phy/ {print $1}") || true' >> $batman_script
  282. echo '' >> $batman_script
  283. echo ' ifconfig $IFACE down' >> $batman_script
  284. echo ' ifconfig $IFACE mtu 1532' >> $batman_script
  285. echo ' iwconfig $IFACE enc off' >> $batman_script
  286. echo ' iwconfig $IFACE mode ad-hoc essid $ESSID channel $CHANNEL' >> $batman_script
  287. echo ' sleep 1' >> $batman_script
  288. echo ' iwconfig $IFACE ap $CELLID' >> $batman_script
  289. echo '' >> $batman_script
  290. echo ' modprobe batman-adv' >> $batman_script
  291. echo ' batctl if add $IFACE' >> $batman_script
  292. echo ' ifconfig $IFACE up' >> $batman_script
  293. echo ' avahi-autoipd --force-bind --daemonize --wait $BRIDGE' >> $batman_script
  294. echo ' avahi-autoipd --force-bind --daemonize --wait $IFACE' >> $batman_script
  295. echo ' ifconfig bat0 up promisc' >> $batman_script
  296. echo '' >> $batman_script
  297. echo ' #Use persistent HWAddr' >> $batman_script
  298. echo ' ether_new=$(ifconfig eth0 | grep HWaddr | sed -e "s/.*HWaddr //")' >> $batman_script
  299. echo ' if [ ! -f /var/lib/mesh-node/bat0 ]; then' >> $batman_script
  300. echo ' mkdir /var/lib/mesh-node' >> $batman_script
  301. echo ' echo "${ether_new}" > /var/lib/mesh-node/bat0' >> $batman_script
  302. echo ' else' >> $batman_script
  303. echo ' ether=$(cat /var/lib/mesh-node/bat0)' >> $batman_script
  304. echo ' ifconfig bat0 hw ether ${ether}' >> $batman_script
  305. echo ' fi' >> $batman_script
  306. echo '' >> $batman_script
  307. echo ' if [ "$EIFACE" ] ; then' >> $batman_script
  308. echo ' brctl addbr $BRIDGE' >> $batman_script
  309. echo ' brctl addif $BRIDGE bat0' >> $batman_script
  310. echo ' brctl addif $BRIDGE $EIFACE' >> $batman_script
  311. echo ' ifconfig bat0 0.0.0.0' >> $batman_script
  312. echo ' ifconfig $EIFACE 0.0.0.0' >> $batman_script
  313. echo ' ifconfig $EIFACE up promisc' >> $batman_script
  314. echo ' ifconfig $BRIDGE up' >> $batman_script
  315. echo ' fi' >> $batman_script
  316. echo '' >> $batman_script
  317. echo ' iptables -A INPUT -p tcp --dport 548 -j ACCEPT' >> $batman_script
  318. echo ' iptables -A INPUT -p udp --dport 548 -j ACCEPT' >> $batman_script
  319. echo ' iptables -A INPUT -p tcp --dport 5353 -j ACCEPT' >> $batman_script
  320. echo ' iptables -A INPUT -p udp --dport 5353 -j ACCEPT' >> $batman_script
  321. echo ' iptables -A INPUT -p tcp --dport 5354 -j ACCEPT' >> $batman_script
  322. echo ' iptables -A INPUT -p udp --dport 5354 -j ACCEPT' >> $batman_script
  323. echo " iptables -A INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT" >> $batman_script
  324. echo " iptables -A INPUT -p udp --dport $ZERONET_PORT -j ACCEPT" >> $batman_script
  325. echo " iptables -A INPUT -p udp --dport $TRACKER_PORT -j ACCEPT" >> $batman_script
  326. echo " iptables -A INPUT -p tcp --dport $TRACKER_PORT -j ACCEPT" >> $batman_script
  327. echo " iptables -A INPUT -p tcp --dport $IPFS_PORT -j ACCEPT" >> $batman_script
  328. echo " iptables -A INPUT -p udp --dport 1900 -j ACCEPT" >> $batman_script
  329. echo " iptables -A INPUT -p tcp --dport 80 -j ACCEPT" >> $batman_script
  330. echo " iptables -A INPUT -p udp -m udp -j ACCEPT" >> $batman_script
  331. echo '' >> $batman_script
  332. echo ' if [ -f /bin/systemctl ]; then' >> $batman_script
  333. echo ' systemctl restart avahi-daemon' >> $batman_script
  334. echo ' else' >> $batman_script
  335. echo ' service avahi-daemon restart' >> $batman_script
  336. echo ' fi' >> $batman_script
  337. echo ' echo "batman" > /tmp/meshtype' >> $batman_script
  338. echo '}' >> $batman_script
  339. echo '' >> $batman_script
  340. echo 'stop() {' >> $batman_script
  341. echo ' if [ -z "$IFACE" ]; then' >> $batman_script
  342. echo ' echo "error: unable to find wifi interface, not enabling batman-adv mesh"' >> $batman_script
  343. echo ' return' >> $batman_script
  344. echo ' fi' >> $batman_script
  345. echo ' if [ "$EIFACE" ]; then' >> $batman_script
  346. echo ' brctl delif $BRIDGE bat0' >> $batman_script
  347. echo ' brctl delif $BRIDGE $EIFACE' >> $batman_script
  348. echo ' ifconfig $BRIDGE down || true' >> $batman_script
  349. echo ' brctl delbr $BRIDGE' >> $batman_script
  350. echo ' ifconfig $EIFACE down -promisc' >> $batman_script
  351. echo ' fi' >> $batman_script
  352. echo '' >> $batman_script
  353. echo ' avahi-autoipd -k $BRIDGE' >> $batman_script
  354. echo ' avahi-autoipd -k $IFACE' >> $batman_script
  355. echo ' ifconfig bat0 down -promisc' >> $batman_script
  356. echo '' >> $batman_script
  357. echo ' batctl if del $IFACE' >> $batman_script
  358. echo ' rmmod batman-adv' >> $batman_script
  359. echo ' ifconfig $IFACE mtu 1500' >> $batman_script
  360. echo ' ifconfig $IFACE down' >> $batman_script
  361. echo ' iwconfig $IFACE mode managed' >> $batman_script
  362. echo '' >> $batman_script
  363. echo ' iptables -D INPUT -p tcp --dport 548 -j ACCEPT' >> $batman_script
  364. echo ' iptables -D INPUT -p udp --dport 548 -j ACCEPT' >> $batman_script
  365. echo ' iptables -D INPUT -p tcp --dport 5353 -j ACCEPT' >> $batman_script
  366. echo ' iptables -D INPUT -p udp --dport 5353 -j ACCEPT' >> $batman_script
  367. echo ' iptables -D INPUT -p tcp --dport 5354 -j ACCEPT' >> $batman_script
  368. echo ' iptables -D INPUT -p udp --dport 5354 -j ACCEPT' >> $batman_script
  369. echo " iptables -D INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT" >> $batman_script
  370. echo " iptables -D INPUT -p udp --dport $ZERONET_PORT -j ACCEPT" >> $batman_script
  371. echo " iptables -D INPUT -p udp --dport $TRACKER_PORT -j ACCEPT" >> $batman_script
  372. echo " iptables -D INPUT -p tcp --dport $TRACKER_PORT -j ACCEPT" >> $batman_script
  373. echo " iptables -D INPUT -p tcp --dport $IPFS_PORT -j ACCEPT" >> $batman_script
  374. echo " iptables -D INPUT -p udp --dport 1900 -j ACCEPT" >> $batman_script
  375. echo " iptables -D INPUT -p tcp --dport 80 -j ACCEPT" >> $batman_script
  376. echo " iptables -D INPUT -p udp -m udp -j ACCEPT" >> $batman_script
  377. echo '' >> $batman_script
  378. echo ' if [ -f /bin/systemctl ]; then' >> $batman_script
  379. echo ' systemctl restart network-manager' >> $batman_script
  380. echo ' else' >> $batman_script
  381. echo ' service network-manager restart' >> $batman_script
  382. echo ' fi' >> $batman_script
  383. echo ' ' >> $batman_script
  384. echo ' # restore tox bootstrap nodes for the internet' >> $batman_script
  385. echo ' if [ -f /usr/share/toxic/DHTnodes.internet ]; then' >> $batman_script
  386. echo ' mv /usr/share/toxic/DHTnodes.internet /usr/share/toxic/DHTnodes' >> $batman_script
  387. echo ' fi' >> $batman_script
  388. echo ' if [ -f /usr/local/share/toxic/DHTnodes.internet ]; then' >> $batman_script
  389. echo ' mv /usr/local/share/toxic/DHTnodes.internet /usr/local/share/toxic/DHTnodes' >> $batman_script
  390. echo ' fi' >> $batman_script
  391. echo '' >> $batman_script
  392. echo ' if [ -f /bin/systemctl ]; then' >> $batman_script
  393. echo ' systemctl stop avahi-daemon' >> $batman_script
  394. echo ' else' >> $batman_script
  395. echo ' service avahi-daemon stop' >> $batman_script
  396. echo ' fi' >> $batman_script
  397. echo '' >> $batman_script
  398. echo ' sudo rm -f /tmp/meshtype' >> $batman_script
  399. echo '' >> $batman_script
  400. echo ' # kill processes' >> $batman_script
  401. echo ' zeronet_proc=$(ps aux | grep zeronet | grep -v grep | awk -F " " "{print $2}" | head -n1)' >> $batman_script
  402. echo ' if [ "$zeronet_proc" ]; then' >> $batman_script
  403. echo ' kill -9 $zeronet_proc 2> /dev/null' >> $batman_script
  404. echo ' fi' >> $batman_script
  405. echo ' tracker_proc=$(ps aux | grep bttrack | grep -v grep | awk -F " " "{print $2}" | head -n1)' >> $batman_script
  406. echo ' if [ "$tracker_proc" ]; then' >> $batman_script
  407. echo ' kill -9 $tracker_proc 2> /dev/null' >> $batman_script
  408. echo ' fi' >> $batman_script
  409. echo '}' >> $batman_script
  410. echo '' >> $batman_script
  411. echo 'if ! grep -q "$IFACE" /proc/net/dev; then' >> $batman_script
  412. echo ' echo "Interface $IFACE was not found"' >> $batman_script
  413. echo ' stop' >> $batman_script
  414. echo ' exit 1' >> $batman_script
  415. echo 'fi' >> $batman_script
  416. echo '' >> $batman_script
  417. echo 'case "$1" in' >> $batman_script
  418. echo ' start|stop)' >> $batman_script
  419. echo ' $1' >> $batman_script
  420. echo ' ;;' >> $batman_script
  421. echo ' restart)' >> $batman_script
  422. echo ' stop' >> $batman_script
  423. echo ' sleep 10' >> $batman_script
  424. echo ' start' >> $batman_script
  425. echo ' ;;' >> $batman_script
  426. echo ' status)' >> $batman_script
  427. echo ' batctl o' >> $batman_script
  428. echo ' ;;' >> $batman_script
  429. echo ' ping)' >> $batman_script
  430. echo ' batctl ping $2' >> $batman_script
  431. echo ' ;;' >> $batman_script
  432. echo ' ls|list)' >> $batman_script
  433. echo ' avahi-browse -atl' >> $batman_script
  434. echo ' ;;' >> $batman_script
  435. echo ' *)' >> $batman_script
  436. echo ' echo "error: invalid parameter $1"' >> $batman_script
  437. echo ' echo "usage: $0 {start|stop|restart|status|ping|ls|list}"' >> $batman_script
  438. echo ' exit 2' >> $batman_script
  439. echo ' ;;' >> $batman_script
  440. echo 'esac' >> $batman_script
  441. echo 'exit 0' >> $batman_script
  442. chmod +x $batman_script
  443. sudo cp -f $batman_script /usr/bin/batman
  444. rm $batman_script
  445. }
  446. function show_help {
  447. echo ''
  448. echo 'freedombone-client'
  449. echo ''
  450. exit 0
  451. }
  452. while [[ $# > 1 ]]
  453. do
  454. key="$1"
  455. case $key in
  456. -h|--help)
  457. show_help
  458. ;;
  459. --essid)
  460. shift
  461. ESSID="$1"
  462. ;;
  463. --channel)
  464. shift
  465. WIFI_CHANNEL=${1}
  466. ;;
  467. *)
  468. # unknown option
  469. ;;
  470. esac
  471. shift
  472. done
  473. echo 'Configuring client'
  474. configure_ssh_client
  475. mesh_batman
  476. mesh_babel
  477. echo 'Configuration complete'
  478. exit 0