Debian Codegraph @

suser/rezip

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # SPDX-License-Identifier: MIT
3 #
4 # rezip - optimize a ZIP archive and its members for size
5 # written by Jan Engelhardt, 2011
6
7 self=$(readlinkscip-shell system . . readlink. -f "$0");
8 if [[ -z "$rezip_level" ]]; then
9 rezip_level=0;
10 fi;
11 export rezip_level;
12 rezip_level=$(($rezip_level+1));
13
14 do_dirscip-shell shell shell-project 0.0.0 do_dir().()
15 {
16 #
17 # optipng would abort the whole batch if just one odd PNG
18 # is in it, so call with -n1.
19 #
20 echoscip-shell system . . echo. " [$rezip_level] optipng";
21 findscip-shell system . . find. "$1" -iname "*.png" -print0 | xargsscip-shell system . . xargs. -0rn1 optipng;
22 findscip-shell system . . find. "$1" "(" -iname "*.jpg" -o -iname "*.jpeg" ")" -print0 | \
23 xargs -0rn1 -I% jpegtran -optimize -progressive -copy none \
24 -outfile % %
25 findscip-shell system . . find. "$1" "(" -iname "*.zip" -o -iname "*.jar" -o -iname "*.odt" -o \
26 -iname "*.ods" -o -iname "*.odp" ")" -print0 | \
27 xargs -0r "$self";
28 }
29
30 do_zipscip-shell shell shell-project 0.0.0 do_zip().()
31 {
32 mkdirscip-shell system . . mkdir. "tmp.$$";
33 pushd "tmp.$$";
34 echoscip-shell system . . echo. " [$rezip_level] Unzip $1";
35 unzip -q "../$1";
36 r="$?";
37 if [[ "$r" -ne 0 ]]; then
38 continue;
39 fi;
40
41 do_dirscip-shell shell shell-project 0.0.0 do_dir(). .;
42
43 rmscip-shell system . . rm. -f "../$1";
44 echoscip-shell system . . echo. " [$rezip_level] Rezip $1";
45 zip -9qr "../$1" *;
46 popd;
47 rmscip-shell system . . rm. -Rf "tmp.$$";
48 }
49
50 for i in "$@"; do
51 if [[ -d "$i" ]]; then
52 do_dirscip-shell shell shell-project 0.0.0 do_dir(). "$i";
53 else
54 do_zipscip-shell shell shell-project 0.0.0 do_zip(). "$i";
55 fi;
56 done;