#!/bin/bash
# Change directory to /config
cd /config
# Git add all the files
git add .
# Commit a message to the change - also add date and time.
git commit -m "Config files on `date +'%d-%m-%Y %H:%M:%S'`"
# Push the changes to Gitea
git push origin master
automation:
alias: Backup Config
description: Pushes any changes made to Home Assistant to Gitea every hour
trigger:
- platform: time_pattern
hours: '1'
condition: []
action:
- service: script.backup_ha_to_gitea
mode: single
I say that it is mostly working because it is calling the script and firing the steps, but it is doing everything but actually pushing the changes to my Gitea instance. I can confirm this by using âgit statusâ using an SSH session. I am also able to call the sh file in the same SSH session and it runs the script all the way through including the push so I know it is not a communication system between the 2 programs.
Does anyone know of anything that I can try to get this automated?
HA runs inside a container in HA OS as well.
The only officially supported installation method which doesnât is âCoreâ, i.e. a python venv.
Works fine only as long as you have your private key in â~/.ssh/idâŠâ, which, in the container is â/root/.ssh/âŠâ.
Unless you did something about it, it definitely wonât work out-of-the-box.
I have it set up via the git config file to use the key pair that is located in /config/.ssh. If I understand this, it should be using that key pair from that config no matter what user is calling the script.
It could also be related to the owner/permissions of the private key.
Openssh refuses to use the key if it doesnât belong to the user and if there are read permissions for group or other. So ensure that the permissions are set to 600.
Overall, I give up on this. I have tried everything I have seen in threads, I have tried different paths including adding /root/, permissions seems to be fine⊠I just donât understand why it will do everything but push to Gitea. I can run the script manually and it is fine. I just canât automate it.
Thatâs the part from the tutorial where you specify what private key is used to access gitea.
But generally, your confusion comes from the fact that you donât grasp that when you do it âmanuallyâ, you are running it from a separate docker container, the âSSH & Web terminalâ addon.
When you execute it as a shell command, it runs in a completely different context : The Home Assistant container.
What you want to do is insert the âgit configâ command in of your bash script, before the âpushâ, as you cannot do it easily directly in HA (and you would have to redo it each time you upgrade, anyway).
I added this to the bash script and it still is not pushing. The bash script is now:
#!/bin/bash
# Change directory to /config
cd /config
# Git add all the files
git add .
# Commit a message to the change - also add date and time.
git commit -m "Config files on `date +'%d-%m-%Y %H:%M:%S'`"
git config core.sshCommand "ssh -i root/config/.ssh/privateGitea -F /dev/null"
# Push the changes to Gitea
git push origin master
Do you use a SSH key with passphrase? When using that it didnât work for me either.
Now I have made a new SSH key without a passphrase and it works using the following bash script.
#!/bin/bash
# Change directory to /config
cd /config
# Git add all the files
git add .
# Commit a message to the change with date and time
git commit -am "Changes on $(date +'%d-%m-%Y %H:%M:%S')"
# Source https://blog.ceard.tech/2020/05/home-assistant-docker-and-using-ssh.html
git config core.sshCommand 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=accept-new -i /ssl/.gitea/gitea_key_no_pp -F /dev/null'
# Push the changes to Gitea
git push origin master
#!/bin/bash
# Change directory to /config
cd /config
# Git add all the files
git add .
# Commit a message to the change with date and time
git commit -am "Config files on `date +'%d-%m-%Y %H:%M:%S'`"
# Source https://blog.ceard.tech/2020/05/home-assistant-docker-and-using-ssh.html
git config core.sshCommand 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=accept-new -i /config/.ssh/privateGitea -F /dev/null'
# Push the changes to Gitea
git push origin master
Automation:
alias: Push HA Config to Gitea
description: Pushs any changes made to Home Assistant to Gitea
trigger:
- platform: time_pattern
hours: '1'
condition: []
action:
- service: shell_command.backup_ha_to_gitea
mode: single
I pretty much just gave up on this and do manual backups.
In your case LilTrublMakr you need to change the - service: shell_command.backup_ha_to_gitea
for - service: shell_command.backup_ha
which is the name you are using in your config yml