Adjusted script

This commit is contained in:
Nicole Rappe 2023-09-22 01:31:12 -06:00
parent 9038a7c9b2
commit 1017a471b2
3 changed files with 14 additions and 22 deletions

3
.env
View File

@ -1,5 +1,4 @@
REPO_URL=https://git.cyberstrawberry.net/container-registry/git-repo-updater
COPY_DIR=/server
NTFY_URL=https://ntfy.cyberstrawberry.net/git-repo-updater
GIT_USERNAME=nicole.rappe
GIT_PASSWORD=REDACTED
GIT_PASSWORD=USE-AN-APP-PASSWORD

View File

@ -11,5 +11,5 @@ services:
- TZ=America/Denver
image: git.cyberstrawberry.net/container-registry/git-repo-updater:latest
volumes:
- /srv/containers/git-repo-updater:/server
- /srv/containers/git-repo-updater:/DATA
restart: always

View File

@ -1,26 +1,21 @@
#!/bin/bash
while true; do
# Fetch environment variables
repo_url=$REPO_URL
copy_dir=$COPY_DIR
ntfy_url=$NTFY_URL
git_username=$GIT_USERNAME
git_password=$GIT_PASSWORD
# Make DATA directory at root directory
mkdir -p /DATA
# 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
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
git clone $REPO_URL repo
fi
cd repo
@ -34,16 +29,14 @@ while true; do
BASE=$(git merge-base @ @{u})
if [ $LOCAL = $REMOTE ]; then
echo "Up-to-date"
echo "Repository Up-to-date"
elif [ $LOCAL = $BASE ]; then
echo "Need to pull"
echo "Pulling Updates from Repository..."
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"
rsync -av --delete ./ /DATA
curl -d "$REPO_URL Automatically Pulled Update" $NTFY_URL
else
echo "Data diverged"
echo "Data Diverged - How exactly did this happen?"
fi
# Wait for 5 seconds before the next iteration