From 7b07643be9d5f767d5d216d899e1fbbcc08d56eb Mon Sep 17 00:00:00 2001 From: Lukas Macura Date: Fri, 13 May 2016 18:00:19 +0200 Subject: [PATCH] Simulate zaf_sudo if needed Add plugin name as env var --- install.sh | 1 + lib/ctrl.lib.sh | 2 +- lib/preload.sh | 5 ++++- lib/zaf.lib.sh | 9 +++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 9102805..942282c 100755 --- a/install.sh +++ b/install.sh @@ -338,6 +338,7 @@ fi export ZAF_TMP_DIR="/tmp/zaf-installer" export ZAF_DIR="$ZAF_TMP_DIR/zaf" +! [ -d $ZAF_TMP_DIR ] && mkdir -p $ZAF_TMP_DIR zaf_debug_init stderr zaf_tmp_init diff --git a/lib/ctrl.lib.sh b/lib/ctrl.lib.sh index 306c322..e84262a 100644 --- a/lib/ctrl.lib.sh +++ b/lib/ctrl.lib.sh @@ -218,7 +218,7 @@ zaf_ctrl_generate_cfg() { zafparams="" args="" fi - env="export ITEM_KEY='$ikey'; export PATH=${ZAF_PLUGINS_DIR}/$2:$ZAF_LIB_DIR:\$PATH; cd ${ZAF_PLUGINS_DIR}/$2; . $ZAF_LIB_DIR/preload.sh; " + env="export ITEM_KEY='$ikey'; export PLUGIN='$2'; export PATH=${ZAF_PLUGINS_DIR}/$2:$ZAF_LIB_DIR:\$PATH; cd ${ZAF_PLUGINS_DIR}/$2; . $ZAF_LIB_DIR/preload.sh; " lock=$(zaf_ctrl_get_item_option $1 $i "Lock") if [ -n "$lock" ]; then lock="${ZAF_LIB_DIR}/zaflock $lock " diff --git a/lib/preload.sh b/lib/preload.sh index cbd9795..2822c16 100644 --- a/lib/preload.sh +++ b/lib/preload.sh @@ -9,6 +9,9 @@ . ${ZAF_LIB_DIR}/zbxapi.lib.sh . ${ZAF_LIB_DIR}/cache.lib.sh +# Plugin specific functions if exists +[ -f ./functions.sh ] && . ./functions.sh + if ! type zaf_version >/dev/null; then echo "Problem loading libraries?" exit 2 @@ -23,7 +26,7 @@ export ZAF_CACHE_DIR export ZAF_PLUGINS_DIR export ZAF_DEBUG unset ZAF_LOG_STDERR -export PATH=$ZAF_LIB_DIR:$ZAF_BIN_DIR:$PATH +export PATH if [ "$(basename $0)" = "preload.sh" ] && [ -n "$*" ]; then tmpf=$(zaf_tmpfile preload) diff --git a/lib/zaf.lib.sh b/lib/zaf.lib.sh index 8f8ac15..562ce7e 100644 --- a/lib/zaf.lib.sh +++ b/lib/zaf.lib.sh @@ -258,3 +258,12 @@ zaf_random() { hexdump -n 2 -e '/2 "%u"' /dev/urandom } +# Emulate sudo +zaf_sudo() { + if zaf_is_root || ! which sudo >/dev/null 2>/dev/null; then + $@ + else + sudo $@ + fi +} +