#!/bin/sh # --------------------------------------------------------------------------- # Install from your HA device's terminal: # # curl -fsSL https://aevocam.com/ha-ins | sh # # Later uninstall via: # # curl -fsSL https://aevocam.com/ha-unins | sh # # --------------------------------------------------------------------------- set -eu REPO_OWNER="JimCarnicelli" REPO_NAME="aevocam-homeassistant" COMPONENT_NAME="aevocam" echo echo "Aevocam Home Assistant Integration Installer" echo "=============================================" echo # --------------------------------------------------------------------------- # Locate the Home Assistant configuration directory. # # Typical environments: # # Home Assistant OS host: # /mnt/data/supervisor/homeassistant # # Terminal/SSH add-on or similar environment: # /config # --------------------------------------------------------------------------- if [ -f "/config/configuration.yaml" ]; then HA_CONFIG="/config" elif [ -f "/mnt/data/supervisor/homeassistant/configuration.yaml" ]; then HA_CONFIG="/mnt/data/supervisor/homeassistant" else echo "ERROR: Could not locate the Home Assistant configuration directory." echo echo "Expected to find configuration.yaml in one of:" echo echo " /config" echo " /mnt/data/supervisor/homeassistant" echo echo "If your Home Assistant configuration is stored elsewhere," echo "this installer cannot currently detect it automatically." exit 1 fi echo "Home Assistant configuration:" echo " $HA_CONFIG" echo CUSTOM_COMPONENTS="$HA_CONFIG/custom_components" INSTALL_DIR="$CUSTOM_COMPONENTS/$COMPONENT_NAME" # --------------------------------------------------------------------------- # Check required utilities. # --------------------------------------------------------------------------- for cmd in curl tar; do if ! command -v "$cmd" >/dev/null 2>&1; then echo "ERROR: Required command '$cmd' was not found." exit 1 fi done # --------------------------------------------------------------------------- # Work in a temporary directory. # --------------------------------------------------------------------------- TMP_BASE="${TMPDIR:-/tmp}" TMP_DIR="$TMP_BASE/aevocam-ha-install-$$" cleanup() { rm -rf "$TMP_DIR" } trap cleanup EXIT INT TERM mkdir -p "$TMP_DIR" ARCHIVE="$TMP_DIR/aevocam.tar.gz" EXTRACT_DIR="$TMP_DIR/extracted" mkdir -p "$EXTRACT_DIR" # Resolve the latest GitHub release tag (installer script itself may come from # main; the package always comes from the newest published release). echo "Resolving latest release..." RELEASE_API="https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/latest" TAG=$( curl \ --fail \ --location \ --silent \ --show-error \ "$RELEASE_API" \ | sed -n 's/^[[:space:]]*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' \ | head -n 1 ) if [ -z "$TAG" ]; then echo "ERROR: Could not determine the latest release tag from GitHub." exit 1 fi # GitHub archive directories replace '/' in tags with '-'. ARCHIVE_ROOT="$REPO_NAME-$(echo "$TAG" | tr '/' '-')" DOWNLOAD_URL="https://github.com/$REPO_OWNER/$REPO_NAME/archive/refs/tags/$TAG.tar.gz" echo "Downloading Aevocam $TAG..." echo curl \ --fail \ --location \ --silent \ --show-error \ "$DOWNLOAD_URL" \ --output "$ARCHIVE" echo "Extracting package..." tar -xzf "$ARCHIVE" -C "$EXTRACT_DIR" SOURCE_DIR="$EXTRACT_DIR/$ARCHIVE_ROOT/custom_components/$COMPONENT_NAME" # --------------------------------------------------------------------------- # Validate the downloaded package before touching the existing installation. # --------------------------------------------------------------------------- if [ ! -d "$SOURCE_DIR" ]; then echo "ERROR: Downloaded package does not contain:" echo " custom_components/$COMPONENT_NAME" exit 1 fi if [ ! -f "$SOURCE_DIR/manifest.json" ]; then echo "ERROR: Downloaded Aevocam integration has no manifest.json." exit 1 fi if [ ! -f "$SOURCE_DIR/__init__.py" ]; then echo "ERROR: Downloaded Aevocam integration has no __init__.py." exit 1 fi # Basic sanity check that we really downloaded the Aevocam integration. if ! grep -q '"domain"[[:space:]]*:[[:space:]]*"aevocam"' \ "$SOURCE_DIR/manifest.json"; then echo "ERROR: Downloaded manifest.json does not identify the" echo "Aevocam integration." exit 1 fi echo "Package looks valid." echo # --------------------------------------------------------------------------- # Install. # --------------------------------------------------------------------------- mkdir -p "$CUSTOM_COMPONENTS" # Build the new tree aside, then swap it into place. Keep the previous # install only until the swap succeeds, then delete it (no lasting backup). STAGING_DIR="$CUSTOM_COMPONENTS/.aevocam-installing" OLD_DIR="$CUSTOM_COMPONENTS/.aevocam-old" rm -rf "$STAGING_DIR" "$OLD_DIR" cp -R "$SOURCE_DIR" "$STAGING_DIR" if [ -d "$INSTALL_DIR" ]; then echo "Replacing existing installation..." mv "$INSTALL_DIR" "$OLD_DIR" fi mv "$STAGING_DIR" "$INSTALL_DIR" rm -rf "$OLD_DIR" # Leftover from older installer versions that kept aevocam.backup. rm -rf "$CUSTOM_COMPONENTS/aevocam.backup" sync echo "Aevocam installed successfully." echo echo "Installed at:" echo " $INSTALL_DIR" echo echo "Next:" echo echo " 1. Restart Home Assistant." echo " 2. Open Settings -> Devices & services." echo " 3. Select Add Integration." echo " 4. Search for Aevocam." echo