git_pull: sanitize git_pull add-on to avoid deleting /config, fix some nits #3596
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
"The risk of complete loss is possible." is a real thing with git_pull! I wiped out my
/config
folder and found that I am not alone. I did a backup just before putting my hands ongit_pull
, so it was innocuous for my HA install.I added some error handling using
set e
so the script would stop running if an error occurred (like a misconfiguration or a connectivity problem). I also found using~
a bit misleading when trying to set$HOME
; for example,git
couldn't find the ssh key when using~
as$HOME
.Also, I decided to pass the SSH deployment key base64 encoded; otherwise, parsing the single-line SSH key would be a lot of struggle.
Last, the repo is cloned to a fresh folder called
/new_config
before destroying the working/config
one.