1
0
mirror of https://github.com/limosek/zaf.git synced 2024-11-23 10:59:06 +01:00

Added makefile for debian package

This commit is contained in:
Lukas Macura 2016-04-06 14:25:10 +02:00
parent 7eea6896e1
commit 081ac01e6b
8 changed files with 127 additions and 5 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
*~
plugins/
out/
tmp/

68
Makefile Normal file
View File

@ -0,0 +1,68 @@
# Zabbix agent framework makefile
CONTROLFILES=$(foreach p,$(PLUGINS),$(p)/control.zaf)
ZAF_EXPORT_OPTS=$(foreach o,$(ZAF_OPTIONS),$(shell echo $(o)|cut -d '=' -f 1))
DEBIAN_DIR=tmp/deb
DEBIAN_CTRL=$(DEBIAN_DIR)/DEBIAN
DEBIAN_PKG=out/zaf.deb
all: help
help:
@echo make '{deb|ipk|rpm}' '[PLUGINS="/dir/plg1 /dir/plg2] [ZAF_OPTIONS="ZAF_cfg=val ..."] [AGENT_OPTIONS="Z_Server=host ..."]'
deb: deb-clean deb-init deb-deps deb-control deb-postinst deb-cp deb-changelog deb-package
deb-clean:
rm -rf $(DEBIAN_DIR) $(DEBIAN_PKG)
deb-init:
@mkdir -p tmp out $(DEBIAN_DIR)
deb-deps: $(CONTROLFILES)
@which dpkg >/dev/null && which dpkg-buildpackage >/dev/null && which dch >/dev/null || { echo "You need essential debian developer tools. Please install them:\nsudo apt-get install build-essential devscripts debhelper"; exit 2; }
deb-control:
@mkdir -p $(DEBIAN_CTRL)
@. lib/zaf.lib.sh; \
. lib/ctrl.lib.sh; \
for p in $(PLUGINS); do \
DEPENDS="$$DEPENDS,$$(zaf_ctrl_get_global_option $$p/control.zaf Depends-dpkg | tr ' ' ',')"; \
done; \
zaf_far '{ZAF_VERSION}' "0.1" <files/control.template | zaf_far '{ZAF_DEPENDS}' "$$DEPENDS" >$(DEBIAN_CTRL)/control
deb-postinst:
ifneq ($(PLUGINS),)
@echo -n "#!/bin/sh\nzaf install " >$(DEBIAN_CTRL)/postinst
@. lib/zaf.lib.sh; \
. lib/ctrl.lib.sh; \
for p in $(PLUGINS); do \
echo -n " "$$(zaf_ctrl_get_global_option $$p/control.zaf Plugin) ; \
done >>$(DEBIAN_CTRL)/postinst
@echo >>$(DEBIAN_CTRL)/postinst
@chmod +x $(DEBIAN_CTRL)/postinst
endif
deb-cp:
@mkdir -p $(DEBIAN_DIR)
INSTALL_PREFIX=$(DEBIAN_DIR) ZAF_DEBUG=0 ./install.sh auto $(ZAF_OPTIONS) $(AGENT_OPTIONS)
@. lib/zaf.lib.sh; \
. lib/ctrl.lib.sh; \
for p in $(PLUGINS); do \
plugin=$$(zaf_ctrl_get_global_option $$p/control.zaf Plugin) ; \
mkdir -p $(DEBIAN_DIR)/usr/lib/zaf/plugins/$$plugin/; \
cp -R $$p/* $(DEBIAN_DIR)/usr/lib/zaf/plugins/$$plugin/; \
done
@rm -rf $(DEBIAN_DIR)/tmp
@cp $(DEBIAN_DIR)/etc/zaf.conf tmp/zaf.conf
grep -E "$$(echo $(ZAF_EXPORT_OPTS) | tr ' ' '|')=" tmp/zaf.conf >$(DEBIAN_DIR)/etc/zaf.conf
ifneq ($(AGENT_OPTIONS),)
echo "ZAF_AGENT_OPTIONS=\"$(AGENT_OPTIONS)\"" >>$(DEBIAN_DIR)/etc/zaf.conf
endif
deb-changelog:
@cp files/changelog.template debian/changelog
deb-package:
dpkg-deb -b $(DEBIAN_DIR) $(DEBIAN_PKG)

5
files/changelog.template Normal file
View File

@ -0,0 +1,5 @@
PACKAGE (0.1) zaf; urgency=medium
* Initial release.
-- Lukas Macura <lukas@macura.cz> Wed, 06 Apr 2016 13:56:25 +0200

11
files/control.template Normal file
View File

@ -0,0 +1,11 @@
Package: zaf
Version: {ZAF_VERSION}
Homepage: https://github.com/limosek/zaf
Section: admin
Priority: optional
Architecture: all
Depends: dash, awk, sed, grep, coreutils {ZAF_DEPENDS}
Maintainer: Lukas Macura <lukas@macura.cz>
Description: Zabbix agent framework package
This tool is used to maintain external zabbix checks in one place. Primary goal is not to make all plugins available here but to be able to use any plugin and decentralized development. If you are maintainer of some external check, it is enough to create zaf file in your repo and use zaf installer everywhere.

View File

@ -0,0 +1,12 @@
ZAF_PKG='dpkg'
ZAF_AGENT_PKG='zabbix-agent'
ZAF_TMP_BASE='/tmp/zaf'
ZAF_LIB_DIR='/usr/lib/zaf'
ZAF_BIN_DIR='/usr/bin'
ZAF_PLUGINS_DIR='/usr/lib/zaf/plugins'
ZAF_PLUGINS_URL='https://raw.githubusercontent.com/limosek/zaf-plugins/master/'
ZAF_PLUGINS_GITURL='https://github.com/limosek/zaf-plugins.git'
ZAF_REPO_DIR='/usr/lib/zaf/repo'
ZAF_AGENT_CONFIGD='/etc/zabbix/zabbix_agentd.d'
ZAF_AGENT_BIN='/usr/sbin/zabbix_agentd'
ZAF_AGENT_RESTART='service zabbix-agent restart'

View File

@ -127,6 +127,7 @@ zaf_configure_agent() {
zaf_install_dir "$ZAF_AGENT_CONFIGD"
echo -n >"$ZAF_AGENT_CONFIGD/zaf_options.conf" || zaf_err "Cannot access $ZAF_AGENT_CONFIGD/zaf_options.conf"
! [ -f "$ZAF_AGENT_CONFIG" ] && zaf_install "$ZAF_AGENT_CONFIG"
for pair in "$@"; do
echo $pair | grep -q '^Z\_' || continue # Skip non Z_ vars
option=$(echo $pair|cut -d '=' -f 1|cut -d '_' -f 2)
@ -239,10 +240,12 @@ reconf)
;;
install)
zaf_configure auto
zaf_configure_agent $ZAF_AGENT_OPTIONS "$@"
zaf_set_agent_option "Include" "$ZAF_AGENT_CONFIGD" append
rm -rif ${ZAF_TMP_DIR}
mkdir -p ${ZAF_TMP_DIR}
if zaf_is_root; then
zaf_configure_agent $ZAF_AGENT_OPTIONS "$@"
zaf_set_agent_option "Include" "$ZAF_AGENT_CONFIGD" append
fi
zaf_install_dir ${ZAF_LIB_DIR}
zaf_install_dir ${ZAF_PLUGINS_DIR}
zaf_install $(zaf_getrest lib/zaf.lib.sh) ${ZAF_LIB_DIR}

View File

@ -92,14 +92,14 @@ zaf_ctrl_install() {
local cmd
pdir="$3"
binaries=$(zaf_ctrl_get_global_block <$2 | zaf_block_get_option "Install-bin")
binaries=$(zaf_ctrl_get_global_option $2 "Install-bin")
for b in $binaries; do
zaf_fetch_url "$1/$b" >"${ZAF_TMP_DIR}/$b"
zaf_install_bin "${ZAF_TMP_DIR}/$b" "$pdir"
done
script=$(zaf_ctrl_get_global_block <$2 | zaf_block_get_moption "Install-script")
script=$(zaf_ctrl_get_global_option $2 "Install-script")
[ -n "$script" ] && eval "$script"
cmd=$(zaf_ctrl_get_global_block <$2 | zaf_block_get_option "Install-cmd")
cmd=$(zaf_ctrl_get_global_option $2 "Install-cmd")
[ -n "$cmd" ] && $cmd
}

View File

@ -8,6 +8,12 @@ zaf_configure_os_openwrt() {
ZAF_CURL_INSECURE=1
}
zaf_configure_os_freebsd() {
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_detect_system() {
if which dpkg >/dev/null; then
ZAF_PKG=dpkg
@ -29,12 +35,18 @@ zaf_detect_system() {
ZAF_OS="$(echo $DISTRIB_ID|tr '[:upper:]' '[:lower:]')"
ZAF_OS_CODENAME="$(echo $DISTRIB_CODENAME|tr '[:upper:]' '[:lower:]')"
return
else if which pkg >/dev/null; then
ZAF_PKG="pkg"
ZAF_OS="freebsd"
ZAF_OS_CODENAME="$(freebsd-version|cut -d '-' -f 1)"
return
else
ZAF_PKG="unknown"
ZAF_OS="unknown"
ZAF_OS_CODENAME="unknown"
ZAF_AGENT_PKG=""
return
fi
fi
fi
fi
@ -137,4 +149,13 @@ zaf_check_deps_opkg() {
done
}
# Check if pkg dependency is met
# $* - packages
zaf_check_deps_pkg() {
local p
for p in $*; do
pkg query -x "Package: %n" $p| grep -q 'Package:' || { echo "Missing package $p" >&2; return 1; }
done
}