cinema-studio-pro/setup.sh
2026-01-19 11:53:17 +05:30

182 lines
5.9 KiB
Bash

#!/bin/bash
# ============================================================================
# Lux Studio - Local Development Setup Script
# ============================================================================
# This script sets up both frontend and backend for LOCAL development
# For production deployment, use deploy.sh instead
# ============================================================================
set -e # Exit on any error
echo "🎬 Setting up Lux Studio for Local Development..."
echo ""
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# ============================================================================
# 1. CHECK PREREQUISITES
# ============================================================================
echo "${BLUE}Step 1: Checking prerequisites...${NC}"
if ! command -v node &> /dev/null; then
echo "${RED}✗ Node.js not found. Please install Node.js 18+ first.${NC}"
exit 1
fi
if ! command -v npm &> /dev/null; then
echo "${RED}✗ npm not found. Please install npm first.${NC}"
exit 1
fi
if ! command -v php &> /dev/null; then
echo "${RED}✗ PHP not found. Please install PHP 7.4+ first.${NC}"
exit 1
fi
if ! command -v composer &> /dev/null; then
echo "${RED}✗ Composer not found. Please install Composer first.${NC}"
exit 1
fi
echo "${GREEN}✓ All prerequisites installed${NC}"
echo " Node.js: $(node --version)"
echo " npm: $(npm --version)"
echo " PHP: $(php --version | head -n 1)"
echo " Composer: $(composer --version | head -n 1)"
echo ""
# ============================================================================
# 2. SETUP BACKEND
# ============================================================================
echo "${BLUE}Step 2: Setting up backend...${NC}"
cd backend
# Create .env from .env.local
if [ ! -f ".env" ]; then
if [ -f ".env.local" ]; then
echo " → Creating backend/.env from .env.local..."
cp .env.local .env
echo "${GREEN} ✓ backend/.env created with local development settings${NC}"
else
echo "${RED} ✗ Error: .env.local not found${NC}"
echo " Please ensure backend/.env.local exists"
exit 1
fi
else
echo "${GREEN} ✓ backend/.env already exists${NC}"
fi
# Install PHP dependencies
echo " → Installing PHP dependencies via Composer..."
composer install --quiet
if [ $? -eq 0 ]; then
echo "${GREEN}✓ Backend setup complete${NC}"
else
echo "${RED}✗ Backend setup failed${NC}"
exit 1
fi
cd ..
echo ""
# ============================================================================
# 3. SETUP FRONTEND
# ============================================================================
echo "${BLUE}Step 3: Setting up frontend...${NC}"
cd frontend
# Create .env from .env.local
if [ ! -f ".env" ]; then
if [ -f ".env.local" ]; then
echo " → Creating frontend/.env from .env.local..."
cp .env.local .env
echo "${GREEN} ✓ frontend/.env created with local development settings${NC}"
else
echo "${RED} ✗ Error: .env.local not found${NC}"
echo " Please ensure frontend/.env.local exists"
exit 1
fi
else
echo "${GREEN} ✓ frontend/.env already exists${NC}"
fi
# Install npm dependencies
echo " → Installing npm dependencies (this may take a few minutes)..."
npm install --silent
if [ $? -eq 0 ]; then
echo "${GREEN}✓ Frontend setup complete${NC}"
else
echo "${RED}✗ Frontend setup failed${NC}"
exit 1
fi
cd ..
echo ""
# ============================================================================
# 4. READ PORT CONFIGURATION
# ============================================================================
# Read ports from .env files
BACKEND_PORT=5015 # Default
FRONTEND_PORT=3000 # Default
if [ -f "backend/.env" ]; then
BACKEND_PORT=$(grep -E "^BACKEND_PORT=" backend/.env | cut -d'=' -f2 | tr -d ' ')
fi
if [ -f "frontend/.env" ]; then
FRONTEND_PORT=$(grep -E "^FRONTEND_PORT=" frontend/.env | cut -d'=' -f2 | tr -d ' ')
fi
# Use defaults if not found
BACKEND_PORT=${BACKEND_PORT:-5015}
FRONTEND_PORT=${FRONTEND_PORT:-3000}
# ============================================================================
# 5. FINAL INSTRUCTIONS
# ============================================================================
echo "${GREEN}════════════════════════════════════════════════════════════${NC}"
echo "${GREEN}🎉 Setup Complete! Ready for Local Development${NC}"
echo "${GREEN}════════════════════════════════════════════════════════════${NC}"
echo ""
echo "${BLUE}📋 Next Steps:${NC}"
echo ""
echo "1. ${YELLOW}Start Backend Server${NC} (Terminal 1):"
echo " ${GREEN}cd backend && php -S localhost:${BACKEND_PORT}${NC}"
echo ""
echo "2. ${YELLOW}Start Frontend Dev Server${NC} (Terminal 2):"
echo " ${GREEN}cd frontend && npm run dev${NC}"
echo ""
echo "3. ${YELLOW}Open in Browser:${NC}"
echo " ${GREEN}http://localhost:${FRONTEND_PORT}${NC}"
echo ""
echo "${BLUE}⚙️ Configuration:${NC}"
echo " • Backend Port: ${BACKEND_PORT} (change in backend/.env)"
echo " • Frontend Port: ${FRONTEND_PORT} (change in frontend/.env)"
echo " • SSO: Enabled (disable by setting VITE_SSO_ENABLED=false in frontend/.env)"
echo ""
echo "${BLUE}📚 Documentation:${NC}"
echo " • README.md - User guide and features"
echo " • CLAUDE.md - Developer guide for AI assistants"
echo " • DEPLOYMENT.md - Production deployment guide"
echo ""
echo "${BLUE}💡 Useful Commands:${NC}"
echo " • Build for production: ${GREEN}cd frontend && npm run build${NC}"
echo " • Run linter: ${GREEN}cd frontend && npm run lint${NC}"
echo " • View logs: Check terminal output and browser console (F12)"
echo ""
echo "Happy coding! 🚀"