summaryrefslogtreecommitdiffstats
path: root/hacs-install.sh
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2025-09-08 19:19:14 +0400
committerSuren A. Chilingaryan <csa@suren.me>2025-09-08 19:19:14 +0400
commit0494cf139a6a3324e10e2cfa3479d9b0b3ddd779 (patch)
treef4a642bda41f5308c22fc10c561542edcb602dd4 /hacs-install.sh
parent346c5ea64f9c9d19dde63c8e85b1477440f2778f (diff)
downloadhass-0494cf139a6a3324e10e2cfa3479d9b0b3ddd779.tar.gz
hass-0494cf139a6a3324e10e2cfa3479d9b0b3ddd779.tar.bz2
hass-0494cf139a6a3324e10e2cfa3479d9b0b3ddd779.tar.xz
hass-0494cf139a6a3324e10e2cfa3479d9b0b3ddd779.zip
System changes
Diffstat (limited to 'hacs-install.sh')
-rw-r--r--hacs-install.sh126
1 files changed, 126 insertions, 0 deletions
diff --git a/hacs-install.sh b/hacs-install.sh
new file mode 100644
index 0000000..baf94d0
--- /dev/null
+++ b/hacs-install.sh
@@ -0,0 +1,126 @@
+#!/bin/bash
+# wget -O - https://get.hacs.xyz | bash -
+set -e
+
+RED_COLOR='\033[0;31m'
+GREEN_COLOR='\033[0;32m'
+GREEN_YELLOW='\033[1;33m'
+NO_COLOR='\033[0m'
+
+declare haPath
+declare -a paths=(
+ "$PWD"
+ "$PWD/config"
+ "/config"
+ "$HOME/.homeassistant"
+ "/usr/share/hassio/homeassistant"
+)
+declare currentVersion
+declare currentYear
+declare currentMonth
+declare currentPatch
+declare targetVersion
+declare targetYear
+declare targetMonth
+declare targetPatch
+
+function info () { echo -e "${GREEN_COLOR}INFO: $1${NO_COLOR}";}
+function warn () { echo -e "${GREEN_YELLOW}WARN: $1${NO_COLOR}";}
+function error () { echo -e "${RED_COLOR}ERROR: $1${NO_COLOR}"; if [ "$2" != "false" ]; then exit 1;fi; }
+
+function checkRequirement () {
+ if [ -z "$(command -v "$1")" ]; then
+ error "'$1' is not installed"
+ fi
+}
+
+checkRequirement "wget"
+checkRequirement "unzip"
+
+info "Trying to find the correct directory..."
+for path in "${paths[@]}"; do
+ if [ -n "$haPath" ]; then
+ break
+ fi
+
+ if [ -f "$path/.HA_VERSION" ]; then
+ haPath="$path"
+ fi
+done
+
+if [ -n "$haPath" ]; then
+ info "Found Home Assistant configuration directory at '$haPath'"
+ cd "$haPath" || error "Could not change path to $haPath"
+ if [ ! -d "$haPath/custom_components" ]; then
+ info "Creating custom_components directory..."
+ mkdir "$haPath/custom_components"
+ fi
+
+ info "Changing to the custom_components directory..."
+ cd "$haPath/custom_components" || error "Could not change path to $haPath/custom_components"
+
+ info "Downloading HACS"
+ wget "https://github.com/hacs/integration/releases/latest/download/hacs.zip"
+
+ if [ -d "$haPath/custom_components/hacs" ]; then
+ warn "HACS directory already exist, cleaning up..."
+ rm -R "$haPath/custom_components/hacs"
+ fi
+
+ info "Creating HACS directory..."
+ mkdir "$haPath/custom_components/hacs"
+
+ info "Unpacking HACS..."
+ unzip "$haPath/custom_components/hacs.zip" -d "$haPath/custom_components/hacs" >/dev/null 2>&1
+
+
+ echo
+ info "Verifying versions"
+ targetVersion=$(sed -n -e '/^MINIMUM_HA_VERSION/p' "$haPath/custom_components/hacs/const.py" | cut -d '"' -f 2)
+ currentVersion=$(cat "$haPath/.HA_VERSION")
+
+ info "Current version is ${currentVersion}, minimum version is ${targetVersion}"
+
+ targetYear=$(echo "${targetVersion}" | cut -d "." -f 1)
+ currentYear=$(echo "${currentVersion}" | cut -d "." -f 1)
+
+ if [ "${currentYear}" -lt "${targetYear}" ]; then
+ rm -R "$haPath/custom_components/hacs"
+ error "Version ${currentVersion} is not new enough, needs at least ${targetVersion}"
+ fi
+
+ if [ "${currentYear}" == "${targetYear}" ]; then
+ targetMonth=$(echo "${targetVersion}" | cut -d "." -f 2)
+ currentMonth=$(echo "${currentVersion}" | cut -d "." -f 2)
+
+ if [ "${currentMonth}" -lt "${targetMonth}" ]; then
+ rm -R "$haPath/custom_components/hacs"
+ error "Version ${currentVersion} is not new enough, needs at least ${targetVersion}"
+ fi
+
+ if [ "${currentMonth}" == "${targetMonth}" ]; then
+ targetPatch=$(echo "${targetVersion}" | cut -d "." -f 3)
+ currentPatch=$(echo "${currentVersion}" | cut -d "." -f 3)
+
+ if [ "${currentPatch}" -lt "${targetPatch}" ]; then
+ rm -R "$haPath/custom_components/hacs"
+ error "Version ${currentVersion} is not new enough, needs at least ${targetVersion}"
+ fi
+ fi
+ fi
+
+ echo
+ info "Removing HACS zip file..."
+ rm "$haPath/custom_components/hacs.zip"
+ info "Installation complete."
+ echo
+ info "Remember to restart Home Assistant before you configure it"
+
+else
+ echo
+ error "Could not find the directory for Home Assistant" false
+ echo "Manually change the directory to the root of your Home Assistant configuration"
+ echo "With the user that is running Home Assistant"
+ echo "and run the script again"
+ exit 1
+fi