Compare commits

...

4 Commits

Author SHA1 Message Date
Joe Carstairs c1096e2b01 pulls out nginx.mk 2026-07-01 15:46:05 +01:00
Joe Carstairs 04e1dad952 pulls out crontab.mk 2026-07-01 15:24:01 +01:00
Joe Carstairs e170bafffc pulls out dyndns.mk 2026-07-01 15:21:01 +01:00
Joe Carstairs 23f31a8c4d Makefile installs modules per hostname 2026-07-01 15:10:23 +01:00
4 changed files with 107 additions and 87 deletions
+24 -87
View File
@@ -7,14 +7,23 @@ include config.mk
CPU_ARCH := $(if $(shell which arch 2>/dev/null),\ CPU_ARCH := $(if $(shell which arch 2>/dev/null),\
$(shell arch),\ $(shell arch),\
$(shell lscpu | grep ^Architecture: | sed "s/^Architecture:[[:space:]]*\([[:alnum:][:punct:]]\+\).*/\1/")) $(shell lscpu | grep ^Architecture: | sed "s/^Architecture:[[:space:]]*\([[:alnum:][:punct:]]\+\).*/\1/"))
HOSTNAME := $(shell cat /etc/hostname)
IMAGE_PREFIX := $(if $(filter armv7%,$(CPU_ARCH)),armv7/) IMAGE_PREFIX := $(if $(filter armv7%,$(CPU_ARCH)),armv7/)
REGISTRY_DOMAIN := git.joeac.net REGISTRY_DOMAIN := git.joeac.net
REGISTRY_USER := joeac REGISTRY_USER := joeac
MODULES := http gemini smtp vaultwarden etherpad ln MODULES_pi-broughton := http gemini smtp vaultwarden ln
MODULES_blade-canongate := etherpad
MASTER_NODE := pi-broughton
IS_MASTER_NODE := $(filter $(MASTER_NODE),$(HOSTNAME))
MODULES := $(MODULES_$(HOSTNAME))
SUBDOMAINS := $(foreach module,$(MODULES),$(SUBDOMAIN_$(module)))
COMPOSE_SERVICES := $(shell podman-compose config \ COMPOSE_SERVICES := $(shell podman-compose config \
| yq ".services | keys" --output-format csv --csv-separator " ") | yq ".services | keys" --output-format csv --csv-separator " ")
MAKE_MODULES := $(foreach module,$(MODULES),\ MAKE_MODULES := $(foreach module,$(MODULES),\
$(shell [ -f $(module)/Makefile ] && echo $(module))) $(shell [ -f $(module)/Makefile ] && echo $(module)))
NGINX_CONFIG_SRC := nginx/nginx.conf
NGINX_CONFIG := /etc/nginx/nginx.conf
NGINX_CONFIG_BACKUP := /etc/nginx/nginx.joeac.net-backup
RESTART_NGINX := sudo rc-service nginx restart RESTART_NGINX := sudo rc-service nginx restart
@@ -117,7 +126,16 @@ endef
# RULES # # RULES #
######### #########
all: $(foreach module,$(MODULES),push_$(module)) .SILENT: usage
.PHONY: usage
usage:
echo "usage:"
echo " make install"
$(foreach module,$(MODULES),echo " make install_$(module)")
echo " make reinstall"
$(foreach module,$(MODULES),echo " make reinstall_$(module)")
echo " make uninstall"
$(foreach module,$(MODULES),echo " make uninstall_$(module)")
$(foreach module,$(COMPOSE_SERVICES),$(eval $(call build_module_rule))) $(foreach module,$(COMPOSE_SERVICES),$(eval $(call build_module_rule)))
$(foreach module,$(COMPOSE_SERVICES),$(eval $(call push_module_rule))) $(foreach module,$(COMPOSE_SERVICES),$(eval $(call push_module_rule)))
@@ -132,39 +150,11 @@ login_registry:
install: $(foreach module,$(MODULES),install_$(module)) install_crontab install: $(foreach module,$(MODULES),install_$(module)) install_crontab
.PHONY: uninstall .PHONY: uninstall
uninstall: uninstall_nginx uninstall_joeac.net_service $(foreach module,$(MODULES),uninstall_$(module)) uninstall_crontab uninstall: uninstall_nginx uninstall_dyndns uninstall_joeac.net_service $(foreach module,$(MODULES),uninstall_$(module)) uninstall_crontab
.PHONY: uninstall_joeac.net_service .PHONY: uninstall_joeac.net_service
rm ~/.config/rc/joeac.net rm ~/.config/rc/joeac.net
nginx_src := $(shell find -L nginx -type f)
nginx_target := $(addprefix /etc/,$(nginx_src))
NGINX_CONFIG_SRC := nginx/nginx.conf
NGINX_CONFIG := /etc/nginx/nginx.conf
NGINX_CONFIG_BACKUP := /etc/nginx/nginx.joeac.net-backup
nginx_config_backup_exists = $(shell test -d $(NGINX_CONFIG_BACKUP) && echo 1 || echo 0)
.PHONY: install_nginx
install_nginx: $(NGINX_CONFIG_BACKUP) $(NGINX_CONFIG) install_dyndns
$(NGINX_CONFIG_BACKUP):
ifeq ($(nginx_config_backup_exists),0)
sudo mv $(NGINX_CONFIG) $(NGINX_CONFIG_BACKUP)
endif
$(NGINX_CONFIG): $(NGINX_CONFIG_SRC)
sudo cp $< $@
$(RESTART_NGINX)
.PHONY: uninstall_nginx
uninstall_nginx: uninstall_dyndns
ifeq ($(nginx_config_backup_exists),0)
@echo "No nginx backup config detected: doing nothing"
else
sudo rm -f $(NGINX_CONFIG)
sudo mv $(NGINX_CONFIG_BACKUP) $(NGINX_CONFIG)
$(RESTART_NGINX)
endif
$(foreach module,$(MODULES),$(eval $(install_module_rule))) $(foreach module,$(MODULES),$(eval $(install_module_rule)))
$(foreach module,$(MODULES),$(eval $(reinstall_module_rule))) $(foreach module,$(MODULES),$(eval $(reinstall_module_rule)))
$(foreach module,$(MODULES),$(eval $(uninstall_module_rule))) $(foreach module,$(MODULES),$(eval $(uninstall_module_rule)))
@@ -192,62 +182,9 @@ $(foreach module,$(MODULES),$(eval $(openrc_restart_rule)))
sudo cp openrc/conf.d/user.$(shell whoami) /etc/conf.d/user.$(shell whoami) sudo cp openrc/conf.d/user.$(shell whoami) /etc/conf.d/user.$(shell whoami)
sudo rc-update add user.$(shell whoami) default sudo rc-update add user.$(shell whoami) default
/etc/nginx/http.d/%joeac.net.conf: nginx/http.d/%joeac.net.conf install_nginx /etc/nginx/http.d include nginx.mk
sudo cp $< $@ include crontab.mk
$(RESTART_NGINX) include dyndns.mk
/etc/nginx/http.d:
sudo mkdir -p /etc/nginx/http.d
.PHONY: install_crontab
install_crontab: /etc/periodic/daily/joeac.net
.PHONY: uninstall_crontab
uninstall_crontab:
sudo rm -f /etc/periodic/daily/joeac.net
/etc/periodic/daily/joeac.net:
echo "#!/bin/sh" > crontab.tmp
echo "git -C /usr/local/lib/joeac.net pull && $(MAKE) --directory /usr/local/lib/joeac.net && rc-service joeac.net restart" \
>> crontab.tmp
sudo mv crontab.tmp /etc/periodic/daily/joeac.net
sudo chmod +x /etc/periodic/daily/joeac.net
.PHONY: install_dyndns
install_dyndns: /usr/local/bin/dyndns.sh ~/.config/dyndns/DIGITALOCEAN_TOKEN
/usr/local/bin/dyndns.sh: /usr/local/lib/digitalocean_dyndns/dyndns.sh /usr/local/bin/get_ip_addr.sh
sudo rm -f /usr/local/bin/dyndns.sh
sudo cp /usr/local/lib/digitalocean_dyndns/dyndns.sh /usr/local/bin/dyndns.sh
/usr/local/bin/get_ip_addr.sh: /usr/local/lib/digitalocean_dyndns/get_ip_addr.sh
sudo rm -f /usr/local/bin/get_ip_addr.sh
sudo cp /usr/local/lib/digitalocean_dyndns/get_ip_addr.sh /usr/local/bin/get_ip_addr.sh
/usr/local/lib/digitalocean_dyndns/%:
cd /usr/local/lib \
&& sudo git clone https://git.joeac.net/joeac/digitalocean_dyndns.git \
~/.config/dyndns/DIGITALOCEAN_TOKEN: DIGITALOCEAN_TOKEN
mkdir -p ~/.config/dyndns/
rm -f ~/.config/dyndns/DIGITALOCEAN_TOKEN
cp DIGITALOCEAN_TOKEN ~/.config/dyndns/DIGITALOCEAN_TOKEN
/etc/periodic/daily/dyndns-%joeac.net:
echo "#!/bin/sh" > crontab.tmp
echo " dyndns.sh 4 $(*F)joeac.net" >> crontab.tmp
echo "CONN_DEVICE_NAME=eth0 dyndns.sh 6 $(*F)joeac.net" >> crontab.tmp
sudo mv crontab.tmp $@
sudo chmod +x $@
.PHONY: uninstall_dyndns
uninstall_dyndns:
sudo rm -rf \
/usr/local/bin/dyndns.sh \
/usr/local/bin/get_ip_addr.sh \
/usr/local/lib/digitalocean_dyndns/ \
~/.config/dyndns \
~/.cache/dyndns
.PHONY: clean .PHONY: clean
clean: clean:
+17
View File
@@ -0,0 +1,17 @@
.PHONY: install_crontab
install_crontab: /etc/periodic/daily/joeac.net
.PHONY: reinstall_crontab
reinstall_crontab: /etc/periodic/daily/joeac.net
.PHONY: uninstall_crontab
uninstall_crontab:
sudo rm -f /etc/periodic/daily/joeac.net
/etc/periodic/daily/joeac.net:
echo "#!/bin/sh" > crontab.tmp
echo "git -C /usr/local/lib/joeac.net pull && $(MAKE) --directory /usr/local/lib/joeac.net && rc-service joeac.net restart" \
>> crontab.tmp
sudo mv crontab.tmp /etc/periodic/daily/joeac.net
sudo chmod +x /etc/periodic/daily/joeac.net
+38
View File
@@ -0,0 +1,38 @@
.PHONY: install_dyndns
install_dyndns: /usr/local/bin/dyndns.sh ~/.config/dyndns/DIGITALOCEAN_TOKEN
.PHONY: reinstall_dyndns
reinstall_dyndns: /usr/local/bin/dyndns.sh ~/.config/dyndns/DIGITALOCEAN_TOKEN
.PHONY: uninstall_dyndns
uninstall_dyndns:
sudo rm -rf \
/usr/local/bin/dyndns.sh \
/usr/local/bin/get_ip_addr.sh \
/usr/local/lib/digitalocean_dyndns/ \
~/.config/dyndns \
~/.cache/dyndns
/usr/local/bin/dyndns.sh: /usr/local/lib/digitalocean_dyndns/dyndns.sh /usr/local/bin/get_ip_addr.sh
sudo rm -f /usr/local/bin/dyndns.sh
sudo cp /usr/local/lib/digitalocean_dyndns/dyndns.sh /usr/local/bin/dyndns.sh
/usr/local/bin/get_ip_addr.sh: /usr/local/lib/digitalocean_dyndns/get_ip_addr.sh
sudo rm -f /usr/local/bin/get_ip_addr.sh
sudo cp /usr/local/lib/digitalocean_dyndns/get_ip_addr.sh /usr/local/bin/get_ip_addr.sh
/usr/local/lib/digitalocean_dyndns/%:
cd /usr/local/lib \
&& sudo git clone https://git.joeac.net/joeac/digitalocean_dyndns.git
~/.config/dyndns/DIGITALOCEAN_TOKEN: DIGITALOCEAN_TOKEN
mkdir -p ~/.config/dyndns/
rm -f ~/.config/dyndns/DIGITALOCEAN_TOKEN
cp DIGITALOCEAN_TOKEN ~/.config/dyndns/DIGITALOCEAN_TOKEN
/etc/periodic/daily/dyndns-%joeac.net: /usr/local/bin/dyndns.sh
echo "#!/bin/sh" > crontab.tmp
echo " /usr/local/bin/dyndns.sh 4 $(*F)joeac.net" >> crontab.tmp
echo "CONN_DEVICE_NAME=eth0 /usr/local/bin/dyndns.sh 6 $(*F)joeac.net" >> crontab.tmp
sudo mv crontab.tmp $@
sudo chmod +x $@
+28
View File
@@ -0,0 +1,28 @@
.PHONY: install_nginx
install_nginx: $(NGINX_CONFIG_BACKUP) $(NGINX_CONFIG)
.PHONY: reinstall_nginx
reinstall_nginx: $(NGINX_CONFIG_BACKUP) $(NGINX_CONFIG)
.PHONY: uninstall_nginx
uninstall_nginx: uninstall_dyndns
ifeq ($(shell test -d $(NGINX_CONFIG_BACKUP) && echo 1 || echo 0),0)
$(warn No nginx backup config detected: doing nothing)
else
sudo mv $(NGINX_CONFIG_BACKUP) $(NGINX_CONFIG)
$(RESTART_NGINX)
endif
$(NGINX_CONFIG_BACKUP):
sudo mv $(NGINX_CONFIG) $(NGINX_CONFIG_BACKUP)
$(NGINX_CONFIG): $(NGINX_CONFIG_SRC) $(NGINX_CONFIG_BACKUP)
sudo cp $< $@
$(RESTART_NGINX)
/etc/nginx/http.d/%joeac.net.conf: nginx/http.d/%joeac.net.conf /etc/nginx/http.d $(NGINX_CONFIG)
sudo cp $< $@
$(RESTART_NGINX)
/etc/nginx/http.d:
sudo mkdir -p /etc/nginx/http.d