Automate Heathergraph Update from GitHub

history edit

Git, Git Bash, Heathergraph

For heathergraph, based on How to check if a Git pull is needed. Makes a bit of a mess of logging to console but does the job.

0 0,8,12,16 * * * /home/pi/heathergraph_update.sh > /home/pi/heathergraph_update.log 2>&1
view raw crontab hosted with ❤ by GitHub
#!/bin/bash
GIT='git -C /home/pi/heathergraph/'
$GIT fetch
UPSTREAM=${1:-'@{u}'}
LOCAL=$($GIT rev-parse @)
REMOTE=$($GIT rev-parse "$UPSTREAM")
BASE=$($GIT merge-base @ "$UPSTREAM")
if [ $LOCAL = $REMOTE ]; then
echo "Git: Up-to-date"
elif [ $LOCAL = $BASE ]; then
echo "Git: Pulling"
$GIT stash
$GIT merge
$GIT stash pop
sudo python ./heathergraph/server.py restart
elif [ $REMOTE = $BASE ]; then
echo "Git: Need to push"
else
echo "Git: Oh dear"
fi