rename secondary user
[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 # This condition is only needed because the nfsroot I use
28 # is based on Jessie, which has an old udev which can't
29 # figure out the persistent interface name used in stretch.
30 if ifclass VM; then NIC1=ens3; return; fi
31 if [[ ! $name ]]; then
32 echo "$0: error: could not find systemd predictable network name. Using $NIC1."
33 fi
34 }
35
36 if [ -z "$NIC1" ]; then
37 echo "ERROR: \$NIC1 is not defined. Cannot configure /etc/network/interfaces properly."
38 fi
39 newnicnames
40 CIDR=$(ip -o -f inet addr show $NIC1 | awk '{print $4}')
41 if ifclass DHCPC && [ $FAI_ACTION = "install" -o $FAI_ACTION = "dirinstall" ]; then
42
43 if ifclass VM; then
44 # note, this condition would apply to the elif below too,
45 # but I don't specify a static ip in fai, so not bothering
46 cat > $target/etc/network/interfaces <<-EOF
47 # generated by FAI
48 auto lo $NIC1
49 iface lo inet loopback
50 iface $NIC1 inet dhcp
51 EOF
52 else
53 cat > $target/etc/network/interfaces <<-EOF
54 # generated by FAI
55 auto lo br0
56 iface lo inet loopback
57 iface $NIC1 inet manual
58 # make a bridge by default so we can have bridged vms.
59 # Some example I read had stp on, but i don't need stp,
60 # and it causes a vm to fail pxe boot, presumably unless
61 # you add some delay.
62 # http://wiki.libvirt.org/page/PXE_boot_%28or_dhcp%29_on_guest_failed
63 iface br0 inet dhcp
64 bridge_ports $NIC1
65 bridge_stp off
66 bridge_maxwait 0
67 EOF
68 fi
69 elif [ $FAI_ACTION = "install" -o $FAI_ACTION = "dirinstall" ]; then
70 [ -n "$CIDR" ] && cat > $target/etc/network/interfaces <<-EOF
71 # generated by FAI
72 auto lo $NIC1
73 iface lo inet loopback
74 iface $NIC1 inet static
75 address $CIDR
76 gateway $GATEWAYS
77 EOF
78 [ -n "$NETWORK" ] && echo "localnet $NETWORK" > $target/etc/networks
79 if [ ! -L $target/etc/resolv.conf -a -e /etc/resolv.conf ]; then
80 cp -p /etc/resolv.conf $target/etc
81 fi
82 fi
83
84 # here fcopy is mostly used, when installing a client for running in a
85 # different subnet than during the installation
86 fcopy -iM /etc/resolv.conf
87 fcopy -iM /etc/network/interfaces /etc/networks
88
89 exit $error