仰望星辰工作室

miaopanel

miaopanel/ scripts/verify-create.sh 2.1 KB · 45 行 原始文件
1#!/usr/bin/env bash
2# Verify runtime detection, package.json scanning and the site created by the
3# new dialog, then clean it up.
4set -uo pipefail
5ENTRY="${1:?usage: verify-create.sh <entry>}"
6BASE="http://127.0.0.1:8888/$ENTRY"
7PASS=$(awk -F': ' '/^password:/{print $2}' /www/server/panel/data/initial_password.txt)
8ORIGIN="http://127.0.0.1:8888"
9
10curl -s -c /tmp/ck.txt -H 'Content-Type: application/json' -H "Origin: $ORIGIN" \
11 -d "{\"username\":\"admin\",\"password\":\"$PASS\"}" "$BASE/api/v1/auth/login" >/dev/null
12CSRF=$(curl -s -b /tmp/ck.txt "$BASE/api/v1/auth/session" | python3 -c "import json,sys;print(json.load(sys.stdin)['data']['csrf'])")
13H=(-b /tmp/ck.txt -H "X-CSRF-Token: $CSRF" -H 'Content-Type: application/json' -H "Origin: $ORIGIN")
14
15echo "== 运行时探测 =="
16curl -s -b /tmp/ck.txt "$BASE/api/v1/system/runtimes"
17
18echo
19echo "== 写入 package.json 并读取 =="
20curl -s "${H[@]}" -X PUT -d '{"path":"/nodedemo/package.json","content":"{\"name\":\"nodedemo\",\"scripts\":{\"start\":\"node server.js\",\"dev\":\"node --watch server.js\"}}"}' \
21 "$BASE/api/v1/files/write" >/dev/null
22curl -s -b /tmp/ck.txt "$BASE/api/v1/sites/package?dir=%2Fnodedemo"
23
24echo
25echo "== 新弹窗创建的站点 =="
26curl -s -b /tmp/ck.txt "$BASE/api/v1/sites" | python3 -c "
27import json,sys
28for s in json.load(sys.stdin)['data']:
29 print(s['id'], s['name'], s['kind'], ','.join(s['domains']), s['root'])
30"
31SID=$(curl -s -b /tmp/ck.txt "$BASE/api/v1/sites" | python3 -c "
32import json,sys
33rows=[s['id'] for s in json.load(sys.stdin)['data'] if s['name']=='ui-create-test']
34print(rows[0] if rows else '')")
35
36if [ -n "$SID" ]; then
37 echo "vhost: $(ls /www/server/panel/vhost/nginx/ui-create-test.conf 2>/dev/null || echo missing)"
38 grep -E 'server_name|root ' /www/server/panel/vhost/nginx/ui-create-test.conf | head -2
39 curl -s "${H[@]}" -X DELETE "$BASE/api/v1/sites/$SID?remove_files=1"; echo
40 echo "after delete: $(ls /www/wwwroot/ui-create-test 2>/dev/null || echo removed)"
41fi
42
43# Remove the temporary package.json so nodedemo keeps its original layout.
44curl -s "${H[@]}" -X DELETE "$BASE/api/v1/files?path=%2Fnodedemo%2Fpackage.json" >/dev/null
45nginx -t 2>&1 | tail -1