mirror of
https://github.com/limosek/zaf.git
synced 2025-11-01 18:17:37 +01:00
Repaired 'which' detection and user environment checking
This commit is contained in:
@@ -137,7 +137,7 @@ zaf_ctrl_check_deps() {
|
||||
fi
|
||||
deps=$(zaf_ctrl_get_global_block <$1 | zaf_block_get_option "Depends-bin" )
|
||||
for cmd in $deps; do
|
||||
if ! which $cmd >/dev/null; then
|
||||
if ! zaf_which $cmd >/dev/null; then
|
||||
zaf_err "Missing binary dependency $cmd. Please install it first."
|
||||
fi
|
||||
done
|
||||
@@ -160,13 +160,13 @@ zaf_ctrl_sudo() {
|
||||
zaf_dbg "Installing sudoers entry $ZAF_SUDOERSD/zaf_$plugin"
|
||||
sudo=$(zaf_ctrl_get_global_option $2 "Sudo" | zaf_far '{PLUGINDIR}' "${plugindir}")
|
||||
[ -z "$sudo" ] && return # Nothing to install
|
||||
if ! which sudo >/dev/null; then
|
||||
if ! zaf_which sudo >/dev/null; then
|
||||
zaf_wrn "Sudo needed bud not installed?"
|
||||
fi
|
||||
cmd=$(echo $sudo | cut -d ' ' -f 1)
|
||||
parms=$(echo $sudo | cut -d ' ' -f 2-)
|
||||
if which $cmd >/dev/null ; then
|
||||
(echo "zabbix ALL=NOPASSWD:SETENV: $(which $cmd) $(echo $parms | tr '%' '*')";echo) >$ZAF_SUDOERSD/zaf_$plugin || zaf_err "Error during zaf_ctrl_sudo"
|
||||
if zaf_which $cmd >/dev/null ; then
|
||||
(echo "zabbix ALL=NOPASSWD:SETENV: $(zaf_which $cmd) $(echo $parms | tr '%' '*')";echo) >$ZAF_SUDOERSD/zaf_$plugin || zaf_err "Error during zaf_ctrl_sudo"
|
||||
chmod 0440 $ZAF_SUDOERSD/zaf_$plugin
|
||||
else
|
||||
zaf_err "Cannot find binary '$cmd' to put into sudoers."
|
||||
|
||||
@@ -20,31 +20,41 @@ zaf_configure_os_freebsd() {
|
||||
ZAF_SUDOERSD="/usr/local/etc/sudoers.d"
|
||||
}
|
||||
|
||||
zaf_which() {
|
||||
if which >/dev/null 2>/dev/null; then
|
||||
which "$1"
|
||||
else
|
||||
[ -x /bin/$1 ] && { echo /bin/$1; return; }
|
||||
[ -x /usr/bin/$1 ] && { echo /usr/bin/$1; return; }
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
zaf_detect_system() {
|
||||
ZAF_FILES_UID=zabbix
|
||||
ZAF_FILES_GID=zabbix
|
||||
ZAF_FILES_UMASK=0770
|
||||
if which dpkg >/dev/null; then
|
||||
if zaf_which dpkg >/dev/null; then
|
||||
ZAF_PKG=dpkg
|
||||
ZAF_OS=$(lsb_release -is|zaf_tolower)
|
||||
ZAF_OS_CODENAME=$(lsb_release -cs|zaf_tolower)
|
||||
ZAF_CURL_INSECURE=0
|
||||
ZAF_AGENT_PKG="zabbix-agent"
|
||||
return
|
||||
else if which rpm >/dev/null; then
|
||||
else if zaf_which rpm >/dev/null; then
|
||||
ZAF_PKG="rpm"
|
||||
ZAF_OS=$(lsb_release -is|zaf_tolower)
|
||||
ZAF_OS_CODENAME=$(lsb_release -cs|zaf_tolower)
|
||||
ZAF_CURL_INSECURE=0
|
||||
ZAF_AGENT_PKG="zabbix-agent"
|
||||
return
|
||||
else if which opkg >/dev/null; then
|
||||
else if zaf_which opkg >/dev/null; then
|
||||
ZAF_PKG="opkg"
|
||||
. /etc/openwrt_release
|
||||
ZAF_OS="$(echo $DISTRIB_ID|zaf_tolower)"
|
||||
ZAF_OS_CODENAME="$(echo $DISTRIB_CODENAME|zaf_tolower)"
|
||||
return
|
||||
else if which pkg >/dev/null; then
|
||||
else if zaf_which pkg >/dev/null; then
|
||||
ZAF_PKG="pkg"
|
||||
ZAF_OS="freebsd"
|
||||
ZAF_OS_CODENAME="$(freebsd-version|cut -d '-' -f 1)"
|
||||
@@ -81,7 +91,7 @@ zaf_os_specific(){
|
||||
}
|
||||
|
||||
zaf_is_root(){
|
||||
[ "$USER" = "root" ]
|
||||
[ "$USER" = "root" ] || [ "$EUID" = "0" ] || [ -n "$ZAF_ISROOT" ]
|
||||
}
|
||||
|
||||
# Install file, bin or directory and respect install prefix
|
||||
|
||||
@@ -21,7 +21,7 @@ fi
|
||||
if ! zaf_fromcache "$key"; then
|
||||
zaf_fromcache "$key" >/dev/null 2>/dev/null
|
||||
[ $? -eq 3 ] && { zaf_err "Operation $key already in progress."; }
|
||||
if which at >/dev/null 2>/dev/null; then
|
||||
if zaf_which at >/dev/null 2>/dev/null; then
|
||||
at -M now >/dev/null 2>/dev/null <<EOF
|
||||
. $(dirname $0)/preload.sh; tmpf=\$(zaf_tmpfile cache); $@ 2>"\$tmpf" | zaf_tocache_stdin "$key" "$seconds" ; [ -s \$tmpf ] && zaf_wrn <\$tmpf
|
||||
EOF
|
||||
|
||||
Reference in New Issue
Block a user