Files
beeper-bridge-docker/fix_permissions.sh
2025-12-06 18:03:42 +00:00

94 lines
2.6 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.local"
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 and is a dict
if 'bridge' not in data:
data['bridge'] = {}
if 'permissions' not in data['bridge'] or not isinstance(data['bridge']['permissions'], dict):
data['bridge']['permissions'] = {}
changed = True
perms = data['bridge']['permissions']
# Force set permissions to ensure they are present
# We use string keys explicitly
# 1. Admin User
if str(admin_user) not in perms:
perms[str(admin_user)] = "admin"
changed = True
print(f" - Added admin permission for {admin_user}")
# 2. Domain Permission
if 'beeper.local' not in perms:
perms['beeper.local'] = "user"
changed = True
print(f" - Added permission for beeper.local")
# 3. Wildcard Fallback (safety net)
if '*' not in perms:
perms['*'] = "user"
changed = True
print(f" - Added wildcard (*) permission")
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