Skip to content

Commit

Permalink
Fix update (#186)
Browse files Browse the repository at this point in the history
* fix update

* add debug script

* execute debug script

* missing comment and blanck line
  • Loading branch information
MateoLostanlen authored Apr 15, 2024
1 parent 2c322cb commit ea217e5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
2 changes: 2 additions & 0 deletions scripts/debug_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo "$(date): Debug script executed !"
25 changes: 11 additions & 14 deletions scripts/update_script.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
#!/bin/bash
# This script performs:
# fetch origin main
#- if any change:
# pull changes
# any others change needed
#
# This script fetches changes from the main branch and updates if there are any.
#
# 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


# 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 !"

bash /home/pi/pyro-engine/scripts/debug_script.sh
echo "$(date): Update done!"
else
echo "$(date): No changes detected"
fi
Expand Down
27 changes: 12 additions & 15 deletions scripts/update_script_develop.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
#!/bin/bash
# This script performs:
# fetch origin main
#- if any change:
# pull changes
# any others change needed
#
# This script fetches changes from the develop branch and updates if there are any.
#
# This script must be run with a crontab, run every hour
# 0 * * * * bash /home/pi/pyro-engine/scripts/update_script_develop.sh >> /home/pi/pyro-engine/logfile.log 2>&1

# 0 * * * * bash /home/pi/pyro-engine/scripts/update_script.sh >> /home/pi/pyro-engine/logfile.log 2>&1

# 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 develop
# Fetch develop branch specifically and update local tracking
git fetch origin develop:refs/remotes/origin/develop

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

# 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 develop
# Add any action here
echo "$(date): Update done !"

bash /home/pi/pyro-engine/scripts/debug_script.sh
echo "$(date): Update done!"
else
echo "$(date): No changes detected"
fi
Expand Down

0 comments on commit ea217e5

Please sign in to comment.