#!/bin/sh set -eu SCRIPT_DIR="$(CDPATH= cd -- "$(dirname "$0")" && pwd)" REPO_DIR="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd)" LOCAL_DIR="$REPO_DIR/.local" PROFILE_DIR="${1:-${STEAMDB_PROFILE_DIR:-$LOCAL_DIR/playwright-steamdb-profile}}" PORT="${2:-${STEAMDB_CDP_PORT:-55685}}" URL="${STEAMDB_BOOTSTRAP_URL:-https://steamdb.info/app/4165870/}" ENV_FILE="${STEAMDB_ENV_FILE:-$LOCAL_DIR/steamdb-env.sh}" mkdir -p "$PROFILE_DIR" "$LOCAL_DIR" existing_pid="$(ps aux | awk -v profile="$PROFILE_DIR" -v port="$PORT" ' index($0, "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome") && index($0, profile) && index($0, "--remote-debugging-port=" port) { print $2 exit } ')" if [ -z "$existing_pid" ]; then open -g -na "Google Chrome" --args \ "--user-data-dir=$PROFILE_DIR" \ "--remote-debugging-port=$PORT" \ --no-first-run \ --disable-sync \ --new-window \ "$URL" attempts=0 until curl -fsS "http://127.0.0.1:$PORT/json/version" >/dev/null 2>&1; do attempts=$((attempts + 1)) if [ "$attempts" -ge 30 ]; then echo "failed to observe a Chrome CDP endpoint on port $PORT" >&2 exit 1 fi sleep 1 done else echo "SteamDB bootstrap browser already running on port $PORT (pid $existing_pid)." fi cat > "$ENV_FILE" <