2016-03-30 16:09:02 +02:00
|
|
|
# Os related functions
|
|
|
|
|
2016-11-22 14:27:44 +01:00
|
|
|
zaf_preconfigure_os_openwrt() {
|
2016-12-07 14:25:34 +01:00
|
|
|
ZAF_AGENT_RESTART="/etc/init.d/zabbix_agentd restart"
|
|
|
|
ZAF_AGENT_CONFIGD="/var/run/zabbix_agentd.conf.d/"
|
|
|
|
ZAF_AGENT_CONFIG="/etc/zabbix_agentd.conf"
|
|
|
|
ZAF_AGENT_PKG="zabbix-agentd"
|
|
|
|
ZAF_CURL_INSECURE=1
|
2016-03-31 15:56:23 +02:00
|
|
|
}
|
2016-11-22 14:27:44 +01:00
|
|
|
zaf_preconfigure_os_beesip() {
|
2016-12-07 14:25:34 +01:00
|
|
|
zaf_preconfigure_os_openwrt
|
2016-04-19 11:09:22 +02:00
|
|
|
}
|
2016-03-31 15:56:23 +02:00
|
|
|
|
2016-11-22 14:27:44 +01:00
|
|
|
zaf_preconfigure_os_freebsd() {
|
2016-12-07 14:25:34 +01:00
|
|
|
ZAF_AGENT_PKG="zabbix3-agent"
|
|
|
|
ZAF_AGENT_CONFIG="/usr/local/etc/zabbix3/zabbix_agentd.conf"
|
|
|
|
ZAF_AGENT_CONFIGD="/usr/local/etc/zabbix3/zabbix_agentd.conf.d/"
|
|
|
|
ZAF_AGENT_BIN="/usr/local/sbin/zabbix_agentd"
|
|
|
|
ZAF_AGENT_RESTART="service zabbix_agentd restart"
|
|
|
|
ZAF_SUDOERSD="/usr/local/etc/sudoers.d"
|
2016-04-06 14:25:10 +02:00
|
|
|
}
|
|
|
|
|
2016-11-22 14:27:44 +01:00
|
|
|
zaf_postconfigure_os_openwrt() {
|
|
|
|
if ! grep -q "zaf agent-config" /etc/init.d/zabbix_agentd; then
|
|
|
|
sed -i 's/uci2config $NAME/uci2config $NAME; zaf agent-config/' /etc/init.d/zabbix_agentd
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
zaf_postconfigure_os_beesip() {
|
|
|
|
zaf_postconfigure_os_openwrt
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:59:59 +01:00
|
|
|
zaf_which() {
|
|
|
|
if which >/dev/null 2>/dev/null; then
|
|
|
|
which "$1"
|
|
|
|
else
|
2016-11-21 17:11:30 +01:00
|
|
|
for i in /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin; do
|
|
|
|
[ -x $i/$1 ] && { echo $i/$1; return; }
|
|
|
|
done
|
2016-11-21 16:59:59 +01:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-03-30 16:09:02 +02:00
|
|
|
zaf_detect_system() {
|
2016-04-24 04:51:35 +02:00
|
|
|
ZAF_FILES_UID=zabbix
|
|
|
|
ZAF_FILES_GID=zabbix
|
|
|
|
ZAF_FILES_UMASK=0770
|
2016-11-21 16:59:59 +01:00
|
|
|
if zaf_which dpkg >/dev/null; then
|
2016-03-31 15:56:23 +02:00
|
|
|
ZAF_PKG=dpkg
|
2016-04-12 10:36:17 +02:00
|
|
|
ZAF_OS=$(lsb_release -is|zaf_tolower)
|
|
|
|
ZAF_OS_CODENAME=$(lsb_release -cs|zaf_tolower)
|
2016-03-30 16:09:02 +02:00
|
|
|
ZAF_CURL_INSECURE=0
|
|
|
|
ZAF_AGENT_PKG="zabbix-agent"
|
|
|
|
return
|
2016-11-21 16:59:59 +01:00
|
|
|
else if zaf_which rpm >/dev/null; then
|
2016-03-30 16:09:02 +02:00
|
|
|
ZAF_PKG="rpm"
|
2016-04-12 10:36:17 +02:00
|
|
|
ZAF_OS=$(lsb_release -is|zaf_tolower)
|
|
|
|
ZAF_OS_CODENAME=$(lsb_release -cs|zaf_tolower)
|
2016-03-30 16:09:02 +02:00
|
|
|
ZAF_CURL_INSECURE=0
|
|
|
|
ZAF_AGENT_PKG="zabbix-agent"
|
|
|
|
return
|
2016-11-21 16:59:59 +01:00
|
|
|
else if zaf_which opkg >/dev/null; then
|
2016-03-30 16:09:02 +02:00
|
|
|
ZAF_PKG="opkg"
|
|
|
|
. /etc/openwrt_release
|
2016-04-12 10:36:17 +02:00
|
|
|
ZAF_OS="$(echo $DISTRIB_ID|zaf_tolower)"
|
|
|
|
ZAF_OS_CODENAME="$(echo $DISTRIB_CODENAME|zaf_tolower)"
|
2016-03-30 16:09:02 +02:00
|
|
|
return
|
2016-11-21 16:59:59 +01:00
|
|
|
else if zaf_which pkg >/dev/null; then
|
2016-04-06 14:25:10 +02:00
|
|
|
ZAF_PKG="pkg"
|
|
|
|
ZAF_OS="freebsd"
|
|
|
|
ZAF_OS_CODENAME="$(freebsd-version|cut -d '-' -f 1)"
|
|
|
|
return
|
2016-03-30 16:09:02 +02:00
|
|
|
else
|
|
|
|
ZAF_PKG="unknown"
|
|
|
|
ZAF_OS="unknown"
|
|
|
|
ZAF_OS_CODENAME="unknown"
|
|
|
|
ZAF_AGENT_PKG=""
|
2016-12-07 14:25:34 +01:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
2016-03-30 16:09:02 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-03-31 15:56:23 +02:00
|
|
|
# Run OS specific command
|
|
|
|
# $1 - name of the function.
|
|
|
|
# all variants will be tested. (name_os_codename, name_os, name_{dpkg|opkg|rpm}, name )
|
|
|
|
zaf_os_specific(){
|
2016-12-07 14:25:34 +01:00
|
|
|
local func="$1"
|
|
|
|
|
|
|
|
if type "${func}_${ZAF_OS}_${ZAF_OS_CODENAME}" >/dev/null 2>/dev/null; then
|
|
|
|
eval "${func}_${ZAF_OS}_${ZAF_OS_CODENAME} $2 $3 $4 $5 $6"
|
|
|
|
else if type "${func}_${ZAF_OS}" >/dev/null 2>/dev/null; then
|
|
|
|
eval "${func}_${ZAF_OS} $2 $3 $4 $5 $6"
|
|
|
|
else if type "${func}_${ZAF_PKG}" >/dev/null 2>/dev/null; then
|
|
|
|
eval "${func}_${ZAF_PKG} $2 $3 $4 $5 $6"
|
|
|
|
else
|
|
|
|
zaf_dbg "No OS/packager specific implementation for $1"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2016-03-31 15:56:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
zaf_is_root(){
|
2016-12-07 14:25:34 +01:00
|
|
|
[ "$USER" = "root" ] || [ "$EUID" = "0" ] || [ -n "$ZAF_ISROOT" ]
|
2016-03-31 15:56:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Install file, bin or directory and respect install prefix
|
|
|
|
# $1 - src file
|
|
|
|
# $2 - directory
|
|
|
|
zaf_install(){
|
2016-12-07 14:25:34 +01:00
|
|
|
zaf_dbg "Install file $1 to $INSTALL_PREFIX/$2/$(basename $1)"
|
|
|
|
$ZAF_DO cp "$1" "$INSTALL_PREFIX/$2/$(basename $1)" || zaf_err "Cannot create file $INSTALL_PREFIX/$2/$(basename $1)!"
|
2016-03-31 15:56:23 +02:00
|
|
|
}
|
|
|
|
# $1 - src file
|
|
|
|
# $2 - directory
|
|
|
|
zaf_install_bin(){
|
2016-12-07 14:25:34 +01:00
|
|
|
zaf_dbg "Install binary $1 to $INSTALL_PREFIX/$2/$(basename $1)"
|
|
|
|
$ZAF_DO cp "$1" "$INSTALL_PREFIX/$2/$(basename $1)" || zaf_err "Cannot create binary $INSTALL_PREFIX/$2/$(basename $1)!"
|
|
|
|
$ZAF_DO chmod +x "$INSTALL_PREFIX/$2/$(basename $1)"
|
2016-03-31 15:56:23 +02:00
|
|
|
}
|
|
|
|
# $1 - directory
|
|
|
|
zaf_install_dir(){
|
2016-12-07 14:25:34 +01:00
|
|
|
zaf_dbg "Install directory $1 to $INSTALL_PREFIX/$1"
|
|
|
|
$ZAF_DO mkdir -p "$INSTALL_PREFIX/$1" || zaf_err "Cannot create directory $INSTALL_PREFIX/$1!"
|
2016-03-31 15:56:23 +02:00
|
|
|
}
|
|
|
|
# $1 - file
|
|
|
|
zaf_touch(){
|
2016-12-07 14:25:34 +01:00
|
|
|
zaf_dbg "Touch $INSTALL_PREFIX/$1"
|
|
|
|
$ZAF_DO touch "$INSTALL_PREFIX/$1"
|
2016-04-01 15:51:45 +02:00
|
|
|
}
|
|
|
|
# $1 - directory
|
|
|
|
zaf_uninstall(){
|
2016-12-07 14:25:34 +01:00
|
|
|
if [ -n "$INSTALL_PREFIX" ]; then
|
|
|
|
zaf_dbg "Removing $INSTALL_PREFIX/$1"
|
2016-04-01 15:51:45 +02:00
|
|
|
$ZAF_DO rm -rf "$INSTALL_PREFIX/$1"
|
2016-12-07 14:25:34 +01:00
|
|
|
else
|
2016-04-01 15:51:45 +02:00
|
|
|
zaf_dbg "Removing $1"
|
|
|
|
$ZAF_DO rm -rf "$1"
|
2016-12-07 14:25:34 +01:00
|
|
|
fi
|
2016-03-31 15:56:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Automaticaly install agent on debian
|
|
|
|
# For another os, create similar function (install_zabbix_centos)
|
|
|
|
zaf_install_agent_debian() {
|
2016-12-07 14:25:34 +01:00
|
|
|
zaf_fetch_url "http://repo.zabbix.com/zabbix/3.0/debian/pool/main/z/zabbix-release/zabbix-release_3.0-1+${ZAF_OS_CODENAME}_all.deb" >"/tmp/zaf-installer/zabbix-release_3.0-1+${ZAF_OS_CODENAME}_all.deb" \
|
2016-04-04 10:27:25 +02:00
|
|
|
&& dpkg -i "/tmp/zaf-installer/zabbix-release_3.0-1+${ZAF_OS_CODENAME}_all.deb" \
|
2016-03-31 15:56:23 +02:00
|
|
|
&& apt-get update \
|
2016-04-04 10:27:25 +02:00
|
|
|
&& apt-get install -y -q $ZAF_AGENT_PKG
|
|
|
|
}
|
|
|
|
|
|
|
|
zaf_install_agent_opkg() {
|
2016-12-07 14:25:34 +01:00
|
|
|
opkg update && \
|
|
|
|
opkg install $ZAF_AGENT_PKG
|
2016-03-31 15:56:23 +02:00
|
|
|
}
|
|
|
|
|
2016-03-30 16:09:02 +02:00
|
|
|
# Check if dpkg dependency is met
|
|
|
|
# $* - packages
|
|
|
|
zaf_check_deps_dpkg() {
|
2016-04-04 10:27:25 +02:00
|
|
|
for i in $*; do
|
2016-12-11 14:58:05 +01:00
|
|
|
dpkg-query -f '${db:Status-Status},${Package}\n' -W $* 2>/dev/null | grep -qE "^(installed|^,)"
|
2016-04-04 10:27:25 +02:00
|
|
|
done
|
2016-03-30 16:09:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Check if dpkg dependency is met
|
|
|
|
# $* - packages
|
|
|
|
zaf_check_deps_rpm() {
|
2016-04-04 10:27:25 +02:00
|
|
|
for i in $*; do
|
|
|
|
rpm --quiet -qi $i | grep -q $i
|
|
|
|
done
|
2016-03-30 16:09:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Check if dpkg dependency is met
|
|
|
|
# $* - packages
|
|
|
|
zaf_check_deps_opkg() {
|
|
|
|
local p
|
|
|
|
for p in $*; do
|
2016-04-12 10:36:17 +02:00
|
|
|
opkg info $p | grep -q 'Package:' || { return 1; }
|
2016-03-30 16:09:02 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-04-06 14:25:10 +02:00
|
|
|
# Check if pkg dependency is met
|
|
|
|
# $* - packages
|
|
|
|
zaf_check_deps_pkg() {
|
|
|
|
local p
|
|
|
|
for p in $*; do
|
2016-04-12 10:36:17 +02:00
|
|
|
pkg query -x "Package: %n" $p| grep -q 'Package:' || { return 1; }
|
2016-04-06 14:25:10 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-03-30 16:09:02 +02:00
|
|
|
|