rev |
line source |
al@865
|
1 #!/bin/sh
|
al@865
|
2 #
|
al@865
|
3 # compressor - module of the SliTaz Cook
|
al@865
|
4 # Copyright (C) SliTaz GNU/Linux - GNU GPL v3
|
al@865
|
5 #
|
al@865
|
6
|
al@865
|
7 . /usr/lib/slitaz/libcook.sh
|
al@865
|
8
|
al@868
|
9 # Compressor cache stuff
|
al@868
|
10
|
al@873
|
11 comp_cache_root='/home/slitaz/cache/cook'
|
al@869
|
12 mkdir -p "$comp_cache_root"
|
al@868
|
13 cache_stat=$(mktemp)
|
al@868
|
14
|
al@868
|
15 # Cache notes.
|
al@868
|
16 # Do not do the same job twice. Getting the file from the cache is much faster
|
al@868
|
17 # than compressing the file one more time. In addition, this cache is trying not
|
al@868
|
18 # to take extra space, using the hardlinks. Although the files from the cache
|
paul@870
|
19 # without reference to itself should be removed periodically.
|
al@868
|
20
|
al@868
|
21
|
al@868
|
22
|
al@868
|
23
|
al@865
|
24 #
|
al@865
|
25 # Functions
|
al@865
|
26 #
|
al@865
|
27
|
al@865
|
28
|
al@912
|
29 # tazpkg install command
|
al@912
|
30
|
al@912
|
31 tpi() {
|
al@912
|
32 tazpkg -gi --quiet --local --cookmode $1
|
al@912
|
33 }
|
al@912
|
34
|
al@912
|
35
|
al@881
|
36 # Working with time (with hundredths precision)
|
al@865
|
37
|
al@881
|
38 get_time() {
|
al@881
|
39 cut -d" " -f2 /proc/uptime
|
al@881
|
40 }
|
al@865
|
41
|
al@881
|
42 calc_time() {
|
al@881
|
43 # L10n: 's' is for seconds, 'm' is for minutes
|
al@881
|
44 awk -va="$1" -vb="$(get_time)" -vs="$(_ 's')" -vm="$(_ 'm')" '
|
al@881
|
45 BEGIN{
|
al@881
|
46 time = b - a;
|
al@881
|
47 if (time < 30)
|
al@881
|
48 printf("%.2f%s\n", time, s);
|
al@881
|
49 else
|
al@881
|
50 printf("%.2f%s ~ %.0f%s\n", time, s, time / 60, m);
|
al@881
|
51 }'
|
al@865
|
52 }
|
al@865
|
53
|
al@865
|
54
|
al@865
|
55 # Compressor mini summary
|
al@865
|
56
|
al@865
|
57 comp_summary() {
|
al@865
|
58 # "$time0" "$size0" "$size1"
|
al@865
|
59 status
|
al@865
|
60 [ "$2" -eq 0 ] && return
|
al@881
|
61 saving=$(awk -va="$2" -vb="$3" 'BEGIN{ printf("%.0f\n", (a - b) / 1024) }')
|
al@868
|
62 cache_msg=''
|
al@868
|
63 if [ -s "$cache_stat" ]; then
|
al@868
|
64 cache_msg=$(_n ' Cache hit: %d/%d.' "$(fgrep '+' $cache_stat | wc -l)" "$(wc -l < $cache_stat)")
|
al@868
|
65 echo -n > $cache_stat
|
al@868
|
66 fi
|
al@868
|
67 _ ' Time: %s. Size: %s B -> %s B. Save: %s KB.%s' \
|
al@881
|
68 "$(calc_time $1)" "$2" "$3" "$saving" "$cache_msg"
|
al@865
|
69 }
|
al@865
|
70
|
al@865
|
71
|
al@865
|
72 # Calculating different sizes
|
al@865
|
73
|
al@865
|
74 sizes() {
|
al@865
|
75 case $1 in
|
al@865
|
76 man) find $install/usr/share/man -type f -exec ls -l \{\} \; ;;
|
al@865
|
77 png) find $install -type f -name '*.png' -exec ls -l \{\} \; ;;
|
al@865
|
78 svg) find $install -type f -name '*.svg' -exec ls -l \{\} \; ;;
|
al@865
|
79 xml) find $install -type f \( -name '*.ui' -o -name '*.glade' \) -exec ls -l \{\} \; ;;
|
al@865
|
80 des) find $install -type f -name '*.desktop' -exec ls -l \{\} \; ;;
|
al@865
|
81 mo1) find $install -type f -name '*.mo' -exec ls -l \{\} \; ;;
|
al@865
|
82 loc) find $install/usr/share/i18n/locales -type f -exec ls -l \{\} \; ;;
|
al@865
|
83 mo2) find $fs/usr/share/locale -type f -name '*.mo' -exec ls -l \{\} \; ;;
|
al@872
|
84 gz) find $install -type f -name '*.gz' ! -path '*/share/man/*' -exec ls -l \{\} \; ;;
|
al@954
|
85 zip) find $install -type f -name '*.zip' -exec ls -l \{\} \; ;;
|
al@899
|
86 str) find $fs -type f \( -name '*.so*' -o -name '*.a' -o -name '*.pyc' -o -name '*.pyo' \
|
al@899
|
87 -o -name '.packlist' -o -name '*.pm' -o -name '*.pl' -o -name '*.pod' \) -exec ls -l \{\} \; ;;
|
al@865
|
88 esac | awk '{s+=$5}END{print s}'
|
al@865
|
89 }
|
al@865
|
90
|
al@865
|
91
|
al@868
|
92 # Query cache for already existing compressed file; substitute original file with the cached
|
al@868
|
93 # compressed one if so.
|
al@868
|
94 # $1: cache section (gz, mangz, png, etc.); $2: path to original file
|
al@868
|
95
|
al@868
|
96 query_cache() {
|
al@868
|
97 md5=$(md5sum "$2")
|
al@868
|
98 cachefile="$comp_cache_root/$1/${md5%% *}"
|
al@868
|
99 echo "$cachefile"
|
al@868
|
100 if [ -f "$cachefile" ]; then
|
al@868
|
101 ln -f "$cachefile" "$2"
|
al@868
|
102 echo '+' >> "$cache_stat"
|
al@868
|
103 else
|
al@868
|
104 echo '-' >> "$cache_stat"
|
al@868
|
105 false
|
al@868
|
106 fi
|
al@868
|
107 }
|
al@868
|
108
|
al@868
|
109
|
al@868
|
110 # Store compressed file to the cache
|
al@868
|
111 # $1: path to cache entry to be stored; $2: path to compressed file to be stored
|
al@868
|
112
|
al@868
|
113 store_cache() {
|
al@868
|
114 mkdir -p "${1%/*}"
|
al@868
|
115 mv "$2" "$1"
|
al@868
|
116 ln "$1" "$2"
|
al@868
|
117 }
|
al@868
|
118
|
al@868
|
119
|
al@865
|
120 # Function to compress all man pages
|
al@865
|
121 # Compressing can be disabled with COOKOPTS="!manz"
|
al@865
|
122
|
al@865
|
123 compress_manpages() {
|
al@881
|
124 time0=$(get_time)
|
al@865
|
125 [ "${COOKOPTS/!manz/}" != "$COOKOPTS" ] && return
|
al@874
|
126 manpath="$install/usr/share/man"
|
al@865
|
127 [ -d "$manpath" ] || return
|
al@865
|
128 size0=$(sizes man); [ -z "$size0" ] && return
|
al@865
|
129
|
al@936
|
130 tpi advancecomp-static
|
al@867
|
131
|
al@865
|
132 action 'Compressing man pages...'
|
al@865
|
133
|
al@865
|
134 # We'll use only Gzip compression, so decompress other formats first
|
al@865
|
135 find $manpath -type f -name '*.bz2' -exec bunzip2 \{\} \;
|
al@865
|
136 find $manpath -type f -name '*.xz' -exec unxz \{\} \;
|
al@865
|
137
|
al@865
|
138 # Fast compress with gzip
|
al@874
|
139 find $manpath -type f ! -name '*.gz' -exec gzip \{\} \;
|
al@865
|
140
|
al@865
|
141 # Fix symlinks
|
al@874
|
142 for i in $(find $manpath -type l); do
|
al@865
|
143 dest=$(readlink $i | sed 's|\.[gbx]z2*$||')
|
al@865
|
144 link=$(echo $i | sed 's|\.[gbx]z2*$||')
|
al@865
|
145 rm $i; ln -s $dest.gz $link.gz
|
al@865
|
146 done
|
al@865
|
147
|
al@865
|
148 # Recompress with advdef (it can't compress, only recompress)
|
al@876
|
149 IFS=$'\n'
|
al@874
|
150 for i in $(find $manpath -type f); do
|
al@868
|
151 if ! cached_path=$(query_cache mangz "$i"); then
|
al@868
|
152 advdef -z4q "$i"
|
al@868
|
153 store_cache "$cached_path" "$i"
|
al@868
|
154 fi
|
al@865
|
155 done
|
al@865
|
156
|
al@865
|
157 comp_summary "$time0" "$size0" "$(sizes man)"
|
al@865
|
158 }
|
al@865
|
159
|
al@865
|
160
|
al@872
|
161 # Function to recompress all gzip archives
|
al@872
|
162 # Recompressing can be disabled with COOKOPTS="!gz"
|
al@872
|
163
|
al@872
|
164 recompress_gz() {
|
al@881
|
165 time0=$(get_time)
|
al@872
|
166 [ "${COOKOPTS/!gz/}" != "$COOKOPTS" ] && return
|
al@872
|
167 size0=$(sizes gz); [ -z "$size0" ] && return
|
al@872
|
168
|
al@936
|
169 tpi advancecomp-static
|
al@872
|
170
|
al@872
|
171 action 'Recompressing gzip files...'
|
al@872
|
172
|
al@872
|
173 # Recompress with advdef
|
al@876
|
174 IFS=$'\n'
|
al@872
|
175 for i in $(find $install -type f -name '*.gz' ! -path '*/share/man/*'); do
|
al@872
|
176 if ! cached_path=$(query_cache gz "$i"); then
|
al@872
|
177 advdef -z4q "$i"
|
al@872
|
178 store_cache "$cached_path" "$i"
|
al@872
|
179 fi
|
al@872
|
180 done
|
al@872
|
181
|
al@872
|
182 comp_summary "$time0" "$size0" "$(sizes gz)"
|
al@872
|
183 }
|
al@872
|
184
|
al@872
|
185
|
al@954
|
186 # Function to recompress all zip archives
|
al@954
|
187 # Recompressing can be disabled with COOKOPTS="!zip"
|
al@954
|
188
|
al@954
|
189 recompress_zip() {
|
al@954
|
190 time0=$(get_time)
|
al@954
|
191 [ "${COOKOPTS/!zip/}" != "$COOKOPTS" ] && return
|
al@954
|
192 size0=$(sizes zip); [ -z "$size0" ] && return
|
al@954
|
193
|
al@954
|
194 tpi advancecomp-static
|
al@954
|
195
|
al@954
|
196 action 'Recompressing zip files...'
|
al@954
|
197
|
al@954
|
198 # Recompress with advzip
|
al@954
|
199 IFS=$'\n'
|
al@954
|
200 for i in $(find $install -type f -name '*.zip'); do
|
al@954
|
201 if ! cached_path=$(query_cache zip "$i"); then
|
al@954
|
202 advzip -z3qk "$i" # -4 is more than 2 orders slower
|
al@954
|
203 store_cache "$cached_path" "$i"
|
al@954
|
204 fi
|
al@954
|
205 done
|
al@954
|
206
|
al@954
|
207 comp_summary "$time0" "$size0" "$(sizes zip)"
|
al@954
|
208 }
|
al@954
|
209
|
al@954
|
210
|
al@865
|
211 # Function used after compile_rules() to compress all png images
|
al@865
|
212 # Compressing can be disabled with COOKOPTS="!pngz"
|
al@865
|
213
|
al@865
|
214 compress_png() {
|
al@881
|
215 time0=$(get_time)
|
al@865
|
216 [ "${COOKOPTS/!pngz/}" != "$COOKOPTS" ] && return
|
al@865
|
217 size0=$(sizes png); [ -z "$size0" ] && return
|
al@865
|
218
|
al@865
|
219 use_pq=true
|
al@865
|
220 use_op=true
|
al@865
|
221 [ "${COOKOPTS/!pngquant/}" != "$COOKOPTS" ] && use_pq=false
|
al@865
|
222 [ "${COOKOPTS/!optipng/}" != "$COOKOPTS" ] && use_op=false
|
al@932
|
223 $use_pq && tpi pngquant-static
|
al@932
|
224 $use_op && tpi optipng-static
|
al@865
|
225
|
al@867
|
226 action 'Compressing png images...'
|
al@865
|
227
|
al@865
|
228 oplevel=$(echo $COOKOPTS | grep 'op[0-8]' | sed 's|.*op\([0-8]\).*|\1|')
|
al@868
|
229 [ -z "$oplevel" ] && oplevel='2'
|
al@868
|
230
|
al@868
|
231 cache_section="png$oplevel"
|
al@868
|
232 $use_pq && cache_section="${cache_section}p"
|
al@868
|
233 $use_op && cache_section="${cache_section}o"
|
al@868
|
234
|
al@865
|
235 [ "$oplevel" == '8' ] && oplevel='7 -zm1-9'
|
al@865
|
236
|
al@978
|
237 IFS=$'\n'
|
al@978
|
238 for i in $(find $install -type f -name '*.png'); do
|
al@960
|
239 unset IFS
|
al@868
|
240 if ! cached_path=$(query_cache $cache_section "$i"); then
|
al@868
|
241 $use_pq && pngquant -f --skip-if-larger --ext .png --speed 1 "$i"
|
al@868
|
242 $use_op && optipng -quiet -strip all -o$oplevel "$i"
|
al@868
|
243 store_cache "$cached_path" "$i"
|
al@868
|
244 fi
|
al@865
|
245 done
|
al@865
|
246
|
al@865
|
247 comp_summary "$time0" "$size0" "$(sizes png)"
|
al@865
|
248 }
|
al@865
|
249
|
al@865
|
250
|
al@865
|
251 # Function used after compile_rules() to compress all svg images
|
al@865
|
252 # Compressing can be disabled with COOKOPTS="!svgz"
|
al@865
|
253
|
al@865
|
254 compress_svg() {
|
al@881
|
255 time0=$(get_time)
|
al@865
|
256 [ "${COOKOPTS/!svgz/}" != "$COOKOPTS" ] && return
|
al@865
|
257 size0=$(sizes svg); [ -z "$size0" ] && return
|
al@865
|
258
|
al@912
|
259 tpi svgcleaner
|
al@867
|
260
|
al@865
|
261 action 'Compressing svg images...'
|
al@865
|
262
|
al@959
|
263 [ "${COOKOPTS/!svgextra/}" == "$COOKOPTS" ] &&
|
al@959
|
264 opts="--apply-transform-to-paths yes --coordinates-precision 1 --paths-coordinates-precision 1"
|
al@959
|
265
|
al@865
|
266 cleaner_log="$(mktemp)"
|
al@959
|
267 for i in $(IFS=$'\n' find $install -type f -name '*.svg'); do
|
al@959
|
268 out="$(unset IFS; svgcleaner "$i" "$i" --copy-on-error --quiet \
|
al@959
|
269 --multipass --remove-unresolved-classes no $opts 2>&1)"
|
al@959
|
270 [ -z "$out" ] || echo -e "$i:\n$out\n" >> "$cleaner_log"
|
al@865
|
271 done
|
al@865
|
272
|
al@865
|
273 comp_summary "$time0" "$size0" "$(sizes svg)"
|
al@865
|
274
|
al@865
|
275 if [ -s "$cleaner_log" ]; then
|
al@865
|
276 _ 'Cleaner warnings and errors:'
|
al@865
|
277 awk '{printf " %s\n", $0;}' "$cleaner_log"
|
al@865
|
278 echo
|
al@865
|
279 fi
|
al@865
|
280 rm "$cleaner_log"
|
al@865
|
281 }
|
al@865
|
282
|
al@865
|
283
|
al@865
|
284 # Function used after compile_rules() to shrink all *.ui and *.glade files:
|
al@865
|
285 # remove insignificant spaces and comments
|
al@865
|
286 # Compressing can be disabled with COOKOPTS="!uiz"
|
al@865
|
287
|
al@865
|
288 compress_ui() {
|
al@865
|
289 [ "${COOKOPTS/!uiz/}" != "$COOKOPTS" ] && return
|
al@865
|
290 [ -z "$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) )" ] && return
|
al@865
|
291
|
al@912
|
292 tpi xmlstarlet
|
al@867
|
293
|
al@865
|
294 action 'Compressing ui files...'
|
al@867
|
295
|
al@865
|
296 size0=$(sizes xml)
|
al@881
|
297 time0=$(get_time)
|
al@865
|
298 temp_ui="$(mktemp)"
|
al@876
|
299 IFS=$'\n'
|
al@865
|
300 for ui in $(find $install -type f \( -name '*.ui' -o -name '*.glade' \) ); do
|
al@865
|
301 xmlstarlet c14n --without-comments "$ui" | xmlstarlet sel -B -t -c '*' > "$temp_ui"
|
al@865
|
302 cat "$temp_ui" > "$ui"
|
al@865
|
303 done
|
al@865
|
304
|
al@865
|
305 comp_summary "$time0" "$size0" "$(sizes xml)"
|
al@865
|
306 rm "$temp_ui"
|
al@865
|
307 }
|
al@865
|
308
|
al@865
|
309
|
al@865
|
310 # Get list of supported locales...
|
al@865
|
311
|
al@865
|
312 get_supported_locales() {
|
al@865
|
313 lpc='/slitaz-i18n/stuff/locale-pack.conf'
|
al@865
|
314 if [ -e "$WOK$lpc" ]; then
|
al@865
|
315 # ... from package in the local wok
|
al@865
|
316 . "$WOK$lpc"
|
al@865
|
317 else
|
al@865
|
318 # ... from Hg
|
al@865
|
319 temp_conf=$(mktemp)
|
al@865
|
320 wget -q -O $temp_conf -T 10 "http://hg.slitaz.org/wok/raw-file/tip$lpc"
|
al@865
|
321 if [ -s $temp_conf ]; then
|
al@865
|
322 . $temp_conf
|
al@865
|
323 else
|
al@865
|
324 # Give up and use hardcoded list
|
al@865
|
325 LOCALE_PACK="ar ca cs da de el en es fi fr hr hu id is it ja nb nl nn pl pt \
|
al@865
|
326 pt_BR ro ru sl sv tr uk zh_CN zh_TW"
|
al@865
|
327 fi
|
al@865
|
328 rm $temp_conf
|
al@865
|
329 fi
|
al@865
|
330 echo $LOCALE_PACK
|
al@865
|
331 }
|
al@865
|
332
|
al@865
|
333
|
al@865
|
334 # Fix common errors and warnings in the .desktop files
|
al@865
|
335 # Fixing can be disabled with COOKOPTS="!fixdesktops"
|
al@865
|
336
|
al@865
|
337 fix_desktop_files() {
|
al@865
|
338 [ "${COOKOPTS/!fixdesktops/}" != "$COOKOPTS" ] && return
|
al@876
|
339 deskpath="$install/usr/share/applications"
|
al@876
|
340 [ -d "$deskpath" ] || return
|
al@876
|
341 [ -z "$(find $deskpath -type f -name '*.desktop')" ] && return
|
al@865
|
342
|
al@865
|
343 size0=$(sizes des)
|
al@881
|
344 time0=$(get_time)
|
al@865
|
345
|
al@865
|
346 if [ -n "$QA" -a -z "$(which desktop-file-validate)" ]; then
|
al@936
|
347 tpi desktop-file-validate-static
|
al@865
|
348 fi
|
al@865
|
349
|
al@865
|
350 # The variable $LOCALE is set in cook.conf and may be overridden in the receipt.
|
al@865
|
351 # Default value is "" (empty). That means for us that we'll use the full
|
al@865
|
352 # list of supported locales here.
|
al@865
|
353 [ -z "$LOCALE" ] && LOCALE=$(get_supported_locales)
|
al@865
|
354
|
al@876
|
355 IFS=$'\n'
|
al@876
|
356 for desktop in $(find $deskpath -type f -name '*.desktop'); do
|
al@865
|
357 cp "$desktop" "$desktop.orig"
|
al@865
|
358
|
al@865
|
359 # Sort out .desktop file (is prerequisite to correct working of `fix-desktop-file`)
|
al@865
|
360 sdft "$desktop" -i
|
al@865
|
361
|
al@865
|
362 # Fix common errors in .desktop file
|
al@865
|
363 fix-desktop-file "$desktop"
|
al@865
|
364
|
al@865
|
365 # Strip unsupported locales from .desktop file
|
al@865
|
366 [ "${COOKOPTS/!i18nz/}" == "$COOKOPTS" ] &&
|
al@865
|
367 sdft "$desktop" -i -k "$LOCALE"
|
al@865
|
368
|
al@865
|
369 # Extra-strip
|
al@865
|
370 [ "${COOKOPTS/!extradesktops/}" == "$COOKOPTS" ] &&
|
al@865
|
371 sdft "$desktop" -i -g -x -tf -r 'Keywords*' -o
|
al@865
|
372
|
al@865
|
373 if [ -n "$QA" ]; then
|
al@865
|
374 # Check the rest of errors, warnings and tips
|
al@865
|
375 _ 'QA: Checking %s...' "$(basename $desktop)"
|
al@918
|
376 busybox diff "$desktop.orig" "$desktop"
|
al@865
|
377 desktop-file-validate "$desktop" | busybox fold -s
|
al@865
|
378 echo
|
al@865
|
379 fi
|
al@865
|
380
|
al@865
|
381 rm "$desktop.orig"
|
al@865
|
382 done
|
al@865
|
383
|
al@865
|
384 comp_summary "$time0" "$size0" "$(sizes des)"
|
al@865
|
385 }
|
al@865
|
386
|
al@865
|
387
|
paul@879
|
388 # Normalize all *.mo files: unconditionally convert to UTF-8; remove strings that are not really necessary
|
al@865
|
389 # to the translation (msgid = msgstr)
|
al@865
|
390 # Normalization can be disabled with COOKOPTS="!monorm"
|
al@865
|
391
|
al@865
|
392 normalize_mo() {
|
al@865
|
393 [ "${COOKOPTS/!monorm/}" != "$COOKOPTS" ] && return
|
al@865
|
394 [ -z "$(find $install -type f -name '*.mo')" ] && return
|
al@865
|
395
|
al@867
|
396 # Gettext functions: msgunfmt, msguniq, msgconv, msgfmt
|
al@912
|
397 tpi gettext
|
al@867
|
398 # Gconv modules (convert to UTF-8)
|
al@912
|
399 tpi glibc-locale
|
al@867
|
400
|
al@865
|
401 action 'Normalizing mo files...'
|
al@867
|
402
|
al@865
|
403 size0=$(sizes mo1)
|
al@881
|
404 time0=$(get_time)
|
al@865
|
405
|
al@865
|
406 # Process all existing *.mo files
|
al@876
|
407 IFS=$'\n'
|
al@865
|
408 for mo in $(find "$install" -type f -name '*.mo'); do
|
al@865
|
409 tmpfile="$(mktemp)"
|
al@865
|
410
|
al@865
|
411 msgunfmt "$mo" | msguniq | msgconv -o "$tmpfile" -t 'UTF-8'
|
al@865
|
412 # add newline
|
al@865
|
413 echo >> "$tmpfile"
|
al@865
|
414
|
al@865
|
415 # get Plural-Forms
|
al@865
|
416 awk '
|
al@865
|
417 BEGIN { skip = ""; }
|
al@865
|
418 {
|
al@865
|
419 if (! skip) {
|
al@865
|
420 s = $0;
|
al@865
|
421 gsub(/^[^\"]*\"/, "", s);
|
al@865
|
422 gsub(/\"$/, "", s);
|
al@865
|
423 printf("%s", s);
|
al@865
|
424 }
|
al@865
|
425 if (! $0) skip = "yes";
|
al@865
|
426 }
|
al@865
|
427 ' "$tmpfile" | sed 's|\\n|\n|g' | grep "^Plural-Forms:" > "$tmpfile.pf"
|
al@865
|
428
|
al@865
|
429 if ! grep -q 'msgid_plural' "$tmpfile"; then
|
al@865
|
430 echo > "$tmpfile.pf"
|
al@865
|
431 fi
|
al@865
|
432
|
al@865
|
433 # main
|
al@865
|
434 awk -v pf="$(cat "$tmpfile.pf")" '
|
al@865
|
435 function clean() {
|
al@865
|
436 mode = msgctxt = msgid = msgid_plural = msgstr = msgstr0 = msgstr1 = msgstr2 = msgstr3 = msgstr4 = msgstr5 = "";
|
al@865
|
437 }
|
al@865
|
438
|
al@865
|
439 function getstring() {
|
al@865
|
440 # Skip unquoted words at the beginning (msgid, msgstr...) and get string from inside quotes
|
al@865
|
441 s = $0;
|
al@865
|
442 gsub(/^[^\"]*\"/, "", s);
|
al@865
|
443 gsub(/\"$/, "", s);
|
al@865
|
444 return s;
|
al@865
|
445 }
|
al@865
|
446
|
al@865
|
447 BEGIN {
|
al@865
|
448 printf("msgid \"\"\nmsgstr \"\"\n\"Content-Type: text/plain; charset=UTF-8\\n\"\n");
|
al@865
|
449 if (pf)
|
al@865
|
450 printf("\"%s\\n\"\n", pf);
|
al@865
|
451 printf("\n");
|
al@865
|
452 skip = 1;
|
al@865
|
453 clean();
|
al@865
|
454 }
|
al@865
|
455
|
al@865
|
456 {
|
al@865
|
457 # Skip the entire header
|
al@865
|
458 if (!skip) {
|
al@865
|
459 if ($1 == "msgctxt" || $1 == "msgid" || $1 == "msgstr" || $1 == "msgid_plural")
|
al@865
|
460 mode = $1;
|
al@865
|
461 if ($1 == "msgstr[0]") mode = "msgstr0";
|
al@865
|
462 if ($1 == "msgstr[1]") mode = "msgstr1";
|
al@865
|
463 if ($1 == "msgstr[2]") mode = "msgstr2";
|
al@865
|
464 if ($1 == "msgstr[3]") mode = "msgstr3";
|
al@865
|
465 if ($1 == "msgstr[4]") mode = "msgstr4";
|
al@865
|
466 if ($1 == "msgstr[5]") mode = "msgstr5";
|
al@865
|
467
|
al@865
|
468 if (mode == "msgctxt") msgctxt = msgctxt getstring();
|
al@865
|
469 if (mode == "msgid") msgid = msgid getstring();
|
al@865
|
470 if (mode == "msgstr") msgstr = msgstr getstring();
|
al@865
|
471 if (mode == "msgid_plural") msgid_plural = msgid_plural getstring();
|
al@865
|
472 if (mode == "msgstr0") msgstr0 = msgstr0 getstring();
|
al@865
|
473 if (mode == "msgstr1") msgstr1 = msgstr1 getstring();
|
al@865
|
474 if (mode == "msgstr2") msgstr2 = msgstr2 getstring();
|
al@865
|
475 if (mode == "msgstr3") msgstr3 = msgstr3 getstring();
|
al@865
|
476 if (mode == "msgstr4") msgstr4 = msgstr4 getstring();
|
al@865
|
477 if (mode == "msgstr5") msgstr5 = msgstr5 getstring();
|
al@865
|
478
|
al@865
|
479 if (! $0) {
|
al@865
|
480 if (msgid != msgstr) {
|
al@865
|
481 if (msgctxt) printf("msgctxt \"%s\"\n", msgctxt);
|
al@865
|
482 printf("msgid \"%s\"\n", msgid);
|
al@865
|
483 if (msgid_plural) printf("msgid_plural \"%s\"\n", msgid_plural);
|
al@865
|
484 if (msgstr) printf("msgstr \"%s\"\n", msgstr);
|
al@865
|
485 if (msgstr0) printf("msgstr[0] \"%s\"\n", msgstr0);
|
al@865
|
486 if (msgstr1) printf("msgstr[1] \"%s\"\n", msgstr1);
|
al@865
|
487 if (msgstr2) printf("msgstr[2] \"%s\"\n", msgstr2);
|
al@865
|
488 if (msgstr3) printf("msgstr[3] \"%s\"\n", msgstr3);
|
al@865
|
489 if (msgstr4) printf("msgstr[4] \"%s\"\n", msgstr4);
|
al@865
|
490 if (msgstr5) printf("msgstr[5] \"%s\"\n", msgstr5);
|
al@865
|
491 printf("\n");
|
al@865
|
492 }
|
al@865
|
493 clean();
|
al@865
|
494 }
|
al@865
|
495 }
|
al@865
|
496 if ($0 == "") skip = "";
|
al@865
|
497 }
|
al@865
|
498 ' "$tmpfile" > "$tmpfile.awk"
|
al@865
|
499
|
al@865
|
500 msgfmt "$tmpfile.awk" -o "$tmpfile.mo"
|
al@865
|
501
|
al@865
|
502 if [ -s "$tmpfile.mo" ]; then
|
al@865
|
503 rm "$mo"; mv "$tmpfile.mo" "$mo"
|
al@865
|
504 else
|
al@865
|
505 _ 'Error processing %s' "$mo"
|
al@865
|
506 [ -e "$tmpfile.mo" ] && rm "$tmpfile.mo"
|
al@865
|
507 fi
|
al@865
|
508
|
al@865
|
509 # Clean
|
al@865
|
510 rm "$tmpfile" "$tmpfile.pf" "$tmpfile.awk"
|
al@865
|
511 done
|
al@865
|
512
|
al@865
|
513 comp_summary "$time0" "$size0" "$(sizes mo1)"
|
al@865
|
514 }
|
al@865
|
515
|
al@865
|
516
|
al@865
|
517 # Strip locale definitions: normalize whitespace and remove comments
|
al@865
|
518 # Stripping can be disabled with COOKOPTS="!locdef"
|
al@865
|
519
|
al@865
|
520 strip_locale_def() {
|
al@865
|
521 [ "${COOKOPTS/!locdef/}" != "$COOKOPTS" ] && return
|
al@865
|
522 [ ! -d "$install/usr/share/i18n/locales" ] && return
|
al@865
|
523 [ -z "$(find $install/usr/share/i18n/locales -type f)" ] && return
|
al@865
|
524
|
al@865
|
525 action 'Stripping locale definitions...'
|
al@865
|
526 size0=$(sizes loc)
|
al@881
|
527 time0=$(get_time)
|
al@865
|
528
|
al@865
|
529 for i in $(find $install/usr/share/i18n/locales -type f); do
|
al@865
|
530 sed -i 's| | |g; s| *| |g; s|^ ||; /^%/d' $i
|
al@865
|
531 done
|
al@865
|
532
|
al@865
|
533 comp_summary "$time0" "$size0" "$(sizes loc)"
|
al@865
|
534 }
|
al@865
|
535
|
al@865
|
536
|
al@865
|
537 # Find and strip: --strip-all (-s) or --strip-debug on static libs as well
|
al@865
|
538 # as removing unneeded files like in Python packages. Cross compiled binaries
|
al@865
|
539 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
|
al@865
|
540 # Stripping can be disabled with COOKOPTS="!strip"
|
al@865
|
541
|
al@865
|
542 strip_package() {
|
al@865
|
543 [ "${COOKOPTS/!strip/}" != "$COOKOPTS" ] && return
|
al@865
|
544
|
al@865
|
545 case "$ARCH" in
|
al@865
|
546 arm*|x86_64) export STRIP="$HOST_SYSTEM-strip" ;;
|
al@865
|
547 *) export STRIP='strip' ;;
|
al@865
|
548 esac
|
al@865
|
549 action 'Executing strip on all files...'
|
al@865
|
550 size0=0
|
al@865
|
551 size1=0
|
al@881
|
552 time0=$(get_time)
|
al@865
|
553
|
al@865
|
554 # Strip executable files
|
al@865
|
555 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games; do
|
al@865
|
556 if [ -d "$dir" ]; then
|
al@865
|
557 oldsize=$(find $dir -type f -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
|
al@865
|
558 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
|
al@865
|
559 newsize=$(find $dir -type f -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
|
al@865
|
560 size0=$((size0 + oldsize)); size1=$((size1 + newsize))
|
al@865
|
561 fi
|
al@865
|
562 done
|
al@865
|
563
|
al@899
|
564 oldsize=$(sizes str)
|
al@899
|
565
|
al@865
|
566 # Strip shared and static libraries
|
al@865
|
567 find $fs -name '*.so*' -exec $STRIP -s '{}' 2>/dev/null \;
|
al@955
|
568 find $fs -name '*.a' -exec $STRIP -d '{}' 2>/dev/null \;
|
al@955
|
569
|
al@955
|
570 # Nullify timestamps of files in ar archives
|
al@957
|
571 # Skip empty 8-byte archives (hi, musl-libc package)
|
al@955
|
572 whereami=$(pwd)
|
al@957
|
573 find $fs -name '*.a' -type f -size +8c | \
|
al@955
|
574 while read i; do
|
al@955
|
575 tempdir=$(mktemp -d); cd $tempdir
|
al@955
|
576 ar -x $i; ar -crD $(basename $i) *
|
al@955
|
577 mv -f $tempdir/$(basename $i) $i
|
al@955
|
578 rm -rf $tempdir
|
al@955
|
579 done
|
al@955
|
580 cd $whereami; unset whereami
|
al@899
|
581
|
al@899
|
582 # Remove Python *.pyc and *.pyo
|
al@865
|
583 find $fs -type f \( -name '*.pyc' -o -name '*.pyo' \) -delete 2>/dev/null
|
al@865
|
584
|
al@899
|
585 # Remove both with the empty subfolders:
|
al@899
|
586 # 1. Perl perllocal.pod and .packlist (unconditionally)
|
al@899
|
587 local perlfiles="$(find $fs -type f \( -name 'perllocal.pod' -o -name '.packlist' \))"
|
al@899
|
588 # 2. Perl *.pod (if not disabled)
|
al@899
|
589 [ "${COOKOPTS/!rmpod/}" == "$COOKOPTS" ] &&
|
al@899
|
590 perlfiles="$perlfiles $(find $fs -type f -name '*.pod')"
|
al@899
|
591 echo "$perlfiles" | xargs rm -f 2>/dev/null
|
al@899
|
592 echo "$perlfiles" | awk 'BEGIN{FS=OFS="/"}{$NF="";print}' | xargs rmdir -p 2>/dev/null
|
al@899
|
593
|
al@899
|
594 # Strip Perl files (*.pm and *.pl) from documentation inside (if not disabled)
|
al@899
|
595 [ "${COOKOPTS/!perlz/}" == "$COOKOPTS" ] &&
|
al@899
|
596 find $fs -type f \( -name '*.pm' -o -name '*.pl' \) -exec sed -i '/^=/,/^=cut/d' '{}' \;
|
al@899
|
597
|
al@899
|
598 newsize=$(sizes str)
|
al@865
|
599
|
al@865
|
600 comp_summary "$time0" "$((size0 + oldsize))" "$((size1 + newsize))"
|
al@865
|
601 }
|
al@865
|
602
|
al@865
|
603
|
al@865
|
604 # Strip unsupported locales (.mo files)
|
al@865
|
605
|
al@865
|
606 strip_mo_i18n() {
|
al@865
|
607 [ "${COOKOPTS/!i18nz/}" != "$COOKOPTS" ] && return
|
al@865
|
608
|
al@865
|
609 [ ! -d "$fs/usr/share/locale" ] && return
|
al@865
|
610 [ -z "$(find $fs/usr/share/locale -type f -name '*.mo')" ] && return
|
al@865
|
611
|
al@865
|
612 action 'Thin out translation files...'
|
al@865
|
613 size0=$(sizes mo2)
|
al@881
|
614 time0=$(get_time)
|
al@865
|
615
|
al@865
|
616 # The variable $LOCALE is set in cook.conf and may be overridden in the receipt.
|
al@865
|
617 # Default value is "" (empty). That means for us that we'll use the full
|
al@865
|
618 # list of supported locales here.
|
al@865
|
619 [ -z "$LOCALE" ] && LOCALE=$(get_supported_locales)
|
al@865
|
620
|
al@865
|
621 # Existing locales
|
al@865
|
622 elocales=" $(ls -1 "$fs/usr/share/locale" | tr '\n' ' ') "
|
al@865
|
623
|
al@865
|
624 # Thin out the list of existing locales. At the end there will be only locales that need
|
al@865
|
625 # deleting (and the garbage like '_AU', _US', '_BR' leaving from 'en_AU', 'en_US', 'pt_BR'...)
|
al@865
|
626 for keep_locale in $LOCALE; do
|
al@865
|
627 elocales=${elocales//$keep_locale}
|
al@865
|
628 done
|
al@865
|
629
|
al@865
|
630 # Remove the unsupported locales
|
al@865
|
631 for rem_locale in $elocales; do
|
al@865
|
632 [ -d "$fs/usr/share/locale/$rem_locale" ] &&
|
al@865
|
633 rm -r "$fs/usr/share/locale/$rem_locale"
|
al@865
|
634 done
|
al@865
|
635
|
al@865
|
636 comp_summary "$time0" "$size0" "$(sizes mo2)"
|
al@865
|
637 }
|
al@865
|
638
|
al@865
|
639
|
al@865
|
640
|
al@865
|
641
|
al@865
|
642 case $1 in
|
al@865
|
643 install)
|
al@865
|
644 # Compressors working in the $install
|
al@865
|
645 case "$ARCH" in
|
al@865
|
646 arm*) ;;
|
al@865
|
647 *)
|
al@872
|
648 recompress_gz
|
al@954
|
649 recompress_zip
|
al@865
|
650 compress_manpages
|
al@865
|
651 compress_png
|
al@865
|
652 compress_svg
|
al@865
|
653 compress_ui
|
al@865
|
654 ;;
|
al@865
|
655 esac
|
al@865
|
656
|
al@865
|
657 fix_desktop_files
|
al@865
|
658 normalize_mo
|
al@865
|
659 strip_locale_def
|
al@865
|
660 ;;
|
al@865
|
661 fs)
|
al@865
|
662 # Compressors working in the $fs
|
al@865
|
663 strip_package
|
al@865
|
664 strip_mo_i18n
|
al@865
|
665 ;;
|
al@865
|
666 esac
|
al@868
|
667
|
al@868
|
668 # Clean
|
al@868
|
669 rm "$cache_stat"
|
al@869
|
670 find $comp_cache_root -type f -links -2 -delete
|