Spaces:
Paused
Paused
Update sync_data.sh
Browse files- sync_data.sh +8 -6
sync_data.sh
CHANGED
|
@@ -13,16 +13,16 @@ IFS='/' read -r GITHUB_USER GITHUB_REPO <<< "$G_NAME"
|
|
| 13 |
|
| 14 |
# 构建 GitHub 仓库的克隆 URL,包含令牌
|
| 15 |
REPO_URL="https://${G_TOKEN}@github.com/${G_NAME}.git"
|
| 16 |
-
|
| 17 |
# 克隆仓库
|
| 18 |
echo "正在克隆仓库……"
|
| 19 |
-
git -c core.excludesFile=/dev/null -c core.attributesFile=/dev/null clone "$REPO_URL" ./github_data || {
|
| 20 |
echo "克隆失败,请检查 G_NAME 和 G_TOKEN 是否正确。"
|
| 21 |
exit 1
|
| 22 |
}
|
| 23 |
|
| 24 |
-
if [ -f ./github_data/webui.db ]; then
|
| 25 |
-
cp ./github_data/webui.db ./data/webui.db
|
| 26 |
echo "从 GitHub 仓库中拉取成功"
|
| 27 |
else
|
| 28 |
echo "GitHub 仓库中未找到 webui.db,将在同步时推送"
|
|
@@ -34,7 +34,7 @@ sync_data() {
|
|
| 34 |
# 1. 同步到 GitHub
|
| 35 |
echo "正在开始同步"
|
| 36 |
# 进入仓库目录
|
| 37 |
-
cd ./github_data
|
| 38 |
ls -la
|
| 39 |
# 配置 Git 用户信息
|
| 40 |
git config user.name "AutoSync Bot"
|
|
@@ -44,7 +44,7 @@ sync_data() {
|
|
| 44 |
git checkout main || git checkout master
|
| 45 |
|
| 46 |
# 复制最新的数据库文件
|
| 47 |
-
cp ../
|
| 48 |
|
| 49 |
# 检查是否有变化
|
| 50 |
if [[ -n $(git status -s) ]]; then
|
|
@@ -66,6 +66,7 @@ sync_data() {
|
|
| 66 |
}
|
| 67 |
# 返回上级目录
|
| 68 |
cd ..
|
|
|
|
| 69 |
|
| 70 |
# 2. 同步到 WebDAV
|
| 71 |
if [ -z "$WEBDAV_URL" ] || [ -z "$WEBDAV_USERNAME" ] || [ -z "$WEBDAV_PASSWORD" ]; then
|
|
@@ -94,6 +95,7 @@ sync_data() {
|
|
| 94 |
else
|
| 95 |
# 返回上级目录
|
| 96 |
cd ..
|
|
|
|
| 97 |
echo "GitHub: 没有检测到数据库变化"
|
| 98 |
fi
|
| 99 |
# 3. 等待统一的时间间隔
|
|
|
|
| 13 |
|
| 14 |
# 构建 GitHub 仓库的克隆 URL,包含令牌
|
| 15 |
REPO_URL="https://${G_TOKEN}@github.com/${G_NAME}.git"
|
| 16 |
+
mkdir -p ./data/github_data
|
| 17 |
# 克隆仓库
|
| 18 |
echo "正在克隆仓库……"
|
| 19 |
+
git -c core.excludesFile=/dev/null -c core.attributesFile=/dev/null clone "$REPO_URL" ./data/github_data || {
|
| 20 |
echo "克隆失败,请检查 G_NAME 和 G_TOKEN 是否正确。"
|
| 21 |
exit 1
|
| 22 |
}
|
| 23 |
|
| 24 |
+
if [ -f ./data/github_data/webui.db ]; then
|
| 25 |
+
cp ./data/github_data/webui.db ./data/webui.db
|
| 26 |
echo "从 GitHub 仓库中拉取成功"
|
| 27 |
else
|
| 28 |
echo "GitHub 仓库中未找到 webui.db,将在同步时推送"
|
|
|
|
| 34 |
# 1. 同步到 GitHub
|
| 35 |
echo "正在开始同步"
|
| 36 |
# 进入仓库目录
|
| 37 |
+
cd ./data/github_data
|
| 38 |
ls -la
|
| 39 |
# 配置 Git 用户信息
|
| 40 |
git config user.name "AutoSync Bot"
|
|
|
|
| 44 |
git checkout main || git checkout master
|
| 45 |
|
| 46 |
# 复制最新的数据库文件
|
| 47 |
+
cp ../webui.db ./webui.db
|
| 48 |
|
| 49 |
# 检查是否有变化
|
| 50 |
if [[ -n $(git status -s) ]]; then
|
|
|
|
| 66 |
}
|
| 67 |
# 返回上级目录
|
| 68 |
cd ..
|
| 69 |
+
cd ..
|
| 70 |
|
| 71 |
# 2. 同步到 WebDAV
|
| 72 |
if [ -z "$WEBDAV_URL" ] || [ -z "$WEBDAV_USERNAME" ] || [ -z "$WEBDAV_PASSWORD" ]; then
|
|
|
|
| 95 |
else
|
| 96 |
# 返回上级目录
|
| 97 |
cd ..
|
| 98 |
+
cd ..
|
| 99 |
echo "GitHub: 没有检测到数据库变化"
|
| 100 |
fi
|
| 101 |
# 3. 等待统一的时间间隔
|