Clean always and change order
[sdnvpn.git] / sdnvpn / artifacts / quagga_setup.sh
index e20c193..a8fe9f6 100644 (file)
@@ -15,16 +15,39 @@ OWN_IP=%s
 # directly access the instance from the external net without NAT
 EXT_NET_MASK=%s
 
-ip link set ens7 up
-ip addr add $OWN_IP/$EXT_NET_MASK dev ens7
+if [[ $(getent hosts | awk '{print $2}') != *"$(cat /etc/hostname | awk '{print $1}')"* ]]
+then 
+echo "127.0.1.1 $(cat /etc/hostname | awk '{print $1}')" | tee -a /etc/hosts
+fi
+
+quagga_int=''
+for net_int in $(netstat -ia | awk 'NR>2{print $1}');
+do
+if [ -z "$(ifconfig | grep $net_int)" ]
+then
+quagga_int=$net_int
+break
+fi
+done
+if [ -z "$quagga_int" ]
+then
+echo 'No available network interface'
+fi
+
+ip link set $quagga_int up
+ip addr add $OWN_IP/$EXT_NET_MASK dev $quagga_int
 
 ZEBRA_CONFIG_LOCATION="/etc/quagga/zebra.conf"
 DAEMONS_FILE_LOCATION="/etc/quagga/daemons"
 BGPD_CONFIG_LOCATION="/etc/quagga/bgpd.conf"
 BGPD_LOG_FILE="/var/log/bgpd.log"
 
-DEBIAN_FONTEND=noninteractive apt-get update
-DEBIAN_FRONTEND=noninteractive apt-get install quagga -y
+# Quagga is already installed to run as well in setups without inet
+# dns fix
+# echo "nameserver 8.8.8.8" > /etc/resolvconf/resolv.conf.d/head
+# resolvconf -u
+# DEBIAN_FRONTEND=noninteractive apt-get update
+# DEBIAN_FRONTEND=noninteractive apt-get install quagga -y
 
 touch $BGPD_LOG_FILE
 chown quagga:quagga $BGPD_LOG_FILE
@@ -68,6 +91,6 @@ log file ${BGPD_LOG_FILE}
 end
 CATEOF
 chown quagga:quagga $BGPD_CONFIG_LOCATION
-
+service quagga restart
 pgrep bgpd
 pgrep zebra