C't-VDR - Hooks

Aus VDR Wiki
(Unterschied zwischen Versionen)
Wechseln zu: Navigation, Suche
(Aufnahmen Schreibrechte zuweisen)
K (Hob den Schutz von „C't-VDR - Hooks“ auf)
 
(9 dazwischenliegende Versionen von 3 Benutzern werden nicht angezeigt)
Zeile 13: Zeile 13:
 
=recording-hooks=
 
=recording-hooks=
 
Recording Hooks befinden sich meistens in dem Verzeichnis  
 
Recording Hooks befinden sich meistens in dem Verzeichnis  
  /usr/share/vdrdevel/recording-hooks  
+
  /usr/share/vdr/recording-hooks  
oder  
+
oder in der devel-Version unter
  /usr/share/vdr/recording-hooks
+
  /usr/share/vdrdevel/recording-hooks
  
 
Beschreibung:
 
Beschreibung:
  
This is a custom Recording Action Hook. It gets called by vdrdevel
+
This is a custom Recording Action Hook. It gets called by vdr
 
before a recording starts, after a recording ended and after a
 
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
+
recording has been edited. It is maintained as a config file in the vdr
 
package. All other recording hooks get executed before this one!
 
package. All other recording hooks get executed before this one!
  
 
If you want to create your own recording hook that may get executed
 
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
+
before any other hook, create it in /usr/share/vdr/recording-hooks or
 
link to this location. All hooks are called in their alphabetical
 
link to this location. All hooks are called in their alphabetical
 
order and should follow this naming scheme:
 
order and should follow this naming scheme:
Zeile 104: Zeile 104:
  
 
{{Box Datei|/usr/share/vdr/shutdown-hooks/S40.imapmail|<pre>
 
{{Box Datei|/usr/share/vdr/shutdown-hooks/S40.imapmail|<pre>
<nowiki> #!/bin/sh
+
<nowiki>#!/bin/sh
# Imap checking script
+
# Imap checking script
  
ps -ae | grep -q imap  
+
ps -ae | grep -q imap  
+
if [ $? -eq 0 ] ; then
if [ $? -eq 0 ] ; then
+
   # wait 5 minutes
   echo "waitung 5 minutes"
+
   echo "TRY_AGAIN=5"
   TRY_AGAIN=5
+
  EXITSTATUS=1
fi
+
else
 +
  EXITSTATUS=0
 +
fi
 +
exit $EXITSTATUS
 
</nowiki></pre>}}
 
</nowiki></pre>}}
  
[[Kategorie:C't-VDR|Hooks]]
+
===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, 12: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