xentaur

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