freedombone-client 23KB

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