#!/usr/bin/make -f

export DH_VERBOSE = 1
export DH_ALLOW_NONROOT=1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@

override_dh_auto_build:
	# No build needed for this package

clean:
	rm -rf debian/suricatavel-agent

override_dh_auto_install:
	# The code, owned by root; configuration, state, caches and logs go where bootstrap/layout.php says
	mkdir -p debian/suricatavel-agent/usr/share/suricatavel-agent/support

	# Copy application files, excluding build directories and other unnecessary files
	cp -r ../app ../bootstrap ../config ../database \
		../public ../resources ../routes ../vendor \
		../artisan ../composer.json ../composer.lock ../.env.prod \
		debian/suricatavel-agent/usr/share/suricatavel-agent
	cp layout/linux.php debian/suricatavel-agent/usr/share/suricatavel-agent/bootstrap/layout.php

	# Never ship data from the build tree
	rm -f debian/suricatavel-agent/usr/share/suricatavel-agent/database/*.sqlite*

	# Copy support files
	cp -r supervisor systemd bin \
		debian/suricatavel-agent/usr/share/suricatavel-agent/support/

	# The supervisor program is installed by postinst, only when supervisor runs the agent; the systemd unit ships
	# disabled, and postinst or Ansible enable it when systemd runs the agent
	mkdir -p debian/suricatavel-agent/usr/lib/systemd/system
	install -m 0644 systemd/suricatavel-agent.service debian/suricatavel-agent/usr/lib/systemd/system/

	# Install global CLI binary symlink
	mkdir -p debian/suricatavel-agent/usr/bin
	ln -sf /usr/share/suricatavel-agent/support/bin/suricatavel-agent debian/suricatavel-agent/usr/bin/suricatavel-agent

override_dh_usrlocal:
	# Do nothing, prevent dh_usrlocal from failing

override_dh_auto_test:
	@:

override_dh_auto_clean:
	@: