diff options
author | Thomas Haller <thaller@redhat.com> | 2019-10-04 11:18:53 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-10-04 12:38:16 +0200 |
commit | c6d53c550094163af8b7f91540162507e84b5639 (patch) | |
tree | 43df8c9e1dcaef7d9036ad42b6a50470653afe41 /examples | |
parent | babd1f314e213388ead0e9272bc5939225383b3f (diff) | |
download | NetworkManager-c6d53c550094163af8b7f91540162507e84b5639.tar.gz |
dispatcher: avoid "dirname" and "basename" calls in "10-ifcfg-rh-routes.sh" script
The script is run for every dispatcher event. Most of the events are not
actually relevant, and we just need to determine that there is nothing
to do and quit.
Avoid calling "dirname" and "basename".
The supported ifcfg-file has a very specific form. We can just check
(and parse) it in one got regular expression in bash.
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/dispatcher/10-ifcfg-rh-routes.sh | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/examples/dispatcher/10-ifcfg-rh-routes.sh b/examples/dispatcher/10-ifcfg-rh-routes.sh index 45dfc40147..0f49ec2a8e 100755 --- a/examples/dispatcher/10-ifcfg-rh-routes.sh +++ b/examples/dispatcher/10-ifcfg-rh-routes.sh @@ -16,17 +16,13 @@ if [ "$2" != "pre-up" ] && [ "$2" != "down" ]; then exit 0 fi -dir=$(dirname "$CONNECTION_FILENAME") -if [ "$dir" != "/etc/sysconfig/network-scripts" ]; then - exit 0 -fi +file_regex='^/etc/sysconfig/network-scripts/ifcfg-([^/]+)$' -profile=$(basename "$CONNECTION_FILENAME" | sed -ne 's/^ifcfg-//p') -if [ -z "$profile" ]; then - exit 0 -fi +[[ "$CONNECTION_FILENAME" =~ $file_regex ]] || exit 0 + +profile="${BASH_REMATCH[1]}" -if [ ! -f "$dir/rule-$profile" ] && [ ! -f "$dir/rule6-$profile" ]; then +if [ ! -f "/etc/sysconfig/network-scripts/rule-$profile" ] && [ ! -f "/etc/sysconfig/network-scripts/rule6-$profile" ]; then exit 0 fi |