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 71 72 73 74 75 76 77 78 79 80 81
|
#! /bin/bash
error=0 ; trap "error=$((error|1))" ERR
ifcfg_config() {
cat > $target/etc/sysconfig/network-scripts/ifcfg-$NIC1 <<-EOF
# generated by FAI
TYPE=Ethernet
PROXY_METHOD=none
BOOTPROTO=dhcp
DEFROUTE=yes
BROWSER_ONLY=no
IP4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=no
NAME=$NIC1
DEVICE=$NIC1
ONBOOT=yes
EOF
}
nm_config() {
uuid=$(uuidgen)
cat > $target/etc/NetworkManager/system-connections/${NIC1}.nmconnection << EOF
# generated by FAI
[connection]
id=$NIC1
uuid=$uuid
type=ethernet
autoconnect-priority=-999
interface-name=$NIC1
[ethernet]
[ipv4]
method=auto
[ipv6]
addr-gen-mode=eui64
method=auto
[proxy]
EOF
chmod 600 $target/etc/NetworkManager/system-connections/${NIC1}.nmconnection
}
# determine predictable network names
fields="ID_NET_NAME_FROM_DATABASE ID_NET_NAME_ONBOARD ID_NET_NAME_SLOT ID_NET_NAME_PATH"
for field in $fields; do
name=$(udevadm info /sys/class/net/$NIC1 | sed -rn "s/^E: $field=(.+)/\1/p")
if [[ $name ]]; then
NIC1=$name
break
fi
done
if [[ ! $name ]]; then
echo "$0: error: could not find systemd predictable network name. Using $NIC1."
fi
if [ $FAI_ACTION != "softupdate" ] && ifclass DHCPC; then
. $target/etc/os-release
major=$(echo ${VERSION_ID} | awk -F '.' '{ print $1 }')
if [ $major -lt 9 ]; then
ifcfg_config
else
nm_config
fi
fi
fcopy -iv /etc/sysconfig/network /etc/resolv.conf /etc/networks
fcopy -ivr /etc/sysconfig/network-scripts
exit $error
|