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

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

# This should be an empty directory
# This will be deleted after the package was created
export GOPATH=$(CURDIR)/tmp

PKGDIR=debian/cgrates

%:
	dh $@

clean:
	dh_clean
	go clean -modcache
	rm -rf $(GOPATH)

binary-arch: clean
	dh_prep
	dh_installdirs
	exec $(CURDIR)/build.sh
	mkdir -p $(PKGDIR)/usr/bin
	cp $(GOPATH)/bin/cgr-* $(PKGDIR)/usr/bin/
	mkdir -p $(PKGDIR)/etc/
	cp -r $(CURDIR)/data/conf/cgrates $(PKGDIR)/etc/
	mkdir -p $(PKGDIR)/etc/logrotate.d
	mkdir -p $(PKGDIR)/etc/rsyslog.d
	cp -r $(CURDIR)/data/conf/logging/deb_logrotate.conf $(PKGDIR)/etc/logrotate.d/cgrates
	cp -r $(CURDIR)/data/conf/logging/deb_rsyslog.conf $(PKGDIR)/etc/rsyslog.d/25-cgrates.conf
	mkdir -p $(PKGDIR)/usr/share/cgrates
	cp -r $(CURDIR)/data/* $(PKGDIR)/usr/share/cgrates/
	tar -xzvf $(PKGDIR)/usr/share/cgrates/tutorials/fs_evsock/freeswitch/etc/freeswitch_conf.tar.gz -C $(PKGDIR)/usr/share/cgrates/tutorials/fs_evsock/freeswitch/etc/
	rm $(PKGDIR)/usr/share/cgrates/tutorials/fs_evsock/freeswitch/etc/freeswitch_conf.tar.gz
	mkdir -p $(PKGDIR)/var/spool/cgrates/cdrc/in
	mkdir -p $(PKGDIR)/var/spool/cgrates/cdrc/out
	mkdir -p $(PKGDIR)/var/spool/cgrates/cdre/csv
	mkdir -p $(PKGDIR)/var/spool/cgrates/cdre/fwv
	mkdir -p $(PKGDIR)/var/spool/cgrates/tpe
	mkdir -p $(PKGDIR)/var/spool/cgrates/failed_posts
	mkdir -p $(PKGDIR)/var/lib/cgrates/history
	mkdir -p $(PKGDIR)/var/lib/cgrates/cache_dump
	mkdir -p $(PKGDIR)/var/log/cgrates
	dh_strip
	dh_compress
	dh_fixperms
	# dh_installinit
	dh_systemd_enable
	dh_systemd_start
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-arch
