Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Hass.io #3732

Merged
merged 34 commits into from Jan 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3149131
initial hass.io support
fredrike Jun 30, 2019
e204d60
better start-stop script
fredrike Jul 1, 2019
4b516bd
fixed daemon version
fredrike Jul 1, 2019
df7dc0c
version bump
fredrike Jul 4, 2019
e797b68
only supports x64 arch
fredrike Jul 4, 2019
8f31d5a
fix newline
fredrike Jul 4, 2019
4e52c6e
updated install_ui
fredrike Jul 9, 2019
d00caa4
new install UI
fredrike Jul 9, 2019
3a23285
add docker stop to stop script
fredrike Jul 20, 2019
f262cc0
remove hassio network at uninstall too
fredrike Jul 23, 2019
d1b1997
fixes for @ymartin59
fredrike Jul 31, 2019
46e4571
service_preupgrade
fredrike Aug 1, 2019
e23d602
add fix_usb_devices
fredrike Aug 1, 2019
eb505bb
lint fixes
fredrike Aug 1, 2019
f5c97b7
fix usb_devices function
fredrike Aug 2, 2019
337ede0
fix uninstall (so new installs will work)
fredrike Aug 2, 2019
008c358
fix upgrade
fredrike Aug 2, 2019
7b9dbcc
more upgrade fixes
fredrike Aug 2, 2019
6295fc0
fix stupid typo
fredrike Aug 3, 2019
94f8c69
minor fixes in usb_devices
fredrike Aug 3, 2019
925f2a3
working updating version
fredrike Aug 4, 2019
fbdbec6
don't overwrite config-file (untested)
fredrike Aug 4, 2019
dd401dd
rev is git commit hash
fredrike Aug 4, 2019
d57bdf8
add remove addons option during uninstall
fredrike Aug 4, 2019
63550c4
more upgrade fixes
fredrike Aug 5, 2019
6dd0666
exprimental fix for usb.rules
fredrike Aug 13, 2019
89590ec
fix devices and remove hassio-dns container when uninstalling
fredrike Oct 4, 2019
3c5c9bc
make sure we are running a working Docker version
fredrike Oct 6, 2019
ca5bddc
fix variables
fredrike Oct 10, 2019
2269c99
remove dependency of busybox
fredrike Oct 10, 2019
d67e38b
fixes for @ymartin59
fredrike Jan 13, 2020
7127120
fix erroneous space
fredrike Jan 13, 2020
6209e1a
remove hassio_dns image and conditionally hass
fredrike Jan 13, 2020
7abccb3
port 8123 conflicts with homeassistant
fredrike Jan 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions spk/hassio/Makefile
@@ -0,0 +1,45 @@
SPK_NAME = hassio
SPK_VERS = 20191224
SPK_REV = 1
SPK_ICON = src/$(SPK_NAME).png
SPK_DEPENDS = "Docker>=18.09.0-0506"
DSM_UI_DIR = app

DEPENDS =

MAINTAINER = fredrike+hassio@gmail.com
DESCRIPTION = "Open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Note: identified USB devices will be added to the file usb_devices.txt located in the hass.io folder."
RELOAD_UI = yes
STARTABLE = yes
DISPLAY_NAME = Hass.io
CHANGELOG = ""

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BETA = 1

UNSUPPORTED_ARCHS = $(ARM_ARCHES) $(PPC_ARCHES) $(x86_ARCHES)

HOMEPAGE = https://www.home-assistant.io/hassio/
LICENSE = Apache License 2.0
HELPURL = https://www.home-assistant.io/docs/

WIZARDS_DIR = src/wizard/

SERVICE_SETUP = src/service-setup.sh

#DSM UI integration
SERVICE_PORT = 8123
fredrike marked this conversation as resolved.
Show resolved Hide resolved
SPK_CONFLICT = homeassistant

INSTALL_DEP_SERVICES = Docker
START_DEP_SERVICES = Docker

COPY_TARGET = nop

POST_STRIP_TARGET = hassio_extra_install

include ../../mk/spksrc.spk.mk

.PHONY: hassio_extra_install
hassio_extra_install:
install -m 755 -d $(STAGING_DIR)/bin
install -m 755 src/hassio.sh $(STAGING_DIR)/bin/
install -m 755 -d $(STAGING_DIR)/var
install -m 644 src/hassio.json $(STAGING_DIR)/var/hassio.dist
Empty file added spk/hassio/PLIST
Empty file.
3 changes: 3 additions & 0 deletions spk/hassio/src/config.ini
@@ -0,0 +1,3 @@
[General]
launch_browser = 1
web_port = 8123
5 changes: 5 additions & 0 deletions spk/hassio/src/hassio.json
@@ -0,0 +1,5 @@
{
"supervisor": "@supervisor@",
"homeassistant": "@homeassistant@",
"data": "@data_dir@"
}
Binary file added spk/hassio/src/hassio.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions spk/hassio/src/hassio.sh
@@ -0,0 +1,59 @@
#!/bin/sh

CONFIG_FILE="/usr/local/hassio/etc/hassio.json"

fix_usb_devices() {
USB_FILE="${HASSIO_DATA}/usb_devices.txt"

docker cp hassio_supervisor:/lib/udev/rules.d/60-serial.rules /lib/udev/rules.d/60-serial-hassio.rules
docker cp hassio_supervisor:/lib/udev/rules.d/60-input-id.rules /lib/udev/rules.d/60-input-id-hassio.rules

udevadm control --reload && udevadm trigger

# Add entries to file
if [ -d /dev/serial/by_id/ ]; then
ls /dev/serial/by_id/* >${USB_FILE}
else
touch ${USB_FILE}
fi
}

runSupervisor() {
HOMEASSISTANT="$(jq --raw-output '.homeassistant' ${CONFIG_FILE})"
HASSIO_DATA="$(jq --raw-output '.data // "/usr/share/hassio"' ${CONFIG_FILE})"

APPARMOR="--security-opt apparmor=unconfined"

/usr/local/bin/docker rm --force hassio_supervisor >/dev/null || true
/usr/local/bin/docker run --name hassio_supervisor \
--privileged \
$APPARMOR \
--security-opt seccomp=unconfined \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/run/dbus:/var/run/dbus \
-v ${HASSIO_DATA}:/data \
-e SUPERVISOR_SHARE=${HASSIO_DATA} \
-e SUPERVISOR_NAME=hassio_supervisor \
-e HOMEASSISTANT_REPOSITORY=${HOMEASSISTANT} \
${SUPERVISOR}
}

start_hassio() {
fix_usb_devices
SUPERVISOR="$(jq --raw-output '.supervisor' ${CONFIG_FILE})"

HASSIO_IMAGE_ID=$(/usr/local/bin/docker inspect --format='{{.Id}}' ${SUPERVISOR})
HASSIO_CONTAINER_ID=$(/usr/local/bin/docker inspect --format='{{.Image}}' hassio_supervisor || echo "--")

# Fix routing
route -vn | grep 172.30.32.0 >/dev/null ||
route add -net 172.30.32.0/23 gw 172.30.32.1

# Run supervisor
([ "${HASSIO_IMAGE_ID}" = "${HASSIO_CONTAINER_ID}" ] && /usr/local/bin/docker start --attach hassio_supervisor) || runSupervisor
}

while true; do
start_hassio
sleep 1
done
97 changes: 97 additions & 0 deletions spk/hassio/src/service-setup.sh
@@ -0,0 +1,97 @@
CFG_FILE="/usr/local/${SYNOPKG_PKGNAME}/etc/hassio.json"

service_postinst() {
if [ "${SYNOPKG_PKG_STATUS}" == "INSTALL" ]; then
DATA_DIR="${wizard_share_path}/${wizard_folder_name}"
# Fix install directory
mkdir -p "${DATA_DIR}"

HOMEASSISTANT_DOCKER="homeassistant/qemux86-64-homeassistant"
HASSIO_DOCKER="homeassistant/amd64-hassio-supervisor"

# Read infos from web
URL_VERSION="https://s3.amazonaws.com/hassio-version/stable.json"
HASSIO_VERSION=$(curl -s $URL_VERSION | jq -e -r '.supervisor')
fredrike marked this conversation as resolved.
Show resolved Hide resolved

# Pull supervisor image
/usr/local/bin/docker pull "${HASSIO_DOCKER}:${HASSIO_VERSION}" >/dev/null &&
/usr/local/bin/docker tag "${HASSIO_DOCKER}:${HASSIO_VERSION}" "${HASSIO_DOCKER}:latest" >/dev/null

if [ ! -f ${CFG_FILE} ]; then
mkdir -p /usr/local/${SYNOPKG_PKGNAME}/etc
cp ${SYNOPKG_PKGDEST}/var/hassio.dist ${CFG_FILE}
# Write config
sed -i -e "s|@supervisor@|${HASSIO_DOCKER}|g" ${CFG_FILE}
sed -i -e "s|@homeassistant@|${HOMEASSISTANT_DOCKER}|g" ${CFG_FILE}
sed -i -e "s|@data_dir@|${DATA_DIR}|g" ${CFG_FILE}
fi
fi
}

service_preuninst() {
if [ ${SYNOPKG_PKG_STATUS} == "UNINSTALL" ]; then
HOMEASSISTANT="$(jq --raw-output '.homeassistant' ${CFG_FILE})"
SUPERVISOR="$(jq --raw-output '.supervisor' ${CFG_FILE})"
fredrike marked this conversation as resolved.
Show resolved Hide resolved
HASSIO_DNS="$(docker inspect --format='{{.Image}}' HASSIO_DNS)"
HASSIO_DATA="$(jq --raw-output '.data // "/usr/share/hassio"' ${CFG_FILE})"

docker rm --force hassio_supervisor hassio_dns
if [ `docker inspect --format='{{.Config.Image}}' homeassistant|grep -q homeassistant/qemux86-64` ]; then
docker rm --force homeassistant && docker image rm ${HOMEASSISTANT}
fi
docker image rm ${SUPERVISOR} ${HASSIO_DNS}
docker network rm hassio

if [ "${wizard_remove_addons}" == "true" ]; then
# Remove addons
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chickenandpork, so you are saying that this doesn't work?

ADDONS_FILE=$(jq -r '.data + "/addons.json"' ${CFG_FILE})

docker rm --force $(jq -r '.user| keys| map("addon_"+.)| join(" ")' $ADDONS_FILE)
docker rmi --force $(jq -r '[.user | keys[] as $k | .[$k].image] | join(" ")' $ADDONS_FILE)
fi

# Move config.json so hassio_supervisor will create a new homeassistant container.
mv "${HASSIO_DATA}/config.json" "${HASSIO_DATA}/config-$(date '+%s').bak"
fi
}

service_preupgrade() {
# Move old config file in var into etc.
if [ -f "${SYNOPKG_PKGDEST}/var/hassio.json" ]; then
mv "${SYNOPKG_PKGDEST}/var/hassio.json" /tmp/hassio.json
fi

if [ -f ${CFG_FILE} ]; then
cp ${CFG_FILE} /tmp/hassio.json
fi
}

service_postupgrade() {
if [ -f /tmp/hassio.json ]; then
mkdir -p /usr/local/${SYNOPKG_PKGNAME}/etc
mv /tmp/hassio.json ${CFG_FILE}
fi

# Move config.json from data dir if there is no homeassistant container.
HASSIO_DATA="$(jq --raw-output '.data // "/usr/share/hassio"' ${CFG_FILE})"
docker ps -a | grep qemux86-64-homeassistant >/dev/null ||
mv "${HASSIO_DATA}/config.json" "${HASSIO_DATA}/config-$(date '+%s').bak"
}

service_prestart ()
{
# Replace generic service startup, fork process in background
echo "Starting hass.io at ${SYNOPKG_PKGDEST}" >> ${LOG_FILE}
COMMAND="bin/hassio.sh"

cd ${SYNOPKG_PKGDEST};
${COMMAND} >> ${LOG_FILE} 2>&1 &
echo "$!" > "${PID_FILE}"

docker start homeassistant
}

service_poststop ()
{
docker stop hassio_supervisor homeassistant
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ADDONS=$(jq -r '.user| keys| map("addon_"+.)| join(" ")' $(jq -r '.data + "/addons.json"' ${CFG_FILE}))
docker stop $ADDONS

}
48 changes: 48 additions & 0 deletions spk/hassio/src/wizard/install_uifile.sh
@@ -0,0 +1,48 @@
#!/bin/sh
set +x

GetShares()
{
for share in `sudo /usr/syno/sbin/synoshare --enum ALL|tail -n +3`; do
path=$(sudo /usr/syno/sbin/synoshare --get "${share}"|sed -n 's/.*Path.*\[\(.*\)\]/\1/p')
echo "[\"$path\", \"$share (${path})\"]"
done | tr -s '\n' ',' | sed -e 's/,$//'
}


FIRST=`/bin/cat<<EOF
{
"step_title": "Data location",
"items": [{
"desc": "The installer will download and build the latest versions of hass.io and homeassistant. <br/>Please fill the desired storage location for the data directory below (create a new <b>Shared Folder</b> if none of the ones below suits storage of hass.io data)."
},{
"type": "combobox",
"subitems": [{
"key": "wizard_share_path",
"desc": "Shared Folder to store hass.io data in",
"editable": false,
"mode": "local",
"value": "",
"valueField": "path",
"displayField": "display_name",
"store": {
"xtype": "arraystore",
"fields": ["path", "display_name"],
"data": [$(GetShares)]
}
}]
}, {
"type": "textfield",
"subitems": [{
"key": "wizard_folder_name",
"desc": "Data folder name",
"value": "hass.io",
"disabled": false
}]
}]
}
EOF`

echo "[$FIRST]" > $SYNOPKG_TEMP_LOGFILE

exit 0
12 changes: 12 additions & 0 deletions spk/hassio/src/wizard/uninstall_uifile
@@ -0,0 +1,12 @@
[{
"step_title": "Uninstall of hass.io",
"items": [{
"type": "multiselect",
"desc": "The hassio_supervisor & homeassistant docker containers will be removed.",
"subitems": [{
"key": "wizard_remove_addons",
"desc": "Remove all installed addon containers too.",
"defaultValue": true
}]
}]
}]