From 94456401d5a4861bb487fdb18de95c47ffbf608f Mon Sep 17 00:00:00 2001 From: nmemmert <67961292+nmemmert@users.noreply.github.com> Date: Thu, 4 Dec 2025 10:43:15 -0500 Subject: [PATCH] Add clean installer (bypassing cache) --- install-ubuntu.sh | 177 +++++++++++++++++----------------------------- 1 file changed, 64 insertions(+), 113 deletions(-) diff --git a/install-ubuntu.sh b/install-ubuntu.sh index 4b5e06f..dccf763 100644 --- a/install-ubuntu.sh +++ b/install-ubuntu.sh @@ -1,89 +1,85 @@ #!/bin/bash -# Resource Monitor - One-Click Ubuntu Installation Script -# Usage: curl -fsSL https://raw.githubusercontent.com/nmemmert/monitor/main/install-ubuntu.sh | bash -# Or: wget -qO- https://raw.githubusercontent.com/nmemmert/monitor/main/install-ubuntu.sh | bash +# Resource Monitor - One-Click Ubuntu Installation Script (Root Compatible) +# Usage: curl -fsSL https://raw.githubusercontent.com/nmemmert/monitor/main/install-ubuntu-root.sh | bash set -e -echo "🚀 Resource Monitor - Ubuntu Installation" -echo "==========================================" +echo "Resource Monitor - Ubuntu Installation" +echo "======================================" echo "" # Check if running as root if [ "$EUID" -eq 0 ]; then - echo "⚠️ Please do not run as root. Run as your regular user with sudo access." - exit 1 + echo "Running as root. Creating dedicated user 'monitor'..." + if ! id "monitor" &>/dev/null; then + useradd -m -s /bin/bash monitor + echo "Created user 'monitor'" + fi + SERVICE_USER="monitor" +else + SERVICE_USER="$USER" fi -# Install directory INSTALL_DIR="/opt/resource-monitor" -SERVICE_USER="$USER" -echo "📋 Installation will:" +echo "Installation will:" echo " - Install Node.js 20.x (if needed)" echo " - Install PM2 process manager" echo " - Clone repository to $INSTALL_DIR" echo " - Install dependencies" -echo " - Set up systemd service" echo " - Open firewall port 3001" echo "" -read -p "Continue? (y/n) " -n 1 -r -echo "" -if [[ ! $REPLY =~ ^[Yy]$ ]]; then - exit 1 -fi +echo "Continuing installation..." # Update system echo "" -echo "📦 Step 1: Updating system packages..." -sudo apt-get update -qq +echo "Step 1: Updating system packages..." +apt-get update -qq -# Install Node.js if not present +# Install Node.js if ! command -v node &> /dev/null; then echo "" - echo "📦 Step 2: Installing Node.js 20.x..." - curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - - sudo apt-get install -y nodejs + echo "Step 2: Installing Node.js 20.x..." + curl -fsSL https://deb.nodesource.com/setup_20.x | bash - + apt-get install -y nodejs else echo "" - echo "✅ Node.js already installed: $(node --version)" + echo "Node.js already installed: $(node --version)" fi -# Install git if not present +# Install git if ! command -v git &> /dev/null; then echo "" - echo "📦 Installing Git..." - sudo apt-get install -y git + echo "Installing Git..." + apt-get install -y git fi -# Install PM2 globally +# Install PM2 echo "" -echo "📦 Step 3: Installing PM2 process manager..." -sudo npm install -g pm2 +echo "Step 3: Installing PM2..." +npm install -g pm2 -# Clone or update repository +# Clone repository echo "" -echo "📥 Step 4: Setting up application..." +echo "Step 4: Cloning repository..." if [ -d "$INSTALL_DIR" ]; then echo "Directory exists, updating..." cd "$INSTALL_DIR" git pull else - echo "Cloning repository..." - REPO_URL="https://github.com/nmemmert/monitor.git" - sudo git clone "$REPO_URL" "$INSTALL_DIR" - sudo chown -R $USER:$USER "$INSTALL_DIR" + git clone "https://github.com/nmemmert/monitor.git" "$INSTALL_DIR" + chown -R $SERVICE_USER:$SERVICE_USER "$INSTALL_DIR" cd "$INSTALL_DIR" fi # Install dependencies echo "" -echo "📦 Step 5: Installing Node.js dependencies..." +echo "Step 5: Installing dependencies..." npm install --production # Build client echo "" -echo "🔨 Step 6: Building React frontend..." +echo "Step 6: Building frontend..." cd client npm install npm run build @@ -91,103 +87,58 @@ cd .. # Setup configuration echo "" -echo "⚙️ Step 7: Setting up configuration..." +echo "Step 7: Setting up configuration..." if [ ! -f ".env" ]; then cp .env.example .env - echo "✅ Created .env file" - echo "" - echo "📝 Configure your settings:" - read -p "Enable email notifications? (y/n) " -n 1 -r - echo "" - if [[ $REPLY =~ ^[Yy]$ ]]; then - read -p "SMTP Host (e.g., smtp.gmail.com): " SMTP_HOST - read -p "SMTP Port (e.g., 587): " SMTP_PORT - read -p "Email Username: " EMAIL_USER - read -s -p "Email Password/App Password: " EMAIL_PASS - echo "" - read -p "From Email: " EMAIL_FROM - read -p "To Email (for alerts): " EMAIL_TO - - sed -i "s/EMAIL_ENABLED=false/EMAIL_ENABLED=true/" .env - sed -i "s/EMAIL_HOST=smtp.gmail.com/EMAIL_HOST=$SMTP_HOST/" .env - sed -i "s/EMAIL_PORT=587/EMAIL_PORT=$SMTP_PORT/" .env - sed -i "s/EMAIL_USER=your-email@gmail.com/EMAIL_USER=$EMAIL_USER/" .env - sed -i "s/EMAIL_PASS=your-app-password/EMAIL_PASS=$EMAIL_PASS/" .env - sed -i "s/EMAIL_FROM=your-email@gmail.com/EMAIL_FROM=$EMAIL_FROM/" .env - sed -i "s/EMAIL_TO=your-email@gmail.com/EMAIL_TO=$EMAIL_TO/" .env - fi - - echo "" - read -p "Enable webhook notifications? (y/n) " -n 1 -r - echo "" - if [[ $REPLY =~ ^[Yy]$ ]]; then - read -p "Webhook URL: " WEBHOOK_URL - sed -i "s/WEBHOOK_ENABLED=false/WEBHOOK_ENABLED=true/" .env - sed -i "s|WEBHOOK_URL=https://your-webhook-url.com|WEBHOOK_URL=$WEBHOOK_URL|" .env - fi -else - echo "✅ .env file already exists" + echo "Created .env file" fi -# Set NODE_ENV to production if ! grep -q "NODE_ENV" .env; then echo "NODE_ENV=production" >> .env fi -# Create data directory mkdir -p data -# Setup firewall +# Firewall echo "" -echo "🔥 Step 8: Configuring firewall..." +echo "Step 8: Configuring firewall..." if command -v ufw &> /dev/null; then - sudo ufw allow 3001/tcp - echo "✅ Port 3001 opened in firewall" -else - echo "⚠️ UFW not found, please open port 3001 manually" + ufw allow 3001/tcp 2>/dev/null || true + echo "Port 3001 opened" fi # Start with PM2 echo "" -echo "🚀 Step 9: Starting application with PM2..." -pm2 stop resource-monitor 2>/dev/null || true -pm2 delete resource-monitor 2>/dev/null || true -pm2 start server/index.js --name resource-monitor -pm2 save +echo "Step 9: Starting application..." +if [ "$EUID" -eq 0 ]; then + su - $SERVICE_USER -c "cd $INSTALL_DIR && pm2 delete resource-monitor 2>/dev/null || true" + su - $SERVICE_USER -c "cd $INSTALL_DIR && pm2 start server/index.js --name resource-monitor" + su - $SERVICE_USER -c "pm2 save" + env PATH=$PATH:/usr/bin pm2 startup systemd -u $SERVICE_USER --hp /home/$SERVICE_USER + su - $SERVICE_USER -c "pm2 save" +else + pm2 delete resource-monitor 2>/dev/null || true + pm2 start server/index.js --name resource-monitor + pm2 save + sudo env PATH=$PATH:/usr/bin pm2 startup systemd -u $USER --hp /home/$USER + pm2 save +fi -# Setup PM2 startup -echo "" -echo "🔄 Step 10: Setting up auto-start on boot..." -sudo env PATH=$PATH:/usr/bin pm2 startup systemd -u $USER --hp /home/$USER -pm2 save - -# Get server IP SERVER_IP=$(hostname -I | awk '{print $1}') echo "" -echo "==============================================" -echo "✅ Installation Complete!" -echo "==============================================" +echo "==========================================" +echo "Installation Complete!" +echo "==========================================" echo "" -echo "🎉 Resource Monitor is now running!" +echo "Access dashboard at: http://$SERVER_IP:3001" echo "" -echo "📊 Access your dashboard at:" -echo " http://$SERVER_IP:3001" -echo " http://localhost:3001 (if on same machine)" +echo "Commands:" +echo " pm2 status" +echo " pm2 logs resource-monitor" +echo " pm2 restart resource-monitor" echo "" -echo "🔧 Useful commands:" -echo " pm2 status - Check status" -echo " pm2 logs resource-monitor - View logs" -echo " pm2 restart resource-monitor - Restart" -echo " pm2 stop resource-monitor - Stop" +echo "Configure notifications:" +echo " nano $INSTALL_DIR/.env" +echo " pm2 restart resource-monitor" echo "" -echo "⚙️ To change settings:" -echo " nano $INSTALL_DIR/.env" -echo " pm2 restart resource-monitor" -echo "" -echo "📝 Add your first resource:" -echo " 1. Open the dashboard in your browser" -echo " 2. Click 'Add Resource'" -echo " 3. Enter your ZimaOS URL and details" -echo "" -echo "Happy monitoring! 🚀"