From 169ea4b1e4627241a288259858df62a5f642fe5a Mon Sep 17 00:00:00 2001 From: Lloyd Date: Tue, 24 Feb 2026 10:59:30 +0000 Subject: [PATCH] Refactor config merging process to strip comments and update radio_type in Proxmox installer --- manage.sh | 11 +++++++++-- scripts/proxmox-install.sh | 13 +------------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/manage.sh b/manage.sh index 7e0838c..6cc99f5 100755 --- a/manage.sh +++ b/manage.sh @@ -902,7 +902,14 @@ validate_and_update_config() { # - Adds missing keys from the left operand (example config) local temp_merged="${config_file}.merged" - if "$YQ_CMD" eval-all '. as $item ireduce ({}; . * $item)' "$updated_example" "$config_file" > "$temp_merged" 2>/dev/null; then + # Strip comments from user config before merge to prevent comment accumulation. + # yq preserves comments from both files, so each upgrade cycle would duplicate + # the header and inline comments. We keep only the example's comments. + local stripped_user="${config_file}.stripped" + "$YQ_CMD" eval '... comments=""' "$config_file" > "$stripped_user" 2>/dev/null || cp "$config_file" "$stripped_user" + + if "$YQ_CMD" eval-all '. as $item ireduce ({}; . * $item)' "$updated_example" "$stripped_user" > "$temp_merged" 2>/dev/null; then + rm -f "$stripped_user" # Verify the merged file is valid YAML if "$YQ_CMD" eval '.' "$temp_merged" > /dev/null 2>&1; then mv "$temp_merged" "$config_file" @@ -917,7 +924,7 @@ validate_and_update_config() { fi else echo " ✗ Config merge failed, keeping original" - rm -f "$temp_merged" + rm -f "$temp_merged" "$stripped_user" return 1 fi } diff --git a/scripts/proxmox-install.sh b/scripts/proxmox-install.sh index 0308edb..27cce2c 100644 --- a/scripts/proxmox-install.sh +++ b/scripts/proxmox-install.sh @@ -220,18 +220,7 @@ pct exec "$CTID" -- bash -c " mkdir -p /etc/pymc_repeater if [ -f /root/pyMC_Repeater/config.yaml.example ]; then cp /root/pyMC_Repeater/config.yaml.example /etc/pymc_repeater/config.yaml - sed -i 's/^radio_type:.*/radio_type: sx1262_ch341/' /etc/pymc_repeater/config.yaml - # Add CH341 section if not present - if ! grep -q '^ch341:' /etc/pymc_repeater/config.yaml; then - cat >> /etc/pymc_repeater/config.yaml <<'CH341CFG' - -# CH341 USB-to-SPI adapter settings (only used when radio_type: sx1262_ch341) -# NOTE: VID/PID are integers. Hex is also accepted in YAML, e.g. 0x1A86. -ch341: - vid: 6790 # 0x1A86 - pid: 21778 # 0x5512 -CH341CFG - fi + sed -i 's/^radio_type: sx1262$/radio_type: sx1262_ch341/' /etc/pymc_repeater/config.yaml fi "