#!/bin/bash

# MarkBase Gitea Runner啟動腳本

RUNNER_BIN=~/.local/bin/gitea-runner
CONFIG_FILE=/Users/accusys/markbase/.runner

echo "啟動 Gitea Runner..."
echo "Runner版本：v1.0.3"
echo "Runner名稱：accusys-Mac-mini-M4-2.local"
echo "Gitea地址：https://gitea.momentry.ddns.net"

#檢查Runner配置是否存在
if [ ! -f "$CONFIG_FILE" ]; then
    echo "錯誤：Runner配置檔案不存在"
    echo "請先執行：gitea-runner register --instance https://gitea.momentry.ddns.net --token <YOUR_TOKEN>"
    exit 1
fi

#檢查Runner二進制檔案
if [ ! -f "$RUNNER_BIN" ]; then
    echo "錯誤：Runner未安裝"
    echo "請先下載：curl -L -o ~/.local/bin/gitea-runner https://gitea.com/gitea/runner/releases/download/v1.0.3/gitea-runner-1.0.3-darwin-arm64"
    exit 1
fi

#啟動Runner daemon
echo "Runner正在啟動..."
cd /Users/accusys/markbase
$RUNNER_BIN daemon

echo "Runner已停止"