fix wrapper

This commit is contained in:
Mateusz Gruszczyński
2025-10-23 22:43:15 +02:00
parent dc6abf271b
commit 90262e9dc4

View File

@@ -333,23 +333,53 @@ def setup_angie():
WRAP = """#!/bin/sh WRAP = """#!/bin/sh
# nginx compat -> angie; safe config test (-t) # nginx compat -> angie; safe config test (-t)
# - remove all user-provided -g # - strip all user-provided -g flags
# - force pid to /tmp during tests to avoid /run/angie perms # - when running with -t, use a temp config without 'pid' and set pid via -g
if printf ' %s ' "$@" | grep -q ' -t '; then
set -- "$@" strip_pid_conf() {
NEW_ARGS="" # 1) find base config from -c if provided, otherwise default
while [ "$#" -gt 0 ]; do local base_conf="/etc/angie/angie.conf"
if [ "$1" = "-g" ]; then local next_is_c=
shift 2 local arg
for arg in "$@"; do
if [ -n "$next_is_c" ]; then
base_conf="$arg"
next_is_c=
continue continue
fi fi
NEW_ARGS="$NEW_ARGS \"${1}\"" [ "$arg" = "-c" ] && next_is_c=1
shift
done done
# 2) create a temporary config with any top-level 'pid ...;' removed
local tmpd tmpc
tmpd="$(mktemp -d)"
tmpc="$tmpd/angie.conf"
# remove lines starting with 'pid ...;' (with optional leading whitespace)
sed -E 's/^[[:space:]]*pid[[:space:]]+[^;]+;//' "$base_conf" > "$tmpc"
printf '%s\n' "$tmpc"
}
if printf ' %s ' "$@" | grep -q ' -t '; then
# rebuild args: drop every -g <arg> and -c <file> (we will pass our own -c)
NEW_ARGS=""
skip_next=""
for a in "$@"; do
if [ -n "$skip_next" ]; then
skip_next=""
continue
fi
if [ "$a" = "-g" ] || [ "$a" = "-c" ]; then
skip_next=1
continue
fi
NEW_ARGS="$NEW_ARGS $a"
done
TMP_CONF="$(strip_pid_conf "$@")"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
eval set -- $NEW_ARGS exec /usr/sbin/angie -g "pid /tmp/angie-test.pid; error_log off;" -c "$TMP_CONF" $NEW_ARGS
exec /usr/sbin/angie -g "pid /tmp/angie-test.pid; error_log off;" "$@"
else else
# full compatibility (e.g. -s reload): forward everything to angie
exec /usr/sbin/angie "$@" exec /usr/sbin/angie "$@"
fi fi
""" """