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