Compare commits

..

12 Commits

Author SHA1 Message Date
joeac c7c8a96a57 moves helper makefiles into make/ dir 2026-07-01 18:31:34 +01:00
joeac f73512107c renames some module rules 2026-07-01 18:26:22 +01:00
joeac f8401d00a4 fixes indent in dyndns.mk 2026-07-01 18:22:53 +01:00
joeac b79037c055 only install openrc module if it is an openrc module 2026-07-01 18:20:01 +01:00
joeac 8af9a55187 move uninstall_joeac.net_service to openrc.mk 2026-07-01 18:19:43 +01:00
joeac 1b200f217b move vars to vars.mk 2026-07-01 18:19:26 +01:00
joeac c0e6d13a1f moves stuff to nginx.mk 2026-07-01 18:11:08 +01:00
joeac 2b00e03999 pulls out uninstall to openrc.mk 2026-07-01 17:55:30 +01:00
joeac bf2dabe3f4 pulls out more dyndns stuff to dyndns.mk 2026-07-01 17:49:04 +01:00
joeac d0f549ce22 removes unneeded nginx vars in Makefiles 2026-07-01 17:33:53 +01:00
joeac 89165e9d88 pulls vars out to container.mk 2026-07-01 17:29:16 +01:00
joeac a601e93d00 pulls out nginx_module.mk 2026-07-01 17:22:50 +01:00
11 changed files with 129 additions and 103 deletions
+3
View File
@@ -5,3 +5,6 @@ indent_size = 2
[*.{md,markdown,mdx}]
max_line_length = 80
[{Makefile,*.mk}]
indent_style = tab
+9 -52
View File
@@ -1,40 +1,10 @@
include config.mk
#############
# VARIABLES #
#############
CPU_ARCH := $(if $(shell which arch 2>/dev/null),\
$(shell arch),\
$(shell lscpu | grep ^Architecture: | sed "s/^Architecture:[[:space:]]*\([[:alnum:][:punct:]]\+\).*/\1/"))
HOSTNAME := $(shell cat /etc/hostname)
IMAGE_PREFIX := $(if $(filter armv7%,$(CPU_ARCH)),armv7/)
REGISTRY_DOMAIN := git.joeac.net
REGISTRY_USER := joeac
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 \
| yq ".services | keys" --output-format csv --csv-separator " ")
MAKE_MODULES := $(foreach module,$(MODULES),\
$(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
include make/vars.mk
#############
# FUNCTIONS #
#############
container_image_name = $(REGISTRY_DOMAIN)/$(REGISTRY_USER)/joeac.net-$(module)
nginx_module_target = $(if $(SUBDOMAIN_$(module)),/etc/nginx/http.d/$(SUBDOMAIN_$(module)).joeac.net.conf)
dyndns_module_target = $(if $(SUBDOMAIN_$(module)),/etc/periodic/daily/dyndns-$(SUBDOMAIN_$(module)).joeac.net)
openrc_module_target = $(if $(filter $(COMPOSE_SERVICES),$(module)),~/.config/rc/init.d/joeac.net.$(module))
install_submake_file = $(shell [ -f "$(module)/install.mk" ] && echo "$(module)/install.mk")
define make_module_rule =
@@ -50,29 +20,19 @@ endef
define install_module_rule =
.PHONY: install_$(module)
install_$(module): install_openrc_$(module) $(nginx_module_target) $(dyndns_module_target) $(install_submake_file)
install_$(module): install_openrc_$(module) install_nginx_$(module) install_dyndns_$(module) $(install_submake_file)
$(if $(install_submake_file),$(MAKE) --makefile=$(notdir $(install_submake_file)) --directory=$(dir $(install_submake_file)) install)
endef
define reinstall_module_rule =
.PHONY: reinstall_$(module)
reinstall_$(module): reinstall_openrc_$(module) $(nginx_module_target) $(dyndns_module_target) $(install_submake_file)
reinstall_$(module): reinstall_openrc_$(module) reinstall_nginx_$(module) reinstall_dyndns_$(module) $(install_submake_file)
$(if $(install_submake_file),$(MAKE) --makefile=$(notdir $(install_submake_file)) --directory=$(dir $(install_submake_file)) reinstall)
endef
define uninstall_module_rule =
.PHONY: uninstall_$(module)
uninstall_$(module):
$(if $(openrc_module_target),\
rc-service -U joeac.net.$(module) stop \
rc-update -U del joeac.net.$(module) default \
rm ~/.config/rc/init.d/joeac.net.$(module) \
)
$(if $(SUBDOMAIN_$(module)),\
sudo rm -f /etc/nginx/http.d/$(SUBDOMAIN_$(module)).joeac.net.conf; \
$(RESTART_NGINX); \
sudo rm -f /etc/periodic/daily/dyndns-$(SUBDOMAIN_$(module)).joeac.net; \
)
uninstall_$(module): uninstall_openrc_$(module) uninstall_nginx_$(module) uninstall_dyndns_$(module)
$(if $(install_submake_file),\
$(MAKE) --makefile=$(notdir (install_submake_file)) --directory $(dir $(install_submake_file)) uninstall
)
@@ -103,18 +63,15 @@ install: $(foreach module,$(MODULES),install_$(module)) install_crontab
.PHONY: uninstall
uninstall: uninstall_nginx uninstall_dyndns uninstall_joeac.net_service $(foreach module,$(MODULES),uninstall_$(module)) uninstall_crontab
.PHONY: uninstall_joeac.net_service
rm ~/.config/rc/joeac.net
$(foreach module,$(MODULES),$(eval $(install_module_rule)))
$(foreach module,$(MODULES),$(eval $(reinstall_module_rule)))
$(foreach module,$(MODULES),$(eval $(uninstall_module_rule)))
include container.mk
include openrc.mk
include nginx.mk
include crontab.mk
include dyndns.mk
include make/container.mk
include make/openrc.mk
include make/nginx.mk
include make/crontab.mk
include make/dyndns.mk
.PHONY: clean
clean:
+4 -4
View File
@@ -1,6 +1,6 @@
services:
gemini:
image: git.joeac.net/joeac/${CONTAINER_PREFIX}joeac.net-gemini
image: git.joeac.net/joeac/${IMAGE_PREFIX}joeac.net-gemini
container_name: joeac.net-gemini
build:
context: .
@@ -9,7 +9,7 @@ services:
- "${GEMINI_PORT}:1965"
http:
image: git.joeac.net/joeac/${CONTAINER_PREFIX}joeac.net-http
image: git.joeac.net/joeac/${IMAGE_PREFIX}joeac.net-http
container_name: joeac.net-http
build:
context: .
@@ -30,7 +30,7 @@ services:
- "${HTTP_PORT}:80"
etherpad:
image: git.joeac.net/joeac/${CONTAINER_PREFIX}joeac.net-etherpad
image: git.joeac.net/joeac/${IMAGE_PREFIX}joeac.net-etherpad
container_name: joeac.net-etherpad
build:
context: .
@@ -48,7 +48,7 @@ services:
- "${ETHERPAD_PORT}:9001"
smtp:
image: git.joeac.net/joeac/${CONTAINER_PREFIX}joeac.net-smtp
image: git.joeac.net/joeac/${IMAGE_PREFIX}joeac.net-smtp
container_name: joeac.net-smtp
build:
context: .
-4
View File
@@ -1,4 +0,0 @@
SUBDOMAIN_http := @
SUBDOMAIN_vaultwarden := pwd
SUBDOMAIN_etherpad := docs
SUBDOMAIN_ln := ln
+10 -1
View File
@@ -1,7 +1,16 @@
CPU_ARCH := $(if $(shell which arch 2>/dev/null),\
$(shell arch),\
$(shell lscpu | grep ^Architecture: | sed "s/^Architecture:[[:space:]]*\([[:alnum:][:punct:]]\+\).*/\1/"))
IMAGE_PREFIX := $(if $(filter armv7%,$(CPU_ARCH)),armv7/)
REGISTRY_DOMAIN := git.joeac.net
REGISTRY_USER := joeac
container_image_name = $(REGISTRY_DOMAIN)/$(REGISTRY_USER)/$(CONTAINER_PREFIX)joeac.net-$(module)
define build_module_rule =
.PHONY: build_$(module)
build_$(module): make_$(module) $(module).Dockerfile
podman-compose build $(module)
IMAGE_PREFIX="$(IMAGE_PREFIX)" podman-compose build $(module)
endef
define push_module_rule =
View File
+28 -12
View File
@@ -1,11 +1,34 @@
.PHONY: install_dyndns
install_dyndns: /usr/local/bin/dyndns.sh ~/.config/dyndns/DIGITALOCEAN_TOKEN
define install_dyndns_module_rule =
.PHONY: install_dyndns_$(module)
install_dyndns_module_$(module): $(if $(SUBDOMAIN_$(module)),/etc/periodic/daily/dyndns-$(SUBDOMAIN_$(module)).joeac.net install_dyndns)
endef
.PHONY: reinstall_dyndns
reinstall_dyndns: /usr/local/bin/dyndns.sh ~/.config/dyndns/DIGITALOCEAN_TOKEN
define reinstall_dyndns_module_rule =
.PHONY: reinstall_dyndns_$(module)
reinstall_dyndns_$(module): $(if $(SUBDOMAIN_$(module)),/etc/periodic/daily/dyndns-$(SUBDOMAIN_$(module)).joeac.net reinstall_dyndns)
endef
define uninstall_dyndns_module_rule =
.PHONY: uninstall_dyndns_$(module)
uninstall_dyndns_$(module):
$(if $(SUBDOMAIN_$(module)), \
sudo rm -f /etc/periodic/daily/dyndns-$(SUBDOMAIN_$(module)).joeac.net
)
endef
$(foreach module,$(ALL_MODULES), $(eval $(install_dyndns_module_rule)))
$(foreach module,$(ALL_MODULES), $(eval $(reinstall_dyndns_module_rule)))
$(foreach module,$(ALL_MODULES), $(eval $(uninstall_dyndns_module_rule)))
/etc/periodic/daily/dyndns-%joeac.net: /usr/local/bin/dyndns.sh ~/.config/dyndns/DIGITALOCEAN_TOKEN
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 $@
.PHONY: uninstall_dyndns
uninstall_dyndns:
uninstall_dyndns: $(foreach module,$(ALL_MODULES),$(uninstall_dyndns_$(module)))
sudo rm -rf \
/usr/local/bin/dyndns.sh \
/usr/local/bin/get_ip_addr.sh \
@@ -29,10 +52,3 @@ uninstall_dyndns:
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 $@
+39
View File
@@ -0,0 +1,39 @@
define install_nginx_module_rule =
.PHONY: install_nginx_$(module)
install_nginx_$(module): $(if $(SUBDOMAIN_$(module)),/etc/nginx/http.d/$(SUBDOMAIN_$(module)).joeac.net.conf)
endef
define reinstall_nginx_module_rule =
.PHONY: reinstall_nginx_$(module)
reinstall_nginx_$(module): $(if $(SUBDOMAIN_$(module)),/etc/nginx/http.d/$(SUBDOMAIN_$(module)).joeac.net.conf)
endef
define uninstall_nginx_module_rule =
.PHONY: uninstall_nginx_$(module)
uninstall_nginx_$(module):
endef
$(foreach module,$(MODULES),$(eval $(install_nginx_module_rule)))
/etc/nginx/http.d/%.joeac.net.conf: nginx/http.d/%.joeac.net.conf /etc/nginx/http.d /etc/nginx/nginx.conf
sudo cp $< $@
sudo rc-service nginx restart
/etc/nginx/http.d:
sudo mkdir -p /etc/nginx/http.d
.PHONY: uninstall_nginx
uninstall_nginx: $(foreach module,$(MODULES),uninstall_nginx_$(module))
ifeq ($(shell test -d /etc/nginx/nginx.joeac.net-backup && echo 1 || echo 0),0)
$(warn No nginx backup config detected: doing nothing)
else
sudo mv /etc/nginx/nginx.joeac.net-backup /etc/nginx/nginx.conf
sudo rc-service nginx restart
endif
/etc/nginx/nginx.conf: nginx/nginx.conf /etc/nginx/nginx.joeac.net-backup
sudo cp $< $@
sudo rc-service nginx restart
/etc/nginx/nginx.joeac.net-backup:
sudo mv /etc/nginx/nginx.conf /etc/nginx/nginx.joeac.net-backup
+19 -2
View File
@@ -1,6 +1,9 @@
is_openrc_module = $(filter $(COMPOSE_SERVICES),$(module))
openrc_module_target = $(if $(is_openrc_module),~/.config/rc/init.d/joeac.net.$(module))
define install_openrc_module_rule =
.PHONY: install_openrc_$(module)
install_openrc_$(module): $(openrc_module_target) openrc_add_$(module) openrc_start_$(module)
install_openrc_$(module): $(if $(is_openrc_module),$(openrc_module_target) openrc_add_$(module) openrc_start_$(module))
~/.config/rc/init.d/joeac.net.$(module): ~/.config/rc/init.d/joeac.net ~/.config/rc/runlevels/default
ln -s $(shell realpath ~)/.config/rc/init.d/joeac.net ~/.config/rc/init.d/joeac.net.$(module)
@@ -8,7 +11,17 @@ endef
define reinstall_openrc_module_rule =
.PHONY: reinstall_openrc_$(module)
reinstall_openrc_$(module): $(if $(openrc_module_target),$(openrc_module_target) openrc_restart_$(module))
reinstall_openrc_$(module): $(if $(is_openrc_module),$(openrc_module_target) openrc_restart_$(module))
endef
define uninstall_openrc_module_rule =
.PHONY: uninstall_openrc_$(module)
uninstall_openrc_$(module):
$(if $(is_openrc_module),\
rc-service -U joeac.net.$(module) stop; \
rc-update -U del joeac.net.$(module) default; \
rm ~/.config/rc/init.d/joeac.net.$(module); \
)
endef
define openrc_add_rule =
@@ -31,6 +44,7 @@ endef
$(foreach module,$(MODULES),$(eval $(install_openrc_module_rule)))
$(foreach module,$(MODULES),$(eval $(reinstall_openrc_module_rule)))
$(foreach module,$(MODULES),$(eval $(uninstall_openrc_module_rule)))
$(foreach module,$(MODULES),$(eval $(openrc_add_rule)))
$(foreach module,$(MODULES),$(eval $(openrc_start_rule)))
$(foreach module,$(MODULES),$(eval $(openrc_restart_rule)))
@@ -52,3 +66,6 @@ $(foreach module,$(MODULES),$(eval $(openrc_restart_rule)))
/etc/conf.d/user.$(shell whoami): openrc/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
.PHONY: uninstall_joeac.net_service
rm ~/.config/rc/joeac.net
+17
View File
@@ -0,0 +1,17 @@
HOSTNAME := $(shell cat /etc/hostname)
HOSTNAMES := pi-broughton blade-canongate
MODULES_pi-broughton := http gemini smtp vaultwarden ln
MODULES_blade-canongate := etherpad
ALL_MODULES := $(sort $(foreach hostname,$(HOSTNAMES),$(MODULES_$(hostname))))
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 \
| yq ".services | keys" --output-format csv --csv-separator " ")
MAKE_MODULES := $(foreach module,$(MODULES),\
$(shell [ -f $(module)/Makefile ] && echo $(module)))
SUBDOMAIN_http := @
SUBDOMAIN_vaultwarden := pwd
SUBDOMAIN_etherpad := docs
SUBDOMAIN_ln := ln
-28
View File
@@ -1,28 +0,0 @@
.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