172 lines
4.9 KiB
Bash
Executable File
172 lines
4.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Bookmark Manager Setup Script
|
|
echo "🚀 Setting up Bookmark Manager Application..."
|
|
echo ""
|
|
|
|
# Function to check command exists
|
|
check_command() {
|
|
if ! command -v $1 &> /dev/null; then
|
|
echo "❌ $1 is not installed or not in PATH"
|
|
return 1
|
|
else
|
|
echo "✅ $1 found: $(which $1)"
|
|
return 0
|
|
fi
|
|
}
|
|
|
|
# Function to check service status
|
|
check_postgres_service() {
|
|
echo "🔍 Checking PostgreSQL service status..."
|
|
|
|
# Try different ways to check PostgreSQL status
|
|
if systemctl is-active --quiet postgresql 2>/dev/null; then
|
|
echo "✅ PostgreSQL service is running (systemctl)"
|
|
return 0
|
|
elif brew services list 2>/dev/null | grep -q "postgresql.*started"; then
|
|
echo "✅ PostgreSQL service is running (brew)"
|
|
return 0
|
|
elif pgrep -x postgres >/dev/null; then
|
|
echo "✅ PostgreSQL process is running"
|
|
return 0
|
|
else
|
|
echo "⚠️ PostgreSQL service may not be running"
|
|
echo " Try starting it with:"
|
|
echo " - Linux: sudo systemctl start postgresql"
|
|
echo " - macOS: brew services start postgresql"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Check prerequisites
|
|
echo "📋 Checking prerequisites..."
|
|
echo ""
|
|
|
|
NODE_OK=false
|
|
POSTGRES_OK=false
|
|
|
|
if check_command "node"; then
|
|
NODE_VERSION=$(node --version)
|
|
echo " Version: $NODE_VERSION"
|
|
NODE_OK=true
|
|
else
|
|
echo " Please install Node.js v16 or higher from https://nodejs.org/"
|
|
fi
|
|
|
|
if check_command "npm"; then
|
|
NPM_VERSION=$(npm --version)
|
|
echo " Version: $NPM_VERSION"
|
|
else
|
|
echo " npm should come with Node.js"
|
|
fi
|
|
|
|
if check_command "psql"; then
|
|
POSTGRES_VERSION=$(psql --version)
|
|
echo " Version: $POSTGRES_VERSION"
|
|
POSTGRES_OK=true
|
|
check_postgres_service
|
|
else
|
|
echo " Please install PostgreSQL from https://www.postgresql.org/download/"
|
|
fi
|
|
|
|
echo ""
|
|
|
|
if [ "$NODE_OK" = false ] || [ "$POSTGRES_OK" = false ]; then
|
|
echo "❌ Prerequisites not met. Please install missing components and try again."
|
|
exit 1
|
|
fi
|
|
|
|
# Navigate to backend directory
|
|
if [ ! -d "backend" ]; then
|
|
echo "❌ Backend directory not found. Are you in the correct directory?"
|
|
exit 1
|
|
fi
|
|
|
|
cd backend
|
|
|
|
# Install dependencies
|
|
echo "📦 Installing backend dependencies..."
|
|
if npm install; then
|
|
echo "✅ Dependencies installed successfully"
|
|
else
|
|
echo "❌ Failed to install dependencies"
|
|
echo " Try running: npm cache clean --force && npm install"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if .env file exists
|
|
if [ ! -f .env ]; then
|
|
echo "📝 Creating environment file..."
|
|
if cp .env.example .env; then
|
|
echo "✅ Environment file created"
|
|
echo ""
|
|
echo "⚠️ IMPORTANT: You need to configure your database settings!"
|
|
echo ""
|
|
echo "1. Edit backend/.env file with your database credentials:"
|
|
echo " - DB_USER (usually 'postgres')"
|
|
echo " - DB_PASSWORD (your PostgreSQL password)"
|
|
echo " - JWT_SECRET (make it long and random)"
|
|
echo ""
|
|
echo "2. Create the databases:"
|
|
echo " psql -U postgres -c \"CREATE DATABASE bookmark_manager;\""
|
|
echo " psql -U postgres -c \"CREATE DATABASE bookmark_manager_test;\""
|
|
echo ""
|
|
echo "3. Then run: npm run db:init"
|
|
echo ""
|
|
echo "4. Finally start the app: npm run dev"
|
|
echo ""
|
|
exit 0
|
|
else
|
|
echo "❌ Failed to create environment file"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Test database connection
|
|
echo "🔍 Testing database connection..."
|
|
if npm run db:status >/dev/null 2>&1; then
|
|
echo "✅ Database connection successful"
|
|
else
|
|
echo "⚠️ Database connection failed"
|
|
echo " Please check your .env configuration"
|
|
echo " Run 'npm run db:diagnostics' for more details"
|
|
fi
|
|
|
|
# Initialize database
|
|
echo "🗄️ Initializing database..."
|
|
if npm run db:init; then
|
|
echo "✅ Database initialized successfully"
|
|
else
|
|
echo "❌ Database initialization failed"
|
|
echo ""
|
|
echo "Common solutions:"
|
|
echo "1. Make sure PostgreSQL is running"
|
|
echo "2. Check your .env file database credentials"
|
|
echo "3. Create databases manually:"
|
|
echo " psql -U postgres -c \"CREATE DATABASE bookmark_manager;\""
|
|
echo " psql -U postgres -c \"CREATE DATABASE bookmark_manager_test;\""
|
|
echo ""
|
|
echo "For detailed troubleshooting, see TROUBLESHOOTING_SETUP.md"
|
|
exit 1
|
|
fi
|
|
|
|
# Skip tests for now to avoid complexity
|
|
echo "⏭️ Skipping tests for initial setup (you can run 'npm test' later)"
|
|
|
|
echo ""
|
|
echo "🎉 Setup complete!"
|
|
echo ""
|
|
echo "To start the application:"
|
|
echo " cd backend"
|
|
echo " npm run dev"
|
|
echo ""
|
|
echo "Then open http://localhost:3001 in your browser"
|
|
echo ""
|
|
echo "Available commands:"
|
|
echo " npm start - Start production server"
|
|
echo " npm run dev - Start development server with auto-reload"
|
|
echo " npm test - Run all tests"
|
|
echo " npm run db:status - Check database status"
|
|
echo ""
|
|
echo "If you encounter issues, check TROUBLESHOOTING_SETUP.md"
|
|
echo "" |