59 lines
1.9 KiB
Bash
Executable File
59 lines
1.9 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# install the heartbeat client, hbc. The server is installed when the arg 'server' is passed
|
|
# install the heartbeat client, hbc. The server is installed when the arg 'server' is passed
|
|
# to the script. The script will install the heartbeat tools in a python
|
|
# virtual environment in ~/venvs/hbd. The hbd and hbc commands will be
|
|
# installed from the wheel and symlinked to ~/bin/hbd and ~/bin/hbc,
|
|
# respectively. If the virtual environment already exists, it will be
|
|
# reused. The script will also remove any existing symlinks for hbd and hbc
|
|
# in ~/bin before creating new ones.
|
|
|
|
|
|
# hbd/hbc from wheel and create symlinks for hbd and hbc in ~/bin
|
|
|
|
set -e
|
|
what=$1
|
|
|
|
if [ -d /homeassistant ]; then
|
|
echo "cannot install in HA, run \"docker exec -it homeassistant $0 $@\""
|
|
exit 1
|
|
fi
|
|
if [ -d /config ]; then
|
|
echo "Installing on HA"
|
|
where="/config/bin"
|
|
venv="/config/venvs"
|
|
else
|
|
if [ ! -d ~/.local/bin ] && [ ! -d ~/bin ]; then
|
|
echo "No suitable bin directory found in PATH, please add either ~/.local/bin or ~/bin to your PATH"
|
|
exit 1
|
|
fi
|
|
for where in ~/bin ~/.local/bin; do
|
|
if echo ":$PATH:" | grep -q ":$where:" ; then
|
|
break
|
|
fi
|
|
done
|
|
venv="~/venvs"
|
|
fi
|
|
python3 -m pip --version > /dev/null 2>&1 || { echo "pip is not installed, please install pip for python3"; exit 1; }
|
|
|
|
if [ "$what" = "server" ]; then
|
|
echo "Installing heartbeat server (hbd)"
|
|
else
|
|
what="client"
|
|
echo "Installing heartbeat client (hbc)"
|
|
fi
|
|
if [ ! -d $venv/hbd ]; then
|
|
mkdir -p $venv
|
|
python3 -m venv $venv/hbd --system-site-packages
|
|
fi
|
|
. $venv/hbd/bin/activate
|
|
pip install --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
|
|
else
|
|
rm -f $where/hbc
|
|
ln -sf $(which hbc) $where/hbc
|
|
fi
|