#!/usr/bin/env bash # ═══════════════════════════════════════════════════════════════ # heima-manager — Installation complète Debian 12 # Cline + Kanban + Web UI Manager + SkillServer/Memorizer bridge # ═══════════════════════════════════════════════════════════════ set -euo pipefail # ── Couleurs ── RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m' BLUE='\033[0;34m'; CYAN='\033[0;36m'; NC='\033[0m' log() { echo -e "${GREEN}[✓]${NC} $1"; } warn() { echo -e "${YELLOW}[!]${NC} $1"; } err() { echo -e "${RED}[✗]${NC} $1"; } info() { echo -e "${CYAN}[i]${NC} $1"; } header(){ echo -e "\n${BLUE}══════════════════════════════════════${NC}"; echo -e "${BLUE} $1${NC}"; echo -e "${BLUE}══════════════════════════════════════${NC}\n"; } # ── Détection Debian 12 ── if [ ! -f /etc/debian_version ] || [ "$(cat /etc/debian_version | cut -d. -f1)" != "12" ]; then warn "Ce script est conçu pour Debian 12. Autres distributions non testées." read -rp "Continuer ? (y/N) " ans [[ "$ans" =~ ^[YyOo]$ ]] || exit 1 fi HEIMA_DIR="/opt/heima-manager" CONFIG_DIR="${HOME}/.config/heima-manager" LOG_DIR="${CONFIG_DIR}/logs" CLINE_DIR="${HOME}/.config/cline" KANBAN_DIR="${HOME}/.config/kanban" SKILL_SERVER="${SKILL_SERVER_URL:-https://skill.tordais.cc}" MEMORIZER_URL="${MEMORIZER_URL:-https://memorizer.tordais.cc}" mkdir -p "$HEIMA_DIR" "$CONFIG_DIR" "$LOG_DIR" "$CLINE_DIR" "$KANBAN_DIR" # ── Étape 1 : Dépendances système ── header "Étape 1/6 — Dépendances système" sudo apt-get update -qq sudo apt-get install -y -qq curl git ca-certificates gnupg lsb-release ufw jq # ── Étape 2 : Node.js 22 LTS ── header "Étape 2/6 — Node.js 22 LTS" if command -v node &>/dev/null && [[ "$(node --version)" =~ ^v2[2-9] ]]; then log "Node.js $(node --version) déjà installé" else curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - sudo apt-get install -y -qq nodejs log "Node.js $(node --version) installé" fi # ── Étape 3 : Cline CLI + Kanban ── header "Étape 3/6 — Cline CLI + Kanban" npm install -g cline kanban 2>&1 | tail -1 log "Cline $(cline --version 2>/dev/null || echo 'ok')" log "Kanban $(kanban --version 2>/dev/null || echo 'ok')" # ── Étape 4 : Config MCP (SkillServer + Memorizer) ── header "Étape 4/6 — Connexion SkillServer + Memorizer" if [ ! -f "${CLINE_DIR}/mcp.json" ]; then cat > "${CLINE_DIR}/mcp.json" << MCPEOF { "mcpServers": { "skillserver": { "command": "bash", "args": [ "-c", "curl -sfL ${SKILL_SERVER}/api/v1/subagents/ | jq -r '.[] | \"\(.name) \(.latestVersion)\"' | while read name ver; do curl -sfL \"${SKILL_SERVER}/api/v1/subagents/\${name}/\${ver}/agent.md\" -o \"${CLINE_DIR}/skills/\${name}.md\"; done && echo \"Synced agents from SkillServer\"" ] }, "memorizer": { "type": "remote", "url": "${MEMORIZER_URL}/mcp", "env": { "MEMORIZER_API_KEY": "\${MEMORIZER_KEY:-}" } } } } MCPEOF log "Config MCP créée dans ${CLINE_DIR}/mcp.json" else warn "Fichier MCP existe déjà — vérifie ${CLINE_DIR}/mcp.json" fi # ── Étape 5 : Service systemd pour Kanban ── header "Étape 5/6 — Service systemd Kanban" KANBAN_PORT="${KANBAN_PORT:-3000}" sudo tee /etc/systemd/system/heima-kanban.service > /dev/null << SERVICEOF [Unit] Description=Heima Manager — Kanban UI (Cline multi-agents) After=network.target [Service] Type=simple User=${USER} WorkingDirectory=${HOME} ExecStart=$(which node) $(which kanban) --port ${KANBAN_PORT} --host 0.0.0.0 Restart=on-failure RestartSec=5 Environment=NODE_ENV=production Environment=KANBAN_PORT=${KANBAN_PORT} StandardOutput=append:${LOG_DIR}/kanban.log StandardError=append:${LOG_DIR}/kanban-error.log [Install] WantedBy=default.target SERVICEOF # ── Étape 6 : Web UI Manager ── header "Étape 6/6 — Web UI Manager (port 4321)" cp manager.js "${HEIMA_DIR}/manager.js" cp update.sh "${HEIMA_DIR}/update.sh" chmod +x "${HEIMA_DIR}/update.sh" sudo tee /etc/systemd/system/heima-manager.service > /dev/null << SERVICEOF [Unit] Description=Heima Manager — Web UI After=network.target heima-kanban.service [Service] Type=simple User=${USER} WorkingDirectory=${HEIMA_DIR} ExecStart=$(which node) manager.js Restart=on-failure RestartSec=5 Environment=NODE_ENV=production Environment=SKILL_SERVER_URL=${SKILL_SERVER} Environment=MEMORIZER_URL=${MEMORIZER_URL} StandardOutput=append:${LOG_DIR}/manager.log StandardError=append:${LOG_DIR}/manager-error.log [Install] WantedBy=default.target SERVICEOF sudo systemctl daemon-reload sudo systemctl enable heima-kanban heima-manager sudo systemctl restart heima-kanban heima-manager # ── Firewall ── header "Configuration pare-feu" sudo ufw allow "${KANBAN_PORT}/tcp" 2>/dev/null || warn "ufw non actif, skip" sudo ufw allow 4321/tcp 2>/dev/null || true # ── Résumé ── header "✅ Installation terminée" echo "" echo -e " ${CYAN}Kanban UI :${NC} http://$(hostname -I 2>/dev/null | awk '{print $1}'):${KANBAN_PORT}" echo -e " ${CYAN}Manager UI :${NC} http://$(hostname -I 2>/dev/null | awk '{print $1}'):4321" echo "" echo -e " ${YELLOW}Commandes utiles :${NC}" echo " systemctl status heima-kanban — État Kanban" echo " systemctl status heima-manager — État Manager" echo " journalctl -u heima-manager -f — Logs Manager" echo " journalctl -u heima-kanban -f — Logs Kanban" echo " ${HEIMA_DIR}/update.sh — Mise à jour manuelle" echo "" echo -e " ${YELLOW}MCP config :${NC} ${CLINE_DIR}/mcp.json" echo " SkillServer → ${SKILL_SERVER}" echo " Memorizer → ${MEMORIZER_URL}" echo "" # ── Agent "rêve" : analyse nocturne automatique (optionnel) ── if [[ "${INSTALL_DREAM_AGENT:-n}" =~ ^[YyOo]$ ]]; then header "Installation agent rêve (cron analyse nocturne)" (crontab -l 2>/dev/null || true; echo "0 3 * * * cd ${HOME} && cline --headless --json 'Analyze the codebase for bugs, anti-patterns, and improvement opportunities. File issues for each finding.' >> ${LOG_DIR}/dream-agent.log 2>&1") | crontab - log "Cron ajouté : analyse quotidienne à 3h du matin" fi log "Rends-toi sur l'interface Manager pour la configuration avancée !"