diff options
| author | erdgeist <> | 2013-09-29 03:13:09 +0000 |
|---|---|---|
| committer | erdgeist <> | 2013-09-29 03:13:09 +0000 |
| commit | 58f235e232b6396097affb0e4328a29d8c16175f (patch) | |
| tree | ebd45f19e57643bdd3361e7348c7390a5a436664 | |
| parent | f894db544e1248b9e7ac7c7ea815dc7f54be2a25 (diff) | |
Implement more plugin config file parameters
| -rwxr-xr-x | minimunin | 53 |
1 files changed, 36 insertions, 17 deletions
| @@ -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 | ||
| 324 | env_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 | |||
| 338 | call_plugin() { | 324 | call_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} | ||
| 345 | EOF | ||
| 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 |
