#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="/home/ai/work/SHiNE/SHiNE-server-sha256"
SERVICE_DIR="${ROOT_DIR}/SHiNE-agent-bot-coder"
UNIT_SRC="${SERVICE_DIR}/scripts/systemd/shine-agent-bot-coder.service"
UNIT_DST="${HOME}/.config/systemd/user/shine-agent-bot-coder.service"

echo "[1/6] Проверка python3..."
command -v python3 >/dev/null 2>&1 || { echo "python3 не найден"; exit 1; }

echo "[2/6] Подготовка папки логов..."
mkdir -p "${SERVICE_DIR}/logs"

echo "[3/6] Копирование user systemd unit..."
mkdir -p "$(dirname "${UNIT_DST}")"
cp "${UNIT_SRC}" "${UNIT_DST}"

echo "[4/6] daemon-reload..."
systemctl --user daemon-reload

echo "[5/6] enable + start..."
systemctl --user enable --now shine-agent-bot-coder

echo "[6/6] Статус:"
systemctl --user status shine-agent-bot-coder --no-pager

echo "Готово. Логи: journalctl --user -u shine-agent-bot-coder -f"
