Compare commits

..

1 Commits

Author SHA1 Message Date
6f85457ed9 Merge pull request 'yamlfix' (#1) from yamlfix into main
Reviewed-on: #1
2025-10-27 18:45:46 +00:00
2 changed files with 30 additions and 58 deletions

View File

@@ -1,4 +1,8 @@
Dokumentation wird bei Gelegenheit nachgereicht. # template_repository
Wichtig: Link für Lizenz anpassen.

View File

@@ -5,9 +5,9 @@
# Synapse: https://git.techniverse.net/scriptos/livekit-ip-watch.git # Synapse: https://git.techniverse.net/scriptos/livekit-ip-watch.git
# Autor: Patrick Asmus # Autor: Patrick Asmus
# Web: https://www.cleveradmin.de # Web: https://www.cleveradmin.de
# Version: 1.2.1 # Version: 1.1
# Datum: 27.10.2025 # Datum: 27.10.2025
# Modifikation: Funktion "detect_compose_cmd" nachträglich committed. # Modifikation: healthcheck auf HTTP mit Custom URL umgestellt.
##################################################### #####################################################
set -euo pipefail set -euo pipefail
@@ -124,25 +124,13 @@ backup_config() {
echo "$backup" echo "$backup"
} }
is_mikefarah_yq() {
yq --version 2>&1 | grep -qi 'mikefarah'
}
update_yaml_with_yq() { update_yaml_with_yq() {
local cidr="$1" local cidr="$1"
if is_mikefarah_yq; then YQ_VAR_CIDR="$cidr" yq -i '
CIDR="$cidr" yq eval -i ' .rtc |= (. // {}) |
.rtc = (.rtc // {}) | .rtc.ips |= (. // {}) |
.rtc.ips = (.rtc.ips // {}) | .rtc.ips.includes = [env(YQ_VAR_CIDR)]
.rtc.ips.includes = [env(CIDR)]
' "$CONFIG_FILE" ' "$CONFIG_FILE"
else
yq -y -i --arg CIDR "$cidr" '
.rtc = (.rtc // {}) |
.rtc.ips = (.rtc.ips // {}) |
.rtc.ips.includes = [$CIDR]
' "$CONFIG_FILE"
fi
} }
update_yaml_fallback() { update_yaml_fallback() {
@@ -150,52 +138,32 @@ update_yaml_fallback() {
local tmp local tmp
tmp="$(mktemp)" tmp="$(mktemp)"
awk -v newcidr="$cidr" ' awk -v newcidr="$cidr" '
function indent_of(s, m,sp) { match(s,/^([ ]*)/,m); sp=length(m[1]); return sp } BEGIN{ in_rtc=0; in_ips=0; in_includes=0; injected=0 }
BEGIN { in_rtc=0; rtc_indent=-1; skipping_ips=0; ips_indent=-1; injected=0 }
{ {
line=$0 line=$0
ind=indent_of(line) if ($0 ~ /^[[:space:]]*rtc:[[:space:]]*$/) { in_rtc=1; in_ips=0; in_includes=0 }
else if (in_rtc && $0 ~ /^[[:space:]]*[[:alnum:]_]+:[[:space:]]*$/ && $0 !~ /^[[:space:]]*ips:/) {
if ($0 ~ /^[[:space:]]*rtc:[[:space:]]*$/) { if (!in_ips && !in_includes && !injected) {
in_rtc=1; rtc_indent=ind; injected=0
print line
next
}
if (in_rtc) {
if (skipping_ips) {
if (ind <= ips_indent) {
if (!injected) {
print " ips:" print " ips:"
print " includes:" print " includes:"
print " - " newcidr print " - " newcidr
injected=1 injected=1
} }
skipping_ips=0
} else { next }
} }
if (in_rtc && $0 ~ /^[[:space:]]*ips:[[:space:]]*$/) { in_ips=1; in_includes=0 }
if ($0 ~ /^[[:space:]]*ips:[[:space:]]*$/ && ind > rtc_indent) { if (in_ips && $0 ~ /^[[:space:]]*includes:[[:space:]]*$/) { in_includes=1; next }
skipping_ips=1; ips_indent=ind if (in_includes) {
if ($0 ~ /^[[:space:]]*-[[:space:]]*[^[:space:]]+/) {
next next
} } else {
if (ind <= rtc_indent && $0 ~ /^[[:alnum:]]_+:[[:space:]]*$/) {
if (!injected) { if (!injected) {
print " ips:"
print " includes:"
print " - " newcidr print " - " newcidr
injected=1 injected=1
} }
in_rtc=0; rtc_indent=-1 in_includes=0
print line in_ips=($0 ~ /^[[:space:]]*ips:/)?1:0
next
} }
print line
next
} }
print line print line
} }
END{ END{