From 1017a471b2c883a8fd599d241c9f18c06ddf5ee7 Mon Sep 17 00:00:00 2001 From: Nicole Rappe Date: Fri, 22 Sep 2023 01:31:12 -0600 Subject: [PATCH] Adjusted script --- .env | 3 +-- docker-compose.yml | 2 +- repo_watcher.sh | 31 ++++++++++++------------------- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/.env b/.env index 98c90da..3454ef3 100644 --- a/.env +++ b/.env @@ -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 \ No newline at end of file +GIT_PASSWORD=USE-AN-APP-PASSWORD \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 70cc96a..085ccdf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 \ No newline at end of file diff --git a/repo_watcher.sh b/repo_watcher.sh index 1207136..51a1a70 100644 --- a/repo_watcher.sh +++ b/repo_watcher.sh @@ -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