-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbeacon_msg.sh
More file actions
76 lines (60 loc) · 1.68 KB
/
beacon_msg.sh
File metadata and controls
76 lines (60 loc) · 1.68 KB
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
#!/bin/sh
#
# Shell script that takes a beacon email message and does stuff with it
#
# e.g. Post to Facebook, Send a XMPP(Jabber) message, update and OpenHAB item
#
LOG=/var/log/beacon_messages
HABURL=
XMPP_DEST=
tmp="/tmp/beacon.in.$$"
cp /dev/null $tmp
cat >> $tmp
# Extract required fields
subject=`egrep "^Subject:" $tmp | head -1 | sed -e "s/Subject: //"`
type=`fgrep "<beacon+" $tmp | tail -1 | sed -e "s/.*beacon+//" -e "s/@.*//" | tr '[a-z]' '[A-Z]'`
# If it is not a beacon message ignore it
if test "$subject" != "Beacon"
then
rm -f $tmp
exit 0
fi
echo "$datetime beacon: Received $type message" >> $LOG
# Strip crud
msg=`cat $tmp | sed -e "1,/^$/d" -e "s/Call OC.*//" -e "s/'//g" | tr "\n" " "`
# Determine type
echo $msg | egrep -q "^VR at"
if test $? -eq 0
then
type="VR"
fi
echo $msg | egrep -q "^FR at"
if test $? -eq 0
then
type="FR"
fi
datetime=`date +"%d.%m.%Y %H:%M:%S"`
echo "$datetime beacon: $msg" >> $LOG
case "$type" in
132500)
/share/scripts/fbpost.php $type "$msg"
;;
VR|FR)
/share/scripts/xsend.py $XMPP_DEST "$type: $msg"
curl --header "Content-Type: text/plain" --request PUT --data "$type" $HABURL
/share/scripts/fbpost.php $type "$msg"
;;
TEST)
/share/scripts/xsend.py $XMPP_DEST "$type: $msg"
/share/scripts/fbpost.php $type "$msg"
;;
SUPPORT)
/share/scripts/xsend.py $XMPP_DEST "$type: $msg"
curl --header "Content-Type: text/plain" --request PUT --data "$type" $HABURL
/share/scripts/fbpost.php $type "$msg"
;;
*)
/share/scripts/fbpost.php Beacon "$msg" > /tmp/beaconmsg.out 2>&1
;;
esac
rm -f $tmp