net-eth: systemd-networkd configuration support
shaba@ asked if it's feasible to extend 50-net-eth with a generator for systemd-networkd style configs having provided examples; here it is (depends on /etc/systemd/network/ being packaged into that one). (fixed up by shaba@'s removal of superfluous quotes)
This commit is contained in:
parent
b7901e580d
commit
5ea3f714aa
@ -13,11 +13,27 @@ else
|
||||
NMCTL=no
|
||||
fi
|
||||
|
||||
IFACEDIR="/etc/net/ifaces"
|
||||
ETCNET_IFDIR="/etc/net/ifaces"
|
||||
SYSTEMD_IFDIR="/etc/systemd/network"
|
||||
|
||||
# uses global variables
|
||||
write_iface() {
|
||||
dir="$IFACEDIR/$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
|
||||
@ -25,14 +41,10 @@ write_iface() {
|
||||
append="DHCP_TIMEOUT=3"
|
||||
;;
|
||||
static)
|
||||
[ -n "$ipv4addr" ] || fatal "ipv4addr missing"
|
||||
echo "$ipv4addr" > "$dir/ipv4address"
|
||||
[ -z "$ipv4gw" ] ||
|
||||
echo "default via $ipv4gw" > "$dir/ipv4route"
|
||||
;;
|
||||
*)
|
||||
fatal "unknown proto value: $proto"
|
||||
;;
|
||||
esac
|
||||
{
|
||||
echo "TYPE=eth"
|
||||
@ -44,6 +56,28 @@ write_iface() {
|
||||
} > "$dir/options"
|
||||
}
|
||||
|
||||
write_systemd_iface() {
|
||||
case "$proto" in
|
||||
dhcp)
|
||||
echo "[Match]"
|
||||
echo "Name=$iface"
|
||||
echo
|
||||
echo "[Network]"
|
||||
echo "DHCP=yes"
|
||||
;;
|
||||
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' \
|
||||
|
Loading…
Reference in New Issue
Block a user