#!/usr/bin/env bash # Verify runtime detection, package.json scanning and the site created by the # new dialog, then clean it up. set -uo pipefail ENTRY="${1:?usage: verify-create.sh }" BASE="http://127.0.0.1:8888/$ENTRY" PASS=$(awk -F': ' '/^password:/{print $2}' /www/server/panel/data/initial_password.txt) ORIGIN="http://127.0.0.1:8888" curl -s -c /tmp/ck.txt -H 'Content-Type: application/json' -H "Origin: $ORIGIN" \ -d "{\"username\":\"admin\",\"password\":\"$PASS\"}" "$BASE/api/v1/auth/login" >/dev/null CSRF=$(curl -s -b /tmp/ck.txt "$BASE/api/v1/auth/session" | python3 -c "import json,sys;print(json.load(sys.stdin)['data']['csrf'])") H=(-b /tmp/ck.txt -H "X-CSRF-Token: $CSRF" -H 'Content-Type: application/json' -H "Origin: $ORIGIN") echo "== 运行时探测 ==" curl -s -b /tmp/ck.txt "$BASE/api/v1/system/runtimes" echo echo "== 写入 package.json 并读取 ==" curl -s "${H[@]}" -X PUT -d '{"path":"/nodedemo/package.json","content":"{\"name\":\"nodedemo\",\"scripts\":{\"start\":\"node server.js\",\"dev\":\"node --watch server.js\"}}"}' \ "$BASE/api/v1/files/write" >/dev/null curl -s -b /tmp/ck.txt "$BASE/api/v1/sites/package?dir=%2Fnodedemo" echo echo "== 新弹窗创建的站点 ==" curl -s -b /tmp/ck.txt "$BASE/api/v1/sites" | python3 -c " import json,sys for s in json.load(sys.stdin)['data']: print(s['id'], s['name'], s['kind'], ','.join(s['domains']), s['root']) " SID=$(curl -s -b /tmp/ck.txt "$BASE/api/v1/sites" | python3 -c " import json,sys rows=[s['id'] for s in json.load(sys.stdin)['data'] if s['name']=='ui-create-test'] print(rows[0] if rows else '')") if [ -n "$SID" ]; then echo "vhost: $(ls /www/server/panel/vhost/nginx/ui-create-test.conf 2>/dev/null || echo missing)" grep -E 'server_name|root ' /www/server/panel/vhost/nginx/ui-create-test.conf | head -2 curl -s "${H[@]}" -X DELETE "$BASE/api/v1/sites/$SID?remove_files=1"; echo echo "after delete: $(ls /www/wwwroot/ui-create-test 2>/dev/null || echo removed)" fi # Remove the temporary package.json so nodedemo keeps its original layout. curl -s "${H[@]}" -X DELETE "$BASE/api/v1/files?path=%2Fnodedemo%2Fpackage.json" >/dev/null nginx -t 2>&1 | tail -1