Git_pull check config before restart (#174)

* Update run.sh

* Update config.json

* report invalid config
This commit is contained in:
Pascal Vizeli
2017-08-25 15:46:51 +02:00
committed by GitHub
parent 579d2168df
commit 04ad144450
2 changed files with 15 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "Git pull", "name": "Git pull",
"version": "1.0", "version": "1.1",
"slug": "git_pull", "slug": "git_pull",
"description": "Simple git pull to update the local configuration", "description": "Simple git pull to update the local configuration",
"url": "https://home-assistant.io/addons/git_pull/", "url": "https://home-assistant.io/addons/git_pull/",

View File

@@ -26,12 +26,24 @@ while true; do
echo "[Info] pull from $REPOSITORY" echo "[Info] pull from $REPOSITORY"
git pull 2&> /dev/null || true git pull 2&> /dev/null || true
# Enable autorestart of homeassistant
if [ "$AUTO_RESTART" == "true" ]; then if [ "$AUTO_RESTART" == "true" ]; then
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)" changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
# Files have changed & check config
if [ ! -z "$changed_files" ]; then if [ ! -z "$changed_files" ]; then
echo "[Info] files changed, restart Home-Assistant" echo "[Info] check Home-Assistant config"
curl -s http://hassio/homeassistant/restart 2&> /dev/null || true if api_ret="$(curl -s -X POST http://hassio/homeassistant/check)"; then
result="$(echo "$api_ret" | jq --raw-output ".result")"
# Config is valid
if [ "$result" != "error" ]; then
echo "[Info] restart Home-Assistant"
curl -s -X POST http://hassio/homeassistant/restart 2&> /dev/null || true
else
echo "[Error] invalid config!"
fi
fi
fi fi
fi fi