sync_to_gogs.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. # ============================================================
  3. # PlateRecApp 自动同步到 Gogs 仓库
  4. # 仓库: https://git.zhonjin.com:40717/steven_roc/PlateRecApp
  5. # ============================================================
  6. set -e
  7. REPO_URL="https://steven_roc:1942ce3d6478f7a572fee3dd4891e49f6c416aad@git.zhonjin.com:40717/steven_roc/PlateRecApp.git"
  8. WORK_DIR="/opt/openAI/project/003.PlateRecAPP"
  9. COMMIT_MSG="${1:-auto sync: $(date '+%Y-%m-%d %H:%M:%S')}"
  10. echo "=========================================="
  11. echo " PlateRecApp -> Gogs 自动同步"
  12. echo " 时间: $(date '+%Y-%m-%d %H:%M:%S')"
  13. echo "=========================================="
  14. # 检查是否在源码目录
  15. if [ ! -f "$WORK_DIR/CMakeLists.txt" ]; then
  16. echo "错误: 未找到 $WORK_DIR/CMakeLists.txt"
  17. echo "请确认源码目录路径正确"
  18. exit 1
  19. fi
  20. cd "$WORK_DIR"
  21. # 初始化 git(首次)
  22. if [ ! -d ".git" ]; then
  23. echo "[1/4] 初始化 Git 仓库..."
  24. git init
  25. git remote add origin "$REPO_URL" 2>/dev/null || git remote set-url origin "$REPO_URL"
  26. git checkout -b master
  27. # 配置 git
  28. git config user.email "steven_roc@126.com"
  29. git config user.name "steven_roc"
  30. # 创建 .gitignore
  31. cat > .gitignore << 'EOF'
  32. # 编译产物
  33. build/
  34. *.o
  35. *.obj
  36. *.exe
  37. PlateRecApp
  38. # 配置文件(含敏感信息)
  39. config.ini
  40. config_*.ini
  41. # 日志
  42. *.log
  43. logs/
  44. # 数据库
  45. *.db
  46. *.sqlite
  47. # 临时文件
  48. *.tmp
  49. *.bak
  50. *.swp
  51. *~
  52. # 系统文件
  53. .DS_Store
  54. Thumbs.db
  55. # IDE
  56. .vscode/
  57. .idea/
  58. *.suo
  59. *.user
  60. EOF
  61. echo "[2/4] 首次提交..."
  62. git add -A
  63. git commit -m "init: PlateRecApp fix27 v44 完整代码初始化"
  64. else
  65. echo "[1/4] Git 仓库已存在"
  66. echo "[2/4] 检查变更..."
  67. git config user.email "steven_roc@126.com"
  68. git config user.name "steven_roc"
  69. CHANGES=$(git status --porcelain | wc -l)
  70. if [ "$CHANGES" -eq 0 ]; then
  71. echo "没有检测到代码变更,跳过同步"
  72. exit 0
  73. fi
  74. echo "检测到 $CHANGES 个文件变更"
  75. git add -A
  76. git commit -m "$COMMIT_MSG"
  77. fi
  78. echo "[3/4] 推送到 Gogs..."
  79. git push -u origin master --force
  80. echo "[4/4] 同步完成!"
  81. echo ""
  82. echo "仓库地址: https://git.zhonjin.com:40717/steven_roc/PlateRecApp"
  83. echo "同步时间: $(date '+%Y-%m-%d %H:%M:%S')"
  84. echo "=========================================="