Skip to content

Instantly share code, notes, and snippets.

@Limych
Forked from juvenn/install.sh
Last active April 22, 2023 21:10
Show Gist options
  • Save Limych/fcd02fefb895c7d981a5534ab99837e7 to your computer and use it in GitHub Desktop.
Save Limych/fcd02fefb895c7d981a5534ab99837e7 to your computer and use it in GitHub Desktop.
Home Assistant Supervisor on Coreelec 20.x
#!/usr/bin/env bash
set -e
function info { echo -e "\e[32m[info] $*\e[39m"; }
function warn { echo -e "\e[33m[warn] $*\e[39m"; }
function error { echo -e "\e[31m[error] $*\e[39m"; exit 1; }
ARCH=$(uname -m)
# Check env
command -v systemctl > /dev/null 2>&1 || error "Only systemd is supported!"
command -v curl > /dev/null 2>&1 || error "Please install curl first"
command -v avahi-daemon > /dev/null 2>&1 || error "Please install avahi first"
command -v dbus-daemon > /dev/null 2>&1 || error "Please install dbus first"
command -v jq > /dev/null 2>&1 || {
installentware
export PATH=/opt/bin:/opt/sbin:\$PATH
/opt/bin/opkg install jq
}
command -v docker > /dev/null 2>&1 || {
curl https://raw.githubusercontent.com/tamusiunas/docker-coreelec/main/auto-install-docker-coreelec.bash \
>./auto-install-docker-coreelec.bash
bash ./auto-install-docker-coreelec.bash noshutdown
rm ./auto-install-docker-coreelec.bash
}
BINARY_DOCKER=$(which docker)
ln -s $BINARY_DOCKER /opt/bin/docker
DOCKER_REPO="ghcr.io/home-assistant"
SERVICE_DOCKER="docker.service"
# Read infos from web
URL_CHECK_ONLINE="checkonline.home-assistant.io"
URL_VERSION="https://version.home-assistant.io/stable.json"
HASSIO_VERSION=$(curl -s ${URL_VERSION} | jq -e -r '.supervisor')
URL_HA="https://raw.githubusercontent.com/home-assistant/supervised-installer/1.1.0/homeassistant-supervised/usr/bin/ha"
URL_BIN_HASSIO="https://raw.githubusercontent.com/home-assistant/supervised-installer/1.1.0/homeassistant-supervised/usr/sbin/hassio-supervisor"
URL_SERVICE_HASSIO="https://raw.githubusercontent.com/home-assistant/supervised-installer/1.1.0/homeassistant-supervised/etc/systemd/system/hassio-supervisor.service"
# Check if Modem Manager is enabled
if systemctl list-unit-files ModemManager.service | grep enabled; then
warn "ModemManager service is enabled. This might cause issue when using serial devices."
fi
# Parse command line parameters
while [[ $# -gt 0 ]]; do
arg="$1"
case $arg in
-m|--machine)
MACHINE=$2
shift
;;
-d|--data-share)
DATA_SHARE=$2
shift
;;
-p|--prefix)
PREFIX=$2
shift
;;
-s|--sysconfdir)
SYSCONFDIR=$2
shift
;;
*)
error "Unrecognized option $1"
;;
esac
shift
done
PREFIX=${PREFIX:-/storage/.opt}
SYSCONFDIR=${SYSCONFDIR:-/storage/.config/system.d}
DATA_SHARE=${DATA_SHARE:-/media/MEDIA/HomeAssistant}
SBIN=${SBIN:-$PREFIX/sbin}
CONFIG=$SYSCONFDIR/hassio.json
# Generate hardware options
case $ARCH in
"i386" | "i686")
MACHINE=${MACHINE:=qemux86}
HOMEASSISTANT_DOCKER="$DOCKER_REPO/$MACHINE-homeassistant"
HASSIO_DOCKER="$DOCKER_REPO/i386-hassio-supervisor"
;;
"x86_64")
MACHINE=${MACHINE:=qemux86-64}
HOMEASSISTANT_DOCKER="$DOCKER_REPO/$MACHINE-homeassistant"
HASSIO_DOCKER="$DOCKER_REPO/amd64-hassio-supervisor"
;;
"arm" |"armv6l")
if [ -z $MACHINE ]; then
error "Please set machine for $ARCH"
fi
HOMEASSISTANT_DOCKER="$DOCKER_REPO/$MACHINE-homeassistant"
HASSIO_DOCKER="$DOCKER_REPO/armhf-hassio-supervisor"
;;
"armv7l")
if [ -z $MACHINE ]; then
error "Please set machine for $ARCH"
fi
HOMEASSISTANT_DOCKER="$DOCKER_REPO/$MACHINE-homeassistant"
HASSIO_DOCKER="$DOCKER_REPO/armv7-hassio-supervisor"
;;
"aarch64")
MACHINE=${MACHINE:=qemuarm-64}
HOMEASSISTANT_DOCKER="$DOCKER_REPO/$MACHINE-homeassistant"
HASSIO_DOCKER="$DOCKER_REPO/aarch64-hassio-supervisor"
;;
*)
error "$ARCH unknown!"
;;
esac
if [ -z "${HOMEASSISTANT_DOCKER}" ]; then
error "Found no Home Assistant Docker images for this host!"
fi
if [[ ! "khadas-vim3 intel-nuc odroid-c2 odroid-n2 odroid-xu qemuarm qemuarm-64 qemux86 qemux86-64 raspberrypi raspberrypi2 raspberrypi3 raspberrypi4 raspberrypi3-64 raspberrypi4-64 tinker" = *"${MACHINE}"* ]]; then
error "Unknown machine type ${MACHINE}!"
fi
### Main
# Init folders
if [ ! -d "$DATA_SHARE" ]; then
mkdir -p "$DATA_SHARE"
fi
if [ ! -d "$SYSCONFDIR" ]; then
mkdir -p "$SYSCONFDIR"
fi
if [ ! -d "$SBIN" ]; then
mkdir -p "$SBIN"
fi
##
# Write configuration
cat > "${CONFIG}" <<- EOF
{
"supervisor": "${HASSIO_DOCKER}",
"machine": "${MACHINE}",
"data": "${DATA_SHARE}"
}
EOF
# Restart Docker service
info "Restarting docker service"
systemctl restart "${SERVICE_DOCKER}"
# Check network connection
while ! ping -c 1 -W 1 ${URL_CHECK_ONLINE}; do
info "Waiting for ${URL_CHECK_ONLINE} - network interface might be down..."
sleep 2
done
# Get primary network interface
PRIMARY_INTERFACE=$(ip route | awk '/^default/ { print $5; exit }')
IP_ADDRESS=$(ip -4 addr show dev "${PRIMARY_INTERFACE}" | awk '/inet / { sub("/.*", "", $2); print $2 }')
##
# Pull supervisor image
info "Install supervisor Docker container"
docker pull "$HASSIO_DOCKER:$HASSIO_VERSION" > /dev/null
docker tag "$HASSIO_DOCKER:$HASSIO_VERSION" "$HASSIO_DOCKER:latest" > /dev/null
##
# Install Hass.io Supervisor
info "Install supervisor startup scripts"
curl -sL ${URL_BIN_HASSIO} > "${PREFIX}/sbin/hassio-supervisor"
curl -sL ${URL_SERVICE_HASSIO} > "${SYSCONFDIR}/hassio-supervisor.service"
sed -i "s,%%HASSIO_CONFIG%%,${CONFIG},g" "${PREFIX}"/sbin/hassio-supervisor
sed -i -e "10i Environment=\"PATH=/opt/bin:/opt/sbin:/usr/bin:/usr/sbin\"" \
-e "s,%%BINARY_DOCKER%%,${BINARY_DOCKER},g" \
-e "s,%%SERVICE_DOCKER%%,${SERVICE_DOCKER},g" \
-e "s,%%BINARY_HASSIO%%,${PREFIX}/sbin/hassio-supervisor,g" \
"${SYSCONFDIR}/hassio-supervisor.service"
chmod a+x "${PREFIX}/sbin/hassio-supervisor"
systemctl enable hassio-supervisor.service > /dev/null 2>&1;
# Start Supervisor
info "Start Home Assistant Supervised"
systemctl start hassio-supervisor.service
# Install HA CLI
info "Installing the 'ha' cli"
curl -sL ${URL_HA} > "${PREFIX}/bin/ha"
chmod a+x "${PREFIX}/bin/ha"
info "Within a few minutes you will be able to reach Home Assistant at:"
info "http://homeassistant.local:8123 or using the IP address of your"
info "machine: http://${IP_ADDRESS}:8123"
@Limych
Copy link
Author

Limych commented Nov 25, 2022

Run this commands via SSH to install Home Assistant:

curl https://gist.githubusercontent.com/Limych/fcd02fefb895c7d981a5534ab99837e7/raw/install-supervised-hass-on-coreelec.bash \
    >./install-supervised-hass.bash
bash ./install-supervised-hass.bash

@Limych
Copy link
Author

Limych commented Nov 25, 2022

In this script used docker installation by @tamusiunas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment