forked from mtusi2026/mtusi2026lab5
13 lines
1.1 KiB
Python
13 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Grant the local operations UI to an existing messenger account."""
|
|
import re,subprocess,sys
|
|
from pathlib import Path
|
|
root=Path(__file__).resolve().parents[1]
|
|
if len(sys.argv)!=2 or not re.fullmatch('[a-z0-9_]{3,32}',sys.argv[1]):raise SystemExit('Укажите логин: make operator USERNAME=n1k0der')
|
|
result=subprocess.check_output([str(root/'scripts/compose.sh'),'exec','-T','postgres','psql','-U','messenger','-d','messenger','-At','-c',"SELECT id FROM users WHERE username='"+sys.argv[1]+"'"],cwd=root,text=True).strip()
|
|
if not result:raise SystemExit('Сначала зарегистрируйте этот аккаунт в мессенджере')
|
|
p=root/'.env';lines=p.read_text().splitlines() if p.exists() else []
|
|
lines=[line for line in lines if not line.startswith('OPS_USER_ID=')];lines.append('OPS_USER_ID='+result);p.write_text('\n'.join(lines)+'\n');p.chmod(0o600)
|
|
subprocess.run([str(root/'scripts/compose.sh'),'up','-d','--no-deps','--wait','api'],cwd=root,check=True)
|
|
print('Панель доступна аккаунту '+sys.argv[1]+'. Перезайдите в мессенджер.')
|