File initramfs-Add-network-handling-support-for-SUSE.patch of Package warewulf
From: Egbert Eich <eich@suse.com>
Date: Mon Oct 11 07:32:44 2021 +0200
Subject: initramfs: Add network handling support for SUSE
Patch-mainline: Not yet
Git-commit: 3b41748246bd6769a939dd2a6849ecb74a45a5bb
References:
SUSE uses ifcfg-* files which are similar but not identical to RHEL.
Also the file locations differ: RHEL stores its files in the directory
/etc/sysconfig/ntwork-scripts while SUSE keeps them in the directory
/etc/sysconfig/network (which is a file on RHEL).
Signed-off-by: Egbert Eich <eich@suse.com>
---
.../capabilities/provision-vnfs/50-config | 3 +
provision/initramfs/init | 141 ++++++++++-----------
2 files changed, 69 insertions(+), 75 deletions(-)
diff --git a/provision/initramfs/capabilities/provision-vnfs/50-config b/provision/initramfs/capabilities/provision-vnfs/50-config
index 5c75b87..a5e6c9d 100644
--- a/provision/initramfs/capabilities/provision-vnfs/50-config
+++ b/provision/initramfs/capabilities/provision-vnfs/50-config
@@ -11,6 +11,9 @@ if [ -d "${NEWROOT}/etc/sysconfig/network-scripts" ]; then
cp -f /tmp/ifcfg-* "${NEWROOT}/etc/sysconfig/network-scripts/"
elif [ -d "${NEWROOT}/etc/network" ]; then
cp -f /tmp/interfaces "${NEWROOT}/etc/network/"
+elif [ -d "${NEWROOT}/etc/sysconfig/network" ]; then
+ [ /tmp/suse/if*-* != "/tmp/suse/if*-*" ] && \
+ cp -f /tmp/suse/if*-* "${NEWROOT}/etc/sysconfig/network/"
fi
if [ -n "$HOSTNAME" ]; then
diff --git a/provision/initramfs/init b/provision/initramfs/init
index e3f0be2..f508cee 100644
--- a/provision/initramfs/init
+++ b/provision/initramfs/init
@@ -75,6 +75,69 @@ for module in `/sbin/detect`; do
done
wwsuccess
+netconf_distro()
+{
+ if [ -z "$WWNETCFGFILE" ]; then
+ msg_white "Creating network initialization files: "
+ msg_gray "($OSDEVICE)"
+ # Debian based /etc/network/interfaces
+ echo "# This was created by the Warewulf bootstrap" > /tmp/interfaces
+ echo "auto lo" >> /tmp/interfaces
+ echo "iface lo inet loopback" >> /tmp/interfaces
+ echo '' >> /tmp/interfaces
+ echo "auto $OSDEVICE" >> /tmp/interfaces
+ echo "iface $OSDEVICE inet static" >> /tmp/interfaces
+ echo " address $WWIPADDR" >> /tmp/interfaces
+ echo " netmask $WWNETMASK" >> /tmp/interfaces
+ if [ -n "$WWGATEWAY" ]; then
+ echo " gateway $WWGATEWAY" >> /tmp/interfaces
+ fi
+ if [ -n "$HWADDR" ]; then
+ echo " hwaddress ether $HWADDR" >> /tmp/interfaces
+ fi
+ if [ -n "$WWMTU" ]; then
+ echo " mtu $WWMTU" >> /tmp/interfaces # DEB
+ fi
+
+ # RHEL based ifcfg
+ echo "# This was created by the Warewulf bootstrap" > /tmp/ifcfg-$OSDEVICE
+ echo "DEVICE=$OSDEVICE" >> /tmp/ifcfg-$OSDEVICE
+ echo "BOOTPROTO=static" >> /tmp/ifcfg-$OSDEVICE
+ echo "ONBOOT=yes" >> /tmp/ifcfg-$OSDEVICE
+ echo "IPADDR=$WWIPADDR" >> /tmp/ifcfg-$OSDEVICE
+ echo "NETMASK=$WWNETMASK" >> /tmp/ifcfg-$OSDEVICE
+ if [ -n "$WWGATEWAY" ]; then
+ echo "GATEWAY=$WWGATEWAY" >> /tmp/ifcfg-$OSDEVICE
+ fi
+ if [ -n "$HWADDR" ]; then
+ echo "HWADDR=$HWADDR" >> /tmp/ifcfg-$OSDEVICE
+ fi
+
+ if [ -n "$WWMTU" ]; then
+ echo "MTU=$WWMTU" >> /tmp/ifcfg-$OSDEVICE # RHEL
+ fi
+
+ # SUSE based ifcfg
+ mkdir -p /tmp/suse
+ echo "# This was created by the Warewulf bootstrap" > /tmp/suse/ifcfg-$OSDEVICE
+ echo "NAME=$OSDEVICE" >> /tmp/suse/ifcfg-$OSDEVICE
+ echo "BOOTPROTO=static" >> /tmp/suse/ifcfg-$OSDEVICE
+ echo "STARTMODE=auto" >> /tmp/suse/ifcfg-$OSDEVICE
+ echo "IPADDR=$WWIPADDR" >> /tmp/suse/ifcfg-$OSDEVICE
+ echo "NETMASK=$WWNETMASK" >> /tmp/suse/ifcfg-$OSDEVICE
+ if [ -n "$HWADDR" ]; then
+ echo "LLADDR=$HWADDR" >> /tmp/suse/ifcfg-$OSDEVICE
+ fi
+ if [ -n "$WWMTU" ]; then
+ echo "MTU=$WWMTU" >> /tmp/suse/ifcfg-$OSDEVICE # RHEL
+ fi
+ if [ -n "$WWGATEWAY" ]; then
+ echo "default $WWGATEWAY - $OSDEVICE" >> /tmp/suse/ifcfg-$OSDEVICE
+ fi
+ wwsuccess
+ fi
+}
+
ifup() {
DEVICE=$1
HWADDR=$2
@@ -107,47 +170,8 @@ ifup() {
wwfailure
fi
fi
-
- if [ -z "$WWNETCFGFILE" ]; then
- msg_white "Creating network initialization files: "
- msg_gray "($OSDEVICE)"
- # Debian based /etc/network/interfaces
- echo "# This was created by the Warewulf bootstrap" > /tmp/interfaces
- echo "auto lo" >> /tmp/interfaces
- echo "iface lo inet loopback" >> /tmp/interfaces
- echo '' >> /tmp/interfaces
- echo "auto $OSDEVICE" >> /tmp/interfaces
- echo "iface $OSDEVICE inet static" >> /tmp/interfaces
- echo " address $WWIPADDR" >> /tmp/interfaces
- echo " netmask $WWNETMASK" >> /tmp/interfaces
- if [ -n "$WWGATEWAY" ]; then
- echo " gateway $WWGATEWAY" >> /tmp/interfaces
- fi
- if [ -n "$HWADDR" ]; then
- echo " hwaddress ether $HWADDR" >> /tmp/interfaces
- fi
-
- # RHEL based ifcfg
- echo "# This was created by the Warewulf bootstrap" > /tmp/ifcfg-$OSDEVICE
- echo "DEVICE=$OSDEVICE" >> /tmp/ifcfg-$OSDEVICE
- echo "BOOTPROTO=static" >> /tmp/ifcfg-$OSDEVICE
- echo "ONBOOT=yes" >> /tmp/ifcfg-$OSDEVICE
- echo "IPADDR=$WWIPADDR" >> /tmp/ifcfg-$OSDEVICE
- echo "NETMASK=$WWNETMASK" >> /tmp/ifcfg-$OSDEVICE
- if [ -n "$WWGATEWAY" ]; then
- echo "GATEWAY=$WWGATEWAY" >> /tmp/ifcfg-$OSDEVICE
- fi
- if [ -n "$HWADDR" ]; then
- echo "HWADDR=$HWADDR" >> /tmp/ifcfg-$OSDEVICE
- fi
-
- if [ -n "$WWMTU" ]; then
- echo "MTU=$WWMTU" >> /tmp/ifcfg-$OSDEVICE # RHEL
- echo " mtu $WWMTU" >> /tmp/interfaces # DEB
- fi
- wwsuccess
- fi
-
+ netconf_distro
+
COUNT=0
msg_white "Trying to reach the master node at $WWMASTER "
while [ $COUNT -le $WWNETRETRY ]; do
@@ -174,40 +198,7 @@ ifup() {
msg_gray "($IPADDR/$NETMASK)"
wwsuccess
- if [ -z "$WWNETCFGFILE" ]; then
- msg_white "Creating network initialization files: "
- msg_gray "($OSDEVICE)"
- # DEB
- echo "# This was created by the Warewulf bootstrap" > /tmp/interfaces
- echo "auto lo" >> /tmp/interfaces
- echo "iface lo inet loopback" >> /tmp/interfaces
- echo '' >> /tmp/interfaces
- echo "auto $OSDEVICE" >> /tmp/interfaces
- echo "iface $OSDEVICE inet static" >> /tmp/interfaces
- echo " address $WWIPADDR" >> /tmp/interfaces
- echo " netmask $WWNETMASK" >> /tmp/interfaces
- if [ -n "$WWGATEWAY" ]; then
- echo " gateway $WWGATEWAY" >> /tmp/interfaces
- fi
- if [ -n "$HWADDR" ]; then
- echo " hwaddress ether $HWADDR" >> /tmp/interfaces
- fi
-
- # RHEL
- echo "# This was created by the Warewulf bootstrap" > /tmp/ifcfg-$OSDEVICE
- echo "DEVICE=$OSDEVICE" >> /tmp/ifcfg-$OSDEVICE
- echo "BOOTPROTO=static" >> /tmp/ifcfg-$OSDEVICE
- echo "ONBOOT=yes" >> /tmp/ifcfg-$OSDEVICE
- echo "IPADDR=$IPADDR" >> /tmp/ifcfg-$OSDEVICE
- echo "NETMASK=$NETMASK" >> /tmp/ifcfg-$OSDEVICE
- echo "GATEWAY=$GATEWAY" >> /tmp/ifcfg-$OSDEVICE
- echo "HWADDR=$HWADDR" >> /tmp/ifcfg-$OSDEVICE
- fi
-
- if [ -n "$WWMTU" ]; then
- echo "MTU=$WWMTU" >> /tmp/ifcfg-$OSDEVICE # RHEL
- echo " mtu $WWMTU" >> /tmp/interfaces # DEB
- fi
+ netconf_distro
return 0
fi
msg_white "."