From f4bc87dc65729ef663f6dc9b7e157a909c5eb92b Mon Sep 17 00:00:00 2001 From: Bastian Bittorf Date: Sun, 12 Feb 2017 14:36:20 +0100 Subject: [PATCH] olsr: allow lazy-plugin-naming: e.g. olsrd_txtinfo (not olsrd_txtinfo.so.1.2) overload init-skript's olsrd_write_loadplugin() with new function find_most_recent_plugin_libary() - so now we can mix 'exact' and lazy names. This change is backward compatible and now we have a better migration strategy. This topic was hot again, after the latest updates of a lot of plugins, resulting in non-working configs... --- olsrd/files/olsrd.init | 48 +++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/olsrd/files/olsrd.init b/olsrd/files/olsrd.init index 258c7a5..9018b2e 100644 --- a/olsrd/files/olsrd.init +++ b/olsrd/files/olsrd.init @@ -475,32 +475,48 @@ olsrd_write_hna6() { return 0 } -olsrd_write_loadplugin() { - local funcname="olsrd_write_loadplugin" +find_most_recent_plugin_libary() +{ + local library="$1" + local file unixtime + + for file in "/lib/$library"* "/usr/lib/$library"* "/usr/local/lib/$library"*; do { + [ -f "$file" ] && { + unixtime="$( date +%s -r "$file" )" + echo "$unixtime $file" + } + } done | sort -n | tail -n1 | cut -d' ' -f2 +} + +olsrd_write_loadplugin() +{ + local funcname='olsrd_write_loadplugin' local cfg="$1" + local ignore name suffix lat lon latlon_infile + validate_varname "$cfg" || return 0 - local ignore - local name - local suffix - local lat - local lon - local latlon_infile config_get_bool ignore "$cfg" ignore 0 [ "$ignore" -ne 0 ] && return 0 + # e.g. olsrd_txtinfo.so.1.1 or 'olsrd_txtinfo' config_get library "$cfg" library - if ! validate_olsrd_option "$library"; then - warning_invalid_value olsrd "$cfg" "library" - return 0 - fi - if ! [ -x "/lib/$library" -o -x "/usr/lib/$library" -o -x "/usr/local/lib/$library" ]; then + + library="$( find_most_recent_plugin_libary "$library" )" + if [ -z "$library" ]; then log "$funcname() Warning: Plugin library '$library' not found, skipped" return 0 + else + library="$( basename "$library" )" fi + validate_olsrd_option "$library" || { + warning_invalid_value olsrd "$cfg" 'library' + return 0 + } + case "$library" in - olsrd_nameservice.*) + 'olsrd_nameservice.'*) config_get name "$cfg" name [ -z "$name" ] && config_set "$cfg" name $SYSTEM_HOSTNAME @@ -527,7 +543,7 @@ olsrd_write_loadplugin() { [ -z "$latlon_file" ] && config_set "$cfg" latlon_file '/var/run/latlon.js' ;; - olsrd_watchdog.*) + 'olsrd_watchdog.'*) config_get wd_file "$cfg" file ;; esac @@ -535,8 +551,6 @@ olsrd_write_loadplugin() { echo -n "${N}LoadPlugin \"$library\"${N}{" config_write_options "$OLSRD_LOADPLUGIN_SCHEMA" "$cfg" olsrd_write_plparam "${T}" echo "${N}}" - - return 0 } olsrd_write_interface() { -- 2.30.2