diff --git a/pyproject.toml b/pyproject.toml index 948a8e1..941a838 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,6 +34,9 @@ server = [ "matrix-nio>=0.24", ] +# Minimal client — hbc_mini only, no external dependencies +mini = [] + # Install both client and server all = [ "hbd[client,server]", diff --git a/scripts/hb_install.sh b/scripts/hb_install.sh index a567556..3e9ced9 100755 --- a/scripts/hb_install.sh +++ b/scripts/hb_install.sh @@ -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 diff --git a/scripts/hbc_mini.py b/scripts/hbc_mini.py index 1fdb94d..022eea1 100755 --- a/scripts/hbc_mini.py +++ b/scripts/hbc_mini.py @@ -875,7 +875,7 @@ async def _handle_update(conn: AsyncConnection): log.info("running installer: %s", installer) try: proc = await asyncio.create_subprocess_exec( - installer, "client", + installer, "miniclient", stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.STDOUT, )