mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-16 13:46:31 +00:00
Add homeassistant repository to build / init hassio python script
This commit is contained in:
parent
b41bc6232f
commit
13f0a30fff
@ -43,9 +43,20 @@ RESIN_BRANCH=${RESIN_BRANCH:=master}
|
|||||||
|
|
||||||
# evaluate git repo and arch
|
# evaluate git repo and arch
|
||||||
case $MACHINE in
|
case $MACHINE in
|
||||||
"raspberrypi3" | "raspberrypi2" | "raspberrypi")
|
"raspberrypi")
|
||||||
ARCH="armhf"
|
ARCH="armhf"
|
||||||
RESIN_REPO="https://github.com/resin-os/resin-raspberrypi"
|
RESIN_REPO="https://github.com/resin-os/resin-raspberrypi"
|
||||||
|
HOMEASSISTANT_REPOSITORY="$DOCKER_REPO/raspberrypi-homeassistant"
|
||||||
|
;;
|
||||||
|
"raspberrypi2")
|
||||||
|
ARCH="armhf"
|
||||||
|
RESIN_REPO="https://github.com/resin-os/resin-raspberrypi"
|
||||||
|
HOMEASSISTANT_REPOSITORY="$DOCKER_REPO/raspberrypi2-homeassistant"
|
||||||
|
;;
|
||||||
|
"raspberrypi3")
|
||||||
|
ARCH="armhf"
|
||||||
|
RESIN_REPO="https://github.com/resin-os/resin-raspberrypi"
|
||||||
|
HOMEASSISTANT_REPOSITORY="$DOCKER_REPO/raspberrypi3-homeassistant"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "[ERROR] ${MACHINE} unknown!"
|
echo "[ERROR] ${MACHINE} unknown!"
|
||||||
@ -67,7 +78,7 @@ echo "[INFO] Inject HassIO yocto layer"
|
|||||||
cp -fr $HASSIO_ROOT/meta-hassio $WORKSPACE/layers/
|
cp -fr $HASSIO_ROOT/meta-hassio $WORKSPACE/layers/
|
||||||
|
|
||||||
# Additional variables
|
# Additional variables
|
||||||
BARYS_ARGUMENTS_VAR="-a HASSIO_SUPERVISOR_TAG=$SUPERVISOR_TAG"
|
BARYS_ARGUMENTS_VAR="-a HASSIO_SUPERVISOR_TAG=$SUPERVISOR_TAG -a HOMEASSISTANT_REPOSITORY=$HOMEASSISTANT_REPOSITORY"
|
||||||
|
|
||||||
# Make sure shared directories are in place
|
# Make sure shared directories are in place
|
||||||
mkdir -p $DOWNLOAD_DIR
|
mkdir -p $DOWNLOAD_DIR
|
||||||
|
40
hassio_api/hassio/bootstrap.py
Normal file
40
hassio_api/hassio/bootstrap.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
"""Bootstrap HassIO."""
|
||||||
|
import asyncio
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
from .const import (
|
||||||
|
FILE_HASSIO_ADDONS, FILE_HASSIO_VERSION, FILE_RESIN_CONFIG,
|
||||||
|
HOMEASSISTANT_CONFIG, CONF_SUPERVISOR_TAG, CONF_SUPERVISOR_IMAGE)
|
||||||
|
|
||||||
|
|
||||||
|
def initialize_system_data():
|
||||||
|
"""Setup default config and create folders."""
|
||||||
|
# homeassistant config folder
|
||||||
|
if not os.path.isdir(HOMEASSISTANT_CONFIG):
|
||||||
|
os.mkdir(HOMEASSISTANT_CONFIG)
|
||||||
|
|
||||||
|
# installed addons
|
||||||
|
if not os.path.isfile(FILE_HASSIO_ADDONS):
|
||||||
|
with open(FILE_HASSIO_ADDONS) as addons_file:
|
||||||
|
addons_file.write(json.dumps({}))
|
||||||
|
|
||||||
|
# supervisor/homeassistant image/tag versions
|
||||||
|
versions = {}
|
||||||
|
if not os.path.isfile(FILE_HASSIO_VERSION):
|
||||||
|
versions.update({
|
||||||
|
CONF_HOMEASSISTANT_IMAGE: os.environ['HOMEASSISTANT_REPOSITORY'],
|
||||||
|
CONF_HOMEASSISTANT_TAG: '',
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
with open(FILE_HASSIO_VERSION, 'r') as conf_file:
|
||||||
|
versions = json.loads(conf_file.read())
|
||||||
|
|
||||||
|
# update version
|
||||||
|
versions.update({
|
||||||
|
CONF_SUPERVISOR_IMAGE: os.environ['SUPERVISOR_IMAGE'],
|
||||||
|
CONF_SUPERVISOR_TAG: os.environ['SUPERVISOR_TAG'],
|
||||||
|
})
|
||||||
|
|
||||||
|
with open(FILE_HASSIO_VERSION, 'w') as conf_file:
|
||||||
|
conf_file.write(json.dumps(versions))
|
18
hassio_api/hassio/const.py
Normal file
18
hassio_api/hassio/const.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
"""Const file for HassIO."""
|
||||||
|
URL_SUPERVISOR_VERSION = \
|
||||||
|
'https://raw.githubusercontent.com/pvizeli/hassio/master/version.json'
|
||||||
|
|
||||||
|
URL_ADDONS_REPO = 'https://github.com/pvizeli/hassio-addons'
|
||||||
|
|
||||||
|
FILE_RESIN_CONFIG = '/boot/config.json'
|
||||||
|
FILE_HASSIO_ADDONS = '/data/addons.json'
|
||||||
|
FILE_HASSIO_VERSION = '/data/version.json'
|
||||||
|
|
||||||
|
HOMEASSISTANT_CONFIG = '/resin-data/config'
|
||||||
|
|
||||||
|
HTTP_PORT = 9123
|
||||||
|
|
||||||
|
CONF_SUPERVISOR_IMAGE = 'supervisor_image'
|
||||||
|
CONF_SUPERVISOR_TAG = 'supervisor_tag'
|
||||||
|
CONF_HOMEASSISTANT_IMAGE = 'homeassistant_image'
|
||||||
|
CONF_HOMEASSISTANT_TAG = 'homeassistant_tag'
|
@ -12,3 +12,16 @@ SUPERVISOR_REPOSITORY_x86-64 = "pvizeli/amd64-hassio-supervisor"
|
|||||||
SUPERVISOR_TAG = "${HASSIO_SUPERVISOR_TAG}"
|
SUPERVISOR_TAG = "${HASSIO_SUPERVISOR_TAG}"
|
||||||
TARGET_REPOSITORY = "${SUPERVISOR_REPOSITORY}"
|
TARGET_REPOSITORY = "${SUPERVISOR_REPOSITORY}"
|
||||||
TARGET_TAG = "${SUPERVISOR_TAG}"
|
TARGET_TAG = "${SUPERVISOR_TAG}"
|
||||||
|
|
||||||
|
SRC_URI += " \
|
||||||
|
file://hassio.conf \
|
||||||
|
"
|
||||||
|
|
||||||
|
FILES_${PN} += " \
|
||||||
|
${sysconfdir} \
|
||||||
|
"
|
||||||
|
|
||||||
|
do_install_append () {
|
||||||
|
install -m 0755 ${WORKDIR}/hassio.conf ${D}${sysconfdir}/
|
||||||
|
sed -i -e 's:@HOMEASSISTANT_REPOSITORY@:${HOMEASSISTANT_REPOSITORY}:g' ${D}${sysconfdir}/hassio.conf
|
||||||
|
}
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
HOMEASSISTANT_REPOSITORY=@HOMEASSISTANT_REPOSITORY@
|
@ -1,6 +1,7 @@
|
|||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
|
|
||||||
source /usr/sbin/resin-vars
|
source /usr/sbin/resin-vars
|
||||||
|
source /etc/hassio.conf
|
||||||
|
|
||||||
SUPERVISOR_IMAGE_ID=$(docker inspect --format='{{.Id}}' $SUPERVISOR_IMAGE)
|
SUPERVISOR_IMAGE_ID=$(docker inspect --format='{{.Id}}' $SUPERVISOR_IMAGE)
|
||||||
SUPERVISOR_CONTAINER_IMAGE_ID=$(docker inspect --format='{{.Image}}' resin_supervisor || echo "")
|
SUPERVISOR_CONTAINER_IMAGE_ID=$(docker inspect --format='{{.Image}}' resin_supervisor || echo "")
|
||||||
@ -11,6 +12,7 @@ runSupervisor() {
|
|||||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||||
-v $CONFIG_PATH:/boot/config.json \
|
-v $CONFIG_PATH:/boot/config.json \
|
||||||
-v /resin-data/resin-supervisor:/data \
|
-v /resin-data/resin-supervisor:/data \
|
||||||
|
-v /resin-data:/resin-data \
|
||||||
-v /proc/net/fib_trie:/mnt/fib_trie \
|
-v /proc/net/fib_trie:/mnt/fib_trie \
|
||||||
-v /var/log/supervisor-log:/var/log \
|
-v /var/log/supervisor-log:/var/log \
|
||||||
-v /:/mnt/root \
|
-v /:/mnt/root \
|
||||||
@ -20,6 +22,7 @@ runSupervisor() {
|
|||||||
-e LED_FILE=${LED_FILE} \
|
-e LED_FILE=${LED_FILE} \
|
||||||
-e SUPERVISOR_IMAGE=${SUPERVISOR_IMAGE} \
|
-e SUPERVISOR_IMAGE=${SUPERVISOR_IMAGE} \
|
||||||
-e SUPERVISOR_TAG=${SUPERVISOR_TAG} \
|
-e SUPERVISOR_TAG=${SUPERVISOR_TAG} \
|
||||||
|
-e HOMEASSISTANT_REPOSITORY=${HOMEASSISTANT_REPOSITORY} \
|
||||||
${SUPERVISOR_IMAGE}
|
${SUPERVISOR_IMAGE}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,28 +69,14 @@ function error_handler {
|
|||||||
|
|
||||||
trap 'error_handler $LINENO' ERR
|
trap 'error_handler $LINENO' ERR
|
||||||
|
|
||||||
request=$(curl -X PUT $API_ENDPOINT/supervisor | jq -e -r '.message')
|
if request=$(curl -X PUT $API_ENDPOINT/supervisor | jq -e -r '.image,.tag')
|
||||||
if [ request != "ok" ]; then
|
read image_name, tag <<<$request
|
||||||
error_handler $LINENO $request
|
|
||||||
fi
|
|
||||||
|
|
||||||
# reload supervisor config
|
# Check that we didn't somehow get an empty tag version.
|
||||||
source /etc/resin-supervisor/supervisor.conf
|
if [ -z "$tag" ]; then
|
||||||
if [ -z "$UPDATER_SUPERVISOR_TAG" ]; then
|
error_handler $LINENO "no tag received"
|
||||||
# Try to get the tag from supervisor.conf
|
|
||||||
if [ -n "$SUPERVISOR_TAG" ]; then
|
|
||||||
UPDATER_SUPERVISOR_TAG=$SUPERVISOR_TAG
|
|
||||||
else
|
|
||||||
echo "ERROR: No tag argument provided."
|
|
||||||
error_handler $LINENO "no tag argument provided"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ -z "$UPDATER_SUPERVISOR_IMAGE" ]; then
|
|
||||||
UPDATER_SUPERVISOR_IMAGE=$SUPERVISOR_IMAGE
|
|
||||||
fi
|
|
||||||
echo "Set based on arguments image=$UPDATER_SUPERVISOR_IMAGE and tag=$UPDATER_SUPERVISOR_TAG."
|
|
||||||
image_name=$UPDATER_SUPERVISOR_IMAGE
|
|
||||||
tag=$UPDATER_SUPERVISOR_TAG
|
|
||||||
|
|
||||||
# Get image id of tag. This will be non-empty only in case it's already downloaded.
|
# Get image id of tag. This will be non-empty only in case it's already downloaded.
|
||||||
echo "Getting image id..."
|
echo "Getting image id..."
|
||||||
|
@ -8,7 +8,7 @@ RUN apk del --no-cache python*
|
|||||||
ENV LANG C.UTF-8
|
ENV LANG C.UTF-8
|
||||||
|
|
||||||
# setup base
|
# setup base
|
||||||
RUN apk add --no-cache python3
|
RUN apk add --no-cache python3 git
|
||||||
|
|
||||||
# install aiohttp
|
# install aiohttp
|
||||||
RUN pip3 install pip --no-cache --upgrade && pip3 install --no-cache aiohttp && pip3 install --no-cache docker
|
RUN pip3 install pip --no-cache --upgrade && pip3 install --no-cache aiohttp && pip3 install --no-cache docker
|
||||||
|
Loading…
x
Reference in New Issue
Block a user