-
Notifications
You must be signed in to change notification settings - Fork 3
/
bitraf-tv-showmessage
executable file
·57 lines (45 loc) · 1.09 KB
/
bitraf-tv-showmessage
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
#!/bin/bash
set -e
urlencode() {
# urlencode <string>
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
*) printf '%s' "$c" | xxd -p -c1 |
while read c; do printf '%%%s' "$c"; done ;;
esac
done
}
urldecode() {
# urldecode <string>
local url_encoded="${1//+/ }"
printf '%b' "${url_encoded//%/\\x}"
}
check() {
local key="$1"; shift
local value="${!key}"
if [[ -z $value ]]
then
echo "Missing environment variable $key"
exit 1
fi
}
check BROKER
opts=()
opts+=(-h "$BROKER")
opts+=(-t "/bitraf/tv/showmessage")
if [[ ! -z $MQTT_USERNAME ]]
then
opts+=(--username "$MQTT_USERNAME" --pw "$MQTT_PASSWORD")
fi
echo "Connecting to MQTT"
mosquitto_sub "${opts[@]}" | while read first rest_of_line
do
message="${first} ${rest_of_line}"
URL=http://tv.local:8080/message/$(urlencode "${message}")
echo "opening" $URL
DISPLAY=:0 zenity --text-info --html --url $URL --width 1824 --height 1084 --timeout 5 &
done
sleep 1