#!/usr/bin/env bash # Recreate the Go site and inspect the generated systemd unit by its real slug. set -uo pipefail ENTRY="${1:-ipdduiyy}" 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" mkdir -p /www/wwwroot/goauto2 cp /bin/true /www/wwwroot/goauto2/server 2>/dev/null || true # Use the existing Go test binary if it is still around. [ -f /tmp/goapp ] && cp /tmp/goapp /www/wwwroot/goauto2/server chmod 0755 /www/wwwroot/goauto2/server 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") curl -s "${H[@]}" -d '{"kind":"go","domains":["go2.auto"],"root":"/goauto2","port":8132,"env":"PORT=8132"}' \ "$BASE/api/v1/sites" > /tmp/go2.json python3 -c " import json d=json.load(open('/tmp/go2.json'))['data'] print('slug=%s name=%s start_cmd=%s port=%s' % (d['slug'], d['name'], d['start_cmd'], d['port']))" SLUG=$(python3 -c "import json;print(json.load(open('/tmp/go2.json'))['data']['slug'])") UNIT="/etc/systemd/system/miaopanel-site-$SLUG.service" echo "unit: $UNIT" grep -E 'ExecStart|WorkingDirectory|EnvironmentFile' "$UNIT" systemctl is-active "miaopanel-site-$SLUG.service" curl -s --max-time 5 -H 'Host: go2.auto' http://127.0.0.1/ || true SID=$(python3 -c "import json;print(json.load(open('/tmp/go2.json'))['data']['id'])") curl -s "${H[@]}" -X DELETE "$BASE/api/v1/sites/$SID?remove_files=1" >/dev/null rm -rf /www/wwwroot/goauto2 echo "cleanup done"