summaryrefslogtreecommitdiff
path: root/modules.d/45ifcfg/write-ifcfg.sh
blob: f5989ef0d62532f2f02c7ee4f1c18959ac2c7e52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh

# 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

for netif in $IFACES ; do
    mkdir -p /tmp/ifcfg/
    # bridge?
    unset bridge
    if [ "$netif" = "$bridgename" ]; then
        bridge=yes
    fi
    cat /sys/class/net/$netif/address > /tmp/net.$netif.hwaddr
    {
	echo "# Generated by dracut initrd" 
	echo "DEVICE=$netif"
	echo "ONBOOT=yes"
	echo "NETBOOT=yes"
	if [ -f /tmp/net.$netif.lease ]; then
	    strstr "$ip" '*:*:*' &&
	    echo "DHCPV6C=yes" 
	    echo "BOOTPROTO=dhcp" 
	else
	    echo "BOOTPROTO=none" 
        # If we've booted with static ip= lines, the override file is there
	    . /tmp/net.$netif.override 
	    echo "IPADDR=$ip"
	    echo "NETMASK=$mask"
	    [ -n "$gw" ] && echo "GATEWAY=$gw"
	fi
    } > /tmp/ifcfg/ifcfg-$netif

    # bridge needs different things written to ifcfg
    if [ -z "$bridge" ]; then
        # standard interface
	{
            echo "HWADDR=$(cat /sys/class/net/$netif/address)"
            echo "TYPE=Ethernet"
            echo "NAME=\"Boot Disk\"" 
	} >> /tmp/ifcfg/ifcfg-$netif
    else
        # bridge
	{
	    echo "TYPE=Bridge"
            echo "NAME=\"Boot Disk\"" 
	} >> /tmp/ifcfg/ifcfg-$netif
        # write separate ifcfg file for the raw eth interface
	{
            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" 
	} >> /tmp/ifcfg/ifcfg-$ethname
    fi
done

# Pass network opts
mkdir /dev/.initramfs/
cp /tmp/net.* /dev/.initramfs/ >/dev/null 2>&1
mkdir -p /dev/.initramfs/state/etc/sysconfig/network-scripts/
cp /tmp/net.$netif.resolv.conf /dev/.initramfs/state/etc/ >/dev/null 2>&1
echo "files /etc/sysconfig/network-scripts" > /dev/.initramfs/rwtab
cp -a /tmp/ifcfg/* /dev/.initramfs/state/etc/sysconfig/network-scripts/ >/dev/null 2>&1