From fef2bf5ac0c455dc74dc0c8563a4567a05006474 Mon Sep 17 00:00:00 2001 From: Lukas Macura Date: Thu, 14 Apr 2016 10:44:50 +0200 Subject: [PATCH] Sync master branch --- README.md | 4 ++-- lib/ctrl.lib.sh | 18 +++++++++++------- lib/zaf.lib.sh | 8 +++++++- zaf | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e9a366b..9f4228e 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ git clone https://github.com/limosek/zaf.git \ && 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" -sudo dpkg -i out/zaf-1.1master.deb +sudo dpkg -i out/zaf-1.2master.deb ``` General usage: ``` @@ -124,7 +124,7 @@ During plugin installation, zaf will check all dependencies, do install binaries Zaf binary can be installed on any system from openwrt to big system. It has minimal dependencies and is shell based. Is has minimal size (up to 50kb of code). It can be used for installing, removing and testing zaf plugin items. Zaf should be run as root. ``` zaf -zaf Version 1.1master. Please use some of this commands: +zaf Version 1.2master. Please use some of this commands: zaf update To update repo zaf plugins To list installed plugins zaf show [plugin] To show installed plugins or plugin info diff --git a/lib/ctrl.lib.sh b/lib/ctrl.lib.sh index 975f6e4..e5ee3f6 100644 --- a/lib/ctrl.lib.sh +++ b/lib/ctrl.lib.sh @@ -55,11 +55,13 @@ zaf_block_get_option() { # $1 - control file # $2 - option name zaf_ctrl_get_global_option() { + local ctrlvar local ctrlopt - eval ctrlopt=\$ZAF_CTRL_$(echo $2| tr '-' '_') - if [ -n "$ctrlopt" ]; then - zaf_wrn "Overriding $2 from env" + ctrlopt="ZAF_CTRL_$(zaf_stripctrl $2)" + eval ctrlvar=\$$ctrlopt + if [ -n "$ctrlvar" ]; then + zaf_dbg "Overriding control field $2 from env $ctrlopt($ctrlvar)" echo $ctrlopt else zaf_ctrl_get_global_block <$1 | zaf_block_get_moption "$2" \ @@ -71,11 +73,13 @@ zaf_ctrl_get_global_option() { # $2 - item name # $3 - option name zaf_ctrl_get_item_option() { + local ctrlvar local ctrlopt - eval ctrlopt=\$ZAF_CTRL_$2_$(echo $3| tr '-' '_') - if [ -n "$ctrlopt" ]; then - zaf_wrn "Overriding item $2 option $3 from env" + ctrlopt="ZAF_CTRLI_$(zaf_stripctrl $2)_$(zaf_stripctrl $3)" + eval ctrlvar=\$$ctrlopt + if [ -n "$ctrlvar" ]; then + zaf_dbg "Overriding item control field $2/$3 from env $ctrlopt($ctrlvar)" echo $ctrlopt else zaf_ctrl_get_item_block <$1 "$2" | zaf_block_get_moption "$3" \ @@ -188,7 +192,7 @@ zaf_ctrl_generate_cfg() { items=$(zaf_ctrl_get_items <"$1") (set -e for i in $items; do - iscript=$(echo $i | tr -d '[]*&;:') + iscript=$(zaf_stripctrl $i) params=$(zaf_ctrl_get_item_option $1 $i "Parameters") if [ -n "$params" ]; then ikey="$2.$i[*]" diff --git a/lib/zaf.lib.sh b/lib/zaf.lib.sh index db71851..ab51cc0 100644 --- a/lib/zaf.lib.sh +++ b/lib/zaf.lib.sh @@ -1,6 +1,6 @@ # Hardcoded variables -ZAF_VERSION="1.1" +ZAF_VERSION="1.2" ZAF_GITBRANCH="master" ZAF_URL="https://github.com/limosek/zaf" ZAF_RAW_URL="https://raw.githubusercontent.com/limosek/zaf" @@ -426,3 +426,9 @@ zaf_toupper() { tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' } +# Return simplified key with discarded special chars. +zaf_stripctrl() { + echo $1 | tr '[]*&;:.-' '________' +} + + diff --git a/zaf b/zaf index 9388cbd..d03009c 100755 --- a/zaf +++ b/zaf @@ -312,7 +312,7 @@ api) *) echo "$0 Version ${ZAF_VERSION}. Please use some of this commands:" - echo "$0 Cmd [ZAF_OPTION=value] [ZAF_CTRL_Option=value] ..." + echo "$0 Cmd [ZAF_OPTION=value] [ZAF_CTRL_Option=value] [ZAF_CTRLI_Item_Option=value] ..." echo "Commands:" echo "$0 update To update repo (not plugins, similar to apt-get update)" echo "$0 upgrade To upgrade installed plugins from repo"