Add fix_permissions.sh to configure user permissions
This commit is contained in:
81
fix_permissions.sh
Executable file
81
fix_permissions.sh
Executable file
@@ -0,0 +1,81 @@
|
||||
#!/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[admin_user] = "admin"
|
||||
changed = True
|
||||
print(f" - Added admin permission for {admin_user}")
|
||||
|
||||
# Add domain fallback (optional, but good for completeness if multiple users)
|
||||
# perms['*'] = "relay" # or whatever default, but sticking to specific user is safer for now
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user