nomadro/apps/admin/deploy/fix_login.py
eric 3e5b7c2098 Monorepo super-optimize: src layout, workspace scripts, docs.
Collapse portal under src/, unify pnpm workspace/scripts, thin VIP topic re-exports, drop orphan vip scaffolds and one-shot scripts, ignore xhs/release, document root commands.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-01 00:34:04 +08:00

52 lines
1.8 KiB
Python

import io
import tarfile
import tempfile
from pathlib import Path
import paramiko
from scp import SCPClient
ROOT = Path(__file__).resolve().parents[1]
HOST = "82.157.112.245"
USER = "ubuntu"
PASSWORD = "Xiao4669805"
tmp = tempfile.NamedTemporaryFile(suffix=".tar.gz", delete=False)
tmp.close()
tar_path = Path(tmp.name)
with tarfile.open(tar_path, "w:gz") as tar:
for rel in ["app/services/wxpay.py", "app/config.py"]:
p = ROOT / "backend" / rel
data = p.read_bytes().replace(b"\r\n", b"\n")
info = tarfile.TarInfo(name=rel)
info.size = len(data)
tar.addfile(info, fileobj=io.BytesIO(data))
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, username=USER, password=PASSWORD, timeout=30)
with SCPClient(c.get_transport()) as scp:
scp.put(str(tar_path), "/tmp/login-fix.tar.gz")
cmd = r"""
set -e
cd /tmp && rm -rf login-fix && mkdir login-fix && tar -xzf login-fix.tar.gz -C login-fix
cp login-fix/app/services/wxpay.py /opt/nomadmini/backend/app/services/wxpay.py
cp login-fix/app/config.py /opt/nomadmini/backend/app/config.py
ENV=/opt/nomadmini/backend/.env
grep -q '^WX_ALLOW_DEVTOOLS_LOGIN=' $ENV && sed -i 's/^WX_ALLOW_DEVTOOLS_LOGIN=.*/WX_ALLOW_DEVTOOLS_LOGIN=true/' $ENV || echo 'WX_ALLOW_DEVTOOLS_LOGIN=true' >> $ENV
sudo systemctl restart nomadmini-api
sleep 2
# test mock login
curl -s -X POST http://127.0.0.1:8010/api/auth/login -H 'Content-Type: application/json' -d '{"code":"the code is a mock one"}'
echo
curl -s http://127.0.0.1:8010/health
echo
rm -rf login-fix login-fix.tar.gz
"""
_, o, e = c.exec_command(cmd)
print(o.read().decode("utf-8", "replace").encode("ascii", "replace").decode())
print(e.read().decode("utf-8", "replace").encode("ascii", "replace").decode())
c.close()
tar_path.unlink(missing_ok=True)