From 79df38ca293d29d00fb80857ed742380bbf6fe2a Mon Sep 17 00:00:00 2001 From: mateo Date: Wed, 20 Mar 2024 12:18:44 +0100 Subject: [PATCH] new script --- scripts/update_script.sh | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/scripts/update_script.sh b/scripts/update_script.sh index 7707809d..9ca9b0de 100644 --- a/scripts/update_script.sh +++ b/scripts/update_script.sh @@ -1,19 +1,33 @@ #!/bin/bash # This script performs: -# pull origin main +# fetch origin main #- if any change: -# kill container -# rebuild docker compose +# pull changes +# any others change needed # -# This script must be run with a crontab, run every day at 3am -# 0 3 * * * bash /home/pi/pyro-engine/scripts/update_script.sh +# This script must be run with a crontab, run every hour +# 0 * * * * bash /home/pi/pyro-engine/scripts/update_and_execute.sh >> /home/pi/pyro-engine/logfile.log 2>&1 -if [ `git -C /home/pi/pyro-engine pull origin main | grep -c "up to date."` -ne 1 ]; - then - echo "pyro-engine up to date"; - else - echo "pyro-engine updated from github"; - make -C /home/pi/pyro-engine stop - make -C /home/pi/pyro-engine run -fi; +# 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 +HEADHASH=$(git rev-parse HEAD) +UPSTREAMHASH=$(git rev-parse origin/main) + +if [ "$HEADHASH" != "$UPSTREAMHASH" ] +then + echo "$(date): New changes detected ! Updating and executing script..." + git pull origin main + # Add any action here + echo "$(date): Update done !" + +else + echo "$(date): No changes detected" +fi +