21c44d52ec
bfk3 needs more than 10 seconds to bring the interface up and get the lease. TODO: make this configurable.
98 lines
1.8 KiB
Bash
Executable File
98 lines
1.8 KiB
Bash
Executable File
#!/bin/sh
|
|
# parse interface configuration tuples:
|
|
# iface:proto[:ipv4addr/netmask[:ipv4gw]]
|
|
# and write it down as intended
|
|
|
|
fatal() { echo "error: $*" >&2; exit 1; }
|
|
|
|
# simple etcnet configurations are also picked up by NM
|
|
if type -t NetworkManager >&/dev/null ||
|
|
type -t connmand >&/dev/null; then
|
|
NMCTL=yes
|
|
else
|
|
NMCTL=no
|
|
fi
|
|
|
|
ETCNET_IFDIR="/etc/net/ifaces"
|
|
SYSTEMD_IFDIR="/etc/systemd/network"
|
|
|
|
write_iface() {
|
|
case "$proto" in
|
|
dhcp)
|
|
;;
|
|
static)
|
|
[ -n "$ipv4addr" ] || fatal "ipv4addr missing"
|
|
;;
|
|
*)
|
|
fatal "unknown proto value: $proto"
|
|
;;
|
|
esac
|
|
[ -d "$ETCNET_IFDIR" ] && write_etcnet_iface ||:
|
|
[ -d "$SYSTEMD_IFDIR" ] && write_systemd_iface ||:
|
|
}
|
|
|
|
# these use global variables
|
|
write_etcnet_iface() {
|
|
dir="$ETCNET_IFDIR/$iface"
|
|
mkdir -p "$dir"
|
|
append=
|
|
case "$proto" in
|
|
dhcp)
|
|
if [ $GLOBAL_ARCH = mipsel ]; then
|
|
append="DHCP_TIMEOUT=20"
|
|
else
|
|
append="DHCP_TIMEOUT=7"
|
|
fi
|
|
;;
|
|
static)
|
|
echo "$ipv4addr" > "$dir/ipv4address"
|
|
[ -z "$ipv4gw" ] ||
|
|
echo "default via $ipv4gw" > "$dir/ipv4route"
|
|
;;
|
|
esac
|
|
{
|
|
echo "TYPE=eth"
|
|
echo "BOOTPROTO=$proto"
|
|
echo "NM_CONTROLLED=$NMCTL"
|
|
echo "DISABLED=$NMCTL"
|
|
echo "#USE_IFPLUGD=yes"
|
|
[ -z "$append" ] || echo "$append"
|
|
} > "$dir/options"
|
|
}
|
|
|
|
write_systemd_iface() {
|
|
case "$proto" in
|
|
dhcp)
|
|
echo "[Match]"
|
|
echo "Name=$iface"
|
|
echo
|
|
echo "[Network]"
|
|
echo "DHCP=yes"
|
|
echo
|
|
echo "[DHCP]"
|
|
echo "UseMTU=yes"
|
|
echo "UseDomains=yes"
|
|
echo "UseNTP=yes"
|
|
echo
|
|
;;
|
|
static)
|
|
echo "[Match]"
|
|
echo "Name=$iface"
|
|
echo
|
|
echo "[Network]"
|
|
echo "Address=$ipv4addr"
|
|
[ -z "$ipv4gw" ] ||
|
|
echo "Gateway=$ipv4gw"
|
|
echo "LinkLocalAddressing=no"
|
|
;;
|
|
esac > "$SYSTEMD_IFDIR/$iface.network"
|
|
}
|
|
|
|
[ -z "$GLOBAL_NET_ETH" ] ||
|
|
echo "$GLOBAL_NET_ETH" \
|
|
| tr ' ' '\n' \
|
|
| while IFS=':' read iface proto ipv4addr ipv4gw; do
|
|
[ -n "$iface" -a -n "$proto" ] || continue
|
|
write_iface
|
|
done
|