diff --git a/scripts/update_script.sh b/scripts/update_script.sh index 37890836..61de8104 100644 --- a/scripts/update_script.sh +++ b/scripts/update_script.sh @@ -1,13 +1,5 @@ #!/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" @@ -15,19 +7,20 @@ 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 -