forked from GrapheneOS/apps.grapheneos.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compress-apks
executable file
·58 lines (44 loc) · 908 Bytes
/
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
#!/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"
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"
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 :::: -