#!/bin/bash

# WinaChat cPanel Installation Script

echo "WinaChat cPanel Setup"
echo "====================="

# Check Node.js
echo "Checking Node.js installation..."
node --version
if [ $? -ne 0 ]; then
    echo "Error: Node.js not installed"
    exit 1
fi

# Install dependencies
echo "Installing dependencies..."
npm install
if [ $? -ne 0 ]; then
    echo "Error: npm install failed"
    exit 1
fi

# Create directories
echo "Creating necessary directories..."
mkdir -p logs
mkdir -p uploads
mkdir -p backups

# Set permissions
echo "Setting permissions..."
chmod 755 scripts/*.js
chmod 755 deploy/cpanel-setup.sh

# Copy environment
echo "Setting up environment..."
if [ ! -f .env ]; then
    cp .env.example .env
    echo "Created .env file - please edit with your database credentials"
fi

echo ""
echo "Setup complete!"
echo ""
echo "Next steps:"
echo "1. Edit .env file with your database credentials"
echo "2. Initialize database: node scripts/init-db.js"
echo "3. Create Node.js app in cPanel Node.js Selector"
echo "4. Restart application"
