argos-setup/first-setup.sh

191 lines
11 KiB
Bash
Raw Normal View History

#!/bin/bash
# ══════════════════════════════════════════════════════════════════════════════
# ARGOS SOC — Installer ambiente
# Tecnotel Servizi SRL — Ubuntu 24.04 LTS
# Uso: sudo bash first-setup.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 first-setup.sh"
. /etc/os-release
feat(setup): Ubuntu 26.04 LTS support + cert autofirmato + 3 file .example Modifiche di compatibilita' e miglioramenti UX dopo analisi del 12/05/26 del codice argos main repo vs argos-setup. 1. Multi-version Ubuntu (24.04 e 26.04 LTS): - first-setup.sh: SUPPORTED_VERSIONS array per check - Aggiunto openssl esplicito alle dipendenze apt - README aggiornato con compatibility matrix - ARGOS code (Python 3.14-ready: no distutils/imp/pkg_resources) gia' compatibile, requirements.txt pin gia' build 2026 2. Certificato SSL autofirmato come 3a opzione: - UI: bottone '🔐 Autofirmato' nel Tab Rete & SSL - Backend: openssl req -x509 -newkey rsa:4096 -days 3650 - SAN dinamica: tutti i DNS (hostname + aliases) + IP server - Subject: C=IT, O=<cliente_full>, OU=ARGOS SOC, CN=<hostname> - Warning UI prominente sulla non-attendibilita' browser - Utile per installazioni LAN/dev senza DNS pubblico 3. Rimozione campi M365: - sp_tenant (SharePoint tenant) rimosso da Tab Cliente - sharepoint_tenant non piu' nel argos.json generato - M365/Entra ID configurabile dall'UI Integrazioni post-install 4. Textarea ai_context opzionale nel Tab Cliente: - Iniettato nei prompt AI per contestualizzare il cliente - Hint con esempio ASREM - Salvato in argos.json -> cliente.ai_context (letto da config.py) 5. Copia di 3 file .example che il setup non gestiva: - automations.json (config feed TI sources + cron daemon) - siem_integrations.json (catalogo SIEM Integration Builder) - subnet_registry.json (mapping sede/reparto da subnet) Necessari dopo i lavori marzo-maggio 2026. 6. Rimozione gen_config.py legacy: - Schema obsoleto (manca ai_context, console_url, network, vendor_heartbeat) - Non piu' richiamato da nessuno (verificato con grep) - Sostituito completamente da setup_server.py inline 7. README aggiornato: - Sezione 'Opzioni certificato SSL' con 3 modalita' - Requisiti: Ubuntu 24.04 LTS o 26.04 LTS - Tab 2 menziona contesto AI opzionale
2026-05-12 11:20:37 +02:00
SUPPORTED_VERSIONS=("24.04" "26.04")
VERSION_OK=0
for v in "${SUPPORTED_VERSIONS[@]}"; do
[[ "$VERSION_ID" == "$v" ]] && VERSION_OK=1
done
[[ "$ID" != "ubuntu" || $VERSION_OK -eq 0 ]] && \
error "Richiesto Ubuntu 24.04 o 26.04 LTS (rilevato: $ID $VERSION_ID)"
info "Sistema rilevato: Ubuntu $VERSION_ID LTS"
echo ""
echo -e "${BLUE}╔══════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ ARGOS SOC — Setup ambiente base ║${NC}"
echo -e "${BLUE}║ Tecnotel Servizi SRL ║${NC}"
echo -e "${BLUE}╚══════════════════════════════════════════╝${NC}"
echo ""
# ══════════════════════════════════════════════════════════════════════════════
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 python3-cryptography \
nginx certbot python3-certbot-nginx \
ufw fail2ban \
build-essential libssl-dev libffi-dev python3-dev \
sqlite3 net-tools dnsutils lsof tcpdump nmap \
feat(setup): Ubuntu 26.04 LTS support + cert autofirmato + 3 file .example Modifiche di compatibilita' e miglioramenti UX dopo analisi del 12/05/26 del codice argos main repo vs argos-setup. 1. Multi-version Ubuntu (24.04 e 26.04 LTS): - first-setup.sh: SUPPORTED_VERSIONS array per check - Aggiunto openssl esplicito alle dipendenze apt - README aggiornato con compatibility matrix - ARGOS code (Python 3.14-ready: no distutils/imp/pkg_resources) gia' compatibile, requirements.txt pin gia' build 2026 2. Certificato SSL autofirmato come 3a opzione: - UI: bottone '🔐 Autofirmato' nel Tab Rete & SSL - Backend: openssl req -x509 -newkey rsa:4096 -days 3650 - SAN dinamica: tutti i DNS (hostname + aliases) + IP server - Subject: C=IT, O=<cliente_full>, OU=ARGOS SOC, CN=<hostname> - Warning UI prominente sulla non-attendibilita' browser - Utile per installazioni LAN/dev senza DNS pubblico 3. Rimozione campi M365: - sp_tenant (SharePoint tenant) rimosso da Tab Cliente - sharepoint_tenant non piu' nel argos.json generato - M365/Entra ID configurabile dall'UI Integrazioni post-install 4. Textarea ai_context opzionale nel Tab Cliente: - Iniettato nei prompt AI per contestualizzare il cliente - Hint con esempio ASREM - Salvato in argos.json -> cliente.ai_context (letto da config.py) 5. Copia di 3 file .example che il setup non gestiva: - automations.json (config feed TI sources + cron daemon) - siem_integrations.json (catalogo SIEM Integration Builder) - subnet_registry.json (mapping sede/reparto da subnet) Necessari dopo i lavori marzo-maggio 2026. 6. Rimozione gen_config.py legacy: - Schema obsoleto (manca ai_context, console_url, network, vendor_heartbeat) - Non piu' richiamato da nessuno (verificato con grep) - Sostituito completamente da setup_server.py inline 7. README aggiornato: - Sezione 'Opzioni certificato SSL' con 3 modalita' - Requisiti: Ubuntu 24.04 LTS o 26.04 LTS - Tab 2 menziona contesto AI opzionale
2026-05-12 11:20:37 +02:00
ca-certificates gnupg apt-transport-https openssl
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"
# Permetti a user 'argos' di eseguire update.sh via UI (Release Notes -> Esegui update)
# Scope ristretto: SOLO update.sh, no wildcard, no shell generica.
# Path duplicato perché /usr/bin/bash e /bin/bash sono symlink ma sudoers
# matcha sul path esatto richiesto dall'invocatore.
cat > /etc/sudoers.d/argos-update <<'SUDOEOF'
argos ALL=(root) NOPASSWD: /usr/bin/bash /opt/argos/app/scripts/update.sh
argos ALL=(root) NOPASSWD: /bin/bash /opt/argos/app/scripts/update.sh
SUDOEOF
chmod 440 /etc/sudoers.d/argos-update
visudo -cf /etc/sudoers.d/argos-update > /dev/null
success "Sudoers per update.sh da UI configurato"
# ══════════════════════════════════════════════════════════════════════════════
section "4. Struttura cartelle"
# ══════════════════════════════════════════════════════════════════════════════
mkdir -p /opt/argos/{app,config,data,feeds,logs,certs,backups}
mkdir -p /opt/argos/config/assets
mkdir -p /opt/argos/data/{reports,models}
chown -R argos:argos /opt/argos
chown -R argos:argos /opt/argos-setup-pkg
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. 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 "6. Fail2ban"
# ══════════════════════════════════════════════════════════════════════════════
systemctl enable --now fail2ban >/dev/null 2>&1
success "Fail2ban attivo"
# ══════════════════════════════════════════════════════════════════════════════
section "7. 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 "8. Web Installer"
# ══════════════════════════════════════════════════════════════════════════════
# Il service argos-setup girera' direttamente da /opt/argos-setup-pkg/
# (cartella del bootstrap clone). A fine install la cartella viene rimossa.
# 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-pkg
ExecStart=/usr/bin/python3 /opt/argos-setup-pkg/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 ""