.PHONY: all install uninstall

# Load retention configuration (KEEP_FREQUENT, KEEP_HOURLY, KEEP_DAILY, KEEP_WEEKLY, KEEP_MONTHLY)
include zfs-auto-snapshot.conf

all:

# Install or update cron files with configured retention values
install:
	install -d /etc/cron.d
	install -d /etc/cron.daily
	install -d /etc/cron.hourly
	install -d /etc/cron.weekly
	install -d /etc/cron.monthly
	sed 's/@KEEP_FREQUENT@/$(KEEP_FREQUENT)/g' etc/zfs-auto-snapshot.cron.frequent > /etc/cron.d/zfs-auto-snapshot
	chmod 0644 /etc/cron.d/zfs-auto-snapshot
	sed 's/@KEEP_HOURLY@/$(KEEP_HOURLY)/g' etc/zfs-auto-snapshot.cron.hourly > /etc/cron.hourly/zfs-auto-snapshot
	chmod 0755 /etc/cron.hourly/zfs-auto-snapshot
	sed 's/@KEEP_DAILY@/$(KEEP_DAILY)/g' etc/zfs-auto-snapshot.cron.daily > /etc/cron.daily/zfs-auto-snapshot
	chmod 0755 /etc/cron.daily/zfs-auto-snapshot
	sed 's/@KEEP_WEEKLY@/$(KEEP_WEEKLY)/g' etc/zfs-auto-snapshot.cron.weekly > /etc/cron.weekly/zfs-auto-snapshot
	chmod 0755 /etc/cron.weekly/zfs-auto-snapshot
	sed 's/@KEEP_MONTHLY@/$(KEEP_MONTHLY)/g' etc/zfs-auto-snapshot.cron.monthly > /etc/cron.monthly/zfs-auto-snapshot
	chmod 0755 /etc/cron.monthly/zfs-auto-snapshot
	install -d /usr/local/sbin
	install -m 0755 src/zfs-auto-snapshot.sh /usr/local/sbin/zfs-auto-snapshot

uninstall:
	rm -f /etc/cron.d/zfs-auto-snapshot
	rm -f /etc/cron.hourly/zfs-auto-snapshot
	rm -f /etc/cron.daily/zfs-auto-snapshot
	rm -f /etc/cron.weekly/zfs-auto-snapshot
	rm -f /etc/cron.monthly/zfs-auto-snapshot
	rm -f /usr/local/sbin/zfs-auto-snapshot



