cleanup install script

This commit is contained in:
Andreas Wrede
2026-05-02 07:55:18 -04:00
parent 6fb67f8615
commit 5819dd6b25
+23 -39
View File
@@ -30,7 +30,8 @@ if [ -d /homeassistant ]; then
fi fi
if [ $on_ha -eq 1 ]; then 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 " # Installing under docker on Home Assistant OS, using /config/bin for executables and /config/venvs for virtual environments
echo "Home Assistant OS detected, installing under docker"
where="/config/bin" where="/config/bin"
venv="/config/venvs" venv="/config/venvs"
else else
@@ -53,23 +54,26 @@ else
venv="$HOME/venvs" venv="$HOME/venvs"
fi fi
fi fi
echo "Installing $what to $where"
echo "Installing heartbeat $what" if [ ! -z "$venv" ]; then
echo "Using virtual environment at $venv/hbd"
fi
if [ "$venv" != "" ] && [ ! -d $venv/hbd ]; then if [ "$venv" != "" ] && [ ! -d $venv/hbd ]; then
set +e
python3 -m pip --version > /dev/null 2>&1
rc=$?
set -e
arg="" arg=""
if [ $rc -ne 0 ]; then have_pip=$(python3 -c "import pip" 2>/dev/null &> /dev/null && echo "Installed" || echo "Not Installed")
if [ "$have_pip" = "Not Installed" ]; then
# some systems do 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" echo "pip is not installed, fetching get-pip.py and installing pip"
arg="--without-pip" arg="--without-pip"
fi fi
mkdir -p $venv mkdir -p $venv
have_venv=$(python3 -c "import venv" &> /dev/null && echo "Installed" || echo "Not Installed") have_venv=$(python3 -c "import venv" 2>/dev/null &> /dev/null && echo "Installed" || echo "Not Installed")
if [ "$have_venv" = "Not Installed" ]; then if [ "$have_venv" = "Not Installed" ]; then
if [ "$have_pip" = "Not Installed" ]; then
echo "python has no venv, and no pip to install virtualenv, cannot continue"
exit 1
fi
echo "python venv module not found, installing virtualenv" echo "python venv module not found, installing virtualenv"
python3 -m pip install --user virtualenv python3 -m pip install --user virtualenv
python3 -m virtualenv $venv/hbd --system-site-packages $arg python3 -m virtualenv $venv/hbd --system-site-packages $arg
@@ -83,50 +87,30 @@ if [ "$venv" != "" ] && [ ! -d $venv/hbd ]; then
deactivate deactivate
fi fi
if [ -z "$venv" ]; then if [ ! -z "$venv" ]; then
echo "Installing heartbeat $what globally"
else
echo "Installing heartbeat $what in virtual environment $venv/hbd"
. $venv/hbd/bin/activate . $venv/hbd/bin/activate
fi fi
if [ "$what" = "mini" ]; then if [ "$what" = "mini" ]; then
echo "Installing hbc mini, which has no external dependencies and is meant for quick setup and testing. For the full client with all features, please run this script with the 'client' argument."
curl -s -o $where/hbc_mini https://git.wrede.ca/andreas/heartbeat/raw/branch/master/scripts/hbc_mini.py curl -s -o $where/hbc_mini https://git.wrede.ca/andreas/heartbeat/raw/branch/master/scripts/hbc_mini.py
chmod +x $where/hbc_mini chmod +x $where/hbc_mini
else else
echo "Installing heartbeat $what, which includes the full client with all features. If you want to install the minimal client with no external dependencies, please run this script with the 'mini' argument."
python3 -mpip install --upgrade --index-url https://git.wrede.ca/api/packages/andreas/pypi/simple/ --extra-index-url https://pypi.org/simple hbd[$what] python3 -mpip install --upgrade --index-url https://git.wrede.ca/api/packages/andreas/pypi/simple/ --extra-index-url https://pypi.org/simple hbd[$what]
fi fi
if [ ! -z "$venv" ]; then
echo "linking executables to $where"
if [ "$what" = "server" ]; then if [ "$what" = "server" ]; then
rm -f $where/hbd rm -f $where/hbd
ln -sf $(which hbd) $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"
elif [ "$what" = "client" ]; then 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 rm -f $where/hbc
ln -sf $(which hbc) $where/hbc ln -sf $(which hbc) $where/hbc
fi fi
if [ "$prog" != "$where/hb_install.sh" ]; then rm -f $where/hb_install.sh
cp "$prog" $where/hb_install.sh ln -sf $(which hb_install.sh) $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://')
$job
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 $hbc_path $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 fi
echo "Installation complete. To upgrade, run the following:"
echo " $where/hb_install.sh $what"
echo "To install on another machine, run the following command on that machine:"
echo " curl -s -o $where/hb_install.sh https://git.wrede.ca/andreas/heartbeat/raw/branch/master/scripts/hb_install.sh"
echo " and then run $where/hb_install.sh [mini|client]"