#!/bin/bash
# Deployment script untuk Laravel Reverb di cPanel

# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m'

echo -e "${BLUE}================================================${NC}"
echo -e "${BLUE}Laravel Reverb Deployment to cPanel${NC}"
echo -e "${BLUE}================================================${NC}\n"

# Step 1: Upload files
echo -e "${YELLOW}Step 1: Preparing files for upload...${NC}"
echo "✓ Public folder (assets already built)"
echo "✓ App folder"
echo "✓ Routes folder"
echo "✓ Config folder"
echo "✓ Database folder (SQLite)"
echo "✓ Resources folder"
echo "✓ Storage folder"
echo "✓ Bootstrap folder"
echo "✓ Vendor folder (composer dependencies)"
echo -e "${GREEN}✓ All essential folders prepared${NC}\n"

# Step 2: Database
echo -e "${YELLOW}Step 2: Database Setup${NC}"
echo "Current: SQLite (database.sqlite)"
echo "✓ No setup needed - database is portable"
echo "Note: Make sure storage/app/database.sqlite is writable\n"

# Step 3: Reverb Server
echo -e "${YELLOW}Step 3: Reverb WebSocket Server${NC}"
echo "⚠️  IMPORTANT for cPanel shared hosting:"
echo ""
echo "Option A: Use external Reverb service (Recommended)"
echo "  - Use existing Reverb instance on your server"
echo "  - Or use Pusher/Ably as alternative"
echo ""
echo "Option B: Run via SSH"
echo "  - SSH into cPanel account"
echo "  - Run: php artisan reverb:start"
echo "  - Use process manager to keep it running"
echo ""
echo "For production, update .env.production:"
echo "  REVERB_HOST=sensors.moscamp.site"
echo "  REVERB_PORT=443"
echo "  REVERB_SCHEME=https\n"

# Step 4: File Permissions
echo -e "${YELLOW}Step 4: Set File Permissions${NC}"
echo "Run these commands via SSH:"
echo "  chmod -R 755 public/"
echo "  chmod -R 775 storage/"
echo "  chmod -R 775 bootstrap/cache/"
echo "  chmod 644 .env\n"

# Step 5: Final checks
echo -e "${YELLOW}Step 5: Final Configuration${NC}"
echo "✓ Update APP_URL in .env to: https://sensors.moscamp.site"
echo "✓ Ensure APP_DEBUG=false for production"
echo "✓ Set APP_ENV=production"
echo "✓ Generate APP_KEY if needed: php artisan key:generate"
echo ""
echo -e "${GREEN}================================================${NC}"
echo -e "${GREEN}Deployment Guide Complete!${NC}"
echo -e "${GREEN}================================================${NC}\n"
