[debian-lan-devel] [debian-lan] 05/06: Handle dynamic NIC labels.

Andreas B. Mundt andi at moszumanska.debian.org
Fri Aug 5 10:45:16 UTC 2016


This is an automated email from the git hooks/post-receive script.

andi pushed a commit to branch master
in repository debian-lan.

commit 1a197096f480591d21c451859b253514656c13f5
Author: Andreas B. Mundt <andi at debian.org>
Date:   Fri Aug 5 09:25:08 2016 +0200

    Handle dynamic NIC labels.
---
 fai/config/hooks/defvar.DEFAULT.sh    | 11 +++++++++++
 fai/config/scripts/FIREWALL/10-config |  6 +++---
 fai/config/scripts/GATEWAY_A/10-misc  | 12 ++++++------
 fai/config/scripts/SERVER_A/10-misc   | 14 +++++++-------
 4 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/fai/config/hooks/defvar.DEFAULT.sh b/fai/config/hooks/defvar.DEFAULT.sh
new file mode 100755
index 0000000..9891c3a
--- /dev/null
+++ b/fai/config/hooks/defvar.DEFAULT.sh
@@ -0,0 +1,11 @@
+#! /bin/bash
+#
+#   Detect all available NICs
+#
+
+## Variable containing <available network interfaces:
+N=0
+for NIC in $(ip link show | grep -E "^\w+:" | cut -d ":" -f2 | grep -v lo) ; do
+    echo "NIC_LABEL${N}=$NIC" >> $LOGDIR/additional.var
+    N=$((N+1))
+done
diff --git a/fai/config/scripts/FIREWALL/10-config b/fai/config/scripts/FIREWALL/10-config
index 5f5c714..e414667 100755
--- a/fai/config/scripts/FIREWALL/10-config
+++ b/fai/config/scripts/FIREWALL/10-config
@@ -1,7 +1,7 @@
 #!/bin/bash
 #
 
-set -e
+set -eu
 
 if [ "$FAI_ACTION" != "install" ] && [ "$CONVERT" != "true" ] ; then
     exit 0
@@ -19,8 +19,8 @@ prepare_shorewall(){
     sed -i "s/IP_FORWARDING=Keep/IP_FORWARDING=on/" $CONFDIR/shorewall.conf
 
     ## Define interfaces and use parameters:
-    sed -i -e 's/eth0/\$NET_IF/' -e 's/eth1/\$LOC_IF/' $CONFDIR/interfaces $CONFDIR/masq $CONFDIR/stoppedrules
-    sed -i -e '$i LOC_IF=eth0' -e '$i NET_IF=eth1' $CONFDIR/params
+    sed -i -e 's/${NIC_LABEL0}/\$NET_IF/' -e 's/${NIC_LABEL1}/\$LOC_IF/' $CONFDIR/interfaces $CONFDIR/masq $CONFDIR/stoppedrules
+    sed -i -e '$i LOC_IF=${NIC_LABEL0}' -e '$i NET_IF=${NIC_LABEL1}' $CONFDIR/params
 
     ## Limited ssh access (uncomment to activate):
     #sed -i -e 's%^\(SSH(ACCEPT).*\)$%\1  -  -  -  -  s:1/min:1%' $CONFDIR/rules
diff --git a/fai/config/scripts/GATEWAY_A/10-misc b/fai/config/scripts/GATEWAY_A/10-misc
index c883af4..a4f7c1a 100755
--- a/fai/config/scripts/GATEWAY_A/10-misc
+++ b/fai/config/scripts/GATEWAY_A/10-misc
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-set -e
+set -eu
 
 ## Switch on apt-cacher-ng:
 # FIXME: resolv.conf does not use the internal name server, so DNS fails here:
@@ -18,20 +18,20 @@ iface lo inet loopback
       dns-search intern
 
 # The internal network interface
-auto eth0
-iface eth0 inet static
+auto ${NIC_LABEL0}
+iface ${NIC_LABEL0} inet static
       address   ${GATEWAY_IPADDR}
       netmask   ${NETMASK}
       broadcast ${BROADCAST_LAN}
 
 # The external network interface
-auto eth1
-iface eth1 inet dhcp
+auto ${NIC_LABEL1}
+iface ${NIC_LABEL1} inet dhcp
 EOF
 
 
 ## Serve internal interface:
 cat > ${target}/etc/dnsmasq.d/DebianLAN.conf <<EOF
 ## Listen for DNS queries on internal interface:
-interface=eth0
+interface=${NIC_LABEL0}
 EOF
diff --git a/fai/config/scripts/SERVER_A/10-misc b/fai/config/scripts/SERVER_A/10-misc
index f61fe9d..b68a79d 100755
--- a/fai/config/scripts/SERVER_A/10-misc
+++ b/fai/config/scripts/SERVER_A/10-misc
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-set -e
+set -eu
 
 ## Switch on apt-cacher-ng:
 ainsl -a /etc/apt/apt.conf 'Acquire::http::Proxy "http://aptcache.intern:3128/";'
@@ -47,8 +47,8 @@ iface lo inet loopback
       dns-search intern
 
 # The internal network interface
-auto eth0
-iface eth0 inet static
+auto ${NIC_LABEL0}
+iface ${NIC_LABEL0} inet static
       address   ${MAINSERVER_IPADDR}
       netmask   ${NETMASK}
       broadcast ${BROADCAST_LAN}
@@ -62,14 +62,14 @@ else
     if $ROOTCMD which dansguardian > /dev/null ; then
 	cat >> $target/etc/network/interfaces <<EOF
       ## Redirect port 80 to dansguardian:
-      post-up iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
+      post-up iptables -t nat -A PREROUTING -i ${NIC_LABEL0} -p tcp --dport 80 -j REDIRECT --to-port 8080
 EOF
     fi
     cat >> $target/etc/network/interfaces <<EOF
 
 # The external network interface
-allow-hotplug eth1
-auto eth1
-iface eth1 inet dhcp
+allow-hotplug ${NIC_LABEL1}
+auto ${NIC_LABEL1}
+iface ${NIC_LABEL1} inet dhcp
 EOF
 fi

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/debian-lan.git



More information about the debian-lan-devel mailing list