1
0
mirror of https://github.com/limosek/zaf.git synced 2024-11-13 05:59:06 +01:00

Repaired plugin (re)installation

This commit is contained in:
Lukas Macura 2016-12-05 11:30:10 +01:00
parent 0ef05853a4
commit 9ac7bd34d4
6 changed files with 36 additions and 27 deletions

View File

@ -104,14 +104,13 @@ git clone https://github.com/limosek/zaf.git \
&& cd zaf \
&& git checkout master \
&& git clone https://github.com/limosek/zaf-plugins.git \
&& make deb PLUGINS="./zaf-plugins/fsx" IPLUGINS="zaf" ZAF_OPTIONS="ZAF_GIT=0" AGENT_OPTIONS="Z_Server=zabbix.server Z_ServerActive=zabbix.server Z_StartAgents=8"
&& make deb PLUGINS="./zaf-plugins/fsx" ZAF_PLUGINS="zaf" ZAF_OPTIONS="ZAF_GIT=0" AGENT_OPTIONS="Z_Server=zabbix.server Z_ServerActive=zabbix.server Z_StartAgents=8"
sudo dpkg -i out/zaf-1.3master.deb
```
General usage:
```
make {deb|ipk|rpm} [PLUGINS="/dir/plg1 [/dir2]...] [IPLUGINS="plg1 [plg2]..."] [ZAF_OPTIONS="ZAF_cfg=val ..."] [AGENT_OPTIONS="Z_Server=host ..."]
PLUGINS are embedded into package. Has to be local directories accessible during build.
IPLUGINS will be downloaded and installed after package is installed. Can be name or url accessible after package installation.
make {deb|ipk|rpm} [ZAF_PLUGINS="plg1 [plg2]" [ZAF_OPTIONS="ZAF_cfg=val ..."] [AGENT_OPTIONS="Z_Server=host ..."]
ZAF_PLUGINS are embedded into package. Has to be local directories accessible during build.
```
## Zaf plugin

View File

@ -56,7 +56,7 @@ zaf_cache_unlock(){
# $2 value
# $3 lifetime in seconds
zaf_tocache(){
! [ -w $ZAF_CACHE_DIR ] && return 1
! [ -w $ZAF_CACHE_DIR ] && return
local key
local value
local expiry
@ -82,7 +82,7 @@ zaf_tocache(){
# $1 key
# $2 lifetime in seconds
zaf_tocache_stdin(){
! [ -w $ZAF_CACHE_DIR ] && { cat; return 1; }
! [ -w $ZAF_CACHE_DIR ] && { cat; return; }
local key
local expiry
local infofile

View File

@ -219,8 +219,6 @@ zaf_ctrl_install() {
zaf_fetch_url "$1/$b" >"${ZAF_TMP_DIR}/$b"
zaf_install "${ZAF_TMP_DIR}/$b" "$pdir"
done
script=$(zaf_ctrl_get_global_option $2 "Install-script")
[ -n "$script" ] && eval "$script"
true
) || zaf_err "Error during zaf_ctrl_install"
}

View File

@ -18,24 +18,16 @@ zaf_update_repo() {
zaf_get_plugin_url() {
local url
if echo "$1" | grep -q '/'; then
if [ "$(zaf_url_info $1)" = "path" ]; then
url="$1" # plugin with path - from directory
else
if echo "$1" | grep -q ^http; then
if [ "$(zaf_url_info $1)" = "url" ]; then
url="$1" # plugin with http[s] url
else
if [ -d "${ZAF_REPO_DIR}/$1" ]; then
url="${ZAF_REPO_DIR}/$1"
if [ -n "${ZAF_REPO_URL}" ]; then
url="${ZAF_REPO_URL}/$1"
else
if [ -n "${ZAF_PREPACKAGED_DIR}" ] && [ -d "${ZAF_PREPACKAGED_DIR}/$1" ]; then
url="${ZAF_PREPACKAGED_DIR}/$1"
else
if [ -n "${ZAF_REPO_URL}" ]; then
url="${ZAF_REPO_URL}/$1"
else
zaf_err "Cannot find plugin $1"
fi
fi
zaf_err "Cannot find plugin $1"
fi
fi
fi
@ -89,14 +81,18 @@ zaf_prepare_plugin() {
url=$(zaf_get_plugin_url "$1")/control.zaf || exit $?
plugindir="$2"
control=${plugindir}/control.zaf
if [ "$(zaf_url_info $1)" = "path" ] && cmp -s "$url" "$control"; then
zaf_err "prepare_plugin: Cannot install from itself!"
fi
zaf_install_dir "$plugindir"
zaf_dbg "Fetching control file from $url ..."
if zaf_fetch_url "$url" >"${INSTALL_PREFIX}/${control}"; then
[ -z "${INSTALL_PREFIX}" ] && zaf_ctrl_check_deps "${control}"
pluginname=$(zaf_ctrl_get_global_block <"${INSTALL_PREFIX}/${control}" | zaf_block_get_option Plugin)
[ "$(basename $plugindir)" != "$pluginname" ] && zaf_err "prepare_plugin: Plugin name mismach ($plugindir vs $pluginname)!"
[ "$(basename $plugindir)" != "$pluginname" ] && zaf_err "prepare_plugin: Plugin name mismach ($plugindir vs ${INSTALL_PREFIX}/${control})!"
true
else
rm -rf "$plugindir"
zaf_err "prepare_plugin: Cannot fetch or write control file ${INSTALL_PREFIX}/$control from url $url!"
fi
}
@ -112,6 +108,7 @@ zaf_install_plugin() {
plugin=$(basename "$1")
plugindir="${ZAF_PLUGINS_DIR}/${plugin}"
if [ -n "$plugin" ] && zaf_prepare_plugin "$1" $plugindir; then
url=$(zaf_get_plugin_url "$1")
zaf_wrn "Installing plugin $plugin"
zaf_dbg "Source url: $url, Destination dir: $plugindir"
control=${plugindir}/control.zaf
@ -125,7 +122,7 @@ zaf_install_plugin() {
zaf_dbg "Generated ${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf"
zaf_ctrl_generate_extitems_cfg "${control}" "${plugin}"
else
zaf_touch "${plugindir}/needinstall"
zaf_touch "${plugindir}/postinst.need"
fi
zaf_ctrl_install "$url" "${control}" "${plugindir}"
else
@ -152,7 +149,6 @@ zaf_postinstall_plugin() {
| zaf_far '{PLUGINDIR}' "${plugindir}" >${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf
zaf_dbg "Generated ${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf"
zaf_ctrl_generate_extitems_cfg "${control}" "${plugin}"
zaf_ctrl_install "$url" "${control}" "${plugindir}"
}

View File

@ -109,6 +109,20 @@ zaf_fetch_url() {
esac
}
# Get info about url
# returns path or url
zaf_url_info() {
if echo "$1" | grep -q '^/'; then
echo "path"
else
if echo "$1" | grep -q ^http; then
echo "url"
else
echo "unknown"
fi
fi
}
# Find and replace string
zaf_far(){
local f

8
zaf
View File

@ -88,17 +88,19 @@ userparms)
done
;;
agent-config)
[ -n "$2" ] && force=yes
for p in $(zaf_list_plugins); do
if [ -f "$ZAF_PLUGINS_DIR/$p/needinstall" ]; then
if [ -f "$ZAF_PLUGINS_DIR/$p/postinst.need" ]; then
zaf_wrn "Calling postinstalation of plugin $p"
zaf_postinstall_plugin $p && rm -f "$ZAF_PLUGINS_DIR/$p/needinstall"
zaf_postinstall_plugin $p && rm -f "$ZAF_PLUGINS_DIR/$p/postinst.need"
force=yes
fi
done
zaf_wrn "Generating config files in $ZAF_AGENT_CONFIGD ..."
for plugin in $(zaf_list_plugins); do
plugindir=$ZAF_PLUGINS_DIR/$plugin
control=$plugindir/control.zaf
if ! [ -f "${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf" ] || [ "$control" -nt "${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf" ] || [ -n "$2" ]; then
if ! [ -f "${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf" ] || [ "$control" -nt "${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf" ] || [ -n "$force" ]; then
zaf_dbg "Generating ${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf"
zaf_ctrl_generate_items_cfg "${control}" "${plugin}" \
| zaf_far '{PLUGINDIR}' "${plugindir}" >${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf