#!/usr/bin/env bash
# Start the Cloudflare credentials setup web interface

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
VENV_DIR="$PROJECT_DIR/venv"

cd "$PROJECT_DIR"

# Create virtual environment if it doesn't exist
if [[ ! -d "$VENV_DIR" ]]; then
    echo "Creating virtual environment..."
    python3 -m venv "$VENV_DIR"
fi

# Activate virtual environment
source "$VENV_DIR/bin/activate"

# Install dependencies if needed
if ! python -c "import flask" 2>/dev/null; then
    echo "Installing Flask and requests..."
    pip install flask requests --quiet
fi

# Start the web server
echo "Starting Cloudflare Setup Web Interface..."
python "$SCRIPT_DIR/cloudflare-setup-web.py"

