install hbc_mini via package or script

This commit is contained in:
Andreas Wrede
2026-05-01 11:13:33 -04:00
parent c4f09e9ced
commit 85ee0e1040
3 changed files with 46 additions and 16 deletions
+42 -15
View File
@@ -12,11 +12,14 @@
set -e
what=$1
on_ha=0
where=""
venv=""
[ "$2" = "HA" ] && on_ha=1
[ -z "$what" ] && what="client"
if [ -d /homeassistant ]; then
echo "cannot install in HA, running \"docker exec homeassistant $0 $@\""
docker exec homeassistant $0 $@
echo "HA, running \"docker exec homeassistant $0 $@\""
docker exec homeassistant $0 $@ HA
rc=$?
if [ $rc -ne 0 ]; then
echo "Failed to install heartbeat in HA, please check the logs for more details"
@@ -24,11 +27,11 @@ if [ -d /homeassistant ]; then
fi
exit 0
fi
if [ -d /config ]; then
echo "Installing on HA"
if [ $on_ha -eq 1 ]; then
echo "Installing under docker on Home Assistant OS, using /config/bin for executables and /config/venvs for virtual environments "
where="/config/bin"
venv="/config/venvs"
on_ha=1
else
if [ ! -d $HOME/.local/bin ] && [ ! -d $HOME/bin ]; then
echo "No suitable bin directory found in PATH, please add either $HOME/.local/bin or $HOME/bin to your PATH"
@@ -43,18 +46,23 @@ else
echo "No suitable bin directory found in PATH, please add either $HOME/.local/bin or $HOME/bin to your PATH"
exit 1
fi
venv="$HOME/venvs"
if [ "$what" = "mini" ]; then
venv=""
else
venv="$HOME/venvs"
fi
fi
echo "Installing heartbeat $what"
if [ ! -d $venv/hbd ]; then
if [ "$venv" != "" ] && [ ! -d $venv/hbd ]; then
set +e
python3 -m pip --version > /dev/null 2>&1
rc=$?
set -e
arg=""
if [ $rc -ne 0 ]; then
# truenas does not have pip installed by default, so we need to fetch get-pip.py and install pip
# some systems do not have pip installed by default, so we need to fetch get-pip.py and install pip
echo "pip is not installed, fetching get-pip.py and installing pip"
arg="--without-pip"
fi
@@ -74,19 +82,32 @@ if [ ! -d $venv/hbd ]; then
deactivate
fi
. $venv/hbd/bin/activate
if [ -z "$venv" ]; then
echo "Installing heartbeat $what globally"
else
echo "Installing heartbeat $what in virtual environment $venv/hbd"
. $venv/hbd/bin/activate
fi
python3 -mpip install --upgrade --index-url https://git.wrede.ca/api/packages/andreas/pypi/simple/ --extra-index-url https://pypi.org/simple hbd[$what]
if [ "$what" = "server" ]; then
rm -f $where/hbd
ln -sf $(which hbd) $where/hbd
echo "hbd installed, you can run it with \"$where/hbd\" or \"hbd\" if $where is in your PATH"
else
rm -f $where/hbc
ln -sf $(which hbc) $where/hbc
# rm -f $where/hb_install.sh
cp "$0" $where/hb_install.sh
chmod +x $where/hb_install.sh
elif [ "$what" = "client" ]; then
hbc_path=$(which hbc)
if [ -z "$hbc_path" ]; then
echo "hbc not found in PATH, installation failed"
exit 1
fi
if [ "$hbc_path" != "$where/hbc" ]; then
rm -f $where/hbc
ln -sf $(which hbc) $where/hbc
fi
if [ "$0" != "$where/hb_install.sh" ]; then
cp "$0" $where/hb_install.sh
chmod +x $where/hb_install.sh
fi
if [ $on_ha -eq 1 ]; then
echo "restarting hbc "
job=$(grep run_hbc configuration.yaml | sed 's/run_hbc://')
@@ -94,4 +115,10 @@ else
else
echo "hbc installed, you can run it with \"$where/hbc\" or \"hbc\" if $where is in your PATH"
fi
elif [ "$what" = "mini" ]; then
hbc_path=$(which hbc_mini)
if [ "$hbc_path" != "$where/hbc_mini" ]; then
ln -sf $(which hbc) $where/hbc_mini
fi
echo "hbc mini installed, you can run it with \"$where/hbc_mini\" or \"hbc_mini\" if $where is in your PATH"
fi