-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsynodlna-reindex-inotify.sh
executable file
·59 lines (45 loc) · 1.31 KB
/
synodlna-reindex-inotify.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
55
56
57
58
59
#!/opt/bin/bash
HERE=$(dirname $0)
[ -f $HERE/config.sh ] && . $HERE/config.sh
. $HERE/lib/common/arraymap.lib.sh
. $HERE/lib/synodlna/synodlna-shares.lib.sh
. $HERE/lib/synodlna/synodlna-synoindex.lib.sh
. $HERE/lib/synodlna/synodlna-synoindex-inotify.lib.sh
function on_exit
{
echo "catch end of script, killing PID[$IT_PID] and dropping inotifywait FIFO"
[ ! -z "$IT_PID" ] && /bin/kill $IT_PID
/bin/rm -v $IT_FIFO
exit
}
trap on_exit SIGINT SIGTERM
IT_FIFO=/tmp/synodlna-reindex-inotify.fifo
IT_BIN=/usr/local/inotify-tools/bin
IT_ONLY_EVENTS="
-e close_write
-e moved_to
-e moved_from
-e move
-e create
-e delete
-e modify
"
IT_EXCLUDE="(@eaDir|#recycle)"
which $IT_BIN/inotifywait
[ $? -ne 0 ] && echo "$IT_BIN/inotifywait missing, stop" && exit 1
# get all DLNA directories from database
dlnashares_extract
DLNA_SHARES=$(dlnashares_get_all_path | cut -d':' -f2)
IT_WATCHDIR=
for s in $DLNA_SHARES
do
echo "set share '$s' to be watched by inotify"
IT_WATCHDIR="$IT_WATCHDIR $VOLUME_ROOT/$s"
done
echo "launching inotifywait...:"
[ ! -e "$IT_FIFO" ] && /opt/bin/mkfifo "$IT_FIFO"
$IT_BIN/inotifywait -rm ${IT_ONLY_EVENTS} ${IT_WATCHDIR} --exclude=${IT_EXCLUDE} --format "%w|%e|%f" -o ${IT_FIFO} &
IT_PID=$!
echo "PID INOTIFY=${IT_PID}"
echo "DEBUG : $DEBUG"
dlna_inotify_liveupdate ${IT_FIFO}