#!/usr/bin/make -f
export DH_VERBOSE=1

pkg_name := php-session-cleaner
logrotate_dir := /etc/logrotate.d
cron_dir := /etc/cron.d
script_dir := /usr/bin
logrotate_name := $(logrotate_dir)/$(pkg_name)
conf_d_dir := /etc/php-cleaner/php-cleaner.d

buildroot := $(CURDIR)/debian/tmp

%:
	dh $@

override_dh_auto_build:

override_dh_auto_install:
	install -d $(buildroot)$(logrotate_dir)
	install -d $(buildroot)$(cron_dir)
	install -d $(buildroot)$(script_dir)
	install -d $(buildroot)$(conf_d_dir)

	echo "/var/log/$(pkg_name).log {" >> $(buildroot)$(logrotate_name)
	echo "    rotate 7" >> $(buildroot)$(logrotate_name)
	echo "    daily" >> $(buildroot)$(logrotate_name)
	echo "    missingok" >> $(buildroot)$(logrotate_name)
	echo "    notifempty" >> $(buildroot)$(logrotate_name)
	echo "    sharedscripts" >> $(buildroot)$(logrotate_name)
	echo "    copytruncate" >> $(buildroot)$(logrotate_name)
	echo "    compress" >> $(buildroot)$(logrotate_name)
	echo "}" >> $(buildroot)$(logrotate_name)

	echo "PATH=/sbin:/bin:/usr/sbin:/usr/bin" > $(buildroot)$(cron_dir)/$(pkg_name)
	echo "0 1 * * * root $(script_dir)/$(pkg_name).sh" >> $(buildroot)$(cron_dir)/$(pkg_name)

	echo "PHP_EXECUTABLE=/opt/alt/php*/usr/bin/php" >> $(buildroot)$(conf_d_dir)/alt-php.conf

	install $(pkg_name).sh $(buildroot)$(script_dir)/$(pkg_name).sh

	dh_movefiles -p $(pkg_name) \
		.$(script_dir)/$(pkg_name).sh \
		.$(logrotate_dir)/$(pkg_name) \
		.$(cron_dir)/$(pkg_name) \
		.$($(conf_d_dir)/alt-php.conf)

override_dh_auto_clean:
