forked from titilambert/pyhydroquebec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
52 lines (47 loc) · 1.07 KB
/
entrypoint.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
#!/bin/sh
set -e
# Check user and password
if [ -z "$PYHQ_USER" ] || [ -z "$PYHQ_PASSWORD" ] && [ "$PYHQ_OUTPUT" != "MQTT" ] && [ "$PYHQ_OUTPUT" != "INFLUXDB" ]
then
echo 'Error: No user or password. Set both environnement variables PYHQ_USER and PYHQ_PASSWORD or either of PYHQ_OUTPUT=MQTT or INFLUXDB'
exit 1
fi
# Output type
if [ ! -z "$PYHQ_OUTPUT" ]
then
case "$PYHQ_OUTPUT" in
"TEXT")
PYHQ_CMD_OUTPUT=""
;;
"JSON")
PYHQ_CMD_OUTPUT="-j"
;;
"INFLUXDB")
PYHQ_CMD_OUTPUT="-i"
;;
"CONTRACTS")
PYHQ_CMD_OUTPUT="-l"
;;
esac
else
PYHQ_CMD_OUTPUT=""
fi
# Contract
if [ ! -z "$PYHQ_CONTRACT" ]
then
PYHQ_CMD_CONTRACT="-c $PYHQ_CONTRACT"
fi
# Config
if [ -z "$CONFIG" ]
then
export CONFIG="/etc/pyhydroquebec/pyhydroquebec.yaml"
fi
if [ "$PYHQ_OUTPUT" == "MQTT" ]
then
mqtt_pyhydroquebec
elif [ "$PYHQ_OUTPUT" == "INFLUXDB" ]
then
influxdb_pyhydroquebec
else
pyhydroquebec -u $PYHQ_USER -p $PYHQ_PASSWORD $PYHQ_CMD_OUTPUT $PYHQ_CMD_CONTRACT
fi