NRPE_DIR=$(DESTDIR)/etc/nagios/nrpe.d
SUDOERS_DIR=$(DESTDIR)/etc/sudoers.d
CRON_DAILY_DIR=$(DESTDIR)/etc/cron.daily
CRON_D_DIR=$(DESTDIR)/etc/cron.d
PLUGINS_DIR=$(DESTDIR)/usr/lib/nagios/plugins

all:
	@echo 'use "make install" to install, or "make deb" to build debian package'

update:
	wget -qN https://github.com/githubDante/ethMon/raw/master/ethMon -O ethMon
	
install:
	test -d $(NRPE_DIR) || mkdir -p $(NRPE_DIR)
	for f in nrpe-tomsoft*.cfg; do install -o root -g root -m 0644 $$f $(NRPE_DIR)/$$f; done
	test -d $(SUDOERS_DIR) || mkdir -p $(SUDOERS_DIR)
	for f in check_raid_common; do install -o root -g root -m 0440 $$f $(SUDOERS_DIR)/$$f; done
	test -d $(CRON_DAILY_DIR) || mkdir -p $(CRON_DAILY_DIR)
	for f in apt-uu-state; do install -o root -g root -m 0755 $$f $(CRON_DAILY_DIR)/$$f; done
	test -d $(CRON_D_DIR) || mkdir -p $(CRON_D_DIR)
	for f in reboot-apt-uu-state; do install -o root -g root -m 0644 $$f $(CRON_D_DIR)/$$f; done
	test -d $(PLUGINS_DIR) || mkdir -p $(PLUGINS_DIR)
	for f in check_tomsoft_version ethMon check_cpu_virtualization; do install -o root -g root -m 0755 $$f $(PLUGINS_DIR)/$$f; done

clean:
	find . -name "*~" -print0 | xargs -0r rm -f --

mrproper: clean
	dh clean
	rm -f ethMon

deb: update
	debuild --lintian-opts -i

checkdeb:
	cd .. && lintian --info `ls -1t *deb | head -n 1`
	
publish: deb checkdeb
	reprepro include wheezy `ls -t1 ../*.changes | head -n1`
	git commit -a

.PHONY: all update install clean mrproper deb checkdeb publish
