igor@66: igor@66: # usage: igor@66: # loads /etc/xgurulla/config igor@66: # igor@66: # N the number of the instance igor@66: # NETWORK_NAME igor@66: # SERVER_NAME igor@66: igor@66: MAX_INSTANCES=10 igor@66: FIRST_VLAN=100 igor@66: LAST_VLAN=200 igor@66: igor@66: . /etc/xgurulla/config igor@66: igor@66: common_setup() igor@66: { igor@66: echo $HOSTNAME > /etc/hostname igor@66: echo 127.0.0.1 $HOSTNAME ${HOSTNAME%%.*} > /etc/hosts igor@66: hostname $HOSTNAME igor@66: touch /root/.hushlogin igor@66: export DEBIAN_FRONTEND=noninteractive igor@66: pkill apt-get ; pkill dpkg ; sleep 5; pkill apt-get; pkill dpkg ; sleep 5 igor@66: dpkg --configure -a igor@66: apt-get -q -y update igor@66: apt-get -q -y install dynamips openvpn bridge-utils rsync vlan unzip screen & igor@66: while ps waux | grep -q apt-get igor@66: do igor@66: sleep 5 igor@66: if ps aux | grep -v grep | grep -q dpkg.*defunct igor@66: then igor@66: pkill apt-get ; pkill dpkg ; sleep 5; pkill apt-get; pkill dpkg ; sleep 5 igor@66: dpkg --configure -a igor@66: apt-get -q -y install dynamips openvpn bridge-utils rsync vlan unzip screen & igor@66: fi igor@66: done igor@66: } igor@66: igor@66: server_bridges_setup() igor@66: { igor@66: brctl addbr br0 igor@66: ip link set br0 up igor@66: ifconfig br0 promisc igor@66: for i in `seq 0 $MAX_INSTANCES` igor@66: do igor@66: brctl addif br0 tap$i igor@66: ip link set tap$i up igor@66: done igor@66: } igor@66: igor@66: vlans_setup() igor@66: { igor@66: interface=$1 igor@66: ip link set $interface up igor@66: vconfig set_name_type VLAN_PLUS_VID_NO_PAD igor@66: for i in `seq $FIRST_VLAN $LAST_VLAN` igor@66: do igor@66: vconfig add $interface $i igor@66: ip link set vlan$i up igor@66: brctl addbr br$i igor@66: ip link set br$i up igor@66: ifconfig br$i promisc igor@66: brctl addif br$i vlan$i igor@66: done igor@66: } igor@66: igor@66: server_setup() igor@66: { igor@66: cd /etc/openvpn igor@66: openvpn --genkey --secret static.key igor@66: for i in `seq 0 $MAX_INSTANCES` igor@66: do igor@66: cat < server$i.conf igor@66: port $((22000+i)) igor@66: secret static.key igor@66: dev tap$i igor@66: EOF igor@66: done igor@66: /etc/init.d/openvpn restart igor@66: } igor@66: igor@66: client_setup() igor@66: { igor@66: cd /etc/openvpn igor@66: scp $SERVER:/etc/openvpn/static.key . igor@66: cat < client.conf igor@66: port $((22000+N)) igor@66: secret static.key igor@66: remote $SERVER igor@66: dev tap0 igor@66: EOF igor@66: /etc/init.d/openvpn restart igor@66: } igor@66: igor@66: copy_files_to_server() igor@66: { igor@66: mkdir /mnt2 igor@66: mount /dev/sdb1 /mnt2 igor@66: rsync -a /mnt2/ /mnt/ igor@66: umount /mnt2 igor@66: rmdir /mnt2 igor@66: igor@66: #mkdir /mnt/ios igor@66: #cd /mnt/ios igor@66: #wget http://igor.chub.in/tmp/ios igor@66: #unzip ios igor@66: } igor@66: igor@66: copy_files_from_server() igor@66: { igor@66: rsync -a $SERVER:/mnt/ /mnt/ igor@66: } igor@66: igor@66: if [ "$1" = vlans_setup ] igor@66: then igor@66: [ "$N" = 0 ] && vlans_setup br0 || vlan_setup tap0 igor@66: exit 0 igor@66: fi igor@66: igor@66: if [ "$1" = server_bridges_setup ] igor@66: then igor@66: [ "$N" = 0 ] && server_bridges_setup igor@66: exit 0 igor@66: fi igor@66: igor@66: igor@66: if [ "$N" = 0 ] igor@66: then igor@66: common_setup igor@66: server_setup igor@66: server_bridges_setup igor@66: vlans_setup br0 igor@66: copy_files_to_server igor@66: else igor@66: common_setup igor@66: client_setup igor@66: vlans_setup tap0 igor@66: copy_files_from_server igor@66: fi igor@66: