#!/usr/bin/make -f
# debian/rules for PNP4Nagios

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk
CFLAGS += -Wextra

%:
	dh $@ --with autoreconf,autotools_dev

override_dh_auto_configure:
	dh_auto_configure -- \
		--with-layout=debian \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info 
#		--without-kohana \
#		--with-kohana_system=/usr/share/php/kohana2/system

override_dh_auto_build:
	dh_auto_build -- all
	#python -m jsmin share/pnp/media/js/jquery.imgareaselect.js \
	#              > share/pnp/media/js/jquery.imgareaselect.min.js

override_dh_auto_install:
	dh_auto_install -- install-config

	# Ignore install.php (for future debugging don't delete it)
	touch debian/tmp/usr/share/pnp4nagios/html/install.ignore

	mkdir -p debian/tmp/usr/share/doc/pnp4nagios/examples/

	# Move template config dir to /etc/pnp4nagios/templates
	rmdir debian/tmp/usr/share/pnp4nagios/html/templates
	mkdir debian/tmp/etc/pnp4nagios/templates
	mv debian/tmp/usr/share/pnp4nagios/html/templates.special \
		debian/tmp/usr/share/doc/pnp4nagios/examples/
	mkdir debian/tmp/etc/pnp4nagios/templates.special

	mkdir -p debian/tmp/usr/sbin/
	mv debian/tmp/usr/bin/npcd \
		debian/tmp/usr/sbin/

	mv debian/tmp/etc/pnp4nagios/rra.cfg-sample \
		debian/tmp/etc/pnp4nagios/rra.cfg

	mv debian/tmp/etc/pnp4nagios/nagios.cfg-sample \
		debian/tmp/usr/share/doc/pnp4nagios/examples/nagios.cfg

	mv debian/tmp/etc/pnp4nagios/misccommands.cfg-sample \
		debian/tmp/usr/share/doc/pnp4nagios/examples/misccommands.cfg

	mkdir debian/tmp/usr/share/doc/pnp4nagios/examples/check_commands
	mv debian/tmp/etc/pnp4nagios/check_commands/check_nwstat.cfg-sample \
		debian/tmp/usr/share/doc/pnp4nagios/examples/check_commands/check_nwstat.cfg

	mkdir debian/tmp/usr/share/doc/pnp4nagios/examples/pages
	mv debian/tmp/etc/pnp4nagios/pages/web_traffic.cfg-sample \
		debian/tmp/usr/share/doc/pnp4nagios/examples/pages/web_traffic.cfg

	cp -av contrib/ssi debian/tmp/usr/share/doc/pnp4nagios/examples/
	rm -fv debian/tmp/usr/share/doc/pnp4nagios/examples/ssi/*.in

	# Icinga module sample configuration
	cp debian/icinga-module.cfg debian/tmp/usr/share/doc/pnp4nagios/examples/

	# Remove external PHP classes/libraries: FPDF, FPDF-TPL, FPDI
	#rm -r debian/tmp/usr/share/pnp4nagios/html/application/vendor/fpdf

	# remove source files
	#rm -f debian/tmp/usr/share/pnp4nagios/html/media/js/jquery.imgareaselect.Debian.txt
	#rm -f debian/tmp/usr/share/pnp4nagios/html/media/js/jquery.imgareaselect.js

	# Remove external JavaScript files: jQuery and jQuery-UI
	# no longer present in DFSG tarball
	#rm debian/tmp/usr/share/pnp4nagios/html/media/js/jquery-min.js
	#rm debian/tmp/usr/share/pnp4nagios/html/media/js/jquery-ui.min.js

	# Clean up some files
	rmdir debian/tmp/usr/bin
	mv debian/tmp/etc/pnp4nagios/check_commands/check_all_local_disks.cfg-sample \
		debian/tmp/etc/pnp4nagios/check_commands/check_all_local_disks.cfg
	rm debian/tmp/etc/pnp4nagios/check_commands/check_nrpe.cfg-sample

	# Add Debian specific config and placeholder files
	#touch debian/tmp/etc/pnp4nagios/pages/.placeholder
	cp -av debian/nagios.cfg debian/tmp/etc/pnp4nagios/
	cp -av debian/check_commands/* debian/tmp/etc/pnp4nagios/check_commands/

	# Remove unnecessary config files (duplicates)
	rm -f debian/tmp/etc/pnp4nagios/config_local.php
	rm -f debian/tmp/etc/pnp4nagios/config.php.0.6*

	# Add subdirs to /var/spool/pnp4nagios/ to prepare for different modes
	mkdir debian/tmp/var/spool/pnp4nagios/nagios
	mkdir debian/tmp/var/spool/pnp4nagios/npcd

	# Delete not used and empty directories
	#rmdir debian/tmp/usr/share/pnp4nagios/html/application/logs/
	rmdir debian/tmp/usr/share/pnp4nagios/html/application/cache/
	rmdir debian/tmp/usr/share/pnp4nagios/html/application/hooks/
	#rmdir debian/tmp/usr/share/pnp4nagios/html/application/libraries/

	mkdir debian/tmp/etc/pnp4nagios/templates.d
	cp debian/README.templates.d debian/tmp/etc/pnp4nagios/templates.d/README

override_dh_installinit:
	dh_installinit -ppnp4nagios-bin --name=npcd
	dh_installinit -ppnp4nagios-bin --name=pnp_gearman_worker

# vi: noexpandtab ts=4 sw=4 :
