From a612c30a439d214a9bfffcf74ee378e843ac91ad Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Fri, 21 Jul 2017 10:44:23 +0200 Subject: [PATCH] Mqtt customize (#143) * new options + version pump * add default options for include_dir * init customize configs * map share RO * Update run.sh * Update Dockerfile --- mosquitto/Dockerfile | 2 +- mosquitto/config.json | 14 +++++++++++--- mosquitto/mosquitto.conf | 1 + mosquitto/run.sh | 7 +++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/mosquitto/Dockerfile b/mosquitto/Dockerfile index d32060e..521f67e 100644 --- a/mosquitto/Dockerfile +++ b/mosquitto/Dockerfile @@ -4,7 +4,7 @@ FROM %%BASE_IMAGE%% ENV LANG C.UTF-8 # Setup base -RUN apk add --no-cache tzdata jq mosquitto +RUN apk add --no-cache jq mosquitto # Copy data COPY run.sh / diff --git a/mosquitto/config.json b/mosquitto/config.json index f5aeaaf..e8fdb4f 100644 --- a/mosquitto/config.json +++ b/mosquitto/config.json @@ -1,21 +1,25 @@ { "name": "Mosquitto broker", - "version": "0.8", + "version": "1.0", "slug": "mosquitto", "description": "An Open Source MQTT broker", "url": "https://home-assistant.io/addons/mosquitto/", - "startup": "before", + "startup": "system", "boot": "auto", "ports": { "1883/tcp": 1883, "8883/tcp": 8883 }, - "map": ["ssl"], + "map": ["ssl", "share"], "options": { "plain": true, "ssl": false, "anonymous": true, "logins": [], + "customize": { + "active": false, + "folder": "moquitto" + }, "certfile": "fullchain.pem", "keyfile": "privkey.pem" }, @@ -26,6 +30,10 @@ "logins": [ {"username": "str", "password": "str"} ], + "customize": { + "active": "bool", + "folder": "str" + }, "certfile": "str", "keyfile": "str" }, diff --git a/mosquitto/mosquitto.conf b/mosquitto/mosquitto.conf index e46b3fe..9a6a519 100644 --- a/mosquitto/mosquitto.conf +++ b/mosquitto/mosquitto.conf @@ -16,3 +16,4 @@ persistence_location /data/ # User settings #password_file /data/users.db #allow_anonymous false +#include_dir /share/mosquitto diff --git a/mosquitto/run.sh b/mosquitto/run.sh index ab6a730..06e6e73 100644 --- a/mosquitto/run.sh +++ b/mosquitto/run.sh @@ -9,6 +9,7 @@ LOGINS=$(jq --raw-output ".logins | length" $CONFIG_PATH) ANONYMOUS=$(jq --raw-output ".anonymous" $CONFIG_PATH) KEYFILE=$(jq --raw-output ".keyfile" $CONFIG_PATH) CERTFILE=$(jq --raw-output ".certfile" $CONFIG_PATH) +CUSTOMIZE_ACTIVE=$(jq --raw-output ".customize.active" $CONFIG_PATH) PLAIN_CONFIG=" listener 1883 @@ -36,6 +37,12 @@ if [ "$ANONYMOUS" == "false" ]; then sed -i "s/#allow_anonymous/allow_anonymous/g" /etc/mosquitto.conf fi +# Allow customize configs from share +if [ "$CUSTOMIZE_ACTIVE" == "true" ]; then + CUSTOMIZE_FOLDER=$(jq --raw-output ".customize.folder" $CONFIG_PATH) + sed -i "s|#include_dir .*|include_dir /share/$CUSTOMIZE_FOLDER|g" /etc/mosquitto.conf +fi + # Generate user data if [ "$LOGINS" -gt "0" ]; then sed -i "s/#password_file/password_file/g" /etc/mosquitto.conf