xentaur

annotate files/prepare-ec2-instance @ 66:aaf034af3a35

Merge of Xgurulla into Xentaur code. Not completed yet!!!

Now Xentaur can work with Amazon EC2,
but only with. Local domains management
is switched off temporarily.
author Igor Chubin <igor@chub.in>
date Sat Jan 09 20:20:08 2010 +0200 (2010-01-09)
parents
children f652fab38c7a
rev   line source
igor@66 1
igor@66 2 # usage:
igor@66 3 # loads /etc/xgurulla/config
igor@66 4 #
igor@66 5 # N the number of the instance
igor@66 6 # NETWORK_NAME
igor@66 7 # SERVER_NAME
igor@66 8
igor@66 9 MAX_INSTANCES=10
igor@66 10 FIRST_VLAN=100
igor@66 11 LAST_VLAN=200
igor@66 12
igor@66 13 . /etc/xgurulla/config
igor@66 14
igor@66 15 common_setup()
igor@66 16 {
igor@66 17 echo $HOSTNAME > /etc/hostname
igor@66 18 echo 127.0.0.1 $HOSTNAME ${HOSTNAME%%.*} > /etc/hosts
igor@66 19 hostname $HOSTNAME
igor@66 20 touch /root/.hushlogin
igor@66 21 export DEBIAN_FRONTEND=noninteractive
igor@66 22 pkill apt-get ; pkill dpkg ; sleep 5; pkill apt-get; pkill dpkg ; sleep 5
igor@66 23 dpkg --configure -a
igor@66 24 apt-get -q -y update
igor@66 25 apt-get -q -y install dynamips openvpn bridge-utils rsync vlan unzip screen &
igor@66 26 while ps waux | grep -q apt-get
igor@66 27 do
igor@66 28 sleep 5
igor@66 29 if ps aux | grep -v grep | grep -q dpkg.*defunct
igor@66 30 then
igor@66 31 pkill apt-get ; pkill dpkg ; sleep 5; pkill apt-get; pkill dpkg ; sleep 5
igor@66 32 dpkg --configure -a
igor@66 33 apt-get -q -y install dynamips openvpn bridge-utils rsync vlan unzip screen &
igor@66 34 fi
igor@66 35 done
igor@66 36 }
igor@66 37
igor@66 38 server_bridges_setup()
igor@66 39 {
igor@66 40 brctl addbr br0
igor@66 41 ip link set br0 up
igor@66 42 ifconfig br0 promisc
igor@66 43 for i in `seq 0 $MAX_INSTANCES`
igor@66 44 do
igor@66 45 brctl addif br0 tap$i
igor@66 46 ip link set tap$i up
igor@66 47 done
igor@66 48 }
igor@66 49
igor@66 50 vlans_setup()
igor@66 51 {
igor@66 52 interface=$1
igor@66 53 ip link set $interface up
igor@66 54 vconfig set_name_type VLAN_PLUS_VID_NO_PAD
igor@66 55 for i in `seq $FIRST_VLAN $LAST_VLAN`
igor@66 56 do
igor@66 57 vconfig add $interface $i
igor@66 58 ip link set vlan$i up
igor@66 59 brctl addbr br$i
igor@66 60 ip link set br$i up
igor@66 61 ifconfig br$i promisc
igor@66 62 brctl addif br$i vlan$i
igor@66 63 done
igor@66 64 }
igor@66 65
igor@66 66 server_setup()
igor@66 67 {
igor@66 68 cd /etc/openvpn
igor@66 69 openvpn --genkey --secret static.key
igor@66 70 for i in `seq 0 $MAX_INSTANCES`
igor@66 71 do
igor@66 72 cat <<EOF > server$i.conf
igor@66 73 port $((22000+i))
igor@66 74 secret static.key
igor@66 75 dev tap$i
igor@66 76 EOF
igor@66 77 done
igor@66 78 /etc/init.d/openvpn restart
igor@66 79 }
igor@66 80
igor@66 81 client_setup()
igor@66 82 {
igor@66 83 cd /etc/openvpn
igor@66 84 scp $SERVER:/etc/openvpn/static.key .
igor@66 85 cat <<EOF > client.conf
igor@66 86 port $((22000+N))
igor@66 87 secret static.key
igor@66 88 remote $SERVER
igor@66 89 dev tap0
igor@66 90 EOF
igor@66 91 /etc/init.d/openvpn restart
igor@66 92 }
igor@66 93
igor@66 94 copy_files_to_server()
igor@66 95 {
igor@66 96 mkdir /mnt2
igor@66 97 mount /dev/sdb1 /mnt2
igor@66 98 rsync -a /mnt2/ /mnt/
igor@66 99 umount /mnt2
igor@66 100 rmdir /mnt2
igor@66 101
igor@66 102 #mkdir /mnt/ios
igor@66 103 #cd /mnt/ios
igor@66 104 #wget http://igor.chub.in/tmp/ios
igor@66 105 #unzip ios
igor@66 106 }
igor@66 107
igor@66 108 copy_files_from_server()
igor@66 109 {
igor@66 110 rsync -a $SERVER:/mnt/ /mnt/
igor@66 111 }
igor@66 112
igor@66 113 if [ "$1" = vlans_setup ]
igor@66 114 then
igor@66 115 [ "$N" = 0 ] && vlans_setup br0 || vlan_setup tap0
igor@66 116 exit 0
igor@66 117 fi
igor@66 118
igor@66 119 if [ "$1" = server_bridges_setup ]
igor@66 120 then
igor@66 121 [ "$N" = 0 ] && server_bridges_setup
igor@66 122 exit 0
igor@66 123 fi
igor@66 124
igor@66 125
igor@66 126 if [ "$N" = 0 ]
igor@66 127 then
igor@66 128 common_setup
igor@66 129 server_setup
igor@66 130 server_bridges_setup
igor@66 131 vlans_setup br0
igor@66 132 copy_files_to_server
igor@66 133 else
igor@66 134 common_setup
igor@66 135 client_setup
igor@66 136 vlans_setup tap0
igor@66 137 copy_files_from_server
igor@66 138 fi
igor@66 139