Last active
March 11, 2020 21:21
-
-
Save bryantebeek/d76d63bd93660ad0971e72093a17a5a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
# Load configs | |
CONFIG_FILE=%%HASSIO_CONFIG%% | |
SUPERVISOR="$(jq --raw-output '.supervisor' ${CONFIG_FILE})" | |
HOMEASSISTANT="$(jq --raw-output '.homeassistant' ${CONFIG_FILE})" | |
DATA="$(jq --raw-output '.data // "/usr/share/hassio"' ${CONFIG_FILE})" | |
# AppArmor Support | |
if command -v apparmor_parser > /dev/null 2>&1 && grep hassio-supervisor /sys/kernel/security/apparmor/profiles > /dev/null 2>&1; then | |
APPARMOR="--security-opt apparmor=hassio-supervisor" | |
else | |
APPARMOR="--security-opt apparmor:unconfined" | |
fi | |
# Init supervisor | |
HASSIO_DATA=${DATA} | |
HASSIO_IMAGE_ID=$(docker inspect --format='{{.Id}}' "${SUPERVISOR}") | |
HASSIO_CONTAINER_ID=$(docker inspect --format='{{.Image}}' hassio_supervisor || echo "") | |
runSupervisor() { | |
docker rm --force hassio_supervisor || true | |
# shellcheck disable=SC2086 | |
docker run --name hassio_supervisor \ | |
--privileged \ | |
$APPARMOR \ | |
--security-opt seccomp=unconfined \ | |
-v /run/docker.sock:/run/docker.sock \ | |
-v /run/dbus:/run/dbus \ | |
-v "${HASSIO_DATA}":/data \ | |
-p 8123:127.0.0.1:8123 \ | |
-e SUPERVISOR_SHARE="${HASSIO_DATA}" \ | |
-e SUPERVISOR_NAME=hassio_supervisor \ | |
-e HOMEASSISTANT_REPOSITORY="${HOMEASSISTANT}" \ | |
"${SUPERVISOR}" | |
} | |
# Run supervisor | |
mkdir -p "${HASSIO_DATA}" | |
([ "${HASSIO_IMAGE_ID}" = "${HASSIO_CONTAINER_ID}" ] && docker start --attach hassio_supervisor) || runSupervisor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment