mirror of
https://github.com/aljazceru/addons.git
synced 2025-12-17 13:14:21 +01:00
Mosquitto addon (#7)
This commit is contained in:
16
mosquitto/Dockerfile
Normal file
16
mosquitto/Dockerfile
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
FROM %%BASE_IMAGE%%
|
||||||
|
|
||||||
|
# Add version
|
||||||
|
ENV VERSION %%VERSION%%
|
||||||
|
ENV LANG C.UTF-8
|
||||||
|
|
||||||
|
# Setup base
|
||||||
|
RUN apk add --no-cache jq mosquitto
|
||||||
|
|
||||||
|
# Copy data
|
||||||
|
COPY run.sh /
|
||||||
|
COPY mosquitto.config /etc/
|
||||||
|
|
||||||
|
RUN chmod a+x /run.sh
|
||||||
|
|
||||||
|
CMD [ "/run.sh" ]
|
||||||
12
mosquitto/README.md
Normal file
12
mosquitto/README.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# Mosquitto
|
||||||
|
MQTT broker for HomeAssistant and HassIO addons.
|
||||||
|
|
||||||
|
## Options
|
||||||
|
|
||||||
|
- `plain`:
|
||||||
|
- `ssl`:
|
||||||
|
- `ssl`:
|
||||||
|
- `anonymous`:
|
||||||
|
- `logins`:
|
||||||
|
- `certfile`:
|
||||||
|
- `keyfile`:
|
||||||
31
mosquitto/config.json
Normal file
31
mosquitto/config.json
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"name": "Mosquitto broker",
|
||||||
|
"version": "0.1",
|
||||||
|
"slug": "mosquitto",
|
||||||
|
"description": "An Open Source MQTT broker",
|
||||||
|
"startup": "before",
|
||||||
|
"boot": "auto",
|
||||||
|
"ports": {
|
||||||
|
"1883/tcp": 1883,
|
||||||
|
"8883/tcp": 8883
|
||||||
|
},
|
||||||
|
"map": ["ssl"],
|
||||||
|
"options": {
|
||||||
|
"plain": true,
|
||||||
|
"ssl": false,
|
||||||
|
"anonymous": true,
|
||||||
|
"logins": [],
|
||||||
|
"certfile": "fullchain.pem",
|
||||||
|
"keyfile": "privkey.pem"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"plain": "bool",
|
||||||
|
"ssl": "bool",
|
||||||
|
"anonymous": "bool",
|
||||||
|
"logins": [
|
||||||
|
{"username": "str", "password": "str"}
|
||||||
|
],
|
||||||
|
"certfile": "str",
|
||||||
|
"keyfile": "str"
|
||||||
|
}
|
||||||
|
}
|
||||||
17
mosquitto/mosquitto.conf
Normal file
17
mosquitto/mosquitto.conf
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
##
|
||||||
|
# defaults
|
||||||
|
protocol mqtt
|
||||||
|
|
||||||
|
##
|
||||||
|
# logging
|
||||||
|
log_dest stdout
|
||||||
|
|
||||||
|
##
|
||||||
|
# datastore
|
||||||
|
persistence true
|
||||||
|
persistence_location /data/
|
||||||
|
|
||||||
|
##
|
||||||
|
# User settings
|
||||||
|
#password_file /data/users.db
|
||||||
|
#allow_anonymous true
|
||||||
54
mosquitto/run.sh
Normal file
54
mosquitto/run.sh
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
CONFIG_PATH=/data/options.json
|
||||||
|
|
||||||
|
PLAIN=$(jq --raw-output ".plain" $CONFIG_PATH)
|
||||||
|
SSL=$(jq --raw-output ".ssl" $CONFIG_PATH)
|
||||||
|
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)
|
||||||
|
|
||||||
|
PLAIN_CONFIG="
|
||||||
|
listener 1883
|
||||||
|
"
|
||||||
|
|
||||||
|
SSL_CONFIG="
|
||||||
|
port 8883
|
||||||
|
listener 8883
|
||||||
|
cafile /ssl/$CERTFILE
|
||||||
|
certfile /ssl/$CERTFILE
|
||||||
|
keyfile /ssl/$KEYFILE
|
||||||
|
"
|
||||||
|
|
||||||
|
# Add plain configs
|
||||||
|
if [ "$PLAIN" == "true" ]; then
|
||||||
|
echo "$PLAIN_CONFIG" >> /etc/mosquitto.conf
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Add ssl configs
|
||||||
|
if [ "$SSL" == "true" ]; then
|
||||||
|
echo "$SSL_CONFIG" >> /etc/mosquitto.conf
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Allow anonymous connections
|
||||||
|
if [ "$ANONYMOUS" == "true" ]; then
|
||||||
|
sed -i "s/#allow_anonymous/allow_anonymous/g" /etc/mosquitto.conf
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Generate user data
|
||||||
|
if [ "$LOGINS" -gt "0" ]; then
|
||||||
|
sed -i "s/#password_file/password_file/g" /etc/mosquitto.conf
|
||||||
|
rm -f /data/users.db || true
|
||||||
|
|
||||||
|
for (( i=0; i < "$LOGINS"; i++ )); do
|
||||||
|
USERNAME=$(jq --raw-output ".logins[$i].username" $CONFIG_PATH)
|
||||||
|
PASSWORD=$(jq --raw-output ".logins[$i].password" $CONFIG_PATH)
|
||||||
|
|
||||||
|
mosquitto_passwd -b /data/users.db "$USERNAME" "$PASSWORD"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# start server
|
||||||
|
exec mosquitto -c /etc/mosquitto.conf < /dev/null
|
||||||
Reference in New Issue
Block a user