From 12b561c0bfb5b4a738edbd8885200ee3ee56a7e7 Mon Sep 17 00:00:00 2001 From: pvizeli Date: Tue, 21 Mar 2017 15:13:28 +0100 Subject: [PATCH] Allow resinhup autoupdate --- build-scripts/README.md | 5 ++ build-scripts/resinos-build/create_resinos.sh | 7 +-- .../resin-vars/resin-vars/resin-vars | 3 ++ .../resinhup/resinhup.bbappend | 5 ++ .../resinhup/resinhup/hassio.conf | 1 + .../resinhup/resinhup/run-resinhup.sh | 49 ++++++++++++------- 6 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 meta-hassio/recipes-support/resinhup/resinhup/hassio.conf diff --git a/build-scripts/README.md b/build-scripts/README.md index 21c7d9969..bc4ead5eb 100644 --- a/build-scripts/README.md +++ b/build-scripts/README.md @@ -8,6 +8,11 @@ Builds are published on: https://hub.docker.com/r/pvizeli/ - yocto-build-env: Allow us to build yocto resinos images - docker-build-env: Allow us to build docker image for all archs +- resinhup-build: Create docker image for inplace update perform +- resinos-build: Create image for SD and docker for inplace update +- hassio-supervisor: Create our supervisor update +- homeassistant: Create docker image with homeassistant + ## Create a server diff --git a/build-scripts/resinos-build/create_resinos.sh b/build-scripts/resinos-build/create_resinos.sh index 1c2607e2d..1d091c5ec 100755 --- a/build-scripts/resinos-build/create_resinos.sh +++ b/build-scripts/resinos-build/create_resinos.sh @@ -20,8 +20,8 @@ cleanup() { trap 'cleanup fail' SIGINT SIGTERM # Sanity checks -if [ "$#" -ne 2 ]; then - echo "Usage: create_resinos.sh " +if [ "$#" -ne 3 ]; then + echo "Usage: create_resinos.sh " echo "Optional environment: BUILD_DIR, PERSISTENT_WORKDIR, RESIN_BRANCH, HASSIO_ROOT" exit 1 fi @@ -33,6 +33,7 @@ popd > /dev/null 2>&1 MACHINE=$1 SUPERVISOR_TAG=$2 +HASSIO_VERSION=$3 PERSISTENT_WORKDIR=${PERSISTENT_WORKDIR:=~/yocto} BUILD_DIR=${BUILD_DIR:=$SCRIPTPATH} WORKSPACE=${BUILD_DIR:=$SCRIPTPATH}/resin-board @@ -68,7 +69,7 @@ echo "[INFO] Inject HassIO yocto layer" cp -fr $HASSIO_ROOT/meta-hassio $WORKSPACE/layers/ # Additional variables -BARYS_ARGUMENTS_VAR="-a HASSIO_SUPERVISOR_TAG=$SUPERVISOR_TAG -a HOMEASSISTANT_REPOSITORY=$HOMEASSISTANT_REPOSITORY" +BARYS_ARGUMENTS_VAR="-a HASSIO_SUPERVISOR_TAG=$SUPERVISOR_TAG -a HOMEASSISTANT_REPOSITORY=$HOMEASSISTANT_REPOSITORY -a HASSIO_VERSION=$HASSIO_VERSION" # Make sure shared directories are in place mkdir -p $DOWNLOAD_DIR diff --git a/meta-hassio/recipes-support/resin-vars/resin-vars/resin-vars b/meta-hassio/recipes-support/resin-vars/resin-vars/resin-vars index eae6a2303..5dd52c8a0 100644 --- a/meta-hassio/recipes-support/resin-vars/resin-vars/resin-vars +++ b/meta-hassio/recipes-support/resin-vars/resin-vars/resin-vars @@ -45,6 +45,9 @@ fi # Resin supervisor variables source /etc/resin-supervisor/supervisor.conf +# ResinOS variables +source /etc/hassio.conf + # If config.json provides redefinitions for our vars let us rewrite their # runtime value if [ -f $CONFIG_PATH ] diff --git a/meta-hassio/recipes-support/resinhup/resinhup.bbappend b/meta-hassio/recipes-support/resinhup/resinhup.bbappend index 02a00ae4a..156fa922a 100644 --- a/meta-hassio/recipes-support/resinhup/resinhup.bbappend +++ b/meta-hassio/recipes-support/resinhup/resinhup.bbappend @@ -2,6 +2,7 @@ FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" SRC_URI += " \ + file://hassio.conf \ file://resinhup.sh \ file://resinhup.service \ " @@ -16,9 +17,13 @@ SYSTEMD_AUTO_ENABLE = "enable" FILES_${PN} += " \ ${systemd_unitdir} \ ${bindir} \ + ${sysconfdir} \ " do_install_append() { + install -m 0755 ${WORKDIR}/hassio.conf ${D}${sysconfdir} + sed -i -e 's:@HASSIO_VERSION@:${HASSIO_VERSION}:g' ${D}${sysconfdir}/hassio.conf + if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then install -d ${D}${systemd_unitdir}/system install -c -m 0644 ${WORKDIR}/resinhup.service ${D}${systemd_unitdir}/system diff --git a/meta-hassio/recipes-support/resinhup/resinhup/hassio.conf b/meta-hassio/recipes-support/resinhup/resinhup/hassio.conf new file mode 100644 index 000000000..c811787dc --- /dev/null +++ b/meta-hassio/recipes-support/resinhup/resinhup/hassio.conf @@ -0,0 +1 @@ +HASSIO_VERSION=%HASSIO_VERSION% diff --git a/meta-hassio/recipes-support/resinhup/resinhup/run-resinhup.sh b/meta-hassio/recipes-support/resinhup/resinhup/run-resinhup.sh index d66feb584..7e4cd4505 100644 --- a/meta-hassio/recipes-support/resinhup/resinhup/run-resinhup.sh +++ b/meta-hassio/recipes-support/resinhup/resinhup/run-resinhup.sh @@ -11,6 +11,9 @@ DOCKER_REPO=pvizeli # Don't run anything before this source as it sets PATH here source /etc/profile +# load config +source /usr/sbin/resin-vars + # Help function function help { cat << EOF @@ -139,11 +142,11 @@ while [[ $# > 0 ]]; do help exit 0 ;; - -t|--tag) + -t|--resinhup-version) if [ -z "$2" ]; then log ERROR "\"$1\" argument needs a value." fi - TAG=$2 + RESINHUP_VERSION=$2 shift ;; --hostos-version) @@ -192,7 +195,19 @@ done # Check that HostOS version was provided if [ -z "$HOSTOS_VERSION" ]; then - log ERROR "--hostos-version is required." + if version=$(curl $ENDPOINT | jq -e -r '.hassio_version') + HOSTOS_VERSION=version + else + log ERROR "--hostos-version is required." + fi +fi + +if [ -z $RESINHUP_VERSION ]; then + if version=$(curl $ENDPOINT | jq -e -r '.resinhub_version') + HOSTOS_VERSION=version + else + log ERROR "--hostos-version is required." + fi fi # Init log file @@ -202,6 +217,12 @@ if [ "$LOG" == "yes" ]; then date >> $LOGFILE fi +# Check if update is needed +if [ $HASSIO_VERSION == $HOSTOS_VERSION ]; then + log "Version $HOSTOS_VERSION is already installed." + exit 0 +fi + # Detect DATA_MOUNTPOINT if [ -d /mnt/data ]; then DATA_MOUNTPOINT=/mnt/data @@ -215,20 +236,10 @@ fi runPreHacks # Detect arch -source /etc/resin-supervisor/supervisor.conf -arch=$MACHINE -if [ -z "$arch" ]; then - log ERROR "Can't detect arch from /etc/resin-supervisor/supervisor.conf ." +if [ -z "$MACHINE" ]; then + log ERROR "Can't detect machine from resin-vars ." else - log "Detected arch: $arch ." -fi - -# Detect slug -slug=$MACHINE -if [ -z $slug ]; then - log ERROR "Can't detect slug from /etc/resin-supervisor/supervisor.conf ." -else - log "Detected slug: $slug ." + log "Detected arch: $MACHINE ." fi # We need to stop update-resin-supervisor.timer otherwise it might restart supervisor which @@ -274,10 +285,10 @@ docker rm $(docker ps -a -q) > /dev/null 2>&1 # Pull resinhup and tag it accordingly log "Pulling resinhup..." -docker pull $DOCKER_REPO/resinhup-$slug:$TAG +docker pull $DOCKER_REPO/resinhup:$MACHINE-$RESINHUP_VERSION if [ $? -ne 0 ]; then tryup - log ERROR "Could not pull $DOCKER_REPO/resinhup-$slug:$TAG ." + log ERROR "Could not pull $DOCKER_REPO/resinhup:$MACHINE-$RESINHUP_VERSION ." fi # Run resinhup @@ -291,7 +302,7 @@ docker run --privileged --rm --net=host $RESINHUP_ENV \ -v /:/host \ -v /lib/modules:/lib/modules:ro \ -v /var/run/docker.sock:/var/run/docker.sock \ - $DOCKER_REPO/resinhup-$slug:$TAG + $DOCKER_REPO/resinhup:$MACHINE-$RESINHUP_VERSION RESINHUP_EXIT=$? # RESINHUP_EXIT # 0 - update done