Refactor config merging process to strip comments and update radio_type in Proxmox installer

This commit is contained in:
Lloyd
2026-02-24 10:59:30 +00:00
parent b292a2a710
commit 169ea4b1e4
2 changed files with 10 additions and 14 deletions

View File

@@ -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
}

View File

@@ -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
"