From d7bd3fb74b559b80d435b4cc2b6335f2d715a322 Mon Sep 17 00:00:00 2001 From: Reto Kromer Date: Sat, 23 Jul 2016 16:48:18 +0200 Subject: [PATCH 1/4] revision - added some { } - added test diff only if Cygwin - integrated version in help - added please wait message - updated version --- check_framemd5.sh | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/check_framemd5.sh b/check_framemd5.sh index 06f4008..ccbc180 100644 --- a/check_framemd5.sh +++ b/check_framemd5.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash - SCRIPT=$(basename $0) - VERSION='2016-07-10' + SCRIPT=$(basename "${0}") + VERSION='2016-07-23' AUTHOR='ffmprovisr' RED='\033[1;31m' BLUE='\033[1;34m' @@ -8,32 +8,29 @@ output_prompt() { cat < ] -END_OF_MSG -} - -output_version() { - cat < ] END_OF_MSG } output_help() { cat < + ${SCRIPT} Pass to the script the audio-visual file and the corresponding MD5 file to check. Dependency: ffmpeg +About: + Version: ${VERSION} + Website: https://github.com/amiaopensource/ffmprovisr/blob/gh-pages/check_framemd5.sh END_OF_MSG } -if [ ! $(which diff) ] ; then +if [[ $OSTYPE == "cygwin" ]] || [ ! $(which diff) ] ; then echo -e "${RED}ERROR:${NC} diff is not installed by default. Please install diffutils from Cygwin." exit 1 fi @@ -45,9 +42,6 @@ elif [ "$#" -eq 1 ]; then if [ "$1" == '-h' ]; then output_help exit 0 - elif [ "$1" == '-v' ]; then - output_version - exit 0 else echo -e "${RED}ERROR:${NC} '$1' is an invalid argument." output_prompt @@ -68,6 +62,7 @@ elif [ "$#" -eq 2 ]; then else md5_tmp="$HOME/$(basename $2).tmp" fi + echo "Please wait..." $(ffmpeg -y -i $1 -loglevel 0 -f framemd5 -an $md5_tmp) old_file=$(grep -v '^#' $2) tmp_file=$(grep -v '^#' $md5_tmp) From 1795578163c9bb1b208e8ff94535b1830722d8bd Mon Sep 17 00:00:00 2001 From: Reto Kromer Date: Sun, 24 Jul 2016 13:47:43 +0200 Subject: [PATCH 2/4] revision Should better match the convention of other AMIA Open Source Bash scripts. --- check_framemd5.sh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/check_framemd5.sh b/check_framemd5.sh index ccbc180..6c57049 100644 --- a/check_framemd5.sh +++ b/check_framemd5.sh @@ -1,18 +1,18 @@ #!/usr/bin/env bash SCRIPT=$(basename "${0}") - VERSION='2016-07-23' + VERSION='2016-07-24' AUTHOR='ffmprovisr' RED='\033[1;31m' BLUE='\033[1;34m' NC='\033[0m' -output_prompt() { +_output_prompt() { cat < ] END_OF_MSG } -output_help() { +_output_help() { cat < Date: Mon, 25 Jul 2016 17:56:10 +0200 Subject: [PATCH 3/4] revision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit plenty of { } --- check_framemd5.sh | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/check_framemd5.sh b/check_framemd5.sh index 6c57049..34f7e81 100644 --- a/check_framemd5.sh +++ b/check_framemd5.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash SCRIPT=$(basename "${0}") - VERSION='2016-07-24' + VERSION='2016-07-25' AUTHOR='ffmprovisr' RED='\033[1;31m' BLUE='\033[1;34m' @@ -35,11 +35,11 @@ if [[ $OSTYPE == "cygwin" ]] || [ ! $(which diff) ] ; then exit 1 fi -if [ "$#" -eq 0 ]; then +if [ "${#}" -eq 0 ]; then _output_prompt exit 0 -elif [ "$#" -eq 1 ]; then - if [ "$1" == '-h' ]; then +elif [ "${#}" -eq 1 ]; then + if [ "${1}" == '-h' ]; then _output_help exit 0 else @@ -47,35 +47,35 @@ elif [ "$#" -eq 1 ]; then _output_prompt exit 1 fi -elif [ "$#" -eq 2 ]; then - if ! [ -f "$1" ]; then - echo -e "${RED}ERROR:${NC} There is no file '$(basename $1)'." +elif [ "${#}" -eq 2 ]; then + if ! [ -f "${1}" ]; then + echo -e "${RED}ERROR:${NC} There is no file '$(basename ${1})'." _output_prompt exit 1 - elif ! [ -f "$2" ]; then - echo -e "${RED}ERROR:${NC} There is no file '$(basename $2)'." + elif ! [ -f "${2}" ]; then + echo -e "${RED}ERROR:${NC} There is no file '$(basename ${2})'." _output_prompt exit 1 else unset md5_tmp if [[ $OSTYPE == "cygwin" ]]; then - md5_tmp=""$USERPROFILE/$(basename $2).tmp"" + md5_tmp=""${USERPROFILE}/$(basename $2).tmp"" else - md5_tmp="$HOME/$(basename $2).tmp" + md5_tmp="${HOME}/$(basename ${2}).tmp" fi echo "Please wait..." - $(ffmpeg -y -i $1 -loglevel 0 -f framemd5 -an $md5_tmp) - 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)'." + $(ffmpeg -y -i ${1} -loglevel 0 -f framemd5 -an ${md5_tmp}) + 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})'." exit 0 else - echo -e "${RED}ERROR:${NC} The following differences were detected between '$(basename $1)' and '$(basename $2)':" - diff "$2" "$md5_tmp" + echo -e "${RED}ERROR:${NC} The following differences were detected between '$(basename ${1})' and '$(basename ${2})':" + diff "${2}" "${md5_tmp}" exit 1 fi - rm "$md5_tmp" + rm "${md5_tmp}" fi else echo -e "${RED}ERROR:${NC} Too many arguments." From 654120caf150a8c678714c235e026e159ba5acc8 Mon Sep 17 00:00:00 2001 From: Reto Kromer Date: Mon, 25 Jul 2016 17:57:37 +0200 Subject: [PATCH 4/4] revision missed that one { } if works on Cygwin --- check_framemd5.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_framemd5.sh b/check_framemd5.sh index 34f7e81..8f5f44f 100644 --- a/check_framemd5.sh +++ b/check_framemd5.sh @@ -59,7 +59,7 @@ elif [ "${#}" -eq 2 ]; then else unset md5_tmp if [[ $OSTYPE == "cygwin" ]]; then - md5_tmp=""${USERPROFILE}/$(basename $2).tmp"" + md5_tmp=""${USERPROFILE}/$(basename ${2}).tmp"" else md5_tmp="${HOME}/$(basename ${2}).tmp" fi