summaryrefslogtreecommitdiff
path: root/script/vdr-uactivity
blob: c7589396b8563bf5a370030a7d79d1ce4b5931dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/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 <reason activity|key|watchdog> -o <orgin startup|shutdown|running> -v <value>"
	${LOG} "                     -C <ConfigDirectory> -c <CacheDirectory> -R <ResourceDirectory>"
	${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)
		if [ "${PARAM_VALUE}" != "_Setup" ]; then
			commandline="${PARAM_ORGIN} ${PARAM_VALUE}"
		else
			commandline="${PARAM_ORGIN} ''"
		fi
	;;
	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