fix stretch, upgrade from jessie broke
[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 if ! ifclass STABLE; then
7 if ifclass VM; then
8 # For a vm, we only get ID_NET_NAME_MAC from below,
9 # but when it reboots, it uses ID_NET_NAME_SLOT.
10 NIC1=ens3
11 else
12 # get persistent interface name. Note, these class conditions
13 # will need to get modified for new oses. testing vm doesn't use
14 # it right now, but other vms do I'm sure.
15 for field in ID_NET_NAME_FROM_DATABASE \
16 ID_NET_NAME_ONBOARD \
17 ID_NET_NAME_SLOT \
18 ID_NET_NAME_PATH \
19 ID_NET_NAME_MAC; do
20 name=$(udevadm info /sys/class/net/$NIC1 | sed -rn "s/^E: $field=(.+)/\1/p")
21 if [[ $name ]]; then
22 NIC1=$name
23 break
24 fi
25 done
26 if [[ ! $name ]]; then
27 echo "$0: error: could not find systemd predictable network name"
28 exit 1
29 fi
30 fi
31 fi
32
33 if ifclass DHCPC && [ $FAI_ACTION = "install" -o $FAI_ACTION = "dirinstall" ]
34 then
35 if ifclass VM; then
36 cat > $target/etc/network/interfaces <<-EOF
37 # generated by FAI
38 auto lo $NIC1
39 iface lo inet loopback
40 iface $NIC1 inet dhcp
41 EOF
42 else
43 cat > $target/etc/network/interfaces <<-EOF
44 # generated by FAI
45 auto lo br0
46 iface lo inet loopback
47 iface $NIC1 inet manual
48 # make a bridge by default so we can have bridged vms.
49 # Some example I read had stp on, but i don't need stp,
50 # and it causes a vm to fail pxe boot, presumably unless
51 # you add some delay.
52 # http://wiki.libvirt.org/page/PXE_boot_%28or_dhcp%29_on_guest_failed
53 iface br0 inet dhcp
54 bridge_ports $NIC1
55 bridge_stp off
56 bridge_maxwait 0
57 EOF
58 fi
59 elif [ $FAI_ACTION = "install" -o $FAI_ACTION = "dirinstall" ]
60 then
61 [ -n "$IPADDR" ] && cat > $target/etc/network/interfaces <<-EOF
62 # generated by FAI
63 auto lo $NIC1
64 iface lo inet loopback
65 iface $NIC1 inet static
66 address $IPADDR
67 netmask $NETMASK
68 broadcast $BROADCAST
69 gateway $GATEWAYS
70 EOF
71 [ -n "$NETWORK" ] && echo "localnet $NETWORK" > $target/etc/networks
72 if [ ! -L $target/etc/resolv.conf -a -e /etc/resolv.conf ]; then
73 cp -p /etc/resolv.conf $target/etc
74 fi
75 fi
76
77 # here fcopy is mostly used, when installing a client for running in a
78 # different subnet than during the installation
79 fcopy -iM /etc/resolv.conf
80 fcopy -iM /etc/network/interfaces /etc/networks
81
82 exit $error