NgixProxy_Pathfinder/scripts/inject_acme.sh

29 lines
915 B
Bash

#!/bin/sh
# Inject ACME challenge snippet into all site configs
# Target: Server blocks listening on port 80
CONF_DIR="/etc/nginx/conf.d"
SNIPPET="include /etc/nginx/snippets/acme_challenge.conf;"
echo "[Inject-ACME] Starting injection..."
for conf in $CONF_DIR/*.conf; do
[ -e "$conf" ] || continue
# Check if already injected
if grep -q "acme_challenge.conf" "$conf"; then
echo "[Inject-ACME] Skipping $conf (already has ACME snippet)"
continue
fi
echo "[Inject-ACME] Injecting into $conf..."
# Logic: Insert snippet before 'return 301' or inside 'listen 80' block
# Simplest reliable way with sed: match "listen 80;" and append snippet after it
# Note: Some configs might use "listen 80;" or "listen [::]:80;" or "listen 80 default_server;"
sed -i '/listen 80.*;/a \ '"$SNIPPET" "$conf"
done
echo "[Inject-ACME] Injection complete."