补充 world geo nginx snippet、OpenAPI/geo 热更新脚本,以及 popadmin package_name 定价补丁,便于运维对齐。 Co-authored-by: Cursor <cursoragent@cursor.com>
77 lines
2.5 KiB
Bash
77 lines
2.5 KiB
Bash
#!/bin/bash
|
||
# Serve echarts world map GeoJSON at /admin/geo/world.json on popadmin.
|
||
# Avoids location / catching the path and 302'ing HTML (breaks resp.json()).
|
||
set -euo pipefail
|
||
|
||
CONF=/etc/nginx/conf.d/popadmin-wyrs.conf
|
||
GEO_DIR=/opt/wyrs-admin/static-override/geo
|
||
GEO_FILE="$GEO_DIR/world.json"
|
||
|
||
if [[ ! -f "$GEO_FILE" ]]; then
|
||
echo "ERROR: missing $GEO_FILE — upload world.json first" >&2
|
||
exit 1
|
||
fi
|
||
chmod 644 "$GEO_FILE"
|
||
ls -la "$GEO_FILE"
|
||
|
||
MARKER_BEGIN='# BEGIN popadmin-world-geo'
|
||
if grep -Fq "$MARKER_BEGIN" "$CONF"; then
|
||
echo "nginx world-geo snippet already present"
|
||
else
|
||
cp -a "$CONF" "$CONF.bak.worldgeo.$(date +%Y%m%d%H%M%S)"
|
||
python3 <<'PY'
|
||
from pathlib import Path
|
||
conf = Path("/etc/nginx/conf.d/popadmin-wyrs.conf")
|
||
text = conf.read_text()
|
||
snip = """
|
||
# BEGIN popadmin-world-geo
|
||
# echarts 世界地图底图(勿被 location / 302 成 HTML)
|
||
location = /admin/geo/world.json {
|
||
alias /opt/wyrs-admin/static-override/geo/world.json;
|
||
default_type application/json;
|
||
add_header Cache-Control "public, max-age=86400";
|
||
}
|
||
# END popadmin-world-geo
|
||
"""
|
||
needle = " location / {\n return 302 /popadmin/;\n }"
|
||
if needle in text:
|
||
text = text.replace(needle, snip + "\n" + needle, 1)
|
||
else:
|
||
idx = text.rfind(" location / {")
|
||
if idx < 0:
|
||
raise SystemExit("cannot find location / insert point")
|
||
text = text[:idx] + snip + "\n" + text[idx:]
|
||
conf.write_text(text)
|
||
print("nginx conf patched with world-geo location")
|
||
PY
|
||
fi
|
||
|
||
nginx -t
|
||
systemctl reload nginx
|
||
echo "nginx reloaded"
|
||
|
||
# smoke via localhost Host header (HTTP → may redirect; prefer HTTPS if available)
|
||
python3 <<'PY'
|
||
import json, ssl, urllib.request
|
||
ctx = ssl._create_unverified_context()
|
||
url = "https://127.0.0.1/admin/geo/world.json"
|
||
req = urllib.request.Request(url, headers={"Host": "popadmin.wyrs365.com"})
|
||
try:
|
||
with urllib.request.urlopen(req, context=ctx, timeout=20) as r:
|
||
raw = r.read()
|
||
ct = r.headers.get("Content-Type", "")
|
||
print("status", r.status, "ct", ct, "bytes", len(raw))
|
||
d = json.loads(raw)
|
||
print("OK type=", d.get("type"), "features=", len(d.get("features") or []))
|
||
except Exception as e:
|
||
print("HTTPS smoke FAIL", e)
|
||
# fallback: direct file check
|
||
import pathlib
|
||
p = pathlib.Path("/opt/wyrs-admin/static-override/geo/world.json")
|
||
d = json.loads(p.read_text(encoding="utf-8"))
|
||
print("file OK type=", d.get("type"), "features=", len(d.get("features") or []))
|
||
PY
|
||
|
||
grep -n "popadmin-world-geo\|admin/geo/world" "$CONF" | head -20
|
||
echo DONE
|