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
This commit is contained in:
Pascal Vizeli
2019-01-24 17:30:19 +01:00
committed by GitHub
parent 705c0b4d01
commit a84f63cc76
3 changed files with 26 additions and 11 deletions

View File

@@ -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

View File

@@ -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/",

View File

@@ -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
if git-synchronize ; then
validate-config
fi
# do we repeat?
if [ ! "$REPEAT_ACTIVE" == "true" ]; then
exit 0