#!/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 utils/usr/bin/*) ocicli/ocicli $((ls common/usr/bin/*) $((ls contrib/*) etc/openstack-cluster-installer/openstack-cluster-installer.conf; do \
		sh -n $$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

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
