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

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

include /usr/share/dpkg/pkg-info.mk
$(info I: DEB_SOURCE=$(DEB_SOURCE))
$(info I: DEB_VERSION_UPSTREAM=$(DEB_VERSION_UPSTREAM))

%:
	dh $@

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	#find . -maxdepth 1 -type f -name "*.crt" -exec openssl verify "{}" \;
	certtool --verify --load-ca-certificate root_X0F.crt --infile class3_X0E.crt
	certtool --verify --load-ca-certificate root_X0F.crt --infile root_X0F.crt
endif

.PHONY: get-orig-source
get-orig-source: $(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM).orig.tar.xz
	@

$(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM).orig.tar.xz:
	mkdir $(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM)
	@echo "# Downloading..."
	cd $(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM) && wget --continue --timestamp --no-check-certificate https://www.cacert.org/certs/root_X0F.crt
	cd $(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM) && wget --continue --timestamp --no-check-certificate https://www.cacert.org/certs/class3_X0E.crt
	find -L "$(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM)" -xdev -type f -print | LC_ALL=C sort \
        | XZ_OPT="-6v" tar -caf $(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM).orig.tar.xz -T- --owner=root --group=root --mode=a+rX
	$(RM) -r $(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM)
