forked from glensc/nagios-plugin-check_raid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
122 lines (106 loc) · 4.24 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Makefile for check_raid plugin
PLUGIN := check_raid
PLUGIN_SCRIPT := $(PLUGIN).pl
PLUGIN_VERSION := $(shell test -e .git && { git tag -d snapshot >/dev/null 2>&1 || :; git describe --tags; } || awk -F"'" '/VERSION/&&/=/{print $$2}' bin/$(PLUGIN_SCRIPT))
PLUGINDIR := /usr/lib/nagios/plugins
PLUGINCONF := /etc/nagios/plugins
CACHE_DIR := $(CURDIR)/cache
CPANM_CACHE := $(CACHE_DIR)/cpanm
CPANM := cpanm --cascade-search --save-dists=$(CPANM_CACHE) --mirror=$(CPANM_CACHE) --mirror=http://search.cpan.org/CPAN
export PERL5LIB := $(CURDIR)/sysdeps/lib/perl5
PATH := $(CURDIR)/sysdeps/bin:$(PATH)
# rpm version related macros
RPM_NAME := nagios-plugin-$(PLUGIN)
version_parts := $(subst -, ,$(PLUGIN_VERSION))
space := $(nil) $(nil)
RPM_VERSION := $(firstword $(version_parts))
RPM_RELEASE := $(subst $(space),.,$(wordlist 2, $(words $(version_parts)), $(version_parts)))
# if built from tag, release "1", otherwise "0.something"
ifneq ($(RPM_RELEASE),)
RPM_RELEASE := 0.$(RPM_RELEASE)
else
RPM_RELEASE := 1
endif
RPM_FILENAME := $(RPM_NAME)-$(RPM_VERSION)-$(RPM_RELEASE).noarch.rpm
all:
test:
perl -MTest::Harness -e 'runtests @ARGV' t/*.t
builddeps:
$(CPANM) -n -L sysdeps App::FatPacker App::FatPacker::Simple
pack:
rm -f $(PLUGIN_SCRIPT)
$(MAKE) $(PLUGIN_SCRIPT)
installdeps:
$(CPANM) --installdeps -Llocal -n .
# Params::Validate adds some Module::Build dependency, but Monitoring-Plugin needs just:
# Configuring Monitoring-Plugin-0.39 ... OK
# ==> Found dependencies: Params::Validate, Class::Accessor, Config::Tiny, Math::Calc::Units
exclude_fatpack_modules := Module::Build,CPAN::Meta,Module::CPANfile,ExtUtils::MakeMaker::CPANfile
fatpack: installdeps
fatpack-simple \
--exclude-strip='^lib/*' \
--exclude-strip='^bin/*' \
--exclude=$(exclude_fatpack_modules) \
bin/$(PLUGIN_SCRIPT) $(options)
$(PLUGIN_SCRIPT): bin/$(PLUGIN_SCRIPT) builddeps
# ensure cpanm is present
$(CPANM) --version
# need 0.10.0 of fatpacker for Module::Pluggable to work
perl -e 'use App::FatPacker 0.10.0'
perl -e 'use App::FatPacker::Simple 0.07'
# ensure we run in clean tree. export git tree and run there.
rm -rf fatpack
install -d fatpack
git archive HEAD | tar -x -C fatpack
sed -i -e '/VERSION/ s;q/.*/;q/$(PLUGIN_VERSION)/;' fatpack/bin/check_raid.pl
$(MAKE) -f $(CURDIR)/Makefile -C fatpack fatpack CACHE_DIR=$(CACHE_DIR) PERL5LIB=$(PERL5LIB) options="--output ../$@"
rm -rf fatpack
grep -o 'fatpacked{.*}' $@
perltidy:
perltidy $(PLUGIN_SCRIPT)
# create snapshot release from current HEAD
# travis will build release tarball and upload it to github release page
snapshot:
@set -e; \
git for-each-ref refs/tags/snapshot --format '%(refname:strip=2)' | xargs git tag -d; \
branch=$$(git rev-parse --abbrev-ref HEAD); \
commit=$$(git rev-parse --short HEAD); \
title="snapshot from $$branch branch"; \
body="created from $$commit on $$branch branch. uploaded by travis. use at your own risk"; \
message=`printf "%s\n\n%s" "$$title" "$$body"`; \
git tag -am "$$message" snapshot HEAD; \
git push -f [email protected]:glensc/nagios-plugin-check_raid.git snapshot
# it's annoying to write shell in travis yaml
travis:
# build check_raid.pl only on tags
# on snapshot, rename for better identifying build
set -e; \
if [ -n "$(TRAVIS_TAG)" ] && [ "$(TRAVIS_PERL_VERSION)" = "5.22" ]; then \
$(MAKE) pack; \
if [ "$(TRAVIS_TAG)" = "snapshot" ]; then \
mv $(PLUGIN_SCRIPT) $(PLUGIN)-$(PLUGIN_VERSION).pl; \
fi; \
fi
install: $(PLUGIN_SCRIPT)
install -d $(DESTDIR)$(PLUGINDIR)
install -p $(PLUGIN_SCRIPT) $(DESTDIR)$(PLUGINDIR)/$(PLUGIN)
install -d $(DESTDIR)$(PLUGINCONF)
cp -p $(PLUGIN).cfg $(DESTDIR)$(PLUGINCONF)
rpm: $(PLUGIN_SCRIPT)
# needs to be ran in git checkout for version setup to work
test -d .git
# display build system info
rpmbuild --version
lsb_release -a || cat /etc/os-release || :
rpmbuild -ba \
--define '_topdir $(CURDIR)' \
--define '_specdir %_topdir' \
--define '_sourcedir %_topdir' \
--define '_rpmdir %_topdir' \
--define '_srcrpmdir %_topdir' \
--define '_builddir %_topdir/BUILD' \
--define 'version $(RPM_VERSION)' \
--define 'release $(RPM_RELEASE)' \
$(RPM_NAME).spec
# display built rpm requires
rpm -qp --requires $(CURDIR)/$(RPM_FILENAME)