-if ifclass DHCPC && [ $FAI_ACTION = "install" -o $FAI_ACTION = "dirinstall" ]; then
-
- cat > $target/etc/network/interfaces <<-EOF
- # generated by FAI
- auto lo $NIC1
- iface lo inet loopback
- iface $NIC1 inet dhcp
-EOF
-elif [ $FAI_ACTION = "install" -o $FAI_ACTION = "dirinstall" ]; then
- [ -n "$CIDR" ] && cat > $target/etc/network/interfaces <<-EOF
- # generated by FAI
- auto lo $NIC1
- iface lo inet loopback
- iface $NIC1 inet static
- address $CIDR
- gateway $GATEWAYS
-EOF
- [ -n "$NETWORK" ] && echo "localnet $NETWORK" > $target/etc/networks
- if [ ! -L $target/etc/resolv.conf -a -e /etc/resolv.conf ]; then
- cp -p /etc/resolv.conf $target/etc
+newnicnames
+
+case "$FAI_ACTION" in
+ install|dirinstall)
+ ifclass DHCPC && METHOD=dhcp || METHOD=static
+ ifclass XORG && RENDERER=NetworkManager || RENDERER=networkd
+
+ if [ -d $target/etc/netplan ]; then
+ # Ubuntu >= 17.10 with netplan.io
+ if [ -n "$NIC1" ]; then
+ netplan_yaml $NIC1 $METHOD > $target/etc/netplan/01-${NIC1}.yaml
+ fi
+ elif [ -d $target/etc/network/interfaces.d ]; then
+ # ifupdown >= 0.7.41 (Debian >= 8, Ubuntu >= 14.04)
+ iface_stanza lo loopback > $target/etc/network/interfaces.d/lo
+
+ if [ -n "$NIC1" -a ! -f $target/etc/NetworkManager/NetworkManager.conf ]; then
+ iface_stanza $NIC1 $METHOD > $target/etc/network/interfaces.d/$NIC1
+ fi
+ else
+ (
+ iface_stanza lo loopback
+ iface_stanza $NIC1 $METHOD
+ ) > $target/etc/network/interfaces