#!/usr/bin/make -f
# debian/rules for linux-patch-api

export DEB_CARGO_PACKAGE=linux-patch-api
export DEB_CARGO_BUILD_FLAGS=--release

%:
	dh $@

override_dh_auto_build:
	cargo build --release --target x86_64-unknown-linux-gnu

override_dh_auto_install:
	dh_auto_install
	# Create installation directories in debian/tmp
	mkdir -p debian/tmp/usr/bin
	mkdir -p debian/tmp/etc/linux_patch_api
	mkdir -p debian/tmp/lib/systemd/system
	mkdir -p debian/tmp/var/log/linux_patch_api
	mkdir -p debian/tmp/var/lib/linux_patch_api
	# Install binary
	cp target/x86_64-unknown-linux-gnu/release/linux-patch-api debian/tmp/usr/bin/
	chmod 755 debian/tmp/usr/bin/linux-patch-api
	# Install systemd service
	cp configs/linux-patch-api.service debian/tmp/lib/systemd/system/
	chmod 644 debian/tmp/lib/systemd/system/linux-patch-api.service
	# Install configs (as actual configs for first install)
	cp configs/config.yaml.example debian/tmp/etc/linux_patch_api/config.yaml
	cp configs/whitelist.yaml.example debian/tmp/etc/linux_patch_api/whitelist.yaml
	chmod 644 debian/tmp/etc/linux_patch_api/*.yaml

