6e61d9a181030bf030d169f349957c3240d67906
[sdnvpn.git] / sdnvpn / artifacts / quagga_setup.sh
1 #! /bin/bash
2
3 set -xe
4
5 # change the password because this script is run on a passwordless cloud-image
6 echo 'ubuntu:opnfv' | chpasswd
7
8 # dns fix
9
10 echo "8.8.8.8" > /etc/resolvconf/resolv.conf.d/head
11 resolvconf -u
12
13 # Wait for a floating IP
14 # as a workaround to NAT breakage
15 sleep 20
16
17 # Variables to be filled in with python
18 NEIGHBOR_IP=%s
19 OWN_IP=%s
20 # directly access the instance from the external net without NAT
21 EXT_NET_MASK=%s
22
23 if [[ $(getent hosts | awk '{print $2}') != *"$(cat /etc/hostname | awk '{print $1}')"* ]]
24 then 
25 echo "127.0.1.1 $(cat /etc/hostname | awk '{print $1}')" | tee -a /etc/hosts
26 fi
27
28 quagga_int=''
29 for net_int in $(netstat -ia | awk 'NR>2{print $1}');
30 do
31 if [ -z "$(ifconfig | grep $net_int)" ]
32 then
33 quagga_int=$net_int
34 break
35 fi
36 done
37 if [ -z "$quagga_int" ]
38 then
39 echo 'No available network interface'
40 fi
41
42 ip link set $quagga_int up
43 ip addr add $OWN_IP/$EXT_NET_MASK dev $quagga_int
44
45 ZEBRA_CONFIG_LOCATION="/etc/quagga/zebra.conf"
46 DAEMONS_FILE_LOCATION="/etc/quagga/daemons"
47 BGPD_CONFIG_LOCATION="/etc/quagga/bgpd.conf"
48 BGPD_LOG_FILE="/var/log/bgpd.log"
49
50 DEBIAN_FRONTEND=noninteractive apt-get update
51 DEBIAN_FRONTEND=noninteractive apt-get install quagga -y
52
53 touch $BGPD_LOG_FILE
54 chown quagga:quagga $BGPD_LOG_FILE
55
56 chown quagga:quagga $DAEMONS_FILE_LOCATION
57 cat <<CATEOF > $DAEMONS_FILE_LOCATION
58 zebra=yes
59 bgpd=yes
60 ospfd=no
61 ospf6d=no
62 ripd=no
63 ripngd=no
64 isisd=no
65 babeld=no
66 CATEOF
67
68 touch $ZEBRA_CONFIG_LOCATION
69 chown quagga:quagga $ZEBRA_CONFIG_LOCATION
70
71 cat <<CATEOF > $BGPD_CONFIG_LOCATION
72 ! -*- bgp -*-
73
74 hostname bgpd
75 password sdncbgpc
76
77 router bgp 200
78  bgp router-id ${OWN_IP}
79  neighbor ${NEIGHBOR_IP} remote-as 100
80  no neighbor ${NEIGHBOR_IP} activate
81 !
82  address-family vpnv4 unicast
83  neighbor ${NEIGHBOR_IP} activate
84  exit-address-family
85 !
86 line vty
87  exec-timeout 0 0
88 !
89 debug bgp events
90 debug bgp  updates
91 log file ${BGPD_LOG_FILE}
92 end
93 CATEOF
94 chown quagga:quagga $BGPD_CONFIG_LOCATION
95 service quagga restart
96 pgrep bgpd
97 pgrep zebra