#!/bin/sh set -e # Check if these are passed and terminate if they are not GITEA_TOKEN="${GITEA_TOKEN:-6767}" GITURL="${GITURL:-6767}" GITREPOPATH="${GITREPOPATH:-6767}" GITURLPROTO="${GITURLPROTO:-http}" # if [[ "$GITEA_TOKEN" == "6767" || "$GITREPOPATH" == "6767" || "$GITURL" == "6767" ]]; then if [[ "$GITEA_TOKEN" == "6767" ]]; then exit 1 fi WORKPTH="${WORKPTH:-/etc/debmirror/}" REPO_DIR="${REPO_DIR:-$WORKPTH/Repo-IP-lists}" REPO_URL="${REPO_URL:-GITURLPROTO://GITURL/GITREPOPATH}" # Clone repo if not exists if [[ ! -d "$REPO_DIR/.git" ]]; then echo "[$(date)] Cloning repository..." git clone "$REPO_URL" "$REPO_DIR" fi cd "$REPO_DIR" # Abort previous rebase/cherry-pick if stuck git rebase --abort 2>/dev/null || true git cherry-pick --abort 2>/dev/null || true # Make sure we're on a clean 'main' git checkout main || git checkout -b main origin/main git pull --rebase --autostash # git remote set-url origin "${GITURLPROTO}://${GITEA_TOKEN}@${GITURL}/${GITREPOPATH}" git remote set-url origin "https://${GITEA_TOKEN}@YuruC3/Repo-IP-lists" git config user.name "UpdateBot" git config user.email "UpdateBot@localhost.local" # Stage the files git add MirrorListV4 MirrorListV6 OPNS_MirrorListV4 OPNS_MirrorListV6 # Only proceed if there are staged changes if [[ ! git diff --quiet --cached ]]; then echo "[$(date)] Committing and pushing changes..." git commit -m "Auto-update mirror list on $(date -Iseconds)" # git pull --rebase --autostash git push --quiet echo "[$(date)] Changes pushed." else echo "[$(date)] No changes to commit or push." fi # #!/bin/sh # set -e # WORKPTH="/etc/debmirror/" # REPO_DIRd="$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" # # stage files # git add MirrorListV4 MirrorListV6 OPNS_MirrorListV4 OPNS_MirrorListV6 # # If anything to commit locally, commit it now # if ! git diff --quiet --cached; 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 # # 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