mirror of
https://github.com/limosek/zaf.git
synced 2024-11-22 02:19:06 +01:00
Repaired files and modes
Repaired init functions
This commit is contained in:
parent
2bb33dc105
commit
b18919362a
107
install.sh
107
install.sh
@ -1,17 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
[ -z "$ZAF_DEBUG" ] && ZAF_DEBUG=1
|
############### Functions
|
||||||
export ZAF_LOG_STDERR="-s"
|
|
||||||
if [ -z "$ZAF_URL" ]; then
|
|
||||||
# Runing as standalone install.sh. We have to download rest of files first.
|
|
||||||
ZAF_URL="https://github.com/limosek/zaf/"
|
|
||||||
fi
|
|
||||||
|
|
||||||
[ -z "$ZAF_GITBRANCH" ] && ZAF_GITBRANCH=1.2
|
|
||||||
|
|
||||||
ZAF_TMP_DIR="/tmp/zaf-installer"
|
|
||||||
ZAF_DIR="$ZAF_TMP_DIR/zaf"
|
|
||||||
mkdir -p $ZAF_TMP_DIR
|
|
||||||
|
|
||||||
# Lite version of zaf_fetch_url, full version will be loaded later
|
# Lite version of zaf_fetch_url, full version will be loaded later
|
||||||
zaf_fetch_url(){
|
zaf_fetch_url(){
|
||||||
@ -33,40 +22,6 @@ zaf_download_files() {
|
|||||||
zaf_fetch_url $ZAF_URL/archive/$ZAF_GITBRANCH.tar.gz | tar -f - -C $ZAF_TMP_DIR -zx && mv $ZAF_TMP_DIR/zaf-$ZAF_GITBRANCH $ZAF_DIR || zaf_err "Cannot download and unpack zaf!"
|
zaf_fetch_url $ZAF_URL/archive/$ZAF_GITBRANCH.tar.gz | tar -f - -C $ZAF_TMP_DIR -zx && mv $ZAF_TMP_DIR/zaf-$ZAF_GITBRANCH $ZAF_DIR || zaf_err "Cannot download and unpack zaf!"
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! [ -f README.md ]; then
|
|
||||||
# We are runing from stdin
|
|
||||||
if ! which curl >/dev/null;
|
|
||||||
then
|
|
||||||
zaf_err "Curl not found. Cannot continue. Please install it."
|
|
||||||
fi
|
|
||||||
echo "Installing from url $url..."
|
|
||||||
[ -z "$*" ] && auto=auto
|
|
||||||
zaf_download_files && cd $ZAF_DIR && exec ./install.sh $auto "$@"
|
|
||||||
echo "Error downloading and runing installer!" >&2
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! type zaf_version >/dev/null; then
|
|
||||||
. lib/zaf.lib.sh
|
|
||||||
. lib/plugin.lib.sh
|
|
||||||
. lib/os.lib.sh
|
|
||||||
. lib/ctrl.lib.sh
|
|
||||||
. lib/cache.lib.sh
|
|
||||||
. lib/zbxapi.lib.sh
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Read options as config for ZAF
|
|
||||||
for pair in "$@"; do
|
|
||||||
echo $pair | grep -q '^ZAF\_' || continue
|
|
||||||
option=$(echo $pair|cut -d '=' -f 1)
|
|
||||||
value=$(echo $pair|cut -d '=' -f 2-)
|
|
||||||
eval "C_${option}='$value'"
|
|
||||||
zaf_wrn "Overriding $option from cmdline."
|
|
||||||
done
|
|
||||||
|
|
||||||
[ -z "$ZAF_CFG_FILE" ] && ZAF_CFG_FILE=$INSTALL_PREFIX/etc/zaf.conf
|
|
||||||
[ -n "$C_ZAF_DEBUG" ] && ZAF_DEBUG=$C_ZAF_DEBUG
|
|
||||||
|
|
||||||
# Read option. If it is already set in zaf.conf, it is skipped. If env variable is set, it is used instead of default
|
# Read option. If it is already set in zaf.conf, it is skipped. If env variable is set, it is used instead of default
|
||||||
# It sets global variable name on result.
|
# It sets global variable name on result.
|
||||||
# $1 - option name
|
# $1 - option name
|
||||||
@ -269,6 +224,9 @@ zaf_configure(){
|
|||||||
zaf_set_option ZAF_AGENT_CONFIG "$ZAF_AGENT_CONFIG"
|
zaf_set_option ZAF_AGENT_CONFIG "$ZAF_AGENT_CONFIG"
|
||||||
zaf_set_option ZAF_AGENT_CONFIGD "$ZAF_AGENT_CONFIGD"
|
zaf_set_option ZAF_AGENT_CONFIGD "$ZAF_AGENT_CONFIGD"
|
||||||
zaf_set_option ZAF_AGENT_BIN "$ZAF_AGENT_BIN"
|
zaf_set_option ZAF_AGENT_BIN "$ZAF_AGENT_BIN"
|
||||||
|
zaf_set_option ZAF_FILES_UID "$ZAF_FILES_UID"
|
||||||
|
zaf_set_option ZAF_FILES_GID "$ZAF_FILES_GID"
|
||||||
|
zaf_set_option ZAF_FILES_UMASK "$ZAF_FILES_UMASK"
|
||||||
zaf_set_option ZAF_AGENT_RESTART "$ZAF_AGENT_RESTART"
|
zaf_set_option ZAF_AGENT_RESTART "$ZAF_AGENT_RESTART"
|
||||||
zaf_set_option ZAF_SUDOERSD "$ZAF_SUDOERSD"
|
zaf_set_option ZAF_SUDOERSD "$ZAF_SUDOERSD"
|
||||||
zaf_set_option ZAF_CROND "$ZAF_CROND"
|
zaf_set_option ZAF_CROND "$ZAF_CROND"
|
||||||
@ -321,18 +279,59 @@ zaf_postconfigure() {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
############ First stage Init
|
||||||
|
|
||||||
|
if ! [ -f README.md ]; then
|
||||||
|
# We are runing from stdin
|
||||||
|
if ! which curl >/dev/null;
|
||||||
|
then
|
||||||
|
zaf_err "Curl not found. Cannot continue. Please install it."
|
||||||
|
fi
|
||||||
|
echo "Installing from url $url..."
|
||||||
|
[ -z "$*" ] && auto=auto
|
||||||
|
zaf_download_files && cd $ZAF_DIR && exec ./install.sh $auto "$@"
|
||||||
|
echo "Error downloading and runing installer!" >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Try to load local downloaded libs
|
||||||
|
if ! type zaf_version >/dev/null; then
|
||||||
|
. lib/zaf.lib.sh
|
||||||
|
. lib/plugin.lib.sh
|
||||||
|
. lib/os.lib.sh
|
||||||
|
. lib/ctrl.lib.sh
|
||||||
|
. lib/cache.lib.sh
|
||||||
|
. lib/zbxapi.lib.sh
|
||||||
|
fi
|
||||||
|
# If something was wrong reading libs, then exit
|
||||||
|
if ! type zaf_version >/dev/null; then
|
||||||
|
echo "Problem loading libraries?"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
########### Second stage init (all functions loaded)
|
||||||
|
|
||||||
|
[ -z "$ZAF_CFG_FILE" ] && ZAF_CFG_FILE=$INSTALL_PREFIX/etc/zaf.conf
|
||||||
if [ -f "${ZAF_CFG_FILE}" ]; then
|
if [ -f "${ZAF_CFG_FILE}" ]; then
|
||||||
. "${ZAF_CFG_FILE}"
|
. "${ZAF_CFG_FILE}"
|
||||||
fi
|
fi
|
||||||
ZAF_TMP_DIR="/tmp/zaf-installer/"
|
|
||||||
! [ -d "${ZAF_TMP_DIR}" ] && mkdir "${ZAF_TMP_DIR}"
|
|
||||||
|
|
||||||
# If debug is on, do not remove tmp dir
|
zaf_debug_init stderr
|
||||||
if [ "$ZAF_DEBUG" -le 3 ]; then
|
|
||||||
trap "rm -rf ${ZAF_TMP_DIR} " EXIT
|
ZAF_TMP_DIR="/tmp/zaf-installer"
|
||||||
else
|
ZAF_DIR="$ZAF_TMP_DIR/zaf"
|
||||||
trap 'zaf_wrn "Leaving $ZAF_TMP_DIR" contents due to ZAF_DEBUG.' EXIT
|
zaf_tmp_init
|
||||||
fi
|
|
||||||
|
zaf_cache_init
|
||||||
|
|
||||||
|
# Read options as config for ZAF
|
||||||
|
for pair in "$@"; do
|
||||||
|
echo $pair | grep -q '^ZAF\_' || continue
|
||||||
|
option=$(echo $pair|cut -d '=' -f 1)
|
||||||
|
value=$(echo $pair|cut -d '=' -f 2-)
|
||||||
|
eval "C_${option}='$value'"
|
||||||
|
zaf_wrn "Overriding $option from cmdline."
|
||||||
|
done
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
interactive)
|
interactive)
|
||||||
|
@ -1,5 +1,30 @@
|
|||||||
# Zaf cache related functions
|
# Zaf cache related functions
|
||||||
|
|
||||||
|
zaf_cache_init(){
|
||||||
|
[ -z "$ZAF_CACHE_DIR" ] && ZAF_CACHE_DIR=${ZAF_TMP_BASE}c
|
||||||
|
if [ -n "$ZAF_CACHE_DIR" ]; then
|
||||||
|
mkdir -p "$ZAF_CACHE_DIR"
|
||||||
|
if zaf_is_root; then
|
||||||
|
zaf_trc "Cache: Changing perms to $ZAF_CACHE_DIR (zabbix/$ZAF_ZABBIX_GID/0770)"
|
||||||
|
chown $ZAF_FILES_UID "$ZAF_CACHE_DIR"
|
||||||
|
chgrp $ZAF_FILES_GID "$ZAF_CACHE_DIR"
|
||||||
|
chmod $ZAF_FILES_UMASK "$ZAF_CACHE_DIR"
|
||||||
|
fi
|
||||||
|
if [ -w $ZAF_CACHE_DIR ]; then
|
||||||
|
zaf_trc "Cache: Removing stale entries"
|
||||||
|
(cd $ZAF_CACHE_DIR && find ./ -type f -name '*.info' -mmin +1 | \
|
||||||
|
while read line ; do
|
||||||
|
echo rm -f $line $(basename $line .info)
|
||||||
|
done
|
||||||
|
)
|
||||||
|
else
|
||||||
|
zaf_err "Cache dir is not accessible! Become root or member of $ZAF_FILES_GID group!"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
zaf_err "Cache dir not set."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
zaf_cache_clean(){
|
zaf_cache_clean(){
|
||||||
if [ -n "$ZAF_CACHE_DIR" ]; then
|
if [ -n "$ZAF_CACHE_DIR" ]; then
|
||||||
zaf_wrn "Removing cache entries"
|
zaf_wrn "Removing cache entries"
|
||||||
@ -7,11 +32,7 @@ zaf_cache_clean(){
|
|||||||
else
|
else
|
||||||
zaf_err "Cache dir not set."
|
zaf_err "Cache dir not set."
|
||||||
fi
|
fi
|
||||||
mkdir -p "$ZAF_CACHE_DIR"
|
zaf_cache_init
|
||||||
if zaf_is_root; then
|
|
||||||
chmod 770 "$ZAF_CACHE_DIR"
|
|
||||||
chgrp $(id -g zabbix) "$ZAF_CACHE_DIR"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get cache key from requested param
|
# Get cache key from requested param
|
||||||
|
@ -21,6 +21,9 @@ zaf_configure_os_freebsd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
zaf_detect_system() {
|
zaf_detect_system() {
|
||||||
|
ZAF_FILES_UID=zabbix
|
||||||
|
ZAF_FILES_GID=zabbix
|
||||||
|
ZAF_FILES_UMASK=0770
|
||||||
if which dpkg >/dev/null; then
|
if which dpkg >/dev/null; then
|
||||||
ZAF_PKG=dpkg
|
ZAF_PKG=dpkg
|
||||||
ZAF_OS=$(lsb_release -is|zaf_tolower)
|
ZAF_OS=$(lsb_release -is|zaf_tolower)
|
||||||
|
@ -9,26 +9,13 @@
|
|||||||
. ${ZAF_LIB_DIR}/zbxapi.lib.sh
|
. ${ZAF_LIB_DIR}/zbxapi.lib.sh
|
||||||
. ${ZAF_LIB_DIR}/cache.lib.sh
|
. ${ZAF_LIB_DIR}/cache.lib.sh
|
||||||
|
|
||||||
[ -z "$ZAF_TMP_BASE" ] && ZAF_TMP_BASE=/tmp/zaf
|
if ! type zaf_version >/dev/null; then
|
||||||
[ -z "$ZAF_TMP_DIR" ] && ZAF_TMP_DIR="${ZAF_TMP_BASE}-$(zaf_random)"
|
echo "Problem loading libraries?"
|
||||||
[ -z "$ZAF_CACHE_DIR" ] && ZAF_CACHE_DIR=${ZAF_TMP_BASE}c
|
exit 2
|
||||||
|
|
||||||
rm -rf "${ZAF_TMP_DIR}"
|
|
||||||
|
|
||||||
if ! [ -d "${ZAF_TMP_DIR}" ]; then
|
|
||||||
mkdir "${ZAF_TMP_DIR}"
|
|
||||||
fi
|
fi
|
||||||
|
zaf_debug_init
|
||||||
! [ -d "${ZAF_CACHE_DIR}" ] && mkdir "${ZAF_CACHE_DIR}"
|
zaf_tmp_init
|
||||||
[ -z "$ZAF_DEBUG" ] && ZAF_DEBUG=1
|
zaf_cache_init
|
||||||
|
|
||||||
if [ "$ZAF_DEBUG" -le 3 ]; then
|
|
||||||
trap "rm -rf ${ZAF_TMP_DIR}" EXIT
|
|
||||||
else
|
|
||||||
trap 'zaf_wrn "Leaving $ZAF_TMP_DIR" contents due to ZAF_DEBUG.' EXIT
|
|
||||||
fi
|
|
||||||
|
|
||||||
#trap 'touch /tmp/aaaa' ALARM
|
|
||||||
|
|
||||||
export ZAF_LIB_DIR
|
export ZAF_LIB_DIR
|
||||||
export ZAF_TMP_DIR
|
export ZAF_TMP_DIR
|
||||||
|
@ -38,6 +38,12 @@ zaf_hlp() {
|
|||||||
dl=$(expr $cols - $kl)
|
dl=$(expr $cols - $kl)
|
||||||
printf %-${kl}s%-${dl}s%b "$1" "$2" "\n"
|
printf %-${kl}s%-${dl}s%b "$1" "$2" "\n"
|
||||||
}
|
}
|
||||||
|
# $1 if nonempty, log to stderr too
|
||||||
|
zaf_debug_init() {
|
||||||
|
[ -z "$ZAF_DEBUG" ] && ZAF_DEBUG=1
|
||||||
|
export ZAF_DEBUG
|
||||||
|
[ -n "$1" ] && export ZAF_LOG_STDERR="-s"
|
||||||
|
}
|
||||||
|
|
||||||
zaf_version(){
|
zaf_version(){
|
||||||
echo $ZAF_VERSION
|
echo $ZAF_VERSION
|
||||||
@ -236,6 +242,23 @@ zaf_date_add() {
|
|||||||
date -d "$1 seconds" "+%Y-%m-%d %H:%M:%S" 2>/dev/null || date -d "$(expr $(date +%s) + $1)" -D %s "+%Y-%m-%d %H:%M:%S"
|
date -d "$1 seconds" "+%Y-%m-%d %H:%M:%S" 2>/dev/null || date -d "$(expr $(date +%s) + $1)" -D %s "+%Y-%m-%d %H:%M:%S"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zaf_tmp_init() {
|
||||||
|
[ -z "$ZAF_TMP_BASE" ] && ZAF_TMP_BASE=/tmp/zaf
|
||||||
|
ZAF_TMP_DIR="${ZAF_TMP_BASE}-$(zaf_random)"
|
||||||
|
mkdir -p $ZAF_TMP_DIR
|
||||||
|
if zaf_is_root; then
|
||||||
|
chown $ZAF_FILES_UID "$ZAF_TMP_DIR"
|
||||||
|
chgrp $ZAF_FILES_GID "$ZAF_TMP_DIR"
|
||||||
|
chmod $ZAF_FILES_UMASK "$ZAF_TMP_DIR"
|
||||||
|
fi
|
||||||
|
# If debug is on, do not remove tmp dir
|
||||||
|
if [ "$ZAF_DEBUG" -le 3 ]; then
|
||||||
|
trap "rm -rf ${ZAF_TMP_DIR}" EXIT
|
||||||
|
else
|
||||||
|
trap 'zaf_wrn "Leaving $ZAF_TMP_DIR" contents due to ZAF_DEBUG.' EXIT
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Create temp file and return its name
|
# Create temp file and return its name
|
||||||
# $1 prefix or empty
|
# $1 prefix or empty
|
||||||
zaf_tmpfile() {
|
zaf_tmpfile() {
|
||||||
|
27
zaf
27
zaf
@ -43,30 +43,9 @@ else
|
|||||||
[ -f ${ZAF_LIB_DIR}/zaf.${ZAF_OS}.sh ] && . ${ZAF_LIB_DIR}/zaf.${ZAF_OS}.sh
|
[ -f ${ZAF_LIB_DIR}/zaf.${ZAF_OS}.sh ] && . ${ZAF_LIB_DIR}/zaf.${ZAF_OS}.sh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ -z "$ZAF_TMP_BASE" ] && ZAF_TMP_BASE=/tmp/zaf
|
zaf_debug_init stderr
|
||||||
ZAF_TMP_DIR="${ZAF_TMP_BASE}-$(zaf_random)"
|
zaf_tmp_init
|
||||||
[ -z "$ZAF_CACHE_DIR" ] && ZAF_CACHE_DIR=${ZAF_TMP_BASE}c
|
zaf_cache_init
|
||||||
|
|
||||||
[ -z "$ZAF_DEBUG" ] && ZAF_DEBUG=1
|
|
||||||
export ZAF_DEBUG
|
|
||||||
export ZAF_LOG_STDERR="-s"
|
|
||||||
|
|
||||||
# If debug is on, do not remove tmp dir
|
|
||||||
if [ "$ZAF_DEBUG" -le 3 ]; then
|
|
||||||
trap "rm -rf ${ZAF_TMP_DIR}" EXIT
|
|
||||||
else
|
|
||||||
trap 'zaf_wrn "Leaving $ZAF_TMP_DIR" contents due to ZAF_DEBUG.' EXIT
|
|
||||||
fi
|
|
||||||
|
|
||||||
! [ -d "${ZAF_TMP_DIR}" ] && mkdir "${ZAF_TMP_DIR}"
|
|
||||||
if ! [ -d "${ZAF_CACHE_DIR}" ]; then
|
|
||||||
mkdir "${ZAF_CACHE_DIR}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if zaf_is_root; then
|
|
||||||
chgrp $(id -g zabbix) "${ZAF_CACHE_DIR}"
|
|
||||||
chmod 770 "${ZAF_CACHE_DIR}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user