Should better match the convention of other AMIA Open Source Bash scripts.
This commit is contained in:
Reto Kromer 2016-07-24 13:47:43 +02:00 committed by GitHub
parent d7bd3fb74b
commit 1795578163

View File

@ -1,18 +1,18 @@
#!/usr/bin/env bash #!/usr/bin/env bash
SCRIPT=$(basename "${0}") SCRIPT=$(basename "${0}")
VERSION='2016-07-23' VERSION='2016-07-24'
AUTHOR='ffmprovisr' AUTHOR='ffmprovisr'
RED='\033[1;31m' RED='\033[1;31m'
BLUE='\033[1;34m' BLUE='\033[1;34m'
NC='\033[0m' NC='\033[0m'
output_prompt() { _output_prompt() {
cat <<END_OF_MSG cat <<END_OF_MSG
Usage: ${SCRIPT} [-h | <av_file> <md5_file>] Usage: ${SCRIPT} [-h | <av_file> <md5_file>]
END_OF_MSG END_OF_MSG
} }
output_help() { _output_help() {
cat <<END_OF_MSG cat <<END_OF_MSG
Syntax: Syntax:
${SCRIPT} ${SCRIPT}
@ -36,27 +36,28 @@ if [[ $OSTYPE == "cygwin" ]] || [ ! $(which diff) ] ; then
fi fi
if [ "$#" -eq 0 ]; then if [ "$#" -eq 0 ]; then
output_prompt _output_prompt
exit 0 exit 0
elif [ "$#" -eq 1 ]; then elif [ "$#" -eq 1 ]; then
if [ "$1" == '-h' ]; then if [ "$1" == '-h' ]; then
output_help _output_help
exit 0 exit 0
else else
echo -e "${RED}ERROR:${NC} '$1' is an invalid argument." echo -e "${RED}ERROR:${NC} '$1' is an invalid argument."
output_prompt _output_prompt
exit 1 exit 1
fi fi
elif [ "$#" -eq 2 ]; then elif [ "$#" -eq 2 ]; then
if ! [ -f "$1" ]; then if ! [ -f "$1" ]; then
echo -e "${RED}ERROR:${NC} There is no file '$(basename $1)'." echo -e "${RED}ERROR:${NC} There is no file '$(basename $1)'."
output_prompt _output_prompt
exit 1 exit 1
elif ! [ -f "$2" ]; then elif ! [ -f "$2" ]; then
echo -e "${RED}ERROR:${NC} There is no file '$(basename $2)'." echo -e "${RED}ERROR:${NC} There is no file '$(basename $2)'."
output_prompt _output_prompt
exit 1 exit 1
else else
unset md5_tmp
if [[ $OSTYPE == "cygwin" ]]; then if [[ $OSTYPE == "cygwin" ]]; then
md5_tmp=""$USERPROFILE/$(basename $2).tmp"" md5_tmp=""$USERPROFILE/$(basename $2).tmp""
else else
@ -68,14 +69,16 @@ elif [ "$#" -eq 2 ]; then
tmp_file=$(grep -v '^#' $md5_tmp) tmp_file=$(grep -v '^#' $md5_tmp)
if [ "$old_file" = "$tmp_file" ]; then if [ "$old_file" = "$tmp_file" ]; then
echo -e "${BLUE}OK${NC} '$(basename $1)' matches '$(basename $2)'." echo -e "${BLUE}OK${NC} '$(basename $1)' matches '$(basename $2)'."
exit 0
else else
echo -e "${RED}ERROR:${NC} The following differences were detected between '$(basename $1)' and '$(basename $2)':" echo -e "${RED}ERROR:${NC} The following differences were detected between '$(basename $1)' and '$(basename $2)':"
diff "$2" "$md5_tmp" diff "$2" "$md5_tmp"
exit 1
fi fi
rm "$md5_tmp" rm "$md5_tmp"
fi fi
else else
echo -e "${RED}ERROR:${NC} Too many arguments." echo -e "${RED}ERROR:${NC} Too many arguments."
output_prompt _output_prompt
exit 1 exit 1
fi fi