#!/usr/bin/make -f

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

%:
	dh ${@}

TDIR:=debian/cacti
SHAREDIR:=${TDIR}/usr/share/cacti
SITEDIR:=${SHAREDIR}/site
RRADIR:=${TDIR}/var/lib/cacti/rra

override_dh_auto_configure:
	# make sure that we catch it when cli-include-path.patch is not up-to-date
	if grep -r -E '(include|repair).*\.\./' cli | grep -v /site/; then \
		echo " ^ fix above include paths in cli directory ^" && false; \
	fi
	# The upstream tar ball is missing one documentation file
	cp -p debian/manual.css docs/html/
	dh_auto_configure

override_dh_clean:
	# make sure that we catch translation updates
	debconf-updatepo
	${RM} -r include/js/themes
	dh_clean

override_dh_installchangelogs:
	dh_installchangelogs docs/CHANGELOG

override_dh_fixperms:
	# normalize permissions in the site directory
	find ${RRADIR} -exec chown root:www-data {} \;
	find ${SITEDIR}/ -type d -exec chmod 755 {} \;
	find ${SITEDIR}/ -type f -exec chmod 644 {} \;
	find ${SITEDIR}/scripts -type f -exec chmod 755 {} \;
	# and then fix the special case files
	find ${SITEDIR}/scripts -type f -name '*.php' -exec chmod 644 {} \;
	chmod 770 ${RRADIR}
	find ${SHAREDIR}/cli -type f -print0 | xargs -0 file | \
		grep -e /usr/bin/php -e "PHP script, ASCII text executable" | \
		cut -d: -f1 | xargs chmod 755

	dh_fixperms -X/var/lib/cacti/rra

get-orig-source:
	uscan --verbose --force-download --repack --compression xz
