-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinclude
81 lines (68 loc) · 1.2 KB
/
include
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
#!/bin/bash
PIPE=/tmp/ulogdash.fifo
DIRGLOB=by-*
MACDIR=by-mac
IDDIR=by-id
NAMEDIR=by-name
LOCKDIR=lock
LOG=log/press.log
OUTLOG=log/lastpress-%s.log
COUNTERFILE=log/counter-%s.txt
function logecho()
{
echo "[$(date)] $1" | tee -a "$LOG"
}
function get_pressctr()
{
echo -n "$(printf "$COUNTERFILE" "$1")"
}
function countpress()
{
TEMP=$(get_pressctr "$1")
C=0
if [ -f "$TEMP" ]; then
C=$(cat "$TEMP")
fi
C=$(($C+1))
echo -n $C > "$TEMP"
}
function get_idlog()
{
echo -n "$(printf "$OUTLOG" "$1")"
}
function clear_idlog()
{
cat /dev/null > "$(get_idlog "$1")"
}
function get_id()
{
echo -n $(basename "$(find -L $DIRGLOB -samefile "$MACDIR/$1" | grep "$IDDIR/")")
}
function get_name()
{
echo -n $(basename "$(find -L $DIRGLOB -samefile "$MACDIR/$1" | grep "$NAMEDIR/")")
}
function get_lockfile()
{
if [ ! -d "$LOCKDIR" ]; then
mkdir -p "$LOCKDIR"
fi
echo -n "$LOCKDIR/${1}.lock"
}
function lock()
{
TEMP=$(get_lockfile "$1")
if [ -f "$TEMP" ]; then
return 1
else
date > "$TEMP"
return 0
fi
}
function unlock()
{
TEMP=$(get_lockfile "$1")
if [ -f "$TEMP" ]; then
rm "$TEMP"
fi
}