#!/usr/bin/make -f
# -*- makefile -*-

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

TMPSERVERDIR=$(CURDIR)/debian/ocsinventory-server
TMPREPORTDIR=$(CURDIR)/debian/ocsinventory-reports
LOGPATH=$(TMPREPORTDIR)/var/log/ocsinventory-reports

%:
	dh $@ --sourcedirectory=Apache --with=apache2

override_dh_clean:
	dh_clean -X main_menu.xml.bak

override_dh_install:
	dh_install -XChanges -XLICENSE.md -XLICENCE
	# Remove a few empty dirs generated by dh_install:
	# Don't remove plugins/main_sections/conf/old_conf/
	rm -vf $(TMPREPORTDIR)/usr/share/ocsinventory-reports/LICENSE

override_dh_installchangelogs:
	dh_installchangelogs -p ocsinventory-reports ocsreports/Changes
	dh_installchangelogs -p ocsinventory-server Apache/Changes

override_dh_fixperms:
	dh_fixperms
	# fix permissions for scripts and images
	find $(TMPREPORTDIR)/usr/share/ocsinventory-reports -type f -exec chmod a-x {} \;
	# fix the permissions for the .pl scripts
	find $(TMPSERVERDIR)/usr/share/ocsinventory-server -name '*.pl' -exec chmod +x {} \;
	find $(TMPREPORTDIR)/usr/share/ocsinventory-reports -name '*.pl' -exec chmod +x {} \;
	chmod -x $(TMPSERVERDIR)/usr/share/ocsinventory-server/binutils/ocs-errors
	chmod -R g-w $(LOGPATH)
	for dirname in logs scripts; do \
		chown -R www-data:www-data $(LOGPATH)/$$dirname; \
	done
	#chown -R www-data:www-data $(TMPREPORTDIR)/usr/share/ocsinventory-reports
	chown -R www-data:adm $(TMPSERVERDIR)/var/log/ocsinventory-server
