]> git.ipfire.org Git - thirdparty/dracut.git/blame - modules.d/45ifcfg/write-ifcfg.sh
ifcfg/write-ifcfg.sh: "IPV6INIT=yes" check also for non-dhcp
[thirdparty/dracut.git] / modules.d / 45ifcfg / write-ifcfg.sh
CommitLineData
9f73fedf 1#!/bin/sh
cc02093d
HH
2# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3# ex: ts=8 sw=4 sts=4 et filetype=sh
9f73fedf 4
47b5c0f2
WT
5# NFS root might have reached here before /tmp/net.ifaces was written
6udevadm settle --timeout=30
9f73fedf 7
96fb9c8d
VB
8if [ -e /tmp/bridge.info ]; then
9 . /tmp/bridge.info
10fi
11
030b00b8
RV
12if [ -e /tmp/vlan.info ]; then
13 . /tmp/vlan.info
14fi
15
d125a470 16mkdir -m 0755 -p /tmp/ifcfg/
66666c67 17mkdir -m 0755 -p /tmp/ifcfg-leases/
96fb9c8d 18
a82d207b
HH
19get_config_line_by_subchannel()
20{
21 local CHANNEL
22 local line
23
24 CHANNELS="$1"
25 while read line; do
26 if strstr "$line" "$CHANNELS"; then
27 echo $line
28 return 0
29 fi
30 done < /etc/ccw.conf
31 return 1
32}
33
34print_s390() {
35 local _netif
36 local SUBCHANNELS
37 local OPTIONS
38 local NETTYPE
39 local CONFIG_LINE
40 local i
41 local channel
02805bd1 42 local OLD_IFS
a82d207b
HH
43
44 _netif="$1"
45 # if we find ccw channel, then use those, instead of
46 # of the MAC
47 SUBCHANNELS=$({
48 for i in /sys/class/net/$_netif/device/cdev[0-9]*; do
49 [ -e $i ] || continue
50 channel=$(readlink -f $i)
51 echo -n "${channel##*/},"
52 done
53 })
54 [ -n "$SUBCHANNELS" ] || return 1
55
56 SUBCHANNELS=${SUBCHANNELS%,}
57 echo "SUBCHANNELS=\"${SUBCHANNELS}\""
a82d207b 58
79b3c8bf
HH
59 CONFIG_LINE=$(get_config_line_by_subchannel $SUBCHANNELS)
60 [ $? -ne 0 -o -z "$CONFIG_LINE" ] && return 0
a82d207b 61
02805bd1 62 OLD_IFS=$IFS
a82d207b 63 IFS=","
02805bd1
HH
64 set -- $CONFIG_LINE
65 IFS=$OLD_IFS
a82d207b
HH
66 NETTYPE=$1
67 shift
68 SUBCHANNELS="$1"
69 OPTIONS=""
70 shift
71 while [ $# -gt 0 ]; do
72 case $1 in
73 *=*) OPTIONS="$OPTIONS $1";;
74 esac
75 shift
76 done
77 OPTIONS=${OPTIONS## }
78 echo "NETTYPE=\"${NETTYPE}\""
79 echo "OPTIONS=\"${OPTIONS}\""
79b3c8bf 80 return 0
a82d207b
HH
81}
82
caf207af
HH
83for netup in /tmp/net.*.did-setup ; do
84 [ -f $netup ] || continue
a82d207b 85
caf207af
HH
86 netif=${netup%%.did-setup}
87 netif=${netif##*/net.}
2c19a5fa 88 strglobin "$netif" ":*:*:*:*:" && continue
cbd60fca 89 [ -e /tmp/ifcfg/ifcfg-$netif ] && continue
beb097d9 90 unset bridge
96fb9c8d 91 unset bond
d136ca4e
HH
92 unset bondslaves
93 unset bondname
94 unset bondoptions
caf207af
HH
95 unset uuid
96 unset ip
97 unset gw
98 unset mtu
99 unset mask
100 unset macaddr
101 unset slave
102 unset ethname
d136ca4e
HH
103 [ -e /tmp/bond.${netif}.info ] && . /tmp/bond.${netif}.info
104
66666c67 105 uuid=$(cat /proc/sys/kernel/random/uuid)
beb097d9
WT
106 if [ "$netif" = "$bridgename" ]; then
107 bridge=yes
96fb9c8d
VB
108 elif [ "$netif" = "$bondname" ]; then
109 # $netif can't be bridge and bond at the same time
110 bond=yes
beb097d9 111 fi
030b00b8
RV
112 if [ "$netif" = "$vlanname" ]; then
113 vlan=yes
114 fi
43a85a73
HH
115 [ -e /sys/class/net/$netif/address ] && \
116 cat /sys/class/net/$netif/address > /tmp/net.$netif.hwaddr
c98bcec8 117 {
3b403b32 118 echo "# Generated by dracut initrd"
caf207af 119 echo "DEVICE=\"$netif\""
cc02093d
HH
120 echo "ONBOOT=yes"
121 echo "NETBOOT=yes"
caf207af 122 echo "UUID=\"$uuid\""
1230f3bc 123 strstr "$(ip -6 addr show dev $netif)" 'inet6' && echo "IPV6INIT=yes"
caf207af
HH
124 if [ -f /tmp/dhclient.$netif.lease ]; then
125 [ -f /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts
fd8e4aef
RV
126 if [ -f /tmp/net.$netif.has_ibft_config ]; then
127 echo "BOOTPROTO=ibft"
128 else
129 echo "BOOTPROTO=dhcp"
130 fi
caf207af 131 cp /tmp/dhclient.$netif.lease /tmp/ifcfg-leases/dhclient-$uuid-$netif.lease
cc02093d 132 else
30430fbe 133 # If we've booted with static ip= lines, the override file is there
3b403b32 134 [ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override
2c19a5fa 135 if strglobin "$ip" '*:*:*'; then
32ec0a76 136 echo "IPV6INIT=yes"
30430fbe 137 echo "IPV6_AUTOCONF=no"
caf207af 138 echo "IPV6ADDR=\"$ip/$mask\""
5bfbfbfc 139 else
e0e99c59 140 if [ -f /tmp/net.$netif.has_ibft_config ]; then
fd8e4aef 141 echo "BOOTPROTO=ibft"
30430fbe 142 else
fd8e4aef 143 echo "BOOTPROTO=none"
caf207af 144 echo "IPADDR=\"$ip\""
fd8e4aef 145 if strstr "$mask" "."; then
caf207af 146 echo "NETMASK=\"$mask\""
fd8e4aef 147 else
caf207af 148 echo "PREFIX=\"$mask\""
fd8e4aef 149 fi
30430fbe
WW
150 fi
151 fi
2c19a5fa 152 if strglobin "$gw" '*:*:*'; then
caf207af 153 echo "IPV6_DEFAULTGW=\"$gw\""
30430fbe 154 elif [ -n "$gw" ]; then
caf207af 155 echo "GATEWAY=\"$gw\""
5bfbfbfc 156 fi
cc02093d 157 fi
caf207af 158 [ -n "$mtu" ] && echo "MTU=\"$mtu\""
c98bcec8 159 } > /tmp/ifcfg/ifcfg-$netif
beb097d9 160
4431431c 161 # bridge needs different things written to ifcfg
030b00b8 162 if [ -z "$bridge" ] && [ -z "$bond" ] && [ -z "$vlan" ]; then
beb097d9 163 # standard interface
cc02093d 164 {
79b3c8bf
HH
165 [ -n "$macaddr" ] && echo "MACADDR=\"$macaddr\""
166 if ! print_s390 $netif; then
fb0e5184
HH
167 if [ -z "$macaddr" ] && \
168 ! is_persistent_ethernet_name "$netif" && \
2e094b20
HH
169 [ -f /sys/class/net/$netif/addr_assign_type ] && \
170 [ "$(cat /sys/class/net/$netif/addr_assign_type)" = "0" ] && \
fb0e5184
HH
171 [ -f /sys/class/net/$netif/address ]; then
172 echo "HWADDR=\"$(cat /sys/class/net/$netif/address)\""
173 fi
a82d207b 174 fi
c98bcec8 175 echo "TYPE=Ethernet"
284d62da 176 echo "NAME=\"$netif\""
caf207af 177 [ -n "$mtu" ] && echo "MTU=\"$mtu\""
cc02093d 178 } >> /tmp/ifcfg/ifcfg-$netif
96fb9c8d
VB
179 fi
180
030b00b8
RV
181 if [ -n "$vlan" ] ; then
182 {
183 echo "TYPE=Vlan"
184 echo "NAME=\"$netif\""
185 echo "VLAN=yes"
186 echo "PHYSDEV=\"$phydevice\""
187 } >> /tmp/ifcfg/ifcfg-$netif
188 fi
189
96fb9c8d
VB
190 if [ -n "$bond" ] ; then
191 # bond interface
192 {
193 # This variable is an indicator of a bond interface for initscripts
194 echo "BONDING_OPTS=\"$bondoptions\""
284d62da 195 echo "NAME=\"$netif\""
6625c085 196 echo "TYPE=Bond"
96fb9c8d
VB
197 } >> /tmp/ifcfg/ifcfg-$netif
198
199 for slave in $bondslaves ; do
200 # write separate ifcfg file for the raw eth interface
201 {
202 echo "# Generated by dracut initrd"
caf207af 203 echo "DEVICE=\"$slave\""
96fb9c8d 204 echo "TYPE=Ethernet"
6625c085 205 echo "ONBOOT=yes"
96fb9c8d 206 echo "NETBOOT=yes"
caf207af 207 echo "HWADDR=\"$(cat /sys/class/net/$slave/address)\""
96fb9c8d 208 echo "SLAVE=yes"
caf207af
HH
209 echo "MASTER=\"$netif\""
210 echo "NAME=\"$slave\""
96fb9c8d
VB
211 } >> /tmp/ifcfg/ifcfg-$slave
212 done
213 fi
214
215 if [ -n "$bridge" ] ; then
beb097d9 216 # bridge
cc02093d
HH
217 {
218 echo "TYPE=Bridge"
284d62da 219 echo "NAME=\"$netif\""
cc02093d 220 } >> /tmp/ifcfg/ifcfg-$netif
96fb9c8d
VB
221 if [ "$ethname" = "$bondname" ] ; then
222 {
96fb9c8d 223 echo "# Generated by dracut initrd"
caf207af 224 echo "DEVICE=\"$bondname\""
6625c085 225 echo "ONBOOT=yes"
96fb9c8d 226 echo "NETBOOT=yes"
3afca618 227 # This variable is an indicator of a bond interface for initscripts
96fb9c8d 228 echo "BONDING_OPTS=\"$bondoptions\""
caf207af 229 echo "BRIDGE=\"$netif\""
3b403b32 230 echo "NAME=\"$bondname\""
96fb9c8d
VB
231 } >> /tmp/ifcfg/ifcfg-$bondname
232 for slave in $bondslaves ; do
233 # write separate ifcfg file for the raw eth interface
96fb9c8d
VB
234 {
235 echo "# Generated by dracut initrd"
caf207af 236 echo "DEVICE=\"$slave\""
96fb9c8d 237 echo "TYPE=Ethernet"
6625c085 238 echo "ONBOOT=yes"
96fb9c8d 239 echo "NETBOOT=yes"
caf207af 240 echo "HWADDR=\"$(cat /sys/class/net/$slave/address)\""
96fb9c8d 241 echo "SLAVE=yes"
caf207af
HH
242 echo "MASTER=\"$bondname\""
243 echo "NAME=\"$slave\""
96fb9c8d
VB
244 } >> /tmp/ifcfg/ifcfg-$slave
245 done
246 else
247 # write separate ifcfg file for the raw eth interface
248 {
249 echo "# Generated by dracut initrd"
caf207af 250 echo "DEVICE=\"$ethname\""
96fb9c8d 251 echo "TYPE=Ethernet"
6625c085 252 echo "ONBOOT=yes"
96fb9c8d 253 echo "NETBOOT=yes"
caf207af
HH
254 echo "HWADDR=\"$(cat /sys/class/net/$ethname/address)\""
255 echo "BRIDGE=\"$netif\""
256 echo "NAME=\"$ethname\""
96fb9c8d
VB
257 } >> /tmp/ifcfg/ifcfg-$ethname
258 fi
beb097d9 259 fi
eb6e141a
HH
260 i=1
261 for ns in $(getargs nameserver); do
caf207af 262 echo "DNS${i}=\"${ns}\"" >> /tmp/ifcfg/ifcfg-$netif
eb6e141a
HH
263 i=$((i+1))
264 done
8ecd9d01 265done
7a6e646c
PS
266
267# Pass network opts
d37ad6ae 268mkdir -m 0755 -p /run/initramfs/state/etc/sysconfig/network-scripts
66666c67 269mkdir -m 0755 -p /run/initramfs/state/var/lib/dhclient
d37ad6ae 270echo "files /etc/sysconfig/network-scripts" >> /run/initramfs/rwtab
66666c67 271echo "files /var/lib/dhclient" >> /run/initramfs/rwtab
d37ad6ae
WW
272{
273 cp /tmp/net.* /run/initramfs/
335bb5a3 274 cp /tmp/net.$netif.resolv.conf /run/initramfs/state/etc/resolv.conf
31cfc9aa 275 copytree /tmp/ifcfg /run/initramfs/state/etc/sysconfig/network-scripts
66666c67 276 cp /tmp/ifcfg-leases/* /run/initramfs/state/var/lib/dhclient
d37ad6ae 277} > /dev/null 2>&1