LIBPREFIX ?= /var/lib/zetikettes
image-name = pol/zetikettes
uuid = $(shell id -u):$(shell id -g)

.PHONY: image
image:			## build the docker images
	docker compose build

.PHONY: initial-db
initial-db: image	## create and populate a database
	mkdir -p $(LIBPREFIX)/data
	docker run --rm \
		--user $(uuid) \
		-v $(LIBPREFIX)/data:/data \
		$(image-name) \
		/zetikettes/zetikettes/manage.py migrate
	docker run --rm \
		--user $(uuid) \
		-v $(LIBPREFIX)/data:/data \
		$(image-name) \
		/zetikettes/zetikettes/manage.py loaddata initial_db
	cp templates/*.svg $(LIBPREFIX)/data/

.PHONY: superuser
superuser: image	## create a superuser in the django admin
	docker run --rm \
		--user $(uuid) \
		-v $(LIBPREFIX)/data:/data \
		-it \
		$(image-name) \
		/zetikettes/zetikettes/manage.py createsuperuser

.PHONY: staticfiles
staticfiles: image	## install all static files
	cp -r frontend $(LIBPREFIX)/
	docker run --rm \
		--user $(uuid) \
		-v $(LIBPREFIX):/libdir \
		-w /libdir \
		$(image-name) \
		/zetikettes/zetikettes/manage.py collectstatic


.PHONY: help
help:           ## Show this help
	@echo Noteworthy targets:
	@egrep '^[a-zA-Z_-]+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help
