Debain-repos/docker/gitPush.sh
2025-05-24 10:22:28 +02:00

53 lines
1.5 KiB
Bash

#!/bin/sh
set -e
WORKPTH="/etc/debmirror/"
REPO_DIR="$WORKPTH/Repo-IP-lists"
REPO_URL="${GITURLPROTO}://${GITURL}/${GITREPOPATH}"
# Clone repo only if it doesn't already exist
if [ ! -d "$REPO_DIR/.git" ]; then
echo "[$(date)] Cloning repository..."
git clone "$REPO_URL" "$REPO_DIR"
fi
cd "$REPO_DIR"
# Make sure remote includes token for pushing
git remote set-url origin "https://${GITEA_TOKEN}@${GITURL}/${GITREPOPATH}"
# Check for unpushed commits
if [ "$(git rev-list --count origin/main..HEAD)" -gt 0 ]; then
echo "Found commits to push"
git push
echo "Pushed successfully"
else
echo "No new commits to push"
fi
# Set identity
git config user.name "UpdateBot"
git config user.email "UpdateBot@localhost.local"
# Stage and commit any local changes before pulling
git add MirrorListV4 MirrorListV6 OPNS_MirrorListV4 OPNS_MirrorListV6
if ! git diff --cached --quiet; then
echo "[$(date)] Committing local changes before pulling"
git commit -m "Auto-commit before pull on $(date -Iseconds)"
fi
# Pull latest updates
git pull --rebase --autostash
# Stage files again in case they changed due to updated script
git add MirrorListV4 MirrorListV6 OPNS_MirrorListV4 OPNS_MirrorListV6
# Commit and push only if there's something to commit
if ! git diff --cached --quiet; then
git commit -m "Auto-update mirror list on $(date -Iseconds)"
git push
echo "[$(date)] Changes pushed successfully."
else
echo "[$(date)] No new changes to commit."
fi