forked from micolous/cbus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint-cmqttd.sh
executable file
·93 lines (76 loc) · 3.1 KB
/
entrypoint-cmqttd.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh
# This script is used as the entrypoint for the cmqttd Docker container. It is not intended for use
# outside of that environment.
#
# This allows passing configuration flags as environment variables, which are more Docker friendly.
# Authentication file for MQTT
CMQTTD_AUTH_FILE="/etc/cmqttd/auth"
# CA certificate directory
CMQTTD_CA_CERT_PATH="/etc/cmqttd/certificates"
# Client certificate, public part
CMQTTD_CLIENT_CERT_PATH="/etc/cmqttd/client.pem"
# Client certificate, private part, must NOT be encrypted
CMQTTD_CLIENT_KEY_PATH="/etc/cmqttd/client.key"
# C-Bus Toolkit project backup file
CMQTTD_PROJECT_FILE="/etc/cmqttd/project.cbz"
# Arguments that are always required.
CMQTTD_ARGS="--broker-address ${MQTT_SERVER:?unset} --timesync ${CBUS_TIMESYNC:-300}"
# Simple arguments
if [ -n "${MQTT_PORT}" ]; then
CMQTTD_ARGS="${CMQTTD_ARGS} --broker-port ${MQTT_PORT}"
fi
if [ -n "${SERIAL_PORT}" ]; then
echo "Using serial PCI at ${SERIAL_PORT}"
CMQTTD_ARGS="${CMQTTD_ARGS} --serial ${SERIAL_PORT}"
elif [ -n "${CNI_ADDR}" ]; then
echo "Using TCP CNI at ${CNI_ADDR}"
CMQTTD_ARGS="${CMQTTD_ARGS} --tcp ${CNI_ADDR}"
else
echo "Either SERIAL_PORT or CNI_ADDR must be specified!"
exit 1
fi
if [ "${CBUS_CLOCK:-1}" != "1" ]; then
echo "Not responding to clock requests."
CMQTTD_ARGS="${CMQTTD_ARGS} --no-clock"
fi
if [ "${MQTT_USE_TLS:-1}" == "1" ]; then
echo "Using TLS to connect to MQTT broker."
# Using TLS, check for certificates directory
if [ -d "${CMQTTD_CA_CERT_PATH}" ]; then
echo "Using custom certificates in ${CMQTTD_CA_CERT_PATH}"
CMQTTD_ARGS="${CMQTTD_ARGS} --broker-ca ${CMQTTD_CA_CERT_PATH}"
else
echo "${CMQTTD_CA_CERT_PATH} not found, using Python CA store."
fi
# Client certificates
if [ -e "${CMQTTD_CLIENT_CERT_PATH}" ] && [ -e "${CMQTTD_CLIENT_KEY_PATH}" ]; then
echo "Using client cert: ${CMQTTD_CLIENT_CERT_PATH}"
echo "Using client key: ${CMQTTD_CLIENT_KEY_PATH}"
CMQTTD_ARGS="${CMQTTD_ARGS} --broker-client-cert ${CMQTTD_CLIENT_CERT_PATH} --broker-client-key ${CMQTTD_CLIENT_KEY_PATH}"
else
echo -n "${CMQTTD_CLIENT_CERT_PATH} and/or ${CMQTTD_CLIENT_KEY_PATH} not found, not using "
echo "client certificates for authentication."
fi
else
echo "Disabling TLS support. This is insecure!"
CMQTTD_ARGS="${CMQTTD_ARGS} --broker-disable-tls"
fi
if [ -e "${CMQTTD_AUTH_FILE}" ]; then
echo "Using MQTT login details in ${CMQTTD_AUTH_FILE}"
CMQTTD_ARGS="${CMQTTD_ARGS} --broker-auth ${CMQTTD_AUTH_FILE}"
else
echo "${CMQTTD_AUTH_FILE} not found; skipping MQTT authentication."
fi
if [ -e "${CMQTTD_PROJECT_FILE}" ]; then
echo "Using C-Bus Toolkit project backup file ${CMQTTD_PROJECT_FILE}"
CMQTTD_ARGS="${CMQTTD_ARGS} --project-file ${CMQTTD_PROJECT_FILE}"
else
echo "${CMQTTD_PROJECT_FILE} not found; using generated labels."
fi
echo ""
# Announce what we think local time is on start-up. This will be sent to the C-Bus network.
echo "Local time zone: ${TZ:-UTC}"
echo -n "Current time: "
date -R
echo "Running with flags: ${CMQTTD_ARGS}"
cmqttd $CMQTTD_ARGS