Skip to content

Instantly share code, notes, and snippets.

@idiotandrobot
Created December 22, 2016 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idiotandrobot/8897bac8f1cfd97677c22554eb46f22f to your computer and use it in GitHub Desktop.
Save idiotandrobot/8897bac8f1cfd97677c22554eb46f22f to your computer and use it in GitHub Desktop.
Automate heathergraph update from github
0 0,8,12,16 * * * /home/pi/heathergraph_update.sh > /home/pi/heathergraph_update.log 2>&1
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment