#!/usr/bin/env python3 """Move this site's domain and HTTPS gateway into its actual BaoTa Go project. This migrates only panel metadata/configuration. It never deletes site files, restarts the Go process, or touches the application's MySQL database. """ import json import os import shutil import sqlite3 import subprocess import sys import time import urllib.request from pathlib import Path PANEL = Path('/www/server/panel') DOMAIN = 'im.bchongw.com' PROJECT = 'xingyu_im' OLD_CONF = PANEL / 'vhost/nginx/html_im.bchongw.com.conf' GO_CONF = PANEL / 'vhost/nginx/go_xingyu_im.conf' ROUTES = PANEL / 'vhost/nginx/extension/xingyu_im/xingyu_routes.conf' CERT = PANEL / 'vhost/cert/xingyu_im' SITE_DB = PANEL / 'data/db/site.db' def run(*args): result = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) if result.returncode: raise RuntimeError('{} failed: {}'.format(args[0], result.stderr.strip())) def write_private(path, text, mode=0o600): fd = os.open(str(path), os.O_WRONLY | os.O_CREAT | os.O_EXCL, mode) with os.fdopen(fd, 'w', encoding='utf-8') as target: target.write(text) def check_public(): for path, content in (('/healthz', '"status":"ok"'), ('/admin/', '星遇社交运营中心'), ('/app/', '星遇社交'), ('/app/static/favicon.svg', ' 1 else 'verify' if action not in ('migrate', 'verify'): raise SystemExit('Usage: baota_bind_go_domain.py [migrate|verify]') {'migrate': migrate, 'verify': verify}[action]()