Small bash code to automate a git pull and restart the docker

This might, or might not be of use to anyone else, however, I wrote a very basic bash script to git pull from my
repo and then restart the home-assistant docker.

Hopefully, it may help someone :slight_smile:

#!/bin/sh

git fetch

UPSTREAM=${1:-'@{u}'}
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse "$UPSTREAM")
BASE=$(git merge-base @ "$UPSTREAM")

if [ $LOCAL = $REMOTE ]; then
   echo "Up-to-date"
elif [ $LOCAL = $BASE ]; then
   git pull && docker restart home-assistant
elif [ $REMOTE = $BASE ]; then
   echo "Need to push"
else
   echo "Diverged"
fi

Run this as a cron job are you’ve got a self-updating home assistant entity. Perfect for those lunchtime code amends.

Jack

1 Like

Thanks that looks really interesting. :+1:
Would you mind however tagging it as “share your projects”?

wasn’t quite sure where it lived - now edited

1 Like