#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk

OTRSHOME := /usr/share/otrs
DB_BASE  := /usr/share/dbconfig-common
DB_DIR   := $(DB_BASE)/data/otrs2
OTRS_DST := $(CURDIR)/debian/otrs2/

binary-post-install/otrs2::
	# setup dbconfig-common
	# PostgreSQL
	cat scripts/database/otrs-schema.postgresql.sql \
	    scripts/database/otrs-initial_insert.postgresql.sql \
		scripts/database/otrs-schema-post.postgresql.sql > \
	    $(OTRS_DST)$(DB_DIR)/install/pgsql
	cp  debian/schemas/DBUpdate-to-3.0.postgresql.sql \
		$(OTRS_DST)$(DB_DIR)/upgrade/pgsql/3.0
	cp  debian/schemas/DBUpdate-to-3.0 \
		$(OTRS_DST)$(DB_BASE)/scripts/otrs2/upgrade/pgsql/3.0.1
	cp  scripts/DBUpdate-to-3.1.postgresql.sql \
		$(OTRS_DST)$(DB_DIR)/upgrade/pgsql/3.1
	cp  debian/schemas/DBUpdate-to-3.1 \
		$(OTRS_DST)$(DB_BASE)/scripts/otrs2/upgrade/pgsql/3.1.2+dfsg1-2.1
	cp  scripts/DBUpdate-to-3.1-post.postgresql.sql \
		$(OTRS_DST)$(DB_DIR)/upgrade/pgsql/3.1.2+dfsg1-2.2
	# MySQL
	cat scripts/database/otrs-schema.mysql.sql \
	    scripts/database/otrs-initial_insert.mysql.sql \
		scripts/database/otrs-schema-post.mysql.sql > \
	    $(OTRS_DST)$(DB_DIR)/install/mysql
	cp  debian/schemas/DBUpdate-to-3.0.mysql.sql \
		$(OTRS_DST)$(DB_DIR)/upgrade/mysql/3.0
	cp  debian/schemas/DBUpdate-to-3.0 \
		$(OTRS_DST)$(DB_BASE)/scripts/otrs2/upgrade/mysql/3.0.1
	cp  scripts/DBUpdate-to-3.1.mysql.sql \
		$(OTRS_DST)$(DB_DIR)/upgrade/mysql/3.1
	cp  debian/schemas/DBUpdate-to-3.1 \
		$(OTRS_DST)$(DB_BASE)/scripts/otrs2/upgrade/mysql/3.1.2+dfsg1-2.1
	cp  scripts/DBUpdate-to-3.1-post.mysql.sql \
		$(OTRS_DST)$(DB_DIR)/upgrade/mysql/3.1.2+dfsg1-2.2
	# I guess we do not need {redhat,suse,fedora}* stuff in Debian
	rm -f $(OTRS_DST)$(OTRSHOME)/scripts/fedora* \
	      $(OTRS_DST)$(OTRSHOME)/scripts/redhat* \
	      $(OTRS_DST)$(OTRSHOME)/scripts/rpc-example.pl \
	      $(OTRS_DST)$(OTRSHOME)/scripts/suse* \
	      $(OTRS_DST)$(OTRSHOME)/scripts/otrs*gentoo* \
	      $(OTRS_DST)$(OTRSHOME)/bin/Cron4Win32.pl
	# fix some permissions
	chmod a+x $(OTRS_DST)$(OTRSHOME)/bin/otrs.*
	chmod a+x $(OTRS_DST)$(OTRSHOME)/scripts/*.pl
	chmod a+x $(OTRS_DST)$(OTRSHOME)/bin/fcgi-bin/*.pl
	find $(OTRS_DST)/var -type f -name *.js -exec chmod a-x {} \;
	find $(OTRS_DST)/var -type f -name *.css -exec chmod a-x {} \;
	# fix a security issue, link against the system prototype.js
	rm -f $(OTRS_DST)/var/lib/otrs/httpd/htdocs/js/prototype.js
	# Remove embedded ttf-dejavu fonts.
	rm -f $(OTRS_DST)/var/lib/otrs/fonts/DejaVu*.ttf
	# Remove default shipped support module.
	rm -f $(OTRS_DST)/var/lib/otrs/packages/Support-*.opm

get-orig-source:
	-uscan --upstream-version 0
