From 84ccaddf2637ebc90d582c865ff64d1feb5c4527 Mon Sep 17 00:00:00 2001 From: desktop Date: Tue, 3 Oct 2023 08:51:19 +0300 Subject: [PATCH] achive & name : add report for failed checks count. --- document/linux/config/bash/module/archive.sh | 25 +++++++++++++------- document/linux/config/bash/module/name.sh | 16 +++++++++---- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/document/linux/config/bash/module/archive.sh b/document/linux/config/bash/module/archive.sh index b881fe5..1100b25 100644 --- a/document/linux/config/bash/module/archive.sh +++ b/document/linux/config/bash/module/archive.sh @@ -2,8 +2,8 @@ archive() { local target="$@" # target file(s). - local count=1 - local total=$# + local count=1 # processed count. + local total=$# # total to process. # set dafult value to target all supported archives. if [[ "$target" = "" ]]; then @@ -32,8 +32,8 @@ archive() archive_fast() { local target="$@" # target file(s). - local count=1 - local total=$# + local count=1 # processed count. + local total=$# # total to process. # set dafult value to target all supported archives. if [[ "$target" = "" ]]; then @@ -64,8 +64,9 @@ archive_check() local target="$@" # target file(s). local saved # saved hash value. local actual # actual file hash value. - local count=1 - local total=$# + local count=1 # processed count. + local total=$# # total to process. + local failed=0 # total failed checks. # set dafult value to target all supported archives. if [[ "$target" = "" ]]; then @@ -89,12 +90,18 @@ archive_check() if [[ "$actual" = "$saved" ]]; then echo "${status}: OK." else - echo "${status}: failed." + echo -e "${color_red}${status}: failed.${color_default}" + ((failed++)) fi # increment counter. ((count++)) done + + # report if any failed. + if [[ ${failed} -gt 0 ]]; then + echo -e "${color_bred}Items failed to validate: ${failed}.${color_default}" + fi } # extract previously created archive with checksum validation. @@ -103,8 +110,8 @@ unarchive() local target="$@" # target file(s). local saved # saved hash value. local actual # actual file hash value. - local count=1 - local total=$# + local count=1 # processed count. + local total=$# # total to process. # set dafult value to target all supported archives. if [[ "$target" = "" ]]; then diff --git a/document/linux/config/bash/module/name.sh b/document/linux/config/bash/module/name.sh index c04053d..556454f 100644 --- a/document/linux/config/bash/module/name.sh +++ b/document/linux/config/bash/module/name.sh @@ -121,33 +121,41 @@ name_hash_check() local files="$@" local count=1 local total=$# + local failed=0 # all files by default. if [[ "$files" = "" ]]; then files="[^.]*" total=$(ls -p | grep -v / | wc -l) fi - # process. for file in $files; do # process only files. if [[ -f "$file" ]]; then + # status info. + local status="[$count/$total] $file" + # extract hashes. stored="${file%%.*}" actual=$(sha1sum -- "$file" | cut -d\ -f1) # compare hashes. - echo -n "[$count/$total] $file: " if [[ "$stored" = "$actual" ]]; then - echo "OK." + echo -e "${status}: OK." else - echo "failed." + echo -e "${color_red}${status}: failed.${color_default}" + ((failed++)) fi # increment count. ((count++)) fi done + + # report if any failed. + if [[ ${failed} -gt 0 ]]; then + echo -e "${color_bred}Items failed to validate: ${failed}.${color_default}" + fi } # rename files for Jellyfin series, i.e. Episode S01E01.mkv