仰望星辰工作室

miaopanel

miaopanel/ scripts/verify-go-unit.sh 1.8 KB · 37 行 原始文件
1#!/usr/bin/env bash
2# Recreate the Go site and inspect the generated systemd unit by its real slug.
3set -uo pipefail
4ENTRY="${1:-ipdduiyy}"
5BASE="http://127.0.0.1:8888/$ENTRY"
6PASS=$(awk -F': ' '/^password:/{print $2}' /www/server/panel/data/initial_password.txt)
7ORIGIN="http://127.0.0.1:8888"
8
9mkdir -p /www/wwwroot/goauto2
10cp /bin/true /www/wwwroot/goauto2/server 2>/dev/null || true
11# Use the existing Go test binary if it is still around.
12[ -f /tmp/goapp ] && cp /tmp/goapp /www/wwwroot/goauto2/server
13chmod 0755 /www/wwwroot/goauto2/server
14
15curl -s -c /tmp/ck.txt -H 'Content-Type: application/json' -H "Origin: $ORIGIN" \
16 -d "{\"username\":\"admin\",\"password\":\"$PASS\"}" "$BASE/api/v1/auth/login" >/dev/null
17CSRF=$(curl -s -b /tmp/ck.txt "$BASE/api/v1/auth/session" | python3 -c "import json,sys;print(json.load(sys.stdin)['data']['csrf'])")
18H=(-b /tmp/ck.txt -H "X-CSRF-Token: $CSRF" -H 'Content-Type: application/json' -H "Origin: $ORIGIN")
19
20curl -s "${H[@]}" -d '{"kind":"go","domains":["go2.auto"],"root":"/goauto2","port":8132,"env":"PORT=8132"}' \
21 "$BASE/api/v1/sites" > /tmp/go2.json
22python3 -c "
23import json
24d=json.load(open('/tmp/go2.json'))['data']
25print('slug=%s name=%s start_cmd=%s port=%s' % (d['slug'], d['name'], d['start_cmd'], d['port']))"
26
27SLUG=$(python3 -c "import json;print(json.load(open('/tmp/go2.json'))['data']['slug'])")
28UNIT="/etc/systemd/system/miaopanel-site-$SLUG.service"
29echo "unit: $UNIT"
30grep -E 'ExecStart|WorkingDirectory|EnvironmentFile' "$UNIT"
31systemctl is-active "miaopanel-site-$SLUG.service"
32curl -s --max-time 5 -H 'Host: go2.auto' http://127.0.0.1/ || true
33
34SID=$(python3 -c "import json;print(json.load(open('/tmp/go2.json'))['data']['id'])")
35curl -s "${H[@]}" -X DELETE "$BASE/api/v1/sites/$SID?remove_files=1" >/dev/null
36rm -rf /www/wwwroot/goauto2
37echo "cleanup done"