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
Add support for Hass.io #3732
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 e204d60
better start-stop script
fredrike 4b516bd
fixed daemon version
fredrike df7dc0c
version bump
fredrike e797b68
only supports x64 arch
fredrike 8f31d5a
fix newline
fredrike 4e52c6e
updated install_ui
fredrike d00caa4
new install UI
fredrike 3a23285
add docker stop to stop script
fredrike f262cc0
remove hassio network at uninstall too
fredrike d1b1997
fixes for @ymartin59
fredrike 46e4571
service_preupgrade
fredrike e23d602
add fix_usb_devices
fredrike eb505bb
lint fixes
fredrike f5c97b7
fix usb_devices function
fredrike 337ede0
fix uninstall (so new installs will work)
fredrike 008c358
fix upgrade
fredrike 7b9dbcc
more upgrade fixes
fredrike 6295fc0
fix stupid typo
fredrike 94f8c69
minor fixes in usb_devices
fredrike 925f2a3
working updating version
fredrike fbdbec6
don't overwrite config-file (untested)
fredrike dd401dd
rev is git commit hash
fredrike d57bdf8
add remove addons option during uninstall
fredrike 63550c4
more upgrade fixes
fredrike 6dd0666
exprimental fix for usb.rules
fredrike 89590ec
fix devices and remove hassio-dns container when uninstalling
fredrike 3c5c9bc
make sure we are running a working Docker version
fredrike ca5bddc
fix variables
fredrike 2269c99
remove dependency of busybox
fredrike d67e38b
fixes for @ymartin59
fredrike 7127120
fix erroneous space
fredrike 6209e1a
remove hassio_dns image and conditionally hass
fredrike 7abccb3
port 8123 conflicts with homeassistant
fredrike File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = "" | ||
|
||
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.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[General] | ||
launch_browser = 1 | ||
web_port = 8123 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"supervisor": "@supervisor@", | ||
"homeassistant": "@homeassistant@", | ||
"data": "@data_dir@" | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}] | ||
}] | ||
}] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.