46 lines
932 B
Plaintext
46 lines
932 B
Plaintext
#!/usr/bin/with-contenv bash
|
|
# shellcheck shell=bash
|
|
|
|
if ! command -v inotifywait 2>&1 >/dev/null; then
|
|
echo "No inotifywait found. install inotify tools"
|
|
apk add inotify-tools
|
|
fi
|
|
|
|
echo "running inotify"
|
|
|
|
BASEEXCLUDE='.*\.swp|.*\.swx'
|
|
|
|
detect(){
|
|
WATCH=$1
|
|
EXCLUDE=$2
|
|
REPLACEIN=$3
|
|
REPLACEWITH=$4
|
|
|
|
echo "watching $WATCH and excluding $EXCLUDE"
|
|
|
|
inotifywait -mre close_write,delete --format '%e|%w|%f' --exclude "$EXCLUDE" "$WATCH" | while read RAWEVENT
|
|
do
|
|
|
|
echo $RAWEVENT
|
|
IFS='|'
|
|
read -a SPLITEVENT <<< "$RAWEVENT"
|
|
|
|
EVENT=${SPLITEVENT[0]}
|
|
DIR=${SPLITEVENT[1]}
|
|
FILE=${SPLITEVENT[2]}
|
|
|
|
REPLACEDFILE=$DIR
|
|
|
|
if [[ $EVENT != 'DELETE' ]]; then
|
|
REPLACEDFILE+=$FILE
|
|
fi
|
|
|
|
if [ -n "$REPLACEIN" ] && [ -n "$REPLACEWITH" ]; then
|
|
REPLACEDFILE=${REPLACEDFILE/$REPLACEIN/$REPLACEWITH}
|
|
fi
|
|
|
|
occ files:scan --path=\"$REPLACEDFILE\" --shallow
|
|
done
|
|
}
|
|
|
|
detect /data/riksolo/files $BASEEXCLUDE /data/riksolo /riksolo |