#!/bin/bash # Cloudflare Tunnel Setup Script for PMFlow set -e echo "🚀 Starting Cloudflare Tunnel Setup..." # Check if cloudflared is installed if ! command -v cloudflared &> /dev/null; then echo "❌ cloudflared is not installed. Please install it first:" echo " brew install cloudflared" exit 1 fi # Ask for configuration read -p "Enter your domain name (e.g., dev.pmflow.com): " DOMAIN_NAME read -p "Enter a name for your tunnel (e.g., pmflow-dev): " TUNNEL_NAME if [ -z "$DOMAIN_NAME" ] || [ -z "$TUNNEL_NAME" ]; then echo "❌ Domain name and tunnel name are required." exit 1 fi echo "Checking authentication..." # Check if cert.pem exists in default location if [ ! -f "$HOME/.cloudflared/cert.pem" ]; then echo "âš ī¸ You need to login to Cloudflare first." cloudflared tunnel login fi echo "Creating tunnel '$TUNNEL_NAME'..." # Check if tunnel exists, if not create it if ! cloudflared tunnel list | grep -q "$TUNNEL_NAME"; then cloudflared tunnel create "$TUNNEL_NAME" else echo "â„šī¸ Tunnel '$TUNNEL_NAME' already exists." fi echo "Routing DNS..." # Route DNS cloudflared tunnel route dns "$TUNNEL_NAME" "$DOMAIN_NAME" # Get Tunnel ID TUNNEL_ID=$(cloudflared tunnel list | grep "$TUNNEL_NAME" | awk '{print $1}') if [ -z "$TUNNEL_ID" ]; then echo "❌ Could not find Tunnel ID for '$TUNNEL_NAME'" exit 1 fi echo "Generating config file..." # Create config.yml cat > devops/tunnel/config.yml <> "$ENV_FILE" fi echo "✅ Updated $ENV_FILE with VITE_APP_DOMAIN=$DOMAIN_NAME" echo "🎉 Setup complete! You can now run the tunnel with:" echo " cloudflared tunnel run --config devops/tunnel/config.yml $TUNNEL_NAME"