cookutils view cook @ rev 838

cook: strip unsupported translations. Rewrite the doc in cookopts.txt.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu Nov 17 01:28:30 2016 +0200 (2016-11-17)
parents 275599c3423c
children bd3b572e2651
line source
1 #!/bin/sh
2 #
3 # Cook - A tool to cook and generate SliTaz packages. Read the README
4 # before adding or modifying any code in cook!
5 #
6 # Copyright (C) SliTaz GNU/Linux - GNU gpl v3
7 # Author: Christophe Lincoln <pankso@slitaz.org>
8 #
10 . /usr/lib/slitaz/libcook.sh
12 VERSION="3.2"
13 export output=raw
16 # Internationalization.
18 export TEXTDOMAIN='cook'
19 _() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; echo; }
20 _n() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; }
21 _p() {
22 local S="$1" P="$2" N="$3"; shift; shift; shift;
23 printf "$(ngettext "$S" "$P" "$N")" "$@"; }
26 #
27 # Functions
28 #
30 usage() {
31 cat <<EOT
33 $(boldify "$(_ 'Usage:')") $(_ 'cook [package|command] [list|--option]')
35 $(boldify "$(_ 'Commands:')")
36 usage|help $(_ 'Display this short usage.')
37 setup $(_ 'Setup your build environment.')
38 *-setup $(_ 'Setup a cross environment.')
39 * = {arm|armv6hf|armv7|x86_64}
40 test $(_ 'Test environment and cook a package.')
41 list-wok $(_ 'List packages in the wok.')
42 search $(_ 'Simple packages search function.')
43 new $(_ 'Create a new package with a receipt.')
44 list $(_ 'Cook a list of packages.')
45 clean-wok $(_ 'Clean-up all packages files.')
46 clean-src $(_ 'Clean-up all packages sources.')
47 uncook $(_ 'Check for uncooked packages')
48 pkgdb $(_ 'Create packages DB lists and flavors.')
50 $(boldify "$(_ 'Options:')")
51 cook <pkg>
52 --clean -c $(_ 'clean the package in the wok.')
53 --install -i $(_ 'cook and install the package.')
54 --getsrc -gs $(_ 'get the package source tarball.')
55 --block -b $(_ 'block a package so cook will skip it.')
56 --unblock -ub $(_ 'unblock a blocked package.')
57 --cdeps $(_ 'check dependencies of cooked package.')
58 --pack $(_ 'repack an already built package.')
59 --debug $(_ 'display debugging messages.')
60 --continue $(_ 'continue running compile_rules.')
61 cook new <pkg>
62 --interactive -x $(_ 'create a receipt interactively.')
63 cook setup
64 --wok $(_ 'clone the cooking wok from Hg repo.')
65 --stable $(_ 'clone the stable wok from Hg repo.')
66 --undigest $(_ 'clone the undigest wok from Hg repo.')
67 --tiny $(_ 'clone the tiny SliTaz wok from Hg repo.')
68 --forced $(_ 'force reinstall of chroot packages.')
69 cook pkgdb
70 --flavors $(_ 'create up-to-date flavors files.')
72 EOT
73 exit 0
74 }
77 # We don't want these escapes in web interface.
79 clean_log() {
80 sed -i -e s'|\[70G\[ \[1;32m| |' \
81 -e s'|\[0;39m \]||' $LOGS/$pkg.log
82 }
85 # Be sure package exists in wok.
87 check_pkg_in_wok() {
88 if [ ! -d "$WOK/$pkg" ]; then
89 newline; _ 'Unable to find package "%s" in the wok' "$pkg"; newline
90 exit 1
91 fi
92 }
95 if_empty_value() {
96 if [ -z "$value" ]; then
97 # L10n: QA is quality assurance
98 _ 'QA: empty variable: %s' "$var=\"\""; newline
99 exit 1
100 fi
101 }
104 # Initialize files used in $CACHE
106 init_db_files() {
107 _ 'Creating directories structure in "%s"' "$SLITAZ"
108 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
109 _ 'Creating DB files in "%s"' "$CACHE"
110 for f in $activity $command $broken $blocked; do
111 touch $f
112 done
113 }
116 # QA: check a receipt consistency before building.
118 receipt_quality() {
119 _ 'QA: checking package receipt...'
120 unset online
121 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
122 online='online'
123 fi
124 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE; do
125 unset value
126 value="$(. $receipt; eval echo \$$var)"
127 case "$var" in
128 PACKAGE|VERSION|SHORT_DESC)
129 if_empty_value ;;
130 CATEGORY)
131 value="${value:-empty}"
132 valid="$(echo $PKGS_CATEGORIES)" # avoid newlines
133 if ! echo " $valid " | grep -q " $value "; then
134 _ 'QA: unknown category "%s"' "$value"
135 longline "$(_ 'Please, use one of: %s' "$valid")"
136 newline
137 exit 1
138 fi ;;
139 WEB_SITE)
140 # We don't check WGET_URL since if dl is needed it will fail.
141 # Break also if we're not online. Here error is not fatal.
142 if_empty_value
143 [ -z "$online" ] && break
144 if ! busybox wget -T 12 -s $value 2>/dev/null; then
145 _ 'QA: unable to reach "%s"' "$value"
146 fi ;;
147 esac
148 done
149 }
152 # Paths used in receipt and by cook itself.
154 set_paths() {
155 pkgdir="$WOK/$PACKAGE"
156 basesrc="$pkgdir/source"
157 tmpsrc="$basesrc/tmp"
158 src="$basesrc/$PACKAGE-$VERSION"
159 taz="$pkgdir/taz"
160 pack="$taz/$PACKAGE-$VERSION$EXTRAVERSION"
161 fs="$pack/fs"
162 stuff="$pkgdir/stuff"
163 install="$pkgdir/install"
164 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
165 lzma_tarball="$pkgsrc.tar.lzma"
166 if [ -n "$PATCH" ]; then
167 [ -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
168 fi
169 if [ -n "$WANTED" ]; then
170 basesrc="$WOK/$WANTED/source"
171 src="$basesrc/$WANTED-$VERSION"
172 install="$WOK/$WANTED/install"
173 wanted_stuff="$WOK/$WANTED/stuff"
174 fi
175 if [ -n "$SOURCE" ]; then
176 source_stuff="$WOK/$SOURCE/stuff"
177 fi
178 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
179 if [ -f "$WOK/linux/receipt" ]; then
180 kvers=$(grep ^VERSION= $WOK/linux/receipt | cut -d\" -f2)
181 kbasevers=${kvers:0:3}
182 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
183 kvers=$(grep ^VERSION= $INSTALLED/linux-api-headers/receipt | cut -d\" -f2)
184 kbasevers=${kvers:0:3}
185 fi
186 # Python version
187 if [ -f "$WOK/python/receipt" ]; then
188 pyvers=$(grep ^VERSION= $WOK/python/receipt | cut -d\" -f2)
189 fi
190 # Perl version for some packages needed it
191 if [ -f "$WOK/perl/receipt" ]; then
192 perlvers=$(grep ^VERSION= $WOK/perl/receipt | cut -d\" -f2)
193 fi
194 # Old way compatibility.
195 _pkg="$install"
196 }
199 # Create source tarball when URL is a SCM.
201 create_tarball() {
202 local tarball
203 tarball="$pkgsrc.tar.bz2"
204 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
205 _ 'Creating tarball "%s"' "$tarball"
206 if [ -n "$LZMA_SRC" ]; then
207 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
208 LZMA_SRC=''
209 else
210 tar -cjf $tarball $pkgsrc || exit 1
211 mv $tarball $SRC; rm -rf $pkgsrc
212 fi
213 TARBALL="$tarball"
214 }
217 # Get package source. For SCM we are in cache so clone here and create a
218 # tarball here.
220 get_source() {
221 local url
222 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
223 set_paths
224 pwd=$(pwd)
225 case "$WGET_URL" in
226 http://*|ftp://*)
227 # Busybox Wget is better!
228 busybox wget -T 60 -c -O $SRC/$TARBALL $WGET_URL || \
229 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
230 (_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
232 https://*)
233 wget -c --no-check-certificate -O $SRC/$TARBALL $WGET_URL || \
234 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
235 (_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
237 hg*|mercurial*)
238 if $(echo "$WGET_URL" | fgrep -q 'hg|'); then
239 url=${WGET_URL#hg|}
240 else
241 url=${WGET_URL#mercurial|}
242 fi
243 _ 'Getting source from %s...' 'Hg'
244 _ 'URL: %s' "$url"
245 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
246 if [ -n "$BRANCH" ]; then
247 _ 'Hg branch: %s' "$BRANCH"
248 hg clone $url --rev $BRANCH $pkgsrc || \
249 (_ 'ERROR: %s' "hg clone $url --rev $BRANCH" && exit 1)
250 else
251 hg clone $url $pkgsrc || (_ 'ERROR: %s' "hg clone $url" && exit 1)
252 fi
253 rm -rf $pkgsrc/.hg
254 create_tarball ;;
256 git*)
257 url=${WGET_URL#git|}
258 _ 'Getting source from %s...' 'Git'
259 _ 'URL: %s' "$url"
260 cd $SRC
261 git clone $url $pkgsrc || (_ 'ERROR: %s' "git clone $url" && exit 1)
262 if [ -n "$BRANCH" ]; then
263 _ 'Git branch: %s' "$BRANCH"
264 cd $pkgsrc; git checkout $BRANCH; cd ..
265 fi
266 cd $SRC
267 create_tarball ;;
269 cvs*)
270 url=${WGET_URL#cvs|}
271 mod=$PACKAGE
272 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
273 _ 'Getting source from %s...' 'CVS'
274 _ 'URL: %s' "$url"
275 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
276 _ 'Cloning to "%s"' "$pwd/$mod"
277 cvs -d:$url co $mod && mv $mod $pkgsrc
278 create_tarball ;;
280 svn*|subversion*)
281 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
282 url=${WGET_URL#svn|}
283 else
284 url=${WGET_URL#subversion|}
285 fi
286 _ 'Getting source from %s...' 'SVN'
287 _ 'URL: %s' "$url"
288 if [ -n "$BRANCH" ]; then
289 echo t | svn co $url -r $BRANCH $pkgsrc
290 else
291 echo t | svn co $url $pkgsrc
292 fi
293 create_tarball ;;
295 bzr*)
296 url=${WGET_URL#bzr|}
297 _ 'Getting source from %s...' 'bazaar'
298 cd $SRC
299 pkgsrc=${url#*:}
300 if [ -n "$BRANCH" ]; then
301 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
302 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
303 else
304 echo "bzr -Ossl.cert_reqs=none branch $url"
305 bzr -Ossl.cert_reqs=none branch $url
306 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
307 _ "Don't forget to add to receipt:"
308 echo -e "BRANCH=\"$BRANCH\"\n"
309 fi
310 mv $pkgsrc $pkgsrc-$BRANCH
311 pkgsrc="$pkgsrc-$BRANCH"
312 create_tarball ;;
314 *)
315 (newline; _ 'ERROR: Unable to handle "%s"' "$WGET_URL"; newline) | \
316 tee -a $LOGS/$PACKAGE.log
317 exit 1 ;;
318 esac
319 }
322 # Extract source package.
324 extract_source() {
325 if [ ! -s "$SRC/$TARBALL" ]; then
326 local url
327 url="$MIRROR_URL/sources/packages"
328 url="$url/${TARBALL:0:1}/$TARBALL"
329 _ 'Getting source from %s...' 'mirror'
330 _ 'URL: %s' "$url"
331 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
332 fi
333 _ 'Extracting source archive "%s"' "$TARBALL"
334 case "$TARBALL" in
335 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
336 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
337 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
338 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
339 *.tar) tar -xf $SRC/$TARBALL ;;
340 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
341 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
342 tar -xf $SRC/$TARBALL 2>/dev/null;;
343 *.7z) 7zr x $SRC/$TARBALL 2>/dev/null >&2 ;;
344 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
345 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
346 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
347 *) cp $SRC/$TARBALL $(pwd) ;;
348 esac
349 }
352 # Display time.
354 disp_time() {
355 local sec div min
356 sec="$1"
357 div=$(( ($1 + 30) / 60))
358 case $div in
359 0) min='';;
360 # L10n: 'm' is for minutes (approximate cooking time)
361 *) min=$(_n ' ~ %dm' "$div");;
362 esac
364 # L10n: 's' is for seconds (cooking time)
365 _ '%ds%s' "$sec" "$min"
366 }
369 # Display cooked package summary.
371 summary() {
372 cd $WOK/$pkg
373 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
374 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
375 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
376 size=$(ls -lh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $5}')
377 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
378 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
380 _ 'Summary for: %s' "$PACKAGE $VERSION"
381 separator
383 # L10n: keep the same width of translations to get a consistent view
384 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
385 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
386 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
387 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
388 _ 'Packed : %s' "$fs"
389 _ 'Compressed : %s' "$size"
390 _ 'Files : %s' "$files"
391 _ 'Cook time : %s' "$(disp_time "$time")"
392 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
393 _ 'Host arch : %s' "$ARCH"
394 separator
395 }
398 # Display debugging error info.
400 debug_info() {
401 title 'Debug information'
402 # L10n: specify your format of date and time (to help: man date)
403 # L10n: not bad one is '+%x %R'
404 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
405 [ "$time" ] && _ 'Cook time: %ds' "$(($(date +%s) - $time))"
406 # L10n: Please, translate all messages beginning with ERROR in a same way
407 lerror=$(_n 'ERROR')
408 for error in \
409 ERROR $lerror 'No package' "cp: can't" "can't open" "can't cd" \
410 'error:' 'fatal error:' 'undefined reference to' \
411 'Unable to connect to' 'link: cannot find the library' \
412 'CMake Error' ': No such file or directory' \
413 'Could not read symbols: File in wrong format'
414 do
415 fgrep "$error" $LOGS/$pkg.log
416 done > $LOGS/$pkg.log.debug_info 2>&1
417 cat $LOGS/$pkg.log.debug_info
418 rm -f $LOGS/$pkg.log.debug_info
419 footer
420 }
423 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
424 # so some packages need to copy these files with the receipt and genpkg_rules.
426 copy_generic_files() {
427 # $LOCALE is set in cook.conf
428 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
429 if [ -d "$install/usr/share/locale" ]; then
430 mkdir -p $fs/usr/share/locale
431 for i in $LOCALE; do
432 if [ -d "$install/usr/share/locale/$i" ]; then
433 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
434 fi
435 done
436 fi
437 fi
439 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
440 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
441 if [ -d "$install/usr/share/pixmaps" ]; then
442 mkdir -p $fs/usr/share/pixmaps
443 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
444 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
445 $fs/usr/share/pixmaps
446 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
447 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
448 $fs/usr/share/pixmaps
449 fi
450 fi
452 # Custom or homemade PNG pixmap can be in stuff.
453 if [ -f "$stuff/$PACKAGE.png" ]; then
454 mkdir -p $fs/usr/share/pixmaps
455 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
456 fi
457 fi
459 # Desktop entry (.desktop).
460 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
461 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
462 if [ -d "$install/usr/share/applications" ] && [ -z "$WANTED" ]; then
463 mkdir -p $fs/usr/share
464 cp -a $install/usr/share/applications $fs/usr/share
465 fi
466 fi
468 # Homemade desktop file(s) can be in stuff.
469 if [ -d "$stuff/applications" ]; then
470 mkdir -p $fs/usr/share
471 cp -a $stuff/applications $fs/usr/share
472 fi
473 if [ -f "$stuff/$PACKAGE.desktop" ]; then
474 mkdir -p $fs/usr/share/applications
475 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
476 fi
478 # Add custom licenses
479 if [ -d "$stuff/licenses" ]; then
480 mkdir -p $fs/usr/share/licenses
481 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
482 fi
483 }
486 # Get list of supported locales...
488 get_supported_locales() {
489 local lpc='/slitaz-i18n/stuff/locale-pack.conf' LOCALE_PACK
490 if [ -e "$WOK$lpc" ]; then
491 # ... from package in the local wok
492 . "$WOK$lpc"
493 else
494 # ... from Hg
495 temp_conf=$(mktemp)
496 wget -q -O $temp_conf -T 10 "http://hg.slitaz.org/wok/raw-file/tip$lpc"
497 if [ -s $temp_conf ]; then
498 . $temp_conf
499 else
500 # Give up and use hardcoded list
501 LOCALE_PACK="ar ca cs da de el en es fi fr hr hu id is it ja nb nl nn pl pt \
502 pt_BR ro ru sl sv tr uk zh_CN zh_TW"
503 fi
504 rm $temp_conf
505 fi
506 echo $LOCALE_PACK
507 }
510 # Fix common errors and warnings in the .desktop files
511 # Fixing can be disabled with COOKOPTS="!fixdesktops"
513 fix_desktop_files() {
514 [ "${COOKOPTS/!fixdesktops/}" != "$COOKOPTS" ] && return
515 [ -z "$(find $install -type f -name '*.desktop')" ] && return
517 local size0=$(find $install -type f -name '*.desktop' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
518 local time0=$(date +%s)
520 if [ -n "$QA" -a -z "$(which desktop-file-validate)" ]; then
521 tazpkg -gi desktop-file-utils-extra --quiet
522 fi
524 # The variable $LOCALE is set in cook.conf and may be overridden in the receipt.
525 # Default value is "" (empty). That means for us that we'll use the full
526 # list of supported locales here.
527 [ -z "$LOCALE" ] && LOCALE=$(get_supported_locales)
529 for desktop in $(find $install -type f -name '*.desktop'); do
530 cp "$desktop" "$desktop.orig"
532 # Sort out .desktop file (is prerequisite to correct working of `fix-desktop-file`)
533 sdft "$desktop" -i
535 # Fix common errors in .desktop file
536 fix-desktop-file "$desktop"
538 # Strip unsupported locales from .desktop file
539 [ "${COOKOPTS/!i18nz/}" == "$COOKOPTS" ] &&
540 sdft "$desktop" -i -k "$LOCALE"
542 # Extra-strip
543 [ "${COOKOPTS/!extradesktops/}" == "$COOKOPTS" ] &&
544 sdft "$desktop" -i -g -x -tf -r 'Keywords*' -o
546 if [ -n "$QA" ]; then
547 # Check the rest of errors, warnings and tips
548 _ 'QA: Checking %s...' "$(basename $desktop)"
549 diff "$desktop.orig" "$desktop"
550 desktop-file-validate "$desktop" | busybox fold -s
551 echo
552 fi
554 rm "$desktop.orig"
555 done
557 local size1=$(find $install -type f -name '*.desktop' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
558 local time1=$(date +%s)
559 comp_summary "$time0" "$time1" "$size0" "$size1"
560 }
563 # Compressor mini summary
565 comp_summary() {
566 [ "$3" -eq 0 ] && return
567 local time=$(($2 - $1))
568 local saving=$(( ($3 - $4) / 1024 ))
569 _ ' Time: %s. Size: %s B -> %s B. Save: %s KB' "$(disp_time $time)" "$3" "$4" "$saving"
570 }
573 # Find and strip: --strip-all (-s) or --strip-debug on static libs as well
574 # as removing unneeded files like in Python packages. Cross compiled binaries
575 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
576 # Stripping can be disabled with COOKOPTS="!strip"
578 strip_package() {
579 [ "${COOKOPTS/!strip/}" != "$COOKOPTS" ] && return
581 case "$ARCH" in
582 arm*|x86_64) export STRIP="$HOST_SYSTEM-strip" ;;
583 *) export STRIP='strip' ;;
584 esac
585 action 'Executing strip on all files...'
586 local size0=0 size1=0 oldsize newsize
587 local time0=$(date +%s)
589 # Strip executable files
590 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games; do
591 if [ -d "$dir" ]; then
592 oldsize=$(find $dir -type f -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
593 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
594 newsize=$(find $dir -type f -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
595 size0=$((size0 + oldsize)); size1=$((size1 + newsize))
596 fi
597 done
599 # Strip shared and static libraries
600 # Remove Python *.pyc and *.pyo, Perl perllocal.pod and .packlist
601 oldsize=$(find $fs -type f \( \
602 -name '*.so*' -o -name '*.a' -o \
603 -name '*.pyc' -o -name '*.pyo' -o \
604 -name 'perllocal.pod' -o -name '.packlist' \) -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
606 find $fs -name '*.so*' -exec $STRIP -s '{}' 2>/dev/null \;
607 find $fs -name '*.a' -exec $STRIP --strip-debug '{}' 2>/dev/null \;
608 find $fs -type f \( -name '*.pyc' -o -name '*.pyo' \) -delete 2>/dev/null
609 find $fs -type f \( -name 'perllocal.pod' -o -name '.packlist' \) -delete 2>/dev/null
611 newsize=$(find $fs -type f \( \
612 -name '*.so*' -o -name '*.a' -o \) -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
614 size0=$((size0 + oldsize)); size1=$((size1 + newsize))
616 local time1=$(date +%s)
617 status
618 comp_summary "$time0" "$time1" "$size0" "$size1"
619 }
622 # Strip unsupported locales (.mo files)
624 strip_mo_i18n() {
625 [ "${COOKOPTS/!i18nz/}" != "$COOKOPTS" ] && return
627 [ -z "$(find $fs -type f -name '*.mo')" ] && return
629 action 'Stripping translations files...'
630 local size0=$(find $fs -type f -name '*.mo' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
631 local time0=$(date +%s)
633 # The variable $LOCALE is set in cook.conf and may be overridden in the receipt.
634 # Default value is "" (empty). That means for us that we'll use the full
635 # list of supported locales here.
636 [ -z "$LOCALE" ] && LOCALE=$(get_supported_locales)
638 # Existing locales
639 elocales=" $(ls -1 "$fs/usr/share/locale" | tr '\n' ' ') "
641 # Thin out the list of existing locales. At the end there will be only locales that need
642 # to delete (and the garbage like '_AU', _US', '_BR' leaving from 'en_AU', 'en_US', 'pt_BR'...)
643 for keep_locale in $LOCALE; do
644 elocales=${elocales//$keep_locale}
645 done
647 # Remove the unsupported locales
648 for rem_locale in $elocales; do
649 [ -d "$fs/usr/share/locale/$rem_locale" ] &&
650 rm -r "$fs/usr/share/locale/$rem_locale"
651 done
653 local size1=$(find $fs -type f -name '*.mo' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
654 local time1=$(date +%s)
655 status
656 comp_summary "$time0" "$time1" "$size0" "$size1"
657 }
660 # Update installed.cook.diff
662 update_installed_cook_diff() {
663 # If a cook failed deps are removed.
664 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
665 cd $CACHE
666 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
667 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
668 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
669 }
672 # Remove installed deps.
674 remove_deps() {
675 # Now remove installed build deps.
676 diff='/tmp/installed.cook.diff'
677 if [ -s $diff ]; then
678 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
679 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
680 _n 'Build dependencies to remove:'; echo " $nb"
681 [ -n "$root" ] && echo "root=\"$root\""
682 _n 'Removing:'
683 for dep in $deps; do
684 echo -n " $dep"
685 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
686 done
687 newline; newline
688 # Keep the last diff for debug and info.
689 mv -f $diff $CACHE/installed.diff
690 fi
691 }
694 # Function to compress all man pages
695 # Compressing can be disabled with COOKOPTS="!manz"
697 compress_manpages() {
698 [ "${COOKOPTS/!manz/}" != "$COOKOPTS" ] && return
700 case "$ARCH" in
701 arm*) return;; # While SliTaz-arm miss `advancecomp`
702 esac
703 local manpath="$install/usr/share/man" dest link
704 [ -d "$manpath" ] || return
706 action 'Compressing man pages...'
708 local size0=$(find $install/usr/share/man -type f -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
709 local time0=$(date +%s)
710 # We'll use only Gzip compression, so decompress other formats first
711 find $manpath -type f -name '*.bz2' -exec bunzip2 \{\} \;
712 find $manpath -type f -name '*.xz' -exec unxz \{\} \;
714 # Fast compress with gzip
715 find $manpath -type f -name '*.[1-9]' -exec gzip \{\} \;
717 # Fix symlinks
718 for i in $(find $install/usr/share/man -type l); do
719 dest=$(readlink $i | sed 's|\.[gbx]z2*$||')
720 link=$(echo $i | sed 's|\.[gbx]z2*$||')
721 rm $i; ln -s $dest.gz $link.gz
722 done
724 # Recompress with advdef (it can't compress, only recompress)
725 tazpkg -gi advancecomp --quiet
726 for i in $(find $install/usr/share/man -type f); do
727 advdef -z4q $i
728 done
730 local size1=$(find $install/usr/share/man -type f -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
731 local time1=$(date +%s)
732 status
733 comp_summary "$time0" "$time1" "$size0" "$size1"
734 }
737 # Function used after compile_rules() to compress all png images
738 # Compressing can be disabled with COOKOPTS="!pngz"
740 cook_compress_png() {
741 [ "${COOKOPTS/!pngz/}" != "$COOKOPTS" ] && return
742 case "$ARCH" in
743 arm*) return;; # While SliTaz-arm miss `pngquant` and `optipng`
744 esac
745 [ -z "$(find $install -type f -name '*.png')" ] && return
747 action 'Compressing png images...'
748 local size0=$(find $install -type f -name '*.png' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
749 local time0=$(date +%s)
751 local use_pq=true use_op=true
752 [ "${COOKOPTS/!pngquant/}" != "$COOKOPTS" ] && use_pq=false
753 [ "${COOKOPTS/!optipng/}" != "$COOKOPTS" ] && use_op=false
755 $use_pq && tazpkg -gi pngquant --quiet
756 $use_op && tazpkg -gi optipng --quiet
758 local oplevel=$(echo $COOKOPTS | grep 'op[0-8]' | sed 's|.*op\([0-8]\).*|\1|')
759 [ -z "$oplevel" ] && oplevel='2'
760 [ "$oplevel" == '8' ] && oplevel='7 -zm1-9'
762 for i in $(find $install -type f -name '*.png'); do
763 $use_pq && pngquant -f --skip-if-larger --ext .png --speed 1 "$i"
764 $use_op && optipng -quiet -strip all -o$oplevel "$i"
765 done
767 local size1=$(find $install -type f -name '*.png' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
768 local time1=$(date +%s)
769 status
770 comp_summary "$time0" "$time1" "$size0" "$size1"
771 }
774 # Function used after compile_rules() to compress all svg images
775 # Compressing can be disabled with COOKOPTS="!svgz"
777 cook_compress_svg() {
778 [ "${COOKOPTS/!svgz/}" != "$COOKOPTS" ] && return
779 case "$ARCH" in
780 arm*) return;; # While SliTaz-arm miss `svgcleaner`
781 esac
782 [ -z "$(find $install -type f -name '*.svg')" ] && return
784 action 'Compressing svg images...'
785 local size0=$(find $install -type f -name '*.svg' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
786 local time0=$(date +%s)
787 tazpkg -gi svgcleaner --quiet
788 cleaner_log="$(mktemp)"
789 for i in $(find $install -type f -name '*.svg'); do
790 echo -n "$i: " >> "$cleaner_log"
791 svgcleaner "$i" "$i" --remove-unresolved-classes false --quiet true >> "$cleaner_log"
792 done
793 local size1=$(find $install -type f -name '*.svg' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
794 local time1=$(date +%s)
795 status
796 comp_summary "$time0" "$time1" "$size0" "$size1"
797 sed -i '/: $/d' "$cleaner_log"
798 if [ -s "$cleaner_log" ]; then
799 echo 'Cleaner warnings and errors:'
800 awk '{printf " %s\n", $0;}' "$cleaner_log"
801 echo
802 fi
803 rm "$cleaner_log"
804 }
807 # Function used after compile_rules() to shrink all *.ui and *.glade files:
808 # remove insignificant spaces and comments
809 # Compressing can be disabled with COOKOPTS="!uiz"
811 compress_ui() {
812 [ "${COOKOPTS/!uiz/}" != "$COOKOPTS" ] && return
813 case "$ARCH" in
814 arm*) return;; # While SliTaz-arm miss `xmlstarlet`
815 esac
816 [ -z "$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) )" ] && return
818 action 'Compressing ui files...'
819 local size0=$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
820 local time0=$(date +%s)
821 tazpkg -gi xmlstarlet --quiet
822 temp_ui="$(mktemp)"
823 for ui in $(find $install -type f \( -name '*.ui' -o -name '*.glade' \) ); do
824 xmlstarlet c14n --without-comments "$ui" | xmlstarlet sel -B -t -c '*' > "$temp_ui"
825 cat "$temp_ui" > "$ui"
826 done
827 local size1=$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
828 local time1=$(date +%s)
829 status
830 comp_summary "$time0" "$time1" "$size0" "$size1"
831 rm "$temp_ui"
832 }
835 # The main cook function.
837 cookit() {
838 title 'Cook: %s' "$PACKAGE $VERSION"
839 set_paths
841 # Handle cross-tools.
842 case "$ARCH" in
843 arm*|x86_64)
844 # CROSS_COMPILE is used by at least Busybox and the kernel to set
845 # the cross-tools prefix. Sysroot is the root of our target arch
846 sysroot="$CROSS_TREE/sysroot"
847 tools="$CROSS_TREE/tools"
848 # Set root path when cross compiling. ARM tested but not x86_64
849 # When cross compiling we must install build deps in $sysroot.
850 arch="-$ARCH"
851 root="$sysroot"
852 _ '%s sysroot: %s' "$ARCH" "$sysroot"
853 _ 'Adding "%s" to PATH' "$tools/bin"
854 export PATH="$PATH:$tools/bin"
855 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
856 export CROSS_COMPILE="$HOST_SYSTEM-"
857 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
858 if [ "$ARCH" == 'x86_64' ]; then
859 export CC="$HOST_SYSTEM-gcc -m64"
860 export CXX="$HOST_SYSTEM-g++ -m64"
861 else
862 export CC="$HOST_SYSTEM-gcc"
863 export CXX="$HOST_SYSTEM-g++"
864 fi
865 export AR="$HOST_SYSTEM-ar"
866 export AS="$HOST_SYSTEM-as"
867 export RANLIB="$HOST_SYSTEM-ranlib"
868 export LD="$HOST_SYSTEM-ld"
869 export STRIP="$HOST_SYSTEM-strip"
870 export LIBTOOL="$HOST_SYSTEM-libtool" ;;
871 esac
873 [ -n "$QA" ] && receipt_quality
874 cd $pkgdir
875 [ -z "$continue" ] && rm -rf source 2>/dev/null
876 rm -rf install taz 2>/dev/null
878 # Disable -pipe if less than 512Mb free RAM.
879 free=$(free | awk '/buffers:/{print $4}')
880 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
881 _ 'Disabling -pipe compile flag: %d RAM free' "$free"
882 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
883 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
884 fi
885 unset free
887 # Export flags and path to be used by make and receipt.
888 DESTDIR="$pkgdir/install"
889 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
890 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
891 #LDFLAGS
893 # Check for build deps and handle implicit depends of *-dev packages
894 # (ex: libusb-dev :: libusb).
895 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
896 touch $CACHE/installed.local $CACHE/installed.web
897 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
898 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
899 for dep in $BUILD_DEPENDS; do
900 implicit="${dep%-dev}"
901 # Don't add implicit dependency if it defined in DEPENDS
902 # echo '' $DEPENDS '' | fgrep -q " $implicit " && implicit=''
903 for i in $dep $implicit; do
904 if [ ! -f "$root$INSTALLED/$i/receipt" ]; then
905 # Try local package first. In some cases implicit doesn't exist, ex:
906 # libboost-dev exists but not libboost, so check if we got vers.
907 unset vers
908 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
909 # We may have a local package.
910 if [ -z "$vers" ]; then
911 vers=$(awk -F$'\t' -vp="$i" '$1==p{print $2; quit}' $PKGS/packages.info 2> /dev/null)
912 fi
913 debug "bdep: $i version: $vers"
914 if [ -f "$PKGS/$i-$vers$arch.tazpkg" ]; then
915 echo $i-$vers$arch.tazpkg >> $CACHE/installed.local
916 else
917 # Priority to package version in wok (maybe more up-to-date)
918 # than the mirrored one.
919 if [ -n "$vers" ]; then
920 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
921 echo $i >> $CACHE/installed.web
922 else
923 # So package exists in wok but not available.
924 _ 'Missing dep (wok/pkg): %s' "$i $vers"
925 echo $i >> $CACHE/missing.dep
926 fi
927 else
928 # Package is not in wok but may be in online repo.
929 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
930 echo $i >> $CACHE/installed.web
931 else
932 _ 'ERROR: unknown dep "%s"' "$i"
933 exit 1
934 fi
935 fi
936 fi
937 fi
938 done
939 done
941 # Get the list of installed packages
942 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
944 # Have we a missing build dep to cook?
945 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
946 _ 'Auto cook config is set: %s' "$AUTO_COOK"
947 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
948 for i in $(uniq $CACHE/missing.dep); do
949 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
950 tee -a $LOGS/$PACKAGE.log.$$
951 # programmers: next two messages are exact copy from remove_deps()
952 togrep1=$(_n 'Build dependencies to remove:')
953 togrep2=$(_n 'Removing:')
954 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
955 fgrep $togrep1 $LOGS/$i.log && \
956 fgrep $togrep2 $LOGS/$i.log && newline) | \
957 tee -a $LOGS/$PACKAGE.log.$$ && break
958 done
959 rm -f $CACHE/missing.dep
960 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
961 fi
963 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
964 # is enabled and cook fails we have ERROR in log, if no auto cook we have
965 # missing dep in cached file.
966 lerror=$(_n 'ERROR')
967 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
968 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
969 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
970 exit 1
971 fi
973 # Install local packages: package-version$arch
974 cd $PKGS
975 for i in $(uniq $CACHE/installed.local); do
976 _ 'Installing dep (pkg/local): %s' "$i"
977 tazpkg install $i --root=$root --local --quiet
978 done
980 # Install web or cached packages (if mirror is set to $PKGS we only
981 # use local packages).
982 for i in $(uniq $CACHE/installed.web); do
983 _ 'Installing dep (web/cache): %s' "$i"
984 tazpkg get-install $i --root=$root --quiet
985 done
987 update_installed_cook_diff
989 # Get source tarball and make sure we have source dir named:
990 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
991 # tarball if it exists.
992 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
993 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
994 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
995 LZMA_SRC=''
996 else
997 get_source || exit 1
998 fi
999 fi
1000 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
1001 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
1002 if ! extract_source ; then
1003 get_source
1004 extract_source || exit 1
1005 fi
1006 if [ -n "$LZMA_SRC" ]; then
1007 cd $pkgdir/source
1008 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
1009 mv tmp tmp-1; mkdir tmp
1010 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
1011 fi
1012 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
1013 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
1014 fi
1015 fi
1016 cd $pkgdir/source/tmp
1017 # Some archives are not well done and don't extract to one dir (ex lzma).
1018 files=$(ls | wc -l)
1019 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
1020 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
1021 mv * ../$PACKAGE-$VERSION/$TARBALL
1022 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
1023 mv * ../$PACKAGE-$VERSION
1024 cd ..; rm -rf tmp
1025 fi
1027 # Libtool shared libs path hack.
1028 case "$ARCH" in
1029 arm*) cross libhack ;;
1030 esac
1032 # Execute receipt rules.
1033 if grep -q ^compile_rules $receipt; then
1034 _ 'Executing: %s' 'compile_rules'
1035 echo "CFLAGS : $CFLAGS"
1036 #echo "LDFLAGS : $LDFLAGS"
1037 [ -d "$src" ] && cd $src
1038 compile_rules $@ || exit 1
1039 # Stay compatible with _pkg
1040 [ -d "$src/_pkg" ] && mv $src/_pkg $install
1041 # QA: compile_rules success so valid.
1042 mkdir -p $install
1043 else
1044 # QA: no compile_rules so no error, valid.
1045 mkdir -p $install
1046 fi
1048 # Actions to do after compiling the package
1049 # Skip all for splitted packages (already done in main package)
1050 if [ -z "$WANTED" ]; then
1051 footer
1052 compress_manpages
1053 cook_compress_png
1054 cook_compress_svg
1055 compress_ui
1056 fix_desktop_files
1057 fi
1058 footer
1060 # Execute testsuite.
1061 if grep -q ^testsuite $receipt; then
1062 title 'Running testsuite'
1063 testsuite $@ || exit 1
1064 footer
1065 fi
1067 update_installed_cook_diff force
1071 # Cook quality assurance.
1073 cookit_quality() {
1074 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
1075 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
1076 fi
1077 # ERROR can be echoed any time in cookit()
1078 lerror=$(_n 'ERROR')
1079 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
1080 grep -Eq "(^$lerror|undefined reference to)" ; then
1081 debug_info | tee -a $LOGS/$pkg.log
1082 rm -f $command
1083 exit 1
1084 fi
1088 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
1089 # but it doesn't handle EXTRAVERSION.
1091 packit() {
1092 set_paths
1094 # Handle cross compilation
1095 case "$ARCH" in
1096 arm*|x86_64) arch="-$ARCH" ;;
1097 esac
1099 title 'Pack: %s' "$PACKAGE $VERSION$arch"
1101 if grep -q ^genpkg_rules $receipt; then
1102 _ 'Executing: %s' 'genpkg_rules'
1103 set -e; cd $pkgdir; mkdir -p $fs
1104 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
1105 $LOGS/$pkg.log
1106 else
1107 _ 'No packages rules: meta package'
1108 mkdir -p $fs
1109 fi
1111 # First QA check to stop now if genpkg_rules failed.
1112 lerror=$(_n 'ERROR')
1113 if fgrep -q ^$lerror $LOGS/$pkg.log; then
1114 exit 1
1115 fi
1117 cd $taz
1118 for file in receipt description.txt; do
1119 [ ! -f "../$file" ] && continue
1120 action 'Copying "%s"...' "$file"
1121 cp -f ../$file $pack; chown 0.0 $pack/$file; status
1122 done
1123 copy_generic_files
1125 # Strip and stuff files.
1126 strip_package
1127 strip_mo_i18n
1129 # Create files.list with redirecting find output.
1130 action 'Creating the list of files...'
1131 cd $fs
1132 find . -type f -print > ../files.list
1133 find . -type l -print >> ../files.list
1134 cd ..; sed -i s/'^.'/''/ files.list
1135 status
1137 # Md5sum of files.
1138 action 'Creating md5sum of files...'
1139 while read file; do
1140 [ -L "fs$file" ] && continue
1141 [ -f "fs$file" ] || continue
1142 case "$file" in
1143 /lib/modules/*/modules.*|*.pyc) continue ;;
1144 esac
1145 md5sum "fs$file" | sed 's/ fs/ /'
1146 done < files.list > md5sum
1147 status
1149 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
1150 2>/dev/null | awk 'END{ print $1 }')
1152 # Build cpio archives.
1153 action 'Compressing the FS...'
1154 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1155 rm -rf fs
1156 status
1158 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
1159 2>/dev/null | awk 'END{ print $1 }')
1161 action 'Updating receipt sizes...'
1162 sed -i s/^PACKED_SIZE.*$// receipt
1163 sed -i s/^UNPACKED_SIZE.*$// receipt
1164 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1165 status
1167 # Set extra version.
1168 if [ -n "$EXTRAVERSION" ]; then
1169 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
1170 sed -i s/^EXTRAVERSION.*$// receipt
1171 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
1172 status
1173 fi
1175 # Compress.
1176 action 'Creating full cpio archive...'
1177 find . -print | cpio -o -H newc --quiet > \
1178 ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
1179 status
1181 action 'Restoring original package tree...'
1182 unlzma -c fs.cpio.lzma | cpio -idm --quiet
1183 status
1185 rm fs.cpio.lzma; cd ..
1187 # QA and give info.
1188 tazpkg=$(ls *.tazpkg)
1189 packit_quality
1190 footer "$(_ 'Package "%s" created' "$tazpkg")"
1194 # Verify package quality and consistency.
1196 packit_quality() {
1197 #action 'QA: checking for broken link...'
1198 #link=$(find $fs/usr -type l -follow)
1199 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
1200 #status
1202 # Exit if any error found in log file.
1203 lerror=$(_n 'ERROR')
1204 if fgrep -q ^$lerror $LOGS/$pkg.log; then
1205 rm -f $command
1206 exit 1
1207 fi
1209 action 'QA: checking for empty package...'
1210 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
1211 if [ "$files" -eq 0 -a "$CATEGORY" != 'meta' ]; then
1212 newline; _ 'ERROR: empty package'
1213 rm -f $command
1214 exit 1
1215 else
1216 :; status
1217 # Find and remove old package(s)
1218 tempd="$(mktemp -d)"; cd "$tempd"
1219 for testpkg in $(ls $PKGS/$pkg-*.tazpkg 2> /dev/null); do
1220 # Extract receipt from each matched package
1221 cpio -F "$testpkg" -i receipt >/dev/null 2>&1
1222 name=$(. receipt; echo $PACKAGE)
1223 rm receipt
1224 if [ "$name" == "$pkg" ]; then
1225 action 'Removing old package "%s"' "$(basename "$testpkg")"
1226 rm -f "$testpkg"
1227 status
1228 fi
1229 done
1230 rm -r "$tempd"
1231 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
1232 sed -i /^${pkg}$/d $broken
1233 #action 'Removing source tree...'
1234 #rm -f $WOK/$pkg/source; status
1235 fi
1239 # Reverse "cat" command: prints input lines in the reverse order
1241 tac() {
1242 sed '1!G;h;$!d' $1
1246 # Install package on --install or update the chroot.
1248 install_package() {
1249 case "$ARCH" in
1250 arm*|x86_64)
1251 arch="-$ARCH"
1252 root="$CROSS_TREE/sysroot" ;;
1253 esac
1254 # Install package if requested but skip install if target host doesn't
1255 # match build system or it will break the build chroot.
1256 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1257 if [ -n "$inst" ] && [ "$build" == "$ARCH" ]; then
1258 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1259 cd $PKGS
1260 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
1261 else
1262 _ 'Unable to install package, build has failed.'; newline
1263 exit 1
1264 fi
1265 fi
1267 # Install package if part of the chroot to keep env up-to-date.
1268 if [ -d "$root$INSTALLED/$pkg" ]; then
1269 . /etc/slitaz/cook.conf
1270 . $WOK/$pkg/taz/$pkg-*/receipt
1271 _ 'Updating %s chroot environment...' "$ARCH"
1272 _ 'Updating chroot: %s' "$pkg ($VERSION$EXTRAVERSION$arch)" | log
1273 cd $PKGS
1274 tazpkg install $pkg-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1275 fi
1279 # remove chroot jail
1281 umount_aufs() {
1282 tac ${1}rw/aufs-umount.sh | sh
1283 rm -rf ${1}rw
1284 umount ${1}root
1285 rmdir ${1}r*
1289 # Launch the cook command into a chroot jail protected by aufs.
1290 # The current filesystems are used read-only and updates are
1291 # stored in a separate branch.
1293 try_aufs_chroot() {
1295 base="/dev/shm/aufsmnt$$"
1297 # Can we setup the chroot? Is it already done?
1298 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1299 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1300 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1301 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
1302 mkdir ${base}root ${base}rw || return
1304 _ 'Setup aufs chroot...'
1306 # Sanity check
1307 for i in / /proc /sys /dev/shm /home ; do
1308 case " $AUFS_MOUNTS " in
1309 *\ $i\ *) ;;
1310 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1311 esac
1312 done
1313 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1314 mount --bind $mnt ${base}root$mnt
1315 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1316 _ 'Aufs mount failure'
1317 umount ${base}root
1318 rm -rf ${base}r*
1319 return
1320 fi
1321 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1322 done
1323 trap "umount_aufs ${base}" INT
1325 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1326 status=$?
1328 _ 'Leaving aufs chroot...'
1329 umount_aufs $base
1330 # Install package outside the aufs jail
1331 install_package
1332 exit $status
1336 # Encode predefined XML entities
1338 xml_ent() {
1339 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1343 # Create a XML feed for freshly built packages.
1345 gen_rss() {
1346 pubdate=$(date '+%a, %d %b %Y %X')
1347 cat > $FEEDS/$pkg.xml <<EOT
1348 <item>
1349 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1350 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1351 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1352 <pubDate>$pubdate</pubDate>
1353 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1354 </item>
1355 EOT
1359 # Truncate stdout log file to $1 Mb.
1361 loglimit() {
1362 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1363 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1364 else
1365 tee /dev/stderr
1366 fi
1370 # Search file in mirrored packages
1372 search_file_mirror() {
1373 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
1377 # Search file in local wok packages
1379 search_file_local() {
1380 # existing packages have precedence over the package/taz folder
1381 srch=$1
1382 { for package in $(find $PKGS -name '*.tazpkg'); do
1383 if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
1384 grep /$srch\$)" ]; then
1385 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
1386 fi
1387 done } | sort -u
1391 # Ask in multiple choice
1393 ask_multiple() {
1394 local multiples first my_choice
1395 multiples="$1"
1396 first=$(echo "$multiples" | head -n1)
1397 newline; _ 'Multiple choice:'; echo "$multiples"; newline
1398 _ 'Select one [%s]: ' "$first"; read my_choice
1399 found="${my_choice:-$first}"
1403 # Search file in local cache (fast), local wok packages, mirrored packages
1405 search_file() {
1406 local srch cache missing
1407 srch="$1"
1408 cache='/var/cache/ldsearch.cache'
1409 missing='/var/cache/missing.file'
1410 touch $cache $missing
1411 found=$(grep $srch $cache | cut -d$'\t' -f2)
1412 if [ -z "$found" ]; then
1413 found=$(search_file_local $srch)
1414 if [ -n "$found" ]; then
1415 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1416 ask_multiple "$found"
1417 fi
1418 echo -e "$srch\t$found" >> $cache
1419 else
1420 found=$(search_file_mirror $srch)
1421 if [ -n "$found" ]; then
1422 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1423 ask_multiple "$found"
1424 fi
1425 echo -e "$srch\t$found" >> $cache
1426 else
1427 echo "$srch" >> $missing
1428 fi
1429 fi
1430 fi
1434 # Return size of file in human readible format
1435 # Note, "du" in opposite returns size occupied by file on disk (4KB multiple in most cases)
1436 filesize() {
1437 busybox ls -lh "$1" | awk '{print $5 "B"}'
1442 # Receipt functions to ease packaging
1445 get_dev_files() {
1446 action 'Getting standard devel files...'
1447 mkdir -p $fs/usr/lib
1448 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1449 cp -a $install/usr/lib/*a $fs/usr/lib
1450 cp -a $install/usr/include $fs/usr
1451 status
1455 # Function to use in compile_rules() to copy man page from $src to $install
1457 cook_pick_manpages() {
1458 local name section
1459 action 'Copying man pages...'
1461 for i in $@; do
1462 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1463 section=${name##*/}; section=${section##*.}
1464 mkdir -p $install/usr/share/man/man$section
1465 cp -a $i $install/usr/share/man/man$section
1466 done
1467 status
1471 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1473 cook_copy_files() {
1474 action 'Copying files...'
1475 cd $install
1476 local i j
1477 for i in $@; do
1478 for j in $(find . -name $i ! -type d); do
1479 mkdir -p $fs$(dirname ${j#.})
1480 cp -a $j $fs/${j#.}
1481 done
1482 done
1483 cd - >/dev/null
1484 status
1488 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1490 cook_copy_folders() {
1491 action 'Copying folders...'
1492 cd $install
1493 local i j
1494 for i in $@; do
1495 for j in $(find . -name $i -type d); do
1496 mkdir -p $fs$(dirname ${j#.})
1497 cp -a $j $fs/${j#.}
1498 done
1499 done
1500 cd - >/dev/null
1501 status
1505 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1506 # (default: 16 and 48) from $install to $fs
1508 cook_copy_icons() {
1509 local sizes=$@
1510 action 'Copying hicolor icons...'
1511 mkdir -p $fs/usr/share/icons/hicolor
1512 for i in ${sizes:-16 48}; do
1513 [ -e "$install/usr/share/icons/hicolor/${i}x$i" ] &&
1514 cp -a $install/usr/share/icons/hicolor/${i}x$i \
1515 $fs/usr/share/icons/hicolor
1516 done
1517 status
1520 dblog() { tee -a $LOGS/pkgdb.log; }
1526 # Commands
1529 case "$1" in
1530 usage|help|-u|-h)
1531 usage ;;
1533 list-wok)
1534 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1535 cd $WOK
1536 if [ "$ARCH" != 'i486' ]; then
1537 count=0
1538 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1539 do
1540 unset HOST_ARCH
1541 . $pkg
1542 count=$(($count + 1))
1543 colorize 34 "$PACKAGE"
1544 done
1545 else
1546 count=$(ls | wc -l)
1547 ls -1
1548 fi
1549 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1550 ;;
1552 activity)
1553 cat $activity ;;
1555 search)
1556 # Just a simple search function, we dont need more actually.
1557 query="$2"
1558 title 'Search results for "%s"' "$query"
1559 cd $WOK; ls -1 | grep "$query"
1560 footer ;;
1562 setup)
1563 # Setup a build environment
1564 check_root
1565 _ 'Cook: setup environment' | log
1566 title 'Setting up your environment'
1567 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1568 cd $SLITAZ
1569 init_db_files
1570 _ 'Checking for packages to install...'
1571 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1572 # ARCH-setup or 'cross check' should be used before: cook setup
1573 case "$ARCH" in
1574 arm*|x86_64)
1575 if [ ! -x '/usr/bin/cross' ]; then
1576 _ 'ERROR: %s is not installed' 'cross'
1577 exit 1
1578 fi
1579 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1580 . /etc/slitaz/cross.conf ;;
1581 esac
1582 for pkg in $SETUP_PKGS; do
1583 if [ -n "$forced" ]; then
1584 tazpkg -gi $pkg --forced
1585 else
1586 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1587 fi
1588 done
1590 # Handle --options
1591 case "$2" in
1592 --wok) hg clone $WOK_URL wok || exit 1 ;;
1593 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1594 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1595 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1596 esac
1598 # SliTaz group and permissions
1599 if ! grep -q ^slitaz /etc/group; then
1600 _ 'Adding group "%s"' 'slitaz'
1601 addgroup slitaz
1602 fi
1603 _ 'Setting permissions for group "%s"...' 'slitaz'
1604 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1605 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1606 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1608 *-setup)
1609 # Setup for cross compiling.
1610 arch="${1%-setup}"
1611 check_root
1612 . /etc/slitaz/cook.conf
1613 for pkg in $CROSS_SETUP; do
1614 if [ -n "$forced" ]; then
1615 tazpkg -gi $pkg --forced
1616 else
1617 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1618 fi
1619 done
1621 _ 'Cook: setup %s cross environment' "$arch" | log
1622 title 'Setting up your %s cross environment' "$arch"
1623 init_db_files
1624 sed -i \
1625 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1626 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1627 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1628 /etc/slitaz/cook.conf
1629 case "$arch" in
1630 arm)
1631 flags='-O2 -march=armv6'
1632 host="$ARCH-slitaz-linux-gnueabi" ;;
1633 armv6hf)
1634 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1635 host="$ARCH-slitaz-linux-gnueabi" ;;
1636 armv7)
1637 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1638 host="$ARCH-slitaz-linux-gnueabi" ;;
1639 x86_64)
1640 flags='-O2 -mtune=generic -pipe'
1641 host="$ARCH-slitaz-linux" ;;
1642 esac
1643 sed -i \
1644 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1645 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1646 . /etc/slitaz/cook.conf
1647 sysroot="$CROSS_TREE/sysroot"
1648 tools="/cross/$arch/tools"
1649 root="$sysroot"
1650 # L10n: keep the same width of translations to get a consistent view
1651 _ 'Target arch : %s' "$ARCH"
1652 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1653 _ 'Build flags : %s' "$flags"
1654 _ 'Arch sysroot : %s' "$sysroot"
1655 _ 'Tools prefix : %s' "$tools/bin"
1656 # Tell the packages manager where to find packages.
1657 _ 'Packages DB : %s' "$root$DB"
1658 mkdir -p $root$INSTALLED
1659 cd $root$DB; rm -f *.bak
1660 for list in packages.list packages.desc packages.equiv packages.md5; do
1661 rm -f $list
1662 ln -s $SLITAZ/packages/$list $list
1663 done
1664 # We must have the cross compiled glibc-base installed or default
1665 # i486 package will be used as dep by tazpkg and then break the
1666 # cross environment
1667 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1668 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1669 fi
1670 # Show GCC version or warn if not yet compiled.
1671 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1672 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1673 else
1674 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1675 _ 'Run "%s" to cook a toolchain' 'cross compile'
1676 fi
1677 footer ;;
1679 test)
1680 # Test a cook environment.
1681 _ 'Cook test: testing the cook environment' | log
1682 [ ! -d "$WOK" ] && exit 1
1683 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1684 cook cooktest ;;
1686 new)
1687 # Create the package folder and an empty receipt.
1688 pkg="$2"
1689 [ -z "$pkg" ] && usage
1690 newline
1691 if [ -d "$WOK/$pkg" ]; then
1692 _ 'Package "%s" already exists.' "$pkg"
1693 exit 1
1694 fi
1696 action 'Creating folder "%s"' "$WOK/$pkg"
1697 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1699 action 'Preparing the package receipt...'
1700 cp $DATA/receipt .
1701 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1702 status; newline
1704 # Interactive mode, asking and seding.
1705 case "$3" in
1706 --interactive|-x)
1707 _ 'Entering interactive mode...'
1708 separator
1709 _ 'Package : %s' "$pkg"
1711 _n 'Version : ' ; read answer
1712 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1714 _n 'Category : ' ; read answer
1715 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1717 # L10n: Short description
1718 _n 'Short desc : ' ; read answer
1719 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1721 _n 'Maintainer : ' ; read answer
1722 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1724 _n 'License : ' ; read answer
1725 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1727 _n 'Web site : ' ; read answer
1728 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1729 newline
1731 # Wget URL.
1732 _ 'Wget URL to download source tarball.'
1733 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1734 _n 'Wget url : ' ; read answer
1735 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1737 # Ask for a stuff dir.
1738 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1739 if [ "$?" -eq 0 ]; then
1740 action 'Creating the stuff directory...'
1741 mkdir $WOK/$pkg/stuff; status
1742 fi
1744 # Ask for a description file.
1745 confirm "$(_n 'Are you going to write a description? (y/N)')"
1746 if [ "$?" -eq 0 ]; then
1747 action 'Creating the "%s" file...' 'description.txt'
1748 touch $WOK/$pkg/description.txt; status
1749 fi
1751 footer "$(_ 'Receipt is ready to use.')" ;;
1752 esac ;;
1754 list)
1755 # Cook a list of packages (better use the Cooker since it will order
1756 # packages before executing cook).
1757 check_root
1758 if [ -z "$2" ]; then
1759 newline; _ 'No list in argument.'; newline
1760 exit 1
1761 fi
1762 if [ ! -f "$2" ]; then
1763 newline; _ 'List "%s" not found.' "$2"; newline
1764 exit 1
1765 fi
1767 _ 'Starting cooking the list "%s"' "$2" | log
1769 for pkg in $(cat $2); do
1770 cook $pkg || broken
1771 done ;;
1773 clean-wok)
1774 check_root
1775 newline; action 'Cleaning all packages files...'
1776 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1777 status; newline ;;
1779 clean-src)
1780 check_root
1781 newline; action 'Cleaning all packages sources...'
1782 rm -rf $WOK/*/source
1783 status; newline ;;
1785 uncook)
1786 cd $WOK
1787 count=0
1788 title 'Checking for uncooked packages'
1790 for pkg in *; do
1791 unset HOST_ARCH EXTRAVERSION
1792 [ ! -e $pkg/receipt ] && continue
1793 . $pkg/receipt
1794 # Source cooked pkg receipt to get EXTRAVERSION
1795 if [ -d "$WOK/$pkg/taz" ]; then
1796 cd $WOK/$pkg/taz/$pkg-*
1797 . receipt; cd $WOK
1798 fi
1799 case "$ARCH" in
1800 i486)
1801 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1802 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1803 count=$(($count + 1))
1804 colorize 34 "$pkg"
1805 fi ;;
1806 arm*)
1807 # Check only packages included in arch
1808 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1809 # *.tazpkg
1810 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1811 count=$(($count + 1))
1812 colorize 34 "$pkg"
1813 fi
1814 fi ;;
1815 esac
1816 done
1818 if [ "$count" -gt "0" ]; then
1819 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1820 else
1821 _ 'All packages are cooked :-)'
1822 newline
1823 fi
1824 ;;
1826 pkgdb)
1827 # Create suitable packages list for TazPKG and only for built packages
1828 # as well as flavors files for TazLiTo. We dont need logs since we do it
1829 # manually to ensure everything is fine before syncing the mirror.
1831 rm $LOGS/pkgdb.log 2>/dev/null
1833 case "$2" in
1834 --flavors|--rmpkg) ;;
1835 *)
1836 [ -n "$2" ] && PKGS="$2"
1837 if [ ! -d "$PKGS" ]; then
1838 { newline; _ "Packages directory \"%s\" doesn't exist" "$PKGS"; newline; } | dblog
1839 exit 1
1840 fi ;;
1841 esac
1843 time=$(date +%s)
1844 flavors="$SLITAZ/flavors"
1845 live="$SLITAZ/live"
1847 echo 'cook:pkgdb' > $command
1848 _ 'Cook pkgdb: Creating all packages lists' | log
1849 newline; { _ 'Creating lists for "%s"' "$PKGS"; separator; } | dblog
1851 { _ 'Cook pkgdb started: %s' "$(date "$(_ '+%%F %%R')")"; newline; } | dblog
1853 cd $PKGS
1854 rm -f packages.* extra.list
1855 touch packages.equiv
1857 _n 'Creating file "%s"' 'packages.list' | dblog
1858 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1859 echo " ($(filesize $PKGS/packages.list))" | dblog
1861 _n 'Creating file "%s"' 'packages.md5' | dblog
1862 md5sum *.tazpkg > $PKGS/packages.md5
1863 echo " ($(filesize $PKGS/packages.md5))" | dblog
1864 cp $PKGS/packages.md5 $PKGS/packages.toremove # list of duplicates
1866 md5sum packages.md5 | cut -d' ' -f1 > ID
1867 ( cat ./ID | tr $'\n' ' '; date -ur ./ID +%s ) > IDs # md5 and timestamp
1869 _n 'Creating file "%s"' 'descriptions.txt' | dblog
1870 rm $PKGS/descriptions.txt 2>/dev/null
1871 for i in $(ls $WOK | sort); do
1872 if [ -e "$WOK/$i/description.txt" ]; then
1873 echo "$i" >> descriptions.txt
1874 cat "$WOK/$i/description.txt" | sed 's|^$| |' >> descriptions.txt
1875 echo >> descriptions.txt
1876 fi
1877 done
1878 echo " ($(filesize $PKGS/descriptions.txt))" | dblog
1881 _ 'Creating lists from "%s"' "$WOK" | dblog
1882 cd $WOK
1883 for pkg in *; do
1884 unset_receipt
1885 . $pkg/receipt
1886 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1887 [ -s $pkg/taz/*/receipt ] && . $pkg/taz/*/receipt
1889 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ] || \
1890 [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1892 # packages.desc lets us search easily in DB
1893 cat >> $PKGS/packages.desc <<EOT
1894 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1895 EOT
1897 # packages.txt used by tazpkg and tazpkg-web also to provide
1898 # a human readable package list with version and description.
1899 cat >> $PKGS/packages.txt <<EOT
1900 $PACKAGE
1901 $VERSION$EXTRAVERSION
1902 $SHORT_DESC
1903 $PACKED_SIZE ($UNPACKED_SIZE installed)
1905 EOT
1907 # packages.info combines TazPkg separate files
1908 # and will substitute them all
1909 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1910 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
1911 MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" $PKGS/packages.md5 | awk '{print $1}')"
1912 cat >> $PKGS/packages.info <<EOT
1913 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5
1914 EOT
1916 # packages.equiv is used by tazpkg install to check depends.
1917 for i in $PROVIDE; do
1918 DEST=''
1919 echo $i | fgrep -q : && DEST="${i#*:}:"
1920 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1921 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1922 $PKGS/packages.equiv
1923 else
1924 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1925 fi
1926 done
1928 # files.list provides a list of all packages files.
1929 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1930 $PKGS/files.list
1932 # list of duplicates
1933 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg/d" $PKGS/packages.toremove
1934 else
1935 # if receipt variable HOST_ARCH absent/empty or contains ARCH
1936 if [ -z "$HOST_ARCH" -o "${HOST_ARCH/$ARCH/}" != "$HOST_ARCH" ]; then
1937 _ ' - absent: %s (%s)' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$ARCH" | dblog
1938 fi
1939 fi
1940 done
1942 # Display list size.
1943 _ 'Done: %s (%s)' 'packages.desc' "$(filesize $PKGS/packages.desc)" | dblog
1944 _ 'Done: %s (%s)' 'packages.txt' "$(filesize $PKGS/packages.txt)" | dblog
1945 _ 'Done: %s (%s)' 'packages.info' "$(filesize $PKGS/packages.info)" | dblog
1946 _ 'Done: %s (%s)' 'packages.equiv' "$(filesize $PKGS/packages.equiv)" | dblog
1948 cd $PKGS
1951 # Check package duplicates
1952 if [ -s "$PKGS/packages.toremove" ]; then
1953 newline | dblog
1954 _ 'Removing duplicates:' | dblog
1955 while read pkgsum pkgfile; do
1956 echo " - $pkgfile" | dblog
1957 sed -i "/${pkgfile%.tazpkg}/d" $PKGS/packages.list
1958 sed -i "/ $pkgfile/d" $PKGS/packages.md5
1959 [ -n "$rmpkg" ] && rm $PKGS/$pkgfile # remove packages only with --rmpkg
1960 done < $PKGS/packages.toremove
1961 newline | dblog
1962 fi
1963 rm $PKGS/packages.toremove
1966 # files.list.lzma
1967 _n 'Creating file "%s"' 'files.list.lzma' | dblog
1968 touch files.list
1969 # pkgs.slitaz.org strongly depends on list sorted by packages names
1970 lzma e files.list files.list.lzma
1971 echo " ($(filesize $PKGS/files.list.lzma))" | dblog
1973 # Pre-sorting filenames causes 10% smaller resulting lzma file
1974 _n 'Creating file "%s"' 'files-list.lzma' | dblog
1975 cat files.list | sort -k2 -o files.list.sorted
1976 lzma e files.list.sorted files-list.lzma
1977 rm -f files.list files.list.sorted
1978 echo " ($(filesize $PKGS/files-list.lzma))" | dblog
1980 [ -e files.list.md5 ] && rm files.list.md5
1981 md5sum files-list.lzma | cut -d' ' -f1 | tr -d $'\n' > files-list.md5
1983 # packages.info.lzma
1984 PI=packages.info
1985 _n 'Creating file "%s"' 'packages.info.lzma' | dblog
1986 touch $PI
1987 lzma e $PI $PI.lzma
1988 echo " ($(filesize $PKGS/packages.info.lzma))" | dblog
1990 # Make bundle to fast recharge
1991 _n 'Creating file "%s"' 'bundle.tar.lzma' | dblog
1992 [ -f bundle.tar.lzma ] && rm bundle.tar.lzma
1993 # Make sure to get "mirrors" file
1994 until [ -e 'mirrors' ]; do
1995 wget -q http://mirror1.slitaz.org/mirrors
1996 echo -n '.' | dblog; sleep 5
1997 done
1998 # Make sure to get "extra.list" file
1999 until [ -e 'extra.list' ]; do
2000 wget -q -O extra.list http://mirror1.slitaz.org/packages/get.list
2001 echo -n '.' | dblog; sleep 5
2002 done
2003 busybox tar -chaf bundle.tar.lzma \
2004 mirrors extra.list files-list.md5 packages.info descriptions.txt \
2005 packages.desc packages.md5 packages.txt packages.list packages.equiv
2006 rm ./mirrors
2007 echo " ($(filesize $PKGS/bundle.tar.lzma))" | dblog
2009 # Display some info.
2010 separator | dblog
2011 nb=$(ls $PKGS/*.tazpkg | wc -l)
2012 time=$(($(date +%s) - $time))
2013 # L10n: 's' is for seconds (cooking time)
2014 { _ 'Packages: %s - Time: %ss' "$nb" "$time"; newline; } | dblog
2017 # Create all flavors files at once. Do we really need code to monitor
2018 # flavors changes? Lets just build them with packages lists before
2019 # syncing the mirror.
2020 [ "$2" != '--flavors' ] && exit 1
2022 if [ ! -d "$flavors" ]; then
2023 { _ 'Missing flavors folder "%s"' "$flavors"; newline; } | dblog
2024 exit 1
2025 fi
2027 [ ! -d "$live" ] && mkdir -p $live
2028 _ 'Creating flavors files in "%s"' "$live" | dblog
2029 _ 'Cook pkgdb: Creating all flavors' | log
2030 separator | dblog
2032 _ 'Recharging lists to use latest packages...' | dblog
2033 tazpkg recharge >/dev/null 2>/dev/null
2035 # We need a custom tazlito config to set working dir to /home/slitaz.
2036 if [ ! -f "$live/tazlito.conf" ]; then
2037 _ 'Creating configuration file "%s"' 'tazlito.conf' | dblog
2038 cp /etc/tazlito/tazlito.conf $live
2039 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
2040 $live/tazlito.conf
2041 fi
2043 # Update Hg flavors repo and pack.
2044 if [ -d "$flavors/.hg" ]; then
2045 cd $flavors; hg pull -u
2046 fi
2048 cd $live
2049 _ 'Starting to generate flavors...' | dblog
2050 rm -f flavors.list *.flavor
2051 for i in $flavors/*; do
2052 fl=$(basename $i)
2053 _ 'Packing flavor "%s"' "$fl" | dblog
2054 tazlito pack-flavor $fl >/dev/null || exit 1
2055 tazlito show-flavor $fl --brief --noheader 2>/dev/null >> flavors.list
2056 done
2057 cp -f $live/*.flavor $live/flavors.list $PKGS
2058 separator | dblog
2059 { _ 'Total flavors size: %s' "$(du -sh $live | awk '{print $1}')"; newline; } | dblog
2060 rm -f $command
2061 separator | dblog
2062 _ 'Cook pkgdb end: %s' "$(date "$(_ '+%%F %%R')")" | dblog
2063 ;;
2065 *)
2066 # Just cook and generate a package.
2067 check_root
2068 time=$(date +%s)
2069 pkg="$1"
2070 [ -z "$pkg" ] && usage
2071 lastcooktime=$(sed '/^Cook time/!d;s|.*: *\([0-9]*\)s.*|\1|' \
2072 $LOGS/$pkg.log 2> /dev/null | sed '$!d')
2073 receipt="$WOK/$pkg/receipt"
2074 check_pkg_in_wok
2075 newline
2077 unset inst
2078 unset_receipt
2079 . $receipt
2081 # Handle cross compilation.
2082 case "$ARCH" in
2083 arm*)
2084 if [ -z "$HOST_ARCH" ]; then
2085 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
2086 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
2087 _ 'cook: %s' "$error"
2088 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
2089 _ 'Cook skip: %s' "$error" | log
2090 newline
2091 exit 1
2092 fi ;;
2093 esac
2095 # Some packages are not included in some arch or fail to cross compile.
2096 : ${HOST_ARCH=i486}
2097 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
2098 # Handle arm{v6hf,v7,..}
2099 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
2100 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
2101 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
2102 _ 'cook: %s' "error"
2103 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
2104 _ 'Cook skip: %s' "$error" | log
2105 sed -i /^${pkg}$/d $broken
2106 newline
2107 exit 0
2108 fi
2110 # Skip blocked, 3 lines also for the Cooker.
2111 if grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ]; then
2112 _ 'Package "%s" is blocked' "$pkg"; newline
2113 exit 0
2114 fi
2116 try_aufs_chroot "$@"
2118 # Log and source receipt.
2119 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
2120 echo "cook:$pkg" > $command
2121 [ "$lastcooktime" ] &&
2122 echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
2123 while read cmd duration start; do
2124 [ $(($start + $duration)) -lt $(date +%s) ] &&
2125 echo "sed -i '/^$cmd $duration/d' $cooktime"
2126 done < $cooktime | sh
2128 # Display and log info if cook process stopped.
2129 # FIXME: gettext not working (in single quotes) here!
2130 trap '_ "\n\nCook stopped: control-C\n\n" | \
2131 tee -a $LOGS/$pkg.log' INT
2133 # Handle --options
2134 case "$2" in
2135 --clean|-c)
2136 action 'Cleaning "%s"' "$pkg"
2137 cd $WOK/$pkg; rm -rf install taz source
2138 status; newline
2139 exit 0 ;;
2141 --install|-i)
2142 inst='yes' ;;
2144 --getsrc|-gs)
2145 title 'Getting source for "%s"' "$pkg"
2146 get_source
2147 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
2148 exit 0 ;;
2150 --block|-b)
2151 action 'Blocking package "%s"' "$pkg"
2152 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
2153 status; newline
2154 exit 0 ;;
2156 --unblock|-ub)
2157 action 'Unblocking package "%s"' "$pkg"
2158 sed -i "/^${pkg}$/"d $blocked
2159 status; newline
2160 exit 0 ;;
2162 --pack)
2163 if [ -d $WOK/$pkg/taz ]; then
2164 rm -rf $WOK/$pkg/taz
2165 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
2166 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
2167 clean_log
2168 else
2169 _ 'Need to build "%s"' "$pkg"
2170 exit 0
2171 fi
2172 exit 0 ;;
2174 --cdeps)
2175 if [ ! -d $WOK/$pkg/taz ]; then
2176 _ 'Need to build "%s"' "$pkg"
2177 exit 0
2178 fi
2180 title 'Checking depends'
2181 lddlist='/tmp/lddlist'; touch $lddlist
2182 missing='/var/cache/missing.file'
2184 # find all deps using ldd
2185 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
2186 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
2187 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
2188 done #"
2190 # remove exe/so duplicates
2191 sort -u $lddlist > $lddlist.sorted
2193 # search packages
2194 for exefile in $(cat $lddlist.sorted); do
2195 search_file $exefile
2196 echo "$found" >> $lddlist.pkgs
2197 echo -n '.'
2198 done
2199 echo
2201 # remove packages duplicates
2202 sort -u $lddlist.pkgs > $lddlist.final
2203 sort -u $missing > $missing.final
2204 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
2205 exit 0 ;;
2206 esac
2208 # Rotate log
2209 for i in $(seq 9 -1 1); do
2210 j=$(($i - 1))
2211 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
2212 done
2213 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
2215 # Check if wanted is built now so we have separate log files.
2216 for wanted in $WANTED ; do
2217 if grep -q "^$wanted$" $blocked; then
2218 _ 'WANTED package "%s" is blocked' "$wanted" | tee $LOGS/$pkg.log
2219 newline
2220 rm -f $command
2221 exit 1
2222 fi
2223 if grep -q "^$wanted$" $broken; then
2224 _ 'WANTED package "%s" is broken' "$wanted" | tee $LOGS/$pkg.log
2225 newline
2226 rm -f $command
2227 exit 1
2228 fi
2229 if [ ! -d "$WOK/$wanted/install" ]; then
2230 cook "$wanted" || exit 1
2231 fi
2232 done
2234 # Cook and pack or exit on error and log everything.
2235 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
2236 remove_deps | tee -a $LOGS/$pkg.log
2237 cookit_quality
2238 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
2239 clean_log
2241 # Exit if any error in packing.
2242 lerror=$(_n 'ERROR')
2243 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
2244 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
2245 debug_info | tee -a $LOGS/$pkg.log
2246 rm -f $command
2247 exit 1
2248 fi
2250 # Create an XML feed
2251 gen_rss
2253 # Time and summary
2254 time=$(($(date +%s) - $time))
2255 summary | tee -a $LOGS/$pkg.log
2256 newline
2258 # We may want to install/update (outside aufs jail !).
2259 [ -s /aufs-umount.sh ] ||
2260 install_package
2262 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2263 # You want automation: use the Cooker Build Bot.
2264 rm -f $command ;;
2265 esac
2267 exit 0