Add fix_config_hard.sh for text-based config patching
This commit is contained in:
84
fix_config_hard.sh
Executable file
84
fix_config_hard.sh
Executable file
@@ -0,0 +1,84 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo "=== Hard Config Fixer ==="
|
||||||
|
echo "Replaces the permissions block in config.yaml using text manipulation to avoid YAML parser issues."
|
||||||
|
|
||||||
|
cat << 'PYTHON_SCRIPT' > hard_patch.py
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
config_file = "data/telegram/config.yaml"
|
||||||
|
|
||||||
|
if not os.path.exists(config_file):
|
||||||
|
print(f"Error: {config_file} not found.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print(f"Patching {config_file}...")
|
||||||
|
|
||||||
|
with open(config_file, 'r') as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
|
||||||
|
new_lines = []
|
||||||
|
skip = False
|
||||||
|
inserted = False
|
||||||
|
permissions_indent = -1
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
stripped = line.strip()
|
||||||
|
|
||||||
|
# Detect start of permissions block
|
||||||
|
if stripped.startswith("permissions:") and not inserted:
|
||||||
|
# Calculate indentation of the "permissions:" line
|
||||||
|
permissions_indent = len(line) - len(line.lstrip())
|
||||||
|
|
||||||
|
new_lines.append(line[:permissions_indent] + "permissions:\n")
|
||||||
|
|
||||||
|
# Indent for content is usually parent + 2 or + 4. We'll match the file style loosely or force 2 spaces relative to parent
|
||||||
|
# But since we are writing text, let's use the parent indent + 2 spaces (standard) or 4.
|
||||||
|
# Looking at grep output, it seemed to be 4 spaces for 'bridge', so permissions (child) likely 4 spaces?
|
||||||
|
# Let's use a safe indentation string based on parent.
|
||||||
|
base_indent = " " * (permissions_indent + 2) # minimal standard indent
|
||||||
|
if permissions_indent >= 4:
|
||||||
|
base_indent = " " * (permissions_indent + 4) # match likely 4-space indent style
|
||||||
|
|
||||||
|
# Force clean permissions block
|
||||||
|
new_lines.append(f'{base_indent}"*": "relay"\n')
|
||||||
|
new_lines.append(f'{base_indent}"@inswe:beeper.com": "admin"\n')
|
||||||
|
new_lines.append(f'{base_indent}"beeper.local": "user"\n')
|
||||||
|
new_lines.append(f'{base_indent}"beeper.com": "user"\n')
|
||||||
|
|
||||||
|
skip = True
|
||||||
|
inserted = True
|
||||||
|
continue
|
||||||
|
|
||||||
|
if skip:
|
||||||
|
# Determine if we are still inside the permissions block
|
||||||
|
current_indent = len(line) - len(line.lstrip())
|
||||||
|
|
||||||
|
# If empty line, keep skipping or preserve? Usually preserve empty lines but here we want to clean up.
|
||||||
|
if stripped == "":
|
||||||
|
continue
|
||||||
|
|
||||||
|
# If indentation is less than or equal to the permissions: line, we are out of the block
|
||||||
|
if current_indent <= permissions_indent:
|
||||||
|
skip = False
|
||||||
|
new_lines.append(line)
|
||||||
|
else:
|
||||||
|
# We are inside the old permissions block, so we skip this line
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
new_lines.append(line)
|
||||||
|
|
||||||
|
with open(config_file, 'w') as f:
|
||||||
|
f.writelines(new_lines)
|
||||||
|
|
||||||
|
print("Patch applied.")
|
||||||
|
PYTHON_SCRIPT
|
||||||
|
|
||||||
|
docker run --rm \
|
||||||
|
-v "$(pwd):/work" \
|
||||||
|
-w /work \
|
||||||
|
python:3.11-slim \
|
||||||
|
python hard_patch.py
|
||||||
|
|
||||||
|
rm hard_patch.py
|
||||||
Reference in New Issue
Block a user