mirror of
https://github.com/aljazceru/addons.git
synced 2025-12-17 13:14:21 +01:00
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
This commit is contained in:
committed by
Pascal Vizeli
parent
61a6e7cefe
commit
2bc8d29eb4
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Git pull",
|
"name": "Git pull",
|
||||||
"version": "2.1",
|
"version": "2.2",
|
||||||
"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/",
|
||||||
|
|||||||
@@ -34,19 +34,25 @@ if [ ! -d /config/.git ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run duckdns
|
# Main programm
|
||||||
cd /config
|
cd /config
|
||||||
while true; do
|
while true; do
|
||||||
|
|
||||||
|
# get actual commit id
|
||||||
|
OLD_COMMIT=$(git rev-parse HEAD)
|
||||||
|
|
||||||
|
# perform pull
|
||||||
echo "[Info] pull from $REPOSITORY"
|
echo "[Info] pull from $REPOSITORY"
|
||||||
git pull 2&> /dev/null || true
|
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
|
if [ "$AUTO_RESTART" == "true" ]; then
|
||||||
changed_files="$(git diff-tree -r --name-only --no-commit-id 'HEAD@{1}' HEAD)"
|
|
||||||
|
|
||||||
# Files have changed & check config
|
# Compare commit ids & check config
|
||||||
if [ ! -z "$changed_files" ]; then
|
if [ "$NEW_COMMIT" != "$OLD_COMMIT" ]; then
|
||||||
echo "[Info] check Home-Assistant config"
|
echo "[Info] check Home-Assistant config"
|
||||||
if api_ret="$(curl -s -X POST http://hassio/homeassistant/check)"; then
|
if api_ret="$(curl -s -X POST http://hassio/homeassistant/check)"; then
|
||||||
result="$(echo "$api_ret" | jq --raw-output ".result")"
|
result="$(echo "$api_ret" | jq --raw-output ".result")"
|
||||||
@@ -59,6 +65,8 @@ while true; do
|
|||||||
echo "[Error] invalid config!"
|
echo "[Error] invalid config!"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
echo "[Info] Nothing has changed."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user