Compare commits

...

2 Commits

Author SHA1 Message Date
7b06fc3c4a refactor(dot-resolver): install the tracked sync-dot-cert.sh instead of generating it
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Every script under /usr/local/bin must be a repo file. install_cert_sync
wrote /usr/local/bin/sync-dot-cert.sh from a heredoc with the domain,
Caddy container and cert dir baked in. The script now lives at
linux_configuration/scripts/sync-dot-cert.sh, takes those three as
arguments (defaults = the installer's constants), and is installed with
install -m 755. dot-cert-sync.service and the first sync pass the
arguments, so --domain reaches the timer too. Test asserts the installed
file is the tracked one byte for byte and runs the script itself against
a docker shim (reload only on change).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014yhTkYV6ZeuAbQYvykFGFc

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-11 19:32:54 +02:00
2dc4081dc9 fix(services): report and remove a stale compulsive-block <app>.orig
check_compulsive_blocker said "<app> wrapper installed (original backed
up)" whenever /usr/bin/<app>.orig existed, even after the package was
removed. A .orig whose /usr/bin/<app> no package owns (read from
${SYSROOT}/var/lib/pacman/local, not pacman -Qqo) is now a warning,
"stale <app>.orig left after package removal", and the repair deletes
it (plus a dangling wrapper) via run, honouring --status/--dry-run.
Unreadable db: never prunes. Pairs with digital-wellbeing 6867f29.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014yhTkYV6ZeuAbQYvykFGFc

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-11 19:24:12 +02:00
9 changed files with 310 additions and 40 deletions

View File

@ -0,0 +1,15 @@
{
"title": "Install the tracked sync-dot-cert.sh instead of generating it",
"objective": "setup_dot_resolver.sh installs linux_configuration/scripts/sync-dot-cert.sh to /usr/local/bin with install -m 755 rather than writing it from a heredoc, with the same runtime behaviour (same docker cp paths, reload stunnel only on change) for the default domain and correct behaviour for a non-default --domain.",
"acceptance_criteria": [
"The installed /usr/local/bin/sync-dot-cert.sh is byte-identical to the tracked file and mode 755; a stale generated copy is replaced",
"dot-cert-sync.service ExecStart passes domain, Caddy container and cert dir",
"The tracked script assembles cert+key into a 600 combined.pem, reloads stunnel on change and is silent when unchanged",
"test_dot_resolver_install.sh passes inside shell_coverage_jail.sh and the change passes in vmbox"
],
"out_of_scope": [
"Rewriting the live host files (kuhy re-runs setup_dot_resolver.sh)",
"Tracking deluge-fix-lt.py (blocked by repo lint for a verbatim copy)"
],
"verifier": "meta/scripts/shell_coverage_jail.sh --subject linux_configuration/features/lib/tests/test_dot_resolver_install.sh <jail_args> --min 0 --fail-on-case-error; vmbox guest run"
}

View File

@ -0,0 +1,36 @@
{
"intent": "check_compulsive_blocker stops reporting a messaging app as wrapped when its package was removed and only /usr/bin/<app>.orig (the real launcher, a blocker bypass) is left; the repair deletes it.",
"scope": [
"linux_configuration/periodic_background/lib/services_apps.sh, linux_configuration/periodic_background/lib/tests/test_services_apps.sh",
"Installer/hook side lives in digital-wellbeing (commit 6867f29); non-goal: no change to the full-installer repair path"
],
"changes": [
"_pkg_owns_path reads ${SYSROOT}/var/lib/pacman/local/*/files (0 owned, 1 unowned, 2 undeterminable) instead of calling the wrapped pacman",
"A .orig on an unowned /usr/bin/<app> is a warning 'stale <app>.orig left after package removal' and is removed via run (plus a dangling wrapper) unless --status; an unreadable db never prunes"
],
"verification": [
{
"command": "periodic_background/lib/tests/run_all.sh",
"result": "pass",
"evidence": "test_services_apps.sh 38 passed 0 failed (new cases fail 8/38 against HEAD); all services suites pass"
},
{
"command": "vmbox guest cco: check_compulsive_blocker on a real stranded /usr/bin/discord.orig",
"result": "pass",
"evidence": "--status: warning, file kept; repair: FIXES=1, file gone; rerun: ok. Passed in vmbox, not verified on the host"
},
{
"command": "shellcheck -x services_apps.sh test_services_apps.sh",
"result": "pass",
"evidence": "clean"
}
],
"risks": [
"A package that ships the app under a different path than /usr/bin/<app> would make its .orig look stale",
"The host's next periodic run will delete /usr/bin/discord.orig itself"
],
"rollback": [
"git revert the commit",
"Run check_and_enable_services.sh --status and confirm the compulsive_blocker section"
]
}

View File

@ -0,0 +1,36 @@
{
"intent": "Every script installed to /usr/local/bin is a tracked repo file: sync-dot-cert.sh is installed from linux_configuration/scripts/ instead of being generated from a heredoc.",
"scope": [
"linux_configuration/scripts/sync-dot-cert.sh, linux_configuration/features/setup_dot_resolver.sh, linux_configuration/features/lib/dot_resolver_install.sh, linux_configuration/features/lib/tests/test_dot_resolver_install.sh",
"Non-goal: stunnel config and units stay generated; deluge-fix-lt.py is not in this commit (repo lint blocks a verbatim copy)"
],
"changes": [
"scripts/sync-dot-cert.sh takes <domain> <caddy-container> <cert-dir> (defaults = the installer's) instead of baking them in; install_cert_sync does sudo install -m 755 of it and dies if it is missing",
"dot-cert-sync.service ExecStart and the installer's first sync pass the three arguments, so a non-default --domain reaches the timer; unused cert_source_dir removed"
],
"verification": [
{
"command": "shell_coverage_jail.sh --subject features/lib/tests/test_dot_resolver_install.sh <jail_args> --min 0 --fail-on-case-error",
"result": "pass",
"evidence": "no case errors; a mutated sync script (reload removed) makes the jail fail"
},
{
"command": "vmbox guest cco: install_cert_sync + install_units as root over a stale generated copy, then the installed script against a docker shim",
"result": "pass",
"evidence": "installed == tracked (cmp), 755 root, ExecStart passes domain/container/dir, docker cp paths identical to the live script, second run silent. Passed in vmbox, not verified on the host"
},
{
"command": "shellcheck -x on the four shell files",
"result": "pass",
"evidence": "clean"
}
],
"risks": [
"The live /usr/local/bin/sync-dot-cert.sh and dot-cert-sync.service stay the old generated ones until setup_dot_resolver.sh is re-run",
"A bare manual sync-dot-cert.sh run uses the defaults, which must track the installer's constants"
],
"rollback": [
"git revert the commit and re-run setup_dot_resolver.sh",
"Check systemctl start dot-cert-sync.service and setup_dot_resolver.sh --check"
]
}

View File

@ -9,25 +9,17 @@ install_cert_sync() {
# Caddy renews on its own schedule; stunnel reads files from disk and must
# be told. A timer copies the current cert out of the container and
# reloads stunnel only when the content actually changed.
# The script is the tracked scripts/sync-dot-cert.sh, installed as-is; the
# values it used to have baked in are now its arguments (sync_script_args).
sudo install -d -m 700 "$CERT_DIR"
sudo tee "$SYNC_SCRIPT" >/dev/null <<EOF
#!/bin/bash
# Copy the Caddy-managed certificate for $DOMAIN out to stunnel.
# Generated by $SCRIPT_NAME - edit that instead.
set -euo pipefail
src="$(cert_source_dir)"
tmp="\$(mktemp -d)"
trap 'rm -rf "\$tmp"' EXIT
docker cp "$CADDY_CONTAINER:\$src/$DOMAIN.crt" "\$tmp/cert.pem"
docker cp "$CADDY_CONTAINER:\$src/$DOMAIN.key" "\$tmp/key.pem"
cat "\$tmp/cert.pem" "\$tmp/key.pem" >"\$tmp/combined.pem"
if ! cmp -s "\$tmp/combined.pem" "$CERT_DIR/combined.pem"; then
install -m 600 "\$tmp/combined.pem" "$CERT_DIR/combined.pem"
systemctl reload-or-restart stunnel-dot.service
echo "certificate updated for $DOMAIN"
fi
EOF
sudo chmod 755 "$SYNC_SCRIPT"
[[ -f $SYNC_SCRIPT_SRC ]] || die "tracked sync script missing: $SYNC_SCRIPT_SRC"
sudo install -m 755 "$SYNC_SCRIPT_SRC" "$SYNC_SCRIPT"
}
# The arguments every caller of $SYNC_SCRIPT passes, so a non-default --domain
# reaches the timer's runs too.
sync_script_args() {
printf '%s %s %s' "$DOMAIN" "$CADDY_CONTAINER" "$CERT_DIR"
}
install_stunnel_conf() {
@ -74,7 +66,7 @@ Description=Copy the Caddy certificate for $DOMAIN to stunnel
[Service]
Type=oneshot
ExecStart=$SYNC_SCRIPT
ExecStart=$SYNC_SCRIPT $(sync_script_args)
EOF
sudo tee /etc/systemd/system/dot-cert-sync.timer >/dev/null <<EOF

View File

@ -38,15 +38,12 @@ DOMAIN="dns.kuhy.duckdns.org"
BIND_ADDR="10.8.0.1"
CADDY_CONTAINER="caddy"
# install_cert_sync interpolates this at GENERATION time (the heredoc is
# unquoted), baking the resolved path into the script it writes. That is
# deliberate, not a bug -- the live /usr/local/bin/sync-dot-cert.sh carries a
# fully populated src=. The fixture must therefore define it exactly as the
# entry script does, or the generated script gets src="" and the assertion
# below silently passes over an empty path.
cert_source_dir() {
printf '/data/caddy/certificates/acme-v02.api.letsencrypt.org-directory/%s' \
"$DOMAIN"
# install_cert_sync installs this tracked file verbatim (no heredoc): every
# script under /usr/local/bin must be a file in a repo.
SYNC_SCRIPT_SRC="$(cd "$SCRIPT_DIR/../../../scripts" && pwd)/sync-dot-cert.sh"
die() {
printf 'die: %s\n' "$1" >&2
return 1
}
# shellcheck source=../dot_resolver_install.sh
@ -64,9 +61,16 @@ mkdir -p /etc/stunnel /etc/systemd/system /usr/local/bin
# --- install_cert_sync ------------------------------------------------------
install_cert_sync
_t_file_has "$SYNC_SCRIPT" 'combined.pem' "cert sync script assembles combined.pem"
_t_file_has "$SYNC_SCRIPT" "src=\"/data/caddy/certificates" "cert source path is baked in, not left empty"
_t_file_has "$SYNC_SCRIPT" 'reload-or-restart' "cert sync restarts stunnel after renewal"
if cmp -s "$SYNC_SCRIPT_SRC" "$SYNC_SCRIPT"; then
_t_pass "the installed sync script is the tracked file, byte for byte"
else
_t_fail "the installed sync script is the tracked file, byte for byte"
fi
if grep -q 'Generated by' "$SYNC_SCRIPT"; then
_t_fail "the sync script is not generated"
else
_t_pass "the sync script is not generated"
fi
if [[ -d $CERT_DIR ]]; then
_t_pass "cert dir created"
else
@ -74,6 +78,46 @@ else
fi
_t_eq "700" "$(stat -c '%a' "$CERT_DIR")" "cert dir is mode 700 (it holds a private key)"
_t_eq "755" "$(stat -c '%a' "$SYNC_SCRIPT")" "sync script is executable"
# Reinstall over a stale generated copy: install replaces it (idempotent).
printf '#!/bin/bash\n# Generated by setup_dot_resolver.sh\n' >"$SYNC_SCRIPT"
install_cert_sync
_t_eq "$(sha256sum <"$SYNC_SCRIPT_SRC")" "$(sha256sum <"$SYNC_SCRIPT")" "a stale generated copy is replaced"
out="$(SYNC_SCRIPT_SRC="$TEST_TMPDIR/absent.sh" install_cert_sync 2>&1 || true)"
_t_has "$out" 'tracked sync script missing' "a missing tracked file stops the install"
# --- the tracked sync script itself -----------------------------------------
# docker cp is stubbed to copy from a fixture tree, so the script's own logic
# (assemble, compare, install, reload-only-on-change) runs for real.
SYNC_CERTS="$TEST_TMPDIR/caddy"
mkdir -p "$SYNC_CERTS"
cat >"$TEST_TMPDIR/bin/docker" <<DOCKER
#!/usr/bin/env bash
printf 'docker %s\n' "\$*" >>"$TEST_TMPDIR/calls.log"
cp "$SYNC_CERTS/\$(basename "\${2#*:}")" "\$3"
DOCKER
chmod +x "$TEST_TMPDIR/bin/docker"
_t_stub systemctl
sync_dir="$TEST_TMPDIR/stunnel-dot"
mkdir -p "$sync_dir"
printf 'CERT1\n' >"$SYNC_CERTS/d.example.crt"
printf 'KEY1\n' >"$SYNC_CERTS/d.example.key"
out="$("$SYNC_SCRIPT_SRC" d.example box "$sync_dir")"
_t_eq "$(printf 'CERT1\nKEY1')" "$(cat "$sync_dir/combined.pem")" "the sync assembles cert + key"
_t_eq "600" "$(stat -c '%a' "$sync_dir/combined.pem")" "combined.pem is mode 600"
_t_has "$out" 'certificate updated for d.example' "a new cert is announced"
_t_called 'docker cp box:/data/caddy/certificates/acme-v02.api.letsencrypt.org-directory/d.example/d.example.crt' \
"the cert is read from the domain's Caddy dir in the named container"
_t_called 'systemctl reload-or-restart stunnel-dot.service' "a new cert reloads stunnel"
: >"$TEST_TMPDIR/calls.log"
out="$("$SYNC_SCRIPT_SRC" d.example box "$sync_dir")"
_t_eq "" "$out" "an unchanged cert is silent"
if grep -q reload "$TEST_TMPDIR/calls.log"; then
_t_fail "an unchanged cert does not reload stunnel"
else
_t_pass "an unchanged cert does not reload stunnel"
fi
_t_unstub docker
_t_unstub systemctl
# --- install_stunnel_conf ---------------------------------------------------
install_stunnel_conf
@ -94,7 +138,8 @@ if grep -q '^Requires=dnsmasq' /etc/systemd/system/stunnel-dot.service; then
else
_t_pass "no Requires=dnsmasq.service"
fi
_t_file_has /etc/systemd/system/dot-cert-sync.service "$SYNC_SCRIPT" "cert-sync service runs the sync script"
_t_file_has /etc/systemd/system/dot-cert-sync.service "^ExecStart=$SYNC_SCRIPT $DOMAIN $CADDY_CONTAINER $CERT_DIR\$" \
"cert-sync service passes domain, container and cert dir"
_t_file_has /etc/systemd/system/dot-cert-sync.timer 'OnCalendar' "cert-sync timer is scheduled"
_t_called 'daemon-reload' "units are followed by a daemon-reload"

View File

@ -77,12 +77,6 @@ require_tools() {
fi
}
cert_source_dir() {
# Caddy stores certs per-domain under its data volume.
printf '/data/caddy/certificates/acme-v02.api.letsencrypt.org-directory/%s' \
"$DOMAIN"
}
verify_prerequisites() {
# A DoT endpoint in front of a resolver that is not running would answer
# every query with a connection error, which looks exactly like a network
@ -110,6 +104,8 @@ verify_prerequisites() {
}
SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
# Installed verbatim to $SYNC_SCRIPT; never generated (see install_cert_sync).
readonly SYNC_SCRIPT_SRC="$SCRIPT_DIR/../scripts/sync-dot-cert.sh"
# shellcheck source=lib/dot_resolver_install.sh
source "$SCRIPT_DIR/lib/dot_resolver_install.sh"
@ -126,7 +122,7 @@ main() {
install_units
log "Syncing certificate..."
sudo "$SYNC_SCRIPT" || die "certificate sync failed - has Caddy issued $DOMAIN yet?"
sudo "$SYNC_SCRIPT" "$DOMAIN" "$CADDY_CONTAINER" "$CERT_DIR" || die "certificate sync failed - has Caddy issued $DOMAIN yet?"
sudo systemctl enable --now stunnel-dot.service
sudo systemctl enable --now dot-cert-sync.timer

View File

@ -27,9 +27,19 @@ check_compulsive_blocker() {
# Check if wrappers are installed for known apps
local checked_any=false
local stale=()
for app in beeper signal-desktop discord; do
local wrapper_path="${SYSROOT}/usr/bin/$app"
if [[ -f "${wrapper_path}.orig" ]] || [[ -L "$wrapper_path" ]]; then
local owned=0
_pkg_owns_path "/usr/bin/$app" || owned=$?
if [[ -f "${wrapper_path}.orig" && $owned -eq 1 ]]; then
# Package removed: pacman deleted the wrapper but not the backup,
# so `<app>.orig` still launches the app around the blocker.
issues+=("stale $app.orig left after package removal")
stale+=("$app")
if [[ $status != "error" ]]; then status="warning"; fi
checked_any=true
elif [[ -f "${wrapper_path}.orig" ]] || [[ -L "$wrapper_path" ]]; then
if [[ -f "${wrapper_path}.orig" ]]; then
msg "$app wrapper installed (original backed up)"
checked_any=true
@ -64,11 +74,38 @@ check_compulsive_blocker() {
err_missing_script "Install script not found: $COMPULSIVE_BLOCK_SCRIPT"
fi
fi
# A stale backup is repaired on its own, whatever the status: the full
# installer is only for a missing blocker.
if [[ $STATUS_ONLY -eq 0 ]]; then
for app in "${stale[@]}"; do
local stale_path="${SYSROOT}/usr/bin/$app"
note "Removing stale ${stale_path}.orig..."
run rm -f "${stale_path}.orig"
# A wrapper left behind would exec the .orig just deleted.
if grep -q "block-compulsive-opening" "$stale_path" 2>/dev/null; then
run rm -f "$stale_path"
fi
((FIXES_APPLIED++)) || true
done
fi
fi
set_service_status "compulsive_blocker" "$status"
}
# Does an installed package own <abs-path>? Read from ${SYSROOT}'s pacman db
# rather than `pacman -Qqo`, so it honours SYSROOT and skips the pacman
# wrapper. grep's exit code is the answer: 0 owned, 1 unowned, 2 undeterminable
# (no db) -- only a definite 1 makes a .orig stale.
_pkg_owns_path() { # <abs-path>
local lists=("${SYSROOT}"/var/lib/pacman/local/*/files)
[[ -e ${lists[0]} ]] || return 2
local rc=0
grep -qxF -- "${1#/}" "${lists[@]}" 2>/dev/null || rc=$?
return "$rc"
}
check_leechblock() {
header "LeechBlock Browser Extension"

View File

@ -24,6 +24,30 @@ _t_called_in() { # <haystack> <needle> <what>
fi
}
_t_not_in() { # <haystack> <needle> <what>
if [[ "$1" == *"$2"* ]]; then
_t_fail "$3 (unexpected '$2')"
else
_t_pass "$3"
fi
}
# What install_wrapper leaves on /usr/bin/<app>: the marker the repair greps.
wrapper_marker() { # <relative-path>
sysfile "$1"
printf 'exec /usr/local/bin/block-compulsive-opening.sh wrapper x\n' >"${SYSROOT_DIR}/$1"
}
# Register <relative-path> as owned by <pkg> in the fixture pacman db.
own_path() { # <pkg> <relative-path>
sysfile "var/lib/pacman/local/$1-1-1/files"
printf '%%FILES%%\n%s\n' "$2" >"${SYSROOT_DIR}/var/lib/pacman/local/$1-1-1/files"
}
sys_state() { # <relative-path> -> present|absent
if [[ -e "${SYSROOT_DIR}/$1" ]]; then echo present; else echo absent; fi
}
TEST_USER="${SUDO_USER:-$USER}"
echo "== check_compulsive_blocker: no target apps present =="
@ -58,9 +82,70 @@ sysfile usr/local/bin/block-compulsive-opening.sh
present_command discord
absent_command beeper signal-desktop
sysfile usr/bin/discord.orig
wrapper_marker usr/bin/discord
own_path discord usr/bin/discord
check_compulsive_blocker >"${TEST_TMPDIR}/out.txt"
_t_called_in "$(cat "${TEST_TMPDIR}/out.txt")" "discord wrapper installed" "a backed-up original counts as wrapped"
_t_eq "ok" "$(get_service_status "compulsive_blocker")" "a wrapped app leaves status ok"
_t_eq "0" "$FIXES_APPLIED" "an owned wrap is not touched"
echo "== check_compulsive_blocker: a .orig left by a package removal is stale =="
reset_state
sysfile usr/local/bin/block-compulsive-opening.sh
absent_command beeper signal-desktop discord
# pacman removed /usr/bin/discord (our wrapper) but not the backup; another
# package in the db proves the db is readable, so "unowned" is definite.
sysfile usr/bin/discord.orig
own_path signal-desktop usr/bin/signal-desktop
check_compulsive_blocker >"${TEST_TMPDIR}/out.txt"
_t_called_in "$(cat "${TEST_TMPDIR}/out.txt")" "stale discord.orig left after package removal" "the stale backup is named"
_t_not_in "$(cat "${TEST_TMPDIR}/out.txt")" "discord wrapper installed" "a stale backup is not reported as a wrapper"
_t_eq "warning" "$(get_service_status "compulsive_blocker")" "a stale backup is a warning"
_t_eq "absent" "$(sys_state usr/bin/discord.orig)" "the repair deletes the stale .orig"
_t_eq "1" "$FIXES_APPLIED" "the removal is counted as a fix"
_t_not_called 'ran block_compulsive_opening' "a stale backup does not rerun the installer"
echo "== check_compulsive_blocker: a stale .orig takes its dangling wrapper with it =="
reset_state
sysfile usr/local/bin/block-compulsive-opening.sh
absent_command beeper signal-desktop discord
sysfile usr/bin/discord.orig
wrapper_marker usr/bin/discord
own_path signal-desktop usr/bin/signal-desktop
check_compulsive_blocker >/dev/null
_t_eq "absent" "$(sys_state usr/bin/discord)" "our wrapper on an unowned path is deleted"
_t_eq "absent" "$(sys_state usr/bin/discord.orig)" "and so is its .orig"
echo "== check_compulsive_blocker: --status reports a stale .orig but keeps it =="
reset_state
sysfile usr/local/bin/block-compulsive-opening.sh
absent_command beeper signal-desktop discord
sysfile usr/bin/discord.orig
own_path signal-desktop usr/bin/signal-desktop
STATUS_ONLY=1
check_compulsive_blocker >"${TEST_TMPDIR}/out.txt"
_t_called_in "$(cat "${TEST_TMPDIR}/out.txt")" "stale discord.orig" "--status still names the stale backup"
_t_eq "present" "$(sys_state usr/bin/discord.orig)" "--status deletes nothing"
echo "== check_compulsive_blocker: --dry-run reports a stale .orig but keeps it =="
reset_state
sysfile usr/local/bin/block-compulsive-opening.sh
absent_command beeper signal-desktop discord
sysfile usr/bin/discord.orig
own_path signal-desktop usr/bin/signal-desktop
DRY_RUN=1
check_compulsive_blocker >/dev/null
_t_eq "present" "$(sys_state usr/bin/discord.orig)" "--dry-run deletes nothing"
echo "== check_compulsive_blocker: an unreadable pacman db never prunes =="
reset_state
sysfile usr/local/bin/block-compulsive-opening.sh
present_command discord
absent_command beeper signal-desktop
sysfile usr/bin/discord.orig
check_compulsive_blocker >"${TEST_TMPDIR}/out.txt"
_t_called_in "$(cat "${TEST_TMPDIR}/out.txt")" "discord wrapper installed" "no db: the backup still counts as a wrapper"
_t_eq "present" "$(sys_state usr/bin/discord.orig)" "no db: the .orig is kept"
echo "== check_compulsive_blocker: a symlinked wrapper without .orig is skipped =="
reset_state

View File

@ -0,0 +1,28 @@
#!/bin/bash
# Copy the Caddy-managed certificate for the DoT hostname out to stunnel, and
# reload stunnel only when the content actually changed.
#
# Installed to /usr/local/bin/sync-dot-cert.sh by
# features/setup_dot_resolver.sh (install -m 755 of THIS file) and run daily by
# dot-cert-sync.timer. The installer passes all three arguments, so the
# defaults below only matter for a bare manual run; they match the installer's.
#
# Usage: sync-dot-cert.sh [<domain> [<caddy-container> [<cert-dir>]]]
set -euo pipefail
domain="${1:-dns.kuhy.duckdns.org}"
container="${2:-gitea-caddy}"
cert_dir="${3:-/etc/stunnel/dot}"
# Caddy stores certs per-domain under its data volume.
src="/data/caddy/certificates/acme-v02.api.letsencrypt.org-directory/$domain"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
docker cp "$container:$src/$domain.crt" "$tmp/cert.pem"
docker cp "$container:$src/$domain.key" "$tmp/key.pem"
cat "$tmp/cert.pem" "$tmp/key.pem" >"$tmp/combined.pem"
if ! cmp -s "$tmp/combined.pem" "$cert_dir/combined.pem"; then
install -m 600 "$tmp/combined.pem" "$cert_dir/combined.pem"
systemctl reload-or-restart stunnel-dot.service
echo "certificate updated for $domain"
fi