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