From 5372f8d4aa275f25ab0de93aacae41636a94c4d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Serhat=20G=C3=BCl=C3=A7i=C3=A7ek?= Date: Sun, 23 Dec 2012 18:16:45 +0100 Subject: [PATCH 01/73] Fix substitution errors with non-bash shells The scripts has the hashbang for /bin/sh, I assume for portability reasons. Some unix systems symlink sh to bash, others like Ubuntu (in my case) symlink sh to dash or some other basic shell which do not support the variable substitution. This is used for sending mail at this moment. For portability reasons I check if we're in a bash shell, if so use the bash variable substitution as this is available/faster than an external command. If not as fallback sed will be used, which most of the cases is present also. Even busybox has some basic sed available. This will maximize portability usage of this script. --- .../9.0/bin/nzbget-postprocess.sh | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/nzbget-postprocessing-files/9.0/bin/nzbget-postprocess.sh b/nzbget-postprocessing-files/9.0/bin/nzbget-postprocess.sh index 0beebb18..df854d76 100644 --- a/nzbget-postprocessing-files/9.0/bin/nzbget-postprocess.sh +++ b/nzbget-postprocessing-files/9.0/bin/nzbget-postprocess.sh @@ -155,6 +155,19 @@ nzbToMedia() { fi } +replaceVarBy() { + if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: Executing function 'replaceVarBy'. Going to replace '${2}' in '${1}' by '${3}'" ; fi + + # If we're not using Bash use sed, as we need to support as much as systems possible, also those running sh/dash etc + if [ -n "${BASH_VERSION}" ]; then + REPLACEDRESULT="${1/${2}/${3}}" + else + REPLACEDRESULT=$(echo "${1}" | sed "s/${2}/${3}/") + fi + + if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: replace result: ${REPLACEDRESULT}" ; fi +} + # Pass on postprocess exit codes to external scripts for handling failed downloads do_exit() { if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: Executing function 'do_exit' with argument $1" ; fi @@ -162,24 +175,31 @@ do_exit() { if [ "$1" -ne "$POSTPROCESS_SUCCESS" ]; then nzbStatus=1 ; fi script=none nzbToMedia $nzbStatus - Email_Subject="${Email_Subject//$NZBPP_NZBFILENAME}" - Email_Subject="${Email_Subject//$NZBPP_CATEGORY}" - Email_Subject="${Email_Subject/