From 0bbbe3549d8100c9462a0023604d6964b20bc8b3 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 5 Jan 2020 13:20:49 +0100 Subject: [PATCH] :sparkles: Adds support for startup init commands --- README.md | 6 ++++++ appdaemon/config.json | 20 ++++++------------- appdaemon/rootfs/etc/cont-init.d/appdaemon.sh | 8 ++++++++ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 0249e6e..232575c 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,12 @@ installed to your AppDaemon setup (e.g., `PyMySQL`. `Requests`, `Pillow`). **Note**: _Adding many packages will result in a longer start-up time for the add-on._ +#### Option: `init_commands` + +Customize your environment even more with the `init_commands` option. +Add one or more shell commands to the list, and they will be executed every +single time this add-on starts. + ## AppDaemon and HADashboard configuration This add-on does not configure the AppDaemon or HADashboard for you. diff --git a/appdaemon/config.json b/appdaemon/config.json index bb1f6ac..cde3674 100755 --- a/appdaemon/config.json +++ b/appdaemon/config.json @@ -6,13 +6,7 @@ "url": "https://github.com/hassio-addons/addon-appdaemon3", "webui": "http://[HOST]:[PORT:5050]", "startup": "application", - "arch": [ - "aarch64", - "amd64", - "armhf", - "armv7", - "i386" - ], + "arch": ["aarch64", "amd64", "armhf", "armv7", "i386"], "boot": "auto", "hassio_api": true, "hassio_role": "default", @@ -25,20 +19,18 @@ "5000/tcp": "AppDaemon RESTFul API", "5050/tcp": "HA Dashboard web interface" }, - "map": [ - "config:rw", - "share:rw", - "ssl" - ], + "map": ["config:rw", "share:rw", "ssl"], "options": { "disable_auto_token": false, "system_packages": [], - "python_packages": [] + "python_packages": [], + "init_commands": [] }, "schema": { "log_level": "match(^(trace|debug|info|notice|warning|error|fatal)$)?", "disable_auto_token": "bool", "system_packages": ["str"], - "python_packages": ["str"] + "python_packages": ["str"], + "init_commands": ["str"] } } diff --git a/appdaemon/rootfs/etc/cont-init.d/appdaemon.sh b/appdaemon/rootfs/etc/cont-init.d/appdaemon.sh index 16c0a59..c72124a 100644 --- a/appdaemon/rootfs/etc/cont-init.d/appdaemon.sh +++ b/appdaemon/rootfs/etc/cont-init.d/appdaemon.sh @@ -99,3 +99,11 @@ if bashio::config.has_value 'python_packages'; then || bashio::exit.nok "Failed installing package ${package}" done fi + +# Executes user configured/requested commands on startup +if bashio::config.has_value 'init_commands'; then + while read -r cmd; do + eval "${cmd}" \ + || bashio::exit.nok "Failed executing init command: ${cmd}" + done <<< "$(bashio::config 'init_commands')" +fi