832461cbb7d6a7083d4153bedf85151355f2d971
[automated-distro-installer] / fai / config / scripts / DEBIAN / 30-interface
1 #! /bin/bash
2
3 # modified from upstream fai example
4 error=0; trap 'error=$(($?>$error?$?:$error))' ERR # save maximum error code
5
6 newnicnames() {
7
8 # determine predictable network names only for stretch and above
9
10 [ $do_init_tasks -eq 0 ] && return
11
12 ver=$($ROOTCMD dpkg-query --showformat='${Version}' --show udev)
13 if dpkg --compare-versions $ver lt 220-7; then
14 return
15 fi
16
17 [ -z $NIC1 ] && return
18
19 fields="ID_NET_NAME_FROM_DATABASE ID_NET_NAME_ONBOARD ID_NET_NAME_SLOT ID_NET_NAME_PATH"
20 for field in $fields; do
21 name=$(udevadm info /sys/class/net/$NIC1 | sed -rn "s/^E: $field=(.+)/\1/p")
22 if [[ $name ]]; then
23 NIC1=$name
24 break
25 fi
26 done
27 if ifclass VM; then
28 NIC1=ens3
29 return
30 fi
31 if [[ ! $name ]]; then
32 echo "$0: error: could not find systemd predictable network name. Using $NIC1."
33 fi
34 }
35
36 newnicnames
37 CIDR=$(ip -o -f inet addr show $NIC1 | awk '{print $4}')
38 if ifclass DHCPC && [ $FAI_ACTION = "install" -o $FAI_ACTION = "dirinstall" ]; then
39
40 if ifclass VM; then
41
42 # note, this condition would apply to the elif below too,
43 # but I don't specify a static ip in fai, so not bothering
44 cat > $target/etc/network/interfaces <<-EOF
45 # generated by FAI
46 auto lo $NIC1
47 iface lo inet loopback
48 iface $NIC1 inet dhcp
49 EOF
50 else
51 cat > $target/etc/network/interfaces <<-EOF
52 # generated by FAI
53 auto lo br0
54 iface lo inet loopback
55 iface $NIC1 inet manual
56 # make a bridge by default so we can have bridged vms.
57 # Some example I read had stp on, but i don't need stp,
58 # and it causes a vm to fail pxe boot, presumably unless
59 # you add some delay.
60 # http://wiki.libvirt.org/page/PXE_boot_%28or_dhcp%29_on_guest_failed
61 iface br0 inet dhcp
62 bridge_ports $NIC1
63 bridge_stp off
64 bridge_maxwait 0
65 EOF
66 fi
67 elif [ $FAI_ACTION = "install" -o $FAI_ACTION = "dirinstall" ]; then
68 [ -n "$CIDR" ] && cat > $target/etc/network/interfaces <<-EOF
69 # generated by FAI
70 auto lo $NIC1
71 iface lo inet loopback
72 iface $NIC1 inet static
73 address $CIDR
74 gateway $GATEWAYS
75 EOF
76 [ -n "$NETWORK" ] && echo "localnet $NETWORK" > $target/etc/networks
77 if [ ! -L $target/etc/resolv.conf -a -e /etc/resolv.conf ]; then
78 cp -p /etc/resolv.conf $target/etc
79 fi
80 fi
81
82 # here fcopy is mostly used, when installing a client for running in a
83 # different subnet than during the installation
84 fcopy -iM /etc/resolv.conf
85 fcopy -iM /etc/network/interfaces /etc/networks
86
87 exit $error