Merge branch 'upstream'
[automated-distro-installer] / fai / config / scripts / ROCKY / 60-network-scripts
diff --git a/fai/config/scripts/ROCKY/60-network-scripts b/fai/config/scripts/ROCKY/60-network-scripts
new file mode 100755 (executable)
index 0000000..9777418
--- /dev/null
@@ -0,0 +1,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