-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashpipe.sh
55 lines (39 loc) · 1.07 KB
/
dashpipe.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
#!/bin/bash
cd "$(dirname "$0")"
. include
if [ ! -p $PIPE ]; then
if [ -e "$PIPE" ]; then
logecho "Delete non-fifo file"
rm $PIPE
fi
logecho "Create fifo"
mkfifo $PIPE
chmod ug=rw,o=- $PIPE
fi
while true
do
if read line <$PIPE; then
# Get MAC address from iptables log line
MAC=$(echo $line | awk '{print $8}' | cut -b 23-39)
if [ -d "$MACDIR/$MAC" ]; then
# Get id and name
ID=$(get_id "$MAC")
NAME=$(get_name "$MAC")
# Count press
countpress "$ID"
# Log
logecho "Dash Button press for $MAC / $ID / $NAME"
# Clear log
clear_idlog "$ID"
CURLOG="$(get_idlog "$ID")"
for I in $MACDIR/$MAC/exec_*; do
if [ -x "$I" ]; then
# Execute file
./saferun.sh "$MAC" "$ID" "$NAME" "$I" &>> "$CURLOG" &
fi
done
else
logecho "Unknown Dash Button press for MAC $MAC"
fi
fi
done