#!/bin/bash # ZMB Webui Frontend Deployment Script set -e echo "=== ZMB Webui Frontend Deployment ===" # Configuration FRONTEND_DIR="/opt/zmb-webui/frontend" NODE_VERSION="v20.19.2" NPM_VERSION="9.2.0" # Colors GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' # No Color # Check Node.js and npm echo -e "${YELLOW}1. Checking Node.js and npm...${NC}" NODE_INSTALLED=$(node --version 2>/dev/null || echo "") if [ -z "$NODE_INSTALLED" ]; then echo -e "${RED}✗ Node.js not installed${NC}" exit 1 fi echo -e "${GREEN}✓ Node.js $NODE_INSTALLED installed${NC}" NPM_INSTALLED=$(npm --version 2>/dev/null || echo "") if [ -z "$NPM_INSTALLED" ]; then echo -e "${RED}✗ npm not installed${NC}" exit 1 fi echo -e "${GREEN}✓ npm $NPM_INSTALLED installed${NC}" # Check frontend directory echo -e "${YELLOW}2. Checking frontend directory...${NC}" if [ ! -d "$FRONTEND_DIR" ]; then echo -e "${RED}✗ Frontend directory not found: $FRONTEND_DIR${NC}" exit 1 fi echo -e "${GREEN}✓ Frontend directory found${NC}" # Install dependencies echo -e "${YELLOW}3. Installing dependencies...${NC}" cd "$FRONTEND_DIR" npm install --prefer-offline --no-audit echo -e "${GREEN}✓ Dependencies installed${NC}" # Build project echo -e "${YELLOW}4. Building Next.js project...${NC}" npm run build echo -e "${GREEN}✓ Build successful${NC}" # Create systemd service echo -e "${YELLOW}5. Setting up systemd service...${NC}" sudo cp /tmp/zmb-webui-frontend.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable zmb-webui-frontend echo -e "${GREEN}✓ Systemd service configured${NC}" # Start service echo -e "${YELLOW}6. Starting frontend service...${NC}" sudo systemctl restart zmb-webui-frontend sleep 2 # Verify service if sudo systemctl is-active --quiet zmb-webui-frontend; then echo -e "${GREEN}✓ Frontend service running${NC}" else echo -e "${RED}✗ Frontend service failed to start${NC}" sudo systemctl status zmb-webui-frontend exit 1 fi # Test connectivity echo -e "${YELLOW}7. Testing connectivity...${NC}" sleep 2 if curl -s http://localhost:3000 > /dev/null 2>&1; then echo -e "${GREEN}✓ Frontend accessible at http://localhost:3000${NC}" else echo -e "${YELLOW}⚠ Frontend not yet responding (may be starting)${NC}" fi # Summary echo "" echo -e "${GREEN}=== Deployment Complete ===${NC}" echo "" echo "Frontend is running at:" echo " Local: http://localhost:3000" echo " Remote: http://$(hostname -I | awk '{print $1}'):9090" echo "" echo "Admin credentials:" echo " Username: admin" echo " Password: testpass123" echo "" echo "Service management:" echo " systemctl status zmb-webui-frontend" echo " systemctl restart zmb-webui-frontend" echo " systemctl stop zmb-webui-frontend" echo "" echo "Logs:" echo " journalctl -u zmb-webui-frontend -f"