DESTDIR ?= ./debian/DEBIAN
PACKAGE ?= trutzbox-master-scripts-backuprestore
CONFDIR ?= $(DESTDIR)/etc/comidio/$(PACKAGE)
FILEDIR ?= $(DESTDIR)/usr/lib/comidio/trutzbox


.PHONY: clean
clean:
	if [ -d $(FILEDIR) ]; then rm -r $(FILEDIR); fi
	if [ -d $(CONFDIR) ]; then rm -r $(CONFDIR); fi
	if [ -d $(DESTDIR) ]; then rm -r $(DESTDIR); fi

.PHONY: install
install:
	@echo Installing to $(DESTDIR)
	mkdir -p $(CONFDIR)
	cp -r etc/comidio/$(PACKAGE)/* $(CONFDIR)/
	mkdir -p $(FILEDIR)
	cp -r backend $(FILEDIR)/
	cp -r firmwareinstallation $(FILEDIR)/
	cp -r system-update $(FILEDIR)/
	find $(DESTDIR)/ -type f | grep .git | xargs -I {} rm -f {}
	find $(DESTDIR)/ -type d | xargs -I {} chmod 755 {}
	find $(FILEDIR)/ -type f | xargs -I {} chmod 600 {}
	find $(FILEDIR)/ -type f | egrep -v '(.fstab$$|README|.conf$$|COPYING)' | xargs -I {} chmod 750 {}
