moves helper makefiles into make/ dir
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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
|
||||
IMAGE_PREFIX="$(IMAGE_PREFIX)" podman-compose build $(module)
|
||||
endef
|
||||
|
||||
define push_module_rule =
|
||||
.PHONY: push_$(module)
|
||||
push_$(module): login_registry build_$(module)
|
||||
podman push $(container_image_name)
|
||||
endef
|
||||
|
||||
$(foreach module,$(COMPOSE_SERVICES),$(eval $(call build_module_rule)))
|
||||
$(foreach module,$(COMPOSE_SERVICES),$(eval $(call push_module_rule)))
|
||||
|
||||
.PHONY: login_registry
|
||||
login_registry:
|
||||
podman login $(REGISTRY_DOMAIN)
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
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
|
||||
|
||||
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: $(foreach module,$(ALL_MODULES),$(uninstall_dyndns_$(module)))
|
||||
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
|
||||
@@ -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
|
||||
@@ -0,0 +1,71 @@
|
||||
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): $(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)
|
||||
endef
|
||||
|
||||
define reinstall_openrc_module_rule =
|
||||
.PHONY: reinstall_openrc_$(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 =
|
||||
.PHONY: openrc_add_$(module)
|
||||
openrc_add_$(module):
|
||||
rc-update -U add joeac.net.$(module) default
|
||||
endef
|
||||
|
||||
define openrc_start_rule =
|
||||
.PHONY: openrc_start_$(module)
|
||||
openrc_start_$(module):
|
||||
rc-service -U joeac.net.$(module) start
|
||||
endef
|
||||
|
||||
define openrc_restart_rule =
|
||||
.PHONY: openrc_restart_$(module)
|
||||
openrc_restart_$(module):
|
||||
rc-service -U joeac.net.$(module) restart
|
||||
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)))
|
||||
|
||||
~/.config/rc/init.d/joeac.net: openrc/init.d/joeac.net ~/.config/rc/init.d ~/.config/rc/runlevels/default /etc/init.d/user.$(shell whoami) /etc/conf.d/user.$(shell whoami)
|
||||
rm -f ~/.config/rc/init.d/joeac.net; \
|
||||
mkdir -p ~/.config/rc/init.d; \
|
||||
cp openrc/init.d/joeac.net ~/.config/rc/init.d/joeac.net
|
||||
|
||||
~/.config/rc/init.d:
|
||||
mkdir -p ~/.config/rc/init.d
|
||||
|
||||
~/.config/rc/runlevels/default:
|
||||
mkdir -p ~/.config/rc/runlevels/default
|
||||
|
||||
/etc/init.d/user.$(shell whoami):
|
||||
sudo ln -s /etc/init.d/user /etc/init.d/user.$(shell whoami)
|
||||
|
||||
/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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user