xentaur

annotate files/prepare-ec2-instance @ 68:f652fab38c7a

ec2 parameters small fixes
author Igor Chubin <igor@chub.in>
date Mon Jan 11 19:36:56 2010 +0200 (2010-01-11)
parents aaf034af3a35
children
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@68 22 perl -p -i -e 's/universe/universe multiverse/' /etc/apt/sources.list
igor@66 23 pkill apt-get ; pkill dpkg ; sleep 5; pkill apt-get; pkill dpkg ; sleep 5
igor@66 24 dpkg --configure -a
igor@66 25 apt-get -q -y update
igor@66 26 apt-get -q -y install dynamips openvpn bridge-utils rsync vlan unzip screen &
igor@66 27 while ps waux | grep -q apt-get
igor@66 28 do
igor@66 29 sleep 5
igor@66 30 if ps aux | grep -v grep | grep -q dpkg.*defunct
igor@66 31 then
igor@66 32 pkill apt-get ; pkill dpkg ; sleep 5; pkill apt-get; pkill dpkg ; sleep 5
igor@66 33 dpkg --configure -a
igor@66 34 apt-get -q -y install dynamips openvpn bridge-utils rsync vlan unzip screen &
igor@66 35 fi
igor@66 36 done
igor@66 37 }
igor@66 38
igor@66 39 server_bridges_setup()
igor@66 40 {
igor@66 41 brctl addbr br0
igor@66 42 ip link set br0 up
igor@66 43 ifconfig br0 promisc
igor@66 44 for i in `seq 0 $MAX_INSTANCES`
igor@66 45 do
igor@66 46 brctl addif br0 tap$i
igor@66 47 ip link set tap$i up
igor@66 48 done
igor@66 49 }
igor@66 50
igor@66 51 vlans_setup()
igor@66 52 {
igor@66 53 interface=$1
igor@66 54 ip link set $interface up
igor@66 55 vconfig set_name_type VLAN_PLUS_VID_NO_PAD
igor@66 56 for i in `seq $FIRST_VLAN $LAST_VLAN`
igor@66 57 do
igor@66 58 vconfig add $interface $i
igor@66 59 ip link set vlan$i up
igor@66 60 brctl addbr br$i
igor@66 61 ip link set br$i up
igor@66 62 ifconfig br$i promisc
igor@66 63 brctl addif br$i vlan$i
igor@66 64 done
igor@66 65 }
igor@66 66
igor@66 67 server_setup()
igor@66 68 {
igor@66 69 cd /etc/openvpn
igor@66 70 openvpn --genkey --secret static.key
igor@66 71 for i in `seq 0 $MAX_INSTANCES`
igor@66 72 do
igor@66 73 cat <<EOF > server$i.conf
igor@66 74 port $((22000+i))
igor@66 75 secret static.key
igor@66 76 dev tap$i
igor@66 77 EOF
igor@66 78 done
igor@66 79 /etc/init.d/openvpn restart
igor@66 80 }
igor@66 81
igor@66 82 client_setup()
igor@66 83 {
igor@66 84 cd /etc/openvpn
igor@66 85 scp $SERVER:/etc/openvpn/static.key .
igor@66 86 cat <<EOF > client.conf
igor@66 87 port $((22000+N))
igor@66 88 secret static.key
igor@66 89 remote $SERVER
igor@66 90 dev tap0
igor@66 91 EOF
igor@66 92 /etc/init.d/openvpn restart
igor@66 93 }
igor@66 94
igor@66 95 copy_files_to_server()
igor@66 96 {
igor@66 97 mkdir /mnt2
igor@66 98 mount /dev/sdb1 /mnt2
igor@66 99 rsync -a /mnt2/ /mnt/
igor@66 100 umount /mnt2
igor@66 101 rmdir /mnt2
igor@66 102
igor@66 103 #mkdir /mnt/ios
igor@66 104 #cd /mnt/ios
igor@66 105 #wget http://igor.chub.in/tmp/ios
igor@66 106 #unzip ios
igor@66 107 }
igor@66 108
igor@66 109 copy_files_from_server()
igor@66 110 {
igor@66 111 rsync -a $SERVER:/mnt/ /mnt/
igor@66 112 }
igor@66 113
igor@66 114 if [ "$1" = vlans_setup ]
igor@66 115 then
igor@66 116 [ "$N" = 0 ] && vlans_setup br0 || vlan_setup tap0
igor@66 117 exit 0
igor@66 118 fi
igor@66 119
igor@66 120 if [ "$1" = server_bridges_setup ]
igor@66 121 then
igor@66 122 [ "$N" = 0 ] && server_bridges_setup
igor@66 123 exit 0
igor@66 124 fi
igor@66 125
igor@66 126
igor@66 127 if [ "$N" = 0 ]
igor@66 128 then
igor@66 129 common_setup
igor@66 130 server_setup
igor@66 131 server_bridges_setup
igor@66 132 vlans_setup br0
igor@66 133 copy_files_to_server
igor@66 134 else
igor@66 135 common_setup
igor@66 136 client_setup
igor@66 137 vlans_setup tap0
igor@66 138 copy_files_from_server
igor@66 139 fi
igor@66 140