From 6c121f1094c28e69490f016448dffd107ef937a6 Mon Sep 17 00:00:00 2001 From: liyanyan <215952619@qq.com> Date: Mon, 6 Jul 2026 00:06:07 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E6=85=A2=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sync.sh | 55 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/sync.sh b/sync.sh index 961fd5f..e68a1ff 100644 --- a/sync.sh +++ b/sync.sh @@ -1,40 +1,43 @@ #!/bin/bash set -e -echo "[1] update iptv-org repo" +echo "[sync] start $(date)" -if [ ! -d iptv ]; then - git clone https://github.com/iptv-org/iptv.git +# ===== config safety ===== +git config --global user.name "iptv-sync" +git config --global user.email "bot@local" +git config --global http.version HTTP/1.1 + +# ===== 1. github gh-pages ===== +if [ ! -d iptv/.git ]; then + git clone --depth 1 -b gh-pages https://github.com/iptv-org/iptv.git iptv +else + cd iptv + git fetch origin gh-pages + git reset --hard origin/gh-pages + cd .. fi -cd iptv -git fetch origin -git checkout gh-pages -git reset --hard origin/gh-pages -cd .. - -echo "[2] update gitea repo" - -if [ ! -d iptv-gh-pages ]; then +# ===== 2. gitea repo ===== +if [ ! -d iptv-gh-pages/.git ]; then git clone https://${GITEA_HOST}/${GITEA_REPO}.git iptv-gh-pages fi +# ===== 3. sync files ===== +rsync -a --delete \ + --exclude='.git' \ + iptv/ iptv-gh-pages/ + +# ===== 4. commit & push ===== cd iptv-gh-pages -git pull origin main || true -echo "[3] sync files" - -# 清空旧内容(保留 .git) -find . -mindepth 1 -maxdepth 1 ! -name ".git" -exec rm -rf {} + - -cp -r ../iptv/* . - -echo "[4] commit & push" - -git add . - -git commit -m "sync: $(date '+%Y-%m-%d %H:%M:%S')" || echo "no changes" +git add -A +git diff --cached --quiet && { + echo "[sync] no changes" + exit 0 +} +git commit -m "sync $(date '+%Y-%m-%d %H:%M:%S')" git push origin main -echo "[done]" \ No newline at end of file +echo "[sync] done $(date)" \ No newline at end of file