#!/bin/sh # Log to syslog and to stderr LOG="mylog" mylog() { [ -n "$(which logger)" ] && logger -t $(basename ${0}) "${1}" echo "${1}" >&2; } usage(){ ${LOG} "Usage: $(basename $0) -r -o -v " ${LOG} " -C -c -R " ${LOG} "$cmd_error" exit 1 } cmd_error="" while getopts ":r:o:v:C:c:R:" opt; do case "$opt" in r) PARAM_REASON="$OPTARG";; o) PARAM_ORGIN="$OPTARG";; v) PARAM_VALUE="$OPTARG";; C) PARAM_CONFIGDIRECTORY="$OPTARG";; c) PARAM_CACHEDIRECTORY="$OPTARG";; R) PARAM_RESOURCEDIRECTORY="$OPTARG";; --) break;; \?) cmd_error="$(gettext 'Error: Error parsing Commandline')"; break;; esac done [ -n "$cmd_error" ] && usage [ -d "${PARAM_CONFIGDIRECTORY}/${PARAM_REASON}" ] || exit 0 case "${PARAM_REASON}" in activity) commandline="${PARAM_ORGIN} ${PARAM_VALUE}" ;; key) [ "${PARAM_VALUE}" != "_Setup" ] \ && commandline="${PARAM_ORGIN} ${PARAM_VALUE}" \ || commandline="${PARAM_ORGIN} ''" ;; watchdog) commandline="${PARAM_ORGIN} ${PARAM_VALUE}" ;; esac hooks="$(find "${PARAM_CONFIGDIRECTORY}/${PARAM_REASON}" -maxdepth 1 -xtype f -name '[0-9][0-9]*' | sort)" for hook in ${hooks}; do if [ -x $hook ]; then eval $hook $commandline "$PARAM_CONFIGDIRECTORY" "$PARAM_CACHEDIRECTORY" "$PARAM_RESOURCEDIRECTORY" else eval /bin/sh $hook $commandline "$PARAM_CONFIGDIRECTORY" "$PARAM_CACHEDIRECTORY" "$PARAM_RESOURCEDIRECTORY" fi [ $? -ne 0 ] && ${LOG} "error when executing ${hook}" done exit 0