#!/usr/bin/make -f

PYTHON3S:=$(shell py3versions -vr)
export PYBUILD_INSTALL_ARGS=--init-system=systemd,sysvinit_deb

%:
	dh $@ --with python3 --buildsystem pybuild

override_dh_auto_install:
	dh_auto_install
	mv $(CURDIR)/debian/cloud-init/etc/NetworkManager/dispatcher.d/hook-network-manager \
		$(CURDIR)/debian/cloud-init/etc/NetworkManager/dispatcher.d/cloud-init-hook-network-manager

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	set -e && set -x && for pyvers in $(PYTHON3S); do \
		PYMAJOR=`echo $$pyvers | cut -d'.' -f1` ; \
		echo "===> Testing with python$$pyvers (python$$PYMAJOR)" ; \
		PYTHON=python$$pyvers PYTHONPATH=. python$$pyvers -m pytest -v tests/unittests ; \
	done
endif

override_dh_installinit:
	dh_installinit --onlyscripts --no-start --no-restart-on-upgrade --name cloud-init-local
	dh_installinit --onlyscripts --no-start --no-restart-on-upgrade
	dh_installinit --onlyscripts --no-start --no-restart-on-upgrade --name cloud-config
	dh_installinit --onlyscripts --no-start --no-restart-on-upgrade --name cloud-final

override_dh_systemd_start:
	dh_systemd_start --no-restart-on-upgrade --no-start