46 lines
1.0 KiB
Bash
46 lines
1.0 KiB
Bash
#!/bin/bash
|
|
|
|
# Fetch environment variables
|
|
repo_url=$REPO_URL
|
|
copy_dir=$COPY_DIR
|
|
ntfy_url=$NTFY_URL
|
|
git_username=$GIT_USERNAME
|
|
git_password=$GIT_PASSWORD
|
|
|
|
# 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
|
|
|
|
# Navigate to the watcher directory
|
|
cd /root/Repo_Watcher
|
|
|
|
# Clone the repo if it doesn't exist
|
|
if [ ! -d "repo" ]; then
|
|
git clone $repo_url repo
|
|
fi
|
|
|
|
cd repo
|
|
|
|
# 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})
|
|
BASE=$(git merge-base @ @{u})
|
|
|
|
if [ $LOCAL = $REMOTE ]; then
|
|
echo "Up-to-date"
|
|
elif [ $LOCAL = $BASE ]; then
|
|
echo "Need to pull"
|
|
git pull origin main
|
|
rsync -av --delete ./ $copy_dir
|
|
curl -d "Data updated from Git repo" $ntfy_url
|
|
elif [ $REMOTE = $BASE ]; then
|
|
echo "Need to push"
|
|
else
|
|
echo "Data diverged"
|
|
fi
|