#!/bin/bash
# 首次推送Git仓库脚本

set -e

echo "========================================="
echo "首次推送Git仓库"
echo "========================================="

# 配置
NOVEL_PATH="/root/.openclaw/workspace/tomato-novel/books/末日重生-开局囤货十亿物资"
GIT_REPO_NAME="novel-morizhongsheng"
GIT_REMOTE_URL="https://gitea.nevadaladalice.top:226/liyuchen/$GIT_REPO_NAME.git"
GIT_USERNAME="liyuchen"
GIT_PASSWORD="liyuchen"

echo "📁 小说路径: $NOVEL_PATH"
echo "🌐 Git仓库: $GIT_REMOTE_URL"

# 检查网络连通性
echo "🔗 检查网络连通性..."
if curl -s --connect-timeout 10 "https://gitea.nevadalice.top:226/" > /dev/null; then
    echo "✅ Gitea 服务器可达"
else
    echo "❌ 无法连接到 Gitea 服务器"
    echo "请检查网络连接和防火墙设置"
    exit 1
fi

# 运行初始化脚本
echo "🔄 运行Git仓库初始化..."
/root/.openclaw/workspace/git_sync_system/init_git_repo.sh

echo "========================================="
echo "🎉 已完成Git仓库准备"
echo "========================================="
echo ""
echo "📋 下一步操作:"
echo "1. 在Gitea创建仓库: $GIT_REPO_NAME"
echo "2. 运行同步脚本: sync_to_git.sh"
echo "3. 设置定时任务: setup_cron.sh"
echo ""
echo "💡 重要提示:"
echo "- 首次使用需要先在Gitea创建同名仓库"
echo "- 首次推送可能需要输入凭据"
echo "- 建议使用SSH密钥认证"
echo "========================================="