| 1 |
PLUGIN=check_ssl_cert |
| 2 |
VERSION=`cat VERSION` |
| 3 |
DIST_DIR=$(PLUGIN)-$(VERSION) |
| 4 |
|
| 5 |
# files to be included in the distribution |
| 6 |
DIST_FILES=AUTHORS.md COPYING.md ChangeLog INSTALL.md Makefile GNUmakefile NEWS.md README.md VERSION $(PLUGIN) $(PLUGIN).spec COPYRIGHT.md ${PLUGIN}.1 CITATION.cff check_ssl_cert.completion check_ssl_cert_icinga2.conf |
| 7 |
|
| 8 |
# this year |
| 9 |
YEAR=`date +"%Y"` |
| 10 |
|
| 11 |
# file to be checked for formatting |
| 12 |
FORMATTED_FILES=test/unit_tests.sh test/integration_tests.sh test/badssl_tests.sh ChangeLog INSTALL.md Makefile VERSION $(PLUGIN) $(PLUGIN).spec COPYRIGHT.md ${PLUGIN}.1 .github/workflows/* utils/*.sh check_ssl_cert.completion |
| 13 |
|
| 14 |
# shell scripts (to be checked with ShellCheck) |
| 15 |
SCRIPTS=check_ssl_cert test/*.sh utils/*.sh |
| 16 |
|
| 17 |
XATTRS_OPTION := $(shell if tar --help 2>&1 | grep -q bsdtar ; then echo '--no-xattrs' ; fi ) |
| 18 |
|
| 19 |
.PHONY: install clean test rpm distclean check version_check codespell integration_tests unit_tests integration_tests_with_proxy unit_tests_with_proxy |
| 20 |
|
| 21 |
all: dist |
| 22 |
|
| 23 |
# checks if the version is updated in all the files |
| 24 |
version_check: CITATION.cff |
| 25 |
@echo "Checking version $(VERSION)" |
| 26 |
grep -q "VERSION *= *[\'\"]*$(VERSION)" $(PLUGIN) |
| 27 |
grep -q "^%global version *$(VERSION)" $(PLUGIN).spec |
| 28 |
grep -q -F -- "- $(VERSION)-" $(PLUGIN).spec |
| 29 |
grep -q "\"$(VERSION)\"" $(PLUGIN).1 |
| 30 |
grep -q -F "${VERSION}" NEWS.md |
| 31 |
grep -q "^version: ${VERSION}" CITATION.cff |
| 32 |
@echo "Version check: OK" |
| 33 |
|
| 34 |
# builds the release files |
| 35 |
dist: version_check CITATION.cff |
| 36 |
rm -rf $(DIST_DIR) $(DIST_DIR).tar.gz |
| 37 |
mkdir $(DIST_DIR) |
| 38 |
cp -r $(DIST_FILES) $(DIST_DIR) |
| 39 |
# avoid to include extended attribute data files |
| 40 |
# see https://superuser.com/questions/259703/get-mac-tar-to-stop-putting-filenames-in-tar-archives |
| 41 |
export COPY_EXTENDED_ATTRIBUTES_DISABLE=true; \ |
| 42 |
export COPYFILE_DISABLE=true; \ |
| 43 |
tar $(XATTRS_OPTION) -c -z -f $(DIST_DIR).tar.gz $(DIST_DIR) && \ |
| 44 |
tar $(XATTRS_OPTION) -c -j -f $(DIST_DIR).tar.bz2 $(DIST_DIR) |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
install: |
| 49 |
ifndef DESTDIR |
| 50 |
@echo "Please define DESTDIR and MANDIR variables with the installation targets" |
| 51 |
@echo "e.g, make DESTDIR=/nagios/plugins/dir MANDIR=/nagios/plugins/man/dir install" |
| 52 |
@echo |
| 53 |
@echo "If you are using 'sudo' please specify the '-E, --preserve-env' option" |
| 54 |
else |
| 55 |
mkdir -p $(DESTDIR) |
| 56 |
install -m 755 $(PLUGIN) $(DESTDIR) |
| 57 |
mkdir -p ${MANDIR}/man1 |
| 58 |
install -m 644 ${PLUGIN}.1 ${MANDIR}/man1/ |
| 59 |
endif |
| 60 |
ifdef COMPLETIONDIR |
| 61 |
mkdir -p $(COMPLETIONDIR) |
| 62 |
install -m 644 check_ssl_cert.completion $(COMPLETIONDIR)/check_ssl_cert |
| 63 |
endif |
| 64 |
|
| 65 |
COMPLETIONS_DIR := $(shell pkg-config --variable=completionsdir bash-completion) |
| 66 |
install_bash_completion: |
| 67 |
ifdef COMPLETIONS_DIR |
| 68 |
cp check_ssl_cert.completion $(COMPLETIONS_DIR)/check_ssl_cert |
| 69 |
endif |
| 70 |
|
| 71 |
CITATION.cff: AUTHORS.md VERSION NEWS.md |
| 72 |
./utils/update_citation.sh |
| 73 |
|
| 74 |
# we check for tabs |
| 75 |
# and remove trailing blanks |
| 76 |
formatting_check: |
| 77 |
! grep -q '[[:blank:]]$$' $(FORMATTED_FILES) |
| 78 |
|
| 79 |
CODESPELL := $(shell command -v codespell 2> /dev/null ) |
| 80 |
# spell check |
| 81 |
codespell: |
| 82 |
ifndef CODESPELL |
| 83 |
@echo "no codespell installed" |
| 84 |
else |
| 85 |
codespell \ |
| 86 |
. |
| 87 |
endif |
| 88 |
|
| 89 |
SHFMT := $(shell command -v shfmt 2> /dev/null) |
| 90 |
format: |
| 91 |
ifndef SHFMT |
| 92 |
@echo "No shfmt installed" |
| 93 |
else |
| 94 |
# -p POSIX |
| 95 |
# -w write to file |
| 96 |
# -s simplify |
| 97 |
# -i 4 indent with 4 spaces |
| 98 |
shfmt -p -w -s -i 4 $(SCRIPTS) |
| 99 |
shfmt -ln bash -w -s -i 4 check_ssl_cert.completion |
| 100 |
endif |
| 101 |
|
| 102 |
clean: |
| 103 |
find . -name "*~" -delete |
| 104 |
find . -name "*.bak" -delete |
| 105 |
find . -name "#*#" -delete |
| 106 |
rm -rf rpmroot |
| 107 |
|
| 108 |
distclean: clean |
| 109 |
rm -rf check_ssl_cert-[0-9]* |
| 110 |
rm -f *.crt |
| 111 |
rm -f *.error |
| 112 |
rm -f headers.txt |
| 113 |
|
| 114 |
check: test |
| 115 |
|
| 116 |
SHELLCHECK := $(shell command -v shellcheck 2> /dev/null) |
| 117 |
SHUNIT := $(shell if [ -z "${SHUNIT2}" ] ; then command -v shunit2 2> /dev/null || if [ -x /usr/share/shunit2/shunit2 ] ; then echo /usr/share/shunit2/shunit2 ; fi; else echo "${SHUNIT2}"; fi ) |
| 118 |
|
| 119 |
distcheck: disttest |
| 120 |
disttest: dist formatting_check shellcheck codespell |
| 121 |
./utils/check_documentation.sh |
| 122 |
man ./check_ssl_cert.1 > /dev/null |
| 123 |
|
| 124 |
test: formatting_check shellcheck unit_tests integration_tests badssl_tests badssl_tests_with_proxy unit_tests_with_proxy integration_tests_with_proxy |
| 125 |
|
| 126 |
unit_tests: |
| 127 |
ifndef SHUNIT |
| 128 |
@echo "No shUnit2 installed: see README.md" |
| 129 |
exit 1 |
| 130 |
else |
| 131 |
( export SHUNIT2=$(SHUNIT) && export LC_ALL=C && cd test && ./unit_tests.sh ) |
| 132 |
endif |
| 133 |
|
| 134 |
unit_tests_with_proxy: |
| 135 |
ifndef SHUNIT |
| 136 |
@echo "No shUnit2 installed: see README.md" |
| 137 |
exit 1 |
| 138 |
else |
| 139 |
./utils/start_proxy.sh ./test/tinyproxy.conf |
| 140 |
( export SHUNIT2=$(SHUNIT) && export http_proxy=127.0.0.1:8888 && export LC_ALL=C && cd test && ./unit_tests.sh ) |
| 141 |
killall tinyproxy |
| 142 |
sleep 1 |
| 143 |
endif |
| 144 |
|
| 145 |
integration_tests: |
| 146 |
ifndef SHUNIT |
| 147 |
@echo "No shUnit2 installed: see README.md" |
| 148 |
exit 1 |
| 149 |
else |
| 150 |
( export SHUNIT2=$(SHUNIT) && export LC_ALL=C && cd test && ./integration_tests.sh ) |
| 151 |
endif |
| 152 |
|
| 153 |
integration_tests_with_proxy: |
| 154 |
ifndef SHUNIT |
| 155 |
@echo "No shUnit2 installed: see README.md" |
| 156 |
exit 1 |
| 157 |
else |
| 158 |
./utils/start_proxy.sh ./test/tinyproxy.conf |
| 159 |
( export SHUNIT2=$(SHUNIT) && export http_proxy=127.0.0.1:8888 && export LC_ALL=C && cd test && ./integration_tests.sh ) |
| 160 |
killall tinyproxy |
| 161 |
sleep 1 |
| 162 |
endif |
| 163 |
|
| 164 |
badssl_tests: |
| 165 |
ifndef SHUNIT |
| 166 |
@echo "No shUnit2 installed: see README.md" |
| 167 |
exit 1 |
| 168 |
else |
| 169 |
( export SHUNIT2=$(SHUNIT) && export LC_ALL=C && cd test && ./badssl_tests.sh ) |
| 170 |
endif |
| 171 |
|
| 172 |
badssl_tests_with_proxy: |
| 173 |
ifndef SHUNIT |
| 174 |
@echo "No shUnit2 installed: see README.md" |
| 175 |
exit 1 |
| 176 |
else |
| 177 |
./utils/start_proxy.sh ./test/tinyproxy.conf |
| 178 |
( export SHUNIT2=$(SHUNIT) && export http_proxy=127.0.0.1:8888 && export LC_ALL=C && cd test && ./badssl_tests.sh ) |
| 179 |
killall tinyproxy |
| 180 |
sleep 1 |
| 181 |
endif |
| 182 |
|
| 183 |
shellcheck: |
| 184 |
ifndef SHELLCHECK |
| 185 |
@echo "No shellcheck installed: skipping check" |
| 186 |
else |
| 187 |
if shellcheck --help 2>&1 | grep -q -- '-o ' ; then shellcheck -o all $(SCRIPTS) ; else shellcheck $(SCRIPTS) ; fi |
| 188 |
endif |
| 189 |
|
| 190 |
rpm: dist |
| 191 |
mkdir -p rpmroot/SOURCES rpmroot/BUILD |
| 192 |
cp $(DIST_DIR).tar.gz rpmroot/SOURCES |
| 193 |
rpmbuild --define "_topdir `pwd`/rpmroot" -ba check_ssl_cert.spec |