← back to Dear Bubbe Admin
setup-admin.sh
125 lines
#!/bin/bash
# Dear Bubbe Admin Dashboard Setup Script
echo "🚀 Setting up Dear Bubbe Admin Dashboard..."
# Create necessary directories
mkdir -p logs reports exports uploads backend/logs
# Install backend dependencies
echo "📦 Installing backend dependencies..."
npm install
# Install frontend dependencies
echo "📦 Installing frontend dependencies..."
cd frontend
npm install
cd ..
# Build frontend for production
echo "🏗️ Building frontend..."
cd frontend
npm run build
cd ..
# Check if MongoDB is running
echo "🔍 Checking MongoDB status..."
if systemctl is-active --quiet mongod; then
echo "✅ MongoDB is running"
else
echo "⚠️ MongoDB is not running. Starting MongoDB..."
sudo systemctl start mongod
sudo systemctl enable mongod
# Wait for MongoDB to start
sleep 3
if systemctl is-active --quiet mongod; then
echo "✅ MongoDB started successfully"
else
echo "❌ Failed to start MongoDB. Please start it manually."
exit 1
fi
fi
# Create MongoDB database and collections
echo "🗃️ Setting up MongoDB database..."
mongo << 'EOF'
use dear-bubbe-admin;
// Create collections with indexes
db.alerts.createIndex({ timestamp: -1 });
db.alerts.createIndex({ "userInfo.ip": 1, timestamp: -1 });
db.alerts.createIndex({ type: 1, severity: 1 });
db.alerts.createIndex({ status: 1, timestamp: -1 });
db.users.createIndex({ userId: 1 }, { unique: true });
db.users.createIndex({ "security.blocked": 1 });
db.users.createIndex({ "security.riskLevel": 1 });
db.users.createIndex({ "stats.lastVisit": -1 });
db.sessions.createIndex({ sessionId: 1 }, { unique: true });
db.sessions.createIndex({ userId: 1, startTime: -1 });
db.sessions.createIndex({ ended: 1, lastActivity: -1 });
db.conversations.createIndex({ timestamp: -1 });
db.conversations.createIndex({ userId: 1, timestamp: -1 });
db.conversations.createIndex({ topics: 1 });
print("Database and indexes created successfully");
exit
EOF
# Set up firewall rules
echo "🔒 Setting up firewall rules..."
sudo ufw allow 3015/tcp
echo "✅ Port 3015 opened for admin dashboard"
# Set proper permissions
echo "🔑 Setting up permissions..."
chmod +x backend/server.js 2>/dev/null || true
chmod +x setup-admin.sh
chmod -R 755 logs reports exports uploads 2>/dev/null || true
# Copy built frontend to backend public directory
if [ -d "frontend/build" ]; then
echo "📁 Copying built frontend..."
mkdir -p backend/public
cp -r frontend/build/* backend/public/
echo "✅ Frontend copied to backend"
fi
# Start the admin dashboard with PM2
echo "🚀 Starting Dear Bubbe Admin Dashboard..."
pm2 start ecosystem.config.js
# Check if service is running
sleep 3
if pm2 list | grep -q "dear-bubbe-admin.*online"; then
echo ""
echo "✅ SUCCESS! Dear Bubbe Admin Dashboard is running!"
echo ""
echo "📊 Dashboard URL: http://45.61.58.125:3015"
echo "🔑 Default Login:"
echo " Username: admin"
echo " Password: password"
echo ""
echo "📋 Management Commands:"
echo " pm2 status dear-bubbe-admin - Check status"
echo " pm2 logs dear-bubbe-admin - View logs"
echo " pm2 restart dear-bubbe-admin - Restart service"
echo " pm2 stop dear-bubbe-admin - Stop service"
echo ""
echo "🔧 Configuration file: /root/Projects/dear-bubbe-admin/.env"
echo ""
echo "⚠️ IMPORTANT SECURITY NOTES:"
echo " 1. Change default admin password immediately"
echo " 2. Update JWT_SECRET in production"
echo " 3. Configure HTTPS for production use"
echo " 4. Set up proper MongoDB authentication"
echo ""
else
echo "❌ Failed to start admin dashboard"
echo "📝 Check logs with: pm2 logs dear-bubbe-admin"
exit 1
fi