#!/bin/bash

# Noble Collectable — Installation Script
# Installs WordPress and sets up the environment

set -e

echo "Installing Noble Collectable..."

# Download WordPress if not exists
if [ ! -f wp-load.php ]; then
    echo "Downloading WordPress..."
    wget -q https://wordpress.org/latest.tar.gz
    tar xzf latest.tar.gz --strip-components=1
    rm latest.tar.gz
    echo "WordPress installed"
fi

# Create wp-config.php if it doesn't exist
if [ ! -f wp-config.php ]; then
    echo "Creating wp-config.php template..."
    cp wp-config-sample.php wp-config.php
    echo "⚠️  IMPORTANT: Edit wp-config.php with your database credentials"
fi

# Set permissions
echo "Setting permissions..."
chmod -R 755 wp-content/
chmod 755 .
chmod 644 wp-config.php 2>/dev/null || true

# Create uploads directory if missing
mkdir -p wp-content/uploads
chmod 755 wp-content/uploads

echo "✅ Installation complete!"
echo ""
echo "Next steps:"
echo "1. Edit wp-config.php with your database credentials"
echo "2. Visit https://noblecollectable.thepixela.com"
echo "3. Complete WordPress setup"
