add: ACME domain, .env generator; minor code refactoring
This commit is contained in:
92
Makefile
92
Makefile
@@ -1,35 +1,35 @@
|
||||
# app custom Makefile
|
||||
|
||||
SHELL = /bin/sh
|
||||
CFG =.env
|
||||
CFG = .env
|
||||
|
||||
SOURCES ?= $(wildcard *.sql)
|
||||
OBJECTS = $(SOURCES:.sql=.done)
|
||||
OBJECTSDIRECT = $(SOURCES:.sql=.direct)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# шаблон файла .env
|
||||
# app custom config
|
||||
# comments prefixed with '#- ' will be copied to $(CFG).sample
|
||||
|
||||
define CONFIG_DEF
|
||||
# dcape-dns config file, generated by make $(CFG)
|
||||
#- Postgresql container name (access via docker)
|
||||
PG_CONTAINER ?= dcape_db_1
|
||||
|
||||
# Postgresql container name (access via docker)
|
||||
PG_CONTAINER=dcape_db_1
|
||||
#- PowerDNS DB user name
|
||||
PGUSER ?= pdns
|
||||
|
||||
# PowerDNS DB user name
|
||||
PGUSER=pdns
|
||||
#- PowerDNS DB name
|
||||
PGDATABASE ?= pdns
|
||||
|
||||
# PowerDNS DB name
|
||||
PGDATABASE=pdns
|
||||
#- Used ONLY for direct DB access without docker (update-direct)
|
||||
PGPASSWORD ?=
|
||||
|
||||
# Used ONLY for direct DB access without docker (start-direct)
|
||||
PGPASSWORD=
|
||||
|
||||
endef
|
||||
export CONFIG_DEF
|
||||
|
||||
all: help
|
||||
#- ACME zone suffix
|
||||
ACME_DOMAIN ?=
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
all: help
|
||||
|
||||
-include $(CFG)
|
||||
export
|
||||
|
||||
@@ -38,41 +38,69 @@ export
|
||||
|
||||
start-hook: update
|
||||
|
||||
start-direct: update-direct
|
||||
|
||||
stop:
|
||||
|
||||
$(CFG): $(CFG).sample
|
||||
@[ -f $@ ] || cp $< $@
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
## Usage
|
||||
#:
|
||||
|
||||
## Load updated zone files via running PG container
|
||||
update: $(OBJECTS)
|
||||
|
||||
%.done: %.sql
|
||||
@echo "*** $< ***"
|
||||
@csum=$$(md5sum $< | sed 's/ .*//') ; \
|
||||
cat $< | docker exec -i $$PG_CONTAINER psql -U $$PGUSER -d $$PGDATABASE -vcsum=$$csum > $@
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
cat $< | docker exec -i $$PG_CONTAINER psql -U $$PGUSER -d $$PGDATABASE -vcsum=$$csum -vACME_DOMAIN=$(ACME_DOMAIN) > $@
|
||||
|
||||
## Load updated zone files via psql connection
|
||||
update-direct: $(CFG) $(OBJECTSDIRECT)
|
||||
|
||||
%.direct: %.sql
|
||||
@echo "*** $< ***"
|
||||
@source $(CFG) && cat $< | PGPASSWORD=$$PGPASSWORD psql -h localhost -U $$PGUSER > $@
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
## Run psql via running PG container
|
||||
psql:
|
||||
@docker exec -it $$PG_CONTAINER psql -U $$PGUSER $$PGDATABASE
|
||||
|
||||
clean:
|
||||
rm -rf *.done
|
||||
# ------------------------------------------------------------------------------
|
||||
## Other
|
||||
#:
|
||||
|
||||
$(CFG).sample:
|
||||
@echo "*** $@ ***"
|
||||
@[ -f $@ ] || echo "$$CONFIG_DEF" > $@
|
||||
# This code generates $(CFG).sample from Makefile vars with previous comment line(s)
|
||||
# See https://gist.github.com/LeKovr/2697fe02504d7c081b0bf79427c93db6
|
||||
|
||||
# Internal: generate config sample data
|
||||
.env.temp.mk:
|
||||
@echo "define CFVAR" > $@
|
||||
@grep -A 1 -h "^#- " $(MAKEFILE_LIST) | grep -vE "^--" \
|
||||
| sed -E 's/^([^\n ]+)\ *\??=([^\n]*)$$/\1=$$(\1)\n/ ; s/^(#)-/\1/' >> $@
|
||||
@echo "endef" >> $@
|
||||
|
||||
ifneq ($(findstring $(MAKECMDGOALS),config $(CFG).sample),)
|
||||
include .env.temp.mk
|
||||
endif
|
||||
|
||||
# Internal: generate config sample
|
||||
$(CFG).sample: .env.temp.mk
|
||||
@echo "# dcape-dns config file, generated by 'make config'\n" > $@
|
||||
@echo "$$CFVAR" >> $@
|
||||
@rm -f $<
|
||||
|
||||
## generate sample config
|
||||
config: $(CFG).sample
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
## Remove .done files
|
||||
clean:
|
||||
rm -rf *.done
|
||||
|
||||
# This code handles group header and target comment with one or two lines only
|
||||
## list Makefile targets
|
||||
## (this is default target)
|
||||
help:
|
||||
@grep -A 1 -h "^## " $(MAKEFILE_LIST) \
|
||||
| sed -E 's/^--$$// ; /./{H;$$!d} ; x ; s/^\n## ([^\n]+)\n(## (.+)\n)*(.+):(.*)$$/" " "\4" "\1" "\3"/' \
|
||||
| sed -E 's/^" " "#" "(.+)" "(.*)"$$/"" "" "" ""\n"\1 \2" "" "" ""/' \
|
||||
| xargs printf "%s\033[36m%-15s\033[0m %s %s\n"
|
||||
|
||||
Reference in New Issue
Block a user