:global GlobalFuncReady false;
# Git commit id & info, expected configuration version
-:global CommitId "main/447/d3c4c763";
+:global CommitId "main/448/465d2959";
:global CommitTAG "unknown";
-:global CommitInfo "Autocommit in repo: ros.vados.ru, generated by owner: root, in 20:25:02 03.05.2026.";
+:global CommitInfo "Autocommit in repo: ros.vados.ru, generated by owner: root, in 20:30:02 03.05.2026.";
# The variables are received right here.
:global GlobalConfVersion 138;
-# Makefile to download and check certificates
+# Makefile to download, check, and clean certificates
SHELL := /bin/bash
BUILD_DIR := $(CURDIR)
DIR_TARGETS := $(notdir $(LIST_DIRS))
TARGETS := $(sort $(FILE_TARGETS) $(DIR_TARGETS))
CHECK_TARGETS := $(addprefix check-,$(TARGETS))
+CLEAN_TARGETS := $(addprefix clean-,$(TARGETS))
# Big CA list with all certificates ~ 2Mb
ALL_CA_URL := https://curl.se/ca/cacert.pem
--silent \
--show-error
-.PHONY: default all all-ca-lst download-list check-list $(TARGETS) $(CHECK_TARGETS)
+.PHONY: default all clean all-ca-lst download-list check-list clean-list $(TARGETS) $(CHECK_TARGETS) $(CLEAN_TARGETS)
default:
@echo "Available download targets: all-ca-lst $(TARGETS)"
@echo "Available check targets: $(CHECK_TARGETS)"
+ @echo "Available clean targets: clean $(CLEAN_TARGETS)"
@echo "all downloads all-ca-lst and certificates from all list targets"
+ @echo "clean checks all target directories and removes unavailable PEM files"
@echo "List format: [scheme://]host[/path/to/generator]/certificate-basename"
@echo "Example: example.com/pki/acme/ISRG-Root-X1 downloads https://example.com/pki/acme/ISRG-Root-X1.pem -> ./<target>/ISRG-Root-X1.pem"
- @echo "check target verifies https://example.com/pki/acme/ with ./<target>/ISRG-Root-X1.pem"
+ @echo "check/clean verify https://example.com/pki/acme/ with ./<target>/ISRG-Root-X1.pem"
all: all-ca-lst $(TARGETS)
+clean: $(CLEAN_TARGETS)
+
all-ca-lst:
@mkdir -p $(CA_LIST_DIR)
@echo "Downloading $(ALL_CA_URL) -> $(ALL_CA_FILE)"
$(CHECK_TARGETS): check-%:
@$(MAKE) check-list LIST="$(call list_for_target,$*)" OUT_DIR="$*"
+$(CLEAN_TARGETS): clean-%:
+ @$(MAKE) clean-list LIST="$(call list_for_target,$*)" OUT_DIR="$*"
+
list_for_target = $(if $(wildcard $(LIST_ROOT)/Makefile.$(1)),$(LIST_ROOT)/Makefile.$(1),$(LIST_ROOT)/$(1))
# Convert a list item to URL/cert in shell:
# host/path/cert-name -> https://host/path/cert-name.pem for download
-# host/path/cert-name -> https://host/path/ for check
+# host/path/cert-name -> https://host/path/ for check/clean
# IPv6 colons may be escaped as \: for make compatibility and are normalized here.
download-list:
@test -n "$(LIST)" || { echo "LIST is required" >&2; exit 2; }
done < "$$list"; \
done; \
true
+
+clean-list:
+ @test -n "$(LIST)" || { echo "LIST is required" >&2; exit 2; }
+ @test -n "$(OUT_DIR)" || { echo "OUT_DIR is required" >&2; exit 2; }
+ @if [ -d "$(LIST)" ]; then inputs=("$(LIST)"/*); else inputs=("$(LIST)"); fi; \
+ for list in "$${inputs[@]}"; do \
+ [ -f "$$list" ] || continue; \
+ while IFS= read -r item || [ -n "$$item" ]; do \
+ [[ -z "$$item" || "$$item" =~ ^[[:space:]]*# ]] && continue; \
+ item="$${item//\\:/:}"; \
+ cert="$${item##*/}"; \
+ url="$${item%/*}/"; \
+ [[ "$$url" =~ ^https?:// ]] || url="https://$$url"; \
+ pem="$(BUILD_DIR)/$(OUT_DIR)/$$cert.pem"; \
+ if [ ! -f "$$pem" ]; then \
+ echo "WARN: missing $$pem" >&2; \
+ continue; \
+ fi; \
+ printf 'Cleaning check %s with %s\n' "$$url" "$$pem"; \
+ if $(CURL) --output /dev/null --cacert "$$pem" "$$url"; then \
+ echo "KEEP: $$pem"; \
+ else \
+ echo "REMOVE: $$pem"; \
+ rm -f -- "$$pem"; \
+ fi; \
+ done < "$$list"; \
+ done; \
+ true