85 lines
2.4 KiB
Bash
Executable File
85 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
echo "=== Bridge Permission Fixer ==="
|
|
echo "Adds default permissions for your user to config.yaml"
|
|
|
|
# Default user ID from bbctl output provided earlier (@inswe:beeper.com)
|
|
# We can also make this interactive or take arguments, but let's be smart.
|
|
DEFAULT_USER="@inswe:beeper.com"
|
|
|
|
echo "Target User: $DEFAULT_USER (admin)"
|
|
|
|
cat << 'PYTHON_SCRIPT' > fix_permissions.py
|
|
import sys
|
|
import os
|
|
|
|
try:
|
|
from ruamel.yaml import YAML
|
|
except ImportError:
|
|
import subprocess
|
|
subprocess.check_call([sys.executable, "-m", "pip", "install", "ruamel.yaml"])
|
|
from ruamel.yaml import YAML
|
|
|
|
yaml = YAML()
|
|
yaml.preserve_quotes = True
|
|
|
|
services = ["telegram"]
|
|
base_dir = "data"
|
|
admin_user = "@inswe:beeper.com"
|
|
domain = "beeper.com" # Implicitly trusted usually, but we set specific user
|
|
|
|
for service in services:
|
|
config_path = os.path.join(base_dir, service, "config.yaml")
|
|
|
|
if not os.path.exists(config_path):
|
|
continue
|
|
|
|
print(f"[{service}] Checking permissions...")
|
|
try:
|
|
with open(config_path, 'r') as f:
|
|
data = yaml.load(f)
|
|
|
|
changed = False
|
|
|
|
# Ensure bridge.permissions structure exists
|
|
if 'bridge' not in data:
|
|
data['bridge'] = {}
|
|
|
|
if 'permissions' not in data['bridge'] or data['bridge']['permissions'] is None:
|
|
data['bridge']['permissions'] = {}
|
|
changed = True
|
|
|
|
perms = data['bridge']['permissions']
|
|
|
|
# Add admin user if missing
|
|
if admin_user not in perms:
|
|
perms[str(admin_user)] = "admin"
|
|
changed = True
|
|
print(f" - Added admin permission for {admin_user}")
|
|
|
|
# Add domain fallback to ensure valid config structure if specific user fails
|
|
if 'beeper.com' not in perms:
|
|
perms['beeper.com'] = "user"
|
|
changed = True
|
|
print(f" - Added basic permission for beeper.com domain")
|
|
|
|
if changed:
|
|
with open(config_path, 'w') as f:
|
|
yaml.dump(data, f)
|
|
print(f"[{service}] Permissions updated.")
|
|
else:
|
|
print(f"[{service}] Permissions already OK.")
|
|
|
|
except Exception as e:
|
|
print(f"[{service}] Error: {e}")
|
|
|
|
PYTHON_SCRIPT
|
|
|
|
docker run --rm \
|
|
-v "$(pwd):/work" \
|
|
-w /work \
|
|
python:3.11-slim \
|
|
sh -c "pip install ruamel.yaml && python fix_permissions.py"
|
|
|
|
rm fix_permissions.py
|