Setup:
-HA OS 8.4
-GitHub account and repository
-Add-on: SSH & Web Terminal
Automation
alias: Push HA configuration to GitHub
trigger:
- at: "23:23:23"
platform: time
action:
- data:
addon: a0d7b954_ssh
input: /config/ha_gitpush.sh
service: hassio.addon_stdin
Shell script (ha_gitpush.sh)
cd /config
git add .
git commit -m "test"
git push origin main
exit
If I run the commands above directly in terminal (add-on: SSH & Web Terminal), everything works fine (files are pushed to GitHub) as expected.
When I execute the automation - it does not work.
I have disabled protection mode. What do I need to do to access the Docker instance running HA? Do I need to change the add-on configuration?
This is my config:
looking the the linked script, the only package you use is git which is already installed in HA. This can be verified by:
docker exec -it homeassistant bash
git --version
You should be able to run the script ânativelyâ using a shell command. Perhaps something like:
shell_command:
git_pushha: ./config/ha_gitpush.sh
automation:
- alias: Push HA configuration to GitHub
trigger:
- at: "23:23:23"
platform: time
action:
- service: shell_command.git_pushha
If youâre wanting an overengineered solution to allow for non-included packages using the SSH & Web Terminal addon, then check out (OP does a great job!):
Youâre right that I donât think SSHâing is necessary here for simple git pulls, pushes and commits. However I would note that depending on how the user sets the permissions in the repo in github they may still have a challenge here. If they want a private repo or a public repo with restrictions on who can publish changes to main then I believe theyâll need git credentials stored in a file somewhere. I remember going through the git CLI login process before and I believe it stores that file in the home directory. If so, that will be a problem as its not persistent (hence why that guide helps people move all their SSH related files elsewhere).
SSHâing to the SSH addon offers one solution to this problem. The author could add a start up script to the addonâs config that copies their credential file from somewhere persistent (like /config) to wherever git expects it to be. Another option would be to see what configuration options git has for location of file(s) like this. Or simply make the repo public and donât add any restrictions on who can push changes to main.