#!/usr/bin/make -f

%:
	dh $@

override_dh_auto_clean:
	dh_auto_clean
	# These are generated during build: let's clean them.
	rm -f debian/openstack-cluster-installer.config debian/openstack-cluster-installer.postinst debian/openstack-cluster-installer.postrm debian/openstack-cluster-installer.templates
	rm -rf debian/po

override_dh_auto_build:
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func openstack-cluster-installer.config
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func openstack-cluster-installer.postinst
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_postrm openstack-cluster-installer.postrm
	pkgos-merge-templates openstack-cluster-installer openstack-cluster-installer db

	# Test all shell scripts
	set -e ; set -x ; for i in $$(ls bin/*) $$(ls poc-bin/*) $$(ls oci-agent/*) $$(ls openstack-ci/usr/bin/*) $$(ls live-image-builder/usr/bin/*) $$(ls utils/usr/bin/*) ocicli/ocicli $$(ls common/usr/bin/*) $$(ls contrib/*) etc/openstack-cluster-installer/openstack-cluster-installer.conf; do \
		sh -n $$i ; \
	done

	# Test all PHP files
	set -e ; set -x ; for i in $$(ls src/*.php) $$(ls src/inc/*.php); do \
		php -l $$i ; \
	done

.PHONY: check_puppet_syntax
check_puppet_syntax:
	# Not called during package build: there's no consistent package
	# name providing the parser across dists (eg: forky has
	# openvox-agent and no puppet package).
	set -e ; set -x ; for i in $$(ls puppet/manifests/*.pp) $$(ls puppet/manifests/sql/*.pp); do \
		puppet parser validate $$i ; \
	done

override_dh_install:
	dh_install
	install -D -m 0440 $(CURDIR)/debian/openstack-cluster-installer.sudoers $(CURDIR)/debian/openstack-cluster-installer/etc/sudoers.d/oci
	# Install variables config files
	install -D -m 0644 src/variables.json $(CURDIR)/debian/openstack-cluster-installer-cli/etc/ocicli/variables.json
	cp etc/openstack-cluster-installer/oci-repository-key.asc $(CURDIR)/debian/openstack-cluster-installer-poc/etc/oci-poc/oci-repository-key.asc

override_dh_installinit:
	dh_installinit
	dh_installinit -p openstack-cluster-installer-poc --name=oci-poc-virtual-network --no-restart-after-upgrade
	dh_installinit -p openstack-cluster-installer-poc --name=oci-poc-vms --no-restart-after-upgrade --no-start

override_dh_systemd_enable:
	dh_systemd_enable
	dh_systemd_enable -p openstack-cluster-installer-agent --name=oci-live-report-status
	dh_systemd_enable -p openstack-cluster-installer-agent --name=openstack-cluster-installer-agent
	dh_systemd_enable -p openstack-cluster-installer-agent --name=oci-live-host-keys
	dh_systemd_enable -p openstack-cluster-installer-utils --name=oci-first-boot
	dh_systemd_enable -p openstack-cluster-installer-utils --name=oci-report-status
	dh_systemd_enable -p openstack-cluster-installer-poc   --name=oci-poc-virtual-network
