]>
Commit | Line | Data |
---|---|---|
e20d949d MT |
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 | set_rtcwake() | |
69 | { | |
70 | # Check timestamp set by shutdown script. | |
71 | local nexttimer=$( cat /var/run/vdr/next-timer 2>/dev/null ) | |
72 | rm -f /var/run/vdr/next-timer | |
73 | ||
74 | if [[ $nexttimer != +([0-9]) ]] ; then | |
75 | # Next timer timestamp not set by shutdown script or bogus, | |
76 | # try to get it via SVDRP. | |
77 | nexttimer=$( svdrpsend NEXT abs 2>/dev/null | \ | |
78 | sed -rne 's/^250[[:space:]]+[0-9]+[[:space:]]+([0-9]+).*/\1/p' ) | |
79 | fi | |
80 | ||
81 | if [[ $nexttimer && $nexttimer -gt $( date +%s ) ]] ; then | |
82 | [[ -f /etc/sysconfig/vdr ]] && . /etc/sysconfig/vdr | |
83 | local when=$(( $nexttimer - ${WAKEUP_BEFORE_RECORDING:-10} * 60 )) | |
84 | local hrwhen=$( date -d "1970-01-01 $when sec UTC" ) | |
85 | log "Setting wakeup time for next recording: $hrwhen" | |
86 | /usr/sbin/rtcwake -m no -t $when >/dev/null | |
87 | fi | |
88 | } | |
89 | ||
90 | if [[ $1 == --set-wakeup ]] ; then | |
91 | # Just set RTC wakeup for next timer event. | |
92 | set_rtcwake | |
93 | exit $? | |
94 | fi | |
95 | ||
96 | rc= | |
97 | while true ; do | |
98 | ||
99 | VDR_OPTIONS=() | |
100 | if [[ $VDR_INIT ]] ; then | |
101 | [[ -f /etc/sysconfig/vdr ]] && . /etc/sysconfig/vdr | |
102 | [[ $DAEMON_COREFILE_LIMIT ]] && \ | |
103 | ulimit -S -c $DAEMON_COREFILE_LIMIT &>/dev/null && \ | |
104 | VDR_OPTIONS+=( --userdump ) && cd ${TMPDIR:-/tmp} | |
105 | build_cmdline | |
106 | fi | |
107 | ||
108 | $VDR "$@" "${VDR_OPTIONS[@]}" | |
109 | rc=$? | |
110 | ||
111 | # 137: "kill -KILL" eg in killproc(), others: "man vdr" | |
112 | case $rc in | |
113 | 0|2|137) | |
114 | log "VDR exited with status $rc, exiting" | |
115 | break | |
116 | ;; | |
117 | *) | |
118 | log "VDR exited with status $rc, attempting restart" | |
119 | case $RELOAD_DVB in yes|true|1) reload_dvb ;; esac | |
120 | ;; | |
121 | esac | |
122 | ||
123 | done | |
124 | ||
125 | exit $rc |