#!/usr/bin/env bash # scripts/start-chrome-new-profile.sh # Crea un perfil nuevo y arranca Chrome (google-chrome-stable) con remote debugging # Uso: # ./scripts/start-chrome-new-profile.sh [start|foreground|headless] # Ejemplos: # ./scripts/start-chrome-new-profile.sh start # ./scripts/start-chrome-new-profile.sh foreground # ./scripts/start-chrome-new-profile.sh headless set -euo pipefail MODE=${1:-start} TIMESTAMP=$(date +%s) PROFILE_DIR="$HOME/.config/avanzacast-remote-profile-new-$TIMESTAMP" CHROME_BIN=${CHROME_BIN:-/usr/bin/google-chrome-stable} PORT=${PORT:-9222} LOG=avanzacast-chrome-new-$TIMESTAMP.log ERR=avanzacast-chrome-new-$TIMESTAMP.err if [ ! -x "$CHROME_BIN" ]; then echo "ERROR: Chrome binary not found or not executable: $CHROME_BIN" echo "Please install Chrome or set CHROME_BIN to the path of your Chrome binary." exit 1 fi mkdir -p "$PROFILE_DIR" chmod 700 "$PROFILE_DIR" # Kill previous debug listeners lsof -ti :$PORT | xargs -r kill -9 || true case "$MODE" in foreground) echo "Running Chrome in foreground with profile: $PROFILE_DIR" exec "$CHROME_BIN" \ --remote-debugging-port=$PORT \ --remote-debugging-address=127.0.0.1 \ --user-data-dir="$PROFILE_DIR" \ --no-first-run \ --no-default-browser-check \ --disable-dev-shm-usage \ --disable-gpu \ --start-maximized \ --v=1 ;; headless) echo "Starting Chrome headless with profile: $PROFILE_DIR (logs: $LOG, $ERR)" nohup "$CHROME_BIN" \ --headless \ --remote-debugging-port=$PORT \ --remote-debugging-address=127.0.0.1 \ --user-data-dir="$PROFILE_DIR" \ --no-sandbox --disable-gpu --disable-dev-shm-usage \ > "$LOG" 2> "$ERR" & echo $! > /tmp/avanzacast-chrome-new-$TIMESTAMP.pid sleep 2 echo "PID: $(cat /tmp/avanzacast-chrome-new-$TIMESTAMP.pid)" echo "curl http://127.0.0.1:$PORT/json/version" curl -sS "http://127.0.0.1:$PORT/json/version" || true echo "Tail of logs ($LOG / $ERR):" tail -n 200 "$LOG" || true tail -n 200 "$ERR" || true ;; start) echo "Starting Chrome in background with profile: $PROFILE_DIR (logs: $LOG, $ERR)" nohup "$CHROME_BIN" \ --remote-debugging-port=$PORT \ --remote-debugging-address=127.0.0.1 \ --user-data-dir="$PROFILE_DIR" \ --no-first-run --no-default-browser-check \ --disable-dev-shm-usage --disable-gpu \ > "$LOG" 2> "$ERR" & PID=$! echo $PID > /tmp/avanzacast-chrome-new-$TIMESTAMP.pid sleep 2 echo "PID: $PID" echo "curl http://127.0.0.1:$PORT/json/version" curl -sS "http://127.0.0.1:$PORT/json/version" || true echo "Tail of logs ($LOG / $ERR):" tail -n 200 "$LOG" || true tail -n 200 "$ERR" || true ;; *) echo "Unknown mode: $MODE" echo "Usage: $0 [start|foreground|headless]" exit 2 ;; esac echo "Profile dir created: $PROFILE_DIR" # Print helpful next steps cat <