From a84f63cc76a2fd87e39f59627746822a6245fe41 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 24 Jan 2019 17:30:19 +0100 Subject: [PATCH] git_pull 7.1 (#514) * continue script when internet connection lost once (#511) * continue script when internet connection lost once changed some "exit 1" to "return 1" in function git-synchronize. By this, the script should not terminate when there's no internet connection during a repeat check. I left "exit 1" for the initial, critical and config topics => script should terminate here I think. * improved style of "if" statement * 7.1 Fix repeat option (#511) * 7.1 Fix repeat option (#511) * git_pull: Enhance restart_ignore to support whole directories (#513) * git_pull: Enhance restart_ignore to support whole directories * Missing double-quote --- git_pull/CHANGELOG.md | 4 ++++ git_pull/config.json | 2 +- git_pull/run.sh | 31 +++++++++++++++++++++---------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/git_pull/CHANGELOG.md b/git_pull/CHANGELOG.md index 356f52e..38dccc0 100644 --- a/git_pull/CHANGELOG.md +++ b/git_pull/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 7.1 +- Enhance restart_ignore to support whole directories +- Fix repeat option: don't terminate if internet connection unavailable during a check + ## 7.0 - Update Hass.io CLI to 2.0.1 diff --git a/git_pull/config.json b/git_pull/config.json index 0247cf7..63f509f 100644 --- a/git_pull/config.json +++ b/git_pull/config.json @@ -1,6 +1,6 @@ { "name": "Git pull", - "version": "7.0", + "version": "7.1", "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 7f8dbda..1068478 100755 --- a/git_pull/run.sh +++ b/git_pull/run.sh @@ -126,13 +126,13 @@ function git-synchronize { # Always do a fetch to update repos echo "[Info] Start git fetch..." - git fetch "$GIT_REMOTE" || { echo "[Error] Git fetch failed"; exit 1; } + git fetch "$GIT_REMOTE" || { echo "[Error] Git fetch failed"; return 1; } # Prune if configured if [ "$GIT_PRUNE" == "true" ] then echo "[Info] Start git prune..." - git prune || { echo "[Error] Git prune failed"; exit 1; } + git prune || { echo "[Error] Git prune failed"; return 1; } fi # Do we switch branches? @@ -149,11 +149,11 @@ function git-synchronize { case "$GIT_COMMAND" in pull) echo "[Info] Start git pull..." - git pull || { echo "[Error] Git pull failed"; exit 1; } + git pull || { echo "[Error] Git pull failed"; return 1; } ;; reset) echo "[Info] Start git reset..." - git reset --hard "$GIT_REMOTE"/"$GIT_CURRENT_BRANCH" || { echo "[Error] Git reset failed"; exit 1; } + git reset --hard "$GIT_REMOTE"/"$GIT_CURRENT_BRANCH" || { echo "[Error] Git reset failed"; return 1; } ;; *) echo "[Error] Git command is not set correctly. Should be either 'reset' or 'pull'" @@ -182,11 +182,21 @@ function validate-config { CHANGED_FILES=$(git diff "$OLD_COMMIT" "$NEW_COMMIT" --name-only) echo "Changed Files: $CHANGED_FILES" if [ -n "$RESTART_IGNORED_FILES" ]; then - for file in $CHANGED_FILES; do - echo "$RESTART_IGNORED_FILES" | grep -qw "${file}" - if [ $? -eq 1 ] ; then + for changed_file in $CHANGED_FILES; do + restart_required_file="" + for restart_ignored_file in $RESTART_IGNORED_FILES; do + if [ -z "${restart_ignored_file#*/}" ]; then + # file to be ignored is a whole dir + restart_required_file=$(echo "${changed_file}" | grep "^${restart_ignored_file}") + else + restart_required_file=$(echo "${changed_file}" | grep "^${restart_ignored_file}$") + fi + # break on first match + if [ -n "$restart_required_file" ]; then break ; fi + done + if [ -z "$restart_required_file" ]; then DO_RESTART="true" - echo "[Info] Detected Restart Required File $file" + echo "[Info] Detected restart-required file: $changed_file" fi done else @@ -217,8 +227,9 @@ cd /config || { echo "[Error] Failed to cd into /config"; exit 1; } while true; do check-ssh-key setup-user-password - git-synchronize - validate-config + if git-synchronize ; then + validate-config + fi # do we repeat? if [ ! "$REPEAT_ACTIVE" == "true" ]; then exit 0