#! /bin/bash

if [ ! -d "/repo/.git" ]; then
    echo "Cloning repository..."
    git clone --branch "$BRANCH" "$REPO_URL" "/repo"
fi

while true; do
    echo "Running repo update..."

    cd "/repo" || exit
    git fetch origin
    LOCAL=$(git rev-parse HEAD)
    REMOTE=$(git rev-parse origin/binaries)

    if [ "$LOCAL" != "$REMOTE" ]; then
        echo "Updating repo..."
        git reset --hard origin/binaries
        echo "Update complete."
    else
        echo "Nothing to do."
    fi

    sleep 600 # check every 10 min
done
