slcl/watchdir

54 lines
653 B
Plaintext
Raw Normal View History

2023-06-19 01:47:43 +02:00
#! /bin/sh
usage()
{
2023-06-19 15:23:09 +02:00
echo "$0 [-s <size>] [-r] [-h] [-j <jobs>] <dir>"
2023-06-19 01:47:43 +02:00
}
REGEN=0
SIZE=96
2023-06-19 15:23:09 +02:00
while getopts rj:s:h arg
2023-06-19 01:47:43 +02:00
do
2023-06-19 15:23:09 +02:00
case $arg in
j) JOBS="$OPTARG"
;;
r) REGEN=1
;;
s) SIZE="$OPTARG"
;;
h) usage
exit 0
;;
?) usage >&2
exit 1
;;
esac
2023-06-19 01:47:43 +02:00
done
shift $(($OPTIND - 1))
if [ $# != 1 ]; then
2023-06-19 15:23:09 +02:00
usage >&2
exit 1
2023-06-19 01:47:43 +02:00
fi
DIR="$1"
[ "$REGEN" -eq 1 ] && "$(dirname $0)/tngen" \
2023-06-19 15:23:09 +02:00
${SIZE:+-s$SIZE} \
${JOBS:+-j$JOBS} \
-d "$DIR" \
"$DIR/user"
2023-06-19 01:47:43 +02:00
while :
do
2023-06-19 15:23:09 +02:00
F="$(inotifywait -e modify,move,create,delete \
--format "%w%f" -qr "$DIR/user/")"
"$(dirname $0)/tngen" \
${SIZE:+-s$SIZE} \
${JOBS:+-j$JOBS} \
-d "$DIR" \
"$(dirname "$F")"
2023-06-19 01:47:43 +02:00
done