diff options
| author | erdgeist <> | 2013-09-29 03:52:41 +0000 | 
|---|---|---|
| committer | erdgeist <> | 2013-09-29 03:52:41 +0000 | 
| commit | 16cf6be1ee090093ad99e006b6ffcb9734d779f4 (patch) | |
| tree | 6116d039bad766426d24a37ad476f1cc07da1743 | |
| parent | 7b21a0a9d6f2655f820f2d930c2532f9eb7e9dc3 (diff) | |
Add license.
Fix the acutal matching of user and command entries in config files.
Use -m on su to be able to execute under user priviliges of users without a login shell.
Use eval before env to expand environment variables.
| -rwxr-xr-x | minimunin | 19 | 
1 files changed, 13 insertions, 6 deletions
| @@ -1,4 +1,10 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh | 
| 2 | # | ||
| 3 | # This script was written by erdgeist@erdgeist.org | ||
| 4 | # The code is released under the beer ware license, this means do whatever you | ||
| 5 | # want with it, as long as you leave this notice along with the code. | ||
| 6 | # Should we meet some day and you find the code is worth it, let's enjoy a beer | ||
| 7 | # together. | ||
| 2 | 8 | ||
| 3 | PLUGIN_DIR=/usr/local/etc/minimunin-plugins | 9 | PLUGIN_DIR=/usr/local/etc/minimunin-plugins | 
| 4 | CONFIG_DIR=/usr/local/etc/minimunin-configs | 10 | CONFIG_DIR=/usr/local/etc/minimunin-configs | 
| @@ -335,17 +341,18 @@ call_plugin() { | |||
| 335 | _pref=${line#*env.} | 341 | _pref=${line#*env.} | 
| 336 | _env="${env} ${_pref%% *}='${_pref#* }'" | 342 | _env="${env} ${_pref%% *}='${_pref#* }'" | 
| 337 | ;; | 343 | ;; | 
| 338 | user ) _user=${line#*user } | 344 | user\ *) _user=${line#*user } | 
| 339 | ;; | 345 | ;; | 
| 340 | command ) _command=${line#*command } | 346 | command\ *) _command=${line#*command } | 
| 341 | ;; | 347 | ;; | 
| 342 | esac | 348 | esac | 
| 343 | done <<EOF | 349 | done <<EOF | 
| 344 | ${CONFIGS} | 350 | ${CONFIGS} | 
| 351 | |||
| 345 | EOF | 352 | EOF | 
| 346 | 353 | ||
| 347 | if [ "${_command }" ]; then | 354 | if [ "${_command}" ]; then | 
| 348 | # if the command is overridden, do a replace on %c | 355 | # if the command is overridden, do a replace on %c -- I wonder if multiple substitutions are intended | 
| 349 | case ${_command} in *%c*) _command=${_command%%%c*}${_plug}${_command#*%c};; esac | 356 | case ${_command} in *%c*) _command=${_command%%%c*}${_plug}${_command#*%c};; esac | 
| 350 | else | 357 | else | 
| 351 | # if not, just use the command | 358 | # if not, just use the command | 
| @@ -356,10 +363,10 @@ EOF | |||
| 356 | _command="${_command} ${_param}" | 363 | _command="${_command} ${_param}" | 
| 357 | 364 | ||
| 358 | # if we're required to switch the user and able to do so (root) use su to become this user | 365 | # 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}'" | 366 | [ "${_user}" -a `id -u` -eq 0 ] && _command="/usr/bin/su -m ${_user} -c '${_command}'" | 
| 360 | 367 | ||
| 361 | # prepend environment and run the command | 368 | # prepend environment and run the command | 
| 362 | ${_env} ${_command} | 369 | eval env ${_env} ${_command} | 
| 363 | 370 | ||
| 364 | return 0 | 371 | return 0 | 
| 365 | } | 372 | } | 
