All checks were successful
Build Frontend / Build Frontend (push) Successful in 25s
177 lines
5.3 KiB
Bash
177 lines
5.3 KiB
Bash
#!/bin/bash
|
|
|
|
# Deploy Ban Notification Fix
|
|
# This script deploys the ban notification feature to production
|
|
|
|
set -e # Exit on error
|
|
|
|
echo "🚀 Deploying Ban Notification Fix..."
|
|
echo ""
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Configuration
|
|
PROJECT_DIR="/path/to/TurboTrades"
|
|
FRONTEND_DIR="$PROJECT_DIR/frontend"
|
|
WEB_ROOT="/var/www/html/turbotrades"
|
|
PM2_APP_NAME="turbotrades-backend"
|
|
|
|
# Check if running on production server
|
|
if [[ ! -d "$PROJECT_DIR" ]]; then
|
|
echo -e "${RED}❌ Error: Project directory not found at $PROJECT_DIR${NC}"
|
|
echo "Please update PROJECT_DIR in this script to match your server setup"
|
|
exit 1
|
|
fi
|
|
|
|
# Step 1: Backup current deployment
|
|
echo -e "${YELLOW}📦 Creating backup...${NC}"
|
|
BACKUP_DIR="$HOME/turbotrades-backup-$(date +%Y%m%d-%H%M%S)"
|
|
mkdir -p "$BACKUP_DIR"
|
|
|
|
# Backup backend files
|
|
cp "$PROJECT_DIR/routes/admin-management.js" "$BACKUP_DIR/admin-management.js.bak" 2>/dev/null || true
|
|
cp "$PROJECT_DIR/middleware/auth.js" "$BACKUP_DIR/auth.js.bak" 2>/dev/null || true
|
|
|
|
# Backup frontend
|
|
if [[ -d "$WEB_ROOT" ]]; then
|
|
cp -r "$WEB_ROOT" "$BACKUP_DIR/frontend" 2>/dev/null || true
|
|
fi
|
|
|
|
echo -e "${GREEN}✓ Backup created at $BACKUP_DIR${NC}"
|
|
echo ""
|
|
|
|
# Step 2: Pull latest changes (if using git)
|
|
cd "$PROJECT_DIR"
|
|
if [[ -d ".git" ]]; then
|
|
echo -e "${YELLOW}📥 Pulling latest changes from git...${NC}"
|
|
git pull
|
|
echo -e "${GREEN}✓ Git pull complete${NC}"
|
|
echo ""
|
|
else
|
|
echo -e "${YELLOW}⚠️ Not a git repository, skipping git pull${NC}"
|
|
echo -e "${YELLOW} Make sure you've manually uploaded the updated files:${NC}"
|
|
echo " - routes/admin-management.js"
|
|
echo " - middleware/auth.js"
|
|
echo " - frontend/src/stores/websocket.js"
|
|
echo ""
|
|
read -p "Press Enter to continue after uploading files..."
|
|
fi
|
|
|
|
# Step 3: Install/update dependencies (if needed)
|
|
echo -e "${YELLOW}📦 Checking dependencies...${NC}"
|
|
cd "$PROJECT_DIR"
|
|
if [[ -f "package.json" ]]; then
|
|
npm install --production 2>/dev/null || echo "Dependencies already up to date"
|
|
fi
|
|
echo -e "${GREEN}✓ Dependencies checked${NC}"
|
|
echo ""
|
|
|
|
# Step 4: Build frontend
|
|
echo -e "${YELLOW}🔨 Building frontend...${NC}"
|
|
cd "$FRONTEND_DIR"
|
|
npm run build
|
|
|
|
if [[ ! -d "dist" ]]; then
|
|
echo -e "${RED}❌ Error: Frontend build failed (dist directory not found)${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}✓ Frontend built successfully${NC}"
|
|
echo ""
|
|
|
|
# Step 5: Deploy frontend
|
|
echo -e "${YELLOW}🚀 Deploying frontend...${NC}"
|
|
if [[ ! -d "$WEB_ROOT" ]]; then
|
|
echo "Creating web root directory..."
|
|
sudo mkdir -p "$WEB_ROOT"
|
|
fi
|
|
|
|
sudo cp -r dist/* "$WEB_ROOT/"
|
|
echo -e "${GREEN}✓ Frontend deployed to $WEB_ROOT${NC}"
|
|
echo ""
|
|
|
|
# Step 6: Restart backend
|
|
echo -e "${YELLOW}🔄 Restarting backend...${NC}"
|
|
cd "$PROJECT_DIR"
|
|
|
|
# Check if PM2 is available
|
|
if command -v pm2 &> /dev/null; then
|
|
pm2 restart "$PM2_APP_NAME"
|
|
|
|
# Wait a moment for restart
|
|
sleep 2
|
|
|
|
# Check if process is running
|
|
if pm2 list | grep -q "$PM2_APP_NAME"; then
|
|
echo -e "${GREEN}✓ Backend restarted successfully${NC}"
|
|
else
|
|
echo -e "${RED}❌ Warning: Backend may not be running${NC}"
|
|
echo "Check logs with: pm2 logs $PM2_APP_NAME"
|
|
fi
|
|
else
|
|
echo -e "${YELLOW}⚠️ PM2 not found, please restart backend manually${NC}"
|
|
fi
|
|
echo ""
|
|
|
|
# Step 7: Verify deployment
|
|
echo -e "${YELLOW}🔍 Verifying deployment...${NC}"
|
|
|
|
# Check if backend is responding
|
|
BACKEND_URL="http://localhost:3000/api/health"
|
|
if curl -s "$BACKEND_URL" > /dev/null 2>&1; then
|
|
echo -e "${GREEN}✓ Backend is responding${NC}"
|
|
else
|
|
echo -e "${RED}❌ Warning: Backend health check failed${NC}"
|
|
fi
|
|
|
|
# Check if frontend files exist
|
|
if [[ -f "$WEB_ROOT/index.html" ]]; then
|
|
echo -e "${GREEN}✓ Frontend files deployed${NC}"
|
|
else
|
|
echo -e "${RED}❌ Warning: Frontend index.html not found${NC}"
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# Step 8: Display logs
|
|
echo -e "${YELLOW}📋 Recent backend logs:${NC}"
|
|
if command -v pm2 &> /dev/null; then
|
|
pm2 logs "$PM2_APP_NAME" --lines 20 --nostream
|
|
else
|
|
echo "PM2 not available, skipping logs"
|
|
fi
|
|
echo ""
|
|
|
|
# Success message
|
|
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${GREEN}✅ Ban Notification Fix Deployed Successfully!${NC}"
|
|
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo ""
|
|
echo -e "${YELLOW}Next Steps:${NC}"
|
|
echo "1. Test the ban flow:"
|
|
echo " - Login as a user in one browser"
|
|
echo " - Login as admin in another browser"
|
|
echo " - Ban the user from admin panel"
|
|
echo " - User should be immediately redirected to /banned page"
|
|
echo ""
|
|
echo "2. Check the logs:"
|
|
echo " pm2 logs $PM2_APP_NAME --lines 50"
|
|
echo ""
|
|
echo "3. Monitor WebSocket connections:"
|
|
echo " pm2 logs $PM2_APP_NAME | grep WebSocket"
|
|
echo ""
|
|
echo -e "${YELLOW}Backup Location:${NC} $BACKUP_DIR"
|
|
echo ""
|
|
echo -e "${YELLOW}Rollback Instructions:${NC}"
|
|
echo "If something goes wrong, restore from backup:"
|
|
echo " cp $BACKUP_DIR/admin-management.js.bak $PROJECT_DIR/routes/admin-management.js"
|
|
echo " cp $BACKUP_DIR/auth.js.bak $PROJECT_DIR/middleware/auth.js"
|
|
echo " sudo cp -r $BACKUP_DIR/frontend/* $WEB_ROOT/"
|
|
echo " pm2 restart $PM2_APP_NAME"
|
|
echo ""
|
|
echo -e "${GREEN}Happy banning! 🔨${NC}"
|