Debain-repos/docker/gitPush.sh
2025-05-22 13:58:40 +02:00

44 lines
1.0 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"
git remote set-url origin "https://${GITEA_TOKEN}@${GITURL}/${GITREPOPATH}"
git config user.name "UpdateBot"
git config user.email "UpdateBot@localhost.local"
# If anything to commit locally, commit it now
if ! git diff --quiet; then
echo "[$(date)] Committing local changes before pulling"
git commit -m "Auto-commit before pull on $(date -Iseconds)"
fi
# Now pull the latest
git pull --rebase --autostash
# stage files
git add MirrorListV4 MirrorListV6
# Commit and push only if there's anything new staged
if git diff --quiet; then
echo "[$(date)] No changes to commit."
else
git commit -a -m "Auto-update mirror list on $(date -Iseconds)" --quiet
git push --quiet
echo "[$(date)] Changes pushed successfully."
fi