xentaur

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