#!/usr/bin/env bash # Interactive setup for Cloudflare API credentials # Usage: ./setup-cloudflare-env.sh SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ENV_FILE="$SCRIPT_DIR/../.env" echo "Cloudflare API Credentials Setup" echo "=================================" echo "" # Check if .env exists if [[ -f "$ENV_FILE" ]]; then echo "Found existing .env file: $ENV_FILE" read -p "Overwrite? (y/N): " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "Keeping existing .env file" exit 0 fi fi echo "" echo "Choose authentication method:" echo "1. API Token (Recommended - more secure)" echo "2. Email + API Key (Legacy)" read -p "Choice [1-2]: " -n 1 -r echo "" if [[ $REPLY == "1" ]]; then echo "" echo "Get your API Token from:" echo " https://dash.cloudflare.com/profile/api-tokens" echo " Create token with: Zone:Edit, Account:Cloudflare Tunnel:Edit permissions" echo "" read -p "Enter Cloudflare API Token: " -s CLOUDFLARE_API_TOKEN echo "" if [[ -z "$CLOUDFLARE_API_TOKEN" ]]; then echo "Error: API Token cannot be empty" exit 1 fi cat > "$ENV_FILE" < "$ENV_FILE" <