Files
cnc_wams/web-rtcp-5axis-sim-plan/open-local.sh

37 lines
950 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
APP_DIR="/home/cnc/桌面/cnc_wams/web-rtcp-5axis-sim-plan/app/dist"
PORT="8092"
URL="http://127.0.0.1:${PORT}/"
LOG_DIR="${HOME}/.cache/web-rtcp-5axis-sim"
LOG_FILE="${LOG_DIR}/local-server.log"
mkdir -p "$LOG_DIR"
is_serving() {
curl -fsS --max-time 1 "$URL" >/dev/null 2>&1
}
if ! is_serving; then
nohup python3 -m http.server "$PORT" --bind 127.0.0.1 --directory "$APP_DIR" >"$LOG_FILE" 2>&1 &
for _ in $(seq 1 40); do
if is_serving; then
break
fi
sleep 0.1
done
fi
if command -v google-chrome-stable >/dev/null 2>&1; then
exec google-chrome-stable --new-window "$URL"
elif command -v google-chrome >/dev/null 2>&1; then
exec google-chrome --new-window "$URL"
elif command -v chromium >/dev/null 2>&1; then
exec chromium --new-window "$URL"
elif command -v chromium-browser >/dev/null 2>&1; then
exec chromium-browser --new-window "$URL"
else
exec xdg-open "$URL"
fi