From 2bc8d29eb4dc0fb1e5cfc0cdbf59ef131467d8f5 Mon Sep 17 00:00:00 2001 From: Julian Kaffke Date: Mon, 4 Dec 2017 12:44:51 +0100 Subject: [PATCH] git_pull: Prevent plugin from always restarting hass.io even if nothing has changed (#205) * Prevent git module from always restarting hass.io `git diff-tree -r --name-only --no-commit-id 'HEAD@{1}' HEAD)` always shows a difference. Getting the commit id prior to pulling is easy and comparing it to the one after pulling makes sure, that checking and restart is only done if ids have changed. * Forgot to get the OLD_COMMIT id * Better sorting and further comments * Pleasing the linter * Update config.json --- git_pull/config.json | 2 +- git_pull/run.sh | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/git_pull/config.json b/git_pull/config.json index 00967fd..9393716 100644 --- a/git_pull/config.json +++ b/git_pull/config.json @@ -1,6 +1,6 @@ { "name": "Git pull", - "version": "2.1", + "version": "2.2", "slug": "git_pull", "description": "Simple git pull to update the local configuration", "url": "https://home-assistant.io/addons/git_pull/", diff --git a/git_pull/run.sh b/git_pull/run.sh index 14d859e..9fdda19 100644 --- a/git_pull/run.sh +++ b/git_pull/run.sh @@ -34,19 +34,25 @@ if [ ! -d /config/.git ]; then fi fi -# Run duckdns +# Main programm cd /config while true; do + # get actual commit id + OLD_COMMIT=$(git rev-parse HEAD) + + # perform pull echo "[Info] pull from $REPOSITORY" git pull 2&> /dev/null || true + + # get actual (new) commit id + NEW_COMMIT=$(git rev-parse HEAD) - # Enable autorestart of homeassistant + # autorestart of homeassistant if enabled if [ "$AUTO_RESTART" == "true" ]; then - changed_files="$(git diff-tree -r --name-only --no-commit-id 'HEAD@{1}' HEAD)" - # Files have changed & check config - if [ ! -z "$changed_files" ]; then + # Compare commit ids & check config + if [ "$NEW_COMMIT" != "$OLD_COMMIT" ]; then echo "[Info] check Home-Assistant config" if api_ret="$(curl -s -X POST http://hassio/homeassistant/check)"; then result="$(echo "$api_ret" | jq --raw-output ".result")" @@ -59,6 +65,8 @@ while true; do echo "[Error] invalid config!" fi fi + else + echo "[Info] Nothing has changed." fi fi