This commit is contained in:
alessandro
2026-08-26 10:45:38 +02:00
11 changed files with 1340 additions and 6 deletions
+12 -6
View File
@@ -4,25 +4,31 @@ set -euo pipefail
# Uso: ./addlistener.sh [env] [properties_file]
# env e' ignorato: endpoint viene sempre letto dalla chiave "endpoint".
ENVIRONMENT="${1:-dev}"
PROPERTIES_FILE="${2:-env/${ENVIRONMENT}/values.env}"
# Hardening per evitare errori con set -u in esecuzioni/sourcing anomali
: "${PROPERTIES_FILE:=env/${ENVIRONMENT}/values.env}"
ENV_DIR="env/${ENVIRONMENT}"
if [[ -n "$ENVIRONMENT" ]]; then
echo "Ambiente richiesto: $ENVIRONMENT (chiave usata: endpoint)"
fi
if [[ ! -d "$ENV_DIR" ]]; then
echo "Warning: directory non trovata: $ENV_DIR" >&2
if [[ -f "${PROPERTIES_FILE:-}" ]]; then
# Estrae endpoint ignorando commenti e spazi, supportando anche endpoint = valore
endpoint_raw="$({ grep -E '^[[:space:]]*endpoint[[:space:]]*=' "${PROPERTIES_FILE}" | tail -n1 || true; } | sed -E 's/^[[:space:]]*endpoint[[:space:]]*=[[:space:]]*//')"
elif [[ -d "$ENV_DIR" ]]; then
# Estrae endpoint da qualsiasi file .env nella directory dell'ambiente
endpoint_raw="$({ grep -r '^[[:space:]]*endpoint[[:space:]]*=' "$ENV_DIR" 2>/dev/null | head -n1 || true; } | sed -E 's/^[^:]*:[[:space:]]*endpoint[[:space:]]*=[[:space:]]*//')"
else
echo "Warning: file non trovato: ${PROPERTIES_FILE:-<non impostato>} e directory non trovata: $ENV_DIR" >&2
exit 0
fi
# Estrae endpoint da qualsiasi file .env nella directory dell'ambiente
endpoint_raw="$({ grep -r '^[[:space:]]*endpoint[[:space:]]*=' "$ENV_DIR" 2>/dev/null | head -n1 || true; } | sed -E 's/^[^:]*:[[:space:]]*endpoint[[:space:]]*=[[:space:]]*//')"
# Rimuove eventuali virgolette e spazi ai bordi
endpoint="$(echo "$endpoint_raw" | sed -E 's/^[[:space:]"\x27]+//; s/[[:space:]"\x27]+$//')"
if [[ -z "$endpoint" ]]; then
echo "La chiave endpoint non e valorizzata in $PROPERTIES_FILE" >&2
echo "La chiave endpoint non e valorizzata in ${PROPERTIES_FILE:-<non impostato>}" >&2
exit 0
fi