#!/bin/sh # Function to process each repo-destination pair process_repo() { REPO_URL=$1 DESTINATION=$2 # Set Git credentials git config --global credential.helper 'store --file /tmp/git-credentials' echo "url=$REPO_URL" > /tmp/git-credentials echo "username=$GIT_USERNAME" >> /tmp/git-credentials echo "password=$GIT_PASSWORD" >> /tmp/git-credentials # Directory to hold the repository locally REPO_DIR="/root/Repo_Cache/$(basename $REPO_URL)" # Clone the repo if it doesn't exist, or navigate to it if it does if [ ! -d "$REPO_DIR" ]; then curl -d "Cloning: $REPO_URL" $NTFY_URL echo "Cloning: $REPO_URL" git clone "$REPO_URL" "$REPO_DIR" fi cd "$REPO_DIR" # Fetch the latest changes git fetch origin main # Check if the local repository is behind the remote LOCAL=$(git rev-parse @) REMOTE=$(git rev-parse @{u}) if [ $LOCAL != $REMOTE ]; then curl -d "Updating: $REPO_URL" $NTFY_URL echo "Updating: $REPO_URL" git pull origin main rsync -av --delete --exclude '.git/' ./ "$DESTINATION" else echo "Repository $REPO_URL Up-to-Date" fi } # Main loop while true; do # Iterate over each environment variable matching 'REPO_[0-9]+' env | grep '^REPO_[0-9]\+=' | while IFS='=' read -r name value; do # Split the value by comma and read into separate variables OLD_IFS="$IFS" # Save the original IFS IFS=',' # Set IFS to comma for splitting set -- $value # Set positional parameters ($1, $2, ...) REPO_URL="$1" # Assign first parameter to REPO_URL DESTINATION="$2" # Assign second parameter to DESTINATION IFS="$OLD_IFS" # Restore original IFS process_repo "$REPO_URL" "$DESTINATION" done # Wait for 5 seconds before the next iteration sleep 5 done