cookutils rev 865

Split modules/compressor (~500 lines of code) from cook.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Wed Jan 11 11:53:04 2017 +0200 (2017-01-11)
parents e6307b60adc8
children fd06b19f712b
files Makefile cook modules/compressor modules/pkgdb web/cooker.cgi
line diff
     1.1 --- a/Makefile	Wed Jan 11 00:31:18 2017 +0200
     1.2 +++ b/Makefile	Wed Jan 11 11:53:04 2017 +0200
     1.3 @@ -28,7 +28,8 @@
     1.4  	install -m 0755 cooker           $(DESTDIR)$(PREFIX)/bin
     1.5  	install -m 0755 cookiso          $(DESTDIR)$(PREFIX)/bin
     1.6  	install -m 0755 cooklinux        $(DESTDIR)$(PREFIX)/bin
     1.7 -	install -m 0755 modules/pkgdb    $(DESTDIR)$(PREFIX)/libexec/cookutils
     1.8 +	install -m 0755 modules/pkgdb modules/compressor \
     1.9 +									 $(DESTDIR)$(PREFIX)/libexec/cookutils
    1.10  	install -m 0644 cook.conf        $(DESTDIR)/etc/slitaz
    1.11  	install -m 0644 cook.site        $(DESTDIR)/etc/slitaz
    1.12  	install -m 0644 web/*            $(DESTDIR)/var/www/cgi-bin/cooker
     2.1 --- a/cook	Wed Jan 11 00:31:18 2017 +0200
     2.2 +++ b/cook	Wed Jan 11 11:53:04 2017 +0200
     2.3 @@ -480,311 +480,6 @@
     2.4  }
     2.5  
     2.6  
     2.7 -# Get list of supported locales...
     2.8 -
     2.9 -get_supported_locales() {
    2.10 -	local lpc='/slitaz-i18n/stuff/locale-pack.conf' LOCALE_PACK
    2.11 -	if [ -e "$WOK$lpc" ]; then
    2.12 -		# ... from package in the local wok
    2.13 -		. "$WOK$lpc"
    2.14 -	else
    2.15 -		# ... from Hg
    2.16 -		temp_conf=$(mktemp)
    2.17 -		wget -q -O $temp_conf -T 10 "http://hg.slitaz.org/wok/raw-file/tip$lpc"
    2.18 -		if [ -s $temp_conf ]; then
    2.19 -			. $temp_conf
    2.20 -		else
    2.21 -			# Give up and use hardcoded list
    2.22 -			LOCALE_PACK="ar ca cs da de el en es fi fr hr hu id is it ja nb nl nn pl pt \
    2.23 -			pt_BR ro ru sl sv tr uk zh_CN zh_TW"
    2.24 -		fi
    2.25 -		rm $temp_conf
    2.26 -	fi
    2.27 -	echo $LOCALE_PACK
    2.28 -}
    2.29 -
    2.30 -
    2.31 -# Fix common errors and warnings in the .desktop files
    2.32 -# Fixing can be disabled with COOKOPTS="!fixdesktops"
    2.33 -
    2.34 -fix_desktop_files() {
    2.35 -	[ "${COOKOPTS/!fixdesktops/}" != "$COOKOPTS" ] && return
    2.36 -	[ -z "$(find $install -type f -name '*.desktop')" ] && return
    2.37 -
    2.38 -	local size0=$(find $install -type f -name '*.desktop' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
    2.39 -	local time0=$(date +%s)
    2.40 -
    2.41 -	if [ -n "$QA" -a -z "$(which desktop-file-validate)" ]; then
    2.42 -		tazpkg -gi desktop-file-utils-extra --quiet
    2.43 -	fi
    2.44 -
    2.45 -	# The variable $LOCALE is set in cook.conf and may be overridden in the receipt.
    2.46 -	# Default value is "" (empty). That means for us that we'll use the full
    2.47 -	# list of supported locales here.
    2.48 -	[ -z "$LOCALE" ] && LOCALE=$(get_supported_locales)
    2.49 -
    2.50 -	for desktop in $(find $install -type f -name '*.desktop'); do
    2.51 -		cp "$desktop" "$desktop.orig"
    2.52 -
    2.53 -		# Sort out .desktop file (is prerequisite to correct working of `fix-desktop-file`)
    2.54 -		sdft "$desktop" -i
    2.55 -
    2.56 -		# Fix common errors in .desktop file
    2.57 -		fix-desktop-file "$desktop"
    2.58 -
    2.59 -		# Strip unsupported locales from .desktop file
    2.60 -		[ "${COOKOPTS/!i18nz/}" == "$COOKOPTS" ] &&
    2.61 -			sdft "$desktop" -i -k "$LOCALE"
    2.62 -
    2.63 -		# Extra-strip
    2.64 -		[ "${COOKOPTS/!extradesktops/}" == "$COOKOPTS" ] &&
    2.65 -			sdft "$desktop" -i -g -x -tf -r 'Keywords*' -o
    2.66 -
    2.67 -		if [ -n "$QA" ]; then
    2.68 -			# Check the rest of errors, warnings and tips
    2.69 -			_ 'QA: Checking %s...' "$(basename $desktop)"
    2.70 -			diff "$desktop.orig" "$desktop"
    2.71 -			desktop-file-validate "$desktop" | busybox fold -s
    2.72 -			echo
    2.73 -		fi
    2.74 -
    2.75 -		rm "$desktop.orig"
    2.76 -	done
    2.77 -
    2.78 -	local size1=$(find $install -type f -name '*.desktop' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
    2.79 -	local time1=$(date +%s)
    2.80 -	comp_summary "$time0" "$time1" "$size0" "$size1"
    2.81 -}
    2.82 -
    2.83 -
    2.84 -# Compressor mini summary
    2.85 -
    2.86 -comp_summary() {
    2.87 -	[ "$3" -eq 0 ] && return
    2.88 -	local time=$(($2 - $1))
    2.89 -	local saving=$(( ($3 - $4) / 1024 ))
    2.90 -	_ '  Time: %s. Size: %s B -> %s B. Save: %s KB' "$(disp_time $time)" "$3" "$4" "$saving"
    2.91 -}
    2.92 -
    2.93 -
    2.94 -# Find and strip: --strip-all (-s) or --strip-debug on static libs as well
    2.95 -# as removing unneeded files like in Python packages. Cross compiled binaries
    2.96 -# must be stripped with cross-tools aka $ARCH-slitaz-*-strip
    2.97 -# Stripping can be disabled with COOKOPTS="!strip"
    2.98 -
    2.99 -strip_package() {
   2.100 -	[ "${COOKOPTS/!strip/}" != "$COOKOPTS" ] && return
   2.101 -
   2.102 -	case "$ARCH" in
   2.103 -		arm*|x86_64) export STRIP="$HOST_SYSTEM-strip" ;;
   2.104 -		*)           export STRIP='strip' ;;
   2.105 -	esac
   2.106 -	action 'Executing strip on all files...'
   2.107 -	local size0=0 size1=0 oldsize newsize
   2.108 -	local time0=$(date +%s)
   2.109 -
   2.110 -	# Strip executable files
   2.111 -	for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games; do
   2.112 -		if [ -d "$dir" ]; then
   2.113 -			oldsize=$(find $dir -type f -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
   2.114 -			find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
   2.115 -			newsize=$(find $dir -type f -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
   2.116 -			size0=$((size0 + oldsize)); size1=$((size1 + newsize))
   2.117 -		fi
   2.118 -	done
   2.119 -
   2.120 -	# Strip shared and static libraries
   2.121 -	# Remove Python *.pyc and *.pyo, Perl perllocal.pod and .packlist
   2.122 -	oldsize=$(find $fs -type f \( \
   2.123 -		-name '*.so*' -o -name '*.a' -o \
   2.124 -		-name '*.pyc' -o -name '*.pyo' -o \
   2.125 -		-name 'perllocal.pod' -o -name '.packlist' \) -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
   2.126 -
   2.127 -	find $fs -name '*.so*' -exec $STRIP -s '{}' 2>/dev/null \;
   2.128 -	find $fs -name '*.a' -exec $STRIP --strip-debug '{}' 2>/dev/null \;
   2.129 -	find $fs -type f \( -name '*.pyc' -o -name '*.pyo' \) -delete 2>/dev/null
   2.130 -	find $fs -type f \( -name 'perllocal.pod' -o -name '.packlist' \) -delete 2>/dev/null
   2.131 -
   2.132 -	newsize=$(find $fs -type f \( \
   2.133 -		-name '*.so*' -o -name '*.a' -o \) -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
   2.134 -
   2.135 -	size0=$((size0 + oldsize)); size1=$((size1 + newsize))
   2.136 -
   2.137 -	local time1=$(date +%s)
   2.138 -	status
   2.139 -	comp_summary "$time0" "$time1" "$size0" "$size1"
   2.140 -}
   2.141 -
   2.142 -
   2.143 -# Strip unsupported locales (.mo files)
   2.144 -
   2.145 -strip_mo_i18n() {
   2.146 -	[ "${COOKOPTS/!i18nz/}" != "$COOKOPTS" ] && return
   2.147 -
   2.148 -	[ ! -d "$fs/usr/share/locale" ] && return
   2.149 -	[ -z "$(find $fs/usr/share/locale -type f -name '*.mo')" ] && return
   2.150 -
   2.151 -	action 'Thin out translation files...'
   2.152 -	local size0=$(find $fs/usr/share/locale -type f -name '*.mo' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
   2.153 -	local time0=$(date +%s)
   2.154 -
   2.155 -	# The variable $LOCALE is set in cook.conf and may be overridden in the receipt.
   2.156 -	# Default value is "" (empty). That means for us that we'll use the full
   2.157 -	# list of supported locales here.
   2.158 -	[ -z "$LOCALE" ] && LOCALE=$(get_supported_locales)
   2.159 -
   2.160 -	# Existing locales
   2.161 -	elocales=" $(ls -1 "$fs/usr/share/locale" | tr '\n' ' ') "
   2.162 -
   2.163 -	# Thin out the list of existing locales. At the end there will be only locales that need
   2.164 -	# deleting (and the garbage like '_AU', _US', '_BR' leaving from 'en_AU', 'en_US', 'pt_BR'...)
   2.165 -	for keep_locale in $LOCALE; do
   2.166 -		elocales=${elocales//$keep_locale}
   2.167 -	done
   2.168 -
   2.169 -	# Remove the unsupported locales
   2.170 -	for rem_locale in $elocales; do
   2.171 -		[ -d "$fs/usr/share/locale/$rem_locale" ] &&
   2.172 -			rm -r "$fs/usr/share/locale/$rem_locale"
   2.173 -	done
   2.174 -
   2.175 -	local size1=$(find $fs -type f -name '*.mo' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
   2.176 -	local time1=$(date +%s)
   2.177 -	status
   2.178 -	comp_summary "$time0" "$time1" "$size0" "$size1"
   2.179 -}
   2.180 -
   2.181 -
   2.182 -# Normalize all *.mo files: unconditionally convert to UTF-8; remove strings that are not really added
   2.183 -# to the translation (msgid = msgstr)
   2.184 -# Normalization can be disabled with COOKOPTS="!monorm"
   2.185 -
   2.186 -normalize_mo() {
   2.187 -	[ "${COOKOPTS/!monorm/}" != "$COOKOPTS" ] && return
   2.188 -	[ -z "$(find $install -type f -name '*.mo')" ] && return
   2.189 -
   2.190 -	action 'Normalizing mo files...'
   2.191 -	local size0=$(find $install -type f -name '*.mo' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
   2.192 -	local time0=$(date +%s)
   2.193 -
   2.194 -	# Gettext functions: msgunfmt, msguniq, msgconv, msgfmt
   2.195 -	tazpkg -gi gettext      --quiet
   2.196 -	# Gconv modules (convert to UTF-8)
   2.197 -	tazpkg -gi glibc-locale --quiet
   2.198 -
   2.199 -	# Process all existing *.mo files
   2.200 -	for mo in $(find "$install" -type f -name '*.mo'); do
   2.201 -		tmpfile="$(mktemp)"
   2.202 -
   2.203 -		msgunfmt "$mo" | msguniq | msgconv -o "$tmpfile" -t 'UTF-8'
   2.204 -		# add newline
   2.205 -		echo >> "$tmpfile"
   2.206 -
   2.207 -		# get Plural-Forms
   2.208 -		awk '
   2.209 -		BEGIN { skip = ""; }
   2.210 -		{
   2.211 -			if (! skip) {
   2.212 -				s = $0;
   2.213 -				gsub(/^[^\"]*\"/, "", s);
   2.214 -				gsub(/\"$/, "", s);
   2.215 -				printf("%s", s);
   2.216 -			}
   2.217 -			if (! $0) skip = "yes";
   2.218 -		}
   2.219 -		' "$tmpfile" | sed 's|\\n|\n|g' | grep "^Plural-Forms:" > "$tmpfile.pf"
   2.220 -
   2.221 -		if ! grep -q 'msgid_plural' "$tmpfile"; then
   2.222 -			echo > "$tmpfile.pf"
   2.223 -		fi
   2.224 -
   2.225 -		# main
   2.226 -		awk -v pf="$(cat "$tmpfile.pf")" '
   2.227 -		function clean() {
   2.228 -			mode = msgctxt = msgid = msgid_plural = msgstr = msgstr0 = msgstr1 = msgstr2 = msgstr3 = msgstr4 = msgstr5 = "";
   2.229 -		}
   2.230 -
   2.231 -		function getstring() {
   2.232 -			# Skip unquoted words at the beginning (msgid, msgstr...) and get string from inside quotes
   2.233 -			s = $0;
   2.234 -			gsub(/^[^\"]*\"/, "", s);
   2.235 -			gsub(/\"$/, "", s);
   2.236 -			return s;
   2.237 -		}
   2.238 -
   2.239 -		BEGIN {
   2.240 -			printf("msgid \"\"\nmsgstr \"\"\n\"Content-Type: text/plain; charset=UTF-8\\n\"\n");
   2.241 -			if (pf)
   2.242 -				printf("\"%s\\n\"\n", pf);
   2.243 -			printf("\n");
   2.244 -			skip = 1;
   2.245 -			clean();
   2.246 -		}
   2.247 -
   2.248 -		{
   2.249 -			# Skip the entire header
   2.250 -			if (!skip) {
   2.251 -				if ($1 == "msgctxt" || $1 == "msgid" || $1 == "msgstr" || $1 == "msgid_plural")
   2.252 -					mode = $1;
   2.253 -				if ($1 == "msgstr[0]") mode = "msgstr0";
   2.254 -				if ($1 == "msgstr[1]") mode = "msgstr1";
   2.255 -				if ($1 == "msgstr[2]") mode = "msgstr2";
   2.256 -				if ($1 == "msgstr[3]") mode = "msgstr3";
   2.257 -				if ($1 == "msgstr[4]") mode = "msgstr4";
   2.258 -				if ($1 == "msgstr[5]") mode = "msgstr5";
   2.259 -
   2.260 -				if (mode == "msgctxt")      msgctxt      = msgctxt      getstring();
   2.261 -				if (mode == "msgid")        msgid        = msgid        getstring();
   2.262 -				if (mode == "msgstr")       msgstr       = msgstr       getstring();
   2.263 -				if (mode == "msgid_plural") msgid_plural = msgid_plural getstring();
   2.264 -				if (mode == "msgstr0")      msgstr0      = msgstr0      getstring();
   2.265 -				if (mode == "msgstr1")      msgstr1      = msgstr1      getstring();
   2.266 -				if (mode == "msgstr2")      msgstr2      = msgstr2      getstring();
   2.267 -				if (mode == "msgstr3")      msgstr3      = msgstr3      getstring();
   2.268 -				if (mode == "msgstr4")      msgstr4      = msgstr4      getstring();
   2.269 -				if (mode == "msgstr5")      msgstr5      = msgstr5      getstring();
   2.270 -
   2.271 -				if (! $0) {
   2.272 -					if (msgid != msgstr) {
   2.273 -						if (msgctxt)      printf("msgctxt \"%s\"\n",      msgctxt);
   2.274 -						                  printf("msgid \"%s\"\n",        msgid);
   2.275 -						if (msgid_plural) printf("msgid_plural \"%s\"\n", msgid_plural);
   2.276 -						if (msgstr)       printf("msgstr \"%s\"\n",       msgstr);
   2.277 -						if (msgstr0)      printf("msgstr[0] \"%s\"\n",    msgstr0);
   2.278 -						if (msgstr1)      printf("msgstr[1] \"%s\"\n",    msgstr1);
   2.279 -						if (msgstr2)      printf("msgstr[2] \"%s\"\n",    msgstr2);
   2.280 -						if (msgstr3)      printf("msgstr[3] \"%s\"\n",    msgstr3);
   2.281 -						if (msgstr4)      printf("msgstr[4] \"%s\"\n",    msgstr4);
   2.282 -						if (msgstr5)      printf("msgstr[5] \"%s\"\n",    msgstr5);
   2.283 -						                  printf("\n");
   2.284 -					}
   2.285 -					clean();
   2.286 -				}
   2.287 -			}
   2.288 -			if ($0 == "") skip = "";
   2.289 -		}
   2.290 -		' "$tmpfile" > "$tmpfile.awk"
   2.291 -
   2.292 -		msgfmt "$tmpfile.awk" -o "$tmpfile.mo"
   2.293 -
   2.294 -		if [ -s "$tmpfile.mo" ]; then
   2.295 -			rm "$mo"; mv "$tmpfile.mo" "$mo"
   2.296 -		else
   2.297 -			_ 'Error processing %s' "$mo"
   2.298 -			[ -e "$tmpfile.mo" ] && rm "$tmpfile.mo"
   2.299 -		fi
   2.300 -
   2.301 -		# Clean
   2.302 -		rm "$tmpfile" "$tmpfile.pf" "$tmpfile.awk"
   2.303 -	done
   2.304 -
   2.305 -	local size1=$(find $install -type f -name '*.mo' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
   2.306 -	local time1=$(date +%s)
   2.307 -	status
   2.308 -	comp_summary "$time0" "$time1" "$size0" "$size1"
   2.309 -}
   2.310 -
   2.311 -
   2.312  # Remove files provided by split packages
   2.313  # For example:
   2.314  #   1. Package "pkg-main":
   2.315 @@ -841,147 +536,6 @@
   2.316  }
   2.317  
   2.318  
   2.319 -# Function to compress all man pages
   2.320 -# Compressing can be disabled with COOKOPTS="!manz"
   2.321 -
   2.322 -compress_manpages() {
   2.323 -	[ "${COOKOPTS/!manz/}" != "$COOKOPTS" ] && return
   2.324 -
   2.325 -	case "$ARCH" in
   2.326 -		arm*) return;; # While SliTaz-arm miss `advancecomp`
   2.327 -	esac
   2.328 -	local manpath="$install/usr/share/man" dest link
   2.329 -	[ -d "$manpath" ] || return
   2.330 -
   2.331 -	action 'Compressing man pages...'
   2.332 -
   2.333 -	local size0=$(find $install/usr/share/man -type f -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
   2.334 -	local time0=$(date +%s)
   2.335 -	# We'll use only Gzip compression, so decompress other formats first
   2.336 -	find $manpath -type f -name '*.bz2' -exec bunzip2 \{\} \;
   2.337 -	find $manpath -type f -name '*.xz'  -exec unxz    \{\} \;
   2.338 -
   2.339 -	# Fast compress with gzip
   2.340 -	find $manpath -type f -name '*.[1-9]*' -exec gzip \{\} \;
   2.341 -
   2.342 -	# Fix symlinks
   2.343 -	for i in $(find $install/usr/share/man -type l); do
   2.344 -		dest=$(readlink $i | sed 's|\.[gbx]z2*$||')
   2.345 -		link=$(echo $i | sed 's|\.[gbx]z2*$||')
   2.346 -		rm $i; ln -s $dest.gz $link.gz
   2.347 -	done
   2.348 -
   2.349 -	# Recompress with advdef (it can't compress, only recompress)
   2.350 -	tazpkg -gi advancecomp --quiet
   2.351 -	for i in $(find $install/usr/share/man -type f); do
   2.352 -		advdef -z4q $i
   2.353 -	done
   2.354 -
   2.355 -	local size1=$(find $install/usr/share/man -type f -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
   2.356 -	local time1=$(date +%s)
   2.357 -	status
   2.358 -	comp_summary "$time0" "$time1" "$size0" "$size1"
   2.359 -}
   2.360 -
   2.361 -
   2.362 -# Function used after compile_rules() to compress all png images
   2.363 -# Compressing can be disabled with COOKOPTS="!pngz"
   2.364 -
   2.365 -compress_png() {
   2.366 -	[ "${COOKOPTS/!pngz/}" != "$COOKOPTS" ] && return
   2.367 -	case "$ARCH" in
   2.368 -		arm*) return;; # While SliTaz-arm miss `pngquant` and `optipng`
   2.369 -	esac
   2.370 -	[ -z "$(find $install -type f -name '*.png')" ] && return
   2.371 -
   2.372 -	action 'Compressing png images...'
   2.373 -	local size0=$(find $install -type f -name '*.png' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
   2.374 -	local time0=$(date +%s)
   2.375 -
   2.376 -	local use_pq=true use_op=true
   2.377 -	[ "${COOKOPTS/!pngquant/}" != "$COOKOPTS" ] && use_pq=false
   2.378 -	[ "${COOKOPTS/!optipng/}"  != "$COOKOPTS" ] && use_op=false
   2.379 -
   2.380 -	$use_pq && tazpkg -gi pngquant --quiet
   2.381 -	$use_op && tazpkg -gi optipng --quiet
   2.382 -
   2.383 -	local oplevel=$(echo $COOKOPTS | grep 'op[0-8]' | sed 's|.*op\([0-8]\).*|\1|')
   2.384 -	[ -z "$oplevel" ]     && oplevel='2'
   2.385 -	[ "$oplevel" == '8' ] && oplevel='7 -zm1-9'
   2.386 -
   2.387 -	for i in $(find $install -type f -name '*.png'); do
   2.388 -		$use_pq && pngquant -f --skip-if-larger --ext .png --speed 1 "$i"
   2.389 -		$use_op && optipng -quiet -strip all -o$oplevel "$i"
   2.390 -	done
   2.391 -
   2.392 -	local size1=$(find $install -type f -name '*.png' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
   2.393 -	local time1=$(date +%s)
   2.394 -	status
   2.395 -	comp_summary "$time0" "$time1" "$size0" "$size1"
   2.396 -}
   2.397 -
   2.398 -
   2.399 -# Function used after compile_rules() to compress all svg images
   2.400 -# Compressing can be disabled with COOKOPTS="!svgz"
   2.401 -
   2.402 -compress_svg() {
   2.403 -	[ "${COOKOPTS/!svgz/}" != "$COOKOPTS" ] && return
   2.404 -	case "$ARCH" in
   2.405 -		arm*) return;; # While SliTaz-arm miss `svgcleaner`
   2.406 -	esac
   2.407 -	[ -z "$(find $install -type f -name '*.svg')" ] && return
   2.408 -
   2.409 -	action 'Compressing svg images...'
   2.410 -	local size0=$(find $install -type f -name '*.svg' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
   2.411 -	local time0=$(date +%s)
   2.412 -	tazpkg -gi svgcleaner --quiet
   2.413 -	cleaner_log="$(mktemp)"
   2.414 -	for i in $(find $install -type f -name '*.svg'); do
   2.415 -		echo -n "$i: " >> "$cleaner_log"
   2.416 -		svgcleaner "$i" "$i" --remove-unresolved-classes false --quiet true >> "$cleaner_log"
   2.417 -	done
   2.418 -	local size1=$(find $install -type f -name '*.svg' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
   2.419 -	local time1=$(date +%s)
   2.420 -	status
   2.421 -	comp_summary "$time0" "$time1" "$size0" "$size1"
   2.422 -	sed -i '/: $/d' "$cleaner_log"
   2.423 -	if [ -s "$cleaner_log" ]; then
   2.424 -		_ 'Cleaner warnings and errors:'
   2.425 -		awk '{printf "  %s\n", $0;}' "$cleaner_log"
   2.426 -		echo
   2.427 -	fi
   2.428 -	rm "$cleaner_log"
   2.429 -}
   2.430 -
   2.431 -
   2.432 -# Function used after compile_rules() to shrink all *.ui and *.glade files:
   2.433 -# remove insignificant spaces and comments
   2.434 -# Compressing can be disabled with COOKOPTS="!uiz"
   2.435 -
   2.436 -compress_ui() {
   2.437 -	[ "${COOKOPTS/!uiz/}" != "$COOKOPTS" ] && return
   2.438 -	case "$ARCH" in
   2.439 -		arm*) return;; # While SliTaz-arm miss `xmlstarlet`
   2.440 -	esac
   2.441 -	[ -z "$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) )" ] && return
   2.442 -
   2.443 -	action 'Compressing ui files...'
   2.444 -	local size0=$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
   2.445 -	local time0=$(date +%s)
   2.446 -	tazpkg -gi xmlstarlet --quiet
   2.447 -	temp_ui="$(mktemp)"
   2.448 -	for ui in $(find $install -type f \( -name '*.ui' -o -name '*.glade' \) ); do
   2.449 -		xmlstarlet c14n --without-comments "$ui" | xmlstarlet sel -B -t -c '*' > "$temp_ui"
   2.450 -		cat "$temp_ui" > "$ui"
   2.451 -	done
   2.452 -	local size1=$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
   2.453 -	local time1=$(date +%s)
   2.454 -	status
   2.455 -	comp_summary "$time0" "$time1" "$size0" "$size1"
   2.456 -	rm "$temp_ui"
   2.457 -}
   2.458 -
   2.459 -
   2.460  # The main cook function.
   2.461  
   2.462  cookit() {
   2.463 @@ -1199,12 +753,7 @@
   2.464  	# Skip all for split packages (already done in main package)
   2.465  	if [ -z "$WANTED" ]; then
   2.466  		footer
   2.467 -		compress_manpages
   2.468 -		compress_png
   2.469 -		compress_svg
   2.470 -		compress_ui
   2.471 -		fix_desktop_files
   2.472 -		normalize_mo
   2.473 +		export COOKOPTS ARCH install; @@PREFIX@@/libexec/cookutils/compressor install
   2.474  	fi
   2.475  	footer
   2.476  
   2.477 @@ -1286,8 +835,7 @@
   2.478  	copy_generic_files
   2.479  
   2.480  	# Strip and stuff files.
   2.481 -	strip_package
   2.482 -	strip_mo_i18n
   2.483 +	export COOKOPTS ARCH HOST_SYSTEM LOCALE fs; @@PREFIX@@/libexec/cookutils/compressor fs
   2.484  
   2.485  	# Create files.list with redirecting find output.
   2.486  	action 'Creating the list of files...'
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/modules/compressor	Wed Jan 11 11:53:04 2017 +0200
     3.3 @@ -0,0 +1,506 @@
     3.4 +#!/bin/sh
     3.5 +#
     3.6 +# compressor - module of the SliTaz Cook
     3.7 +# Copyright (C) SliTaz GNU/Linux - GNU GPL v3
     3.8 +#
     3.9 +
    3.10 +. /usr/lib/slitaz/libcook.sh
    3.11 +
    3.12 +
    3.13 +#
    3.14 +# Functions
    3.15 +#
    3.16 +
    3.17 +
    3.18 +# Display time.
    3.19 +
    3.20 +disp_time() {
    3.21 +	div=$(( ($1 + 30) / 60))
    3.22 +	case $div in
    3.23 +		0) min='';;
    3.24 +		# L10n: 'm' is for minutes (approximate time)
    3.25 +		*) min=$(_n ' ~ %dm' "$div");;
    3.26 +	esac
    3.27 +
    3.28 +	# L10n: 's' is for seconds (cooking time)
    3.29 +	_ '%ds%s' "$1" "$min"
    3.30 +}
    3.31 +
    3.32 +
    3.33 +# Compressor mini summary
    3.34 +
    3.35 +comp_summary() {
    3.36 +	# "$time0" "$size0" "$size1"
    3.37 +	time1=$(date +%s)
    3.38 +	status
    3.39 +	[ "$2" -eq 0 ] && return
    3.40 +	time=$(($time1 - $1))
    3.41 +	saving=$(( ($2 - $3) / 1024 ))
    3.42 +	_ '  Time: %s. Size: %s B -> %s B. Save: %s KB' "$(disp_time $time)" "$2" "$3" "$saving"
    3.43 +}
    3.44 +
    3.45 +
    3.46 +# Calculating different sizes
    3.47 +
    3.48 +sizes() {
    3.49 +	case $1 in
    3.50 +		man) find $install/usr/share/man          -type f                                       -exec ls -l \{\} \; ;;
    3.51 +		png) find $install                        -type f -name '*.png'                         -exec ls -l \{\} \; ;;
    3.52 +		svg) find $install                        -type f -name '*.svg'                         -exec ls -l \{\} \; ;;
    3.53 +		xml) find $install                        -type f \( -name '*.ui' -o -name '*.glade' \) -exec ls -l \{\} \; ;;
    3.54 +		des) find $install                        -type f -name '*.desktop'                     -exec ls -l \{\} \; ;;
    3.55 +		mo1) find $install                        -type f -name '*.mo'                          -exec ls -l \{\} \; ;;
    3.56 +		loc) find $install/usr/share/i18n/locales -type f                                       -exec ls -l \{\} \; ;;
    3.57 +		mo2) find $fs/usr/share/locale            -type f -name '*.mo'                          -exec ls -l \{\} \; ;;
    3.58 +	esac | awk '{s+=$5}END{print s}'
    3.59 +}
    3.60 +
    3.61 +
    3.62 +# Function to compress all man pages
    3.63 +# Compressing can be disabled with COOKOPTS="!manz"
    3.64 +
    3.65 +compress_manpages() {
    3.66 +	time0=$(date +%s)
    3.67 +	[ "${COOKOPTS/!manz/}" != "$COOKOPTS" ] && return
    3.68 +	manpath="$install/usr/share/man" 
    3.69 +	[ -d "$manpath" ] || return
    3.70 +	size0=$(sizes man); [ -z "$size0" ] && return
    3.71 +
    3.72 +	action 'Compressing man pages...'
    3.73 +
    3.74 +	# We'll use only Gzip compression, so decompress other formats first
    3.75 +	find $manpath -type f -name '*.bz2' -exec bunzip2 \{\} \;
    3.76 +	find $manpath -type f -name '*.xz'  -exec unxz    \{\} \;
    3.77 +
    3.78 +	# Fast compress with gzip
    3.79 +	find $manpath -type f -name '*.[1-9]*' -exec gzip \{\} \;
    3.80 +
    3.81 +	# Fix symlinks
    3.82 +	for i in $(find $install/usr/share/man -type l); do
    3.83 +		dest=$(readlink $i | sed 's|\.[gbx]z2*$||')
    3.84 +		link=$(echo $i | sed 's|\.[gbx]z2*$||')
    3.85 +		rm $i; ln -s $dest.gz $link.gz
    3.86 +	done
    3.87 +
    3.88 +	# Recompress with advdef (it can't compress, only recompress)
    3.89 +	tazpkg -gi advancecomp --quiet
    3.90 +	for i in $(find $install/usr/share/man -type f); do
    3.91 +		advdef -z4q $i
    3.92 +	done
    3.93 +
    3.94 +	comp_summary "$time0" "$size0" "$(sizes man)"
    3.95 +}
    3.96 +
    3.97 +
    3.98 +# Function used after compile_rules() to compress all png images
    3.99 +# Compressing can be disabled with COOKOPTS="!pngz"
   3.100 +
   3.101 +compress_png() {
   3.102 +	time0=$(date +%s)
   3.103 +	[ "${COOKOPTS/!pngz/}" != "$COOKOPTS" ] && return
   3.104 +	size0=$(sizes png); [ -z "$size0" ] && return
   3.105 +
   3.106 +	action 'Compressing png images...'
   3.107 +
   3.108 +	use_pq=true
   3.109 +	use_op=true
   3.110 +	[ "${COOKOPTS/!pngquant/}" != "$COOKOPTS" ] && use_pq=false
   3.111 +	[ "${COOKOPTS/!optipng/}"  != "$COOKOPTS" ] && use_op=false
   3.112 +
   3.113 +	$use_pq && tazpkg -gi pngquant --quiet
   3.114 +	$use_op && tazpkg -gi optipng --quiet
   3.115 +
   3.116 +	oplevel=$(echo $COOKOPTS | grep 'op[0-8]' | sed 's|.*op\([0-8]\).*|\1|')
   3.117 +	[ -z "$oplevel" ]     && oplevel='2'
   3.118 +	[ "$oplevel" == '8' ] && oplevel='7 -zm1-9'
   3.119 +
   3.120 +	for i in $(find $install -type f -name '*.png'); do
   3.121 +		$use_pq && pngquant -f --skip-if-larger --ext .png --speed 1 "$i"
   3.122 +		$use_op && optipng -quiet -strip all -o$oplevel "$i"
   3.123 +	done
   3.124 +
   3.125 +	comp_summary "$time0" "$size0" "$(sizes png)"
   3.126 +}
   3.127 +
   3.128 +
   3.129 +# Function used after compile_rules() to compress all svg images
   3.130 +# Compressing can be disabled with COOKOPTS="!svgz"
   3.131 +
   3.132 +compress_svg() {
   3.133 +	time0=$(date +%s)
   3.134 +	[ "${COOKOPTS/!svgz/}" != "$COOKOPTS" ] && return
   3.135 +	size0=$(sizes svg); [ -z "$size0" ] && return
   3.136 +
   3.137 +	action 'Compressing svg images...'
   3.138 +
   3.139 +	tazpkg -gi svgcleaner --quiet
   3.140 +	cleaner_log="$(mktemp)"
   3.141 +	for i in $(find $install -type f -name '*.svg'); do
   3.142 +		echo -n "$i: " >> "$cleaner_log"
   3.143 +		svgcleaner "$i" "$i" --remove-unresolved-classes false --quiet true >> "$cleaner_log"
   3.144 +	done
   3.145 +
   3.146 +	comp_summary "$time0" "$size0" "$(sizes svg)"
   3.147 +
   3.148 +	sed -i '/: $/d' "$cleaner_log"
   3.149 +	if [ -s "$cleaner_log" ]; then
   3.150 +		_ 'Cleaner warnings and errors:'
   3.151 +		awk '{printf "  %s\n", $0;}' "$cleaner_log"
   3.152 +		echo
   3.153 +	fi
   3.154 +	rm "$cleaner_log"
   3.155 +}
   3.156 +
   3.157 +
   3.158 +# Function used after compile_rules() to shrink all *.ui and *.glade files:
   3.159 +# remove insignificant spaces and comments
   3.160 +# Compressing can be disabled with COOKOPTS="!uiz"
   3.161 +
   3.162 +compress_ui() {
   3.163 +	[ "${COOKOPTS/!uiz/}" != "$COOKOPTS" ] && return
   3.164 +	[ -z "$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) )" ] && return
   3.165 +
   3.166 +	action 'Compressing ui files...'
   3.167 +	size0=$(sizes xml)
   3.168 +	time0=$(date +%s)
   3.169 +	tazpkg -gi xmlstarlet --quiet
   3.170 +	temp_ui="$(mktemp)"
   3.171 +	for ui in $(find $install -type f \( -name '*.ui' -o -name '*.glade' \) ); do
   3.172 +		xmlstarlet c14n --without-comments "$ui" | xmlstarlet sel -B -t -c '*' > "$temp_ui"
   3.173 +		cat "$temp_ui" > "$ui"
   3.174 +	done
   3.175 +
   3.176 +	comp_summary "$time0" "$size0" "$(sizes xml)"
   3.177 +	rm "$temp_ui"
   3.178 +}
   3.179 +
   3.180 +
   3.181 +# Get list of supported locales...
   3.182 +
   3.183 +get_supported_locales() {
   3.184 +	lpc='/slitaz-i18n/stuff/locale-pack.conf'
   3.185 +	if [ -e "$WOK$lpc" ]; then
   3.186 +		# ... from package in the local wok
   3.187 +		. "$WOK$lpc"
   3.188 +	else
   3.189 +		# ... from Hg
   3.190 +		temp_conf=$(mktemp)
   3.191 +		wget -q -O $temp_conf -T 10 "http://hg.slitaz.org/wok/raw-file/tip$lpc"
   3.192 +		if [ -s $temp_conf ]; then
   3.193 +			. $temp_conf
   3.194 +		else
   3.195 +			# Give up and use hardcoded list
   3.196 +			LOCALE_PACK="ar ca cs da de el en es fi fr hr hu id is it ja nb nl nn pl pt \
   3.197 +			pt_BR ro ru sl sv tr uk zh_CN zh_TW"
   3.198 +		fi
   3.199 +		rm $temp_conf
   3.200 +	fi
   3.201 +	echo $LOCALE_PACK
   3.202 +}
   3.203 +
   3.204 +
   3.205 +# Fix common errors and warnings in the .desktop files
   3.206 +# Fixing can be disabled with COOKOPTS="!fixdesktops"
   3.207 +
   3.208 +fix_desktop_files() {
   3.209 +	[ "${COOKOPTS/!fixdesktops/}" != "$COOKOPTS" ] && return
   3.210 +	[ -z "$(find $install -type f -name '*.desktop')" ] && return
   3.211 +
   3.212 +	size0=$(sizes des)
   3.213 +	time0=$(date +%s)
   3.214 +
   3.215 +	if [ -n "$QA" -a -z "$(which desktop-file-validate)" ]; then
   3.216 +		tazpkg -gi desktop-file-utils-extra --quiet
   3.217 +	fi
   3.218 +
   3.219 +	# The variable $LOCALE is set in cook.conf and may be overridden in the receipt.
   3.220 +	# Default value is "" (empty). That means for us that we'll use the full
   3.221 +	# list of supported locales here.
   3.222 +	[ -z "$LOCALE" ] && LOCALE=$(get_supported_locales)
   3.223 +
   3.224 +	for desktop in $(find $install -type f -name '*.desktop'); do
   3.225 +		cp "$desktop" "$desktop.orig"
   3.226 +
   3.227 +		# Sort out .desktop file (is prerequisite to correct working of `fix-desktop-file`)
   3.228 +		sdft "$desktop" -i
   3.229 +
   3.230 +		# Fix common errors in .desktop file
   3.231 +		fix-desktop-file "$desktop"
   3.232 +
   3.233 +		# Strip unsupported locales from .desktop file
   3.234 +		[ "${COOKOPTS/!i18nz/}" == "$COOKOPTS" ] &&
   3.235 +			sdft "$desktop" -i -k "$LOCALE"
   3.236 +
   3.237 +		# Extra-strip
   3.238 +		[ "${COOKOPTS/!extradesktops/}" == "$COOKOPTS" ] &&
   3.239 +			sdft "$desktop" -i -g -x -tf -r 'Keywords*' -o
   3.240 +
   3.241 +		if [ -n "$QA" ]; then
   3.242 +			# Check the rest of errors, warnings and tips
   3.243 +			_ 'QA: Checking %s...' "$(basename $desktop)"
   3.244 +			diff "$desktop.orig" "$desktop"
   3.245 +			desktop-file-validate "$desktop" | busybox fold -s
   3.246 +			echo
   3.247 +		fi
   3.248 +
   3.249 +		rm "$desktop.orig"
   3.250 +	done
   3.251 +
   3.252 +	comp_summary "$time0" "$size0" "$(sizes des)"
   3.253 +}
   3.254 +
   3.255 +
   3.256 +# Normalize all *.mo files: unconditionally convert to UTF-8; remove strings that are not really added
   3.257 +# to the translation (msgid = msgstr)
   3.258 +# Normalization can be disabled with COOKOPTS="!monorm"
   3.259 +
   3.260 +normalize_mo() {
   3.261 +	[ "${COOKOPTS/!monorm/}" != "$COOKOPTS" ] && return
   3.262 +	[ -z "$(find $install -type f -name '*.mo')" ] && return
   3.263 +
   3.264 +	action 'Normalizing mo files...'
   3.265 +	size0=$(sizes mo1)
   3.266 +	time0=$(date +%s)
   3.267 +
   3.268 +	# Gettext functions: msgunfmt, msguniq, msgconv, msgfmt
   3.269 +	tazpkg -gi gettext      --quiet
   3.270 +	# Gconv modules (convert to UTF-8)
   3.271 +	tazpkg -gi glibc-locale --quiet
   3.272 +
   3.273 +	# Process all existing *.mo files
   3.274 +	for mo in $(find "$install" -type f -name '*.mo'); do
   3.275 +		tmpfile="$(mktemp)"
   3.276 +
   3.277 +		msgunfmt "$mo" | msguniq | msgconv -o "$tmpfile" -t 'UTF-8'
   3.278 +		# add newline
   3.279 +		echo >> "$tmpfile"
   3.280 +
   3.281 +		# get Plural-Forms
   3.282 +		awk '
   3.283 +		BEGIN { skip = ""; }
   3.284 +		{
   3.285 +			if (! skip) {
   3.286 +				s = $0;
   3.287 +				gsub(/^[^\"]*\"/, "", s);
   3.288 +				gsub(/\"$/, "", s);
   3.289 +				printf("%s", s);
   3.290 +			}
   3.291 +			if (! $0) skip = "yes";
   3.292 +		}
   3.293 +		' "$tmpfile" | sed 's|\\n|\n|g' | grep "^Plural-Forms:" > "$tmpfile.pf"
   3.294 +
   3.295 +		if ! grep -q 'msgid_plural' "$tmpfile"; then
   3.296 +			echo > "$tmpfile.pf"
   3.297 +		fi
   3.298 +
   3.299 +		# main
   3.300 +		awk -v pf="$(cat "$tmpfile.pf")" '
   3.301 +		function clean() {
   3.302 +			mode = msgctxt = msgid = msgid_plural = msgstr = msgstr0 = msgstr1 = msgstr2 = msgstr3 = msgstr4 = msgstr5 = "";
   3.303 +		}
   3.304 +
   3.305 +		function getstring() {
   3.306 +			# Skip unquoted words at the beginning (msgid, msgstr...) and get string from inside quotes
   3.307 +			s = $0;
   3.308 +			gsub(/^[^\"]*\"/, "", s);
   3.309 +			gsub(/\"$/, "", s);
   3.310 +			return s;
   3.311 +		}
   3.312 +
   3.313 +		BEGIN {
   3.314 +			printf("msgid \"\"\nmsgstr \"\"\n\"Content-Type: text/plain; charset=UTF-8\\n\"\n");
   3.315 +			if (pf)
   3.316 +				printf("\"%s\\n\"\n", pf);
   3.317 +			printf("\n");
   3.318 +			skip = 1;
   3.319 +			clean();
   3.320 +		}
   3.321 +
   3.322 +		{
   3.323 +			# Skip the entire header
   3.324 +			if (!skip) {
   3.325 +				if ($1 == "msgctxt" || $1 == "msgid" || $1 == "msgstr" || $1 == "msgid_plural")
   3.326 +					mode = $1;
   3.327 +				if ($1 == "msgstr[0]") mode = "msgstr0";
   3.328 +				if ($1 == "msgstr[1]") mode = "msgstr1";
   3.329 +				if ($1 == "msgstr[2]") mode = "msgstr2";
   3.330 +				if ($1 == "msgstr[3]") mode = "msgstr3";
   3.331 +				if ($1 == "msgstr[4]") mode = "msgstr4";
   3.332 +				if ($1 == "msgstr[5]") mode = "msgstr5";
   3.333 +
   3.334 +				if (mode == "msgctxt")      msgctxt      = msgctxt      getstring();
   3.335 +				if (mode == "msgid")        msgid        = msgid        getstring();
   3.336 +				if (mode == "msgstr")       msgstr       = msgstr       getstring();
   3.337 +				if (mode == "msgid_plural") msgid_plural = msgid_plural getstring();
   3.338 +				if (mode == "msgstr0")      msgstr0      = msgstr0      getstring();
   3.339 +				if (mode == "msgstr1")      msgstr1      = msgstr1      getstring();
   3.340 +				if (mode == "msgstr2")      msgstr2      = msgstr2      getstring();
   3.341 +				if (mode == "msgstr3")      msgstr3      = msgstr3      getstring();
   3.342 +				if (mode == "msgstr4")      msgstr4      = msgstr4      getstring();
   3.343 +				if (mode == "msgstr5")      msgstr5      = msgstr5      getstring();
   3.344 +
   3.345 +				if (! $0) {
   3.346 +					if (msgid != msgstr) {
   3.347 +						if (msgctxt)      printf("msgctxt \"%s\"\n",      msgctxt);
   3.348 +						                  printf("msgid \"%s\"\n",        msgid);
   3.349 +						if (msgid_plural) printf("msgid_plural \"%s\"\n", msgid_plural);
   3.350 +						if (msgstr)       printf("msgstr \"%s\"\n",       msgstr);
   3.351 +						if (msgstr0)      printf("msgstr[0] \"%s\"\n",    msgstr0);
   3.352 +						if (msgstr1)      printf("msgstr[1] \"%s\"\n",    msgstr1);
   3.353 +						if (msgstr2)      printf("msgstr[2] \"%s\"\n",    msgstr2);
   3.354 +						if (msgstr3)      printf("msgstr[3] \"%s\"\n",    msgstr3);
   3.355 +						if (msgstr4)      printf("msgstr[4] \"%s\"\n",    msgstr4);
   3.356 +						if (msgstr5)      printf("msgstr[5] \"%s\"\n",    msgstr5);
   3.357 +						                  printf("\n");
   3.358 +					}
   3.359 +					clean();
   3.360 +				}
   3.361 +			}
   3.362 +			if ($0 == "") skip = "";
   3.363 +		}
   3.364 +		' "$tmpfile" > "$tmpfile.awk"
   3.365 +
   3.366 +		msgfmt "$tmpfile.awk" -o "$tmpfile.mo"
   3.367 +
   3.368 +		if [ -s "$tmpfile.mo" ]; then
   3.369 +			rm "$mo"; mv "$tmpfile.mo" "$mo"
   3.370 +		else
   3.371 +			_ 'Error processing %s' "$mo"
   3.372 +			[ -e "$tmpfile.mo" ] && rm "$tmpfile.mo"
   3.373 +		fi
   3.374 +
   3.375 +		# Clean
   3.376 +		rm "$tmpfile" "$tmpfile.pf" "$tmpfile.awk"
   3.377 +	done
   3.378 +
   3.379 +	comp_summary "$time0" "$size0" "$(sizes mo1)"
   3.380 +}
   3.381 +
   3.382 +
   3.383 +# Strip locale definitions: normalize whitespace and remove comments
   3.384 +# Stripping can be disabled with COOKOPTS="!locdef"
   3.385 +
   3.386 +strip_locale_def() {
   3.387 +	[ "${COOKOPTS/!locdef/}" != "$COOKOPTS" ] && return
   3.388 +	[ ! -d "$install/usr/share/i18n/locales" ] && return
   3.389 +	[ -z "$(find $install/usr/share/i18n/locales -type f)" ] && return
   3.390 +
   3.391 +	action 'Stripping locale definitions...'
   3.392 +	size0=$(sizes loc)
   3.393 +	time0=$(date +%s)
   3.394 +
   3.395 +	for i in $(find $install/usr/share/i18n/locales -type f); do
   3.396 +		sed -i 's|	| |g; s|  *| |g; s|^ ||; /^%/d' $i
   3.397 +	done
   3.398 +
   3.399 +	comp_summary "$time0" "$size0" "$(sizes loc)"
   3.400 +}
   3.401 +
   3.402 +
   3.403 +# Find and strip: --strip-all (-s) or --strip-debug on static libs as well
   3.404 +# as removing unneeded files like in Python packages. Cross compiled binaries
   3.405 +# must be stripped with cross-tools aka $ARCH-slitaz-*-strip
   3.406 +# Stripping can be disabled with COOKOPTS="!strip"
   3.407 +
   3.408 +strip_package() {
   3.409 +	[ "${COOKOPTS/!strip/}" != "$COOKOPTS" ] && return
   3.410 +
   3.411 +	case "$ARCH" in
   3.412 +		arm*|x86_64) export STRIP="$HOST_SYSTEM-strip" ;;
   3.413 +		*)           export STRIP='strip' ;;
   3.414 +	esac
   3.415 +	action 'Executing strip on all files...'
   3.416 +	size0=0
   3.417 +	size1=0
   3.418 +	time0=$(date +%s)
   3.419 +
   3.420 +	# Strip executable files
   3.421 +	for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games; do
   3.422 +		if [ -d "$dir" ]; then
   3.423 +			oldsize=$(find $dir -type f -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
   3.424 +			find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
   3.425 +			newsize=$(find $dir -type f -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
   3.426 +			size0=$((size0 + oldsize)); size1=$((size1 + newsize))
   3.427 +		fi
   3.428 +	done
   3.429 +
   3.430 +	# Strip shared and static libraries
   3.431 +	# Remove Python *.pyc and *.pyo, Perl perllocal.pod and .packlist
   3.432 +	oldsize=$(find $fs -type f \( \
   3.433 +		-name '*.so*' -o -name '*.a' -o \
   3.434 +		-name '*.pyc' -o -name '*.pyo' -o \
   3.435 +		-name 'perllocal.pod' -o -name '.packlist' \) -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
   3.436 +
   3.437 +	find $fs -name '*.so*' -exec $STRIP -s '{}' 2>/dev/null \;
   3.438 +	find $fs -name '*.a' -exec $STRIP --strip-debug '{}' 2>/dev/null \;
   3.439 +	find $fs -type f \( -name '*.pyc' -o -name '*.pyo' \) -delete 2>/dev/null
   3.440 +	find $fs -type f \( -name 'perllocal.pod' -o -name '.packlist' \) -delete 2>/dev/null
   3.441 +
   3.442 +	newsize=$(find $fs -type f \( \
   3.443 +		-name '*.so*' -o -name '*.a' -o \) -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
   3.444 +
   3.445 +	comp_summary "$time0" "$((size0 + oldsize))" "$((size1 + newsize))"
   3.446 +}
   3.447 +
   3.448 +
   3.449 +# Strip unsupported locales (.mo files)
   3.450 +
   3.451 +strip_mo_i18n() {
   3.452 +	[ "${COOKOPTS/!i18nz/}" != "$COOKOPTS" ] && return
   3.453 +
   3.454 +	[ ! -d "$fs/usr/share/locale" ] && return
   3.455 +	[ -z "$(find $fs/usr/share/locale -type f -name '*.mo')" ] && return
   3.456 +
   3.457 +	action 'Thin out translation files...'
   3.458 +	size0=$(sizes mo2)
   3.459 +	time0=$(date +%s)
   3.460 +
   3.461 +	# The variable $LOCALE is set in cook.conf and may be overridden in the receipt.
   3.462 +	# Default value is "" (empty). That means for us that we'll use the full
   3.463 +	# list of supported locales here.
   3.464 +	[ -z "$LOCALE" ] && LOCALE=$(get_supported_locales)
   3.465 +
   3.466 +	# Existing locales
   3.467 +	elocales=" $(ls -1 "$fs/usr/share/locale" | tr '\n' ' ') "
   3.468 +
   3.469 +	# Thin out the list of existing locales. At the end there will be only locales that need
   3.470 +	# deleting (and the garbage like '_AU', _US', '_BR' leaving from 'en_AU', 'en_US', 'pt_BR'...)
   3.471 +	for keep_locale in $LOCALE; do
   3.472 +		elocales=${elocales//$keep_locale}
   3.473 +	done
   3.474 +
   3.475 +	# Remove the unsupported locales
   3.476 +	for rem_locale in $elocales; do
   3.477 +		[ -d  "$fs/usr/share/locale/$rem_locale" ] &&
   3.478 +		rm -r "$fs/usr/share/locale/$rem_locale"
   3.479 +	done
   3.480 +
   3.481 +	comp_summary "$time0" "$size0" "$(sizes mo2)"
   3.482 +}
   3.483 +
   3.484 +
   3.485 +
   3.486 +
   3.487 +case $1 in
   3.488 +	install)
   3.489 +		# Compressors working in the $install
   3.490 +		case "$ARCH" in
   3.491 +			arm*) ;;
   3.492 +			*)
   3.493 +				compress_manpages
   3.494 +				compress_png
   3.495 +				compress_svg
   3.496 +				compress_ui
   3.497 +				;;
   3.498 +		esac
   3.499 +
   3.500 +		fix_desktop_files
   3.501 +		normalize_mo
   3.502 +		strip_locale_def
   3.503 +		;;
   3.504 +	fs)
   3.505 +		# Compressors working in the $fs
   3.506 +		strip_package
   3.507 +		strip_mo_i18n
   3.508 +		;;
   3.509 +esac
     4.1 --- a/modules/pkgdb	Wed Jan 11 00:31:18 2017 +0200
     4.2 +++ b/modules/pkgdb	Wed Jan 11 11:53:04 2017 +0200
     4.3 @@ -6,13 +6,6 @@
     4.4  
     4.5  . /usr/lib/slitaz/libcook.sh
     4.6  
     4.7 -export output=raw
     4.8 -
     4.9 -
    4.10 -# Internationalization.
    4.11 -
    4.12 -export TEXTDOMAIN='cook'
    4.13 -
    4.14  
    4.15  #
    4.16  # Functions
     5.1 --- a/web/cooker.cgi	Wed Jan 11 00:31:18 2017 +0200
     5.2 +++ b/web/cooker.cgi	Wed Jan 11 11:53:04 2017 +0200
     5.3 @@ -16,7 +16,7 @@
     5.4  commits="$CACHE/commits"
     5.5  cooklist="$CACHE/cooklist"
     5.6  cookorder="$CACHE/cookorder"
     5.7 -command="$CACHE/command"
     5.8 +command="$CACHE/command"; touch $command
     5.9  blocked="$CACHE/blocked"
    5.10  broken="$CACHE/broken"
    5.11  cooknotes="$CACHE/cooknotes"
    5.12 @@ -315,7 +315,7 @@
    5.13  			bpkg=$pkg
    5.14  			. $wok/$pkg/receipt
    5.15  
    5.16 -			[ -n "$WANTED" ] && bpkg="$WANTED"
    5.17 +			[ -n "$WANTED" ] && bpkg="${WANTED%% *}" # see locale-* with multiple WANTED
    5.18  			[ -n "$WEB_SITE" ] && # busybox wget -s $WEB_SITE &&
    5.19  			echo "<a href='$WEB_SITE'>home</a>"
    5.20