1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| #!/usr/bin/bash
function check() { for file in "$1"/.* "$1"/*; do if [ -d "$file" ]; then test -L "$file" && continue check "$file" elif [ -e "$file" ]; then sha1sum "$file" fi done }
if [ $# -ne 1 ]; then echo "The number of parameters does not match!" echo "Usage: $(basename $0) <dir>" exit 1 elif [ ! -d "$1" ]; then echo "'$1' is not a directory!" echo "Usage: $(basename $0) <dir>" exit 2 fi
result="/tmp/list-$(date +%Y%m%d%H%M%S).sha1" cd "$1" && check "." | tee "$result"
if [ $? -eq 0 ]; then echo -e "\n\033[32m[ $1 ]\033[0m \033[33m[ "$result" ]\033[0m" else echo -e "\n\033[32m[ $1 ]\033[0m \033[31m[ ERROR ]\033[0m" exit 3 fi
echo -e '\033[31m################# COMPARING #################\033[0m' /usr/bin/python3 - "$result" << EOF ######################################################### import sys
hash_dict = {}
with open(sys.argv[1], 'r', encoding="utf-8") as file: for line in file: hash_value = line.split(' ')[0].strip('\\\') file_name = ' '.join(line.split(' ')[1: ])
exist = hash_dict.get(hash_value) if not exist: hash_dict[hash_value] = [file_name, ] else: hash_dict[hash_value] += [file_name, ]
index = 1 for key, values in hash_dict.items(): if len(values) == 1: continue
print(f"[{index}]\t {key}") for file_name in values: print(f"\t{file_name}", end='')
print() index += 1 ######################################################### EOF echo -e '\033[31m#################### DONE ###################\033[0m'
|