#!/usr/bin/make -f
# -*- makefile -*-
include /usr/share/cdbs/1/rules/debhelper.mk

SHELL := /bin/bash
BUILD_ROOT=$(CURDIR)/debian/$(cdbs_curpkg)
export rubylibdir=/opt/puppetlabs/puppet/lib/ruby/vendor_ruby
DIST := $(shell lsb_release -i | awk '{print tolower($$3)}')
RELEASE := $(shell lsb_release -r | awk '{print $$2}')
CODENAME := $(shell lsb_release -c | sed -n 's/^Codename:\s*\(.*\)$$/\1/p')
SYSV_CODENAMES := squeeze wheezy lucid precise trusty jessie
export DESTDIR=$(BUILD_ROOT)
export prefix=/opt/puppetlabs/server/apps/puppetdb
export bindir=/opt/puppetlabs/server/apps/puppetdb/bin
export confdir=/etc
export datadir=/opt/puppetlabs/server/data/puppetdb
export realname=puppetdb
export EZ_VERBOSE=1

install/puppetdb::
	bash install.sh install_deb
	if [[ ${DIST} == debian ]] ; then \
		if [[ $$(echo "${RELEASE}>=7" | bc -l) -eq 1 || ${RELEASE} == testing || ${RELEASE} == unstable ]] ; then \
			bash install.sh logrotate ; \
		else \
			bash install.sh logrotate_legacy ; \
		fi ; \
	elif [[ ${DIST} == ubuntu ]] ; then \
		if [[ $$(echo "${RELEASE}>=13.04" | bc -l) -eq 1 ]] ; then \
			bash install.sh logrotate ; \
		else \
			bash install.sh logrotate_legacy ; \
		fi ; \
	fi
	if $$(echo "${SYSV_CODENAMES}" | grep -q ${CODENAME}) ; then \
		bash install.sh sysv_init_deb ; \
	else \
		bash install.sh systemd_deb ; \
	fi

install/puppetdb-termini::
	bash install.sh termini
