#!/usr/bin/env bash # ═══════════════════════════════════════════════════════════════════════════════ # 🦊 Foxy Dev Team — Service Installer # ═══════════════════════════════════════════════════════════════════════════════ # Installs systemd user services for: # - foxy-api (FastAPI backend) # - foxy-telegram (Telegram bot v3) # # Usage: # chmod +x install-services.sh # ./install-services.sh # # The services run under the current user (systemd --user). # ═══════════════════════════════════════════════════════════════════════════════ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" SERVICE_DIR="$HOME/.config/systemd/user" ENV_FILE="$PROJECT_DIR/backend/.env" RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; NC='\033[0m' log() { echo -e "${CYAN}[INSTALL]${NC} $1"; } ok() { echo -e "${GREEN} ✅${NC} $1"; } warn() { echo -e "${YELLOW} ⚠️${NC} $1"; } err() { echo -e "${RED} ❌${NC} $1"; } # ─── Pre-checks ─────────────────────────────────────────────────────────────── log "🦊 Foxy Dev Team — Installation des services" echo "" if ! command -v python3 &>/dev/null; then err "python3 non trouvé. Installez Python 3.10+." exit 1 fi if ! command -v uvicorn &>/dev/null; then warn "uvicorn non trouvé. Installation des dépendances..." pip3 install -r "$PROJECT_DIR/backend/requirements.txt" fi if [ ! -f "$ENV_FILE" ]; then warn "Fichier .env non trouvé. Copie du template..." cp "$PROJECT_DIR/backend/.env.example" "$ENV_FILE" warn "⚠️ IMPORTANT : Éditez $ENV_FILE avec vos valeurs réelles !" fi # ─── Create systemd directory ───────────────────────────────────────────────── mkdir -p "$SERVICE_DIR" # ─── foxy-api.service ───────────────────────────────────────────────────────── log "Création du service foxy-api..." cat > "$SERVICE_DIR/foxy-api.service" < "$SERVICE_DIR/foxy-telegram.service" </dev/null || true log "Démarrage des services..." systemctl --user start foxy-api.service ok "foxy-api démarré" # Wait for API to be ready before starting the bot sleep 3 systemctl --user start foxy-telegram.service ok "foxy-telegram démarré" echo "" log "═══════════════════════════════════════════════════════════" log "🦊 Installation terminée !" echo "" log " Commandes utiles :" echo " systemctl --user status foxy-api" echo " systemctl --user status foxy-telegram" echo " journalctl --user -u foxy-api -f" echo " journalctl --user -u foxy-telegram -f" echo "" log " Dashboard : http://localhost:5173" log " API : http://localhost:7000" log " API Docs : http://localhost:7000/docs" log "═══════════════════════════════════════════════════════════"