From 582013bae86d7fb6b343292fdd6b89f02abbbb9f Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 27 May 2021 19:27:22 +0300 Subject: [PATCH] bos #20450 Implement script that check presense of duplicated images --- find_duplicated_images.sh | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 find_duplicated_images.sh diff --git a/find_duplicated_images.sh b/find_duplicated_images.sh new file mode 100755 index 000000000..ddb60cb00 --- /dev/null +++ b/find_duplicated_images.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +find_duplicated_images_usage() +{ + echo "Find duplicated images." + echo + echo "Usage: $(basename ${0}) [options]" + echo + echo "Options:" + echo + echo " --help (-h) Print this help information and exit." + echo " --print (-p) List duplicated files. Default: OFF." + echo + exit 0 +} + + + +find_duplicated_images_main() +{ + local verbose=0 + + local where=$(readlink -f $(dirname "${0}")) + + # parse command line + local option + while getopts ":-:hp" option ${@} + do + if [ "${option}" = "-" ] + then + case ${OPTARG} in + help ) find_duplicated_images_usage ;; + print ) verbose=1 ;; + * ) echo "Wrong option: --${OPTARG}" > /dev/stderr ; exit 1 ;; + esac + else + case ${option} in + h ) find_duplicated_images_usage ;; + p ) verbose=1 ;; + ? ) echo "Wrong option" > /dev/stderr ; exit 1 ;; + esac + fi + done + shift $((OPTIND - 1)) + + local result=0 + + if [ "${verbose}" = "1" ] + then + local filename + for filename in $(find ${where} -type f -wholename "*/doc/*.png" -exec basename {} \; | sort | uniq -d) + do + find ${where} -type f -wholename "*/doc/*/${filename}" + result=$((result+1)) + done + else + result=$(find -type f -wholename "*/doc/*.png" -exec basename {} \; | sort | uniq -d | wc -l) + fi + + return ${result} +} + +find_duplicated_images_main "${@}" -- 2.39.2