mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 16:30:07 +01:00
ifup: extend ifup/ifdown to be smarter about NetworkManager profiles
Now that NetworkManager on Fedora 33 and RHEL 9 no longer writes ifcfg-rh files by default ([1]), ifup/ifdown became less useful. Possibly users shouldn't use it and it would be fine that new-style profiles (keyfile) no longer work with these commands. But this is deemed as too disruptive for users. Note that our previous ifup/ifdown compat scripts only honored the argument to be part of the ifcfg filename. That was not what initscripts were doing, which called `need_config()` function that searched also the contents of the files. With this extension, ifup/ifdown gets smarter too, to better guess what the user might have wanted. Extend the script by making it smarter, and to work with connection profile names. With this extension we further solidify ifup/ifdown as part of NetworkManager command line API. That is problematic, because these tools pollute the $PATH, by not having a clear NM-specific name. Also, these scripts should only exist on Fedora/RHEL, which makes their usage non-portable to other distros. Also, other distros already ship different tools with name ifup/ifdown. Extending the use of these scripts is thus undesirable, as it furthers distro-specific commands. Still, these arguments seem to not hold and users need to be "helped". As Fedora users cannot be expected to unlearn "ifup" today, there is no reason to assume they could in a few years. This likely means we will never get rid of these scripts. Also, if we truly would make ifup/ifdown part of NetworkManager, then a better implementation would be that nmcli honors being called with these names. That is not done, because nmcli's implementation currently is not as nice to make that extension trivial (as it should be). It also would mean to embrace ifup/ifdown officially. A shell script works well enough as a hack. [1] https://fedoraproject.org/wiki/Changes/NetworkManager_keyfile_instead_of_ifcfg_rh https://bugzilla.redhat.com/show_bug.cgi?id=1954607 https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/936
This commit is contained in:
parent
e6583941b1
commit
30e7400528
2 changed files with 88 additions and 6 deletions
47
src/core/settings/plugins/ifcfg-rh/nm-ifdown
Normal file → Executable file
47
src/core/settings/plugins/ifcfg-rh/nm-ifdown
Normal file → Executable file
|
|
@ -1,3 +1,44 @@
|
|||
#!/bin/sh
|
||||
nmcli connection load "/etc/sysconfig/network-scripts/ifcfg-$1" &&
|
||||
exec nmcli connection down filename "/etc/sysconfig/network-scripts/ifcfg-$1"
|
||||
#!/bin/bash
|
||||
|
||||
CONFIG="$1"
|
||||
|
||||
if [ -z "${CONFIG}" ] ; then
|
||||
echo $"Usage: ifdown <device name>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
usage_and_fail() {
|
||||
cat <<EOF >&2
|
||||
$1!
|
||||
|
||||
See all profiles with \`nmcli connection\`.
|
||||
Reload files from disk with \`nmcli connection reload\`
|
||||
Deactivate the desired profile with \`nmcli connection down \"\$NAME\"\`
|
||||
EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
OLD_IFS="$IFS"
|
||||
|
||||
re='^/etc/sysconfig/network-scripts/ifcfg-[^/]+$'
|
||||
for f in "/etc/sysconfig/network-scripts/ifcfg-$CONFIG" "/etc/sysconfig/network-scripts/$CONFIG" ; do
|
||||
[[ "$f" =~ $re ]] || continue
|
||||
[ -f "$f" ] || continue
|
||||
|
||||
nmcli connection load "$f" \
|
||||
&& nmcli connection down filename "$f" \
|
||||
&& exit 0
|
||||
|
||||
usage_and_fail "Failure to deactivate file \"$CONFIG\""
|
||||
done
|
||||
|
||||
IFS=$'\n '
|
||||
APATHS=( $(nmcli -g GENERAL.DBUS-PATH connection show --active "$CONFIG" 2>/dev/null) )
|
||||
IFS="$OLD_IFS"
|
||||
if [ "${#APATHS[@]}" -eq 1 ] ; then
|
||||
nmcli connection down apath "${APATHS[0]}" \
|
||||
&& exit 0
|
||||
usage_and_fail "Failure to deactivate profile \"$CONFIG\" (apath ${APATHS[@]})"
|
||||
fi
|
||||
|
||||
usage_and_fail "No suitable profile \"$CONFIG\" found"
|
||||
|
|
|
|||
47
src/core/settings/plugins/ifcfg-rh/nm-ifup
Normal file → Executable file
47
src/core/settings/plugins/ifcfg-rh/nm-ifup
Normal file → Executable file
|
|
@ -1,3 +1,44 @@
|
|||
#!/bin/sh
|
||||
nmcli connection load "/etc/sysconfig/network-scripts/ifcfg-$1" &&
|
||||
exec nmcli connection up filename "/etc/sysconfig/network-scripts/ifcfg-$1"
|
||||
#!/bin/bash
|
||||
|
||||
CONFIG="$1"
|
||||
|
||||
if [ -z "${CONFIG}" ] ; then
|
||||
echo $"Usage: ifup <device name>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
usage_and_fail() {
|
||||
cat <<EOF >&2
|
||||
$1!
|
||||
|
||||
See all profiles with \`nmcli connection\`.
|
||||
Reload files from disk with \`nmcli connection reload\`
|
||||
Activate the desired profile with \`nmcli connection up \"\$NAME\"\`
|
||||
EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
OLD_IFS="$IFS"
|
||||
|
||||
re='^/etc/sysconfig/network-scripts/ifcfg-[^/]+$'
|
||||
for f in "/etc/sysconfig/network-scripts/ifcfg-$CONFIG" "/etc/sysconfig/network-scripts/$CONFIG" ; do
|
||||
[[ "$f" =~ $re ]] || continue
|
||||
[ -f "$f" ] || continue
|
||||
|
||||
nmcli connection load "$f" \
|
||||
&& nmcli connection up filename "$f" \
|
||||
&& exit 0
|
||||
|
||||
usage_and_fail "Failure to activate file \"$CONFIG\""
|
||||
done
|
||||
|
||||
IFS=$'\n '
|
||||
UUIDS=( $(nmcli -g connection.uuid connection show "$CONFIG" 2>/dev/null) )
|
||||
IFS="$OLD_IFS"
|
||||
if [ "${#UUIDS[@]}" -eq 1 ] ; then
|
||||
nmcli connection up uuid "${UUIDS[0]}" \
|
||||
&& exit 0
|
||||
usage_and_fail "Failure to activate profile \"$CONFIG\" (uuid ${UUIDS[0]})"
|
||||
fi
|
||||
|
||||
usage_and_fail "No suitable profile \"$CONFIG\" found"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue