#!/usr/bin/env bash
# HousemAId one-command install (get.gethousemaid.ai). Downloads housemaid-get, checks its SHA-256, runs it.
set -euo pipefail
BASE="${HM_GET_BASE:-https://get.gethousemaid.ai}"
WANT="1f8eb591e2e8428d6ff48d47c42a01214cd462b3ababb6fbf4857fc69cb24c7b"
command -v python3 >/dev/null || { echo "HousemAId needs python3 (Ubuntu has it): sudo apt-get install -y python3"; exit 1; }
[ "$(id -u)" = 0 ] || { echo "Run it with sudo: curl -fsSL $BASE | sudo bash -s -- --key ... --host ..."; exit 1; }
D=/var/lib/housemaid-get; mkdir -p "$D"; chmod 700 "$D"
curl -fsSL --retry 5 -o "$D/housemaid-get.new" "$BASE/housemaid-get"
GOT=$(sha256sum "$D/housemaid-get.new" | cut -d' ' -f1)
if [ "$GOT" != "$WANT" ]; then rm -f "$D/housemaid-get.new"; echo "STOP: the downloaded installer is not the one HousemAId published (checksum differs). Nothing was installed. Tell support@gethousemaid.ai."; exit 1; fi
mv "$D/housemaid-get.new" "$D/housemaid-get"; chmod 700 "$D/housemaid-get"
ARGS=(); KEY=""
while [ $# -gt 0 ]; do case "$1" in --key) KEY="$2"; shift 2;; --key=*) KEY="${1#--key=}"; shift;; *) ARGS+=("$1"); shift;; esac; done
export HM_GET_KEY="$KEY" HM_GET_BASE="$BASE"
if [ -r /dev/tty ] && (exec </dev/tty) 2>/dev/null; then exec python3 "$D/housemaid-get" "${ARGS[@]}" </dev/tty; fi
exec python3 "$D/housemaid-get" "${ARGS[@]}"
