Split build stuff to new repo

This commit is contained in:
pvizeli 2017-04-06 11:52:28 +02:00
parent 4399888ce7
commit 2f47f9aa9b
64 changed files with 0 additions and 1638 deletions

View File

@ -1,35 +0,0 @@
# Build Server
You need a linux with [AUFS](https://docs.docker.com/engine/userguide/storagedriver/aufs-driver/) and docker support. You need to have the build user in docker group for he can run docker. It is not possible to run this process as root! You need also install `jq`
Builds are published on: https://hub.docker.com/r/pvizeli/
## Build env
- 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
First install ubuntu server 16.04.
Follow install instruction from docker to install it:
https://docs.docker.com/engine/installation/linux/ubuntu/
After that move the `builder` user into docker group.
```
sudo groupadd docker
sudo gpasswd -a ${USER} docker
sudo service docker restart
newgrp docker
```
Other software:
```
sudo apt-get install jq pigz
```

View File

@ -1,29 +0,0 @@
FROM ubuntu:16.04
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
# Install docker
# https://docs.docker.com/engine/installation/linux/ubuntu/#install-using-the-repository
RUN apt-get update && apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common \
&& rm -rf /var/lib/apt/lists/*
VOLUME /var/lib/docker
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
RUN apt-get update && apt-get install -y \
docker-ce \
&& rm -rf /var/lib/apt/lists/*
# setup arm binary support
RUN apt-get update && apt-get install -y \
qemu-user-static \
binfmt-support \
&& rm -rf /var/lib/apt/lists/*
COPY run-docker.sh /
WORKDIR /docker

View File

@ -1,31 +0,0 @@
#!/bin/bash
set -ev
DOCKER_REPO=pvizeli
DOCKER_IMAGE=docker-build-env
# Get the absolute script location
pushd `dirname $0` > /dev/null 2>&1
SCRIPTPATH=`pwd`
popd > /dev/null 2>&1
# Sanity checks
if [ "$#" -ne 1 ]; then
echo "Usage: create_build_env.sh [<TAG> | NONE]"
exit 1
fi
DOCKER_TAG=$1
# Build
docker build --pull --tag ${DOCKER_REPO}/${DOCKER_IMAGE}:${DOCKER_TAG} -f ${SCRIPTPATH}/Dockerfile ${SCRIPTPATH}
# Tag
docker tag ${DOCKER_REPO}/${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_REPO}/${DOCKER_IMAGE}:latest
if [ ${DOCKER_TAG} != "NONE" ]; then
# push
docker push ${DOCKER_REPO}/${DOCKER_IMAGE}:${DOCKER_TAG}
docker push ${DOCKER_REPO}/${DOCKER_IMAGE}:latest
fi

View File

@ -1,76 +0,0 @@
#!/bin/bash
set -e
DOCKER_TIMEOUT=20 # Wait 20 seconds for docker to start
cleanup() {
echo "[INFO] Running cleanup..."
# Stop docker gracefully
echo "[INFO] Stopping in container docker..."
DOCKERPIDFILE=/var/run/docker.pid
if [ -f $DOCKERPIDFILE ] && [ -s $DOCKERPIDFILE ] && ps $(cat $DOCKERPIDFILE) | grep -q docker; then
kill $(cat $DOCKERPIDFILE)
# Now wait for it to die
STARTTIME=$(date +%s)
ENDTIME=$(date +%s)
while [ -f $DOCKERPIDFILE ] && [ -s $DOCKERPIDFILE ] && ps $(cat $DOCKERPIDFILE) | grep -q docker; do
if [ $(($ENDTIME - $STARTTIME)) -le $DOCKER_TIMEOUT ]; then
sleep 1
ENDTIME=$(date +%s)
else
echo "[ERROR] Timeout while waiting for in container docker to die."
exit 1
fi
done
else
echo "[WARN] Can't stop docker container."
echo "[WARN] Your host might have been left with unreleased resources (ex. loop devices)."
fi
if [ "$1" == "fail" ]; then
exit 1
fi
}
trap 'cleanup fail' SIGINT SIGTERM
# Start docker
echo "[INFO] Setup qemu-arm."
mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
update-binfmts --enable qemu-arm
update-binfmts --enable qemu-aarch64
# Start docker
echo "[INFO] Starting docker."
dockerd 2> /dev/null &
echo "[INFO] Waiting for docker to initialize..."
STARTTIME=$(date +%s)
ENDTIME=$(date +%s)
until docker info >/dev/null 2>&1; do
if [ $(($ENDTIME - $STARTTIME)) -le $DOCKER_TIMEOUT ]; then
sleep 1
ENDTIME=$(date +%s)
else
echo "[ERROR] Timeout while waiting for docker to come up."
exit 1
fi
done
echo "[INFO] Docker was initialized."
# Start barys with all the arguments requested
echo "[INFO] Running build..."
# Build
docker build --pull --tag ${DOCKER_REPO}/${DOCKER_IMAGE}:${DOCKER_TAG} .
# Tag
docker tag ${DOCKER_REPO}/${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_REPO}/${DOCKER_IMAGE}:latest
echo "[INFO] Push image"
if [ ${DOCKER_TAG} != "NONE" ]; then
# push
docker push ${DOCKER_REPO}/${DOCKER_IMAGE}:${DOCKER_TAG}
docker push ${DOCKER_REPO}/${DOCKER_IMAGE}:latest
fi
cleanup
exit 0

View File

@ -1,15 +0,0 @@
#!/bin/bash
set -e
# Sanity checks
if [ "$#" -ne 1 ]; then
echo "Usage: create_all.sh <TAG>|NONE"
echo "Optional environment: BUILD_DIR"
exit 1
fi
for arch in "armhf" "aarch64" "i386" "amd64"
do
./create_hassio_supervisor.sh $arch $1
done

View File

@ -1,76 +0,0 @@
#!/bin/bash
set -e
BUILD_CONTAINER_NAME=hassio-build-$$
DOCKER_REPO=pvizeli
cleanup() {
echo "[INFO] Cleanup."
# Stop docker container
echo "[INFO] Cleaning up hassio-build container."
docker stop $BUILD_CONTAINER_NAME 2> /dev/null || true
docker rm --volumes $BUILD_CONTAINER_NAME 2> /dev/null || true
if [ "$1" == "fail" ]; then
exit 1
fi
}
trap 'cleanup fail' SIGINT SIGTERM
# Sanity checks
if [ "$#" -ne 2 ]; then
echo "Usage: create_hassio_supervisor.sh <ARCH> <TAG>|NONE"
echo "Optional environment: BUILD_DIR"
exit 1
fi
if [ $1 != 'armhf' ] && [ $1 != 'aarch64' ] && [ $1 != 'i386' ] && [ $1 != 'amd64' ]; then
echo "Error: $1 is not a supported platform for hassio-supervisor!"
exit 1
fi
# Get the absolute script location
pushd `dirname $0` > /dev/null 2>&1
SCRIPTPATH=`pwd`
popd > /dev/null 2>&1
ARCH=$1
BASE_IMAGE="resin\/${ARCH}-alpine:3.5"
DOCKER_TAG=$2
DOCKER_IMAGE=${ARCH}-hassio-supervisor
BUILD_DIR=${BUILD_DIR:=$SCRIPTPATH}
WORKSPACE=${BUILD_DIR:=$SCRIPTPATH}/hassio-supervisor
# setup docker
echo "[INFO] Setup docker for supervisor"
mkdir -p $BUILD_DIR
mkdir -p $WORKSPACE
cp ../../supervisor/Dockerfile $WORKSPACE/Dockerfile
sed -i "s/%%BASE_IMAGE%%/${BASE_IMAGE}/g" $WORKSPACE/Dockerfile
sed -i "s/%%SUPERVISOR_TAG%%/${DOCKER_TAG}/g" $WORKSPACE/Dockerfile
cp -r ../../hassio_api $WORKSPACE/
# Run build
echo "[INFO] start docker build"
docker stop $BUILD_CONTAINER_NAME 2> /dev/null || true
docker rm --volumes $BUILD_CONTAINER_NAME 2> /dev/null || true
docker run --rm \
-v $WORKSPACE:/docker \
-v ~/.docker:/root/.docker \
-e DOCKER_REPO=$DOCKER_REPO \
-e DOCKER_IMAGE=$DOCKER_IMAGE \
-e DOCKER_TAG=$DOCKER_TAG \
--name $BUILD_CONTAINER_NAME \
--privileged \
pvizeli/docker-build-env \
/run-docker.sh
echo "[INFO] cleanup WORKSPACE"
cd $BUILD_DIR
rm -rf $WORKSPACE
cleanup
exit 0

View File

@ -1,79 +0,0 @@
#!/bin/bash
set -e
BUILD_CONTAINER_NAME=homeassistant-build-$$
DOCKER_REPO=pvizeli
cleanup() {
echo "[INFO] Cleanup."
# Stop docker container
echo "[INFO] Cleaning up homeassistant-build container."
docker stop $BUILD_CONTAINER_NAME 2> /dev/null || true
docker rm --volumes $BUILD_CONTAINER_NAME 2> /dev/null || true
if [ "$1" == "fail" ]; then
exit 1
fi
}
trap 'cleanup fail' SIGINT SIGTERM
# Sanity checks
if [ "$#" -ne 2 ]; then
echo "Usage: create_homeassistant.sh <HASS_VERS> <MACHINE>"
echo "Optional environment: BUILD_DIR"
exit 1
fi
# Get the absolute script location
pushd `dirname $0` > /dev/null 2>&1
SCRIPTPATH=`pwd`
popd > /dev/null 2>&1
HASS_VERS=$1
MACHINE=$2
BASE_IMAGE="resin\/${MACHINE}-alpine-python:3.6"
DOCKER_TAG=$1
DOCKER_IMAGE=${MACHINE}-homeassistant
BUILD_DIR=${BUILD_DIR:=$SCRIPTPATH}
WORKSPACE=${BUILD_DIR}/hass
HASS_GIT=${BUILD_DIR}/hass_git
# setup docker
echo "[INFO] Setup docker for homeassistant"
mkdir -p $BUILD_DIR
mkdir -p $WORKSPACE
echo "[INFO] load homeassistant"
cp ../../homeassistant/Dockerfile $WORKSPACE/Dockerfile
sed -i "s/%%BASE_IMAGE%%/${BASE_IMAGE}/g" $WORKSPACE/Dockerfile
sed -i "s/%%HASS_VERSION%%/${HASS_VERS}/g" $WORKSPACE/Dockerfile
git https://github.com/home-assistant/home-assistant $HASS_GIT
cd $HASS_GIT && git checkout $HASS_VERS
cp $HASS_GIT/requirements.txt $WORKSPACE/
# Run build
echo "[INFO] start docker build"
docker stop $BUILD_CONTAINER_NAME 2> /dev/null || true
docker rm --volumes $BUILD_CONTAINER_NAME 2> /dev/null || true
docker run --rm \
-v $WORKSPACE:/docker \
-v ~/.docker:/root/.docker \
-e DOCKER_REPO=$DOCKER_REPO \
-e DOCKER_IMAGE=$DOCKER_IMAGE \
-e DOCKER_TAG=$DOCKER_TAG \
--name $BUILD_CONTAINER_NAME \
--privileged \
pvizeli/docker-build-env \
/run-docker.sh
echo "[INFO] cleanup WORKSPACE"
cd $BUILD_DIR
rm -rf $WORKSPACE
rm -rf $HASS_GIT
cleanup
exit 0

View File

@ -1,86 +0,0 @@
#!/bin/bash
set -e
BUILD_CONTAINER_NAME=resinhup-build-$$
DOCKER_REPO=pvizeli
cleanup() {
echo "[INFO] Cleanup."
# Stop docker container
echo "[INFO] Cleaning up homeassistant-build container."
docker stop $BUILD_CONTAINER_NAME 2> /dev/null || true
docker rm --volumes $BUILD_CONTAINER_NAME 2> /dev/null || true
if [ "$1" == "fail" ]; then
exit 1
fi
}
trap 'cleanup fail' SIGINT SIGTERM
# Sanity checks
if [ "$#" -ne 2 ]; then
echo "Usage: create_resinhup.sh <VERS> <MACHINE>"
echo "Optional environment: BUILD_DIR"
exit 1
fi
# Get the absolute script location
pushd `dirname $0` > /dev/null 2>&1
SCRIPTPATH=`pwd`
popd > /dev/null 2>&1
MACHINE=$2
RESINHUP_VER=$1
BASE_IMAGE="resin\/${MACHINE}-python:3.6"
DOCKER_TAG=${MACHINE}-${RESINHUP_VER}
DOCKER_IMAGE=resinhup
BUILD_DIR=${BUILD_DIR:=$SCRIPTPATH}
WORKSPACE=${BUILD_DIR:=$SCRIPTPATH}/resinhup
# evaluate git repo and arch
case $MACHINE in
"raspberrypi3")
DOCKER_FILE_NAME="Dockerfile.raspberrypi3"
;;
"raspberrypi2")
DOCKER_FILE_NAME="Dockerfile.raspberryp-pi2"
;;
"raspberrypi")
DOCKER_FILE_NAME="Dockerfile.raspberry-pi"
;;
*)
echo "[ERROR] ${MACHINE} unknown!"
exit 1
;;
esac
# setup docker
echo "[INFO] Setup workspace"
mkdir -p $BUILD_DIR
git clone https://github.com/pvizeli/resinhup $WORKSPACE
cd $WORKSPACE && cp $DOCKER_FILE_NAME Dockerfile
# Run build
echo "[INFO] start docker build"
docker stop $BUILD_CONTAINER_NAME 2> /dev/null || true
docker rm --volumes $BUILD_CONTAINER_NAME 2> /dev/null || true
docker run --rm \
-v $WORKSPACE:/docker \
-v ~/.docker:/root/.docker \
-e DOCKER_REPO=$DOCKER_REPO \
-e DOCKER_IMAGE=$DOCKER_IMAGE \
-e DOCKER_TAG=$DOCKER_TAG \
--name $BUILD_CONTAINER_NAME \
--privileged \
pvizeli/docker-build-env \
/run-docker.sh
echo "[INFO] cleanup WORKSPACE"
cd $BUILD_DIR
rm -rf $WORKSPACE
cleanup
exit 0

View File

@ -1,5 +0,0 @@
## Possible problems
### Boost
Some times it can fail on boost build. In this case you need run `bitbake boost` inside build env. After that it work

View File

@ -1,148 +0,0 @@
#!/bin/bash
set -e
BUILD_CONTAINER_NAME=yocto-build-$$
DOCKER_REPO=pvizeli
cleanup() {
echo "[INFO] Cleanup."
# Stop docker container
echo "[INFO] Cleaning up yocto-build container."
docker stop $BUILD_CONTAINER_NAME 2> /dev/null || true
docker rm --volumes $BUILD_CONTAINER_NAME 2> /dev/null || true
if [ "$1" == "fail" ]; then
exit 1
fi
}
trap 'cleanup fail' SIGINT SIGTERM
# Sanity checks
if [ "$#" -ne 3 ]; then
echo "Usage: create_resinos.sh <MACHINE> <HASSIO_VERSION> <RESINOS_HASSIO_VERSION>"
echo "Optional environment: BUILD_DIR, PERSISTENT_WORKDIR, RESIN_BRANCH, HASSIO_ROOT"
exit 1
fi
# Get the absolute script location
pushd `dirname $0` > /dev/null 2>&1
SCRIPTPATH=`pwd`
popd > /dev/null 2>&1
MACHINE=$1
HASSIO_VERSION=$2
RESINOS_HASSIO_VERSION=$3
PERSISTENT_WORKDIR=${PERSISTENT_WORKDIR:=~/yocto}
BUILD_DIR=${BUILD_DIR:=$SCRIPTPATH}
WORKSPACE=${BUILD_DIR:=$SCRIPTPATH}/resin-board
HASSIO_ROOT=${HASSIO_ROOT:=$SCRIPTPATH/../..}
DOWNLOAD_DIR=$PERSISTENT_WORKDIR/shared-downloads
SSTATE_DIR=$PERSISTENT_WORKDIR/$MACHINE/sstate
RESIN_BRANCH=${RESIN_BRANCH:=master}
# evaluate git repo and arch
case $MACHINE in
"raspberrypi" | "raspberrypi2" | "raspberrypi3")
ARCH="armhf"
RESIN_REPO="https://github.com/resin-os/resin-raspberrypi"
HOMEASSISTANT_REPOSITORY="$DOCKER_REPO/$MACHINE-homeassistant"
;;
*)
echo "[ERROR] ${MACHINE} unknown!"
exit 1
;;
esac
echo "[INFO] Checkout repository"
if [ ! -d $WORKSPACE ]; then
mkdir -p $BUILD_DIR
cd $BUILD_DIR && git clone $RESIN_REPO resin-board
if [ $RESIN_BRANCH != "master" ]; then
cd $WORKSPACE && git checkout $RESIN_BRANCH
fi
cd $WORKSPACE && git submodule update --init --recursive
fi
echo "[INFO] Inject HassIO yocto layer"
cp -fr $HASSIO_ROOT/meta-hassio $WORKSPACE/layers/
if [ ! -d $WORKSPACE/build/conf ]; then
sed -i 's%${TOPDIR}/../layers/meta-resin/meta-resin-common \\%${TOPDIR}/../layers/meta-resin/meta-resin-common \\\n${TOPDIR}/../layers/meta-hassio \\%g' $WORKSPACE/layers/*/conf/samples/bblayers.conf.sample
fi
# Additional variables
BARYS_ARGUMENTS_VAR="-a HASSIO_SUPERVISOR_TAG=$HASSIO_VERSION -a HOMEASSISTANT_REPOSITORY=$HOMEASSISTANT_REPOSITORY -a RESINOS_HASSIO_VERSION=$RESINOS_HASSIO_VERSION"
# Make sure shared directories are in place
mkdir -p $DOWNLOAD_DIR
mkdir -p $SSTATE_DIR
# Run build
echo "[INFO] Init docker build."
docker stop $BUILD_CONTAINER_NAME 2> /dev/null || true
docker rm --volumes $BUILD_CONTAINER_NAME 2> /dev/null || true
docker run --rm \
-v $WORKSPACE:/yocto/resin-board \
-v $DOWNLOAD_DIR:/yocto/shared-downloads \
-v $SSTATE_DIR:/yocto/shared-sstate \
-e BUILDER_UID=$(id -u) \
-e BUILDER_GID=$(id -g) \
--name $BUILD_CONTAINER_NAME \
--privileged \
pvizeli/yocto-build-env \
/run-resinos.sh \
--log \
--machine "$MACHINE" \
${BARYS_ARGUMENTS_VAR} \
--shared-downloads /yocto/shared-downloads \
--shared-sstate /yocto/shared-sstate \
--resinio
# Write deploy artifacts
BUILD_DEPLOY_DIR=$WORKSPACE/deploy
DEVICE_TYPE_JSON=$WORKSPACE/$MACHINE.json
VERSION_HOSTOS=$(cat $WORKSPACE/build/tmp/deploy/images/$MACHINE/VERSION_HOSTOS)
DEPLOY_ARTIFACT=$(jq --raw-output '.yocto.deployArtifact' $DEVICE_TYPE_JSON)
COMPRESSED=$(jq --raw-output '.yocto.compressed' $DEVICE_TYPE_JSON)
ARCHIVE=$(jq --raw-output '.yocto.archive' $DEVICE_TYPE_JSON)
mkdir -p $BUILD_DEPLOY_DIR
rm -rf $BUILD_DEPLOY_DIR/* # do we have anything there?
cp $(readlink --canonicalize $WORKSPACE/build/tmp/deploy/images/$MACHINE/$DEPLOY_ARTIFACT) $BUILD_DEPLOY_DIR/$DEPLOY_ARTIFACT
if [ "${COMPRESSED}" == 'true' ]; then
if [ "${ARCHIVE}" == 'true' ]; then
(cd $BUILD_DEPLOY_DIR && tar --remove-files --use-compress-program pigz --directory=$DEPLOY_ARTIFACT -cvf ${DEPLOY_ARTIFACT}.tar.gz .)
else
mv $BUILD_DEPLOY_DIR/$DEPLOY_ARTIFACT $BUILD_DEPLOY_DIR/resin.img
(cd $BUILD_DEPLOY_DIR && tar --remove-files --use-compress-program pigz -cvf resin.img.tar.gz resin.img)
fi
fi
if [ -f $(readlink --canonicalize $WORKSPACE/build/tmp/deploy/images/$MACHINE/resin-image-$MACHINE.resinhup-tar) ]; then
mv -v $(readlink --canonicalize $WORKSPACE/build/tmp/deploy/images/$MACHINE/resin-image-$MACHINE.resinhup-tar) $BUILD_DEPLOY_DIR/resinhup-$VERSION_HOSTOS.tar
else
echo "WARNING: No resinhup package found."
fi
cp $WORKSPACE/build/tmp/deploy/images/$MACHINE/VERSION $BUILD_DEPLOY_DIR || true
cp $WORKSPACE/build/tmp/deploy/images/$MACHINE/VERSION_HOSTOS $BUILD_DEPLOY_DIR || true
cp $DEVICE_TYPE_JSON $BUILD_DEPLOY_DIR/device-type.json
# move to deploy directory the kernel modules headers so we have it as a build artifact in jenkins
cp $WORKSPACE/build/tmp/deploy/images/$MACHINE/kernel_modules_headers.tar.gz $BUILD_DEPLOY_DIR || true
echo "INFO: Pushing resinhup package to dockerhub"
DOCKER_IMAGE="$DOCKER_REPO/resinos-hassio"
DOCKER_TAG="$RESINOS_HASSIO_VERSION-$MACHINE"
if [ -f $BUILD_DEPLOY_DIR/resinhup-$VERSION_HOSTOS.tar ]; then
docker import $BUILD_DEPLOY_DIR/resinhup-$VERSION_HOSTOS.tar $DOCKER_IMAGE:$DOCKER_TAG
docker push $DOCKER_IMAGE:$DOCKER_TAG
docker rmi $DOCKER_IMAGE:$DOCKER_TAG # cleanup
else
echo "ERROR: The build didn't produce a resinhup package."
exit 1
fi
# Cleanup the build directory
# Keep this after writing all artifacts
exit 0
rm -rf $WORKSPACE/build

View File

@ -1,58 +0,0 @@
FROM ubuntu:16.04
# Install the following utilities (required by poky)
RUN apt-get update && apt-get install -y \
build-essential \
chrpath \
curl \
diffstat \
gcc-multilib \
gawk \
git-core \
libsdl1.2-dev \
texinfo \
unzip \
wget \
xterm \
cpio \
file \
python3 \
&& rm -rf /var/lib/apt/lists/*
# Set the locale to UTF-8 for bulding with poky morty
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
# Additional host packages required by resin
RUN apt-get update && apt-get install -y \
apt-transport-https \
&& rm -rf /var/lib/apt/lists/*
RUN curl --silent https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
ENV NODE_VERSION node_4.x
ENV DISTRO vivid
RUN echo "deb https://deb.nodesource.com/$NODE_VERSION $DISTRO main" | tee /etc/apt/sources.list.d/nodesource.list &&\
echo "deb-src https://deb.nodesource.com/$NODE_VERSION $DISTRO main" | tee -a /etc/apt/sources.list.d/nodesource.list
RUN apt-get update && apt-get install -y \
jq \
nodejs \
sudo \
&& rm -rf /var/lib/apt/lists/*
# Install docker
# https://docs.docker.com/engine/installation/linux/ubuntu/#install-using-the-repository
RUN apt-get update && apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common \
&& rm -rf /var/lib/apt/lists/*
VOLUME /var/lib/docker
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
RUN apt-get update && apt-get install -y \
docker-ce \
&& rm -rf /var/lib/apt/lists/*
COPY run-resinos.sh /
WORKDIR /yocto/resin-board

View File

@ -1,31 +0,0 @@
#!/bin/bash
set -ev
DOCKER_REPO=pvizeli
DOCKER_IMAGE=yocto-build-env
# Get the absolute script location
pushd `dirname $0` > /dev/null 2>&1
SCRIPTPATH=`pwd`
popd > /dev/null 2>&1
# Sanity checks
if [ "$#" -ne 1 ]; then
echo "Usage: create_build_env.sh [<TAG> | NONE]"
exit 1
fi
DOCKER_TAG=$1
# Build
docker build --pull --tag ${DOCKER_REPO}/${DOCKER_IMAGE}:${DOCKER_TAG} -f ${SCRIPTPATH}/Dockerfile ${SCRIPTPATH}
# Tag
docker tag ${DOCKER_REPO}/${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_REPO}/${DOCKER_IMAGE}:latest
if [ ${DOCKER_TAG} != "NONE" ]; then
# push
docker push ${DOCKER_REPO}/${DOCKER_IMAGE}:${DOCKER_TAG}
docker push ${DOCKER_REPO}/${DOCKER_IMAGE}:latest
fi

View File

@ -1,68 +0,0 @@
#!/bin/bash
set -e
DOCKER_TIMEOUT=20 # Wait 20 seconds for docker to start
cleanup() {
echo "[INFO] Running cleanup..."
# Stop docker gracefully
echo "[INFO] Stopping in container docker..."
DOCKERPIDFILE=/var/run/docker.pid
if [ -f $DOCKERPIDFILE ] && [ -s $DOCKERPIDFILE ] && ps $(cat $DOCKERPIDFILE) | grep -q docker; then
kill $(cat $DOCKERPIDFILE)
# Now wait for it to die
STARTTIME=$(date +%s)
ENDTIME=$(date +%s)
while [ -f $DOCKERPIDFILE ] && [ -s $DOCKERPIDFILE ] && ps $(cat $DOCKERPIDFILE) | grep -q docker; do
if [ $(($ENDTIME - $STARTTIME)) -le $DOCKER_TIMEOUT ]; then
sleep 1
ENDTIME=$(date +%s)
else
echo "[ERROR] Timeout while waiting for in container docker to die."
exit 1
fi
done
else
echo "[WARN] Can't stop docker container."
echo "[WARN] Your host might have been left with unreleased resources (ex. loop devices)."
fi
if [ "$1" == "fail" ]; then
exit 1
fi
}
trap 'cleanup fail' SIGINT SIGTERM
# Create the normal user to be used for bitbake (barys)
echo "[INFO] Creating and setting builder user $BUILDER_UID:$BUILDER_GID."
groupadd -g $BUILDER_GID builder
groupadd docker || true
useradd -m -u $BUILDER_UID -g $BUILDER_GID -G docker builder
# Start docker
echo "[INFO] Starting docker."
dockerd 2> /dev/null &
echo "[INFO] Waiting for docker to initialize..."
STARTTIME=$(date +%s)
ENDTIME=$(date +%s)
until docker info >/dev/null 2>&1; do
if [ $(($ENDTIME - $STARTTIME)) -le $DOCKER_TIMEOUT ]; then
sleep 1
ENDTIME=$(date +%s)
else
echo "[ERROR] Timeout while waiting for docker to come up."
exit 1
fi
done
echo "[INFO] Docker was initialized."
# Start barys with all the arguments requested
echo "[INFO] Running build as builder user..."
sudo -H -u builder /yocto/resin-board/resin-yocto-scripts/build/barys $@ &
barys_pid=$!
wait $barys_pid || true
cleanup
exit 0

Binary file not shown.

View File

@ -1,34 +0,0 @@
FROM %%BASE_IMAGE%%
# Add version
ENV VERSION %%HASS_VERSION%%
ENV LANG C.UTF-8
# install core packages
RUN apk --no-cache add libuv git linux-headers eudev-dev libusb-dev
# install component packages
RUN apk --no-cache add ffmpeg nmap net-tools
##
# install zwave
WORKDIR /usr/src/
RUN pip3 install --no-cache-dir cython==0.25.2
RUN git clone https://github.com/OpenZWave/python-openzwave \
&& cd python-openzwave \
&& git checkout v0.3.2 \
&& make build \
&& make install \
&& mkdir -p /usr/local/share/python-openzwave \
&& cp -R openzwave/config /usr/local/share/python-openzwave/config \
&& rm -rf /usr/src/python-openzwave
##
# install pip module for components
# install home-assistant
RUN pip3 install --no-cache-dir uvloop homeassistant==%%HASS_VERSION%%
# Run hass
CMD [ "python", "-m", "homeassistant", "--config", "/config" ]

View File

@ -1,10 +0,0 @@
BBPATH .= ":${LAYERDIR}"
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
${LAYERDIR}/recipes-*/*/*.bbappend"
BBFILE_COLLECTIONS += "hassio"
BBFILE_PATTERN_hassio = "^${LAYERDIR}/"
LAYERVERSION_hassio = "1"
LAYERDEPENDS_hassio = "resin-common"

View File

@ -1,23 +0,0 @@
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SUPERVISOR_REPOSITORY_armv5 = "pvizeli/armhf-hassio-supervisor"
SUPERVISOR_REPOSITORY_armv6 = "pvizeli/armhf-hassio-supervisor"
SUPERVISOR_REPOSITORY_armv7a = "pvizeli/armhf-hassio-supervisor"
SUPERVISOR_REPOSITORY_armv7ve = "pvizeli/armhf-hassio-supervisor"
SUPERVISOR_REPOSITORY_aarch64 = "pvizeli/aarch64-hassio-supervisor"
SUPERVISOR_REPOSITORY_x86 = "pvizeli/i386-hassio-supervisor"
SUPERVISOR_REPOSITORY_x86-64 = "pvizeli/amd64-hassio-supervisor"
SUPERVISOR_TAG = "${HASSIO_SUPERVISOR_TAG}"
TARGET_REPOSITORY = "${SUPERVISOR_REPOSITORY}"
TARGET_TAG = "${SUPERVISOR_TAG}"
SYSTEMD_AUTO_ENABLE = "enable"
do_install_append () {
install -d ${D}${sysconfdir}/resin-supervisor
sed -i -e 's:@HOMEASSISTANT_REPOSITORY@:${HOMEASSISTANT_REPOSITORY}:g' ${D}${sysconfdir}/resin-supervisor/supervisor.conf
sed -i -e 's:@MACHINE@:${MACHINE}:g' ${D}${sysconfdir}/resin-supervisor/supervisor.conf
sed -i -e 's:@RESINOS_HASSIO_VERSION@:${RESINOS_HASSIO_VERSION}:g' ${D}${sysconfdir}/resin-supervisor/supervisor.conf
}

View File

@ -1,22 +0,0 @@
#!/bin/sh -e
source /usr/sbin/resin-vars
source /etc/resin-supervisor/supervisor.conf
SUPERVISOR_IMAGE_ID=$(docker inspect --format='{{.Id}}' $SUPERVISOR_IMAGE)
SUPERVISOR_CONTAINER_IMAGE_ID=$(docker inspect --format='{{.Image}}' resin_supervisor || echo "")
runSupervisor() {
docker rm --force resin_supervisor || true
docker run --name resin_supervisor \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/run/hassio-hc.sock:/var/run/hassio-hc.sock \
-v /resin-data:/data \
-v /var/log/supervisor-log:/var/log \
-e SUPERVISOR_SHARE=/resin-data \
-e SUPERVISOR_NAME=resin_supervisor \
-e HOMEASSISTANT_REPOSITORY=${HOMEASSISTANT_REPOSITORY} \
${SUPERVISOR_IMAGE}
}
([ "$SUPERVISOR_IMAGE_ID" == "$SUPERVISOR_CONTAINER_IMAGE_ID" ] && docker start --attach resin_supervisor) || runSupervisor

View File

@ -1,6 +0,0 @@
SUPERVISOR_IMAGE=@SUPERVISOR_REPOSITORY@
SUPERVISOR_TAG=@SUPERVISOR_TAG@
LED_FILE=@LED_FILE@
MACHINE=@MACHINE@
HOMEASSISTANT_REPOSITORY=@HOMEASSISTANT_REPOSITORY@
RESINOS_HASSIO_VERSION=@RESINOS_HASSIO_VERSION@

View File

@ -1,128 +0,0 @@
#!/bin/bash
set -o pipefail
SUPERVISOR_CONFIG="/resin-data/config.json"
# Help function
function update-resin-supervisor-help {
cat << EOF
Wrapper to run supervisor agent updates on resin distributions.
$0 <OPTION>
Options:
-h, --help
Display this help and exit.
-i <SUPERVISOR IMAGE>, --supervisor-image <SUPERVISOR IMAGE>
Set supervisor image to update to.
-t <SUPERVISOR TAG>, --supervisor-tag <SUPERVISOR TAG>
Set supervisor tag to update to.
EOF
}
# Parse arguments
while [[ $# > 0 ]]; do
arg="$1"
case $arg in
-h|--help)
update-resin-supervisor-help
exit 0
;;
-i|--supervisor-image)
if [ -z "$2" ]; then
log ERROR "\"$1\" argument needs a value."
fi
UPDATER_SUPERVISOR_IMAGE=$2
shift
;;
-t|--supervisor-tag)
if [ -z "$2" ]; then
log ERROR "\"$1\" argument needs a value."
fi
UPDATER_SUPERVISOR_TAG=$2
shift
;;
*)
log ERROR "Unrecognized option $1."
;;
esac
shift
done
# Don't souce before parsing args - resin-vars parses args too
source /usr/sbin/resin-vars
source /etc/resin-supervisor/supervisor.conf
# A temporary file used until next reboot
UPDATECONF=/tmp/update-supervisor.conf
if [ -z "$ENDPOINT" -o -z "$CONFIG_PATH" ]; then
echo "Environment variables API_ENDPOINT and CONFIG_PATH must be set."
exit 1
fi
function error_handler {
# If docker pull fails, start the old supervisor again and exit
rm -rf $UPDATECONF
systemctl start resin-supervisor
exit 1
}
trap 'error_handler $LINENO' ERR
if [ -f $SUPERVISOR_CONFIG ]; then
tag=$(jq --raw-output ".hassio_current // empty" $SUPERVISOR_CONFIG)
image_name=$SUPERVISOR_IMAGE
fi
# override from params
if [ ! -z $UPDATER_SUPERVISOR_TAG ]; then
tag=$UPDATER_SUPERVISOR_TAG
fi
if [ ! -z $UPDATER_SUPERVISOR_IMAGE ]; then
image_name=$UPDATER_SUPERVISOR_IMAGE
fi
# Check that we didn't somehow get an empty tag version.
if [ -z $tag ] || [ -z $image_name ]; then
error_handler $LINENO "no tag received"
fi
# Get image id of tag. This will be non-empty only in case it's already downloaded.
echo "Getting image id..."
imageid=$(docker inspect -f '{{.Id}}' "$image_name:$tag") || imageid=""
if [ -n "$imageid" ]; then
echo "Supervisor $image_name:$tag already downloaded."
exit 0
fi
# Try to stop old supervisor to prevent it deleting the intermediate images while downloading the new one
echo "Stop supervisor..."
systemctl stop resin-supervisor
# Pull target version.
echo "Pulling supervisor $image_name:$tag..."
docker pull "$image_name:$tag"
docker rm --force resin_supervisor || true
# Store the tagged image string so resin-supervisor.service can pick it up
echo "SUPERVISOR_IMAGE=$image_name:$tag" > $UPDATECONF
# Run supervisor with the device-type-specific options.
# We give a specific name to the container to guarantee only one running.
echo "Start supervisor..."
systemctl start resin-supervisor
# Mark supervisor as working. This version will run when the device reboots.
echo "Mark pulled tag as latest..."
docker tag "$image_name:$tag" "$image_name:latest"
sed --in-place "s|SUPERVISOR_IMAGE=.*|SUPERVISOR_IMAGE=$image_name|" /etc/resin-supervisor/supervisor.conf
sed --in-place "s|SUPERVISOR_TAG=.*|SUPERVISOR_TAG=$tag|" /etc/resin-supervisor/supervisor.conf
# cleanup old image
echo "Cleanup old supervisor"
docker rmi $SUPERVISOR_IMAGE:$SUPERVISOR_TAG || true

View File

@ -1,38 +0,0 @@
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI += " \
file://sync-authorized-keys \
file://sync-authorized-keys.service \
"
SYSTEMD_SERVICE_${PN} += "sync-authorized-keys.service"
FILES_${PN} += " \
${systemd_unitdir} \
${bindir} \
"/home/root/.ssh/" \
"
RDEPENDS_${PN} += "bash"
do_install_append() {
install -d ${D}/home/root/.ssh
install -d ${D}${bindir}
install -m 0755 ${WORKDIR}/sync-authorized-keys ${D}${bindir}
if [ "${RESIN_CONNECTABLE_ENABLE_SERVICES}" = "1" ]; then
rm -fr ${D}${localstatedir}/lib/dropbear/
rm -f ${D}/home/root/.ssh/authorized_keys
fi
if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
install -d ${D}${systemd_unitdir}/system
install -c -m 0644 ${WORKDIR}/sync-authorized-keys.service ${D}${systemd_unitdir}/system
sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \
-e 's,@SBINDIR@,${sbindir},g' \
-e 's,@BINDIR@,${bindir},g' \
${D}${systemd_unitdir}/system/*.service
fi
}

View File

@ -1,11 +0,0 @@
#!/bin/bash
set -e
BOOT_SSH_KEY=/mnt/boot/authorized_keys
HOME_SSH_KEY=/home/root/.ssh/authorized_keys
if [ -f $BOOT_SSH_KEY ]; then
cp $BOOT_SSH_KEY $HOME_SSH_KEY
chmod 0600 $HOME_SSH_KEY
fi

View File

@ -1,13 +0,0 @@
[Unit]
Description=SSH authorized_keys sync
Requires=home-root-.ssh.mount mnt-boot.mount
After=home-root-.ssh.mount mnt-boot.mount
Before=etc-dropbear.mount
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=@BASE_BINDIR@/bash @BINDIR@/sync-authorized-keys
[Install]
WantedBy=multi-user.target

View File

@ -1,2 +0,0 @@
CONNECTIVITY_PACKAGES_remove = "openvpn"

View File

@ -1,4 +0,0 @@
RDEPENDS_${PN}_remove = "resin-connectable"
RDEPENDS_${PN}_remove = "resin-provisioner"
RDEPENDS_${PN}_append = " hassio-host-controll"

View File

@ -1,39 +0,0 @@
DESCRIPTION = "hassio device controll"
SECTION = "console/utils"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${RESIN_COREBASE}/COPYING.Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
SRC_URI = " \
file://hassio-hc \
file://hassio-hc.service \
"
inherit allarch systemd
SYSTEMD_SERVICE_${PN} += "hassio-hc.service"
SYSTEMD_AUTO_ENABLE = "enable"
RDEPENDS_${PN} = " \
bash \
socat \
"
FILES_${PN} += " \
${systemd_unitdir} \
${bindir} \
"
do_install() {
install -d ${D}${bindir}
install -m 0775 ${WORKDIR}/hassio-hc ${D}${bindir}/hassio-hc
if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
install -d ${D}${systemd_unitdir}/system
install -c -m 0644 ${WORKDIR}/hassio-hc.service ${D}${systemd_unitdir}/system
sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \
-e 's,@SBINDIR@,${sbindir},g' \
-e 's,@BINDIR@,${bindir},g' \
${D}${systemd_unitdir}/system/*.service
fi
}

View File

@ -1,51 +0,0 @@
#!/bin/bash
set -e
# Don't run anything before this source as it sets PATH here
source /etc/profile
# load config
source /usr/sbin/resin-vars
source /etc/resin-supervisor/supervisor.conf
#
# MAIN
#
while read cmd
do
IFS=" " read -r -a parse <<< $cmd
if [ ${parse[0]} == "info" ]; then
echo "{ \"level\": 15, \"os\": \"resinos\", \"version\": \"$RESINOS_HASSIO_VERSION\", \"hostname\": \"$CONFIG_HOSTNAME\" }"
continue
fi
if [ ${parse[0]} == "reboot" ]; then
systemctl reboot && echo "OK" || echo "ERROR"
continue
fi
if [ ${parse[0]} == "shutdown" ]; then
systemctl poweroff && echo "OK" || echo "ERROR"
continue
fi
if [ ${parse[0]} == "host-update" ]; then
if [ ! -z ${parse[1]} ]; then
nohup resinhub --hostos-version ${parse[1]} > /dev/null 2>&1 &
else
nohup resinhub > /dev/null 2>&1 &
fi
echo "OK"
continue
fi
if [ ${parse[0]} == "supervisor-update" ]; then
if [ ! -z ${parse[1]} ]; then
nohup update-resin-supervisor --supervisor-tag ${parse[1]} > /dev/null 2>&1 &
else
nohup update-resin-supervisor > /dev/null 2>&1 &
fi
echo "OK"
continue
fi
echo "WRONG"
done

View File

@ -1,11 +0,0 @@
[Unit]
Description=HassIO HostControll
Wants=resin-supervisor.service
Before=resin-supervisor.service
[Service]
Type=simple
ExecStart=@BINDIR@/socat UNIX-LISTEN:/var/run/hassio-hc.sock,fork EXEC:@BINDIR@/hassio-hc
[Install]
WantedBy=resin.target

View File

@ -1,2 +0,0 @@
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

View File

@ -1,2 +0,0 @@
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

View File

@ -1,2 +0,0 @@
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

View File

@ -1,5 +0,0 @@
#!/bin/sh
set -e
exit 0

View File

@ -1,17 +0,0 @@
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI += " \
file://home-root-.ssh.mount \
"
SYSTEMD_SERVICE_${PN} += " \
home-root-.ssh.mount \
"
do_install_append () {
if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
install -d ${D}${systemd_unitdir}/system
install -c -m 0644 ${WORKDIR}/home-root-.ssh.mount ${D}${systemd_unitdir}/system
fi
}

View File

@ -1,14 +0,0 @@
[Unit]
Description=SSH authorized_keys state bind mount
Requires=mnt-state.mount resin-state-reset.service
After=mnt-state.mount resin-state-reset.service
Before=etc-dropbear.mount
[Mount]
What=/mnt/state/root-overlay/home/root/.ssh
Where=/home/root/.ssh
Type=none
Options=bind
[Install]
WantedBy=resin-bind.target

View File

@ -1,2 +0,0 @@
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

View File

@ -1,60 +0,0 @@
#!/bin/bash
help () {
cat << EOF
Script for setting resin shell environment
resin-vars [options]
Options:
-h, --help
Display this help and exit.
-c, --config-path CONFIG_PATH
Use a non default config.json file.
Default: /mnt/boot/config.json
EOF
}
# Parse arguments
while [[ $# > 0 ]]; do
key=$1
case $key in
-h|--help)
help
exit 0
;;
-c|--config-path)
CONFIG_PATH=$2
shift
;;
*)
echo "[WARNING] $0 : Argument '$1' unknown. Ignoring."
;;
esac
shift
done
# Resin-boot mountpoint
BOOT_MOUNTPOINT="/mnt/boot"
# Default values
if [ -z "$CONFIG_PATH" ]; then
CONFIG_PATH=$BOOT_MOUNTPOINT/config.json
fi
# If config.json provides redefinitions for our vars let us rewrite their
# runtime value
if [ -f $CONFIG_PATH ]
then
ENDPOINT=$(jq --raw-output ".endpoint // empty" $CONFIG_PATH)
CONFIG_HOSTNAME=$(jq --raw-output ".hostname // empty" $CONFIG_PATH)
PERSISTENT_LOGGING=$(jq --raw-output ".persistentLogging // empty" $CONFIG_PATH)
if [ -z "$PERSISTENT_LOGGING" ]; then
PERSISTENT_LOGGING=false
fi
if [ -z "$ENDPOINT" ]; then
ENDPOINT="https://raw.githubusercontent.com/pvizeli/hassio/master/version.json"
fi
else
echo "[WARNING] $0 : '$CONFIG_PATH' not found."
fi

View File

@ -1,9 +0,0 @@
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI += "file://resinhup"
do_install_append() {
install -d ${D}${bindir}
install -m 0755 ${WORKDIR}/resinhup ${D}${bindir}
}

View File

@ -1,346 +0,0 @@
#!/bin/bash
set -e
# Default values
LOGFILE=/tmp/`basename "$0"`.log
LOG=yes
ONLY_SUPERVISOR=no
NOREBOOT=no
DOCKER_REPO=pvizeli
# Don't run anything before this source as it sets PATH here
source /etc/profile
# Help function
function help {
cat << EOF
Wrapper to run host OS updates on resin distributions.
$0 <OPTION>
Options:
-h, --help
Display this help and exit.
-f, --force
Run the resinhup tool without fingerprints check and validation.
--staging
Do this update for devices in staging.
By default resinhup assumes the devices are in production.
-t <TAG>, --tag <TAG>
Use a specific tag for resinhup image.
Default: 1.0 .
--remote <REMOTE>
Run the updater with this remote configuration.
This argument will be passed to resinhup and will be used as the location from
which the update bundles will be downloaded.
--hostos-version <HOSTOS_VERSION>
Run the updater for this specific HostOS version.
This is a mandatory argument.
--supervisor-registry <SUPERVISOR REGISTRY>
Update supervisor getting the image from this registry.
--supervisor-tag <SUPERVISOR TAG>
In the case of a successful host OS update, bring in a newer supervisor too
using this tag.
--only-supervisor
Update only the supervisor.
-n, --nolog
By default tool logs to stdout and file. This flag deactivates log to
$LOGFILE file.
--no-reboot
Dont reboot if update is successful. This is useful when debugging.
EOF
}
# If things fail try to bring board back to the initial state
function tryup {
systemctl start resin-supervisor > /dev/null 2>&1
systemctl start update-resin-supervisor.timer > /dev/null 2>&1
/etc/init.d/crond start > /dev/null 2>&1
}
# Catch INT signals and try to bring things back
trap ctrl_c INT
function ctrl_c() {
log "Trapped INT signal"
tryup
exit 1
}
# Log function helper
function log {
# Address log levels
case $1 in
ERROR)
loglevel=ERROR
shift
;;
WARN)
loglevel=WARNING
shift
;;
*)
loglevel=LOG
;;
esac
ENDTIME=$(date +%s)
if [ "z$LOG" == "zyes" ]; then
printf "[%09d%s%s\n" "$(($ENDTIME - $STARTTIME))" "][$loglevel]" "$1" | tee -a $LOGFILE
else
printf "[%09d%s%s\n" "$(($ENDTIME - $STARTTIME))" "][$loglevel]" "$1"
fi
if [ "$loglevel" == "ERROR" ]; then
exit 1
fi
}
function runPreHacks {
local _boot_mountpoint="$(grep $(blkid | grep resin-boot | cut -d ":" -f 1) /proc/mounts | cut -d ' ' -f 2)"
# we might need to repartition this so make sure it is unmounted
log "Make sure resin-boot is unmounted..."
if [ -z $_boot_mountpoint ]; then
log WARN "Mount point for resin-boot partition could not be found. It is probably already unmounted."
# XXX support old devices
elif [ $_boot_mountpoint = "/boot" ]; then
umount $_boot_mountpoint &> /dev/null
fi
# can't fix label of data partition from container
e2label $DATA_MOUNTPOINT resin-data
}
# Test if a version is greater than another
function version_gt() {
test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"
}
#
# MAIN
#
# Log timer
STARTTIME=$(date +%s)
# Parse arguments
while [[ $# > 0 ]]; do
arg="$1"
case $arg in
-h|--help)
help
exit 0
;;
-t|--resinhup-version)
if [ -z "$2" ]; then
log ERROR "\"$1\" argument needs a value."
fi
RESINHUP_VERSION=$2
shift
;;
--hostos-version)
if [ -z "$2" ]; then
log ERROR "\"$1\" argument needs a value."
fi
HOSTOS_VERSION=$2
shift
;;
--remote)
if [ -z "$2" ]; then
log ERROR "\"$1\" argument needs a value."
fi
REMOTE=$2
shift
;;
--supervisor-registry)
if [ -z "$2" ]; then
log ERROR "\"$1\" argument needs a value."
fi
SUPERVISOR_REGISTRY=$2
shift
;;
--supervisor-tag)
if [ -z "$2" ]; then
log ERROR "\"$1\" argument needs a value."
fi
UPDATER_SUPERVISOR_TAG=$2
shift
;;
--only-supervisor)
ONLY_SUPERVISOR=yes
;;
-n|--nolog)
LOG=no
;;
--no-reboot)
NOREBOOT=yes
;;
*)
log ERROR "Unrecognized option $1."
;;
esac
shift
done
# load config
source /usr/sbin/resin-vars
source /etc/resin-supervisor/supervisor.conf
# Check that HostOS version was provided
if [ -z "$HOSTOS_VERSION" ]; then
if version=$(curl --silent $ENDPOINT | jq -e -r '.resinos_version'); then
HOSTOS_VERSION=$version
else
log ERROR "--hostos-version is required."
fi
fi
if [ -z $RESINHUP_VERSION ]; then
if version=$(curl --silent $ENDPOINT | jq -e -r '.resinhup_version'); then
RESINHUP_VERSION=$version
else
log ERROR "--resinhup-version is required."
fi
fi
# Init log file
# LOGFILE init and header
if [ "$LOG" == "yes" ]; then
echo "================"`basename "$0"`" HEADER START====================" > $LOGFILE
date >> $LOGFILE
fi
# Check if update is needed
log "Detected HassIO version: $RESINOS_HASSIO_VERSION ."
log "Update HassIO to version: $HOSTOS_HASSIO_VERSION ."
if [ $RESINOS_HASSIO_VERSION == $HOSTOS_VERSION ]; then
log "Version $HOSTOS_VERSION is already installed."
exit 0
fi
# protect downgrade
downgrade=$(awk -vn1=$RESINOS_HASSIO_VERSION -vn2=$HOSTOS_VERSION 'BEGIN{print (n1<n2) ? 0:1}')
if [ $downgrade == 1 ]; then
log ERROR "Downgrade are not supported"
exit 0
fi
# Detect DATA_MOUNTPOINT
if [ -d /mnt/data ]; then
DATA_MOUNTPOINT=/mnt/data
elif [ -d /mnt/data-disk ]; then
DATA_MOUNTPOINT=/mnt/data-disk
else
log ERROR "Can't find the resin-data mountpoint."
fi
# Run pre hacks
runPreHacks
# Detect arch
if [ -z "$MACHINE" ]; then
log ERROR "Can't detect machine from resin-vars ."
else
log "Detected arch: $MACHINE ."
fi
# We need to stop update-resin-supervisor.timer otherwise it might restart supervisor which
# will delete downloaded layers. Same for cron jobs.
systemctl stop update-resin-supervisor.timer > /dev/null 2>&1
/etc/init.d/crond stop > /dev/null 2>&1 # We might have cron jobs which restart supervisor
# Supervisor update
if [ ! -z "$UPDATER_SUPERVISOR_TAG" ]; then
log "Supervisor update requested through arguments ."
# Default UPDATER_SUPERVISOR_IMAGE to the one in /etc/supervisor.conf
if [ -z "$SUPERVISOR_REGISTRY" ]; then
UPDATER_SUPERVISOR_IMAGE=$SUPERVISOR_IMAGE
else
UPDATER_SUPERVISOR_IMAGE="$SUPERVISOR_REGISTRY/resin/$arch-supervisor"
fi
log "Update to supervisor $UPDATER_SUPERVISOR_IMAGE:$UPDATER_SUPERVISOR_TAG..."
log "Updating supervisor..."
/usr/bin/update-resin-supervisor --supervisor-image $UPDATER_SUPERVISOR_IMAGE --supervisor-tag $UPDATER_SUPERVISOR_TAG
if [ $? -ne 0 ]; then
tryup
log ERROR "Could not update supervisor to $UPDATER_SUPERVISOR_IMAGE:$UPDATER_SUPERVISOR_TAG ."
fi
else
log "Supervisor update not requested through arguments ."
fi
# That's it if we only wanted supervisor update
if [ "$ONLY_SUPERVISOR" == "yes" ]; then
log "Update only of the supervisor requested."
exit 0
fi
# Avoid supervisor cleaning up resinhup and stop containers
log "Stopping all containers..."
systemctl stop resin-supervisor > /dev/null 2>&1
docker stop $(docker ps -a -q) > /dev/null 2>&1
log "Removing all containers..."
docker rm $(docker ps -a -q) > /dev/null 2>&1
# Pull resinhup and tag it accordingly
log "Pulling resinhup..."
docker pull $DOCKER_REPO/resinhup:$MACHINE-$RESINHUP_VERSION
if [ $? -ne 0 ]; then
tryup
log ERROR "Could not pull $DOCKER_REPO/resinhup:$MACHINE-$RESINHUP_VERSION ."
fi
# Run resinhup
log "Running resinhup for version $HOSTOS_VERSION ..."
RESINHUP_STARTTIME=$(date +%s)
# Set options
RESINHUP_ENV="-e VERSION=$HOSTOS_VERSION-$MACHINE -e REMOTE=$DOCKER_REPO/resinos-hassio"
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:$MACHINE-$RESINHUP_VERSION
RESINHUP_EXIT=$?
docker rmi $DOCKER_REPO/resinhup:$MACHINE-$RESINHUP_VERSION || true
# RESINHUP_EXIT
# 0 - update done
# 2 - only intermediate step was done and will continue after reboot
# 3 - device already updated at a requested version or later
if [ $RESINHUP_EXIT -eq 0 ] || [ $RESINHUP_EXIT -eq 2 ] || [ $RESINHUP_EXIT -eq 3 ]; then
RESINHUP_ENDTIME=$(date +%s)
log "Update suceeded in $(($RESINHUP_ENDTIME - $RESINHUP_STARTTIME)) seconds."
# Restore config
cp /mnt/boot/config.json.hup.old /mnt/boot/config.json || true
cp /mnt/boot/system-connections/resin-sample.hup.old /mnt/boot/config.json || true
# Everything is fine - Reboot
if [ "$NOREBOOT" == "no" ]; then
log "Rebooting board in 5 seconds..."
nohup bash -c " /bin/sleep 5 ; /sbin/reboot " > /dev/null 2>&1 &
else
log "'No-reboot' requested."
fi
else
RESINHUP_ENDTIME=$(date +%s)
# Don't tryup so support can have a chance to see what went wrong and how to recover
log ERROR "Update failed after $(($RESINHUP_ENDTIME - $RESINHUP_STARTTIME)) seconds. Check the logs."
fi
# Success
exit $RESINHUP_EXIT

View File

@ -1,20 +0,0 @@
FROM %%BASE_IMAGE%%
# Add version
ENV VERSION %%SUPERVISOR_TAG%%
ENV LANG C.UTF-8
# remove several traces of python
RUN apk del --no-cache python*
# setup base
RUN apk add --no-cache python3 git
# update pip
RUN pip3 install pip --no-cache-dir --upgrade
# install HassIO
COPY hassio_api /usr/src/hassio_api
RUN pip3 install --no-cache-dir /usr/src/hassio_api
CMD [ "python3", "-m", "hassio" ]

View File

@ -1,20 +0,0 @@
# HassIO supervisor
- Docker socket for Docker management
- HassIO HostControll socket for manage host functions
- Persistent volume to store all data
## Run supervisor on a normal docker host
```bash
docker run --name resin_supervisor \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/run/hassio-hc.sock:/var/run/hassio-hc.sock \
-v /resin-data:/data \
-v /var/log/supervisor-log:/var/log \
-e SUPERVISOR_SHARE=/resin-data \
-e SUPERVISOR_NAME=resin_supervisor \
-e HOMEASSISTANT_REPOSITORY=${HOMEASSISTANT_REPOSITORY} \
${SUPERVISOR_IMAGE}
```