C't-VDR - Hooks

Aus VDR Wiki
(Unterschied zwischen Versionen)
Wechseln zu: Navigation, Suche
(Aufnahmen Schreibrechte zuweisen: Box kleiner)
K (Hob den Schutz von „C't-VDR - Hooks“ auf)
 
(19 dazwischenliegende Versionen von 8 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
=Hooks=
 
 
Hooks sind kleine Scripte, die das VDR Hauptprogramm bei einer bestimmten Aktion aufruft.
 
Hooks sind kleine Scripte, die das VDR Hauptprogramm bei einer bestimmten Aktion aufruft.
 
Die einzelnen Hooks werden ähnlich wie die Init-Prozesse in verschiedenen Verzeichnissen
 
Die einzelnen Hooks werden ähnlich wie die Init-Prozesse in verschiedenen Verzeichnissen
Zeile 5: Zeile 4:
  
 
Es gibt drei Arten von Hooks:
 
Es gibt drei Arten von Hooks:
* command-hooks   
+
* command-hooks   
* recording-hooks   
+
* recording-hooks   
* shutdown-hooks
+
* shutdown-hooks
  
==command-hooks==
+
=command-hooks=
<pre>
+
==Beispiele==
#
+
# Custom VDR Shutdown Hook
+
# -------------------------
+
#
+
# Here you can place any commands, you want to be executed when VDR wants
+
# to shutdown.
+
#
+
# * To abort the shutdown, exit with an errorlevel <> 0.
+
#
+
# * If you want a message to be displayed on the OSD when aborting a shutdown,
+
#  then write to stdout:
+
#
+
#  ABORT_MESSAGE=<message to display>
+
#
+
# * If you want to defer the shutdown, write to stdout:
+
#
+
#  TRY_AGAIN=<minutes to wait before next shutdown request>
+
#
+
# * To overwrite the command that will be executed to shutdown the machine
+
#  after all shutdown hooks have been processed, write to stdout:
+
#
+
#  SHUTDOWNCMD=<new shutdown command>
+
#
+
# i.e.:
+
#
+
# echo "ABORT_MESSAGE=\"I do not want to shutdown now!\"" ; exit 1
+
#
+
  
 +
=recording-hooks=
 +
Recording Hooks befinden sich meistens in dem Verzeichnis
 +
/usr/share/vdr/recording-hooks
 +
oder in der devel-Version unter
 +
/usr/share/vdrdevel/recording-hooks
  
</pre>
+
Beschreibung:
  
 +
This is a custom Recording Action Hook. It gets called by vdr
 +
before a recording starts, after a recording ended and after a
 +
recording has been edited. It is maintained as a config file in the vdr
 +
package. All other recording hooks get executed before this one!
  
==recording-hooks==
+
If you want to create your own recording hook that may get executed
Recording Hooks befinden sich meistens in dem Verzeichnis
+
before any other hook, create it in /usr/share/vdr/recording-hooks or
/usr/share/vdrdevel/recording-hooks  
+
link to this location. All hooks are called in their alphabetical
oder
+
order and should follow this naming scheme:
/usr/share/vdr/recording-hooks
+
  
Vorlage (aus dem Verzeichnis kopiert)
+
R<XX>.<identifier>
<pre>
+
# Custom VDR Recording Action Hook
+
# ----------------------------------
+
#
+
# This is a custom Recording Action Hook. It gets called by vdrdevel
+
# before a recording starts, after a recording ended and after a
+
# recording has been edited. It is maintained as a config file in the vdrdevel
+
# package. All other recording hooks get executed before this one!
+
#
+
# If you want to create your own recording hook that may get executed
+
# before any other hook, create it in /usr/share/vdrdevel/recording-hooks or
+
# link to this location. All hooks are called in their alphabetical
+
# order and should follow this naming scheme:
+
#
+
# R<XX>.<identifier>
+
#
+
# Where <XX> is a two digit number, that mainly specifies the execution order
+
# and <identifier> is a unique descriptor.
+
#
+
# Two parameters are passed:
+
#
+
# Parameter 1 can have the values "before", "after" and "edited", depending
+
# on whether the recording hook is called before the recording starts,
+
# after the recording ends or after the recording has been edited.
+
#
+
# Parameter 2 is the directory of the recording. Be aware, that this directory
+
# doesn't exist before the recording starts.
+
#
+
  
case $1 in
+
Where <XX> is a two digit number, that mainly specifies the execution order
before)
+
and <identifier> is a unique descriptor.
# do here what ever you would like to do right BEFORE
+
# the recording $2 STARTS
+
;;
+
after)
+
# do here what ever you would like to do right AFTER
+
# the recording $2 ENDED
+
;;
+
edited)
+
# do here what ever you would like to do right AFTER
+
# the recording $2 has been EDITED
+
;;
+
esac
+
  
</pre>
+
Two parameters are passed:
  
==shutdown-hooks==
+
Parameter 1 can have the values "before", "after" and "edited", depending
 +
on whether the recording hook is called before the recording starts,
 +
after the recording ends or after the recording has been edited.
  
==Beispiel-Hooks==
+
Parameter 2 is the directory of the recording. Be aware, that this directory
 +
doesn't exist before the recording starts.
 +
 
 +
 
 +
case $1 in
 +
before)
 +
# do here what ever you would like to do right BEFORE
 +
# the recording $2 STARTS
 +
;;
 +
after)
 +
# do here what ever you would like to do right AFTER
 +
# the recording $2 ENDED
 +
;;
 +
edited)
 +
# do here what ever you would like to do right AFTER
 +
# the recording $2 has been EDITED
 +
;;
 +
esac
 +
==Beispiele==
 
===Aufnahmen Schreibrechte zuweisen===
 
===Aufnahmen Schreibrechte zuweisen===
 
Dieses kleine Script gibt dem kompletten Aufnahmeverzeichnis Schreibrechte  
 
Dieses kleine Script gibt dem kompletten Aufnahmeverzeichnis Schreibrechte  
  
{{Box Datei|/usr/share/vdrdevel/recording-hooks/R90.makepublic|
+
{{Box Datei|/usr/share/vdr/recording-hooks/R90.makepublic|
 
  #
 
  #
 
  # Vergibt Schreibrechte der Gruppe
 
  # Vergibt Schreibrechte der Gruppe
Zeile 108: Zeile 68:
 
   case $1 in
 
   case $1 in
 
     after)
 
     after)
         chmod -R g+w $2/*
+
         chmod -R g+w $2/..
        chmod g+w $2
+
 
         ;;
 
         ;;
 
  esac  
 
  esac  
 
}}
 
}}
  
Anmerkung: Entgegen einigen Behauptungen funktioniert es NICHT, den VDR Prozess mit einer bestimmten umask Einstellung zu starten. Der VDR legt beim Öffnen der Dateien explizit die Zugriffsrechte fest und überschreibt somit die umask Einstellung. Dieses Script stellt eine Alternative zum Verändern des Quelltextes dar.
+
Anmerkung: Ab der VDR-Version 1.3.28 kann die gleiche Funktionalität mit der shell-Definition per umask erreicht werden. In  älteren Versionen des VDR legt beim Öffnen der Dateien explizit die Zugriffsrechte fest und ignoriert somit die umask Einstellung. Dieses Script stellt damit für diese ältere Versionen eine Alternative zum Verändern des Quelltextes dar.
 +
 
 +
=shutdown-hooks=
 +
 
 +
 
 +
Here you can place any commands, you want to be executed when VDR wants to shutdown.
 +
 
 +
* To abort the shutdown, exit with an errorlevel <> 0.
 +
 
 +
* If you want a message to be displayed on the OSD when aborting a shutdown, then write to stdout:
 +
 
 +
ABORT_MESSAGE=<message to display>
 +
 
 +
* If you want to defer the shutdown, write to stdout:
 +
 
 +
TRY_AGAIN=<minutes to wait before next shutdown request>
 +
 
 +
* To overwrite the command that will be executed to shutdown the machine after all shutdown hooks have been processed, write to stdout:
 +
 
 +
SHUTDOWNCMD=<new shutdown command>
 +
 
 +
i.e.:
 +
 
 +
echo "ABORT_MESSAGE=\"I do not want to shutdown now!\"" ; exit 1
 +
==Beispiele==
 +
 
 +
===IMAP Mail===
 +
Dieses kleine Script hält den Shutdown Prozess an, falls noch Imap Sessions geöffnet sind.
 +
Alternativ können auch andere Prozesse überprüft werden.
 +
 
 +
{{Box Datei|/usr/share/vdr/shutdown-hooks/S40.imapmail|<pre>
 +
<nowiki>#!/bin/sh
 +
# Imap checking script
 +
 
 +
ps -ae | grep -q imap
 +
if [ $? -eq 0 ] ; then
 +
  # wait 5 minutes
 +
  echo "TRY_AGAIN=5"
 +
  EXITSTATUS=1
 +
else
 +
  EXITSTATUS=0
 +
fi
 +
exit $EXITSTATUS
 +
</nowiki></pre>}}
 +
 
 +
===ACPI Shutdown===
 +
Dieses einfache Variante eines Shutdown-Script schreibt die nächste Startzeit eines Timer in die ACPI Tabellen des Mainboards.
 +
 
 +
{{Box Datei|/usr/share/vdr/shutdown-hooks/S99.acpi-shutdown|<pre>
 +
<nowiki>#!/bin/sh
 +
# Simple ACPI shutdown hook
 +
# $1 : Next timer seconds from 1970 from 1970/01/01, UTC
 +
# $2 : Next timer seconds from now
 +
# $3 : Next timer title
 +
# $4 : Shutdown forced
 +
 
 +
DEV=/sys/class/rtc/rtc0/wakealarm
 +
 
 +
offset=`expr $2 - 180`
 +
 
 +
if [ "$offset" -lt "60" ] ; then
 +
  echo "ABORT_MESSAGE=\"Next timer following now!\""
 +
  EXITSTATUS=1
 +
else
 +
  next=$(/bin/date --date "now +$offset seconds" "+%s")
 +
  echo 0 >  $DEV
 +
  echo $next > $DEV
 +
  echo $next > $DEV
 +
  EXITSTATUS=0
 +
fi
 +
exit $EXITSTATUS
 +
</nowiki></pre>}}
 +
 
 +
[[Kategorie:C't-VDR]]
 +
[[Kategorie:Wakeup]]

Aktuelle Version vom 5. März 2011, 13:10 Uhr

Hooks sind kleine Scripte, die das VDR Hauptprogramm bei einer bestimmten Aktion aufruft. Die einzelnen Hooks werden ähnlich wie die Init-Prozesse in verschiedenen Verzeichnissen gespeichert und alphabetisch aufgerufen. Die Namen beginnen allerdings immer mit einer zweistelligen Zahl, sodass die Reihenfolge immer festliegt.

Es gibt drei Arten von Hooks:

  • command-hooks
  • recording-hooks
  • shutdown-hooks

Inhaltsverzeichnis

[Bearbeiten] command-hooks

[Bearbeiten] Beispiele

[Bearbeiten] recording-hooks

Recording Hooks befinden sich meistens in dem Verzeichnis

/usr/share/vdr/recording-hooks 

oder in der devel-Version unter

/usr/share/vdrdevel/recording-hooks

Beschreibung:

This is a custom Recording Action Hook. It gets called by vdr before a recording starts, after a recording ended and after a recording has been edited. It is maintained as a config file in the vdr package. All other recording hooks get executed before this one!

If you want to create your own recording hook that may get executed before any other hook, create it in /usr/share/vdr/recording-hooks or link to this location. All hooks are called in their alphabetical order and should follow this naming scheme:

R<XX>.<identifier>

Where <XX> is a two digit number, that mainly specifies the execution order and <identifier> is a unique descriptor.

Two parameters are passed:

Parameter 1 can have the values "before", "after" and "edited", depending on whether the recording hook is called before the recording starts, after the recording ends or after the recording has been edited.

Parameter 2 is the directory of the recording. Be aware, that this directory doesn't exist before the recording starts.


case $1 in
	before)
		# do here what ever you would like to do right BEFORE
		# the recording $2 STARTS
		;;
	after)
		# do here what ever you would like to do right AFTER
		# the recording $2 ENDED
		;;
	edited)
		# do here what ever you would like to do right AFTER
		# the recording $2 has been EDITED
		;;
esac

[Bearbeiten] Beispiele

[Bearbeiten] Aufnahmen Schreibrechte zuweisen

Dieses kleine Script gibt dem kompletten Aufnahmeverzeichnis Schreibrechte

Datei
/usr/share/vdr/recording-hooks/R90.makepublic
#
# Vergibt Schreibrechte der Gruppe
# ----------------------------------
 case $1 in
    after)
        chmod -R g+w $2/..
        ;;
esac 


Anmerkung: Ab der VDR-Version 1.3.28 kann die gleiche Funktionalität mit der shell-Definition per umask erreicht werden. In älteren Versionen des VDR legt beim Öffnen der Dateien explizit die Zugriffsrechte fest und ignoriert somit die umask Einstellung. Dieses Script stellt damit für diese ältere Versionen eine Alternative zum Verändern des Quelltextes dar.

[Bearbeiten] shutdown-hooks

Here you can place any commands, you want to be executed when VDR wants to shutdown.

  • To abort the shutdown, exit with an errorlevel <> 0.
  • If you want a message to be displayed on the OSD when aborting a shutdown, then write to stdout:
ABORT_MESSAGE=<message to display>
  • If you want to defer the shutdown, write to stdout:
TRY_AGAIN=<minutes to wait before next shutdown request>
  • To overwrite the command that will be executed to shutdown the machine after all shutdown hooks have been processed, write to stdout:
SHUTDOWNCMD=<new shutdown command>

i.e.:

echo "ABORT_MESSAGE=\"I do not want to shutdown now!\"" ; exit 1

[Bearbeiten] Beispiele

[Bearbeiten] IMAP Mail

Dieses kleine Script hält den Shutdown Prozess an, falls noch Imap Sessions geöffnet sind. Alternativ können auch andere Prozesse überprüft werden.

Datei
/usr/share/vdr/shutdown-hooks/S40.imapmail
#!/bin/sh
# Imap checking script

ps -ae | grep -q imap 
if [ $? -eq 0 ] ; then
   # wait 5 minutes
   echo "TRY_AGAIN=5"
   EXITSTATUS=1
else
   EXITSTATUS=0
fi
exit $EXITSTATUS


[Bearbeiten] ACPI Shutdown

Dieses einfache Variante eines Shutdown-Script schreibt die nächste Startzeit eines Timer in die ACPI Tabellen des Mainboards.

Datei
/usr/share/vdr/shutdown-hooks/S99.acpi-shutdown
#!/bin/sh 
# Simple ACPI shutdown hook
# $1 : Next timer seconds from 1970 from 1970/01/01, UTC
# $2 : Next timer seconds from now
# $3 : Next timer title
# $4 : Shutdown forced

DEV=/sys/class/rtc/rtc0/wakealarm

offset=`expr $2 - 180`

if [ "$offset" -lt "60" ] ; then
  echo "ABORT_MESSAGE=\"Next timer following now!\""
  EXITSTATUS=1
else 
  next=$(/bin/date --date "now +$offset seconds" "+%s")
  echo 0 >  $DEV
  echo $next > $DEV
  echo $next > $DEV
  EXITSTATUS=0
fi
exit $EXITSTATUS