#!/bin/bash # TrustOS Cloudflare Tunnel Quick Setup # This script guides you through setting up remote access via Cloudflare set -e echo "╔════════════════════════════════════════════════════════════════╗" echo "║ 🌐 TRUSTOS CLOUDFLARE TUNNEL SETUP ║" echo "╚════════════════════════════════════════════════════════════════╝" echo "" # Check if cloudflared is installed if ! command -v cloudflared &> /dev/null; then echo "❌ cloudflared not installed" echo "" echo "Installing Cloudflare tunnel..." curl -s -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o /usr/local/bin/cloudflared chmod +x /usr/local/bin/cloudflared echo "✅ cloudflared installed" fi echo "" echo "📋 SETUP STEPS:" echo "═════════════════════════════════════════════════════════════════" echo "" # Step 1: Login echo "STEP 1️⃣ : Authenticate with Cloudflare" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" echo "This will open a browser to authenticate. You need:" echo " ✓ Cloudflare account (free tier works)" echo " ✓ Internet browser" echo "" echo "Press ENTER to continue or Ctrl+C to cancel..." read -r cloudflared tunnel login echo "" echo "✅ Authenticated!" echo "" # Step 2: Create tunnel echo "STEP 2️⃣ : Create Tunnel" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" cloudflared tunnel create trustos echo "" echo "✅ Tunnel 'trustos' created!" echo "" # Step 3: Get domain echo "STEP 3️⃣ : Configure Domain" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" echo "You can:" echo " A) Use Cloudflare DNS (simplest)" echo " B) Use your own domain registrar" echo "" echo "Enter your domain (e.g., trustos.example.com): " read -r DOMAIN if [ -z "$DOMAIN" ]; then echo "❌ No domain provided. Exiting." exit 1 fi echo "" echo "Setting up domain: $DOMAIN" echo "" # Route DNS cloudflared tunnel route dns trustos "$DOMAIN" echo "" echo "✅ Domain routed!" echo "" # Step 4: Start tunnel echo "STEP 4️⃣ : Start Tunnel" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" echo "Choose how to run the tunnel:" echo "" echo "Option A) As systemd service (background, automatic restarts)" echo "Option B) Manual (foreground, for testing)" echo "" echo "Enter choice (A/B): " read -r CHOICE if [ "$CHOICE" = "A" ] || [ "$CHOICE" = "a" ]; then echo "" echo "Starting tunnel service..." systemctl restart trustos-tunnel systemctl enable trustos-tunnel echo "" echo "⏳ Waiting for tunnel to start..." sleep 3 if systemctl is-active --quiet trustos-tunnel; then echo "✅ Tunnel service started!" echo "" echo "View logs: journalctl -u trustos-tunnel -f" else echo "❌ Failed to start service. Trying manual mode..." CHOICE="B" fi fi if [ "$CHOICE" = "B" ] || [ "$CHOICE" = "b" ]; then echo "" echo "Starting tunnel (foreground mode)..." echo "Press Ctrl+C to stop" echo "" cloudflared tunnel run trustos --url http://localhost:80 fi echo "" echo "╔════════════════════════════════════════════════════════════════╗" echo "║ 🎉 SETUP COMPLETE! ║" echo "╚════════════════════════════════════════════════════════════════╝" echo "" echo "🌐 Your TrustOS instance is now accessible at:" echo "" echo " https://$DOMAIN" echo "" echo "📊 Tunnel Information:" cloudflared tunnel info trustos echo "" echo "🔐 Demo Credentials:" echo " Email: executive@acmecorp.io" echo " Password: TrustOS2024!" echo "" echo "⚙️ Management:" echo " View tunnel status: cloudflared tunnel info trustos" echo " View tunnel logs: journalctl -u trustos-tunnel -f" echo " Stop tunnel: systemctl stop trustos-tunnel" echo " Restart tunnel: systemctl restart trustos-tunnel" echo "" echo "💡 Tip: Share the HTTPS URL with anyone to give them access!" echo ""