dags/pikvm/acme_rsync/Makefile

68 lines
1.7 KiB
Makefile
Raw Normal View History

2022-10-18 17:01:08 +02:00
# because we are using pikvm here and making use of its persistent storage,
# remember to run it as `kvmd-pstrun make`
# https://docs.pikvm.org/pst/
2022-09-16 17:26:21 +02:00
2022-10-18 17:01:08 +02:00
ifdef KVMD_PST_DATA # should be set to `/var/lib/kvmd/pst/data`
DATA_DIR := $(KVMD_PST_DATA)
else
DATA_DIR := /tmp
endif
2022-09-16 16:20:06 +02:00
2022-10-18 17:01:08 +02:00
WD=$(DATA_DIR)/dags/acme_rsync
2022-09-16 17:26:21 +02:00
2022-09-16 16:20:06 +02:00
.PHONY: all sync_certs
2022-10-18 17:01:08 +02:00
NGINX_RELOAD=$(WD)/nginx_reload
2022-09-16 17:26:21 +02:00
2022-10-18 17:01:08 +02:00
all: sync_certs $(NGINX_RELOAD)
2022-09-16 16:20:06 +02:00
###############################################################################
2022-10-18 17:01:08 +02:00
ACME_DIR=$(DATA_DIR)/acme
2022-09-16 18:27:15 +02:00
DOMAIN=monotremata.xyz
CERT_PATH=$(ACME_DIR)/$(DOMAIN)
CERT=$(CERT_PATH)/fullchain.cer
KEY=$(CERT_PATH)/$(DOMAIN).key
2022-09-16 16:20:06 +02:00
2022-10-18 17:01:08 +02:00
###############################################################################
$(CERT): sync_certs
$(KEY): sync_certs
2022-09-16 16:20:06 +02:00
###############################################################################
# Sync the certificates using rsync. Because `sync` is a phony
# target, it will be run each time, but the certificate files will only be
# updated if a renewal happens
2022-10-18 17:01:08 +02:00
$(CERT): sync_certs
$(KEY): sync_certs
2022-09-16 16:20:06 +02:00
2022-09-23 10:38:10 +02:00
RSYNCD_HOST=narwhal
RSYNCD_USER=user
GOPASS=doas -u gopass gopass
RSYNC_PASSWORD = $(shell $(GOPASS) $(RSYNCD_HOST)/rsyncd/$(RSYNCD_USER))
2022-10-18 17:01:08 +02:00
REMOTE_ACME_PATH=rsync://$(RSYNCD_USER)@10.0.0.5/acme
RSYNC_OPTS=--archive --delete --acls --xattrs --compress --verbose --human-readable
2022-09-16 16:20:06 +02:00
sync_certs:
2022-09-16 18:27:15 +02:00
mkdir -p $(ACME_DIR)
2022-10-18 17:01:08 +02:00
@echo "data dir: $(DATA_DIR)"
2022-09-23 10:38:10 +02:00
@echo "running rsync"
@export RSYNC_PASSWORD=$(RSYNC_PASSWORD); \
2022-09-16 16:20:06 +02:00
rsync \
$(RSYNC_OPTS) \
$(REMOTE_ACME_PATH) \
2022-09-16 18:27:15 +02:00
$(ACME_DIR)
2022-09-16 17:26:21 +02:00
###############################################################################
2022-10-18 17:01:08 +02:00
$(NGINX_RELOAD): $(CERT) $(KEY)
@echo "reloading nginx"
2022-09-16 17:26:21 +02:00
mkdir -p $(@D)
2022-10-18 17:01:08 +02:00
systemctl reload kvmd-nginx
2022-09-16 17:26:21 +02:00
touch $@
###############################################################################