3 # modified from upstream fai example
4 error
=0; trap 'error=$(($?>$error?$?:$error))' ERR
# save maximum error code
7 # network configuration using ubuntu's netplan.io
10 echo "Generating netplan configuration for $IFNAME ($METHOD)" >&2
11 echo "# generated by FAI"
14 echo " renderer: $RENDERER"
24 echo " addresses: [$CIDR]"
25 echo " gateway4: $GATEWAYS_1"
27 echo " search: [$DOMAIN]"
28 echo " addresses: [${DNSSRVS// /, }]"
35 # classic network configuration using /etc/network/interfaces
38 echo "Generating interface configuration for $IFNAME ($METHOD)" >&2
39 echo "# generated by FAI"
41 echo "iface $IFNAME inet $METHOD"
44 echo " address $IPADDR"
45 echo " netmask $NETMASK"
46 echo " broadcast $BROADCAST"
47 echo " gateway $GATEWAYS"
54 # determine predictable network names only for stretch and above
56 [ $do_init_tasks -eq 0 ] && return
57 [ -z "$NIC1" ] && return
58 ver
=$
($ROOTCMD dpkg-query
--showformat='${Version}' --show udev
)
59 if dpkg
--compare-versions $ver lt
220-7; then
64 fields
="ID_NET_NAME_FROM_DATABASE ID_NET_NAME_ONBOARD ID_NET_NAME_SLOT ID_NET_NAME_PATH"
65 for field
in $fields; do
66 name
=$
(udevadm info
/sys
/class
/net
/$NIC1 |
sed -rn "s/^E: $field=(.+)/\1/p")
72 if [[ ! $name ]]; then
73 echo "$0: error: could not find systemd predictable network name. Using $NIC1."
77 if [ -z "$NIC1" ]; then
78 echo "WARNING: \$NIC1 is not defined. Cannot add ethernet to /etc/network/interfaces."
80 CIDR
=$
(ip
-o -f inet addr show
$NIC1 |
awk '{print $4}')
85 ifclass DHCPC
&& METHOD
=dhcp || METHOD
=static
86 ifclass XORG
&& RENDERER
=NetworkManager || RENDERER
=networkd
88 if [ -d $target/etc
/netplan
]; then
89 # Ubuntu >= 17.10 with netplan.io
90 if [ -n "$NIC1" ]; then
91 netplan_yaml
$NIC1 $METHOD > $target/etc
/netplan
/01-${NIC1}.yaml
93 elif [ -d $target/etc
/network
/interfaces.d
]; then
94 # ifupdown >= 0.7.41 (Debian >= 8, Ubuntu >= 14.04)
97 # note, this condition would apply to the elif below too,
98 # but I don't specify a static ip in fai, so not bothering
99 cat > $target/etc
/network
/interfaces
<<-EOF
102 iface lo inet loopback
103 iface $NIC1 inet dhcp
104 iface $NIC1 inet6 auto
107 elif ifclass LINODE
; then
108 # NIC1 is wrong, probably because the installer distro
109 # is stretch and the installed one is buster.
110 # todo: after upgrading installer to buster,
111 # try removing this condition
112 cat > $target/etc
/network
/interfaces
<<EOF
115 iface lo inet loopback
116 iface $linode_if inet dhcp
117 iface $linode_if inet6 auto
121 cat > $target/etc
/network
/interfaces
<<EOF
124 iface lo inet loopback
125 iface $NIC1 inet manual
126 # make a bridge by default so we can have bridged vms.
127 # Some example I read had stp on, but i don't need stp,
128 # and it causes a vm to fail pxe boot, presumably unless
129 # you add some delay.
130 # http://wiki.libvirt.org/page/PXE_boot_%28or_dhcp%29_on_guest_failed
138 if ifclass LINODE
; then
139 mkdir
-p $target/etc
/initramfs-tools
/conf.d
140 cat >$target/etc
/initramfs-tools
/conf.d
/mine
<<EOF
141 # dhcp in initramfs doesn't work on linode. i dunno why, whatever.
142 # man 5 initramfs.conf
143 # /usr/share/doc/klibc-utils/README.ipconfig.gz
144 # /usr/share/initramfs-tools/scripts/functions
145 IP=$linode_ip::$linode_gw:255.255.255.0::$linode_if:off
151 iface_stanza lo loopback
152 iface_stanza
$NIC1 $METHOD
153 ) > $target/etc
/network
/interfaces
156 if ! ifclass DHCPC
; then
157 [ -n "$NETWORK" ] && echo "localnet $NETWORK" > $target/etc
/networks
158 if [ ! -L $target/etc
/resolv.conf
-a -e /etc
/resolv.conf
]; then
159 cp -p /etc
/resolv.conf
$target/etc
166 # here fcopy is mostly used, when installing a client for running in a
167 # different subnet than during the installation
168 fcopy
-iM /etc
/resolv.conf
169 fcopy
-iM /etc
/network
/interfaces
/etc
/networks