forked from GrapheneOS/apps.grapheneos.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompress-apks
executable file
·64 lines (50 loc) · 1.18 KB
/
compress-apks
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
#!/bin/bash
set -o errexit -o nounset -o pipefail
if [[ $# -eq 1 ]]; then
fd=$1
else
touch lock
exec {fd}< lock
fi
if ! flock -n $fd; then
echo already locked >&2
exit 1
fi
maybe_brotli() {
COMP="$1.br"
if [[ -f $COMP ]]; then
return
fi
TMP="$COMP.tmp"
rm -f $TMP
echo "brotli $1 (minimal compression):"
time brotli --quality=1 --suffix=".br.tmp" "$1"
#echo "botli $1 (default compression):"
#time brotli --suffix=".br.tmp" "$1"
sync $TMP
mv $TMP $COMP
# fully preserve file times, brotli reduces precision of mtime to a second
touch -r "$1" $COMP
}
export -f maybe_brotli
maybe_zopfli() {
COMP="$1.gz"
if [[ -f $COMP ]]; then
return
fi
TMP="$COMP.tmp"
rm -f $TMP
echo "zopfli $1 (pigz compression):"
#time zopfli --i1 -c "$1" > $TMP
#time pigz -11 -c "$1" > $TMP
time pigz -6 -c "$1" > $TMP
#echo "zopfli $1 (default compression):"
#time zopfli -c "$1" > $TMP
sync $TMP
mv $TMP $COMP
# preserve file times
touch -r "$1" $COMP
}
export -f maybe_zopfli
find "apps/packages" -regex '.+\.apk' |
parallel -q ::: maybe_brotli maybe_zopfli :::: -