Files
users/scripts/push-to-github.sh

71 lines
2.3 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 以本地为准:上传本地全部文件到 GitHub 与 Gitea不拉取、不改本地
# 在终端执行: bash scripts/push-to-github.sh
set -e
cd "$(dirname "$0")/.."
# 从卡若AI 账号与API索引 提取 GitHub Token
TOKEN_FILE="$HOME/Documents/个人/卡若AI/01_卡资/_团队成员/金盾/账号密码与资料管理/账号与API索引.md"
if [ -f "$TOKEN_FILE" ]; then
GITHUB_TOKEN=$(grep "Token.*ghp_" "$TOKEN_FILE" | sed -E "s/.*\`([^\`]+)\`.*/\1/")
fi
if [ -z "$GITHUB_TOKEN" ]; then
echo "未找到 GitHub Token使用 origin 推送(需已配置凭据)"
PUSH_URL="origin"
else
PUSH_URL="https://${GITHUB_TOKEN}@github.com/fnvtk/users.git"
echo "已从卡若AI 读取 Token"
fi
GITEA_TOKEN="07f82fbd81a64fb714d9a6c47b11cc5b98f2fa2e"
GITEA_URL="http://fnvtk:${GITEA_TOKEN}@open.quwanzhi.com:3000/fnvtk/users.git"
echo "=== 1. 当前状态(本地分支) ==="
git status
echo ""
echo "=== 2. 添加本地全部文件 ==="
git add -A
git status
echo ""
echo "=== 3. 提交(有变更才提交) ==="
if git diff --cached --quiet; then
echo "工作区无新变更,将直接以当前提交强制覆盖远程"
else
git commit -m "chore: 以本地为准,上传全部并替换 GitHub"
echo "提交完成"
fi
echo ""
echo "=== 4. 推送到 GitHub main ==="
git push "$PUSH_URL" HEAD:main
echo ""
echo "=== 5. 强制推送到 GitHub v0/fnvtk-5efaab9c ==="
# 当前分支HEAD覆盖远程 v0/fnvtk-5efaab9c重叠处一律以本地为准
git push --force "$PUSH_URL" HEAD:v0/fnvtk-5efaab9c
echo ""
echo "=== 6. 确保 Gitea 仓库存在 ==="
curl -u "fnvtk:zhiqun1984" -X POST "http://open.quwanzhi.com:3000/api/v1/user/repos" \
-H "Content-Type: application/json" \
-d '{"name":"users","description":"神射手 users 仓库","private":false}' || true
echo ""
echo "=== 7. 配置并推送到 Gitea main ==="
if git remote get-url gitea >/dev/null 2>&1; then
git remote set-url gitea "$GITEA_URL"
else
git remote add gitea "$GITEA_URL"
fi
unset HTTP_PROXY HTTPS_PROXY ALL_PROXY
GIT_HTTP_VERSION=HTTP/1.1 git push -u gitea HEAD:main
echo ""
echo "=== 完成 ==="
echo "GitHub main: https://github.com/fnvtk/users/tree/main"
echo "GitHub v0: https://github.com/fnvtk/users/tree/v0/fnvtk-5efaab9c"
echo "Gitea: http://open.quwanzhi.com:3000/fnvtk/users"