]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/vdr/runvdr
Merge remote-tracking branch 'origin/next' into fifteen
[people/pmueller/ipfire-2.x.git] / config / vdr / runvdr
1 #!/bin/bash
2
3 # runvdr - VDR launcher
4 #
5 # runvdr [VDROPTION]...
6
7 shopt -s extglob nocasematch nullglob
8
9 VDR=/usr/sbin/vdr
10 PLUGINDIR=/usr/lib/vdr
11 PLUGINVER=VDR_PLUGIN_VERSION
12 PLUGINSUF=${PLUGINVER:+.$PLUGINVER}
13
14 log()
15 {
16 type -P logger &>/dev/null && \
17 logger -s -p daemon.info -t ${0##*/} "$1" 2>&1 || echo "INFO: $1"
18 }
19
20 plugconf()
21 {
22 local plugin=$1 PLUGIN_OPTIONS= PLUGIN_ENABLED=
23 if [[ -e /etc/sysconfig/vdr-plugins.d/$plugin.conf ]] ; then
24 . /etc/sysconfig/vdr-plugins.d/$plugin.conf
25 case $PLUGIN_ENABLED in no|false|0) return ;; esac
26 fi
27 if [[ $PLUGIN_OPTIONS ]] ; then
28 VDR_OPTIONS+=( --plugin="$plugin $PLUGIN_OPTIONS" )
29 else
30 VDR_OPTIONS+=( --plugin=$plugin )
31 fi
32 }
33
34 build_cmdline()
35 {
36 local plugin= p=
37 # Add "priority" plugins.
38 for plugin in $VDR_PLUGIN_ORDER ; do
39 [[ -e $PLUGINDIR/libvdr-${plugin}.so$PLUGINSUF ]] && plugconf $plugin
40 done
41 # Add the rest available.
42 for plugin in $PLUGINDIR/libvdr-*.so$PLUGINSUF ; do
43 plugin=${plugin##*/libvdr-}
44 plugin=${plugin%.so$PLUGINSUF}
45 for p in $VDR_PLUGIN_ORDER ; do
46 if [[ $plugin == $p ]] ; then
47 # Already added.
48 continue 2
49 fi
50 done
51 plugconf $plugin
52 done
53 }
54
55 reload_dvb()
56 {
57 local modules=$( /sbin/lsmod | \
58 awk '/^dvb_core/ { gsub(","," ",$4) ; print $4 }' )
59 if [[ $modules ]] ; then
60 log "Reloading DVB modules"
61 /sbin/modprobe -r $modules dvb_core
62 for module in $modules ; do
63 /sbin/modprobe $module
64 done
65 fi
66 }
67
68 rc=
69 while true ; do
70 VDR_OPTIONS=()
71 [[ -f /etc/sysconfig/vdr ]] && . /etc/sysconfig/vdr
72 [[ $DAEMON_COREFILE_LIMIT ]] && \
73 ulimit -S -c $DAEMON_COREFILE_LIMIT &>/dev/null && \
74 VDR_OPTIONS+=( --userdump ) && cd ${TMPDIR:-/tmp}
75 build_cmdline
76
77 $VDR "$@" "${VDR_OPTIONS[@]}"
78 rc=$?
79
80 # 137: "kill -KILL" eg in killproc(), others: "man vdr"
81 case $rc in
82 0|2|137)
83 log "VDR exited with status $rc, exiting"
84 break
85 ;;
86 *)
87 log "VDR exited with status $rc, attempting restart"
88 case $RELOAD_DVB in yes|true|1) reload_dvb ;; esac
89 ;;
90 esac
91
92 done
93
94 exit $rc