#!/usr/bin/make -f

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

%:
	dh  $@

override_dh_install:
	dh_install

override_dh_fixperms:
	dh_fixperms

# Stuff for get-orig-source.
upstream_version := $(shell dpkg-parsechangelog | sed -ne 's/^Version: \(.*\)-.*/\1/p')
isodate := $(shell dpkg-parsechangelog | sed -ne 's/^Version.*git\(.*\)-.*/\1/p')
unixdate := $(shell date -d $(isodate) +%s)
# Add 24 hours to the Unix time.
unixdate := $(shell expr $(unixdate) + 86400 )

get-orig-source:
	# Cleaning
	rm -rf mcollective-plugins-$(upstream_version)
	rm -f ../mcollective-plugins_$(upstream_version).orig.tar.gz

	# Download the latest GIT version and downgrade it to $(isodate).
	git clone https://github.com/puppetlabs/mcollective-plugins.git mcollective-plugins-$(upstream_version)

#	cd mcollective-plugins-$(upstream_version) && git reset --hard $(shell cd mcollective-plugins-$(upstream_version) && git rev-list --all -n 1 --before=$(unixdate))
#unixdate = 1231196400
#hash of GIT commit = 1d3f869e61dc5139d16596075a9e2c4e9a2f503f
# Ugly hack with "xargs" that works.
	cd mcollective-plugins-$(upstream_version) && echo `git rev-list --all -n 1 --before=$(unixdate)` | xargs git reset --hard

	# Make a pristine package.
# --no-name/-n is important because it won't save the timestamp in the
# 5th to 8th byte of the gzip.
	cd mcollective-plugins-$(upstream_version) && git archive --format=tar --prefix=mcollective-plugins-$(upstream_version)/ master | gzip -9 --no-name > ../mcollective-plugins_$(upstream_version).orig.tar.gz

	# Clean again, because we use svn-buildpackage afterwards.
	rm -rf mcollective-plugins-$(upstream_version)
