#!/usr/bin/make -f

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

%:
	dh $@

override_dh_install:
	cp scripts/apache2-httpd.include.conf debian/otrs2.conf
	dh_install
	# 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-6.0.0 \
		$(OTRS_DST)$(DB_BASE)/scripts/otrs2/upgrade/pgsql/6.0.0
	cp	debian/schemas/DBUpdate-to-6.0.1 \
		$(OTRS_DST)$(DB_BASE)/scripts/otrs2/upgrade/pgsql/6.0.1
	# 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-6.0.0 \
		$(OTRS_DST)$(DB_BASE)/scripts/otrs2/upgrade/mysql/6.0.0
	cp  debian/schemas/DBUpdate-to-6.0.1 \
		$(OTRS_DST)$(DB_BASE)/scripts/otrs2/upgrade/mysql/6.0.1
	# Remove useless stuff.
	rm -rf $(OTRS_DST)$(OTRSHOME)/scripts/auto_build
	# Remove embedded ttf-dejavu fonts.
	rm $(OTRS_DST)/var/lib/otrs/fonts/DejaVu*.ttf
	# Remove embedded fontawesome fonts.
	rm $(OTRS_DST)/var/lib/otrs/httpd/htdocs/common/fonts/fontawesome-webfont.ttf
	rm $(OTRS_DST)/var/lib/otrs/httpd/htdocs/common/fonts/FontAwesome.otf
	# Remove extra license file.
	rm $(OTRS_DST)/var/lib/otrs/httpd/htdocs/js/thirdparty/ckeditor-*/LICENSE.md
	rm $(OTRS_DST)/var/lib/otrs/httpd/htdocs/js/thirdparty/ckeditor-*/plugins/codesnippet/lib/highlight/LICENSE

override_dh_installchangelogs:
	dh_installchangelogs CHANGES.md
