refactor: 优化同步慢的问题
This commit is contained in:
parent
d65f11a96c
commit
6c121f1094
55
sync.sh
55
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]"
|
||||
echo "[sync] done $(date)"
|
||||
Loading…
x
Reference in New Issue
Block a user