hass.tibber_prices/scripts/setup

94 lines
3.7 KiB
Bash
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# script/setup: Setup script used by DevContainers to prepare the project
set -e
cd "$(dirname "$0")/.."
# Install optional pyright for type checking
if command -v npm >/dev/null 2>&1 && ! command -v pyright >/dev/null 2>&1; then
echo "==> Installing pyright for type checking..."
npm install -g pyright 2>/dev/null || {
echo " ⚠️ Warning: pyright installation failed (optional)"
echo " You can install it manually: npm install -g pyright"
}
fi
# Install optional release note backend: GitHub Copilot CLI (AI-powered)
if command -v npm >/dev/null 2>&1 && ! command -v copilot >/dev/null 2>&1; then
echo "==> Installing GitHub Copilot CLI for AI-powered release notes..."
npm install -g @github/copilot 2>/dev/null || {
echo " ⚠️ Warning: GitHub Copilot CLI installation failed (optional)"
echo " You can install it manually: npm install -g @github/copilot"
}
fi
# Install optional release note backend: git-cliff (template-based)
if command -v cargo >/dev/null 2>&1 && ! command -v git-cliff >/dev/null 2>&1; then
echo "==> Installing git-cliff for template-based release notes..."
cargo install git-cliff || {
echo " ⚠️ Warning: git-cliff installation failed (optional)"
}
fi
scripts/bootstrap
# Install HACS for testing with other custom components
echo ""
echo "==> Installing HACS in dev environment..."
echo " This allows testing your integration alongside other HACS components."
# Ensure config directory is initialized by Home Assistant first
if [ ! -f "config/.HA_VERSION" ]; then
echo " → Initializing Home Assistant config directory..."
hass --config "${PWD}/config" --script ensure_config >/dev/null 2>&1 || true
fi
# Create custom_components directory if it doesn't exist
mkdir -p config/custom_components
# Clean up existing HACS installation if present
if [ -d "config/custom_components/hacs" ]; then
echo " → Removing existing HACS installation..."
rm -rf config/custom_components/hacs
fi
if [ -L "custom_components/hacs" ]; then
echo " → Removing existing HACS symlink..."
rm -f custom_components/hacs
fi
# Download and extract HACS (stable release ZIP)
cd config/custom_components
echo " → Downloading HACS..."
if wget -q https://github.com/hacs/integration/releases/latest/download/hacs.zip && \
unzip -q hacs.zip -d hacs && \
rm hacs.zip; then
cd ../..
# Install HACS Python dependencies
echo " → Installing HACS Python dependencies..."
if uv pip install -q 'aiogithubapi>=22.10.1'; then
# Create symlink so HA finds HACS alongside tibber_prices
echo " → Creating symlink in custom_components/..."
ln -sf "${PWD}/config/custom_components/hacs" custom_components/hacs
echo " ✓ HACS installed successfully in config/custom_components/hacs/"
echo " HACS is installed as stable release (no auto-updates)"
echo " HACS will install other integrations in config/custom_components/"
echo " Run './scripts/sync-hacs' after installing integrations via HACS"
else
echo " ⚠️ Warning: Failed to install HACS Python dependencies"
echo " You can install manually: uv pip install 'aiogithubapi>=22.10.1'"
fi
else
echo " ⚠️ Warning: HACS installation failed"
echo " You can install manually:"
echo " cd config/custom_components"
echo " wget https://github.com/hacs/integration/releases/latest/download/hacs.zip"
echo " unzip hacs.zip -d hacs && rm hacs.zip"
cd ../..
fi
echo ""
echo "==> Project is now ready to go!"