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