xentaur

diff files/prepare-ec2-instance @ 67:6c145935ece5

Fixed path scripts and configuration templates moved to a single file.
author Igor Chubin <igor@chub.in>
date Mon Jan 11 13:01:35 2010 +0200 (2010-01-11)
parents
children f652fab38c7a
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/files/prepare-ec2-instance	Mon Jan 11 13:01:35 2010 +0200
     1.3 @@ -0,0 +1,139 @@
     1.4 +
     1.5 +# usage: 
     1.6 +# loads /etc/xgurulla/config
     1.7 +#
     1.8 +# N the number of the instance
     1.9 +# NETWORK_NAME
    1.10 +# SERVER_NAME
    1.11 +
    1.12 +MAX_INSTANCES=10
    1.13 +FIRST_VLAN=100
    1.14 +LAST_VLAN=200
    1.15 +
    1.16 +. /etc/xgurulla/config
    1.17 +
    1.18 +common_setup()
    1.19 +{
    1.20 +	echo $HOSTNAME > /etc/hostname
    1.21 +	echo 127.0.0.1 $HOSTNAME ${HOSTNAME%%.*} > /etc/hosts
    1.22 +	hostname $HOSTNAME
    1.23 +	touch /root/.hushlogin
    1.24 +	export DEBIAN_FRONTEND=noninteractive
    1.25 +	pkill apt-get ; pkill dpkg ; sleep 5; pkill apt-get; pkill dpkg ; sleep 5
    1.26 +	dpkg --configure -a
    1.27 +     	apt-get -q -y update
    1.28 +        apt-get -q -y install dynamips openvpn bridge-utils rsync vlan unzip screen &
    1.29 +	while ps waux | grep -q apt-get
    1.30 +	do
    1.31 +		sleep 5
    1.32 +		if ps aux | grep -v grep | grep -q dpkg.*defunct
    1.33 +		then
    1.34 +	pkill apt-get ; pkill dpkg ; sleep 5; pkill apt-get; pkill dpkg ; sleep 5
    1.35 +			dpkg --configure -a
    1.36 +    			apt-get -q -y install dynamips openvpn bridge-utils rsync vlan unzip screen &
    1.37 +		fi
    1.38 +	done
    1.39 +}
    1.40 +
    1.41 +server_bridges_setup()
    1.42 +{
    1.43 +    brctl addbr br0
    1.44 +    ip link set br0 up
    1.45 +    ifconfig br0 promisc
    1.46 +    for i in `seq 0 $MAX_INSTANCES`
    1.47 +    do
    1.48 +        brctl addif br0 tap$i
    1.49 +        ip link set tap$i up
    1.50 +    done
    1.51 +}
    1.52 +
    1.53 +vlans_setup()
    1.54 +{
    1.55 +    interface=$1
    1.56 +    ip link set $interface up
    1.57 +    vconfig set_name_type VLAN_PLUS_VID_NO_PAD
    1.58 +    for i in `seq $FIRST_VLAN $LAST_VLAN`
    1.59 +    do
    1.60 +        vconfig add $interface $i
    1.61 +	ip link set vlan$i up
    1.62 +        brctl addbr br$i 
    1.63 +        ip link set br$i up
    1.64 +        ifconfig br$i promisc
    1.65 +	brctl addif br$i vlan$i
    1.66 +    done
    1.67 +}
    1.68 +
    1.69 +server_setup()
    1.70 +{
    1.71 +    cd /etc/openvpn
    1.72 +    openvpn --genkey --secret static.key
    1.73 +    for i in `seq 0 $MAX_INSTANCES`
    1.74 +    do
    1.75 +    cat <<EOF > server$i.conf
    1.76 +port $((22000+i))
    1.77 +secret static.key
    1.78 +dev tap$i
    1.79 +EOF
    1.80 +    done
    1.81 +    /etc/init.d/openvpn restart
    1.82 +}
    1.83 +
    1.84 +client_setup()
    1.85 +{
    1.86 +    cd /etc/openvpn
    1.87 +    scp $SERVER:/etc/openvpn/static.key .
    1.88 +    cat <<EOF > client.conf
    1.89 +port $((22000+N))
    1.90 +secret static.key
    1.91 +remote $SERVER
    1.92 +dev tap0
    1.93 +EOF
    1.94 +    /etc/init.d/openvpn restart
    1.95 +}
    1.96 +
    1.97 +copy_files_to_server()
    1.98 +{
    1.99 +    mkdir /mnt2
   1.100 +    mount /dev/sdb1 /mnt2
   1.101 +    rsync -a /mnt2/ /mnt/
   1.102 +    umount /mnt2
   1.103 +    rmdir /mnt2
   1.104 +    
   1.105 +    #mkdir /mnt/ios
   1.106 +    #cd /mnt/ios
   1.107 +    #wget http://igor.chub.in/tmp/ios
   1.108 +    #unzip ios
   1.109 +}
   1.110 +
   1.111 +copy_files_from_server()
   1.112 +{
   1.113 +    rsync -a $SERVER:/mnt/ /mnt/
   1.114 +}
   1.115 +
   1.116 +if [ "$1" = vlans_setup ]
   1.117 +then
   1.118 +   [ "$N" = 0 ]  && vlans_setup br0 || vlan_setup tap0
   1.119 +   exit 0
   1.120 +fi
   1.121 +
   1.122 +if [ "$1" = server_bridges_setup ]
   1.123 +then
   1.124 +   [ "$N" = 0 ]  && server_bridges_setup
   1.125 +   exit 0
   1.126 +fi
   1.127 +
   1.128 +
   1.129 +if [ "$N" = 0 ] 
   1.130 +then
   1.131 +    common_setup
   1.132 +    server_setup
   1.133 +    server_bridges_setup
   1.134 +    vlans_setup br0
   1.135 +    copy_files_to_server
   1.136 +else
   1.137 +    common_setup
   1.138 +    client_setup
   1.139 +    vlans_setup tap0
   1.140 +    copy_files_from_server
   1.141 +fi
   1.142 +