#!/bin/bash # ══════════════════════════════════════════════════════════════════════════════ # ARGOS SOC — Installer ambiente # Tecnotel Servizi SRL — Ubuntu 24.04 LTS # Uso: sudo bash install.sh # ══════════════════════════════════════════════════════════════════════════════ set -euo pipefail RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m' BLUE='\033[0;34m'; CYAN='\033[0;36m'; NC='\033[0m' info() { echo -e "${CYAN}[INFO]${NC} $1"; } success() { echo -e "${GREEN}[OK]${NC} $1"; } warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; } section() { echo -e "\n${BLUE}══════════════════════════════════════${NC}"; echo -e "${BLUE} $1${NC}"; echo -e "${BLUE}══════════════════════════════════════${NC}"; } [[ $EUID -ne 0 ]] && error "Eseguire come root: sudo bash install.sh" . /etc/os-release [[ "$ID" != "ubuntu" || "$VERSION_ID" != "24.04" ]] && error "Richiesto Ubuntu 24.04 LTS" echo "" echo -e "${BLUE}╔══════════════════════════════════════════╗${NC}" echo -e "${BLUE}║ ARGOS SOC — Installer v1.0.0 ║${NC}" echo -e "${BLUE}║ Tecnotel Servizi SRL ║${NC}" echo -e "${BLUE}╚══════════════════════════════════════════╝${NC}" echo "" GITEA_REPO="https://3eefb5a2802e8c5a9395396b1bb98e2d5fe46101@argos-update.tecnotelsrl.com:3443/tecnotel/argos.git" # ══════════════════════════════════════════════════════════════════════════════ section "1. Sistema base" # ══════════════════════════════════════════════════════════════════════════════ timedatectl set-timezone Europe/Rome apt-get update -qq apt-get upgrade -y -qq apt-get install -y -qq \ curl wget git vim htop unzip jq \ python3 python3-pip python3-venv \ nginx certbot python3-certbot-nginx \ ufw fail2ban \ build-essential libssl-dev libffi-dev python3-dev \ sqlite3 net-tools dnsutils lsof tcpdump nmap \ ca-certificates gnupg apt-transport-https success "Pacchetti sistema installati" # ══════════════════════════════════════════════════════════════════════════════ section "2. Node.js 20 LTS" # ══════════════════════════════════════════════════════════════════════════════ if ! node --version 2>/dev/null | grep -q "v2[02]"; then curl -fsSL https://deb.nodesource.com/setup_20.x | bash - >/dev/null 2>&1 apt-get install -y nodejs -qq fi success "Node.js $(node --version) installato" # ══════════════════════════════════════════════════════════════════════════════ section "3. Utente applicazione" # ══════════════════════════════════════════════════════════════════════════════ if ! id "argos" &>/dev/null; then useradd -r -s /bin/bash -m -d /home/argos argos success "Utente argos creato" else warn "Utente argos già esistente" fi # Aggiungi argos al gruppo systemd-journal per lettura log via journalctl # (necessario per la pagina 'Log Servizi' in UI) usermod -aG systemd-journal argos success "Utente argos aggiunto al gruppo systemd-journal" # Permetti a user 'argos' di restart dei servizi via UI (Backup & Restore) # Scope ristretto: solo restart dei 4 demoni ARGOS, nessun altro comando. cat > /etc/sudoers.d/argos-systemctl <<'SUDOEOF' argos ALL=(ALL) NOPASSWD: /bin/systemctl restart argos-backend argos ALL=(ALL) NOPASSWD: /bin/systemctl restart argos-sync argos ALL=(ALL) NOPASSWD: /bin/systemctl restart argos-ops argos ALL=(ALL) NOPASSWD: /bin/systemctl restart argos-analytics SUDOEOF chmod 440 /etc/sudoers.d/argos-systemctl visudo -cf /etc/sudoers.d/argos-systemctl > /dev/null success "Sudoers per restart servizi configurato" # ══════════════════════════════════════════════════════════════════════════════ section "4. Struttura cartelle" # ══════════════════════════════════════════════════════════════════════════════ mkdir -p /opt/argos/{app,config,data,feeds,logs,certs,backups,setup} mkdir -p /opt/argos/config/assets mkdir -p /opt/argos/data/{reports,models} chown -R argos:argos /opt/argos chmod -R 750 /opt/argos # /opt/argos/feeds: pubblicamente leggibili (FortiGate ETF via nginx/www-data) chmod 755 /opt/argos/feeds success "Struttura /opt/argos/ creata" # ══════════════════════════════════════════════════════════════════════════════ section "5. Clone repository" # ══════════════════════════════════════════════════════════════════════════════ git config --global --add safe.directory /opt/argos/app 2>/dev/null || true if [[ -d /opt/argos/app/.git ]]; then warn "Repository già presente — aggiorno" git -C /opt/argos/app pull origin main else git clone "$GITEA_REPO" /opt/argos/app fi chown -R argos:argos /opt/argos/app success "Repository clonato in /opt/argos/app/" # ══════════════════════════════════════════════════════════════════════════════ section "6. Python virtualenv" # ══════════════════════════════════════════════════════════════════════════════ python3 -m venv /opt/argos/app/backend/venv /opt/argos/app/backend/venv/bin/pip install --upgrade pip -q if [[ -f /opt/argos/app/backend/requirements.txt ]]; then /opt/argos/app/backend/venv/bin/pip install -r /opt/argos/app/backend/requirements.txt -q success "Dipendenze Python installate" else warn "requirements.txt non trovato — installare manualmente dopo" fi chown -R argos:argos /opt/argos/app/backend/venv # ══════════════════════════════════════════════════════════════════════════════ section "7. Firewall UFW" # ══════════════════════════════════════════════════════════════════════════════ ufw --force reset >/dev/null ufw default deny incoming >/dev/null ufw default allow outgoing >/dev/null ufw allow 22/tcp comment 'SSH' >/dev/null ufw allow 80/tcp comment 'HTTP' >/dev/null ufw allow 443/tcp comment 'HTTPS' >/dev/null ufw allow 8888/tcp comment 'ARGOS Web Installer (temporaneo)' >/dev/null ufw --force enable >/dev/null success "Firewall UFW configurato" # ══════════════════════════════════════════════════════════════════════════════ section "8. Fail2ban" # ══════════════════════════════════════════════════════════════════════════════ systemctl enable --now fail2ban >/dev/null 2>&1 success "Fail2ban attivo" # ══════════════════════════════════════════════════════════════════════════════ section "9. Nginx temporaneo" # ══════════════════════════════════════════════════════════════════════════════ rm -f /etc/nginx/sites-enabled/default cat > /etc/nginx/sites-available/argos-setup << 'NGINX' server { listen 80 default_server; server_name _; return 200 'ARGOS SOC Setup in corso — vai a http://IP:8888'; add_header Content-Type text/plain; } NGINX ln -sf /etc/nginx/sites-available/argos-setup /etc/nginx/sites-enabled/ nginx -t && systemctl restart nginx success "Nginx temporaneo configurato" # ══════════════════════════════════════════════════════════════════════════════ section "10. Web Installer" # ══════════════════════════════════════════════════════════════════════════════ # Copia file setup cp /opt/argos/app/scripts/setup_server.py /opt/argos/setup/ cp /opt/argos/app/scripts/setup.html /opt/argos/setup/ # Systemd service web installer cat > /etc/systemd/system/argos-setup.service << 'EOF' [Unit] Description=ARGOS SOC Web Installer After=network.target [Service] Type=simple User=root WorkingDirectory=/opt/argos/setup ExecStart=/opt/argos/app/backend/venv/bin/python3 /opt/argos/setup/setup_server.py Restart=on-failure RestartSec=3 StandardOutput=journal StandardError=journal SyslogIdentifier=argos-setup [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable --now argos-setup success "Web installer avviato" SERVER_IP=$(hostname -I | awk '{print $1}') echo "" echo -e "${GREEN}╔══════════════════════════════════════════════════════╗${NC}" echo -e "${GREEN}║ Ambiente pronto! ║${NC}" echo -e "${GREEN}╚══════════════════════════════════════════════════════╝${NC}" echo "" echo -e " ${CYAN}Completa la configurazione aprendo nel browser:${NC}" echo -e " ${YELLOW}→ http://${SERVER_IP}:8888${NC}" echo "" echo -e " ${YELLOW}NOTA:${NC} La porta 8888 verrà chiusa automaticamente" echo -e " al termine dell'installazione." echo ""