mirror of
https://github.com/limosek/zaf.git
synced 2024-11-23 10:59:06 +01:00
Support for global plugin parameters
This commit is contained in:
parent
63b00e70aa
commit
a9a0ff9528
@ -40,14 +40,15 @@ zaf_plugin_info() {
|
|||||||
local items
|
local items
|
||||||
|
|
||||||
! [ -f "$control" ] && zaf_err "Control file $control not found."
|
! [ -f "$control" ] && zaf_err "Control file $control not found."
|
||||||
plugin=$(zaf_ctrl_get_global_block <"${control}" | zaf_block_get_option Plugin)
|
plugin=$(zaf_ctrl_get_global_option "${control}" Plugin)
|
||||||
pdescription=$(zaf_ctrl_get_global_block <"${control}" | zaf_block_get_moption Description)
|
pdescription=$(zaf_ctrl_get_global_option "${control}" Description)
|
||||||
pmaintainer=$(zaf_ctrl_get_global_block <"${control}" | zaf_block_get_option Maintainer)
|
pmaintainer=$(zaf_ctrl_get_global_option "${control}" Maintainer)
|
||||||
pversion=$(zaf_ctrl_get_global_block <"${control}" | zaf_block_get_option Version)
|
pversion=$(zaf_ctrl_get_global_option "${control}" Version)
|
||||||
purl=$(zaf_ctrl_get_global_block <"${control}" | zaf_block_get_option Url)
|
purl=$(zaf_ctrl_get_global_option "${control}" Url)
|
||||||
phome=$(zaf_ctrl_get_global_block <"${control}" | zaf_block_get_option Home)
|
phome=$(zaf_ctrl_get_global_option "${control}" Home)
|
||||||
pitems=$(zaf_ctrl_get_items <"${control}")
|
pitems=$(zaf_ctrl_get_items <"${control}")
|
||||||
peitems=$(zaf_ctrl_get_extitems <"${control}")
|
peitems=$(zaf_ctrl_get_extitems <"${control}")
|
||||||
|
params=$(zaf_ctrl_get_global_option "${control}" Parameters)
|
||||||
echo
|
echo
|
||||||
echo -n "Plugin '$plugin' "; [ -n "$pversion" ] && echo -n "version ${pversion}"; echo ":"
|
echo -n "Plugin '$plugin' "; [ -n "$pversion" ] && echo -n "version ${pversion}"; echo ":"
|
||||||
echo "$pdescription"; echo
|
echo "$pdescription"; echo
|
||||||
@ -57,18 +58,41 @@ zaf_plugin_info() {
|
|||||||
echo
|
echo
|
||||||
if zaf_is_plugin "$(basename $plugin)"; then
|
if zaf_is_plugin "$(basename $plugin)"; then
|
||||||
items=$(zaf_list_plugin_items $plugin)
|
items=$(zaf_list_plugin_items $plugin)
|
||||||
|
if [ -n "$params" ]; then
|
||||||
|
printf "%b" "Plugin parameters: (name,default,actual value)\n"
|
||||||
|
zaf_ctrl_get_global_option "${control}" Parameters | while read param default ; do
|
||||||
|
printf "%b" "$param\t$default\t$(zaf_get_plugin_parameter $(dirname $1) $param)\n"
|
||||||
|
done
|
||||||
|
echo;
|
||||||
|
fi
|
||||||
[ -n "$items" ] && { echo -n "Defined items: "; echo $items; }
|
[ -n "$items" ] && { echo -n "Defined items: "; echo $items; }
|
||||||
items=$(zaf_list_plugin_items $plugin test)
|
items=$(zaf_list_plugin_items $plugin test)
|
||||||
[ -n "$items" ] && { echo -n "Test items: "; echo $items; }
|
[ -n "$items" ] && { echo -n "Test items: "; echo $items; }
|
||||||
items=$(zaf_list_plugin_items $plugin precache)
|
items=$(zaf_list_plugin_items $plugin precache)
|
||||||
[ -n "$items" ] && { echo -n "Precache items: "; echo $items; }
|
[ -n "$items" ] && { echo -n "Precache items: "; echo $items; }
|
||||||
[ -n "$peitems" ] && { echo -n "External check items: "; echo $peitems; }
|
[ -n "$peitems" ] && { echo -n "External check items: "; echo $peitems; }
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "Items: $pitems"
|
echo "Items: $pitems"
|
||||||
fi
|
fi
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Set plugin global parameter
|
||||||
|
# $1 plugindir
|
||||||
|
# $2 parameter
|
||||||
|
# $3 value
|
||||||
|
zaf_set_plugin_parameter() {
|
||||||
|
printf "%s" "$3" >"${INSTALL_PREFIX}/${1}/${2}.value"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get plugin global parameter
|
||||||
|
# $1 plugindir
|
||||||
|
# $2 parameter
|
||||||
|
zaf_get_plugin_parameter() {
|
||||||
|
[ -f "${1}/${2}.value" ] && cat "${1}/${2}.value"
|
||||||
|
}
|
||||||
|
|
||||||
# Prepare plugin into dir
|
# Prepare plugin into dir
|
||||||
# $1 is url, directory or plugin name (will be searched in default plugin dir).
|
# $1 is url, directory or plugin name (will be searched in default plugin dir).
|
||||||
# $2 is directory to prepare.
|
# $2 is directory to prepare.
|
||||||
@ -104,6 +128,9 @@ zaf_install_plugin() {
|
|||||||
local tmpplugindir
|
local tmpplugindir
|
||||||
local control
|
local control
|
||||||
local version
|
local version
|
||||||
|
local eparam
|
||||||
|
local param
|
||||||
|
local default
|
||||||
|
|
||||||
plugin=$(basename "$1")
|
plugin=$(basename "$1")
|
||||||
plugindir="${ZAF_PLUGINS_DIR}/${plugin}"
|
plugindir="${ZAF_PLUGINS_DIR}/${plugin}"
|
||||||
@ -125,6 +152,24 @@ zaf_install_plugin() {
|
|||||||
zaf_touch "${plugindir}/postinst.need"
|
zaf_touch "${plugindir}/postinst.need"
|
||||||
fi
|
fi
|
||||||
zaf_ctrl_install "$url" "${control}" "${plugindir}"
|
zaf_ctrl_install "$url" "${control}" "${plugindir}"
|
||||||
|
rm "${plugindir}/params"
|
||||||
|
zaf_touch "${plugindir}/params"
|
||||||
|
(zaf_ctrl_get_global_option "${control}" "Parameters"; echo) | \
|
||||||
|
while read param default; do
|
||||||
|
[ -z "$param" ] && continue
|
||||||
|
echo $param >>"${plugindir}/params"
|
||||||
|
eval eparam=\$ZAF_${plugin}_${param}
|
||||||
|
if [ -z "$eparam" ] && ! zaf_get_plugin_parameter "$plugindir" "$param" >/dev/null; then
|
||||||
|
zaf_wrn "Do not forget to set parameter $param. Use zaf plugin-set $plugin $param value. Default is $default."
|
||||||
|
zaf_set_plugin_parameter "$plugindir" "$param" "$default"
|
||||||
|
else
|
||||||
|
if [ -n "$eparam" ]; then
|
||||||
|
zaf_dbg "Setting $param to $eparam from env."
|
||||||
|
zaf_set_plugin_parameter "$plugindir" "$param" "$eparam"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
else
|
else
|
||||||
zaf_err "Cannot install plugin '$plugin' to $plugindir!"
|
zaf_err "Cannot install plugin '$plugin' to $plugindir!"
|
||||||
fi
|
fi
|
||||||
|
@ -9,6 +9,14 @@
|
|||||||
. ${ZAF_LIB_DIR}/zbxapi.lib.sh
|
. ${ZAF_LIB_DIR}/zbxapi.lib.sh
|
||||||
. ${ZAF_LIB_DIR}/cache.lib.sh
|
. ${ZAF_LIB_DIR}/cache.lib.sh
|
||||||
|
|
||||||
|
# Global plugin parameters
|
||||||
|
[ -f ./params ] && for p in $(cat ./params); do
|
||||||
|
var=$p
|
||||||
|
value="$(cat ${p}.value)"
|
||||||
|
zaf_trc "Global $p parameter $var=$value"
|
||||||
|
eval export $var="$value"
|
||||||
|
done
|
||||||
|
|
||||||
# Plugin specific functions if exists
|
# Plugin specific functions if exists
|
||||||
[ -f ./functions.sh ] && . ./functions.sh
|
[ -f ./functions.sh ] && . ./functions.sh
|
||||||
|
|
||||||
@ -30,8 +38,12 @@ export PATH
|
|||||||
|
|
||||||
if [ "$(basename $0)" = "preload.sh" ] && [ -n "$*" ]; then
|
if [ "$(basename $0)" = "preload.sh" ] && [ -n "$*" ]; then
|
||||||
tmpf=$(zaf_tmpfile preload)
|
tmpf=$(zaf_tmpfile preload)
|
||||||
|
export tmpf
|
||||||
$@ 2>$tmpf
|
$@ 2>$tmpf
|
||||||
[ -s $tmpf ] && zaf_wrn <$tmpf
|
[ -s $tmpf ] && zaf_wrn <$tmpf
|
||||||
|
else
|
||||||
|
tmpf=$(zaf_tmpfile preload)
|
||||||
|
export tmpf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,8 +78,8 @@ zaf_agentparm(){
|
|||||||
echo "$value" | grep -qE "$regexp" || zaf_err "$ITEM_KEY: Bad parameter '$name' value '$value' (not in regexp '$regexp')."
|
echo "$value" | grep -qE "$regexp" || zaf_err "$ITEM_KEY: Bad parameter '$name' value '$value' (not in regexp '$regexp')."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
eval $name=$value
|
|
||||||
zaf_trc "$ITEM_KEY: Param $name set to $value"
|
zaf_trc "$ITEM_KEY: Param $name set to $value"
|
||||||
|
eval $name=\"$value\"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fetch url to stdout
|
# Fetch url to stdout
|
||||||
|
17
zaf
17
zaf
@ -235,7 +235,7 @@ reinstall)
|
|||||||
done
|
done
|
||||||
[ -n "$reinstalled" ] && zaf_is_root && zaf_restart_agent
|
[ -n "$reinstalled" ] && zaf_is_root && zaf_restart_agent
|
||||||
;;
|
;;
|
||||||
remove)
|
remove|uninstall)
|
||||||
shift
|
shift
|
||||||
[ -z "$1" ] && echo "$0 remove plugin [plugin]..."
|
[ -z "$1" ] && echo "$0 remove plugin [plugin]..."
|
||||||
for p in $@; do
|
for p in $@; do
|
||||||
@ -246,6 +246,21 @@ remove)
|
|||||||
done
|
done
|
||||||
[ -n "$removed" ] && zaf_is_root && zaf_restart_agent
|
[ -n "$removed" ] && zaf_is_root && zaf_restart_agent
|
||||||
;;
|
;;
|
||||||
|
plugin-set)
|
||||||
|
plugin="$2"
|
||||||
|
param="$3"
|
||||||
|
value="$4"
|
||||||
|
if [ -z "$plugin" ] || [ -z "$param" ]; then
|
||||||
|
zaf_err "$0 plugin-set plugin parameter value"
|
||||||
|
else
|
||||||
|
if zaf_is_plugin "$plugin"; then
|
||||||
|
plugindir="${ZAF_PLUGINS_DIR}/${plugin}"
|
||||||
|
zaf_set_plugin_parameter "$plugindir" "$param" "$value"
|
||||||
|
else
|
||||||
|
zaf_err "Plugin $plugin is not installed."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
###### Zaf related commands
|
###### Zaf related commands
|
||||||
self-upgrade)
|
self-upgrade)
|
||||||
|
Loading…
Reference in New Issue
Block a user