Initial Commit
This commit is contained in:
commit
263e390a59
18
Dockerfile
Normal file
18
Dockerfile
Normal file
@ -0,0 +1,18 @@
|
||||
FROM ubuntu:latest
|
||||
|
||||
# Install necessary packages
|
||||
RUN apt-get update && \
|
||||
apt-get install -y git curl cron rsync
|
||||
|
||||
# Add script and cronjob
|
||||
COPY repo_watcher.sh /root/Repo_Watcher/repo_watcher.sh
|
||||
COPY crontab.txt /crontab.txt
|
||||
|
||||
# Make script executable
|
||||
RUN chmod +x /root/Repo_Watcher/repo_watcher.sh
|
||||
|
||||
# Apply cron job
|
||||
RUN crontab /crontab.txt
|
||||
|
||||
# Start cron in foreground
|
||||
CMD ["cron", "-f"]
|
4
README.md
Normal file
4
README.md
Normal file
@ -0,0 +1,4 @@
|
||||
**Basic Docker Run Command**:
|
||||
```
|
||||
docker run -e REPO_URL='https://your.git.repo.url' -e COPY_DIR='/your/copy/dir' -e NTFY_URL='https://your.ntfy.url' -e GIT_USERNAME='your_username' -e GIT_PASSWORD='your_password' git_repo_updater
|
||||
```
|
1
crontab.txt
Normal file
1
crontab.txt
Normal file
@ -0,0 +1 @@
|
||||
* * * * * /bin/bash /root/Repo_Watcher/repo_watcher.sh >/dev/null 2>&1
|
0
docker-compose.yml
Normal file
0
docker-compose.yml
Normal file
45
repo_watcher.sh
Normal file
45
repo_watcher.sh
Normal file
@ -0,0 +1,45 @@
|
||||
#!/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
|
Loading…
x
Reference in New Issue
Block a user