#!/bin/bash

NOADPATH="/etc/vdr/noad"
PARAM=$#

if [ -z "$1" ]; then
  logger -s "RECORDINGHOOKS: fehlender Aufrufparameter"
  exit 1
fi

case "$1" in
  "before")
    for (( I=1; $I <= $PARAM; I++ )); do
      NOADPARAM="$NOADPARAM \"$1\""
      shift
    done
    logger -s "RECORDINGHOOKS: `date`: $NOADPARAM"
    for command in $NOADPATH/rec_before.d/*; do
      logger -s "RECORDINGHOOKS: Start $command $NOADPARAM"
      eval $command $NOADPARAM &
    done
  ;;
  "after")
    for (( I=1; $I <= $PARAM; I++ )); do
      NOADPARAM="$NOADPARAM \"$1\""
      shift
    done
    logger -s "RECORDINGHOOKS: `date`: $NOADPARAM"
    for command in $NOADPATH/rec_after.d/*; do
      logger -s "RECORDINGHOOKS: Start $command $NOADPARAM"
      eval $command $NOADPARAM &
    done
  ;;
  "edited")
    for (( I=1; $I <= $PARAM; I++ )); do
      NOADPARAM="$NOADPARAM \"$1\""
      shift
    done
    logger -s "RECORDINGHOOKS: `date`: $NOADPARAM"
    for command in $NOADPATH/rec_edited.d/*; do
      logger -s "RECORDINGHOOKS: Start $command $NOADPARAM"
      eval $command $NOADPARAM &
    done
  ;;
  *)
    logger -s "RECORDINGHOOKS: FEHLER Unbekannter Befehl"
  ;;
esac
