Wbm2009v2/config-StaticRouting

From Hackerspace Brussels
Jump to: navigation, search

Parent: Wbm2009v2

Contents

[edit] configuration script

#!/usr/bin/bash 

# setting hostname 
set -a
NAME="@PARAM1@"
sysctl -w kernel.hostname=$NAME
uci set system.@system[0].hostname=$NAME
uci commit

# setting wireless 
set -a
IP="@PARAM3@"
CHANNEL="@PARAM5@"
CELL="@PARAM6@"
uci set wireless.wifi0.channel=$CHANNEL
uci set wireless.wifi0.disabled=0
uci set wireless.wifi0.hwmode=11g
uci set wireless.@wifi-iface[0].network=wlan
uci set wireless.@wifi-iface[0].mode=adhoc
uci set wireless.@wifi-iface[0].ssid=WBM2009v2-Test0
uci set wireless.@wifi-iface[0].encryption=none
uci set wireless.@wifi-iface[0].bssid=$CELL
uci set wireless.@wifi-iface[0].rate=54M
uci set wireless.@wifi-iface[0].bgscan=0
uci set network.wlan=interface
uci set network.wlan.proto=static
uci set network.wlan.ipaddr=$IP
uci set network.wlan.netmask=255.255.255.0
uci set wireless.wifi0.disabled=0
uci commit wireless && wifi
uci commit

# disabling servers
set -a
/etc/init.d/dnsmasq stop
/etc/init.d/dnsmasq disable
/etc/init.d/firewall stop
/etc/init.d/firewall disable
/etc/init.d/httpd stop
/etc/init.d/httpd disable

# configure wired network interface
WIREDIP="@PARAM2@"
uci set network.zlan=alias
uci set network.zlan.interface=lan
uci set network.zlan.proto=static
uci set network.zlan.ipaddr=$WIREDIP
uci set network.zlan.netmask=255.255.255.0
uci commit


cat > /etc/rc.local << EOF

echo 1 > /proc/sys/net/ipv4/ip_forward
eval "@PARAM7@"
eval "@PARAM8@"
exit 0

EOF

reboot
exit

[edit] the node table

#MAC,             PARAM1,   PARAM2,       PARAM3,      PARAM4, PARAM5,PARAM6         ,PARAM7                                                                                                                                                                                                ,PARAM8        ,PARAM9
#MAC,             hostname, wired-ip,     wireless-ip, x,   channel  cell            ,return-routes                                                                                                                                                                                         ,forward-routes ,PARAM9
00:18:84:29:ca:5c , zoo01,  192.168.3.1, 192.168.13.1, x  ,  1  , 02:02:02:02:aa:aa,                                                                                                                                                                                                        ,route add -net 192.168.6.0/24 gw 192.168.13.2 && route add -net 192.168.15.0/24 gw 192.168.13.2 && route add -net 192.168.5.0/24 gw 192.168.13.2  && route add -net 192.168.14.0/24 gw 192.168.13.2
00:18:84:29:b0:0c , zoo07,  192.168.4.1, 192.168.13.2, x  ,  1  , 02:02:02:02:aa:aa,  route add -net 192.168.3.0/24 gw 192.168.13.1                                                                                                                                                         ,route add -net 192.168.6.0/24 gw 192.168.4.2  && route add -net 192.168.15.0/24 gw 192.168.4.2  && route add -net 192.168.5.0/24 gw 192.168.4.2 
00:18:84:24:a1:d0 , zoo08,  192.168.4.2, 192.168.14.1, x  ,  6  , 02:02:02:02:aa:bb,  route add -net 192.168.3.0/24 gw 192.168.4.1  && route add -net 192.168.13.0/24 gw 192.168.4.1  && route add -net 192.168.4.0/24 gw 192.168.4.1                                                       ,route add -net 192.168.6.0/24 gw 192.168.14.2 && route add -net 192.168.15.0/24 gw 192.168.14.2 && route add -net 192.168.5.0/24 gw 192.168.14.2
00:18:84:23:a0:b4 , zoo03,  192.168.5.1, 192.168.14.2, x  ,  6  , 02:02:02:02:aa:bb,  route add -net 192.168.3.0/24 gw 192.168.14.1 && route add -net 192.168.13.0/24 gw 192.168.14.1 && route add -net 192.168.4.0/24 gw 192.168.14.1                                                      ,route add -net 192.168.6.0/24 gw 192.168.5.2  && route add -net 192.168.15.0/24 gw 192.168.5.2
00:18:84:29:be:44 , zoo06,  192.168.5.2, 192.168.15.1, x  ,  12 , 02:02:02:02:aa:cc,  route add -net 192.168.3.0/24 gw 192.168.5.1  && route add -net 192.168.13.0/24 gw 192.168.5.1  && route add -net 192.168.4.0/24 gw 192.168.5.1                                                       ,route add -net 192.168.6.0/24 gw 192.168.15.2
00:18:84:24:07:78 , zoo04,  192.168.6.1, 192.168.15.2, x  ,  12 , 02:02:02:02:aa:cc,  route add -net 192.168.3.0/24 gw 192.168.15.1 && route add -net 192.168.13.0/24 gw 192.168.15.1 && route add -net 192.168.4.0/24 gw 192.168.15.1 && route add -net 192.168.5.0/24 gw 192.168.15.1     ,


[edit] important

to run these, i patched the Wbm2009v2/NodeConfigurationFactory, enabled use of ampersand and slash in the parameters,

[edit] ssh-loop

#!/bin/bash

ME="ssh-loop.sh"
IP="192.168.1.1"
SKIP_LINE_COUNT=11

_usage() {
  cat <<__END_OF_USAGE
Usage: $ME HOSTS COMMANDS

  HOSTS      file containing hosts list (hwaddr,param1,param2...param9))
  COMMANDS   file containing commands to be run on each host

__END_OF_USAGE
}

HOSTS=$1
COMMANDS=$2
[ -n "$HOSTS" -a -n "$COMMANDS" ] || {
  _usage
  exit 1
}
[ -f "$HOSTS" ] || {
  echo "$ME: error accessing HOSTS file '$HOSTS'"
  exit 1
}
[ -f "$COMMANDS" ] || {
  echo "$ME: error accessing COMMANDS file '$COMMANDS'"
  exit 1
}

echo "1. checking sudo..."
sudo true || exit 1

echo "2. looping over nodes..."
IFS=","
cat $HOSTS | grep -v '^#' |  sed -e 's/ *, */,/g' -e's/\//###/g' -e 's/\&\&/####/g'  | while read mac param1 param2 param3 param4 param5 param6 param7 param8 param9; do
  echo -n "-- mac: $mac -- " 1>&2
  sudo arp -s $IP $mac >/dev/null
  ping -c 1 -q -r -t 1 $IP >/dev/null
  if [ $? -eq 0 ]; then
    echo "alive! ---" 1>&2
    echo "[$mac] [$param1] [$param2] [$param3] [$param4] [$param5] [$param6] [$param7] [$param8] [$param9]"
    cat $COMMANDS \
	| sed	-e "s/@MAC@/$mac/g" \
		-e "s/@PARAM1@/$param1/g" \
		-e "s/@PARAM2@/$param2/g" \
		-e "s/@PARAM3@/$param3/g" \
		-e "s/@PARAM4@/$param4/g" \
		-e "s/@PARAM5@/$param5/g" \
		-e "s/@PARAM6@/$param6/g" \
		-e "s/@PARAM7@/$param7/g" \
		-e "s/@PARAM8@/$param8/g" \
		-e "s/@PARAM9@/$param9/g" \
		-e "s/####/\&\&/g" \
		-e "s/###/\//g" \
	| ssh -T -q -o "UserKnownHostsFile /dev/null" -o "StrictHostKeyChecking no" root@"$IP" 2>&1 \
	| tail -n +$SKIP_LINE_COUNT
  else
    echo "not found! ---" 1>&2
  fi
  sudo arp -d $IP >/dev/null
done
echo "3. done!"


[edit] copy-loop.sh

#!/bin/bash

ME="copy-loop.sh"
IP="192.168.1.1"
SKIP_LINE_COUNT=11

_usage() {
  cat <<__END_OF_USAGE
Usage: $ME HOSTS FILES

  HOSTS      file containing hosts list (hwaddr,param1,param2...param9))
  FILES   file containing commands to be run on each host

__END_OF_USAGE
}

HOSTS=$1
shift #shifts all commandline parameters
FILES=$* 

[ -n "$HOSTS" -a -n "$FILES" ] || {
  _usage
  exit 1
}
[ -f "$HOSTS" ] || {
  echo "$ME: error accessing HOSTS file '$HOSTS'"
  exit 1
}

for F in $FILES; do
 [ -f "$F" ] || {
  echo "$ME: error accessing FILES file '$FILES'"
  exit 1
 }
done

echo "1. checking sudo..."
sudo true || exit 1


echo "2. looping over nodes..."
cat $HOSTS | grep -v '^#' |  sed -e 's/ *, */,/g' -e's/\//###/g' -e 's/\&\&/####/g'  |  while IFS="," read mac param1 param2 param3 param4 param5 param6 param7 param8 param9; do
  echo -n "-- mac: $mac -- " 1>&2
  sudo arp -s $IP $mac >/dev/null
  ping -c 1 -q -r -t 1 $IP >/dev/null
  if [ $? -eq 0 ]; then
    echo "alive! ---" 1>&2
    echo "[$mac] [$param1] [$param2] [$param3] [$param4] [$param5] [$param6] [$param7] [$param8] [$param9]"
    scp $FILES root@192.168.1.1:/tmp
  else
    echo "not found! ---" 1>&2
  fi
  sudo arp -d $IP >/dev/null
done
echo "3. done!"