summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xminimunin53
1 files changed, 36 insertions, 17 deletions
diff --git a/minimunin b/minimunin
index ce7a857..c42ce59 100755
--- a/minimunin
+++ b/minimunin
@@ -321,28 +321,47 @@ get_sys() {
321 LANG=C LC_ALL=C ${SYSCTL} -n $@ 321 LANG=C LC_ALL=C ${SYSCTL} -n $@
322} 322}
323 323
324env_for_plugin_from_config() {
325 unset in_sect
326 while read line; do
327 case ${line## } in
328 \[*\]) case [$1 in ${line%%]*}) in_sect=true;; *) unset in_sect ;; esac
329 ;;
330 env.*) [ "${in_sect}" ] || continue
331 _pref=${line#*env.};
332 printf "%s " ${_pref%% *}=\'${_pref#* }\'
333 ;;
334 esac
335 done
336}
337
338call_plugin() { 324call_plugin() {
339 _param=$2 325 _param=$2
340 _plug=`/usr/bin/find ${PLUGIN_DIR} \( -type l -or -type f \) -perm +111 -name $1 2>/dev/null | /usr/bin/head -n 1` 326 _plug=`/usr/bin/find ${PLUGIN_DIR} \( -type l -or -type f \) -perm +111 -name $1 2>/dev/null | /usr/bin/head -n 1`
341 [ -z "${_plug}" ] && return 1 327 [ -z "${_plug}" ] && return 1
342 328
343 _env=$( printf "%s\n" "${CONFIGS}" | env_for_plugin_from_config $1 ) 329 unset in_sect _env _user _command
344 eval env ${_env} ${_plug} ${_param} 330 while read line; do
345 return $? 331 case ${line## } in
332 \[*\]) case [$1 in ${line%%]*}) in_sect=true;; *) unset in_sect ;; esac
333 ;;
334 env.*) [ "${in_sect}" ] || continue
335 _pref=${line#*env.}
336 _env="${env} ${_pref%% *}='${_pref#* }'"
337 ;;
338 user ) _user=${line#*user }
339 ;;
340 command ) _command=${line#*command }
341 ;;
342 esac
343 done <<EOF
344${CONFIGS}
345EOF
346
347 if [ "${_command }" ]; then
348 # if the command is overridden, do a replace on %c
349 case ${_command} in *%c*) _command=${_command%%%c*}${_plug}${_command#*%c};; esac
350 else
351 # if not, just use the command
352 _command="${_plug}"
353 fi
354
355 # attach the config or fetch parameter
356 _command="${_command} ${_param}"
357
358 # if we're required to switch the user and able to do so (root) use su to become this user
359 [ "${_user}" -a `id -u` -eq 0 ] && _command="/usr/bin/su ${user} -c '${_command}'"
360
361 # prepend environment and run the command
362 ${_env} ${_command}
363
364 return 0
346} 365}
347 366
348# After function definitions, main() can use them 367# After function definitions, main() can use them