From 9ac7bd34d436b8a061f367799d2cf6c770cbfc4c Mon Sep 17 00:00:00 2001 From: Lukas Macura Date: Mon, 5 Dec 2016 11:30:10 +0100 Subject: [PATCH] Repaired plugin (re)installation --- README.md | 7 +++---- lib/cache.lib.sh | 4 ++-- lib/ctrl.lib.sh | 2 -- lib/plugin.lib.sh | 28 ++++++++++++---------------- lib/zaf.lib.sh | 14 ++++++++++++++ zaf | 8 +++++--- 6 files changed, 36 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index a786377..7bd513c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/cache.lib.sh b/lib/cache.lib.sh index 64cfd19..355963a 100644 --- a/lib/cache.lib.sh +++ b/lib/cache.lib.sh @@ -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 diff --git a/lib/ctrl.lib.sh b/lib/ctrl.lib.sh index 2246e4f..039be6e 100644 --- a/lib/ctrl.lib.sh +++ b/lib/ctrl.lib.sh @@ -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" } diff --git a/lib/plugin.lib.sh b/lib/plugin.lib.sh index de55c26..3b87c44 100644 --- a/lib/plugin.lib.sh +++ b/lib/plugin.lib.sh @@ -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}" } diff --git a/lib/zaf.lib.sh b/lib/zaf.lib.sh index 18dcb43..eda248e 100644 --- a/lib/zaf.lib.sh +++ b/lib/zaf.lib.sh @@ -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 diff --git a/zaf b/zaf index 76d8b8b..f28db62 100755 --- a/zaf +++ b/zaf @@ -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