#!/bin/bash # Kao Installation Script # Installs to /opt/kao and sets up systemd service set -e INSTALL_DIR="/opt/kao" SERVICE_FILE="/etc/systemd/system/kao.service" CURRENT_USER=$(whoami) echo "====================================" echo " Kao Installer" echo "====================================" echo "Install directory: $INSTALL_DIR" echo "Running as user: $CURRENT_USER" echo "" # Check if running with appropriate permissions if [ ! -w "/opt" ]; then echo "Error: Need write access to /opt" echo "Run with: sudo $0" exit 1 fi # Create install directory echo "[1/5] Creating install directory..." mkdir -p "$INSTALL_DIR" cp -r aggregator.py kao.py index.html config.json requirements.txt detectors "$INSTALL_DIR/" chown -R "$CURRENT_USER:$CURRENT_USER" "$INSTALL_DIR" # Create virtual environment echo "[2/5] Creating virtual environment..." cd "$INSTALL_DIR" python3 -m venv venv ./venv/bin/pip install --upgrade pip -q ./venv/bin/pip install -r requirements.txt -q # Create systemd service echo "[3/5] Creating systemd service..." cat > "$SERVICE_FILE" << EOF [Unit] Description=Kao - System Status Monitor After=network.target [Service] Type=simple User=$CURRENT_USER WorkingDirectory=$INSTALL_DIR ExecStart=$INSTALL_DIR/venv/bin/python $INSTALL_DIR/kao.py Restart=always RestartSec=5 [Install] WantedBy=multi-user.target EOF # Reload systemd and enable service echo "[4/5] Enabling service..." systemctl daemon-reload systemctl enable kao.service # Start service echo "[5/5] Starting Kao..." systemctl start kao.service echo "" echo "====================================" echo " Installation complete!" echo "====================================" echo "" echo "Kao is now running at http://$(hostname -I | awk '{print $1}'):5000" echo "" echo "Commands:" echo " sudo systemctl status kao # Check status" echo " sudo systemctl restart kao # Restart" echo " sudo systemctl stop kao # Stop" echo " sudo journalctl -u kao -f # View logs" echo "" echo "Config file: $INSTALL_DIR/config.json"