#!/bin/sh
##
##  fileschanged-dispatch -- fileschanged(8) OpenPKG dispatch utility
##

#   take information from command-line
if [ $# -ne 2 ]; then
    echo "ERROR: invalid number of arguments" 1>&2
    exit 1
fi
action="$1"
file="$2"

#   determine command to execute
OIFS="$IFS"; IFS="
"
for line in \
    `sed -e '/^ *#.*/d' -e '/^ *$/d' \
         <@l_prefix@/etc/fileschanged/fileschanged.conf`; do
    eval `echo "$line" | sed -e 's;^;X;' -e 's%^X\([^ ][^ ]*\)  *\([^ ][^ ]*\) *$%prefix="\1";command="\2"%' -e 's;^X.*;;'`
    case "$file" in
        ${prefix} | ${prefix}/* )
            ($command "$action" "$file") >/dev/null 2>&1 || true
            ;;
    esac
done
IFS="$OIFS"

