-
Notifications
You must be signed in to change notification settings - Fork 50
/
optimize-jar.sh
executable file
·78 lines (57 loc) · 1.92 KB
/
optimize-jar.sh
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
77
78
#!/bin/bash
#
# Inventory Profiles Next
#
# Copyright (c) 2024 Plamen K. Kosseff <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
convert() {
local OUT=$3
local IN=$1
local TMP_OUT=$2
echo converting "$IN" to "$OUT"
unzip -d "$TMP_OUT" "$IN" > /dev/null
pushd . > /dev/null
# shellcheck disable=SC2164
cd "$2"
find . -type f | sort | zip -q -X -9 -@ "$OUT" > /dev/null
if [[ "x$IPNEXT_RELEASE" == "x" ]]; then
advzip -3 -z -i 100 "$OUT" > /dev/null
else
advzip -4 -z -i 100 "$OUT" > /dev/null
fi
# shellcheck disable=SC2164
popd > /dev/null
}
if [[ "x$1" == "x" ]]; then
echo "source jar not specified"
exit 1
fi
if [[ "x$2" == "x" ]]; then
echo "root dir not specified"
exit 1
fi
mkdir "$2/jaropt/" > /dev/null
UNPACK_DIR=$(mktemp -d "$2/jaropt/XXXXXXXXXX")
TMP_OUTPUT_DIR=$(mktemp -d "$2/jaropt/XXXXXXXXXX")
JAR_NAME=$(basename "$1")
convert "$1" "$UNPACK_DIR" "$TMP_OUTPUT_DIR/$JAR_NAME"
ORGSIZE=$(stat --printf "%s" "$1")
NEWSIZE=$(stat --printf "%s" "$TMP_OUTPUT_DIR/$JAR_NAME")
PERCENT=$(awk -vo="$ORGSIZE" -vn="$NEWSIZE" 'BEGIN { printf("%.3f", n/o*100)}')
echo "$ORGSIZE -> $NEWSIZE or $PERCENT%"
mkdirhier $(dirname "$3")
mv "$TMP_OUTPUT_DIR/$JAR_NAME" "$3"
rm -rf "$UNPACK_DIR" "$TMP_OUTPUT_DIR"