aboutsummaryrefslogtreecommitdiff
path: root/watchdir
blob: fe215b2f13dd72493124da5f5b65a6fcd6d3d80e (plain) (blame)
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
#! /bin/sh

usage()
{
    echo "$0 [-s <size>] [-r] [-h] [-d <subdir>] <dir>"
}

REGEN=0
SIZE=96

while getopts rs:d:h arg
do
    case $arg in
    r) REGEN=1
    ;;
    s) SIZE="$OPTARG"
    ;;
    h) usage
        exit 0
    ;;
    d) SUBDIR="$OPTARG"
    ;;
    ?) usage >&2
        exit 1
    ;;
    esac
done

shift $(($OPTIND - 1))

if [ $# != 1 ]; then
    usage >&2
    exit 1
fi

DIR="$1"

[ "$REGEN" -eq 1 ] && "$(dirname $0)/tngen" \
    ${SIZE:+-s$SIZE} \
    -d "$DIR" \
    "$DIR/user"

while :
do
    F="$(inotifywait -e modify,move,create,delete \
        --format "%w%f" -qr "$DIR/user/")"
    sleep 1 # TODO: revisit this
    "$(dirname $0)/tngen" \
        ${SIZE:+-s$SIZE} \
        -d "$DIR" \
        "$F"
done