diff --git a/debian/merge-commands.sh b/debian/merge-commands.sh index 7b47011..67e539c 100644 --- a/debian/merge-commands.sh +++ b/debian/merge-commands.sh @@ -1,14 +1,14 @@ +#!/usr/bin/env bash # -# This file is called by /etc/init.d/vdr and the by vdr.service +# This file is called by /etc/init.d/vdr and by vdr.service # -# merges single ..conf files into one .conf +# Merges single ..conf files into one .conf # in alphabetical order # -. /usr/lib/vdr/config-loader.sh +source /usr/lib/vdr/config-loader.sh -writewarning () -{ +f_writewarning() { cat > "$2" < "$2" <> "$cmdfile" +shopt -s nullglob # In case of no matches + +# Only match '..conf' +cat "${CMDHOOKSDIR}/${cmdtype}".*.conf > "$cmdfile" diff --git a/debian/vdr-recordingaction b/debian/vdr-recordingaction index 5828b9a..5bfb716 100755 --- a/debian/vdr-recordingaction +++ b/debian/vdr-recordingaction @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash # # VDR Recording Action Script - Tobias Grimm # --------------------------- @@ -24,26 +24,29 @@ # Parameter 2 is the directory of the recording. Be aware, that this directory # doesn't exist before the recording starts. # +# VERSION=230415 -REC_HOOKS_DIR=/usr/share/vdr/recording-hooks +SELF="$(readlink /proc/$$/fd/255)" || SELF="$0" # Path ($0) +SELF_NAME="${SELF##*/}" # Scriptname +REC_HOOKS_DIR='/usr/share/vdr/recording-hooks' -recordinghooks=`find $REC_HOOKS_DIR -maxdepth 1 -xtype f | sort` +shopt -s nullglob # In case of no matches -for recordinghook in $recordinghooks; do - case $1 in - before|after) - action="$1 recording $2" - ;; - edited) - action="after cutting recording $2 from $3" - ;; +for rec_hook in "${REC_HOOKS_DIR}"/R[0-9][0-9].* ; do # Only match 'R.' + case $1 in + before|after) + action="$1 recording $2" + ;; + edited) + action="after cutting recording $2 from $3" + ;; esac - if [ -x $recordinghook ]; then - logger -t recordingaction "executing $recordinghook $action" - $recordinghook "$@" + if [[ -x "$rec_hook" ]] ; then + logger -t "$SELF_NAME" "Executing $rec_hook $action" + "$rec_hook" "$@" else - logger -t recordingaction "executing $recordinghook $action as shell script" - /bin/sh $recordinghook "$@" + logger -t "$SELF_NAME" "Executing $rec_hook $action as shell script" + /usr/bin/sh "$rec_hook" "$@" fi - [ $? -ne 0 ] && logger -t recordingaction "error when executing $recordinghook" + [[ $? -ne 0 ]] && logger -t "$SELF_NAME" "Error when executing $rec_hook" done diff --git a/debian/vdr-shutdown b/debian/vdr-shutdown index b2a1739..20e46bc 100755 --- a/debian/vdr-shutdown +++ b/debian/vdr-shutdown @@ -1,54 +1,64 @@ -#!/bin/sh +#!/usr/bin/env bash # # VDR Shutdown Script - Tobias Grimm # ------------------- # # see README.Debian # +# These hooks are called in their alphabetical order and should follow +# this naming scheme: +# +# S. +# +# Where is a two digit number, that mainly specifies the execution order +# and is a unique descriptor. +# +# VERSION=230416 -. /usr/lib/vdr/config-loader.sh +source /usr/lib/vdr/config-loader.sh -SHUTDOWN_HOOKS_DIR=/usr/share/vdr/shutdown-hooks/ +SHUTDOWN_HOOKS_DIR='/usr/share/vdr/shutdown-hooks' +svdrpsend='/usr/bin/svdrpsend' -log="logger -t vdr-shutdown" -svdrpsend="/usr/bin/svdrpsend" +f_log() { + logger -t 'vdr-shutdown' "$*" +} -osdmsg() -{ - # OSD message must be deferred, to let VDR display it AFTER the - # shutdown script has been executed - sleep 2 - $svdrpsend MESG "$1" +f_osdmsg() { + # OSD message must be deferred, to let VDR display it AFTER the + # shutdown script has been executed + sleep 2 + "$svdrpsend" MESG "$1" } -shutdownhooks=`find $SHUTDOWN_HOOKS_DIR -maxdepth 1 -xtype f | sort` - -for shutdownhook in $shutdownhooks; do - TRY_AGAIN=0 - - if [ -x $shutdownhook ]; then - $log "executing $shutdownhook" - result_data=`$shutdownhook "$@"` - else - $log "executing $shutdownhook as shell script" - result_data=`/bin/sh $shutdownhook "$@"` - fi - result=$? - eval $result_data - if [ $result -ne 0 ] ; then - $log "Shutdown aborted by $shutdownhook with exitcode $result" - osdmsg "Shutdown abgebrochen / Shutdown aborted!" & - [ -z "$ABORT_MESSAGE" ] || osdmsg "$ABORT_MESSAGE" & - exit $result - fi - - if [ $TRY_AGAIN -gt 0 ] - then - $log "$shutdownhook requests to try again in $TRY_AGAIN minutes" - nohup sh -c "( sleep $(( $TRY_AGAIN * 60 )) && $svdrpsend \"HITK Power\" )" >/dev/null 2>&1 & - osdmsg "Shutdown aborted. Retry in $TRY_AGAIN minutes." & - exit 0 - fi +shopt -s nullglob # In case of no matches + +for shutdown_hook in "${SHUTDOWN_HOOKS_DIR}"/S[0-9][0-9].* ; do # Only match 'S.' + TRY_AGAIN=0 + + if [[ -x "$shutdown_hook" ]] ; then + f_log "Executing $shutdown_hook" + result_data=$("$shutdown_hook" "$@") + else + f_log "Executing $shutdown_hook as shell script" + result_data=$(/usr/bin/sh "$shutdown_hook" "$@") + fi + result=$? + eval "$result_data" + if [[ $result -ne 0 ]] ; then + f_log "Shutdown aborted by $shutdown_hook with exitcode $result" + f_osdmsg "Shutdown abgebrochen!" & + [[ -n "$ABORT_MESSAGE" ]] && f_osdmsg "$ABORT_MESSAGE" & + exit $result + fi + + if [[ $TRY_AGAIN -gt 0 ]] ; then + f_log "$shutdown_hook requests to try again in $TRY_AGAIN minutes" + nohup sh -c "(sleep $((TRY_AGAIN * 60)) && $svdrpsend \"HITK Power\")" &>/dev/null & + f_osdmsg "Shutdown abgebrochen! Neuer Versuch in $TRY_AGAIN Minuten" & + exit 0 + fi done -eval $SHUTDOWNCMD & +eval "$SHUTDOWNCMD" & +