PageRenderTime 38ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/vdr-devel/vdr-runvdr.sh

https://bitbucket.org/kaendfinger/aur-mirror
Shell | 125 lines | 96 code | 17 blank | 12 comment | 25 complexity | e867e399822ca441e60c8daa7867ba11 MD5 | raw file
Possible License(s): LGPL-2.0, Unlicense, AGPL-1.0, BitTorrent-1.0, EPL-1.0, GPL-3.0, BSD-3-Clause, GPL-2.0, MIT, CC-BY-SA-3.0, BSD-2-Clause, MPL-2.0, BSD-3-Clause-No-Nuclear-License-2014, JSON, AGPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0, LGPL-2.1, ISC, CC-BY-3.0, WTFPL, 0BSD, CC0-1.0, LGPL-3.0, Cube, Apache-2.0
  1. #!/bin/bash
  2. # runvdr - VDR launcher
  3. #
  4. # runvdr [VDROPTION]...
  5. shopt -s extglob nocasematch nullglob
  6. VDR=/usr/sbin/vdr
  7. PLUGINDIR=/usr/lib/vdr
  8. PLUGINVER=VDR_PLUGIN_VERSION
  9. PLUGINSUF=${PLUGINVER:+.$PLUGINVER}
  10. log()
  11. {
  12. type -P logger &>/dev/null && \
  13. logger -s -p daemon.info -t ${0##*/} "$1" 2>&1 || echo "INFO: $1"
  14. }
  15. plugconf()
  16. {
  17. local plugin=$1 PLUGIN_OPTIONS= PLUGIN_ENABLED=
  18. if [[ -e /etc/vdr/vdr-plugins.d/$plugin.conf ]] ; then
  19. . /etc/vdr/vdr-plugins.d/$plugin.conf
  20. case $PLUGIN_ENABLED in no|false|0) return ;; esac
  21. fi
  22. if [[ $PLUGIN_OPTIONS ]] ; then
  23. VDR_OPTIONS+=( --plugin="$plugin $PLUGIN_OPTIONS" )
  24. else
  25. VDR_OPTIONS+=( --plugin=$plugin )
  26. fi
  27. }
  28. build_cmdline()
  29. {
  30. local plugin= p=
  31. # Add "priority" plugins.
  32. for plugin in $VDR_PLUGIN_ORDER ; do
  33. [[ -e $PLUGINDIR/libvdr-${plugin}.so$PLUGINSUF ]] && plugconf $plugin
  34. done
  35. # Add the rest available.
  36. for plugin in $PLUGINDIR/libvdr-*.so$PLUGINSUF ; do
  37. plugin=${plugin##*/libvdr-}
  38. plugin=${plugin%.so$PLUGINSUF}
  39. for p in $VDR_PLUGIN_ORDER ; do
  40. if [[ $plugin == $p ]] ; then
  41. # Already added.
  42. continue 2
  43. fi
  44. done
  45. plugconf $plugin
  46. done
  47. }
  48. reload_dvb()
  49. {
  50. local modules=$( /sbin/lsmod | \
  51. awk '/^dvb_core/ { gsub(","," ",$4) ; print $4 }' )
  52. if [[ $modules ]] ; then
  53. log "Reloading DVB modules"
  54. /sbin/modprobe -r $modules dvb_core
  55. for module in $modules ; do
  56. /sbin/modprobe $module
  57. done
  58. fi
  59. }
  60. set_rtcwake()
  61. {
  62. # Check timestamp set by shutdown script.
  63. local nexttimer=$( cat /var/run/vdr/next-timer 2>/dev/null )
  64. rm -f /var/run/vdr/next-timer
  65. if [[ $nexttimer != +([0-9]) ]] ; then
  66. # Next timer timestamp not set by shutdown script or bogus,
  67. # try to get it via SVDRP.
  68. nexttimer=$( svdrpsend NEXT abs 2>/dev/null | \
  69. sed -rne 's/^250[[:space:]]+[0-9]+[[:space:]]+([0-9]+).*/\1/p' )
  70. fi
  71. if [[ $nexttimer && $nexttimer -gt $( date +%s ) ]] ; then
  72. [[ -f /etc/vdr/vdr ]] && . /etc/vdr/vdr
  73. local when=$(( $nexttimer - ${WAKEUP_BEFORE_RECORDING:-10} * 60 ))
  74. local hrwhen=$( date -d "1970-01-01 $when sec UTC" )
  75. log "Setting wakeup time for next recording: $hrwhen"
  76. /usr/sbin/rtcwake -m no -t $when >/dev/null
  77. fi
  78. }
  79. if [[ $1 == --set-wakeup ]] ; then
  80. # Just set RTC wakeup for next timer event.
  81. set_rtcwake
  82. exit $?
  83. fi
  84. rc=
  85. while true ; do
  86. VDR_OPTIONS=()
  87. if [[ $VDR_INIT ]] ; then
  88. [[ -f /etc/vdr/vdr ]] && . /etc/vdr/vdr
  89. [[ $DAEMON_COREFILE_LIMIT ]] && \
  90. ulimit -S -c $DAEMON_COREFILE_LIMIT &>/dev/null && \
  91. VDR_OPTIONS+=( --userdump ) && cd ${TMPDIR:-/tmp}
  92. build_cmdline
  93. fi
  94. $VDR "$@" "${VDR_OPTIONS[@]}"
  95. rc=$?
  96. # 137: "kill -KILL" eg in killproc(), others: "man vdr"
  97. case $rc in
  98. 0|2|137)
  99. log "VDR exited with status $rc, exiting"
  100. break
  101. ;;
  102. *)
  103. log "VDR exited with status $rc, attempting restart"
  104. case $RELOAD_DVB in yes|true|1) reload_dvb ;; esac
  105. ;;
  106. esac
  107. done
  108. exit $rc