From 1031e3ae1d284a05f00cadaeeb801fe5cb0365ff Mon Sep 17 00:00:00 2001 From: Me Date: Wed, 14 Mar 2018 16:46:45 +0100 Subject: [PATCH 1/2] chg: use authcode file located in HOME dir. Signed-off-by: Me --- AAXtoMP3 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index c743d07..6dcb82b 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -5,6 +5,7 @@ set -o errexit -o noclobber -o nounset -o pipefail codec=libmp3lame extension=mp3 mode=chaptered +authcodeFile="${HOME}/.authcode"; GREP=$(grep --version | grep -q GNU && echo "grep" || echo "ggrep") if ! [[ $(type -P "$GREP") ]]; then @@ -47,11 +48,11 @@ then shift fi -if [ ! -f .authcode ]; then +if [ ! -f "$authcodeFile" ]; then auth_code=$1 shift else - auth_code=`head -1 .authcode` + auth_code=`head -1 "$authcodeFile"` fi debug() { From 15945b18b1e0c4aa6e033ea98fa90122d01aab23 Mon Sep 17 00:00:00 2001 From: Me Date: Thu, 15 Mar 2018 00:35:57 +0100 Subject: [PATCH 2/2] chg: search HOME and local dir for authcode file in this order, first occurence accepted. Signed-off-by: Me --- AAXtoMP3 | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index 6dcb82b..d1bb0a3 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -5,7 +5,8 @@ set -o errexit -o noclobber -o nounset -o pipefail codec=libmp3lame extension=mp3 mode=chaptered -authcodeFile="${HOME}/.authcode"; +authcode=".authcode"; +authcodeDirs="${HOME}/ ./"; GREP=$(grep --version | grep -q GNU && echo "grep" || echo "ggrep") if ! [[ $(type -P "$GREP") ]]; then @@ -48,12 +49,26 @@ then shift fi -if [ ! -f "$authcodeFile" ]; then - auth_code=$1 - shift -else - auth_code=`head -1 "$authcodeFile"` -fi +auth_code=""; +for dir in $authcodeDirs; do + codeFile="${dir}$authcode"; + + if [ ! -f "$codeFile" ]; then + auth_code=$1 + shift + break; + elif [ -s "$codeFile" ]; then + auth_code=`head -1 "$codeFile"` + break; + else + echo "INFO: Sorry, empty \"$codeFile\" found, skipping."; + fi; +done; + +if [ -z "$auth_code" ]; then + echo "INFO: Sorry, no authcode provided."; + exit 1; +fi; debug() { echo "$(date "+%F %T%z") ${1}"