PREFIX        ?= /usr/local
BINDIR        := $(PREFIX)/bin
SYSTEMDDIR    := /etc/systemd/system
CONFDIR       := /etc
LOGDIR        := /var/log/enodia-sentinel

.PHONY: install uninstall enable disable status logs check baseline drill clean

install:
	install -Dm755 src/sentinel.sh      $(DESTDIR)$(BINDIR)/sentinel.sh
	install -Dm755 src/sentinel-redteam $(DESTDIR)$(BINDIR)/sentinel-redteam
	install -Dm644 systemd/enodia-sentinel.service $(DESTDIR)$(SYSTEMDDIR)/enodia-sentinel.service
	@if [ ! -e "$(DESTDIR)$(CONFDIR)/enodia-sentinel.conf" ]; then \
		install -Dm644 config/enodia-sentinel.conf $(DESTDIR)$(CONFDIR)/enodia-sentinel.conf; \
		echo "Installed default config at $(CONFDIR)/enodia-sentinel.conf"; \
	else \
		install -Dm644 config/enodia-sentinel.conf $(DESTDIR)$(CONFDIR)/enodia-sentinel.conf.new; \
		echo "Existing config preserved; new template at $(CONFDIR)/enodia-sentinel.conf.new"; \
	fi
	install -dm750 $(DESTDIR)$(LOGDIR)
	@echo "Installed. Run 'sudo make enable' to start the service."

uninstall:
	rm -f $(DESTDIR)$(BINDIR)/sentinel.sh
	rm -f $(DESTDIR)$(BINDIR)/sentinel-redteam
	rm -f $(DESTDIR)$(SYSTEMDDIR)/enodia-sentinel.service
	rm -f $(DESTDIR)$(CONFDIR)/enodia-sentinel.conf.new
	@echo "Uninstalled. Config and logs preserved."

enable:
	systemctl daemon-reload
	systemctl enable --now enodia-sentinel.service

disable:
	systemctl disable --now enodia-sentinel.service

status:
	systemctl status enodia-sentinel.service --no-pager

logs:
	journalctl -u enodia-sentinel.service -f

check:
	sentinel.sh --check

baseline:
	sentinel.sh --baseline

drill:
	sentinel-redteam

clean:
	@echo "Nothing to clean (no build artifacts)."
