updated style

more consistent coding style with other parts of the AMIA Open Source repository
This commit is contained in:
Reto Kromer 2016-12-31 11:04:15 +01:00 committed by GitHub
parent 7706114be7
commit c2f4519df2

View File

@ -1,19 +1,19 @@
#!/usr/bin/env bash #!/usr/bin/env bash
SCRIPT=$(basename "${0}") SCRIPT=$(basename "${0}")
VERSION='2016-12-17' VERSION='2016-12-31'
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'
if [[ $OSTYPE = "cygwin" ]] || [ ! $(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." echo -e "${RED}Error: 'diff' is not installed by default. Please install 'diffutils' from Cygwin.${NC}"
exit 1 exit 1
fi fi
_output_prompt(){ _output_prompt(){
cat <<EOF cat <<EOF
Usage: ${SCRIPT} [-h | -i <av_file> -m <md5_file>] Usage: ${SCRIPT} [-h] | [ -i <av_file> -m <md5_file> ]
EOF EOF
exit 1 exit 1
} }
@ -45,8 +45,8 @@ while getopts ":hi:m:" opt; do
h) _output_help ;; h) _output_help ;;
i) input_file=$OPTARG ;; i) input_file=$OPTARG ;;
m) input_hash=$OPTARG ;; m) input_hash=$OPTARG ;;
:) echo -e "${RED}Error:${NC} option -${OPTARG} requires an argument" ; _output_prompt ;; :) echo -e "${RED}Error: option -${OPTARG} requires an argument${NC}" ; _output_prompt ;;
*) echo -e "${RED}Error:${NC}bad option -${OPTARG}" ; _output_prompt ;; *) echo -e "${RED}Error: bad option -${OPTARG}${NC}" ; _output_prompt ;;
esac esac
done done
@ -59,18 +59,16 @@ else
md5_tmp="${HOME}/$(basename ${input_hash}).tmp" md5_tmp="${HOME}/$(basename ${input_hash}).tmp"
fi fi
$(ffmpeg -i ${input_file} -loglevel 0 -f framemd5 -an ${md5_tmp}) $(ffmpeg -i ${input_file} -loglevel 0 -f framemd5 -an ${md5_tmp})
[[ ! -f ${md5_tmp} ]] && { echo -e "${RED}Error:${NC} '${input_file}' is not a valid audio-visual file."; _output_prompt; } [[ ! -f ${md5_tmp} ]] && { echo -e "${RED}Error: '${input_file}' is not a valid audio-visual file.${NC}" ; _output_prompt ; }
unset old_file unset old_file
unset tmp_file unset tmp_file
old_file=$(grep -v '^#' ${input_hash}) old_file=$(grep -v '^#' ${input_hash})
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 ${input_file})' matches '$(basename ${input_hash})'." echo -e "${BLUE}'$(basename ${input_file})' matches '$(basename ${input_hash})'${NC}"
rm "${md5_tmp}" rm "${md5_tmp}"
exit 0
else else
echo -e "${RED}ERROR:${NC} The following differences were detected between '$(basename ${input_file})' and '$(basename ${input_hash})':" echo -e "${RED}The following differences were detected between '$(basename ${input_file})' and '$(basename ${input_hash})':${NC}"
diff "${input_hash}" "${md5_tmp}" diff "${input_hash}" "${md5_tmp}"
rm "${md5_tmp}" rm "${md5_tmp}"
exit 1
fi fi