nixos/network-interfaces: prevent failure when a network address already exists

The original code tests output of `ip addr add` command to detect if an
adress already exists. The error message was changed in the past and the
test no longer works.

The patch replaces `ip addr add` with `ip addr replace`. The new command
replaces an existing address or creates a new one if there isn't any.

fixes 306841
This commit is contained in:
Tomáš Kuča
2024-05-17 01:02:29 +02:00
parent ea77cefecb
commit 71ce6b582b

View File

@@ -203,10 +203,10 @@ let
''
echo "${cidr}" >> $state
echo -n "adding address ${cidr}... "
if out=$(ip addr add "${cidr}" dev "${i.name}" 2>&1); then
if out=$(ip addr replace "${cidr}" dev "${i.name}" 2>&1); then
echo "done"
elif ! echo "$out" | grep "File exists" >/dev/null 2>&1; then
echo "'ip addr add "${cidr}" dev "${i.name}"' failed: $out"
else
echo "'ip addr replace "${cidr}" dev "${i.name}"' failed: $out"
exit 1
fi
''