Only run HA CLI interactively if stdout is a terminal (#3292)

* Only run HA CLI interactively if stdout is a terminal

Flags for running HA CLI commands in an interactive shell added in #3238
cause the command to fail if the process is not running in a terminal.
This is needed for example for the fsfreeze hook, otherwise the command
fails, as seen in this trace when the hook is executed:

-----------
+ '[' thaw '=' freeze ]
+ '[' thaw '=' thaw ]
+ echo 'File system thaw requested, thawing Home Assistant'
File system thaw requested, thawing Home Assistant
+ ha backups thaw
the input device is not a TTY
------------

However, for example on Proxmox this message is not logged anywhere and
the hook just fails silently (i.e. it doesn't cause the backup to fail).

Fixes #3251

* Use -i also when not running in a terminal

(cherry picked from commit 78d281fce1)
This commit is contained in:
Jan Čermák 2024-04-08 15:43:12 +02:00 committed by Jan Čermák
parent 3e970f1e9a
commit 5dc234d14f
No known key found for this signature in database
GPG Key ID: A78C897AA3AF012B
1 changed files with 6 additions and 1 deletions

View File

@ -3,4 +3,9 @@
# HA utility
# ==============================================================================
docker exec -it hassio_cli ha "$@"
if [ -t 1 ]; then
# stdout (fd 1) must be terminal, otherwise `-t` causes error
docker exec -it hassio_cli ha "$@"
else
docker exec -i hassio_cli ha "$@"
fi