From 98393cacef27eafd371b26427cb2c53884caf065 Mon Sep 17 00:00:00 2001 From: Reto Kromer Date: Sat, 1 Oct 2016 07:33:22 +0200 Subject: [PATCH 1/8] housekeeping - possibly last changes... before using getopt. --- check_framemd5.sh | 52 ++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/check_framemd5.sh b/check_framemd5.sh index 8f5f44f..2b7b3c4 100644 --- a/check_framemd5.sh +++ b/check_framemd5.sh @@ -1,19 +1,25 @@ #!/usr/bin/env bash SCRIPT=$(basename "${0}") - VERSION='2016-07-25' + VERSION='2016-10-01' AUTHOR='ffmprovisr' RED='\033[1;31m' - BLUE='\033[1;34m' + BLUE='\033[1;34m' NC='\033[0m' -_output_prompt() { - cat < ] -END_OF_MSG +EOF + exit 1 } -_output_help() { - cat < Date: Sat, 1 Oct 2016 16:32:29 +0200 Subject: [PATCH 2/8] Update check_framemd5.sh --- check_framemd5.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_framemd5.sh b/check_framemd5.sh index 2b7b3c4..f427fd6 100644 --- a/check_framemd5.sh +++ b/check_framemd5.sh @@ -7,7 +7,7 @@ NC='\033[0m' if [[ $OSTYPE = "cygwin" ]] || [ ! $(which diff) ]; then - echo -e "${RED}ERROR:${NC} diff is not installed by default. Please install diffutils from Cygwin." + echo -e "${RED}ERROR:${NC} 'diff' is not installed by default. Please install 'diffutils' from Cygwin." exit 1 fi From c715431c370d2a96096ebf282b8a9717094c64ea Mon Sep 17 00:00:00 2001 From: Reto Kromer Date: Sat, 1 Oct 2016 17:20:00 +0200 Subject: [PATCH 3/8] uniforming --- check_framemd5.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/check_framemd5.sh b/check_framemd5.sh index f427fd6..3c1dd07 100644 --- a/check_framemd5.sh +++ b/check_framemd5.sh @@ -48,10 +48,10 @@ elif [ "${#}" -eq 1 ]; then _output_prompt fi elif [ "${#}" -eq 2 ]; then - if ! [ -f "${1}" ]; then + if [[ ! -f "${1}" ]]; then echo -e "${RED}ERROR:${NC} There is no file '$(basename ${1})'." _output_prompt - elif ! [ -f "${2}" ]; then + elif [[ ! -f "${2}" ]]; then echo -e "${RED}ERROR:${NC} There is no file '$(basename ${2})'." _output_prompt else @@ -63,7 +63,7 @@ elif [ "${#}" -eq 2 ]; then md5_tmp="${HOME}/$(basename ${2}).tmp" fi $(ffmpeg -y -i ${1} -loglevel 0 -f framemd5 -an ${md5_tmp}) - if ! [ -f ${md5_tmp} ]; then + if [[ ! -f ${md5_tmp} ]]; then echo -e "${RED}ERROR:${NC} '$(basename ${1})' is not an audio-visual file." output_prompt fi From 1577451a412287de9d89ff30c83eee8b838440d9 Mon Sep 17 00:00:00 2001 From: Reto Kromer Date: Sat, 1 Oct 2016 17:34:38 +0200 Subject: [PATCH 4/8] uniforming --- check_framemd5.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/check_framemd5.sh b/check_framemd5.sh index 3c1dd07..facc67c 100644 --- a/check_framemd5.sh +++ b/check_framemd5.sh @@ -37,17 +37,17 @@ EOF exit 0 } -if [ "${#}" -eq 0 ]; then +if [[ "${#}" -eq 0 ]]; then _output_prompt exit 0 -elif [ "${#}" -eq 1 ]; then +elif [[ "${#}" -eq 1 ]]; then if [[ "${1}" = '-h' ]]; then _output_help else echo -e "${RED}ERROR:${NC} '$1' is an invalid argument." _output_prompt fi -elif [ "${#}" -eq 2 ]; then +elif [[ "${#}" -eq 2 ]]; then if [[ ! -f "${1}" ]]; then echo -e "${RED}ERROR:${NC} There is no file '$(basename ${1})'." _output_prompt From 5fd84ee1d738dfccecf75ec18f2eb7cee8fed8f7 Mon Sep 17 00:00:00 2001 From: Reto Kromer Date: Sun, 2 Oct 2016 20:58:17 +0200 Subject: [PATCH 5/8] now with `getopts` --- check_framemd5.sh | 81 ++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 46 deletions(-) diff --git a/check_framemd5.sh b/check_framemd5.sh index facc67c..2ccba6a 100644 --- a/check_framemd5.sh +++ b/check_framemd5.sh @@ -37,50 +37,39 @@ EOF exit 0 } -if [[ "${#}" -eq 0 ]]; then - _output_prompt - exit 0 -elif [[ "${#}" -eq 1 ]]; then - if [[ "${1}" = '-h' ]]; then - _output_help - else - echo -e "${RED}ERROR:${NC} '$1' is an invalid argument." - _output_prompt - fi -elif [[ "${#}" -eq 2 ]]; then - if [[ ! -f "${1}" ]]; then - echo -e "${RED}ERROR:${NC} There is no file '$(basename ${1})'." - _output_prompt - elif [[ ! -f "${2}" ]]; then - echo -e "${RED}ERROR:${NC} There is no file '$(basename ${2})'." - _output_prompt - else - echo -e "${BLUE}Please wait...${NC}" - unset md5_tmp - if [[ $OSTYPE = "cygwin" ]]; then - md5_tmp=""${USERPROFILE}/$(basename ${2}).tmp"" - else - md5_tmp="${HOME}/$(basename ${2}).tmp" - fi - $(ffmpeg -y -i ${1} -loglevel 0 -f framemd5 -an ${md5_tmp}) - if [[ ! -f ${md5_tmp} ]]; then - echo -e "${RED}ERROR:${NC} '$(basename ${1})' is not an audio-visual file." - output_prompt - fi - old_file=$(grep -v "^#" ${2}) - tmp_file=$(grep -v "^#" ${md5_tmp}) - if [[ "${old_file}" = "${tmp_file}" ]]; then - echo -e "${BLUE}OK${NC} '$(basename ${1})' matches '$(basename ${2})'." - rm "${md5_tmp}" - exit 0 - else - echo -e "${RED}ERROR:${NC} The following differences were detected between '$(basename ${1})' and '$(basename ${2})':" - diff "${2}" "${md5_tmp}" - rm "${md5_tmp}" - exit 1 - fi - fi -else - echo -e "${RED}ERROR:${NC} Too many arguments." - _output_prompt +while getopts ":hi:c:" opt; do + case $opt in + h) output_help ;; + i) input_file=$OPTARG ;; + c) input_hash=$OPTARG ;; + *) echo "bad option -${OPTARG}" ; output_prompt ;; + :) echo "Option -${OPTARG} requires an argument" ; output_prompt ;; + esac +done + +[ -z "$@" ] && output_prompt + +echo -e "${BLUE}Please wait...${NC}" +unset md5_tmp +if [[ $OSTYPE = "cygwin" ]]; then + md5_tmp=""${USERPROFILE}/$(basename ${input_hash}).tmp"" +else + md5_tmp="${HOME}/$(basename ${input_hash}).tmp" +fi +$(ffmpeg -i ${input_file} -loglevel 0 -f framemd5 -an ${md5_tmp}) +if [[ ! -f ${md5_tmp} ]]; then + echo -e "${RED}ERROR:${NC} '$(basename ${input_file})' is not an audio-visual file." + output_prompt +fi +old_file=$(grep -v '^#' ${input_hash}) +tmp_file=$(grep -v '^#' ${md5_tmp}) +if [[ "${old_file}" = "${tmp_file}" ]]; then + echo -e "${BLUE}OK${NC} '$(basename ${input_file})' matches '$(basename ${input_hash})'." + rm "${md5_tmp}" + exit 0 +else + echo -e "${RED}ERROR:${NC} The following differences were detected between '$(basename ${input_file})' and '$(basename ${input_hash})':" + diff "${input_hash}" "${md5_tmp}" + rm "${md5_tmp}" + exit 1 fi From 937061e354a91d860d35322b9949fbcb02564b66 Mon Sep 17 00:00:00 2001 From: Reto Kromer Date: Sun, 2 Oct 2016 21:02:31 +0200 Subject: [PATCH 6/8] updated also the... date --- check_framemd5.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_framemd5.sh b/check_framemd5.sh index 2ccba6a..d371837 100644 --- a/check_framemd5.sh +++ b/check_framemd5.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash SCRIPT=$(basename "${0}") - VERSION='2016-10-01' + VERSION='2016-10-02' AUTHOR='ffmprovisr' RED='\033[1;31m' BLUE='\033[1;34m' From 588482ff3b69434369ba71c4a42de21baa3ad653 Mon Sep 17 00:00:00 2001 From: Reto Kromer Date: Sat, 8 Oct 2016 11:47:43 +0200 Subject: [PATCH 7/8] Argh! Ugly error - hope this works also on Windows (otherwise please open an issue) --- check_framemd5.sh | 86 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 75 insertions(+), 11 deletions(-) diff --git a/check_framemd5.sh b/check_framemd5.sh index d371837..867fad4 100644 --- a/check_framemd5.sh +++ b/check_framemd5.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash SCRIPT=$(basename "${0}") - VERSION='2016-10-02' + VERSION='2016-10-08' AUTHOR='ffmprovisr' RED='\033[1;31m' BLUE='\033[1;34m' @@ -13,7 +13,7 @@ fi _output_prompt(){ cat < ] +Usage: ${SCRIPT} [-h | -i -m ] EOF exit 1 } @@ -25,7 +25,7 @@ Syntax: Prompts a short help message. ${SCRIPT} -h This help. - ${SCRIPT} + ${SCRIPT} -i -m Pass to the script the audio-visual file and the corresponding MD5 file to check. Dependency: @@ -37,29 +37,93 @@ EOF exit 0 } -while getopts ":hi:c:" opt; do +while getopts ":hi:m:" opt; do case $opt in - h) output_help ;; + h) _output_help ;; i) input_file=$OPTARG ;; - c) input_hash=$OPTARG ;; - *) echo "bad option -${OPTARG}" ; output_prompt ;; - :) echo "Option -${OPTARG} requires an argument" ; output_prompt ;; + m) input_hash=$OPTARG ;; + *) echo "bad option -${OPTARG}" ; _output_prompt ;; + :) echo "Option -${OPTARG} requires an argument" ; _output_prompt ;; esac done -[ -z "$@" ] && output_prompt +[ -z "$@" ] && _output_prompt echo -e "${BLUE}Please wait...${NC}" unset md5_tmp if [[ $OSTYPE = "cygwin" ]]; then md5_tmp=""${USERPROFILE}/$(basename ${input_hash}).tmp"" -else +else md5_tmp="${HOME}/$(basename ${input_hash}).tmp" fi $(ffmpeg -i ${input_file} -loglevel 0 -f framemd5 -an ${md5_tmp}) if [[ ! -f ${md5_tmp} ]]; then echo -e "${RED}ERROR:${NC} '$(basename ${input_file})' is not an audio-visual file." - output_prompt + _output_prompt +fi +old_file=$(grep -v '^#' ${input_hash}) +tmp_file=$(grep -v '^#' ${md5_tmp}) +if [[ "${old_file}" = "${tmp_file}" ]]; then + echo -e "${BLUE}OK${NC} '$(basename ${input_file})' matches '$(basename ${input_hash})'." + rm "${md5_tmp}" + exit 0 +else + echo -e "${RED}ERROR:${NC} The following differences were detected between '$(basename ${input_file})' and '$(basename ${input_hash})':" + diff "${input_hash}" "${md5_tmp}" + rm "${md5_tmp}" + exit 1 +fi + +if [[ "${old_file}" = "${tmp_file}" ]]; then + echo -e "${BLUE}OK${NC} '$(basename ${input_file})' matches '$(basename ${input_hash})'." + rm "${md5_tmp}" + exit 0 +else + echo -e "${RED}ERROR:${NC} The following differences were detected between '$(basename ${input_file})' and '$(basename ${input_hash})':" + diff "${input_hash}" "${md5_tmp}" + rm "${md5_tmp}" + exit 1 +fi + +fi +$(ffmpeg -i ${input_file} -loglevel 0 -f framemd5 -an ${md5_tmp}) +if [[ ! -f ${md5_tmp} ]]; then + echo -e "${RED}ERROR:${NC} '$(basename ${input_file})' is not an audio-visual file." + _output_prompt +fi +old_file=$(grep -v '^#' ${input_hash}) +tmp_file=$(grep -v '^#' ${md5_tmp}) +if [[ "${old_file}" = "${tmp_file}" ]]; then + echo -e "${BLUE}OK${NC} '$(basename ${input_file})' matches '$(basename ${input_hash})'." + rm "${md5_tmp}" + exit 0 +else + echo -e "${RED}ERROR:${NC} The following differences were detected between '$(basename ${input_file})' and '$(basename ${input_hash})':" + diff "${input_hash}" "${md5_tmp}" + rm "${md5_tmp}" + exit 1 +fi + + i) input_file=$OPTARG ;; + c) input_hash=$OPTARG ;; + m) echo "bad option -${OPTARG}" ; _output_prompt ;; + :) echo "Option -${OPTARG} requires an argument" ; _output_prompt ;; + esac +done + +[ -z "$@" ] && _output_prompt + +echo -e "${BLUE}Please wait...${NC}" +unset md5_tmp +if [[ $OSTYPE = "cygwin" ]]; then + md5_tmp=""${USERPROFILE}/$(basename ${input_hash}).tmp"" +else + md5_tmp="${HOME}/$(basename ${input_hash}).tmp" +fi +$(ffmpeg -i ${input_file} -loglevel 0 -f framemd5 -an ${md5_tmp}) +if [[ ! -f ${md5_tmp} ]]; then + echo -e "${RED}ERROR:${NC} '$(basename ${input_file})' is not an audio-visual file." + _output_prompt fi old_file=$(grep -v '^#' ${input_hash}) tmp_file=$(grep -v '^#' ${md5_tmp}) From 35d752a229c2722da09ef6214275130279bc697b Mon Sep 17 00:00:00 2001 From: Reto Kromer Date: Sat, 8 Oct 2016 11:49:07 +0200 Subject: [PATCH 8/8] Update check_framemd5.sh --- check_framemd5.sh | 64 ----------------------------------------------- 1 file changed, 64 deletions(-) diff --git a/check_framemd5.sh b/check_framemd5.sh index 867fad4..e6b8a5e 100644 --- a/check_framemd5.sh +++ b/check_framemd5.sh @@ -73,67 +73,3 @@ else rm "${md5_tmp}" exit 1 fi - -if [[ "${old_file}" = "${tmp_file}" ]]; then - echo -e "${BLUE}OK${NC} '$(basename ${input_file})' matches '$(basename ${input_hash})'." - rm "${md5_tmp}" - exit 0 -else - echo -e "${RED}ERROR:${NC} The following differences were detected between '$(basename ${input_file})' and '$(basename ${input_hash})':" - diff "${input_hash}" "${md5_tmp}" - rm "${md5_tmp}" - exit 1 -fi - -fi -$(ffmpeg -i ${input_file} -loglevel 0 -f framemd5 -an ${md5_tmp}) -if [[ ! -f ${md5_tmp} ]]; then - echo -e "${RED}ERROR:${NC} '$(basename ${input_file})' is not an audio-visual file." - _output_prompt -fi -old_file=$(grep -v '^#' ${input_hash}) -tmp_file=$(grep -v '^#' ${md5_tmp}) -if [[ "${old_file}" = "${tmp_file}" ]]; then - echo -e "${BLUE}OK${NC} '$(basename ${input_file})' matches '$(basename ${input_hash})'." - rm "${md5_tmp}" - exit 0 -else - echo -e "${RED}ERROR:${NC} The following differences were detected between '$(basename ${input_file})' and '$(basename ${input_hash})':" - diff "${input_hash}" "${md5_tmp}" - rm "${md5_tmp}" - exit 1 -fi - - i) input_file=$OPTARG ;; - c) input_hash=$OPTARG ;; - m) echo "bad option -${OPTARG}" ; _output_prompt ;; - :) echo "Option -${OPTARG} requires an argument" ; _output_prompt ;; - esac -done - -[ -z "$@" ] && _output_prompt - -echo -e "${BLUE}Please wait...${NC}" -unset md5_tmp -if [[ $OSTYPE = "cygwin" ]]; then - md5_tmp=""${USERPROFILE}/$(basename ${input_hash}).tmp"" -else - md5_tmp="${HOME}/$(basename ${input_hash}).tmp" -fi -$(ffmpeg -i ${input_file} -loglevel 0 -f framemd5 -an ${md5_tmp}) -if [[ ! -f ${md5_tmp} ]]; then - echo -e "${RED}ERROR:${NC} '$(basename ${input_file})' is not an audio-visual file." - _output_prompt -fi -old_file=$(grep -v '^#' ${input_hash}) -tmp_file=$(grep -v '^#' ${md5_tmp}) -if [[ "${old_file}" = "${tmp_file}" ]]; then - echo -e "${BLUE}OK${NC} '$(basename ${input_file})' matches '$(basename ${input_hash})'." - rm "${md5_tmp}" - exit 0 -else - echo -e "${RED}ERROR:${NC} The following differences were detected between '$(basename ${input_file})' and '$(basename ${input_hash})':" - diff "${input_hash}" "${md5_tmp}" - rm "${md5_tmp}" - exit 1 -fi