Commit 5ea3f714 authored by Michael Shigorin's avatar Michael Shigorin

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)
parent b7901e58
......@@ -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' \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment