Skip to content

Commit

Permalink
main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
MateoLostanlen committed Apr 12, 2024
1 parent 57e8b85 commit 2fb681b
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions scripts/update_script.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
#!/bin/bash
# This script performs:
# fetch origin main
#- if any change:
# pull changes
# any others change needed
#
# This script must be run with a crontab, run every hour
# 0 * * * * bash /home/pi/pyro-engine/scripts/update_script.sh >> /home/pi/pyro-engine/logfile.log 2>&1

# This script fetches changes from the main branch and updates if there are any.

# Print current date and time
echo "$(date): Checking for updates"

# Navigate to the repository directory
cd /home/pi/pyro-engine

# Check for updates and pull
git fetch origin
# Fetch main branch specifically and update local tracking
git fetch origin main:refs/remotes/origin/main

# Get the lamain commit hash of the current HEAD and the remote main branch
HEADHASH=$(git rev-parse HEAD)
UPSTREAMHASH=$(git rev-parse origin/main)
UPSTREAMHASH=$(git rev-parse refs/remotes/origin/main)

# Compare hashes and update if they are different
if [ "$HEADHASH" != "$UPSTREAMHASH" ]
then
echo "$(date): New changes detected ! Updating and executing script..."
echo "$(date): New changes detected! Updating and executing script..."
git pull origin main
# Add any action here
echo "$(date): Update done !"

# Add any additional actions here
echo "$(date): Update done!"
else
echo "$(date): No changes detected"
fi

0 comments on commit 2fb681b

Please sign in to comment.