From f222a49570313b1c1032805cb956d3429b67ca55 Mon Sep 17 00:00:00 2001 From: MegaV0lt Date: Sat, 15 Apr 2023 11:57:14 +0200 Subject: [PATCH 1/8] Update vdr-recordingaction Respect naming scheme vor recordinkhooks. It was not possible to dsable a recordinghook by renaming --- debian/vdr-recordingaction | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/debian/vdr-recordingaction b/debian/vdr-recordingaction index 5828b9a..c877da9 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 From 6038442bd12ceeac916b4b43558cd1f2bb449907 Mon Sep 17 00:00:00 2001 From: MegaV0lt Date: Sat, 15 Apr 2023 12:09:27 +0200 Subject: [PATCH 2/8] Update vdr-recordingaction Typo --- debian/vdr-recordingaction | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/vdr-recordingaction b/debian/vdr-recordingaction index c877da9..9cfb139 100755 --- a/debian/vdr-recordingaction +++ b/debian/vdr-recordingaction @@ -48,5 +48,5 @@ for rec_hook in "${REC_HOOKS_DIR}"/R[0-9][0-9].* ; do # Only match 'R. Date: Sat, 15 Apr 2023 12:14:18 +0200 Subject: [PATCH 3/8] Update vdr-recordingaction Add some quotes --- debian/vdr-recordingaction | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/debian/vdr-recordingaction b/debian/vdr-recordingaction index 9cfb139..5bfb716 100755 --- a/debian/vdr-recordingaction +++ b/debian/vdr-recordingaction @@ -41,12 +41,12 @@ for rec_hook in "${REC_HOOKS_DIR}"/R[0-9][0-9].* ; do # Only match 'R. Date: Sun, 16 Apr 2023 11:16:26 +0200 Subject: [PATCH 4/8] Update vdr-shutdown Follow naming scheme --- debian/vdr-shutdown | 90 +++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/debian/vdr-shutdown b/debian/vdr-shutdown index b2a1739..d1b1cd6 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 abgebruchen! Neuer Versuch in $TRY_AGAIN Minuten" & + exit 0 + fi done -eval $SHUTDOWNCMD & +eval "$SHUTDOWNCMD" & + From 1a3e2518b2506859d741ca90c121abf0247a66a9 Mon Sep 17 00:00:00 2001 From: MegaV0lt Date: Tue, 18 Apr 2023 14:53:11 +0200 Subject: [PATCH 5/8] Update merge-commands.sh Eliminate use of external 'find' and 'sort' --- debian/merge-commands.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/debian/merge-commands.sh b/debian/merge-commands.sh index 7b47011..820c328 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 + +for cmd in "${CMDHOOKSDIR}/${cmdtype}".*.conf ; do # Only match '..conf' + cat "$cmd" >> "$cmdfile" +done From 0d61100bbdf07e33185720ce78a1203f301aaf41 Mon Sep 17 00:00:00 2001 From: MegaV0lt Date: Tue, 18 Apr 2023 14:56:38 +0200 Subject: [PATCH 6/8] Update merge-commands.sh --- debian/merge-commands.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/merge-commands.sh b/debian/merge-commands.sh index 820c328..356295b 100644 --- a/debian/merge-commands.sh +++ b/debian/merge-commands.sh @@ -18,7 +18,7 @@ EOF } cmdtype="$1" -cmdfile="/var/cache/vdr/$cmdtype.conf" +cmdfile="/var/cache/vdr/${cmdtype}.conf" f_writewarning "$cmdtype" "$cmdfile" From ada7261b09757e2223fd1c0fbadf6d08489313db Mon Sep 17 00:00:00 2001 From: MegaV0lt Date: Tue, 18 Apr 2023 14:58:12 +0200 Subject: [PATCH 7/8] Update vdr-shutdown Fix typo --- debian/vdr-shutdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/vdr-shutdown b/debian/vdr-shutdown index d1b1cd6..20e46bc 100755 --- a/debian/vdr-shutdown +++ b/debian/vdr-shutdown @@ -55,7 +55,7 @@ for shutdown_hook in "${SHUTDOWN_HOOKS_DIR}"/S[0-9][0-9].* ; do # Only match 'S 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 abgebruchen! Neuer Versuch in $TRY_AGAIN Minuten" & + f_osdmsg "Shutdown abgebrochen! Neuer Versuch in $TRY_AGAIN Minuten" & exit 0 fi done From 92362d94fdf30135f4c22d5bcf3e2a7f95bab44c Mon Sep 17 00:00:00 2001 From: MegaV0lt Date: Tue, 18 Apr 2023 15:09:20 +0200 Subject: [PATCH 8/8] Update merge-commands.sh Remove 'for' loop as it is not needed --- debian/merge-commands.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/debian/merge-commands.sh b/debian/merge-commands.sh index 356295b..67e539c 100644 --- a/debian/merge-commands.sh +++ b/debian/merge-commands.sh @@ -24,6 +24,5 @@ f_writewarning "$cmdtype" "$cmdfile" shopt -s nullglob # In case of no matches -for cmd in "${CMDHOOKSDIR}/${cmdtype}".*.conf ; do # Only match '..conf' - cat "$cmd" >> "$cmdfile" -done +# Only match '..conf' +cat "${CMDHOOKSDIR}/${cmdtype}".*.conf > "$cmdfile"