Blame 0078-ifcfg-write-ifcfg.sh-fixed-logic.patch

Harald Hoyer 75f812
From caf207afa7c2a65f25be26a735643a873f5c092f Mon Sep 17 00:00:00 2001
Harald Hoyer 75f812
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 75f812
Date: Thu, 30 May 2013 14:37:41 +0200
Harald Hoyer 75f812
Subject: [PATCH] ifcfg/write-ifcfg.sh: fixed logic
Harald Hoyer 75f812
Harald Hoyer 75f812
seems like nobody tested this with recent dracut versions.
Harald Hoyer 75f812
---
Harald Hoyer 75f812
 modules.d/45ifcfg/write-ifcfg.sh | 75 ++++++++++++++++++++++------------------
Harald Hoyer 75f812
 1 file changed, 41 insertions(+), 34 deletions(-)
Harald Hoyer 75f812
Harald Hoyer 75f812
diff --git a/modules.d/45ifcfg/write-ifcfg.sh b/modules.d/45ifcfg/write-ifcfg.sh
Harald Hoyer 75f812
index 625d00b..2e78c49 100755
Harald Hoyer 75f812
--- a/modules.d/45ifcfg/write-ifcfg.sh
Harald Hoyer 75f812
+++ b/modules.d/45ifcfg/write-ifcfg.sh
Harald Hoyer 75f812
@@ -4,10 +4,6 @@
Harald Hoyer 75f812
 
Harald Hoyer 75f812
 # NFS root might have reached here before /tmp/net.ifaces was written
Harald Hoyer 75f812
 udevadm settle --timeout=30
Harald Hoyer 75f812
-# Don't write anything if we don't know our bootdev
Harald Hoyer 75f812
-[ -f /tmp/net.ifaces ] || return 1
Harald Hoyer 75f812
-
Harald Hoyer 75f812
-read IFACES < /tmp/net.ifaces
Harald Hoyer 75f812
 
Harald Hoyer 75f812
 if [ -e /tmp/bridge.info ]; then
Harald Hoyer 75f812
     . /tmp/bridge.info
Harald Hoyer 75f812
@@ -79,15 +75,25 @@ print_s390() {
Harald Hoyer 75f812
     echo "OPTIONS=\"${OPTIONS}\""
Harald Hoyer 75f812
 }
Harald Hoyer 75f812
 
Harald Hoyer 75f812
+for netup in /tmp/net.*.did-setup ; do
Harald Hoyer 75f812
+    [ -f $netup ] || continue
Harald Hoyer 75f812
 
Harald Hoyer 75f812
-for netif in $IFACES ; do
Harald Hoyer 75f812
+    netif=${netup%%.did-setup}
Harald Hoyer 75f812
+    netif=${netif##*/net.}
Harald Hoyer 75f812
     [ -e /tmp/ifcfg/ifcfg-$netif ] && continue
Harald Hoyer 75f812
-    # bridge?
Harald Hoyer 75f812
     unset bridge
Harald Hoyer 75f812
     unset bond
Harald Hoyer 75f812
     unset bondslaves
Harald Hoyer 75f812
     unset bondname
Harald Hoyer 75f812
     unset bondoptions
Harald Hoyer 75f812
+    unset uuid
Harald Hoyer 75f812
+    unset ip
Harald Hoyer 75f812
+    unset gw
Harald Hoyer 75f812
+    unset mtu
Harald Hoyer 75f812
+    unset mask
Harald Hoyer 75f812
+    unset macaddr
Harald Hoyer 75f812
+    unset slave
Harald Hoyer 75f812
+    unset ethname
Harald Hoyer 75f812
     [ -e /tmp/bond.${netif}.info ] && . /tmp/bond.${netif}.info
Harald Hoyer 75f812
 
Harald Hoyer 75f812
     uuid=$(cat /proc/sys/kernel/random/uuid)
Harald Hoyer 75f812
@@ -100,45 +106,46 @@ for netif in $IFACES ; do
Harald Hoyer 75f812
     cat /sys/class/net/$netif/address > /tmp/net.$netif.hwaddr
Harald Hoyer 75f812
     {
Harald Hoyer 75f812
         echo "# Generated by dracut initrd"
Harald Hoyer 75f812
-        echo "DEVICE=$netif"
Harald Hoyer 75f812
+        echo "DEVICE=\"$netif\""
Harald Hoyer 75f812
         echo "ONBOOT=yes"
Harald Hoyer 75f812
         echo "NETBOOT=yes"
Harald Hoyer 75f812
-        echo "UUID=$uuid"
Harald Hoyer 75f812
-        [ -n "$mtu" ] && echo "MTU=$mtu"
Harald Hoyer 75f812
-        if [ -f /tmp/net.$netif.lease ]; then
Harald Hoyer 75f812
+        echo "UUID=\"$uuid\""
Harald Hoyer 75f812
+        if [ -f /tmp/dhclient.$netif.lease ]; then
Harald Hoyer 75f812
+            [ -f /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts
Harald Hoyer 75f812
             strstr "$ip" '*:*:*' && echo "IPV6INIT=yes"
Harald Hoyer 75f812
             if [ -f /tmp/net.$netif.has_ibft_config ]; then
Harald Hoyer 75f812
                 echo "BOOTPROTO=ibft"
Harald Hoyer 75f812
             else
Harald Hoyer 75f812
                 echo "BOOTPROTO=dhcp"
Harald Hoyer 75f812
             fi
Harald Hoyer 75f812
-            cp /tmp/net.$netif.lease /tmp/ifcfg-leases/dhclient-$uuid-$netif.lease
Harald Hoyer 75f812
+            cp /tmp/dhclient.$netif.lease /tmp/ifcfg-leases/dhclient-$uuid-$netif.lease
Harald Hoyer 75f812
         else
Harald Hoyer 75f812
             # If we've booted with static ip= lines, the override file is there
Harald Hoyer 75f812
             [ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override
Harald Hoyer 75f812
             if strstr "$ip" '*:*:*'; then
Harald Hoyer 75f812
                 echo "IPV6INIT=yes"
Harald Hoyer 75f812
                 echo "IPV6_AUTOCONF=no"
Harald Hoyer 75f812
-                echo "IPV6ADDR=$ip/$mask"
Harald Hoyer 75f812
+                echo "IPV6ADDR=\"$ip/$mask\""
Harald Hoyer 75f812
             else
Harald Hoyer 75f812
                 if [ -f /tmp/net.$netif.has_ibft_config ]; then
Harald Hoyer 75f812
                     echo "BOOTPROTO=ibft"
Harald Hoyer 75f812
                 else
Harald Hoyer 75f812
                     echo "BOOTPROTO=none"
Harald Hoyer 75f812
-                    echo "IPADDR=$ip"
Harald Hoyer 75f812
+                    echo "IPADDR=\"$ip\""
Harald Hoyer 75f812
                     if strstr "$mask" "."; then
Harald Hoyer 75f812
-                        echo "NETMASK=$mask"
Harald Hoyer 75f812
+                        echo "NETMASK=\"$mask\""
Harald Hoyer 75f812
                     else
Harald Hoyer 75f812
-                        echo "PREFIX=$mask"
Harald Hoyer 75f812
+                        echo "PREFIX=\"$mask\""
Harald Hoyer 75f812
                     fi
Harald Hoyer 75f812
                 fi
Harald Hoyer 75f812
             fi
Harald Hoyer 75f812
             if strstr "$gw" '*:*:*'; then
Harald Hoyer 75f812
-                echo "IPV6_DEFAULTGW=$gw"
Harald Hoyer 75f812
+                echo "IPV6_DEFAULTGW=\"$gw\""
Harald Hoyer 75f812
             elif [ -n "$gw" ]; then
Harald Hoyer 75f812
-                echo "GATEWAY=$gw"
Harald Hoyer 75f812
+                echo "GATEWAY=\"$gw\""
Harald Hoyer 75f812
             fi
Harald Hoyer 75f812
         fi
Harald Hoyer 75f812
+        [ -n "$mtu" ] && echo "MTU=\"$mtu\""
Harald Hoyer 75f812
     } > /tmp/ifcfg/ifcfg-$netif
Harald Hoyer 75f812
 
Harald Hoyer 75f812
     # bridge needs different things written to ifcfg
Harald Hoyer 75f812
@@ -146,14 +153,14 @@ for netif in $IFACES ; do
Harald Hoyer 75f812
         # standard interface
Harald Hoyer 75f812
         {
Harald Hoyer 75f812
             if [ -n "$macaddr" ]; then
Harald Hoyer 75f812
-                echo "MACADDR=$macaddr"
Harald Hoyer 75f812
+                echo "MACADDR=\"$macaddr\""
Harald Hoyer 75f812
             else
Harald Hoyer 75f812
                 echo "HWADDR=\"$(cat /sys/class/net/$netif/address)\""
Harald Hoyer 75f812
             fi
Harald Hoyer 75f812
             print_s390 $netif
Harald Hoyer 75f812
             echo "TYPE=Ethernet"
Harald Hoyer 75f812
             echo "NAME=\"$netif\""
Harald Hoyer 75f812
-            [ -n "$mtu" ] && echo "MTU=$mtu"
Harald Hoyer 75f812
+            [ -n "$mtu" ] && echo "MTU=\"$mtu\""
Harald Hoyer 75f812
         } >> /tmp/ifcfg/ifcfg-$netif
Harald Hoyer 75f812
     fi
Harald Hoyer 75f812
 
Harald Hoyer 75f812
@@ -170,14 +177,14 @@ for netif in $IFACES ; do
Harald Hoyer 75f812
             # write separate ifcfg file for the raw eth interface
Harald Hoyer 75f812
             {
Harald Hoyer 75f812
                 echo "# Generated by dracut initrd"
Harald Hoyer 75f812
-                echo "DEVICE=$slave"
Harald Hoyer 75f812
+                echo "DEVICE=\"$slave\""
Harald Hoyer 75f812
                 echo "TYPE=Ethernet"
Harald Hoyer 75f812
                 echo "ONBOOT=yes"
Harald Hoyer 75f812
                 echo "NETBOOT=yes"
Harald Hoyer 75f812
-                echo "HWADDR=$(cat /sys/class/net/$slave/address)"
Harald Hoyer 75f812
+                echo "HWADDR=\"$(cat /sys/class/net/$slave/address)\""
Harald Hoyer 75f812
                 echo "SLAVE=yes"
Harald Hoyer 75f812
-                echo "MASTER=$netif"
Harald Hoyer 75f812
-                echo "NAME=$slave"
Harald Hoyer 75f812
+                echo "MASTER=\"$netif\""
Harald Hoyer 75f812
+                echo "NAME=\"$slave\""
Harald Hoyer 75f812
             } >> /tmp/ifcfg/ifcfg-$slave
Harald Hoyer 75f812
         done
Harald Hoyer 75f812
     fi
Harald Hoyer 75f812
@@ -191,45 +198,45 @@ for netif in $IFACES ; do
Harald Hoyer 75f812
         if [ "$ethname" = "$bondname" ] ; then
Harald Hoyer 75f812
             {
Harald Hoyer 75f812
                 echo "# Generated by dracut initrd"
Harald Hoyer 75f812
-                echo "DEVICE=$bondname"
Harald Hoyer 75f812
+                echo "DEVICE=\"$bondname\""
Harald Hoyer 75f812
                 echo "ONBOOT=yes"
Harald Hoyer 75f812
                 echo "NETBOOT=yes"
Harald Hoyer 75f812
                 # This variable is an indicator of a bond interface for initscripts
Harald Hoyer 75f812
                 echo "BONDING_OPTS=\"$bondoptions\""
Harald Hoyer 75f812
-                echo "BRIDGE=$netif"
Harald Hoyer 75f812
+                echo "BRIDGE=\"$netif\""
Harald Hoyer 75f812
                 echo "NAME=\"$bondname\""
Harald Hoyer 75f812
             } >> /tmp/ifcfg/ifcfg-$bondname
Harald Hoyer 75f812
             for slave in $bondslaves ; do
Harald Hoyer 75f812
                 # write separate ifcfg file for the raw eth interface
Harald Hoyer 75f812
                 {
Harald Hoyer 75f812
                     echo "# Generated by dracut initrd"
Harald Hoyer 75f812
-                    echo "DEVICE=$slave"
Harald Hoyer 75f812
+                    echo "DEVICE=\"$slave\""
Harald Hoyer 75f812
                     echo "TYPE=Ethernet"
Harald Hoyer 75f812
                     echo "ONBOOT=yes"
Harald Hoyer 75f812
                     echo "NETBOOT=yes"
Harald Hoyer 75f812
-                    echo "HWADDR=$(cat /sys/class/net/$slave/address)"
Harald Hoyer 75f812
+                    echo "HWADDR=\"$(cat /sys/class/net/$slave/address)\""
Harald Hoyer 75f812
                     echo "SLAVE=yes"
Harald Hoyer 75f812
-                    echo "MASTER=$bondname"
Harald Hoyer 75f812
-                    echo "NAME=$slave"
Harald Hoyer 75f812
+                    echo "MASTER=\"$bondname\""
Harald Hoyer 75f812
+                    echo "NAME=\"$slave\""
Harald Hoyer 75f812
                 } >> /tmp/ifcfg/ifcfg-$slave
Harald Hoyer 75f812
             done
Harald Hoyer 75f812
         else
Harald Hoyer 75f812
             # write separate ifcfg file for the raw eth interface
Harald Hoyer 75f812
             {
Harald Hoyer 75f812
                 echo "# Generated by dracut initrd"
Harald Hoyer 75f812
-                echo "DEVICE=$ethname"
Harald Hoyer 75f812
+                echo "DEVICE=\"$ethname\""
Harald Hoyer 75f812
                 echo "TYPE=Ethernet"
Harald Hoyer 75f812
                 echo "ONBOOT=yes"
Harald Hoyer 75f812
                 echo "NETBOOT=yes"
Harald Hoyer 75f812
-                echo "HWADDR=$(cat /sys/class/net/$ethname/address)"
Harald Hoyer 75f812
-                echo "BRIDGE=$netif"
Harald Hoyer 75f812
-                echo "NAME=$ethname"
Harald Hoyer 75f812
+                echo "HWADDR=\"$(cat /sys/class/net/$ethname/address)\""
Harald Hoyer 75f812
+                echo "BRIDGE=\"$netif\""
Harald Hoyer 75f812
+                echo "NAME=\"$ethname\""
Harald Hoyer 75f812
             } >> /tmp/ifcfg/ifcfg-$ethname
Harald Hoyer 75f812
         fi
Harald Hoyer 75f812
     fi
Harald Hoyer 75f812
     i=1
Harald Hoyer 75f812
     for ns in $(getargs nameserver); do
Harald Hoyer 75f812
-        echo "DNS${i}=${ns}" >> /tmp/ifcfg/ifcfg-$netif
Harald Hoyer 75f812
+        echo "DNS${i}=\"${ns}\"" >> /tmp/ifcfg/ifcfg-$netif
Harald Hoyer 75f812
         i=$((i+1))
Harald Hoyer 75f812
     done
Harald Hoyer 75f812
 done