update to 31b795ca71189b326b80666076398f31aea4f2be
[automated-distro-installer] / fai / config / scripts / CENTOS / 60-network-scripts
index a9f6d914a59974be31ea1e1ca089b32ef7f19281..2542b9e4852f145b585b2b53e06ab575d7876fb1 100755 (executable)
@@ -1,29 +1,37 @@
 #! /bin/bash
 
-# (c) Michael Goetze, 2011, mgoetze@mgoetze.net
-
 error=0 ; trap "error=$((error|1))" ERR
 
-# Note: Kudzu will automatically configure eth0 for DHCP
-if [ $FAI_ACTION != "softupdate" ] && ! ifclass DHCPC
-then
-       ainsl -v /etc/sysconfig/network "^GATEWAY=$GATEWAYS_1\$"
-       [ -n "$IPADDR" ] && cat > $target/etc/sysconfig/network-scripts/ifcfg-eth0 <<-EOF
+
+# 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
+       cat > $target/etc/sysconfig/network-scripts/ifcfg-$NIC1 <<-EOF
                # generated by FAI
-               DEVICE=eth0
-               BOOTPROTO=static
+               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
-               HWADDR=`ip l sh dev eth0 | tail -1 | cut -d" " -f6`
-               IPADDR=$IPADDR
-               NETMASK=$NETMASK
        EOF
-    # Kudzu for some reason won't write eth0 into /etc/sysconfig/hwconf
-    # from within the chroot. The following hack puts it in there
-    # so that Kudzu doesn't overwrite our config on first boot.
-    if [ -f $target/sbin/kudzu ]; then
-       grep eth0 $target/etc/sysconfig/hwconf || $ROOTCMD kudzu -c NETWORK -p \
-        >> $target/etc/sysconfig/hwconf
-    fi
 fi
 
 fcopy -iv /etc/sysconfig/network /etc/resolv.conf /etc/networks