]>
zdv2.bktei.com Git - BK-2020-03.git/blob - user/cbz_dedup.sh
2 # Desc: Deduplicates files within a CBZ file
3 # Usage: cbz_dedup.sh [CBZ file]
4 # Example: cbz_dedup.sh input.cbz
6 # Depends: jdupes 1.27.3, unzip 6.00 by Debian
9 yell
() { echo "$0: $*" >&2; } # print script path and all args to stderr
10 die
() { yell
"$*"; exit 111; } # same as yell() but non-zero exit status
11 must
() { "$@" || die
"cannot $*"; } # runs args as command, reports args if command fails
13 # Desc: Display script usage information
18 # Depends: GNU-coreutils 8.30 (cat)
24 cbz_dedup.sh input.cbz
26 }; # Display information on how to use this script.
31 if [[ $# -ne 1 ]]; then showUsage
; die
"FATAL:Invalid arg count (should be 1):$#"; fi;
33 if [[ ! "$1" =~
$re1 ]]; then showUsage
; die
"FATAL:Not a .cbz file:$1"; fi;
34 if [[ ! -f "$1" ]]; then die
"FATAL:Not a file:$1"; fi;
36 dir_tmp
="$(mktemp -d)";
37 if [[ ! -d "$dir_tmp" ]]; then die
"FATAL:Could not make temporary directory:${dir_tmp}"; fi;
38 trap 'rm -rf "${dir_tmp}"' EXIT
;
39 pout
="${dir_tmp}/${fout}";
42 for _cmd
in unzip zip jdupes
; do
43 if ! command -v "$_cmd" 1>/dev
/random
2>&1; then
44 die
"FATAL:Missing app:${_cmd}";
48 # Extract CBZ to temp dir
49 must
unzip "$fin" -x / -d "$dir_tmp";
53 tmp_size1
="$(du -bd0 "$dir_tmp" | cut -f1; )";
54 must jdupes
-dN "${dir_tmp}";
56 tmp_size2
="$(du -bd0 "$dir_tmp" | cut -f1; )";
58 # Replace CBZ if size changed
59 if [[ "$tmp_size1" -eq "$tmp_size2" ]]; then yell
"STATUS:No deduplication detected."; return 0; fi;
62 must
zip -j "$pout" "${dir_tmp}"/*;
64 ## Preserve original CBZ
65 must
mv -n "$fin" "${fin%.*}_original.cbz";
68 must
mv -n "$pout" "$fin";