Add clean installer (bypassing cache)

This commit is contained in:
nmemmert committed 2025-12-04 10:43:15 -05:00
1 parent 77c7cea950
commit 94456401d5
1 file changed
+64 -113
+64 -113
View File
@@ -1,89 +1,85 @@
#!/bin/bash #!/bin/bash
# Resource Monitor - One-Click Ubuntu Installation Script # Resource Monitor - One-Click Ubuntu Installation Script (Root Compatible)
# Usage: curl -fsSL https://raw.githubusercontent.com/nmemmert/monitor/main/install-ubuntu.sh | bash # Usage: curl -fsSL https://raw.githubusercontent.com/nmemmert/monitor/main/install-ubuntu-root.sh | bash
# Or: wget -qO- https://raw.githubusercontent.com/nmemmert/monitor/main/install-ubuntu.sh | bash
set -e set -e
echo "🚀 Resource Monitor - Ubuntu Installation" echo "Resource Monitor - Ubuntu Installation"
echo "==========================================" echo "======================================"
echo "" echo ""
# Check if running as root # Check if running as root
if [ "$EUID" -eq 0 ]; then if [ "$EUID" -eq 0 ]; then
echo "⚠️ Please do not run as root. Run as your regular user with sudo access." echo "Running as root. Creating dedicated user 'monitor'..."
exit 1 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 fi
# Install directory
INSTALL_DIR="/opt/resource-monitor" INSTALL_DIR="/opt/resource-monitor"
SERVICE_USER="$USER"
echo "📋 Installation will:" echo "Installation will:"
echo " - Install Node.js 20.x (if needed)" echo " - Install Node.js 20.x (if needed)"
echo " - Install PM2 process manager" echo " - Install PM2 process manager"
echo " - Clone repository to $INSTALL_DIR" echo " - Clone repository to $INSTALL_DIR"
echo " - Install dependencies" echo " - Install dependencies"
echo " - Set up systemd service"
echo " - Open firewall port 3001" echo " - Open firewall port 3001"
echo "" echo ""
read -p "Continue? (y/n) " -n 1 -r echo "Continuing installation..."
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
# Update system # Update system
echo "" echo ""
echo "📦 Step 1: Updating system packages..." echo "Step 1: Updating system packages..."
sudo apt-get update -qq apt-get update -qq
# Install Node.js if not present # Install Node.js
if ! command -v node &> /dev/null; then if ! command -v node &> /dev/null; then
echo "" echo ""
echo "📦 Step 2: Installing Node.js 20.x..." echo "Step 2: Installing Node.js 20.x..."
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
sudo apt-get install -y nodejs apt-get install -y nodejs
else else
echo "" echo ""
echo "✅ Node.js already installed: $(node --version)" echo "Node.js already installed: $(node --version)"
fi fi
# Install git if not present # Install git
if ! command -v git &> /dev/null; then if ! command -v git &> /dev/null; then
echo "" echo ""
echo "📦 Installing Git..." echo "Installing Git..."
sudo apt-get install -y git apt-get install -y git
fi fi
# Install PM2 globally # Install PM2
echo "" echo ""
echo "📦 Step 3: Installing PM2 process manager..." echo "Step 3: Installing PM2..."
sudo npm install -g pm2 npm install -g pm2
# Clone or update repository # Clone repository
echo "" echo ""
echo "📥 Step 4: Setting up application..." echo "Step 4: Cloning repository..."
if [ -d "$INSTALL_DIR" ]; then if [ -d "$INSTALL_DIR" ]; then
echo "Directory exists, updating..." echo "Directory exists, updating..."
cd "$INSTALL_DIR" cd "$INSTALL_DIR"
git pull git pull
else else
echo "Cloning repository..." git clone "https://github.com/nmemmert/monitor.git" "$INSTALL_DIR"
REPO_URL="https://github.com/nmemmert/monitor.git" chown -R $SERVICE_USER:$SERVICE_USER "$INSTALL_DIR"
sudo git clone "$REPO_URL" "$INSTALL_DIR"
sudo chown -R $USER:$USER "$INSTALL_DIR"
cd "$INSTALL_DIR" cd "$INSTALL_DIR"
fi fi
# Install dependencies # Install dependencies
echo "" echo ""
echo "📦 Step 5: Installing Node.js dependencies..." echo "Step 5: Installing dependencies..."
npm install --production npm install --production
# Build client # Build client
echo "" echo ""
echo "🔨 Step 6: Building React frontend..." echo "Step 6: Building frontend..."
cd client cd client
npm install npm install
npm run build npm run build
@@ -91,103 +87,58 @@ cd ..
# Setup configuration # Setup configuration
echo "" echo ""
echo "⚙️ Step 7: Setting up configuration..." echo "Step 7: Setting up configuration..."
if [ ! -f ".env" ]; then if [ ! -f ".env" ]; then
cp .env.example .env cp .env.example .env
echo "✅ Created .env file" 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"
fi fi
# Set NODE_ENV to production
if ! grep -q "NODE_ENV" .env; then if ! grep -q "NODE_ENV" .env; then
echo "NODE_ENV=production" >> .env echo "NODE_ENV=production" >> .env
fi fi
# Create data directory
mkdir -p data mkdir -p data
# Setup firewall # Firewall
echo "" echo ""
echo "🔥 Step 8: Configuring firewall..." echo "Step 8: Configuring firewall..."
if command -v ufw &> /dev/null; then if command -v ufw &> /dev/null; then
sudo ufw allow 3001/tcp ufw allow 3001/tcp 2>/dev/null || true
echo "✅ Port 3001 opened in firewall" echo "Port 3001 opened"
else
echo "⚠️ UFW not found, please open port 3001 manually"
fi fi
# Start with PM2 # Start with PM2
echo "" echo ""
echo "🚀 Step 9: Starting application with PM2..." echo "Step 9: Starting application..."
pm2 stop resource-monitor 2>/dev/null || true if [ "$EUID" -eq 0 ]; then
pm2 delete resource-monitor 2>/dev/null || true su - $SERVICE_USER -c "cd $INSTALL_DIR && pm2 delete resource-monitor 2>/dev/null || true"
pm2 start server/index.js --name resource-monitor su - $SERVICE_USER -c "cd $INSTALL_DIR && pm2 start server/index.js --name resource-monitor"
pm2 save 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}') SERVER_IP=$(hostname -I | awk '{print $1}')
echo "" echo ""
echo "==============================================" echo "=========================================="
echo "✅ Installation Complete!" echo "Installation Complete!"
echo "==============================================" echo "=========================================="
echo "" echo ""
echo "🎉 Resource Monitor is now running!" echo "Access dashboard at: http://$SERVER_IP:3001"
echo "" echo ""
echo "📊 Access your dashboard at:" echo "Commands:"
echo " http://$SERVER_IP:3001" echo " pm2 status"
echo " http://localhost:3001 (if on same machine)" echo " pm2 logs resource-monitor"
echo " pm2 restart resource-monitor"
echo "" echo ""
echo "🔧 Useful commands:" echo "Configure notifications:"
echo " pm2 status - Check status" echo " nano $INSTALL_DIR/.env"
echo " pm2 logs resource-monitor - View logs" echo " pm2 restart resource-monitor"
echo " pm2 restart resource-monitor - Restart"
echo " pm2 stop resource-monitor - Stop"
echo "" 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! 🚀"