From a1353fba88c1d4883a29694277111fe5a3e33bd0 Mon Sep 17 00:00:00 2001
From: Andy Witter <awitter@georgialibraries.org>
Date: Mon, 8 Apr 2019 16:01:56 -0400
Subject: [PATCH] Add support for using second interfaces as primary interface
 when detected.

---
 templates/setup-functions | 15 +++++++++++----
 templates/setup-head.sh   |  7 +++++++
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/templates/setup-functions b/templates/setup-functions
index ff66067..1229092 100755
--- a/templates/setup-functions
+++ b/templates/setup-functions
@@ -152,16 +152,23 @@ if [ -e /etc/apparmor.d/usr.sbin.ejabberdctl ]; then
 fi
 }
 
-ConfigNetwork () {
+ConfigNetwork () { ### for NON LVS servers.
 # PRIMARY_IF=$(ip route get 8.8.8.8 | awk '{print $5; exit}') #TODO remove this as its declared above in the GetNics Function - done
-if [ ! -z "$PRIMARY_INTERFACE" ]; then #TODO update variable - done
-        sed -i "s/Primary_IF/$PRIMARY_INTERFACE/g" /etc/network/interfaces #TODO update variable - done
+if [ ! -z "${SECOND_PHYSICAL_INTERFACE}" ] 
+then
+    PRIMARY_INTERFACE="${SECOND_PHYSICAL_INTERFACE}"
+fi
+
+if [ ! -z "$PRIMARY_INTERFACE" ]; #TODO update variable - done
+then 
+    sed -i "s/Primary_IF/$PRIMARY_INTERFACE/g" /etc/network/interfaces #TODO update variable - done
 else
-   echo "ERROR: Unable to set primary interface. You must edit /etc/network/interfaces manually."
+    echo "ERROR: Unable to set primary interface. You must edit /etc/network/interfaces manually."
 fi
 #TODO expand this function to handle all interfaces anywhere. aw-4/4/2019
 }
 
+
 ### Setup monitoring.
 SetupMonitoring () {
 ## Monitored hosts
diff --git a/templates/setup-head.sh b/templates/setup-head.sh
index 98ef157..58095f2 100755
--- a/templates/setup-head.sh
+++ b/templates/setup-head.sh
@@ -148,8 +148,15 @@ fi
 
 GetNics ### Get the network interface #TODO change function called here from GetNic to GetNics - done
 
+
 ### Temporary create and alias interface for installation
+GetNics
+if [ ! -z "${SECOND_PHYSICAL_INTERFACE}" ]
+then
+    PRIMARY_INTERFACE="${SECOND_PHYSICAL_INTERFACE}"
+fi
 ip a add Priv_IP/My_CIDR dev $PRIMARY_INTERFACE label ${PRIMARY_INTERFACE}:0 #TODO update Variable to $3PRIMARY_INTERFACE - done
+ip link set $PRIMARY_INTERFACE up
 
 ### Install Opensrf and Evergreen debs.
 if [ -e debconf-settings ]
-- 
2.11.0