Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow naming scheme #5

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions debian/merge-commands.sh
Original file line number Diff line number Diff line change
@@ -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 <cmdtype>.<name>.conf files into one <cmdtype>.conf
# Merges single <cmdtype>.<name>.conf files into one <cmdtype>.conf
# in alphabetical order
#

. /usr/lib/vdr/config-loader.sh
source /usr/lib/vdr/config-loader.sh

writewarning ()
{
f_writewarning() {
cat > "$2" <<EOF
# This file is automatically generated by the vdr init-script. You can
# define custom commands in /etc/vdr/command-hooks/$1.custom.conf
Expand All @@ -17,9 +17,12 @@ cat > "$2" <<EOF
EOF
}

cmdtype=$1
cmdfile="/var/cache/vdr/$cmdtype.conf"
cmdtype="$1"
cmdfile="/var/cache/vdr/${cmdtype}.conf"

writewarning $cmdtype "$cmdfile"
f_writewarning "$cmdtype" "$cmdfile"

find $CMDHOOKSDIR -maxdepth 1 -name "$cmdtype.*.conf" | sort | xargs cat >> "$cmdfile"
shopt -s nullglob # In case of no matches

# Only match '<cmdtype>.<name>.conf'
cat "${CMDHOOKSDIR}/${cmdtype}".*.conf > "$cmdfile"
37 changes: 20 additions & 17 deletions debian/vdr-recordingaction
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash
#
# VDR Recording Action Script - Tobias Grimm <[email protected]>
# ---------------------------
Expand All @@ -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<XX>.<identifier>'
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
90 changes: 50 additions & 40 deletions debian/vdr-shutdown
Original file line number Diff line number Diff line change
@@ -1,54 +1,64 @@
#!/bin/sh
#!/usr/bin/env bash
#
# VDR Shutdown Script - Tobias Grimm <[email protected]>
# -------------------
#
# see README.Debian
#
# These hooks are called in their alphabetical order and should follow
# this naming scheme:
#
# S<XX>.<identifier>
#
# Where <XX> is a two digit number, that mainly specifies the execution order
# and <identifier> 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<XX>.<identifier>'
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" &