bridge: install.sh, un comando per installare tutto

Clona il repository, crea l'ambiente, chiede le credenziali (password senza eco,
mai nella cronologia), verifica di riuscire a leggere l'impianto, installa e
avvia il servizio, e stampa indirizzo e token da mettere nell'app.

Non serve root e non tocca niente fuori dalla home. I percorsi sono variabili
(AIRA_INSTALL_DIR, AIRA_CONFIG_DIR, AIRA_PORT) con valori predefiniti sensati,
cosi' lo script funziona per chiunque: i valori predefiniti dei programmi esistenti
non sono stati cambiati, per non toccare installazioni in corso.

Provato per davvero: clonazione, ambiente Python con pyairahome/grpc/cryptography,
lettura del token, e il file del servizio passato a systemd-analyze verify. Il ramo
che usa systemctl --user non e' verificabile da qui (nessun bus utente): da provare
su una macchina con sessione systemd.

README: installazione in un comando, con la procedura manuale come ripiego.
setup_creds.py: messaggi in inglese, per il pubblico del forum.
This commit is contained in:
Carlo Baratto committed 2026-10-12 15:04:48 +02:00
1 parent e9527f66bb
commit 02d467f46c
3 files changed
+227 -15

No files matched your search

+36 -5
View File
@@ -17,24 +17,55 @@ Tested against an Aira Home heat pump (Europe). Python 3.9+.
## Install ## Install
One command. It clones this repository into `~/harbour-aira`, creates a private
Python environment, asks for your Aira email and password (typed without echo),
checks that it can read your plant, and installs itself as a service that starts
by itself at boot.
```bash
curl -fsSL https://git.hackatoniclife.com/kaneda/harbour-aira/raw/branch/main/bridge/install.sh | bash
```
It never needs root and it changes nothing outside your home directory. When it
finishes, it prints two things to copy into the app: the address and the token.
On a Raspberry Pi the slow part is installing the Python libraries, a few
minutes; everything else is seconds.
To update later, run the same command again.
### If something goes wrong
Everything is a normal user service, so you can look at it:
```bash
systemctl --user status harbour-aira-bridge
journalctl --user -u harbour-aira-bridge -f
systemctl --user restart harbour-aira-bridge
```
If your machine has no systemd user session, the script says so and prints the
command to start the bridge by hand.
### Doing it manually
If you would rather see every step, the install is short:
```bash ```bash
git clone https://git.hackatoniclife.com/kaneda/harbour-aira.git git clone https://git.hackatoniclife.com/kaneda/harbour-aira.git
cd harbour-aira/bridge cd harbour-aira/bridge
python3 -m venv .venv python3 -m venv .venv
. .venv/bin/activate .venv/bin/python -m pip install -r requirements.txt
pip install -r requirements.txt
# where credentials and bridge configuration will live
export AIRA_CONFIG_DIR="$HOME/.config/aira" export AIRA_CONFIG_DIR="$HOME/.config/aira"
mkdir -p "$AIRA_CONFIG_DIR" mkdir -p "$AIRA_CONFIG_DIR"
# your Aira email + password: typed without echo, saved in a file readable # your Aira email + password: typed without echo, saved in a file readable
# only by your user (600). Nothing is printed, nothing is logged. # only by your user (600). Nothing is printed, nothing is logged.
python setup_creds.py .venv/bin/python setup_creds.py
# sanity check: logs in and prints your plant state (read-only) # sanity check: logs in and prints your plant state (read-only)
python aira_probe.py .venv/bin/python aira_probe.py
``` ```
If `aira_probe.py` prints your temperatures and modes, the hard part is done. If `aira_probe.py` prints your temperatures and modes, the hard part is done.
+181
View File
@@ -0,0 +1,181 @@
#!/usr/bin/env bash
#
# One-command install of the Aira bridge for the harbour-aira Sailfish app.
#
# What it does, in order:
# 1. clones (or updates) this repository into ~/harbour-aira
# 2. creates a private Python environment and installs the bridge
# 3. asks for your Aira email and password, typed without echo, and saves
# them in a file only you can read (never in the shell history, never in
# the logs, never on the phone)
# 4. checks that the bridge can log in and read your plant
# 5. installs and starts it as a systemd user service
# 6. prints the address and the token to type into the app
#
# Run it with: bash install.sh
#
# It changes nothing outside your home directory, and it never needs root.
set -euo pipefail
REPO_URL="${AIRA_REPO_URL:-https://git.hackatoniclife.com/kaneda/harbour-aira.git}"
INSTALL_DIR="${AIRA_INSTALL_DIR:-$HOME/harbour-aira}"
CONFIG_DIR="${AIRA_CONFIG_DIR:-$HOME/.config/aira}"
PORT="${AIRA_PORT:-8790}"
SKIP_SERVICE="${AIRA_SKIP_SERVICE:-0}"
SKIP_CREDS="${AIRA_SKIP_CREDS:-0}"
say() { printf '\n\033[1m%s\033[0m\n' "$*"; }
ok() { printf ' ok %s\n' "$*"; }
warn() { printf ' note %s\n' "$*"; }
die() { printf '\n error: %s\n\n' "$*" >&2; exit 1; }
# ---------------------------------------------------------------- prerequisites
say "Checking what this machine has"
command -v git >/dev/null 2>&1 || die "git is not installed. On Debian/Raspberry Pi OS: apt install git"
command -v python3 >/dev/null 2>&1 || die "python3 is not installed. On Debian/Raspberry Pi OS: apt install python3 python3-venv"
PY_OK=$(python3 -c 'import sys; print(1 if sys.version_info >= (3, 9) else 0)')
[ "$PY_OK" = "1" ] || die "python3 is $(python3 -V 2>&1 | cut -d' ' -f2), but the bridge needs 3.9 or newer."
python3 -c 'import venv' 2>/dev/null || die "the venv module is missing. On Debian/Raspberry Pi OS: apt install python3-venv"
ok "git $(git --version | cut -d' ' -f3), $(python3 -V 2>&1)"
# ------------------------------------------------------------------- the bridge
say "Fetching the bridge into $INSTALL_DIR"
if [ -d "$INSTALL_DIR/.git" ]; then
git -C "$INSTALL_DIR" pull --ff-only >/dev/null || warn "could not update the existing copy; using it as it is"
ok "already there, brought up to date"
else
mkdir -p "$(dirname "$INSTALL_DIR")"
git clone --quiet "$REPO_URL" "$INSTALL_DIR"
ok "cloned"
fi
BRIDGE="$INSTALL_DIR/bridge"
[ -f "$BRIDGE/aira_bridge.py" ] || die "the bridge is not where it should be ($BRIDGE)."
say "Installing the bridge and its libraries"
if [ ! -x "$BRIDGE/.venv/bin/python" ]; then
python3 -m venv "$BRIDGE/.venv"
fi
"$BRIDGE/.venv/bin/python" -m pip install --quiet --upgrade pip
# pyairahome pulls in grpcio, protobuf, pycognito, cryptography: on a Raspberry
# Pi this step is the slow one, a few minutes. Progress is hidden on purpose,
# the alternative is a page of compiler output that means nothing to a user.
"$BRIDGE/.venv/bin/python" -m pip install --quiet -r "$BRIDGE/requirements.txt"
ok "libraries in place"
# ------------------------------------------------------------- your credentials
mkdir -p "$CONFIG_DIR"
chmod 700 "$CONFIG_DIR"
if [ "$SKIP_CREDS" = "1" ]; then
warn "skipping the credentials step (AIRA_SKIP_CREDS=1)"
elif [ -f "$CONFIG_DIR/aira.json" ]; then
say "Aira credentials already present"
ok "$CONFIG_DIR/aira.json, left untouched"
else
say "Your Aira account"
printf ' Use the same email and password as the Aira app.\n'
printf ' The password is typed without echo: it is not shown, not saved in\n'
printf ' the shell history, and it stays on this machine.\n'
AIRA_CONFIG_DIR="$CONFIG_DIR" "$BRIDGE/.venv/bin/python" "$BRIDGE/setup_creds.py" \
|| die "credentials not saved."
fi
# ------------------------------------------------------------------ sanity check
if [ "$SKIP_CREDS" != "1" ]; then
say "Talking to your heat pump (read-only)"
printf ' This logs in to Aira and reads the current state. Nothing is changed.\n\n'
if AIRA_CONFIG_DIR="$CONFIG_DIR" "$BRIDGE/.venv/bin/python" "$BRIDGE/aira_probe.py"; then
ok "the bridge can reach your plant"
else
die "the bridge could not read your plant. Check the email and password, and that this machine can reach the internet."
fi
fi
# ------------------------------------------------------------------ the service
started=0
if [ "$SKIP_SERVICE" = "1" ]; then
warn "skipping the service step (AIRA_SKIP_SERVICE=1)"
elif command -v systemctl >/dev/null 2>&1 && systemctl --user show-environment >/dev/null 2>&1; then
say "Installing the service, so it starts by itself"
UNIT_DIR="$HOME/.config/systemd/user"
mkdir -p "$UNIT_DIR"
cat > "$UNIT_DIR/harbour-aira-bridge.service" <<UNIT
# Local HTTP bridge for the harbour-aira Sailfish app (generated by install.sh).
[Unit]
Description=Aira bridge for the harbour-aira app (local heat pump HTTP API)
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
WorkingDirectory=$BRIDGE
Environment=AIRA_CONFIG_DIR=$CONFIG_DIR
ExecStart=$BRIDGE/.venv/bin/python $BRIDGE/aira_bridge.py --host 0.0.0.0 --port $PORT
Restart=on-failure
RestartSec=5
[Install]
WantedBy=default.target
UNIT
# Without lingering the service stops as soon as you close your session,
# which looks exactly like a broken bridge from the phone.
loginctl enable-linger "$USER" >/dev/null 2>&1 || warn "could not enable lingering: the service may stop when you log out"
systemctl --user daemon-reload
systemctl --user enable --now harbour-aira-bridge.service >/dev/null
started=1
ok "service installed and started"
else
warn "no systemd user session here: start the bridge by hand when you need it"
printf ' AIRA_CONFIG_DIR=%s %s/.venv/bin/python %s/aira_bridge.py --port %s\n' \
"$CONFIG_DIR" "$BRIDGE" "$BRIDGE" "$PORT"
fi
# ---------------------------------------------------------- what the app needs
if [ "$started" = "1" ]; then
printf ' waiting for the bridge to answer'
for _ in $(seq 1 30); do
if curl -fsS "http://127.0.0.1:$PORT/health" >/dev/null 2>&1; then break; fi
printf '.'; sleep 1
done
printf '\n'
if curl -fsS "http://127.0.0.1:$PORT/health" >/dev/null 2>&1; then
ok "the bridge is answering"
else
warn "the bridge is not answering yet; check: systemctl --user status harbour-aira-bridge"
fi
fi
TOKEN=""
if [ -f "$CONFIG_DIR/aira_bridge.json" ]; then
TOKEN=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1])).get("token",""))' "$CONFIG_DIR/aira_bridge.json" 2>/dev/null || true)
fi
# The address the phone should use: this machine's address on the LAN.
ADDR=$(hostname -I 2>/dev/null | awk '{print $1}')
[ -n "$ADDR" ] || ADDR="<address-of-this-machine>"
cat <<LAST
------------------------------------------------------------------
In the app, open Settings and enter:
address http://$ADDR:$PORT
token ${TOKEN:-<see $CONFIG_DIR/aira_bridge.json>}
Both are private: the token is the key to your plant on your own
network. Do not share it, and do not forward this port from the
internet. Nothing here is exposed outside your LAN.
Useful commands:
systemctl --user status harbour-aira-bridge
systemctl --user restart harbour-aira-bridge
journalctl --user -u harbour-aira-bridge -f
To update later, run this script again: it pulls the new version.
------------------------------------------------------------------
LAST
+10 -10
View File
@@ -1,10 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"""Salva le credenziali Aira in $AIRA_CONFIG_DIR/aira.json (permessi 600). """Save the Aira credentials in $AIRA_CONFIG_DIR/aira.json (permissions 600).
Va eseguito da te, nel tuo terminale: la password viene digitata senza eco e non Run it yourself, in your own terminal: the password is typed without echo and
compare ne' nei log ne' nella cronologia della shell. never appears in the logs or in the shell history.
Uso: Usage:
cd bridge cd bridge
.venv/bin/python setup_creds.py .venv/bin/python setup_creds.py
""" """
@@ -20,14 +20,14 @@ TARGET = BASE / "aira.json"
def main() -> int: def main() -> int:
email = input("Email account Aira: ").strip() email = input("Aira account email: ").strip()
if not email: if not email:
print("email vuota, annullo", file=sys.stderr) print("empty email, aborting", file=sys.stderr)
return 1 return 1
password = getpass.getpass("Password (non verra' mostrata): ") password = getpass.getpass("Password (will not be shown): ")
if not password: if not password:
print("password vuota, annullo", file=sys.stderr) print("empty password, aborting", file=sys.stderr)
return 1 return 1
TARGET.parent.mkdir(parents=True, exist_ok=True) TARGET.parent.mkdir(parents=True, exist_ok=True)
@@ -36,8 +36,8 @@ def main() -> int:
os.chmod(tmp, stat.S_IRUSR | stat.S_IWUSR) os.chmod(tmp, stat.S_IRUSR | stat.S_IWUSR)
tmp.replace(TARGET) tmp.replace(TARGET)
print(f"\nOK: credenziali salvate in {TARGET} (permessi 600)") print(f"\nOK: credentials saved in {TARGET} (permissions 600)")
print("Ora lancia: .venv/bin/python aira_probe.py") print("Next: .venv/bin/python aira_probe.py")
return 0 return 0