dracut/0078-ifcfg-write-ifcfg.sh-f...

205 lines
7.4 KiB
Diff

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