cookutils view cook @ rev 841

cook: 1) set_paths(): follow receipt possible changes (allow auto-updating); 2) strip_mo_i18n(): search for *.mo files only in /usr/share/locale (fix gambas2 cooking)
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Nov 29 15:53:17 2016 +0200 (2016-11-29)
parents d8bac8bb4eab
children 7c61b5215cab
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 . "$pkgdir/receipt"
157 basesrc="$pkgdir/source"
158 tmpsrc="$basesrc/tmp"
159 src="$basesrc/$PACKAGE-$VERSION"
160 taz="$pkgdir/taz"
161 pack="$taz/$PACKAGE-$VERSION$EXTRAVERSION"
162 fs="$pack/fs"
163 stuff="$pkgdir/stuff"
164 install="$pkgdir/install"
165 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
166 lzma_tarball="$pkgsrc.tar.lzma"
167 if [ -n "$PATCH" ]; then
168 [ -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
169 fi
170 if [ -n "$WANTED" ]; then
171 basesrc="$WOK/$WANTED/source"
172 src="$basesrc/$WANTED-$VERSION"
173 install="$WOK/$WANTED/install"
174 wanted_stuff="$WOK/$WANTED/stuff"
175 fi
176 if [ -n "$SOURCE" ]; then
177 source_stuff="$WOK/$SOURCE/stuff"
178 fi
179 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
180 if [ -f "$WOK/linux/receipt" ]; then
181 kvers=$(grep ^VERSION= $WOK/linux/receipt | cut -d\" -f2)
182 kbasevers=${kvers:0:3}
183 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
184 kvers=$(grep ^VERSION= $INSTALLED/linux-api-headers/receipt | cut -d\" -f2)
185 kbasevers=${kvers:0:3}
186 fi
187 # Python version
188 if [ -f "$WOK/python/receipt" ]; then
189 pyvers=$(grep ^VERSION= $WOK/python/receipt | cut -d\" -f2)
190 fi
191 # Perl version for some packages needed it
192 if [ -f "$WOK/perl/receipt" ]; then
193 perlvers=$(grep ^VERSION= $WOK/perl/receipt | cut -d\" -f2)
194 fi
195 # Old way compatibility.
196 _pkg="$install"
197 }
200 # Create source tarball when URL is a SCM.
202 create_tarball() {
203 local tarball
204 tarball="$pkgsrc.tar.bz2"
205 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
206 _ 'Creating tarball "%s"' "$tarball"
207 if [ -n "$LZMA_SRC" ]; then
208 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
209 LZMA_SRC=''
210 else
211 tar -cjf $tarball $pkgsrc || exit 1
212 mv $tarball $SRC; rm -rf $pkgsrc
213 fi
214 TARBALL="$tarball"
215 }
218 # Get package source. For SCM we are in cache so clone here and create a
219 # tarball here.
221 get_source() {
222 local url
223 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
224 set_paths
225 pwd=$(pwd)
226 case "$WGET_URL" in
227 http://*|ftp://*)
228 # Busybox Wget is better!
229 busybox wget -T 60 -c -O $SRC/$TARBALL $WGET_URL || \
230 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
231 (_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
233 https://*)
234 wget -c --no-check-certificate -O $SRC/$TARBALL $WGET_URL || \
235 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
236 (_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
238 hg*|mercurial*)
239 if $(echo "$WGET_URL" | fgrep -q 'hg|'); then
240 url=${WGET_URL#hg|}
241 else
242 url=${WGET_URL#mercurial|}
243 fi
244 _ 'Getting source from %s...' 'Hg'
245 _ 'URL: %s' "$url"
246 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
247 if [ -n "$BRANCH" ]; then
248 _ 'Hg branch: %s' "$BRANCH"
249 hg clone $url --rev $BRANCH $pkgsrc || \
250 (_ 'ERROR: %s' "hg clone $url --rev $BRANCH" && exit 1)
251 else
252 hg clone $url $pkgsrc || (_ 'ERROR: %s' "hg clone $url" && exit 1)
253 fi
254 rm -rf $pkgsrc/.hg
255 create_tarball ;;
257 git*)
258 url=${WGET_URL#git|}
259 _ 'Getting source from %s...' 'Git'
260 _ 'URL: %s' "$url"
261 cd $SRC
262 git clone $url $pkgsrc || (_ 'ERROR: %s' "git clone $url" && exit 1)
263 if [ -n "$BRANCH" ]; then
264 _ 'Git branch: %s' "$BRANCH"
265 cd $pkgsrc; git checkout $BRANCH; cd ..
266 fi
267 cd $SRC
268 create_tarball ;;
270 cvs*)
271 url=${WGET_URL#cvs|}
272 mod=$PACKAGE
273 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
274 _ 'Getting source from %s...' 'CVS'
275 _ 'URL: %s' "$url"
276 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
277 _ 'Cloning to "%s"' "$pwd/$mod"
278 cvs -d:$url co $mod && mv $mod $pkgsrc
279 create_tarball ;;
281 svn*|subversion*)
282 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
283 url=${WGET_URL#svn|}
284 else
285 url=${WGET_URL#subversion|}
286 fi
287 _ 'Getting source from %s...' 'SVN'
288 _ 'URL: %s' "$url"
289 if [ -n "$BRANCH" ]; then
290 echo t | svn co $url -r $BRANCH $pkgsrc
291 else
292 echo t | svn co $url $pkgsrc
293 fi
294 create_tarball ;;
296 bzr*)
297 url=${WGET_URL#bzr|}
298 _ 'Getting source from %s...' 'bazaar'
299 cd $SRC
300 pkgsrc=${url#*:}
301 if [ -n "$BRANCH" ]; then
302 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
303 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
304 else
305 echo "bzr -Ossl.cert_reqs=none branch $url"
306 bzr -Ossl.cert_reqs=none branch $url
307 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
308 _ "Don't forget to add to receipt:"
309 echo -e "BRANCH=\"$BRANCH\"\n"
310 fi
311 mv $pkgsrc $pkgsrc-$BRANCH
312 pkgsrc="$pkgsrc-$BRANCH"
313 create_tarball ;;
315 *)
316 (newline; _ 'ERROR: Unable to handle "%s"' "$WGET_URL"; newline) | \
317 tee -a $LOGS/$PACKAGE.log
318 exit 1 ;;
319 esac
320 }
323 # Extract source package.
325 extract_source() {
326 if [ ! -s "$SRC/$TARBALL" ]; then
327 local url
328 url="$MIRROR_URL/sources/packages"
329 url="$url/${TARBALL:0:1}/$TARBALL"
330 _ 'Getting source from %s...' 'mirror'
331 _ 'URL: %s' "$url"
332 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
333 fi
334 _ 'Extracting source archive "%s"' "$TARBALL"
335 case "$TARBALL" in
336 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
337 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
338 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
339 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
340 *.tar) tar -xf $SRC/$TARBALL ;;
341 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
342 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
343 tar -xf $SRC/$TARBALL 2>/dev/null;;
344 *.7z) 7zr x $SRC/$TARBALL 2>/dev/null >&2 ;;
345 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
346 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
347 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
348 *) cp $SRC/$TARBALL $(pwd) ;;
349 esac
350 }
353 # Display time.
355 disp_time() {
356 local sec div min
357 sec="$1"
358 div=$(( ($1 + 30) / 60))
359 case $div in
360 0) min='';;
361 # L10n: 'm' is for minutes (approximate cooking time)
362 *) min=$(_n ' ~ %dm' "$div");;
363 esac
365 # L10n: 's' is for seconds (cooking time)
366 _ '%ds%s' "$sec" "$min"
367 }
370 # Display cooked package summary.
372 summary() {
373 set_paths
374 cd $WOK/$pkg
375 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
376 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
377 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
378 size=$(ls -lh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $5}')
379 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
380 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
382 _ 'Summary for: %s' "$PACKAGE $VERSION"
383 separator
385 # L10n: keep the same width of translations to get a consistent view
386 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
387 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
388 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
389 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
390 _ 'Packed : %s' "$fs"
391 _ 'Compressed : %s' "$size"
392 _ 'Files : %s' "$files"
393 _ 'Cook time : %s' "$(disp_time "$time")"
394 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
395 _ 'Host arch : %s' "$ARCH"
396 separator
397 }
400 # Display debugging error info.
402 debug_info() {
403 title 'Debug information'
404 # L10n: specify your format of date and time (to help: man date)
405 # L10n: not bad one is '+%x %R'
406 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
407 [ "$time" ] && _ 'Cook time: %ds' "$(($(date +%s) - $time))"
408 # L10n: Please, translate all messages beginning with ERROR in a same way
409 lerror=$(_n 'ERROR')
410 for error in \
411 ERROR $lerror 'No package' "cp: can't" "can't open" "can't cd" \
412 'error:' 'fatal error:' 'undefined reference to' \
413 'Unable to connect to' 'link: cannot find the library' \
414 'CMake Error' ': No such file or directory' \
415 'Could not read symbols: File in wrong format'
416 do
417 fgrep "$error" $LOGS/$pkg.log
418 done > $LOGS/$pkg.log.debug_info 2>&1
419 cat $LOGS/$pkg.log.debug_info
420 rm -f $LOGS/$pkg.log.debug_info
421 footer
422 }
425 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
426 # so some packages need to copy these files with the receipt and genpkg_rules.
428 copy_generic_files() {
429 # $LOCALE is set in cook.conf
430 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
431 if [ -d "$install/usr/share/locale" ]; then
432 mkdir -p $fs/usr/share/locale
433 for i in $LOCALE; do
434 if [ -d "$install/usr/share/locale/$i" ]; then
435 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
436 fi
437 done
438 fi
439 fi
441 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
442 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
443 if [ -d "$install/usr/share/pixmaps" ]; then
444 mkdir -p $fs/usr/share/pixmaps
445 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
446 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
447 $fs/usr/share/pixmaps
448 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
449 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
450 $fs/usr/share/pixmaps
451 fi
452 fi
454 # Custom or homemade PNG pixmap can be in stuff.
455 if [ -f "$stuff/$PACKAGE.png" ]; then
456 mkdir -p $fs/usr/share/pixmaps
457 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
458 fi
459 fi
461 # Desktop entry (.desktop).
462 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
463 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
464 if [ -d "$install/usr/share/applications" ] && [ -z "$WANTED" ]; then
465 mkdir -p $fs/usr/share
466 cp -a $install/usr/share/applications $fs/usr/share
467 fi
468 fi
470 # Homemade desktop file(s) can be in stuff.
471 if [ -d "$stuff/applications" ]; then
472 mkdir -p $fs/usr/share
473 cp -a $stuff/applications $fs/usr/share
474 fi
475 if [ -f "$stuff/$PACKAGE.desktop" ]; then
476 mkdir -p $fs/usr/share/applications
477 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
478 fi
480 # Add custom licenses
481 if [ -d "$stuff/licenses" ]; then
482 mkdir -p $fs/usr/share/licenses
483 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
484 fi
485 }
488 # Get list of supported locales...
490 get_supported_locales() {
491 local lpc='/slitaz-i18n/stuff/locale-pack.conf' LOCALE_PACK
492 if [ -e "$WOK$lpc" ]; then
493 # ... from package in the local wok
494 . "$WOK$lpc"
495 else
496 # ... from Hg
497 temp_conf=$(mktemp)
498 wget -q -O $temp_conf -T 10 "http://hg.slitaz.org/wok/raw-file/tip$lpc"
499 if [ -s $temp_conf ]; then
500 . $temp_conf
501 else
502 # Give up and use hardcoded list
503 LOCALE_PACK="ar ca cs da de el en es fi fr hr hu id is it ja nb nl nn pl pt \
504 pt_BR ro ru sl sv tr uk zh_CN zh_TW"
505 fi
506 rm $temp_conf
507 fi
508 echo $LOCALE_PACK
509 }
512 # Fix common errors and warnings in the .desktop files
513 # Fixing can be disabled with COOKOPTS="!fixdesktops"
515 fix_desktop_files() {
516 [ "${COOKOPTS/!fixdesktops/}" != "$COOKOPTS" ] && return
517 [ -z "$(find $install -type f -name '*.desktop')" ] && return
519 local size0=$(find $install -type f -name '*.desktop' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
520 local time0=$(date +%s)
522 if [ -n "$QA" -a -z "$(which desktop-file-validate)" ]; then
523 tazpkg -gi desktop-file-utils-extra --quiet
524 fi
526 # The variable $LOCALE is set in cook.conf and may be overridden in the receipt.
527 # Default value is "" (empty). That means for us that we'll use the full
528 # list of supported locales here.
529 [ -z "$LOCALE" ] && LOCALE=$(get_supported_locales)
531 for desktop in $(find $install -type f -name '*.desktop'); do
532 cp "$desktop" "$desktop.orig"
534 # Sort out .desktop file (is prerequisite to correct working of `fix-desktop-file`)
535 sdft "$desktop" -i
537 # Fix common errors in .desktop file
538 fix-desktop-file "$desktop"
540 # Strip unsupported locales from .desktop file
541 [ "${COOKOPTS/!i18nz/}" == "$COOKOPTS" ] &&
542 sdft "$desktop" -i -k "$LOCALE"
544 # Extra-strip
545 [ "${COOKOPTS/!extradesktops/}" == "$COOKOPTS" ] &&
546 sdft "$desktop" -i -g -x -tf -r 'Keywords*' -o
548 if [ -n "$QA" ]; then
549 # Check the rest of errors, warnings and tips
550 _ 'QA: Checking %s...' "$(basename $desktop)"
551 diff "$desktop.orig" "$desktop"
552 desktop-file-validate "$desktop" | busybox fold -s
553 echo
554 fi
556 rm "$desktop.orig"
557 done
559 local size1=$(find $install -type f -name '*.desktop' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
560 local time1=$(date +%s)
561 comp_summary "$time0" "$time1" "$size0" "$size1"
562 }
565 # Compressor mini summary
567 comp_summary() {
568 [ "$3" -eq 0 ] && return
569 local time=$(($2 - $1))
570 local saving=$(( ($3 - $4) / 1024 ))
571 _ ' Time: %s. Size: %s B -> %s B. Save: %s KB' "$(disp_time $time)" "$3" "$4" "$saving"
572 }
575 # Find and strip: --strip-all (-s) or --strip-debug on static libs as well
576 # as removing unneeded files like in Python packages. Cross compiled binaries
577 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
578 # Stripping can be disabled with COOKOPTS="!strip"
580 strip_package() {
581 [ "${COOKOPTS/!strip/}" != "$COOKOPTS" ] && return
583 case "$ARCH" in
584 arm*|x86_64) export STRIP="$HOST_SYSTEM-strip" ;;
585 *) export STRIP='strip' ;;
586 esac
587 action 'Executing strip on all files...'
588 local size0=0 size1=0 oldsize newsize
589 local time0=$(date +%s)
591 # Strip executable files
592 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games; do
593 if [ -d "$dir" ]; then
594 oldsize=$(find $dir -type f -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
595 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
596 newsize=$(find $dir -type f -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
597 size0=$((size0 + oldsize)); size1=$((size1 + newsize))
598 fi
599 done
601 # Strip shared and static libraries
602 # Remove Python *.pyc and *.pyo, Perl perllocal.pod and .packlist
603 oldsize=$(find $fs -type f \( \
604 -name '*.so*' -o -name '*.a' -o \
605 -name '*.pyc' -o -name '*.pyo' -o \
606 -name 'perllocal.pod' -o -name '.packlist' \) -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
608 find $fs -name '*.so*' -exec $STRIP -s '{}' 2>/dev/null \;
609 find $fs -name '*.a' -exec $STRIP --strip-debug '{}' 2>/dev/null \;
610 find $fs -type f \( -name '*.pyc' -o -name '*.pyo' \) -delete 2>/dev/null
611 find $fs -type f \( -name 'perllocal.pod' -o -name '.packlist' \) -delete 2>/dev/null
613 newsize=$(find $fs -type f \( \
614 -name '*.so*' -o -name '*.a' -o \) -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
616 size0=$((size0 + oldsize)); size1=$((size1 + newsize))
618 local time1=$(date +%s)
619 status
620 comp_summary "$time0" "$time1" "$size0" "$size1"
621 }
624 # Strip unsupported locales (.mo files)
626 strip_mo_i18n() {
627 [ "${COOKOPTS/!i18nz/}" != "$COOKOPTS" ] && return
629 [ -d "$fs/usr/share/locale" ] || return
630 [ -z "$(find $fs/usr/share/locale -type f -name '*.mo')" ] && return
632 action 'Stripping translations files...'
633 local size0=$(find $fs$fs/usr/share/locale -type f -name '*.mo' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
634 local time0=$(date +%s)
636 # The variable $LOCALE is set in cook.conf and may be overridden in the receipt.
637 # Default value is "" (empty). That means for us that we'll use the full
638 # list of supported locales here.
639 [ -z "$LOCALE" ] && LOCALE=$(get_supported_locales)
641 # Existing locales
642 elocales=" $(ls -1 "$fs/usr/share/locale" | tr '\n' ' ') "
644 # Thin out the list of existing locales. At the end there will be only locales that need
645 # to delete (and the garbage like '_AU', _US', '_BR' leaving from 'en_AU', 'en_US', 'pt_BR'...)
646 for keep_locale in $LOCALE; do
647 elocales=${elocales//$keep_locale}
648 done
650 # Remove the unsupported locales
651 for rem_locale in $elocales; do
652 [ -d "$fs/usr/share/locale/$rem_locale" ] &&
653 rm -r "$fs/usr/share/locale/$rem_locale"
654 done
656 local size1=$(find $fs -type f -name '*.mo' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
657 local time1=$(date +%s)
658 status
659 comp_summary "$time0" "$time1" "$size0" "$size1"
660 }
663 # Update installed.cook.diff
665 update_installed_cook_diff() {
666 # If a cook failed deps are removed.
667 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
668 cd $CACHE
669 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
670 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
671 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
672 }
675 # Remove installed deps.
677 remove_deps() {
678 # Now remove installed build deps.
679 diff='/tmp/installed.cook.diff'
680 if [ -s $diff ]; then
681 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
682 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
683 _n 'Build dependencies to remove:'; echo " $nb"
684 [ -n "$root" ] && echo "root=\"$root\""
685 _n 'Removing:'
686 for dep in $deps; do
687 echo -n " $dep"
688 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
689 done
690 newline; newline
691 # Keep the last diff for debug and info.
692 mv -f $diff $CACHE/installed.diff
693 fi
694 }
697 # Function to compress all man pages
698 # Compressing can be disabled with COOKOPTS="!manz"
700 compress_manpages() {
701 [ "${COOKOPTS/!manz/}" != "$COOKOPTS" ] && return
703 case "$ARCH" in
704 arm*) return;; # While SliTaz-arm miss `advancecomp`
705 esac
706 local manpath="$install/usr/share/man" dest link
707 [ -d "$manpath" ] || return
709 action 'Compressing man pages...'
711 local size0=$(find $install/usr/share/man -type f -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
712 local time0=$(date +%s)
713 # We'll use only Gzip compression, so decompress other formats first
714 find $manpath -type f -name '*.bz2' -exec bunzip2 \{\} \;
715 find $manpath -type f -name '*.xz' -exec unxz \{\} \;
717 # Fast compress with gzip
718 find $manpath -type f -name '*.[1-9]' -exec gzip \{\} \;
720 # Fix symlinks
721 for i in $(find $install/usr/share/man -type l); do
722 dest=$(readlink $i | sed 's|\.[gbx]z2*$||')
723 link=$(echo $i | sed 's|\.[gbx]z2*$||')
724 rm $i; ln -s $dest.gz $link.gz
725 done
727 # Recompress with advdef (it can't compress, only recompress)
728 tazpkg -gi advancecomp --quiet
729 for i in $(find $install/usr/share/man -type f); do
730 advdef -z4q $i
731 done
733 local size1=$(find $install/usr/share/man -type f -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
734 local time1=$(date +%s)
735 status
736 comp_summary "$time0" "$time1" "$size0" "$size1"
737 }
740 # Function used after compile_rules() to compress all png images
741 # Compressing can be disabled with COOKOPTS="!pngz"
743 cook_compress_png() {
744 [ "${COOKOPTS/!pngz/}" != "$COOKOPTS" ] && return
745 case "$ARCH" in
746 arm*) return;; # While SliTaz-arm miss `pngquant` and `optipng`
747 esac
748 [ -z "$(find $install -type f -name '*.png')" ] && return
750 action 'Compressing png images...'
751 local size0=$(find $install -type f -name '*.png' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
752 local time0=$(date +%s)
754 local use_pq=true use_op=true
755 [ "${COOKOPTS/!pngquant/}" != "$COOKOPTS" ] && use_pq=false
756 [ "${COOKOPTS/!optipng/}" != "$COOKOPTS" ] && use_op=false
758 $use_pq && tazpkg -gi pngquant --quiet
759 $use_op && tazpkg -gi optipng --quiet
761 local oplevel=$(echo $COOKOPTS | grep 'op[0-8]' | sed 's|.*op\([0-8]\).*|\1|')
762 [ -z "$oplevel" ] && oplevel='2'
763 [ "$oplevel" == '8' ] && oplevel='7 -zm1-9'
765 for i in $(find $install -type f -name '*.png'); do
766 $use_pq && pngquant -f --skip-if-larger --ext .png --speed 1 "$i"
767 $use_op && optipng -quiet -strip all -o$oplevel "$i"
768 done
770 local size1=$(find $install -type f -name '*.png' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
771 local time1=$(date +%s)
772 status
773 comp_summary "$time0" "$time1" "$size0" "$size1"
774 }
777 # Function used after compile_rules() to compress all svg images
778 # Compressing can be disabled with COOKOPTS="!svgz"
780 cook_compress_svg() {
781 [ "${COOKOPTS/!svgz/}" != "$COOKOPTS" ] && return
782 case "$ARCH" in
783 arm*) return;; # While SliTaz-arm miss `svgcleaner`
784 esac
785 [ -z "$(find $install -type f -name '*.svg')" ] && return
787 action 'Compressing svg images...'
788 local size0=$(find $install -type f -name '*.svg' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
789 local time0=$(date +%s)
790 tazpkg -gi svgcleaner --quiet
791 cleaner_log="$(mktemp)"
792 for i in $(find $install -type f -name '*.svg'); do
793 echo -n "$i: " >> "$cleaner_log"
794 svgcleaner "$i" "$i" --remove-unresolved-classes false --quiet true >> "$cleaner_log"
795 done
796 local size1=$(find $install -type f -name '*.svg' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
797 local time1=$(date +%s)
798 status
799 comp_summary "$time0" "$time1" "$size0" "$size1"
800 sed -i '/: $/d' "$cleaner_log"
801 if [ -s "$cleaner_log" ]; then
802 echo 'Cleaner warnings and errors:'
803 awk '{printf " %s\n", $0;}' "$cleaner_log"
804 echo
805 fi
806 rm "$cleaner_log"
807 }
810 # Function used after compile_rules() to shrink all *.ui and *.glade files:
811 # remove insignificant spaces and comments
812 # Compressing can be disabled with COOKOPTS="!uiz"
814 compress_ui() {
815 [ "${COOKOPTS/!uiz/}" != "$COOKOPTS" ] && return
816 case "$ARCH" in
817 arm*) return;; # While SliTaz-arm miss `xmlstarlet`
818 esac
819 [ -z "$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) )" ] && return
821 action 'Compressing ui files...'
822 local size0=$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
823 local time0=$(date +%s)
824 tazpkg -gi xmlstarlet --quiet
825 temp_ui="$(mktemp)"
826 for ui in $(find $install -type f \( -name '*.ui' -o -name '*.glade' \) ); do
827 xmlstarlet c14n --without-comments "$ui" | xmlstarlet sel -B -t -c '*' > "$temp_ui"
828 cat "$temp_ui" > "$ui"
829 done
830 local size1=$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
831 local time1=$(date +%s)
832 status
833 comp_summary "$time0" "$time1" "$size0" "$size1"
834 rm "$temp_ui"
835 }
838 # The main cook function.
840 cookit() {
841 title 'Cook: %s' "$PACKAGE $VERSION"
842 set_paths
844 # Handle cross-tools.
845 case "$ARCH" in
846 arm*|x86_64)
847 # CROSS_COMPILE is used by at least Busybox and the kernel to set
848 # the cross-tools prefix. Sysroot is the root of our target arch
849 sysroot="$CROSS_TREE/sysroot"
850 tools="$CROSS_TREE/tools"
851 # Set root path when cross compiling. ARM tested but not x86_64
852 # When cross compiling we must install build deps in $sysroot.
853 arch="-$ARCH"
854 root="$sysroot"
855 _ '%s sysroot: %s' "$ARCH" "$sysroot"
856 _ 'Adding "%s" to PATH' "$tools/bin"
857 export PATH="$PATH:$tools/bin"
858 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
859 export CROSS_COMPILE="$HOST_SYSTEM-"
860 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
861 if [ "$ARCH" == 'x86_64' ]; then
862 export CC="$HOST_SYSTEM-gcc -m64"
863 export CXX="$HOST_SYSTEM-g++ -m64"
864 else
865 export CC="$HOST_SYSTEM-gcc"
866 export CXX="$HOST_SYSTEM-g++"
867 fi
868 export AR="$HOST_SYSTEM-ar"
869 export AS="$HOST_SYSTEM-as"
870 export RANLIB="$HOST_SYSTEM-ranlib"
871 export LD="$HOST_SYSTEM-ld"
872 export STRIP="$HOST_SYSTEM-strip"
873 export LIBTOOL="$HOST_SYSTEM-libtool" ;;
874 esac
876 [ -n "$QA" ] && receipt_quality
877 cd $pkgdir
878 [ -z "$continue" ] && rm -rf source 2>/dev/null
879 rm -rf install taz 2>/dev/null
881 # Disable -pipe if less than 512Mb free RAM.
882 free=$(free | awk '/buffers:/{print $4}')
883 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
884 _ 'Disabling -pipe compile flag: %d RAM free' "$free"
885 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
886 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
887 fi
888 unset free
890 # Export flags and path to be used by make and receipt.
891 DESTDIR="$pkgdir/install"
892 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
893 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
894 #LDFLAGS
896 # Check for build deps and handle implicit depends of *-dev packages
897 # (ex: libusb-dev :: libusb).
898 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
899 touch $CACHE/installed.local $CACHE/installed.web
900 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
901 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
902 for dep in $BUILD_DEPENDS; do
903 implicit="${dep%-dev}"
904 # Don't add implicit dependency if it defined in DEPENDS
905 # echo '' $DEPENDS '' | fgrep -q " $implicit " && implicit=''
906 for i in $dep $implicit; do
907 if [ ! -f "$root$INSTALLED/$i/receipt" ]; then
908 # Try local package first. In some cases implicit doesn't exist, ex:
909 # libboost-dev exists but not libboost, so check if we got vers.
910 unset vers
911 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
912 # We may have a local package.
913 if [ -z "$vers" ]; then
914 vers=$(awk -F$'\t' -vp="$i" '$1==p{print $2; quit}' $PKGS/packages.info 2> /dev/null)
915 fi
916 debug "bdep: $i version: $vers"
917 if [ -f "$PKGS/$i-$vers$arch.tazpkg" ]; then
918 echo $i-$vers$arch.tazpkg >> $CACHE/installed.local
919 else
920 # Priority to package version in wok (maybe more up-to-date)
921 # than the mirrored one.
922 if [ -n "$vers" ]; then
923 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
924 echo $i >> $CACHE/installed.web
925 else
926 # So package exists in wok but not available.
927 _ 'Missing dep (wok/pkg): %s' "$i $vers"
928 echo $i >> $CACHE/missing.dep
929 fi
930 else
931 # Package is not in wok but may be in online repo.
932 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
933 echo $i >> $CACHE/installed.web
934 else
935 _ 'ERROR: unknown dep "%s"' "$i"
936 exit 1
937 fi
938 fi
939 fi
940 fi
941 done
942 done
944 # Get the list of installed packages
945 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
947 # Have we a missing build dep to cook?
948 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
949 _ 'Auto cook config is set: %s' "$AUTO_COOK"
950 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
951 for i in $(uniq $CACHE/missing.dep); do
952 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
953 tee -a $LOGS/$PACKAGE.log.$$
954 # programmers: next two messages are exact copy from remove_deps()
955 togrep1=$(_n 'Build dependencies to remove:')
956 togrep2=$(_n 'Removing:')
957 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
958 fgrep $togrep1 $LOGS/$i.log && \
959 fgrep $togrep2 $LOGS/$i.log && newline) | \
960 tee -a $LOGS/$PACKAGE.log.$$ && break
961 done
962 rm -f $CACHE/missing.dep
963 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
964 fi
966 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
967 # is enabled and cook fails we have ERROR in log, if no auto cook we have
968 # missing dep in cached file.
969 lerror=$(_n 'ERROR')
970 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
971 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
972 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
973 exit 1
974 fi
976 # Install local packages: package-version$arch
977 cd $PKGS
978 for i in $(uniq $CACHE/installed.local); do
979 _ 'Installing dep (pkg/local): %s' "$i"
980 tazpkg install $i --root=$root --local --quiet
981 done
983 # Install web or cached packages (if mirror is set to $PKGS we only
984 # use local packages).
985 for i in $(uniq $CACHE/installed.web); do
986 _ 'Installing dep (web/cache): %s' "$i"
987 tazpkg get-install $i --root=$root --quiet
988 done
990 update_installed_cook_diff
992 # Get source tarball and make sure we have source dir named:
993 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
994 # tarball if it exists.
995 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
996 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
997 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
998 LZMA_SRC=''
999 else
1000 get_source || exit 1
1001 fi
1002 fi
1003 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
1004 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
1005 if ! extract_source ; then
1006 get_source
1007 extract_source || exit 1
1008 fi
1009 if [ -n "$LZMA_SRC" ]; then
1010 cd $pkgdir/source
1011 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
1012 mv tmp tmp-1; mkdir tmp
1013 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
1014 fi
1015 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
1016 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
1017 fi
1018 fi
1019 cd $pkgdir/source/tmp
1020 # Some archives are not well done and don't extract to one dir (ex lzma).
1021 files=$(ls | wc -l)
1022 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
1023 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
1024 mv * ../$PACKAGE-$VERSION/$TARBALL
1025 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
1026 mv * ../$PACKAGE-$VERSION
1027 cd ..; rm -rf tmp
1028 fi
1030 # Libtool shared libs path hack.
1031 case "$ARCH" in
1032 arm*) cross libhack ;;
1033 esac
1035 # Execute receipt rules.
1036 if grep -q ^compile_rules $receipt; then
1037 _ 'Executing: %s' 'compile_rules'
1038 echo "CFLAGS : $CFLAGS"
1039 #echo "LDFLAGS : $LDFLAGS"
1040 [ -d "$src" ] && cd $src
1041 compile_rules $@ || exit 1
1042 # Stay compatible with _pkg
1043 [ -d "$src/_pkg" ] && mv $src/_pkg $install
1044 # QA: compile_rules success so valid.
1045 mkdir -p $install
1046 else
1047 # QA: no compile_rules so no error, valid.
1048 mkdir -p $install
1049 fi
1051 # Actions to do after compiling the package
1052 # Skip all for splitted packages (already done in main package)
1053 if [ -z "$WANTED" ]; then
1054 footer
1055 compress_manpages
1056 cook_compress_png
1057 cook_compress_svg
1058 compress_ui
1059 fix_desktop_files
1060 fi
1061 footer
1063 # Execute testsuite.
1064 if grep -q ^testsuite $receipt; then
1065 title 'Running testsuite'
1066 testsuite $@ || exit 1
1067 footer
1068 fi
1070 update_installed_cook_diff force
1074 # Cook quality assurance.
1076 cookit_quality() {
1077 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
1078 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
1079 fi
1080 # ERROR can be echoed any time in cookit()
1081 lerror=$(_n 'ERROR')
1082 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
1083 grep -Eq "(^$lerror|undefined reference to)" ; then
1084 debug_info | tee -a $LOGS/$pkg.log
1085 rm -f $command
1086 exit 1
1087 fi
1091 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
1092 # but it doesn't handle EXTRAVERSION.
1094 packit() {
1095 set_paths
1097 # Handle cross compilation
1098 case "$ARCH" in
1099 arm*|x86_64) arch="-$ARCH" ;;
1100 esac
1102 title 'Pack: %s' "$PACKAGE $VERSION$arch"
1104 if grep -q ^genpkg_rules $receipt; then
1105 _ 'Executing: %s' 'genpkg_rules'
1106 set -e; cd $pkgdir; mkdir -p $fs
1107 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
1108 $LOGS/$pkg.log
1109 else
1110 _ 'No packages rules: meta package'
1111 mkdir -p $fs
1112 fi
1114 # First QA check to stop now if genpkg_rules failed.
1115 lerror=$(_n 'ERROR')
1116 if fgrep -q ^$lerror $LOGS/$pkg.log; then
1117 exit 1
1118 fi
1120 cd $taz
1121 for file in receipt description.txt; do
1122 [ ! -f "../$file" ] && continue
1123 action 'Copying "%s"...' "$file"
1124 cp -f ../$file $pack; chown 0.0 $pack/$file; status
1125 done
1126 copy_generic_files
1128 # Strip and stuff files.
1129 strip_package
1130 strip_mo_i18n
1132 # Create files.list with redirecting find output.
1133 action 'Creating the list of files...'
1134 cd $fs
1135 find . -type f -print > ../files.list
1136 find . -type l -print >> ../files.list
1137 cd ..; sed -i s/'^.'/''/ files.list
1138 status
1140 # Md5sum of files.
1141 action 'Creating md5sum of files...'
1142 while read file; do
1143 [ -L "fs$file" ] && continue
1144 [ -f "fs$file" ] || continue
1145 case "$file" in
1146 /lib/modules/*/modules.*|*.pyc) continue ;;
1147 esac
1148 md5sum "fs$file" | sed 's/ fs/ /'
1149 done < files.list > md5sum
1150 status
1152 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
1153 2>/dev/null | awk 'END{ print $1 }')
1155 # Build cpio archives.
1156 action 'Compressing the FS...'
1157 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1158 rm -rf fs
1159 status
1161 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
1162 2>/dev/null | awk 'END{ print $1 }')
1164 action 'Updating receipt sizes...'
1165 sed -i s/^PACKED_SIZE.*$// receipt
1166 sed -i s/^UNPACKED_SIZE.*$// receipt
1167 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1168 status
1170 # Set extra version.
1171 if [ -n "$EXTRAVERSION" ]; then
1172 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
1173 sed -i s/^EXTRAVERSION.*$// receipt
1174 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
1175 status
1176 fi
1178 # Compress.
1179 action 'Creating full cpio archive...'
1180 find . -print | cpio -o -H newc --quiet > \
1181 ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
1182 status
1184 action 'Restoring original package tree...'
1185 unlzma -c fs.cpio.lzma | cpio -idm --quiet
1186 status
1188 rm fs.cpio.lzma; cd ..
1190 # QA and give info.
1191 tazpkg=$(ls *.tazpkg)
1192 packit_quality
1193 footer "$(_ 'Package "%s" created' "$tazpkg")"
1197 # Verify package quality and consistency.
1199 packit_quality() {
1200 #action 'QA: checking for broken link...'
1201 #link=$(find $fs/usr -type l -follow)
1202 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
1203 #status
1205 # Exit if any error found in log file.
1206 lerror=$(_n 'ERROR')
1207 if fgrep -q ^$lerror $LOGS/$pkg.log; then
1208 rm -f $command
1209 exit 1
1210 fi
1212 action 'QA: checking for empty package...'
1213 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
1214 if [ "$files" -eq 0 -a "$CATEGORY" != 'meta' ]; then
1215 newline; _ 'ERROR: empty package'
1216 rm -f $command
1217 exit 1
1218 else
1219 :; status
1220 # Find and remove old package(s)
1221 tempd="$(mktemp -d)"; cd "$tempd"
1222 for testpkg in $(ls $PKGS/$pkg-*.tazpkg 2> /dev/null); do
1223 # Extract receipt from each matched package
1224 cpio -F "$testpkg" -i receipt >/dev/null 2>&1
1225 name=$(. receipt; echo $PACKAGE)
1226 rm receipt
1227 if [ "$name" == "$pkg" ]; then
1228 action 'Removing old package "%s"' "$(basename "$testpkg")"
1229 rm -f "$testpkg"
1230 status
1231 fi
1232 done
1233 rm -r "$tempd"
1234 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
1235 sed -i /^${pkg}$/d $broken
1236 #action 'Removing source tree...'
1237 #rm -f $WOK/$pkg/source; status
1238 fi
1242 # Reverse "cat" command: prints input lines in the reverse order
1244 tac() {
1245 sed '1!G;h;$!d' $1
1249 # Install package on --install or update the chroot.
1251 install_package() {
1252 case "$ARCH" in
1253 arm*|x86_64)
1254 arch="-$ARCH"
1255 root="$CROSS_TREE/sysroot" ;;
1256 esac
1257 # Install package if requested but skip install if target host doesn't
1258 # match build system or it will break the build chroot.
1259 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1260 if [ -n "$inst" ] && [ "$build" == "$ARCH" ]; then
1261 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1262 cd $PKGS
1263 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
1264 else
1265 _ 'Unable to install package, build has failed.'; newline
1266 exit 1
1267 fi
1268 fi
1270 # Install package if part of the chroot to keep env up-to-date.
1271 if [ -d "$root$INSTALLED/$pkg" ]; then
1272 . /etc/slitaz/cook.conf
1273 . $WOK/$pkg/taz/$pkg-*/receipt
1274 _ 'Updating %s chroot environment...' "$ARCH"
1275 _ 'Updating chroot: %s' "$pkg ($VERSION$EXTRAVERSION$arch)" | log
1276 cd $PKGS
1277 tazpkg install $pkg-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1278 fi
1282 # remove chroot jail
1284 umount_aufs() {
1285 tac ${1}rw/aufs-umount.sh | sh
1286 rm -rf ${1}rw
1287 umount ${1}root
1288 rmdir ${1}r*
1292 # Launch the cook command into a chroot jail protected by aufs.
1293 # The current filesystems are used read-only and updates are
1294 # stored in a separate branch.
1296 try_aufs_chroot() {
1298 base="/dev/shm/aufsmnt$$"
1300 # Can we setup the chroot? Is it already done?
1301 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1302 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1303 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1304 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
1305 mkdir ${base}root ${base}rw || return
1307 _ 'Setup aufs chroot...'
1309 # Sanity check
1310 for i in / /proc /sys /dev/shm /home ; do
1311 case " $AUFS_MOUNTS " in
1312 *\ $i\ *) ;;
1313 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1314 esac
1315 done
1316 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1317 mount --bind $mnt ${base}root$mnt
1318 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1319 _ 'Aufs mount failure'
1320 umount ${base}root
1321 rm -rf ${base}r*
1322 return
1323 fi
1324 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1325 done
1326 trap "umount_aufs ${base}" INT
1328 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1329 status=$?
1331 _ 'Leaving aufs chroot...'
1332 umount_aufs $base
1333 # Install package outside the aufs jail
1334 install_package
1335 exit $status
1339 # Encode predefined XML entities
1341 xml_ent() {
1342 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1346 # Create a XML feed for freshly built packages.
1348 gen_rss() {
1349 pubdate=$(date '+%a, %d %b %Y %X')
1350 cat > $FEEDS/$pkg.xml <<EOT
1351 <item>
1352 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1353 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1354 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1355 <pubDate>$pubdate</pubDate>
1356 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1357 </item>
1358 EOT
1362 # Truncate stdout log file to $1 Mb.
1364 loglimit() {
1365 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1366 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1367 else
1368 tee /dev/stderr
1369 fi
1373 # Search file in mirrored packages
1375 search_file_mirror() {
1376 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
1380 # Search file in local wok packages
1382 search_file_local() {
1383 # existing packages have precedence over the package/taz folder
1384 srch=$1
1385 { for package in $(find $PKGS -name '*.tazpkg'); do
1386 if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
1387 grep /$srch\$)" ]; then
1388 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
1389 fi
1390 done } | sort -u
1394 # Ask in multiple choice
1396 ask_multiple() {
1397 local multiples first my_choice
1398 multiples="$1"
1399 first=$(echo "$multiples" | head -n1)
1400 newline; _ 'Multiple choice:'; echo "$multiples"; newline
1401 _ 'Select one [%s]: ' "$first"; read my_choice
1402 found="${my_choice:-$first}"
1406 # Search file in local cache (fast), local wok packages, mirrored packages
1408 search_file() {
1409 local srch cache missing
1410 srch="$1"
1411 cache='/var/cache/ldsearch.cache'
1412 missing='/var/cache/missing.file'
1413 touch $cache $missing
1414 found=$(grep $srch $cache | cut -d$'\t' -f2)
1415 if [ -z "$found" ]; then
1416 found=$(search_file_local $srch)
1417 if [ -n "$found" ]; then
1418 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1419 ask_multiple "$found"
1420 fi
1421 echo -e "$srch\t$found" >> $cache
1422 else
1423 found=$(search_file_mirror $srch)
1424 if [ -n "$found" ]; then
1425 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1426 ask_multiple "$found"
1427 fi
1428 echo -e "$srch\t$found" >> $cache
1429 else
1430 echo "$srch" >> $missing
1431 fi
1432 fi
1433 fi
1437 # Return size of file in human readible format
1438 # Note, "du" in opposite returns size occupied by file on disk (4KB multiple in most cases)
1439 filesize() {
1440 busybox ls -lh "$1" | awk '{print $5 "B"}'
1445 # Receipt functions to ease packaging
1448 get_dev_files() {
1449 action 'Getting standard devel files...'
1450 mkdir -p $fs/usr/lib
1451 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1452 cp -a $install/usr/lib/*a $fs/usr/lib
1453 cp -a $install/usr/include $fs/usr
1454 status
1458 # Function to use in compile_rules() to copy man page from $src to $install
1460 cook_pick_manpages() {
1461 local name section
1462 action 'Copying man pages...'
1464 for i in $@; do
1465 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1466 section=${name##*/}; section=${section##*.}
1467 mkdir -p $install/usr/share/man/man$section
1468 cp -a $i $install/usr/share/man/man$section
1469 done
1470 status
1474 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1476 cook_copy_files() {
1477 action 'Copying files...'
1478 cd $install
1479 local i j
1480 for i in $@; do
1481 for j in $(find . -name $i ! -type d); do
1482 mkdir -p $fs$(dirname ${j#.})
1483 cp -a $j $fs/${j#.}
1484 done
1485 done
1486 cd - >/dev/null
1487 status
1491 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1493 cook_copy_folders() {
1494 action 'Copying folders...'
1495 cd $install
1496 local i j
1497 for i in $@; do
1498 for j in $(find . -name $i -type d); do
1499 mkdir -p $fs$(dirname ${j#.})
1500 cp -a $j $fs/${j#.}
1501 done
1502 done
1503 cd - >/dev/null
1504 status
1508 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1509 # (default: 16 and 48) from $install to $fs
1511 cook_copy_icons() {
1512 local sizes=$@
1513 action 'Copying hicolor icons...'
1514 mkdir -p $fs/usr/share/icons/hicolor
1515 for i in ${sizes:-16 48}; do
1516 [ -e "$install/usr/share/icons/hicolor/${i}x$i" ] &&
1517 cp -a $install/usr/share/icons/hicolor/${i}x$i \
1518 $fs/usr/share/icons/hicolor
1519 done
1520 status
1523 dblog() { tee -a $LOGS/pkgdb.log; }
1529 # Commands
1532 case "$1" in
1533 usage|help|-u|-h)
1534 usage ;;
1536 list-wok)
1537 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1538 cd $WOK
1539 if [ "$ARCH" != 'i486' ]; then
1540 count=0
1541 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1542 do
1543 unset HOST_ARCH
1544 . $pkg
1545 count=$(($count + 1))
1546 colorize 34 "$PACKAGE"
1547 done
1548 else
1549 count=$(ls | wc -l)
1550 ls -1
1551 fi
1552 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1553 ;;
1555 activity)
1556 cat $activity ;;
1558 search)
1559 # Just a simple search function, we dont need more actually.
1560 query="$2"
1561 title 'Search results for "%s"' "$query"
1562 cd $WOK; ls -1 | grep "$query"
1563 footer ;;
1565 setup)
1566 # Setup a build environment
1567 check_root
1568 _ 'Cook: setup environment' | log
1569 title 'Setting up your environment'
1570 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1571 cd $SLITAZ
1572 init_db_files
1573 _ 'Checking for packages to install...'
1574 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1575 # ARCH-setup or 'cross check' should be used before: cook setup
1576 case "$ARCH" in
1577 arm*|x86_64)
1578 if [ ! -x '/usr/bin/cross' ]; then
1579 _ 'ERROR: %s is not installed' 'cross'
1580 exit 1
1581 fi
1582 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1583 . /etc/slitaz/cross.conf ;;
1584 esac
1585 for pkg in $SETUP_PKGS; do
1586 if [ -n "$forced" ]; then
1587 tazpkg -gi $pkg --forced
1588 else
1589 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1590 fi
1591 done
1593 # Handle --options
1594 case "$2" in
1595 --wok) hg clone $WOK_URL wok || exit 1 ;;
1596 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1597 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1598 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1599 esac
1601 # SliTaz group and permissions
1602 if ! grep -q ^slitaz /etc/group; then
1603 _ 'Adding group "%s"' 'slitaz'
1604 addgroup slitaz
1605 fi
1606 _ 'Setting permissions for group "%s"...' 'slitaz'
1607 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1608 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1609 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1611 *-setup)
1612 # Setup for cross compiling.
1613 arch="${1%-setup}"
1614 check_root
1615 . /etc/slitaz/cook.conf
1616 for pkg in $CROSS_SETUP; do
1617 if [ -n "$forced" ]; then
1618 tazpkg -gi $pkg --forced
1619 else
1620 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1621 fi
1622 done
1624 _ 'Cook: setup %s cross environment' "$arch" | log
1625 title 'Setting up your %s cross environment' "$arch"
1626 init_db_files
1627 sed -i \
1628 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1629 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1630 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1631 /etc/slitaz/cook.conf
1632 case "$arch" in
1633 arm)
1634 flags='-O2 -march=armv6'
1635 host="$ARCH-slitaz-linux-gnueabi" ;;
1636 armv6hf)
1637 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1638 host="$ARCH-slitaz-linux-gnueabi" ;;
1639 armv7)
1640 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1641 host="$ARCH-slitaz-linux-gnueabi" ;;
1642 x86_64)
1643 flags='-O2 -mtune=generic -pipe'
1644 host="$ARCH-slitaz-linux" ;;
1645 esac
1646 sed -i \
1647 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1648 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1649 . /etc/slitaz/cook.conf
1650 sysroot="$CROSS_TREE/sysroot"
1651 tools="/cross/$arch/tools"
1652 root="$sysroot"
1653 # L10n: keep the same width of translations to get a consistent view
1654 _ 'Target arch : %s' "$ARCH"
1655 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1656 _ 'Build flags : %s' "$flags"
1657 _ 'Arch sysroot : %s' "$sysroot"
1658 _ 'Tools prefix : %s' "$tools/bin"
1659 # Tell the packages manager where to find packages.
1660 _ 'Packages DB : %s' "$root$DB"
1661 mkdir -p $root$INSTALLED
1662 cd $root$DB; rm -f *.bak
1663 for list in packages.list packages.desc packages.equiv packages.md5; do
1664 rm -f $list
1665 ln -s $SLITAZ/packages/$list $list
1666 done
1667 # We must have the cross compiled glibc-base installed or default
1668 # i486 package will be used as dep by tazpkg and then break the
1669 # cross environment
1670 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1671 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1672 fi
1673 # Show GCC version or warn if not yet compiled.
1674 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1675 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1676 else
1677 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1678 _ 'Run "%s" to cook a toolchain' 'cross compile'
1679 fi
1680 footer ;;
1682 test)
1683 # Test a cook environment.
1684 _ 'Cook test: testing the cook environment' | log
1685 [ ! -d "$WOK" ] && exit 1
1686 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1687 cook cooktest ;;
1689 new)
1690 # Create the package folder and an empty receipt.
1691 pkg="$2"
1692 [ -z "$pkg" ] && usage
1693 newline
1694 if [ -d "$WOK/$pkg" ]; then
1695 _ 'Package "%s" already exists.' "$pkg"
1696 exit 1
1697 fi
1699 action 'Creating folder "%s"' "$WOK/$pkg"
1700 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1702 action 'Preparing the package receipt...'
1703 cp $DATA/receipt .
1704 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1705 status; newline
1707 # Interactive mode, asking and seding.
1708 case "$3" in
1709 --interactive|-x)
1710 _ 'Entering interactive mode...'
1711 separator
1712 _ 'Package : %s' "$pkg"
1714 _n 'Version : ' ; read answer
1715 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1717 _n 'Category : ' ; read answer
1718 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1720 # L10n: Short description
1721 _n 'Short desc : ' ; read answer
1722 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1724 _n 'Maintainer : ' ; read answer
1725 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1727 _n 'License : ' ; read answer
1728 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1730 _n 'Web site : ' ; read answer
1731 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1732 newline
1734 # Wget URL.
1735 _ 'Wget URL to download source tarball.'
1736 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1737 _n 'Wget url : ' ; read answer
1738 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1740 # Ask for a stuff dir.
1741 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1742 if [ "$?" -eq 0 ]; then
1743 action 'Creating the stuff directory...'
1744 mkdir $WOK/$pkg/stuff; status
1745 fi
1747 # Ask for a description file.
1748 confirm "$(_n 'Are you going to write a description? (y/N)')"
1749 if [ "$?" -eq 0 ]; then
1750 action 'Creating the "%s" file...' 'description.txt'
1751 touch $WOK/$pkg/description.txt; status
1752 fi
1754 footer "$(_ 'Receipt is ready to use.')" ;;
1755 esac ;;
1757 list)
1758 # Cook a list of packages (better use the Cooker since it will order
1759 # packages before executing cook).
1760 check_root
1761 if [ -z "$2" ]; then
1762 newline; _ 'No list in argument.'; newline
1763 exit 1
1764 fi
1765 if [ ! -f "$2" ]; then
1766 newline; _ 'List "%s" not found.' "$2"; newline
1767 exit 1
1768 fi
1770 _ 'Starting cooking the list "%s"' "$2" | log
1772 for pkg in $(cat $2); do
1773 cook $pkg || broken
1774 done ;;
1776 clean-wok)
1777 check_root
1778 newline; action 'Cleaning all packages files...'
1779 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1780 status; newline ;;
1782 clean-src)
1783 check_root
1784 newline; action 'Cleaning all packages sources...'
1785 rm -rf $WOK/*/source
1786 status; newline ;;
1788 uncook)
1789 cd $WOK
1790 count=0
1791 title 'Checking for uncooked packages'
1793 for pkg in *; do
1794 unset HOST_ARCH EXTRAVERSION
1795 [ ! -e $pkg/receipt ] && continue
1796 . $pkg/receipt
1797 # Source cooked pkg receipt to get EXTRAVERSION
1798 if [ -d "$WOK/$pkg/taz" ]; then
1799 cd $WOK/$pkg/taz/$pkg-*
1800 . receipt; cd $WOK
1801 fi
1802 case "$ARCH" in
1803 i486)
1804 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1805 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1806 count=$(($count + 1))
1807 colorize 34 "$pkg"
1808 fi ;;
1809 arm*)
1810 # Check only packages included in arch
1811 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1812 # *.tazpkg
1813 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1814 count=$(($count + 1))
1815 colorize 34 "$pkg"
1816 fi
1817 fi ;;
1818 esac
1819 done
1821 if [ "$count" -gt "0" ]; then
1822 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1823 else
1824 _ 'All packages are cooked :-)'
1825 newline
1826 fi
1827 ;;
1829 pkgdb)
1830 # Create suitable packages list for TazPKG and only for built packages
1831 # as well as flavors files for TazLiTo. We dont need logs since we do it
1832 # manually to ensure everything is fine before syncing the mirror.
1834 rm $LOGS/pkgdb.log 2>/dev/null
1836 case "$2" in
1837 --flavors|--rmpkg) ;;
1838 *)
1839 [ -n "$2" ] && PKGS="$2"
1840 if [ ! -d "$PKGS" ]; then
1841 { newline; _ "Packages directory \"%s\" doesn't exist" "$PKGS"; newline; } | dblog
1842 exit 1
1843 fi ;;
1844 esac
1846 time=$(date +%s)
1847 flavors="$SLITAZ/flavors"
1848 live="$SLITAZ/live"
1850 echo 'cook:pkgdb' > $command
1851 _ 'Cook pkgdb: Creating all packages lists' | log
1852 newline; { _ 'Creating lists for "%s"' "$PKGS"; separator; } | dblog
1854 { _ 'Cook pkgdb started: %s' "$(date "$(_ '+%%F %%R')")"; newline; } | dblog
1856 cd $PKGS
1857 rm -f packages.* extra.list
1858 touch packages.equiv
1860 _n 'Creating file "%s"' 'packages.list' | dblog
1861 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1862 echo " ($(filesize $PKGS/packages.list))" | dblog
1864 _n 'Creating file "%s"' 'packages.md5' | dblog
1865 md5sum *.tazpkg > $PKGS/packages.md5
1866 echo " ($(filesize $PKGS/packages.md5))" | dblog
1867 cp $PKGS/packages.md5 $PKGS/packages.toremove # list of duplicates
1869 md5sum packages.md5 | cut -d' ' -f1 > ID
1870 ( cat ./ID | tr $'\n' ' '; date -ur ./ID +%s ) > IDs # md5 and timestamp
1872 _n 'Creating file "%s"' 'descriptions.txt' | dblog
1873 rm $PKGS/descriptions.txt 2>/dev/null
1874 for i in $(ls $WOK | sort); do
1875 if [ -e "$WOK/$i/description.txt" ]; then
1876 echo "$i" >> descriptions.txt
1877 cat "$WOK/$i/description.txt" | sed 's|^$| |' >> descriptions.txt
1878 echo >> descriptions.txt
1879 fi
1880 done
1881 echo " ($(filesize $PKGS/descriptions.txt))" | dblog
1884 _ 'Creating lists from "%s"' "$WOK" | dblog
1885 cd $WOK
1886 for pkg in *; do
1887 unset_receipt
1888 . $pkg/receipt
1889 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1890 [ -s $pkg/taz/*/receipt ] && . $pkg/taz/*/receipt
1892 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ] || \
1893 [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1895 # packages.desc lets us search easily in DB
1896 cat >> $PKGS/packages.desc <<EOT
1897 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1898 EOT
1900 # packages.txt used by tazpkg and tazpkg-web also to provide
1901 # a human readable package list with version and description.
1902 cat >> $PKGS/packages.txt <<EOT
1903 $PACKAGE
1904 $VERSION$EXTRAVERSION
1905 $SHORT_DESC
1906 $PACKED_SIZE ($UNPACKED_SIZE installed)
1908 EOT
1910 # packages.info combines TazPkg separate files
1911 # and will substitute them all
1912 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1913 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
1914 MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" $PKGS/packages.md5 | awk '{print $1}')"
1915 cat >> $PKGS/packages.info <<EOT
1916 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5
1917 EOT
1919 # packages.equiv is used by tazpkg install to check depends.
1920 for i in $PROVIDE; do
1921 DEST=''
1922 echo $i | fgrep -q : && DEST="${i#*:}:"
1923 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1924 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1925 $PKGS/packages.equiv
1926 else
1927 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1928 fi
1929 done
1931 # files.list provides a list of all packages files.
1932 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1933 $PKGS/files.list
1935 # list of duplicates
1936 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg/d" $PKGS/packages.toremove
1937 else
1938 # if receipt variable HOST_ARCH absent/empty or contains ARCH
1939 if [ -z "$HOST_ARCH" -o "${HOST_ARCH/$ARCH/}" != "$HOST_ARCH" ]; then
1940 _ ' - absent: %s (%s)' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$ARCH" | dblog
1941 fi
1942 fi
1943 done
1945 # Display list size.
1946 _ 'Done: %s (%s)' 'packages.desc' "$(filesize $PKGS/packages.desc)" | dblog
1947 _ 'Done: %s (%s)' 'packages.txt' "$(filesize $PKGS/packages.txt)" | dblog
1948 _ 'Done: %s (%s)' 'packages.info' "$(filesize $PKGS/packages.info)" | dblog
1949 _ 'Done: %s (%s)' 'packages.equiv' "$(filesize $PKGS/packages.equiv)" | dblog
1951 cd $PKGS
1954 # Check package duplicates
1955 if [ -s "$PKGS/packages.toremove" ]; then
1956 newline | dblog
1957 _ 'Removing duplicates:' | dblog
1958 while read pkgsum pkgfile; do
1959 echo " - $pkgfile" | dblog
1960 sed -i "/${pkgfile%.tazpkg}/d" $PKGS/packages.list
1961 sed -i "/ $pkgfile/d" $PKGS/packages.md5
1962 [ -n "$rmpkg" ] && rm $PKGS/$pkgfile # remove packages only with --rmpkg
1963 done < $PKGS/packages.toremove
1964 newline | dblog
1965 fi
1966 rm $PKGS/packages.toremove
1969 # files.list.lzma
1970 _n 'Creating file "%s"' 'files.list.lzma' | dblog
1971 touch files.list
1972 # pkgs.slitaz.org strongly depends on list sorted by packages names
1973 lzma e files.list files.list.lzma
1974 echo " ($(filesize $PKGS/files.list.lzma))" | dblog
1976 # Pre-sorting filenames causes 10% smaller resulting lzma file
1977 _n 'Creating file "%s"' 'files-list.lzma' | dblog
1978 cat files.list | sort -k2 -o files.list.sorted
1979 lzma e files.list.sorted files-list.lzma
1980 rm -f files.list files.list.sorted
1981 echo " ($(filesize $PKGS/files-list.lzma))" | dblog
1983 [ -e files.list.md5 ] && rm files.list.md5
1984 md5sum files-list.lzma | cut -d' ' -f1 | tr -d $'\n' > files-list.md5
1986 # packages.info.lzma
1987 PI=packages.info
1988 _n 'Creating file "%s"' 'packages.info.lzma' | dblog
1989 touch $PI
1990 lzma e $PI $PI.lzma
1991 echo " ($(filesize $PKGS/packages.info.lzma))" | dblog
1993 # Make bundle to fast recharge
1994 _n 'Creating file "%s"' 'bundle.tar.lzma' | dblog
1995 [ -f bundle.tar.lzma ] && rm bundle.tar.lzma
1996 # Make sure to get "mirrors" file
1997 until [ -e 'mirrors' ]; do
1998 wget -q http://mirror1.slitaz.org/mirrors
1999 echo -n '.' | dblog; sleep 5
2000 done
2001 # Make sure to get "extra.list" file
2002 until [ -e 'extra.list' ]; do
2003 wget -q -O extra.list http://mirror1.slitaz.org/packages/get.list
2004 echo -n '.' | dblog; sleep 5
2005 done
2006 busybox tar -chaf bundle.tar.lzma \
2007 mirrors extra.list files-list.md5 packages.info descriptions.txt \
2008 packages.desc packages.md5 packages.txt packages.list packages.equiv
2009 rm ./mirrors
2010 echo " ($(filesize $PKGS/bundle.tar.lzma))" | dblog
2012 # Display some info.
2013 separator | dblog
2014 nb=$(ls $PKGS/*.tazpkg | wc -l)
2015 time=$(($(date +%s) - $time))
2016 # L10n: 's' is for seconds (cooking time)
2017 { _ 'Packages: %s - Time: %ss' "$nb" "$time"; newline; } | dblog
2020 # Create all flavors files at once. Do we really need code to monitor
2021 # flavors changes? Lets just build them with packages lists before
2022 # syncing the mirror.
2023 [ "$2" != '--flavors' ] && exit 1
2025 if [ ! -d "$flavors" ]; then
2026 { _ 'Missing flavors folder "%s"' "$flavors"; newline; } | dblog
2027 exit 1
2028 fi
2030 [ ! -d "$live" ] && mkdir -p $live
2031 _ 'Creating flavors files in "%s"' "$live" | dblog
2032 _ 'Cook pkgdb: Creating all flavors' | log
2033 separator | dblog
2035 _ 'Recharging lists to use latest packages...' | dblog
2036 tazpkg recharge >/dev/null 2>/dev/null
2038 # We need a custom tazlito config to set working dir to /home/slitaz.
2039 if [ ! -f "$live/tazlito.conf" ]; then
2040 _ 'Creating configuration file "%s"' 'tazlito.conf' | dblog
2041 cp /etc/tazlito/tazlito.conf $live
2042 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
2043 $live/tazlito.conf
2044 fi
2046 # Update Hg flavors repo and pack.
2047 if [ -d "$flavors/.hg" ]; then
2048 cd $flavors; hg pull -u
2049 fi
2051 cd $live
2052 _ 'Starting to generate flavors...' | dblog
2053 rm -f flavors.list *.flavor
2054 for i in $flavors/*; do
2055 fl=$(basename $i)
2056 _ 'Packing flavor "%s"' "$fl" | dblog
2057 tazlito pack-flavor $fl >/dev/null || exit 1
2058 tazlito show-flavor $fl --brief --noheader 2>/dev/null >> flavors.list
2059 done
2060 cp -f $live/*.flavor $live/flavors.list $PKGS
2061 separator | dblog
2062 { _ 'Total flavors size: %s' "$(du -sh $live | awk '{print $1}')"; newline; } | dblog
2063 rm -f $command
2064 separator | dblog
2065 _ 'Cook pkgdb end: %s' "$(date "$(_ '+%%F %%R')")" | dblog
2066 ;;
2068 *)
2069 # Just cook and generate a package.
2070 check_root
2071 time=$(date +%s)
2072 pkg="$1"
2073 [ -z "$pkg" ] && usage
2074 lastcooktime=$(sed '/^Cook time/!d;s|.*: *\([0-9]*\)s.*|\1|' \
2075 $LOGS/$pkg.log 2> /dev/null | sed '$!d')
2076 receipt="$WOK/$pkg/receipt"
2077 check_pkg_in_wok
2078 newline
2080 unset inst
2081 unset_receipt
2082 . $receipt
2084 # Handle cross compilation.
2085 case "$ARCH" in
2086 arm*)
2087 if [ -z "$HOST_ARCH" ]; then
2088 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
2089 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
2090 _ 'cook: %s' "$error"
2091 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
2092 _ 'Cook skip: %s' "$error" | log
2093 newline
2094 exit 1
2095 fi ;;
2096 esac
2098 # Some packages are not included in some arch or fail to cross compile.
2099 : ${HOST_ARCH=i486}
2100 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
2101 # Handle arm{v6hf,v7,..}
2102 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
2103 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
2104 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
2105 _ 'cook: %s' "error"
2106 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
2107 _ 'Cook skip: %s' "$error" | log
2108 sed -i /^${pkg}$/d $broken
2109 newline
2110 exit 0
2111 fi
2113 # Skip blocked, 3 lines also for the Cooker.
2114 if grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ]; then
2115 _ 'Package "%s" is blocked' "$pkg"; newline
2116 exit 0
2117 fi
2119 try_aufs_chroot "$@"
2121 # Log and source receipt.
2122 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
2123 echo "cook:$pkg" > $command
2124 [ "$lastcooktime" ] &&
2125 echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
2126 while read cmd duration start; do
2127 [ $(($start + $duration)) -lt $(date +%s) ] &&
2128 echo "sed -i '/^$cmd $duration/d' $cooktime"
2129 done < $cooktime | sh
2131 # Display and log info if cook process stopped.
2132 # FIXME: gettext not working (in single quotes) here!
2133 trap '_ "\n\nCook stopped: control-C\n\n" | \
2134 tee -a $LOGS/$pkg.log' INT
2136 # Handle --options
2137 case "$2" in
2138 --clean|-c)
2139 action 'Cleaning "%s"' "$pkg"
2140 cd $WOK/$pkg; rm -rf install taz source
2141 status; newline
2142 exit 0 ;;
2144 --install|-i)
2145 inst='yes' ;;
2147 --getsrc|-gs)
2148 title 'Getting source for "%s"' "$pkg"
2149 get_source
2150 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
2151 exit 0 ;;
2153 --block|-b)
2154 action 'Blocking package "%s"' "$pkg"
2155 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
2156 status; newline
2157 exit 0 ;;
2159 --unblock|-ub)
2160 action 'Unblocking package "%s"' "$pkg"
2161 sed -i "/^${pkg}$/"d $blocked
2162 status; newline
2163 exit 0 ;;
2165 --pack)
2166 if [ -d $WOK/$pkg/taz ]; then
2167 rm -rf $WOK/$pkg/taz
2168 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
2169 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
2170 clean_log
2171 else
2172 _ 'Need to build "%s"' "$pkg"
2173 exit 0
2174 fi
2175 exit 0 ;;
2177 --cdeps)
2178 if [ ! -d $WOK/$pkg/taz ]; then
2179 _ 'Need to build "%s"' "$pkg"
2180 exit 0
2181 fi
2183 title 'Checking depends'
2184 lddlist='/tmp/lddlist'; touch $lddlist
2185 missing='/var/cache/missing.file'
2187 # find all deps using ldd
2188 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
2189 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
2190 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
2191 done #"
2193 # remove exe/so duplicates
2194 sort -u $lddlist > $lddlist.sorted
2196 # search packages
2197 for exefile in $(cat $lddlist.sorted); do
2198 search_file $exefile
2199 echo "$found" >> $lddlist.pkgs
2200 echo -n '.'
2201 done
2202 echo
2204 # remove packages duplicates
2205 sort -u $lddlist.pkgs > $lddlist.final
2206 sort -u $missing > $missing.final
2207 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
2208 exit 0 ;;
2209 esac
2211 # Rotate log
2212 for i in $(seq 9 -1 1); do
2213 j=$(($i - 1))
2214 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
2215 done
2216 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
2218 # Check if wanted is built now so we have separate log files.
2219 for wanted in $WANTED ; do
2220 if grep -q "^$wanted$" $blocked; then
2221 _ 'WANTED package "%s" is blocked' "$wanted" | tee $LOGS/$pkg.log
2222 newline
2223 rm -f $command
2224 exit 1
2225 fi
2226 if grep -q "^$wanted$" $broken; then
2227 _ 'WANTED package "%s" is broken' "$wanted" | tee $LOGS/$pkg.log
2228 newline
2229 rm -f $command
2230 exit 1
2231 fi
2232 if [ ! -d "$WOK/$wanted/install" ]; then
2233 cook "$wanted" || exit 1
2234 fi
2235 done
2237 # Cook and pack or exit on error and log everything.
2238 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
2239 remove_deps | tee -a $LOGS/$pkg.log
2240 cookit_quality
2241 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
2242 clean_log
2244 # Exit if any error in packing.
2245 lerror=$(_n 'ERROR')
2246 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
2247 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
2248 debug_info | tee -a $LOGS/$pkg.log
2249 rm -f $command
2250 exit 1
2251 fi
2253 # Create an XML feed
2254 gen_rss
2256 # Time and summary
2257 time=$(($(date +%s) - $time))
2258 summary | tee -a $LOGS/$pkg.log
2259 newline
2261 # We may want to install/update (outside aufs jail !).
2262 [ -s /aufs-umount.sh ] ||
2263 install_package
2265 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2266 # You want automation: use the Cooker Build Bot.
2267 rm -f $command ;;
2268 esac
2270 exit 0