cookutils view cook @ rev 832

cook: add cook_compress_svg()
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Nov 04 12:58:55 2016 +0200 (2016-11-04)
parents 2af6b8cb0c48
children cf394b12c320
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 cooked package summary.
354 summary() {
355 cd $WOK/$pkg
356 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
357 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
358 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
359 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
360 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
361 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
363 sec="$time"
364 div=$(( ($time + 30) / 60))
365 case $div in
366 0) min='';;
367 # L10n: 'm' is for minutes (approximate cooking time)
368 *) min=$(_n '~ %dm' "$div");;
369 esac
371 _ 'Summary for: %s' "$PACKAGE $VERSION"
372 separator
374 # L10n: keep the same width of translations to get a consistent view
375 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
376 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
377 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
378 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
379 _ 'Packed : %s' "$fs"
380 _ 'Compressed : %s' "$size"
381 _ 'Files : %s' "$files"
382 # L10n: 's' is for seconds (cooking time)
383 _ 'Cook time : %ds %s' "$sec" "$min"
384 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
385 _ 'Host arch : %s' "$ARCH"
386 separator
387 }
390 # Display debugging error info.
392 debug_info() {
393 title 'Debug information'
394 # L10n: specify your format of date and time (to help: man date)
395 # L10n: not bad one is '+%x %R'
396 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
397 [ "$time" ] && _ 'Cook time: %ds' "$(($(date +%s) - $time))"
398 # L10n: Please, translate all messages beginning with ERROR in a same way
399 lerror=$(_n 'ERROR')
400 for error in \
401 ERROR $lerror 'No package' "cp: can't" "can't open" "can't cd" \
402 'error:' 'fatal error:' 'undefined reference to' \
403 'Unable to connect to' 'link: cannot find the library' \
404 'CMake Error' ': No such file or directory' \
405 'Could not read symbols: File in wrong format'
406 do
407 fgrep "$error" $LOGS/$pkg.log
408 done > $LOGS/$pkg.log.debug_info 2>&1
409 cat $LOGS/$pkg.log.debug_info
410 rm -f $LOGS/$pkg.log.debug_info
411 footer
412 }
415 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
416 # so some packages need to copy these files with the receipt and genpkg_rules.
418 copy_generic_files() {
419 # $LOCALE is set in cook.conf
420 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
421 if [ -d "$install/usr/share/locale" ]; then
422 mkdir -p $fs/usr/share/locale
423 for i in $LOCALE; do
424 if [ -d "$install/usr/share/locale/$i" ]; then
425 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
426 fi
427 done
428 fi
429 fi
431 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
432 if [ "$GENERIC_PIXMAPS" != 'no' ]; then
433 if [ -d "$install/usr/share/pixmaps" ]; then
434 mkdir -p $fs/usr/share/pixmaps
435 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
436 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
437 $fs/usr/share/pixmaps
438 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
439 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
440 $fs/usr/share/pixmaps
441 fi
442 fi
444 # Custom or homemade PNG pixmap can be in stuff.
445 if [ -f "$stuff/$PACKAGE.png" ]; then
446 mkdir -p $fs/usr/share/pixmaps
447 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
448 fi
449 fi
451 # Desktop entry (.desktop).
452 # Generic desktop entry copy can be disabled with GENERIC_MENUS="no"
453 if [ "$GENERIC_MENUS" != 'no' ]; then
454 if [ -d "$install/usr/share/applications" ] && [ -z "$WANTED" ]; then
455 mkdir -p $fs/usr/share
456 cp -a $install/usr/share/applications $fs/usr/share
457 fi
458 fi
460 # Homemade desktop file(s) can be in stuff.
461 if [ -d "$stuff/applications" ]; then
462 mkdir -p $fs/usr/share
463 cp -a $stuff/applications $fs/usr/share
464 fi
465 if [ -f "$stuff/$PACKAGE.desktop" ]; then
466 mkdir -p $fs/usr/share/applications
467 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
468 fi
470 # Add custom licenses
471 if [ -d "$stuff/licenses" ]; then
472 mkdir -p $fs/usr/share/licenses
473 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
474 fi
475 }
478 # Fix common errors and warnings in the .desktop files
480 fix_desktop_files() {
481 [ -d "$install/usr/share/applications" ] || return
483 if [ -n "$QA" -a -z "$(which desktop-file-validate)" ]; then
484 action 'Installing dep (web/cache): %s' 'desktop-file-utils-extra'
485 tazpkg -gi desktop-file-utils-extra --quiet
486 status
487 fi
489 for desktop in $(find $install/usr/share/applications -name '*.desktop'); do
490 cp "$desktop" "$desktop.orig"
492 # Sort out .desktop file (is prerequisite to correct working of `fix-desktop-file`)
493 sdft "$desktop" -i
495 # Fix common errors in .desktop file
496 fix-desktop-file "$desktop"
498 if [ -n "$QA" ]; then
499 # Check the rest of errors, warnings and tips
500 _ 'QA: Checking %s...' "$(basename $desktop)"
501 diff "$desktop.orig" "$desktop"
502 desktop-file-validate "$desktop" | busybox fold -s
503 echo
504 fi
506 rm "$desktop.orig"
507 done
508 }
511 # Find and strip: --strip-all (-s) or --strip-debug on static libs as well
512 # as removing unneeded files like in Python packages. Cross compiled binaries
513 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
515 strip_package() {
516 case "$ARCH" in
517 arm*|x86_64) export STRIP="$HOST_SYSTEM-strip" ;;
518 *) export STRIP='strip' ;;
519 esac
520 action 'Executing strip on all files...'
521 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games; do
522 if [ -d "$dir" ]; then
523 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
524 fi
525 done
526 find $fs -name '*.so*' -exec $STRIP -s '{}' 2>/dev/null \;
527 find $fs -name '*.a' -exec $STRIP --strip-debug '{}' 2>/dev/null \;
528 status
530 # Remove Python .pyc and .pyo from packages.
531 find $fs -type f \( -name '*.pyc' -o -name '*.pyo' \) -delete 2>/dev/null
533 # Remove Perl perllocal.pod and .packlist from packages.
534 find $fs -type f \( -name 'perllocal.pod' -o -name '.packlist' \) -delete 2>/dev/null
535 }
538 # Update installed.cook.diff
540 update_installed_cook_diff() {
541 # If a cook failed deps are removed.
542 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
543 cd $CACHE
544 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
545 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
546 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
547 }
550 # Remove installed deps.
552 remove_deps() {
553 # Now remove installed build deps.
554 diff='/tmp/installed.cook.diff'
555 if [ -s $diff ]; then
556 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
557 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
558 _n 'Build dependencies to remove:'; echo " $nb"
559 [ -n "$root" ] && echo "root=\"$root\""
560 _n 'Removing:'
561 for dep in $deps; do
562 echo -n " $dep"
563 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
564 done
565 newline; newline
566 # Keep the last diff for debug and info.
567 mv -f $diff $CACHE/installed.diff
568 fi
569 }
571 # Function to compress all man pages
573 compress_manpages() {
574 case "$ARCH" in
575 arm*) return;; # While SliTaz-arm miss `advancecomp`
576 esac
577 # Don't compress man pages for splitted packages
578 [ -n "$WANTED" ] && return
579 local manpath="$install/usr/share/man" dest link
580 [ -d "$manpath" ] || return
582 action 'Compressing man pages...'
584 # We'll use only Gzip compression, so decompress other formats first
585 find $manpath -type f -name '*.bz2' -exec bunzip2 \{\} \;
586 find $manpath -type f -name '*.xz' -exec unxz \{\} \;
588 # Fast compress with gzip
589 find $manpath -type f -name '*.[1-9]' -exec gzip \{\} \;
591 # Fix symlinks
592 for i in $(find $install/usr/share/man -type l); do
593 dest=$(readlink $i | sed 's|\.[gbx]z2*$||')
594 link=$(echo $i | sed 's|\.[gbx]z2*$||')
595 rm $i; ln -s $dest.gz $link.gz
596 done
598 # Recompress with advdef (it can't compress, only recompress)
599 tazpkg -gi advancecomp --quiet
600 for i in $(find $install/usr/share/man -type f); do
601 advdef -z4q $i
602 done
604 status
605 }
608 # The main cook function.
610 cookit() {
611 title 'Cook: %s' "$PACKAGE $VERSION"
612 set_paths
614 # Handle cross-tools.
615 case "$ARCH" in
616 arm*|x86_64)
617 # CROSS_COMPILE is used by at least Busybox and the kernel to set
618 # the cross-tools prefix. Sysroot is the root of our target arch
619 sysroot="$CROSS_TREE/sysroot"
620 tools="$CROSS_TREE/tools"
621 # Set root path when cross compiling. ARM tested but not x86_64
622 # When cross compiling we must install build deps in $sysroot.
623 arch="-$ARCH"
624 root="$sysroot"
625 _ '%s sysroot: %s' "$ARCH" "$sysroot"
626 _ 'Adding "%s" to PATH' "$tools/bin"
627 export PATH="$PATH:$tools/bin"
628 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
629 export CROSS_COMPILE="$HOST_SYSTEM-"
630 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
631 if [ "$ARCH" == 'x86_64' ]; then
632 export CC="$HOST_SYSTEM-gcc -m64"
633 export CXX="$HOST_SYSTEM-g++ -m64"
634 else
635 export CC="$HOST_SYSTEM-gcc"
636 export CXX="$HOST_SYSTEM-g++"
637 fi
638 export AR="$HOST_SYSTEM-ar"
639 export AS="$HOST_SYSTEM-as"
640 export RANLIB="$HOST_SYSTEM-ranlib"
641 export LD="$HOST_SYSTEM-ld"
642 export STRIP="$HOST_SYSTEM-strip"
643 export LIBTOOL="$HOST_SYSTEM-libtool" ;;
644 esac
646 [ -n "$QA" ] && receipt_quality
647 cd $pkgdir
648 [ -z "$continue" ] && rm -rf source 2>/dev/null
649 rm -rf install taz 2>/dev/null
651 # Disable -pipe if less than 512Mb free RAM.
652 free=$(free | awk '/buffers:/{print $4}')
653 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
654 _ 'Disabling -pipe compile flag: %d RAM free' "$free"
655 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
656 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
657 fi
658 unset free
660 # Export flags and path to be used by make and receipt.
661 DESTDIR="$pkgdir/install"
662 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
663 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
664 #LDFLAGS
666 # Check for build deps and handle implicit depends of *-dev packages
667 # (ex: libusb-dev :: libusb).
668 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
669 touch $CACHE/installed.local $CACHE/installed.web
670 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
671 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
672 for dep in $BUILD_DEPENDS; do
673 implicit="${dep%-dev}"
674 # Don't add implicit dependency if it defined in DEPENDS
675 # echo '' $DEPENDS '' | fgrep -q " $implicit " && implicit=''
676 for i in $dep $implicit; do
677 if [ ! -f "$root$INSTALLED/$i/receipt" ]; then
678 # Try local package first. In some cases implicit doesn't exist, ex:
679 # libboost-dev exists but not libboost, so check if we got vers.
680 unset vers
681 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
682 # We may have a local package.
683 if [ -z "$vers" ]; then
684 vers=$(awk -F$'\t' -vp="$i" '$1==p{print $2; quit}' $PKGS/packages.info 2> /dev/null)
685 fi
686 debug "bdep: $i version: $vers"
687 if [ -f "$PKGS/$i-$vers$arch.tazpkg" ]; then
688 echo $i-$vers$arch.tazpkg >> $CACHE/installed.local
689 else
690 # Priority to package version in wok (maybe more up-to-date)
691 # than the mirrored one.
692 if [ -n "$vers" ]; then
693 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
694 echo $i >> $CACHE/installed.web
695 else
696 # So package exists in wok but not available.
697 _ 'Missing dep (wok/pkg): %s' "$i $vers"
698 echo $i >> $CACHE/missing.dep
699 fi
700 else
701 # Package is not in wok but may be in online repo.
702 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
703 echo $i >> $CACHE/installed.web
704 else
705 _ 'ERROR: unknown dep "%s"' "$i"
706 exit 1
707 fi
708 fi
709 fi
710 fi
711 done
712 done
714 # Get the list of installed packages
715 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
717 # Have we a missing build dep to cook?
718 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
719 _ 'Auto cook config is set: %s' "$AUTO_COOK"
720 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
721 for i in $(uniq $CACHE/missing.dep); do
722 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
723 tee -a $LOGS/$PACKAGE.log.$$
724 # programmers: next two messages are exact copy from remove_deps()
725 togrep1=$(_n 'Build dependencies to remove:')
726 togrep2=$(_n 'Removing:')
727 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
728 fgrep $togrep1 $LOGS/$i.log && \
729 fgrep $togrep2 $LOGS/$i.log && newline) | \
730 tee -a $LOGS/$PACKAGE.log.$$ && break
731 done
732 rm -f $CACHE/missing.dep
733 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
734 fi
736 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
737 # is enabled and cook fails we have ERROR in log, if no auto cook we have
738 # missing dep in cached file.
739 lerror=$(_n 'ERROR')
740 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
741 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
742 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
743 exit 1
744 fi
746 # Install local packages: package-version$arch
747 cd $PKGS
748 for i in $(uniq $CACHE/installed.local); do
749 _ 'Installing dep (pkg/local): %s' "$i"
750 tazpkg install $i --root=$root --local --quiet
751 done
753 # Install web or cached packages (if mirror is set to $PKGS we only
754 # use local packages).
755 for i in $(uniq $CACHE/installed.web); do
756 _ 'Installing dep (web/cache): %s' "$i"
757 tazpkg get-install $i --root=$root --quiet
758 done
760 update_installed_cook_diff
762 # Get source tarball and make sure we have source dir named:
763 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
764 # tarball if it exists.
765 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
766 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
767 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
768 LZMA_SRC=''
769 else
770 get_source || exit 1
771 fi
772 fi
773 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
774 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
775 if ! extract_source ; then
776 get_source
777 extract_source || exit 1
778 fi
779 if [ -n "$LZMA_SRC" ]; then
780 cd $pkgdir/source
781 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
782 mv tmp tmp-1; mkdir tmp
783 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
784 fi
785 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
786 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
787 fi
788 fi
789 cd $pkgdir/source/tmp
790 # Some archives are not well done and don't extract to one dir (ex lzma).
791 files=$(ls | wc -l)
792 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
793 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
794 mv * ../$PACKAGE-$VERSION/$TARBALL
795 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
796 mv * ../$PACKAGE-$VERSION
797 cd ..; rm -rf tmp
798 fi
800 # Libtool shared libs path hack.
801 case "$ARCH" in
802 arm*) cross libhack ;;
803 esac
805 # Execute receipt rules.
806 if grep -q ^compile_rules $receipt; then
807 _ 'Executing: %s' 'compile_rules'
808 echo "CFLAGS : $CFLAGS"
809 #echo "LDFLAGS : $LDFLAGS"
810 [ -d "$src" ] && cd $src
811 compile_rules $@ || exit 1
812 # Stay compatible with _pkg
813 [ -d "$src/_pkg" ] && mv $src/_pkg $install
814 # QA: compile_rules success so valid.
815 mkdir -p $install
816 else
817 # QA: no compile_rules so no error, valid.
818 mkdir -p $install
819 fi
821 # Actions to do after compiling the package
822 compress_manpages
823 footer
825 # Execute testsuite.
826 if grep -q ^testsuite $receipt; then
827 title 'Running testsuite'
828 testsuite $@ || exit 1
829 footer
830 fi
832 fix_desktop_files
833 update_installed_cook_diff force
834 }
837 # Cook quality assurance.
839 cookit_quality() {
840 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
841 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
842 fi
843 # ERROR can be echoed any time in cookit()
844 lerror=$(_n 'ERROR')
845 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
846 grep -Eq "(^$lerror|undefined reference to)" ; then
847 debug_info | tee -a $LOGS/$pkg.log
848 rm -f $command
849 exit 1
850 fi
851 }
854 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
855 # but it doesn't handle EXTRAVERSION.
857 packit() {
858 set_paths
860 # Handle cross compilation
861 case "$ARCH" in
862 arm*|x86_64) arch="-$ARCH" ;;
863 esac
865 title 'Pack: %s' "$PACKAGE $VERSION$arch"
867 if grep -q ^genpkg_rules $receipt; then
868 _ 'Executing: %s' 'genpkg_rules'
869 set -e; cd $pkgdir; mkdir -p $fs
870 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
871 $LOGS/$pkg.log
872 else
873 _ 'No packages rules: meta package'
874 mkdir -p $fs
875 fi
877 # First QA check to stop now if genpkg_rules failed.
878 lerror=$(_n 'ERROR')
879 if fgrep -q ^$lerror $LOGS/$pkg.log; then
880 exit 1
881 fi
883 cd $taz
884 for file in receipt description.txt; do
885 [ ! -f "../$file" ] && continue
886 action 'Copying "%s"...' "$file"
887 cp -f ../$file $pack; chown 0.0 $pack/$file; status
888 done
889 copy_generic_files
891 # Strip and stuff files.
892 strip_package
894 # Create files.list with redirecting find output.
895 action 'Creating the list of files...'
896 cd $fs
897 find . -type f -print > ../files.list
898 find . -type l -print >> ../files.list
899 cd ..; sed -i s/'^.'/''/ files.list
900 status
902 # Md5sum of files.
903 action 'Creating md5sum of files...'
904 while read file; do
905 [ -L "fs$file" ] && continue
906 [ -f "fs$file" ] || continue
907 case "$file" in
908 /lib/modules/*/modules.*|*.pyc) continue ;;
909 esac
910 md5sum "fs$file" | sed 's/ fs/ /'
911 done < files.list > md5sum
912 status
914 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
915 2>/dev/null | awk 'END{ print $1 }')
917 # Build cpio archives.
918 action 'Compressing the FS...'
919 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
920 rm -rf fs
921 status
923 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
924 2>/dev/null | awk 'END{ print $1 }')
926 action 'Updating receipt sizes...'
927 sed -i s/^PACKED_SIZE.*$// receipt
928 sed -i s/^UNPACKED_SIZE.*$// receipt
929 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
930 status
932 # Set extra version.
933 if [ -n "$EXTRAVERSION" ]; then
934 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
935 sed -i s/^EXTRAVERSION.*$// receipt
936 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
937 status
938 fi
940 # Compress.
941 action 'Creating full cpio archive...'
942 find . -print | cpio -o -H newc --quiet > \
943 ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
944 status
946 action 'Restoring original package tree...'
947 unlzma -c fs.cpio.lzma | cpio -idm --quiet
948 status
950 rm fs.cpio.lzma; cd ..
952 # QA and give info.
953 tazpkg=$(ls *.tazpkg)
954 packit_quality
955 footer "$(_ 'Package "%s" created' "$tazpkg")"
956 }
959 # Verify package quality and consistency.
961 packit_quality() {
962 #action 'QA: checking for broken link...'
963 #link=$(find $fs/usr -type l -follow)
964 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
965 #status
967 # Exit if any error found in log file.
968 lerror=$(_n 'ERROR')
969 if fgrep -q ^$lerror $LOGS/$pkg.log; then
970 rm -f $command
971 exit 1
972 fi
974 action 'QA: checking for empty package...'
975 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
976 if [ "$files" -eq 0 -a "$CATEGORY" != 'meta' ]; then
977 newline; _ 'ERROR: empty package'
978 rm -f $command
979 exit 1
980 else
981 :; status
982 # Find and remove old package(s)
983 tempd="$(mktemp -d)"; cd "$tempd"
984 for testpkg in $(ls $PKGS/$pkg-*.tazpkg 2> /dev/null); do
985 # Extract receipt from each matched package
986 cpio -F "$testpkg" -i receipt >/dev/null 2>&1
987 name=$(. receipt; echo $PACKAGE)
988 rm receipt
989 if [ "$name" == "$pkg" ]; then
990 action 'Removing old package "%s"' "$(basename "$testpkg")"
991 rm -f "$testpkg"
992 status
993 fi
994 done
995 rm -r "$tempd"
996 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
997 sed -i /^${pkg}$/d $broken
998 #action 'Removing source tree...'
999 #rm -f $WOK/$pkg/source; status
1000 fi
1004 # Reverse "cat" command: prints input lines in the reverse order
1006 tac() {
1007 sed '1!G;h;$!d' $1
1011 # Install package on --install or update the chroot.
1013 install_package() {
1014 case "$ARCH" in
1015 arm*|x86_64)
1016 arch="-$ARCH"
1017 root="$CROSS_TREE/sysroot" ;;
1018 esac
1019 # Install package if requested but skip install if target host doesn't
1020 # match build system or it will break the build chroot.
1021 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1022 if [ -n "$inst" ] && [ "$build" == "$ARCH" ]; then
1023 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1024 cd $PKGS
1025 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
1026 else
1027 _ 'Unable to install package, build has failed.'; newline
1028 exit 1
1029 fi
1030 fi
1032 # Install package if part of the chroot to keep env up-to-date.
1033 if [ -d "$root$INSTALLED/$pkg" ]; then
1034 . /etc/slitaz/cook.conf
1035 . $WOK/$pkg/taz/$pkg-*/receipt
1036 _ 'Updating %s chroot environment...' "$ARCH"
1037 _ 'Updating chroot: %s' "$pkg ($VERSION$EXTRAVERSION$arch)" | log
1038 cd $PKGS
1039 tazpkg install $pkg-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1040 fi
1044 # remove chroot jail
1046 umount_aufs() {
1047 tac ${1}rw/aufs-umount.sh | sh
1048 rm -rf ${1}rw
1049 umount ${1}root
1050 rmdir ${1}r*
1054 # Launch the cook command into a chroot jail protected by aufs.
1055 # The current filesystems are used read-only and updates are
1056 # stored in a separate branch.
1058 try_aufs_chroot() {
1060 base="/dev/shm/aufsmnt$$"
1062 # Can we setup the chroot? Is it already done?
1063 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1064 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1065 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1066 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
1067 mkdir ${base}root ${base}rw || return
1069 _ 'Setup aufs chroot...'
1071 # Sanity check
1072 for i in / /proc /sys /dev/shm /home ; do
1073 case " $AUFS_MOUNTS " in
1074 *\ $i\ *) ;;
1075 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1076 esac
1077 done
1078 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1079 mount --bind $mnt ${base}root$mnt
1080 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1081 _ 'Aufs mount failure'
1082 umount ${base}root
1083 rm -rf ${base}r*
1084 return
1085 fi
1086 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1087 done
1088 trap "umount_aufs ${base}" INT
1090 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1091 status=$?
1093 _ 'Leaving aufs chroot...'
1094 umount_aufs $base
1095 # Install package outside the aufs jail
1096 install_package
1097 exit $status
1101 # Encode predefined XML entities
1103 xml_ent() {
1104 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1108 # Create a XML feed for freshly built packages.
1110 gen_rss() {
1111 pubdate=$(date '+%a, %d %b %Y %X')
1112 cat > $FEEDS/$pkg.xml <<EOT
1113 <item>
1114 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1115 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1116 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1117 <pubDate>$pubdate</pubDate>
1118 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1119 </item>
1120 EOT
1124 # Truncate stdout log file to $1 Mb.
1126 loglimit() {
1127 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1128 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1129 else
1130 tee /dev/stderr
1131 fi
1135 # Search file in mirrored packages
1137 search_file_mirror() {
1138 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
1142 # Search file in local wok packages
1144 search_file_local() {
1145 # existing packages have precedence over the package/taz folder
1146 srch=$1
1147 { for package in $(find $PKGS -name '*.tazpkg'); do
1148 if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
1149 grep /$srch\$)" ]; then
1150 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
1151 fi
1152 done } | sort -u
1156 # Ask in multiple choice
1158 ask_multiple() {
1159 local multiples first my_choice
1160 multiples="$1"
1161 first=$(echo "$multiples" | head -n1)
1162 newline; _ 'Multiple choice:'; echo "$multiples"; newline
1163 _ 'Select one [%s]: ' "$first"; read my_choice
1164 found="${my_choice:-$first}"
1168 # Search file in local cache (fast), local wok packages, mirrored packages
1170 search_file() {
1171 local srch cache missing
1172 srch="$1"
1173 cache='/var/cache/ldsearch.cache'
1174 missing='/var/cache/missing.file'
1175 touch $cache $missing
1176 found=$(grep $srch $cache | cut -d$'\t' -f2)
1177 if [ -z "$found" ]; then
1178 found=$(search_file_local $srch)
1179 if [ -n "$found" ]; then
1180 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1181 ask_multiple "$found"
1182 fi
1183 echo -e "$srch\t$found" >> $cache
1184 else
1185 found=$(search_file_mirror $srch)
1186 if [ -n "$found" ]; then
1187 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1188 ask_multiple "$found"
1189 fi
1190 echo -e "$srch\t$found" >> $cache
1191 else
1192 echo "$srch" >> $missing
1193 fi
1194 fi
1195 fi
1199 # Return size of file in human readible format
1200 # Note, "du" in opposite returns size occupied by file on disk (4KB multiple in most cases)
1201 filesize() {
1202 busybox ls -lh "$1" | awk '{print $5 "B"}'
1207 # Receipt functions to ease packaging
1210 get_dev_files() {
1211 action 'Getting standard devel files...'
1212 mkdir -p $fs/usr/lib
1213 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1214 cp -a $install/usr/lib/*a $fs/usr/lib
1215 cp -a $install/usr/include $fs/usr
1216 status
1220 # Function to use in compile_rules() to copy man page from $src to $install
1222 cook_pick_manpages() {
1223 local name section
1224 action 'Copying man pages...'
1226 for i in $@; do
1227 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1228 section=${name##*/}; section=${section##*.}
1229 mkdir -p $install/usr/share/man/man$section
1230 cp -a $i $install/usr/share/man/man$section
1231 done
1232 status
1236 # Function to use in compile_rules() to compress all png images
1238 cook_compress_png() {
1239 case "$ARCH" in
1240 arm*) return;; # While SliTaz-arm miss `pngquant` and `optipng`
1241 esac
1243 action 'Compressing png images...'
1244 local size0=$(find $install -type f -name '*.png' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
1245 tazpkg -gi pngquant --quiet
1246 tazpkg -gi optipng --quiet
1247 for i in $(find $install -type f -name '*.png'); do
1248 pngquant -f --skip-if-larger --ext .png --speed 1 "$i"
1249 optipng -quiet -strip all -o7 -zm1-9 "$i"
1250 done
1251 local size1=$(find $install -type f -name '*.png' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
1252 status
1253 echo " Size: $size0 B -> $size1 B"
1257 # Function to use in compile_rules() to compress all svg images
1259 cook_compress_svg() {
1260 case "$ARCH" in
1261 arm*) return;; # While SliTaz-arm miss `svgcleaner`
1262 esac
1264 action 'Compressing svg images...'
1265 local size0=$(find $install -type f -name '*.svg' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
1266 tazpkg -gi svgcleaner --quiet
1267 for i in $(find $install -type f -name '*.svg'); do
1268 svgcleaner "$i" "$i" --remove-unresolved-classes false
1269 done
1270 local size1=$(find $install -type f -name '*.svg' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
1271 status
1272 echo " Size: $size0 B -> $size1 B"
1276 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1278 cook_copy_files() {
1279 action 'Copying files...'
1280 cd $install
1281 local i j
1282 for i in $@; do
1283 for j in $(find . -name $i ! -type d); do
1284 mkdir -p $fs$(dirname ${j#.})
1285 cp -a $j $fs/${j#.}
1286 done
1287 done
1288 cd - >/dev/null
1289 status
1293 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1294 # (default: 16 and 48) from $install to $fs
1296 cook_copy_icons() {
1297 local sizes=$@
1298 action 'Copying hicolor icons...'
1299 mkdir -p $fs/usr/share/icons/hicolor
1300 for i in ${sizes:-16 48}; do
1301 [ -e "$install/usr/share/icons/hicolor/${i}x$i" ] &&
1302 cp -a $install/usr/share/icons/hicolor/${i}x$i \
1303 $fs/usr/share/icons/hicolor
1304 done
1305 status
1308 dblog() { tee -a $LOGS/pkgdb.log; }
1314 # Commands
1317 case "$1" in
1318 usage|help|-u|-h)
1319 usage ;;
1321 list-wok)
1322 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1323 cd $WOK
1324 if [ "$ARCH" != 'i486' ]; then
1325 count=0
1326 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1327 do
1328 unset HOST_ARCH
1329 . $pkg
1330 count=$(($count + 1))
1331 colorize 34 "$PACKAGE"
1332 done
1333 else
1334 count=$(ls | wc -l)
1335 ls -1
1336 fi
1337 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1338 ;;
1340 activity)
1341 cat $activity ;;
1343 search)
1344 # Just a simple search function, we dont need more actually.
1345 query="$2"
1346 title 'Search results for "%s"' "$query"
1347 cd $WOK; ls -1 | grep "$query"
1348 footer ;;
1350 setup)
1351 # Setup a build environment
1352 check_root
1353 _ 'Cook: setup environment' | log
1354 title 'Setting up your environment'
1355 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1356 cd $SLITAZ
1357 init_db_files
1358 _ 'Checking for packages to install...'
1359 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1360 # ARCH-setup or 'cross check' should be used before: cook setup
1361 case "$ARCH" in
1362 arm*|x86_64)
1363 if [ ! -x '/usr/bin/cross' ]; then
1364 _ 'ERROR: %s is not installed' 'cross'
1365 exit 1
1366 fi
1367 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1368 . /etc/slitaz/cross.conf ;;
1369 esac
1370 for pkg in $SETUP_PKGS; do
1371 if [ -n "$forced" ]; then
1372 tazpkg -gi $pkg --forced
1373 else
1374 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1375 fi
1376 done
1378 # Handle --options
1379 case "$2" in
1380 --wok) hg clone $WOK_URL wok || exit 1 ;;
1381 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1382 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1383 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1384 esac
1386 # SliTaz group and permissions
1387 if ! grep -q ^slitaz /etc/group; then
1388 _ 'Adding group "%s"' 'slitaz'
1389 addgroup slitaz
1390 fi
1391 _ 'Setting permissions for group "%s"...' 'slitaz'
1392 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1393 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1394 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1396 *-setup)
1397 # Setup for cross compiling.
1398 arch="${1%-setup}"
1399 check_root
1400 . /etc/slitaz/cook.conf
1401 for pkg in $CROSS_SETUP; do
1402 if [ -n "$forced" ]; then
1403 tazpkg -gi $pkg --forced
1404 else
1405 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1406 fi
1407 done
1409 _ 'Cook: setup %s cross environment' "$arch" | log
1410 title 'Setting up your %s cross environment' "$arch"
1411 init_db_files
1412 sed -i \
1413 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1414 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1415 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1416 /etc/slitaz/cook.conf
1417 case "$arch" in
1418 arm)
1419 flags='-O2 -march=armv6'
1420 host="$ARCH-slitaz-linux-gnueabi" ;;
1421 armv6hf)
1422 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1423 host="$ARCH-slitaz-linux-gnueabi" ;;
1424 armv7)
1425 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1426 host="$ARCH-slitaz-linux-gnueabi" ;;
1427 x86_64)
1428 flags='-O2 -mtune=generic -pipe'
1429 host="$ARCH-slitaz-linux" ;;
1430 esac
1431 sed -i \
1432 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1433 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1434 . /etc/slitaz/cook.conf
1435 sysroot="$CROSS_TREE/sysroot"
1436 tools="/cross/$arch/tools"
1437 root="$sysroot"
1438 # L10n: keep the same width of translations to get a consistent view
1439 _ 'Target arch : %s' "$ARCH"
1440 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1441 _ 'Build flags : %s' "$flags"
1442 _ 'Arch sysroot : %s' "$sysroot"
1443 _ 'Tools prefix : %s' "$tools/bin"
1444 # Tell the packages manager where to find packages.
1445 _ 'Packages DB : %s' "$root$DB"
1446 mkdir -p $root$INSTALLED
1447 cd $root$DB; rm -f *.bak
1448 for list in packages.list packages.desc packages.equiv packages.md5; do
1449 rm -f $list
1450 ln -s $SLITAZ/packages/$list $list
1451 done
1452 # We must have the cross compiled glibc-base installed or default
1453 # i486 package will be used as dep by tazpkg and then break the
1454 # cross environment
1455 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1456 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1457 fi
1458 # Show GCC version or warn if not yet compiled.
1459 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1460 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1461 else
1462 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1463 _ 'Run "%s" to cook a toolchain' 'cross compile'
1464 fi
1465 footer ;;
1467 test)
1468 # Test a cook environment.
1469 _ 'Cook test: testing the cook environment' | log
1470 [ ! -d "$WOK" ] && exit 1
1471 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1472 cook cooktest ;;
1474 new)
1475 # Create the package folder and an empty receipt.
1476 pkg="$2"
1477 [ -z "$pkg" ] && usage
1478 newline
1479 if [ -d "$WOK/$pkg" ]; then
1480 _ 'Package "%s" already exists.' "$pkg"
1481 exit 1
1482 fi
1484 action 'Creating folder "%s"' "$WOK/$pkg"
1485 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1487 action 'Preparing the package receipt...'
1488 cp $DATA/receipt .
1489 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1490 status; newline
1492 # Interactive mode, asking and seding.
1493 case "$3" in
1494 --interactive|-x)
1495 _ 'Entering interactive mode...'
1496 separator
1497 _ 'Package : %s' "$pkg"
1499 _n 'Version : ' ; read answer
1500 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1502 _n 'Category : ' ; read answer
1503 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1505 # L10n: Short description
1506 _n 'Short desc : ' ; read answer
1507 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1509 _n 'Maintainer : ' ; read answer
1510 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1512 _n 'License : ' ; read answer
1513 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1515 _n 'Web site : ' ; read answer
1516 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1517 newline
1519 # Wget URL.
1520 _ 'Wget URL to download source tarball.'
1521 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1522 _n 'Wget url : ' ; read answer
1523 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1525 # Ask for a stuff dir.
1526 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1527 if [ "$?" -eq 0 ]; then
1528 action 'Creating the stuff directory...'
1529 mkdir $WOK/$pkg/stuff; status
1530 fi
1532 # Ask for a description file.
1533 confirm "$(_n 'Are you going to write a description? (y/N)')"
1534 if [ "$?" -eq 0 ]; then
1535 action 'Creating the "%s" file...' 'description.txt'
1536 touch $WOK/$pkg/description.txt; status
1537 fi
1539 footer "$(_ 'Receipt is ready to use.')" ;;
1540 esac ;;
1542 list)
1543 # Cook a list of packages (better use the Cooker since it will order
1544 # packages before executing cook).
1545 check_root
1546 if [ -z "$2" ]; then
1547 newline; _ 'No list in argument.'; newline
1548 exit 1
1549 fi
1550 if [ ! -f "$2" ]; then
1551 newline; _ 'List "%s" not found.' "$2"; newline
1552 exit 1
1553 fi
1555 _ 'Starting cooking the list "%s"' "$2" | log
1557 for pkg in $(cat $2); do
1558 cook $pkg || broken
1559 done ;;
1561 clean-wok)
1562 check_root
1563 newline; action 'Cleaning all packages files...'
1564 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1565 status; newline ;;
1567 clean-src)
1568 check_root
1569 newline; action 'Cleaning all packages sources...'
1570 rm -rf $WOK/*/source
1571 status; newline ;;
1573 uncook)
1574 cd $WOK
1575 count=0
1576 title 'Checking for uncooked packages'
1578 for pkg in *; do
1579 unset HOST_ARCH EXTRAVERSION
1580 [ ! -e $pkg/receipt ] && continue
1581 . $pkg/receipt
1582 # Source cooked pkg receipt to get EXTRAVERSION
1583 if [ -d "$WOK/$pkg/taz" ]; then
1584 cd $WOK/$pkg/taz/$pkg-*
1585 . receipt; cd $WOK
1586 fi
1587 case "$ARCH" in
1588 i486)
1589 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1590 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1591 count=$(($count + 1))
1592 colorize 34 "$pkg"
1593 fi ;;
1594 arm*)
1595 # Check only packages included in arch
1596 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1597 # *.tazpkg
1598 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1599 count=$(($count + 1))
1600 colorize 34 "$pkg"
1601 fi
1602 fi ;;
1603 esac
1604 done
1606 if [ "$count" -gt "0" ]; then
1607 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1608 else
1609 _ 'All packages are cooked :-)'
1610 newline
1611 fi
1612 ;;
1614 pkgdb)
1615 # Create suitable packages list for TazPKG and only for built packages
1616 # as well as flavors files for TazLiTo. We dont need logs since we do it
1617 # manually to ensure everything is fine before syncing the mirror.
1619 rm $LOGS/pkgdb.log 2>/dev/null
1621 case "$2" in
1622 --flavors|--rmpkg) ;;
1623 *)
1624 [ -n "$2" ] && PKGS="$2"
1625 if [ ! -d "$PKGS" ]; then
1626 { newline; _ "Packages directory \"%s\" doesn't exist" "$PKGS"; newline; } | dblog
1627 exit 1
1628 fi ;;
1629 esac
1631 time=$(date +%s)
1632 flavors="$SLITAZ/flavors"
1633 live="$SLITAZ/live"
1635 echo 'cook:pkgdb' > $command
1636 _ 'Cook pkgdb: Creating all packages lists' | log
1637 newline; { _ 'Creating lists for "%s"' "$PKGS"; separator; } | dblog
1639 { _ 'Cook pkgdb started: %s' "$(date "$(_ '+%%F %%R')")"; newline; } | dblog
1641 cd $PKGS
1642 rm -f packages.* extra.list
1643 touch packages.equiv
1645 _n 'Creating file "%s"' 'packages.list' | dblog
1646 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1647 echo " ($(filesize $PKGS/packages.list))" | dblog
1649 _n 'Creating file "%s"' 'packages.md5' | dblog
1650 md5sum *.tazpkg > $PKGS/packages.md5
1651 echo " ($(filesize $PKGS/packages.md5))" | dblog
1652 cp $PKGS/packages.md5 $PKGS/packages.toremove # list of duplicates
1654 md5sum packages.md5 | cut -d' ' -f1 > ID
1655 ( cat ./ID | tr $'\n' ' '; date -ur ./ID +%s ) > IDs # md5 and timestamp
1657 _n 'Creating file "%s"' 'descriptions.txt' | dblog
1658 rm $PKGS/descriptions.txt 2>/dev/null
1659 for i in $(ls $WOK | sort); do
1660 if [ -e "$WOK/$i/description.txt" ]; then
1661 echo "$i" >> descriptions.txt
1662 cat "$WOK/$i/description.txt" | sed 's|^$| |' >> descriptions.txt
1663 echo >> descriptions.txt
1664 fi
1665 done
1666 echo " ($(filesize $PKGS/descriptions.txt))" | dblog
1669 _ 'Creating lists from "%s"' "$WOK" | dblog
1670 cd $WOK
1671 for pkg in *; do
1672 unset_receipt
1673 . $pkg/receipt
1674 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1675 [ -s $pkg/taz/*/receipt ] && . $pkg/taz/*/receipt
1677 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ] || \
1678 [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1680 # packages.desc lets us search easily in DB
1681 cat >> $PKGS/packages.desc <<EOT
1682 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1683 EOT
1685 # packages.txt used by tazpkg and tazpkg-web also to provide
1686 # a human readable package list with version and description.
1687 cat >> $PKGS/packages.txt <<EOT
1688 $PACKAGE
1689 $VERSION$EXTRAVERSION
1690 $SHORT_DESC
1691 $PACKED_SIZE ($UNPACKED_SIZE installed)
1693 EOT
1695 # packages.info combines TazPkg separate files
1696 # and will substitute them all
1697 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1698 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
1699 MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" $PKGS/packages.md5 | awk '{print $1}')"
1700 cat >> $PKGS/packages.info <<EOT
1701 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5
1702 EOT
1704 # packages.equiv is used by tazpkg install to check depends.
1705 for i in $PROVIDE; do
1706 DEST=''
1707 echo $i | fgrep -q : && DEST="${i#*:}:"
1708 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1709 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1710 $PKGS/packages.equiv
1711 else
1712 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1713 fi
1714 done
1716 # files.list provides a list of all packages files.
1717 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1718 $PKGS/files.list
1720 # list of duplicates
1721 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg/d" $PKGS/packages.toremove
1722 else
1723 # if receipt variable HOST_ARCH absent/empty or contains ARCH
1724 if [ -z "$HOST_ARCH" -o "${HOST_ARCH/$ARCH/}" != "$HOST_ARCH" ]; then
1725 _ ' - absent: %s (%s)' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$ARCH" | dblog
1726 fi
1727 fi
1728 done
1730 # Display list size.
1731 _ 'Done: %s (%s)' 'packages.desc' "$(filesize $PKGS/packages.desc)" | dblog
1732 _ 'Done: %s (%s)' 'packages.txt' "$(filesize $PKGS/packages.txt)" | dblog
1733 _ 'Done: %s (%s)' 'packages.info' "$(filesize $PKGS/packages.info)" | dblog
1734 _ 'Done: %s (%s)' 'packages.equiv' "$(filesize $PKGS/packages.equiv)" | dblog
1736 cd $PKGS
1739 # Check package duplicates
1740 if [ -s "$PKGS/packages.toremove" ]; then
1741 newline | dblog
1742 _ 'Removing duplicates:' | dblog
1743 while read pkgsum pkgfile; do
1744 echo " - $pkgfile" | dblog
1745 sed -i "/${pkgfile%.tazpkg}/d" $PKGS/packages.list
1746 sed -i "/ $pkgfile/d" $PKGS/packages.md5
1747 [ -n "$rmpkg" ] && rm $PKGS/$pkgfile # remove packages only with --rmpkg
1748 done < $PKGS/packages.toremove
1749 newline | dblog
1750 fi
1751 rm $PKGS/packages.toremove
1754 # files.list.lzma
1755 _n 'Creating file "%s"' 'files.list.lzma' | dblog
1756 touch files.list
1757 # pkgs.slitaz.org strongly depends on list sorted by packages names
1758 lzma e files.list files.list.lzma
1759 echo " ($(filesize $PKGS/files.list.lzma))" | dblog
1761 # Pre-sorting filenames causes 10% smaller resulting lzma file
1762 _n 'Creating file "%s"' 'files-list.lzma' | dblog
1763 cat files.list | sort -k2 -o files.list.sorted
1764 lzma e files.list.sorted files-list.lzma
1765 rm -f files.list files.list.sorted
1766 echo " ($(filesize $PKGS/files-list.lzma))" | dblog
1768 [ -e files.list.md5 ] && rm files.list.md5
1769 md5sum files-list.lzma | cut -d' ' -f1 | tr -d $'\n' > files-list.md5
1771 # packages.info.lzma
1772 PI=packages.info
1773 _n 'Creating file "%s"' 'packages.info.lzma' | dblog
1774 touch $PI
1775 lzma e $PI $PI.lzma
1776 echo " ($(filesize $PKGS/packages.info.lzma))" | dblog
1778 # Make bundle to fast recharge
1779 _n 'Creating file "%s"' 'bundle.tar.lzma' | dblog
1780 [ -f bundle.tar.lzma ] && rm bundle.tar.lzma
1781 # Make sure to get "mirrors" file
1782 until [ -e 'mirrors' ]; do
1783 wget -q http://mirror1.slitaz.org/mirrors
1784 echo -n '.' | dblog; sleep 5
1785 done
1786 # Make sure to get "extra.list" file
1787 until [ -e 'extra.list' ]; do
1788 wget -q -O extra.list http://mirror1.slitaz.org/packages/get.list
1789 echo -n '.' | dblog; sleep 5
1790 done
1791 busybox tar -chaf bundle.tar.lzma \
1792 mirrors extra.list files-list.md5 packages.info descriptions.txt \
1793 packages.desc packages.md5 packages.txt packages.list packages.equiv
1794 rm ./mirrors
1795 echo " ($(filesize $PKGS/bundle.tar.lzma))" | dblog
1797 # Display some info.
1798 separator | dblog
1799 nb=$(ls $PKGS/*.tazpkg | wc -l)
1800 time=$(($(date +%s) - $time))
1801 # L10n: 's' is for seconds (cooking time)
1802 { _ 'Packages: %s - Time: %ss' "$nb" "$time"; newline; } | dblog
1805 # Create all flavors files at once. Do we really need code to monitor
1806 # flavors changes? Lets just build them with packages lists before
1807 # syncing the mirror.
1808 [ "$2" != '--flavors' ] && exit 1
1810 if [ ! -d "$flavors" ]; then
1811 { _ 'Missing flavors folder "%s"' "$flavors"; newline; } | dblog
1812 exit 1
1813 fi
1815 [ ! -d "$live" ] && mkdir -p $live
1816 _ 'Creating flavors files in "%s"' "$live" | dblog
1817 _ 'Cook pkgdb: Creating all flavors' | log
1818 separator | dblog
1820 _ 'Recharging lists to use latest packages...' | dblog
1821 tazpkg recharge >/dev/null 2>/dev/null
1823 # We need a custom tazlito config to set working dir to /home/slitaz.
1824 if [ ! -f "$live/tazlito.conf" ]; then
1825 _ 'Creating configuration file "%s"' 'tazlito.conf' | dblog
1826 cp /etc/tazlito/tazlito.conf $live
1827 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1828 $live/tazlito.conf
1829 fi
1831 # Update Hg flavors repo and pack.
1832 if [ -d "$flavors/.hg" ]; then
1833 cd $flavors; hg pull -u
1834 fi
1836 cd $live
1837 _ 'Starting to generate flavors...' | dblog
1838 rm -f flavors.list *.flavor
1839 for i in $flavors/*; do
1840 fl=$(basename $i)
1841 _ 'Packing flavor "%s"' "$fl" | dblog
1842 tazlito pack-flavor $fl >/dev/null || exit 1
1843 tazlito show-flavor $fl --brief --noheader 2>/dev/null >> flavors.list
1844 done
1845 cp -f $live/*.flavor $live/flavors.list $PKGS
1846 separator | dblog
1847 { _ 'Total flavors size: %s' "$(du -sh $live | awk '{print $1}')"; newline; } | dblog
1848 rm -f $command
1849 separator | dblog
1850 _ 'Cook pkgdb end: %s' "$(date "$(_ '+%%F %%R')")" | dblog
1851 ;;
1853 *)
1854 # Just cook and generate a package.
1855 check_root
1856 time=$(date +%s)
1857 pkg="$1"
1858 [ -z "$pkg" ] && usage
1859 lastcooktime=$(sed '/^Cook time/!d;s|.*: *\([0-9]*\)s.*|\1|' \
1860 $LOGS/$pkg.log 2> /dev/null | sed '$!d')
1861 receipt="$WOK/$pkg/receipt"
1862 check_pkg_in_wok
1863 newline
1865 unset inst
1866 unset_receipt
1867 . $receipt
1869 # Handle cross compilation.
1870 case "$ARCH" in
1871 arm*)
1872 if [ -z "$HOST_ARCH" ]; then
1873 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1874 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1875 _ 'cook: %s' "$error"
1876 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1877 _ 'Cook skip: %s' "$error" | log
1878 newline
1879 exit 1
1880 fi ;;
1881 esac
1883 # Some packages are not included in some arch or fail to cross compile.
1884 : ${HOST_ARCH=i486}
1885 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1886 # Handle arm{v6hf,v7,..}
1887 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1888 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1889 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1890 _ 'cook: %s' "error"
1891 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1892 _ 'Cook skip: %s' "$error" | log
1893 sed -i /^${pkg}$/d $broken
1894 newline
1895 exit 0
1896 fi
1898 # Skip blocked, 3 lines also for the Cooker.
1899 if grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ]; then
1900 _ 'Package "%s" is blocked' "$pkg"; newline
1901 exit 0
1902 fi
1904 try_aufs_chroot "$@"
1906 # Log and source receipt.
1907 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1908 echo "cook:$pkg" > $command
1909 [ "$lastcooktime" ] &&
1910 echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1911 while read cmd duration start; do
1912 [ $(($start + $duration)) -lt $(date +%s) ] &&
1913 echo "sed -i '/^$cmd $duration/d' $cooktime"
1914 done < $cooktime | sh
1916 # Display and log info if cook process stopped.
1917 # FIXME: gettext not working (in single quotes) here!
1918 trap '_ "\n\nCook stopped: control-C\n\n" | \
1919 tee -a $LOGS/$pkg.log' INT
1921 # Handle --options
1922 case "$2" in
1923 --clean|-c)
1924 action 'Cleaning "%s"' "$pkg"
1925 cd $WOK/$pkg; rm -rf install taz source
1926 status; newline
1927 exit 0 ;;
1929 --install|-i)
1930 inst='yes' ;;
1932 --getsrc|-gs)
1933 title 'Getting source for "%s"' "$pkg"
1934 get_source
1935 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1936 exit 0 ;;
1938 --block|-b)
1939 action 'Blocking package "%s"' "$pkg"
1940 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1941 status; newline
1942 exit 0 ;;
1944 --unblock|-ub)
1945 action 'Unblocking package "%s"' "$pkg"
1946 sed -i "/^${pkg}$/"d $blocked
1947 status; newline
1948 exit 0 ;;
1950 --pack)
1951 if [ -d $WOK/$pkg/taz ]; then
1952 rm -rf $WOK/$pkg/taz
1953 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1954 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1955 clean_log
1956 else
1957 _ 'Need to build "%s"' "$pkg"
1958 exit 0
1959 fi
1960 exit 0 ;;
1962 --cdeps)
1963 if [ ! -d $WOK/$pkg/taz ]; then
1964 _ 'Need to build "%s"' "$pkg"
1965 exit 0
1966 fi
1968 title 'Checking depends'
1969 lddlist='/tmp/lddlist'; touch $lddlist
1970 missing='/var/cache/missing.file'
1972 # find all deps using ldd
1973 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
1974 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
1975 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
1976 done #"
1978 # remove exe/so duplicates
1979 sort -u $lddlist > $lddlist.sorted
1981 # search packages
1982 for exefile in $(cat $lddlist.sorted); do
1983 search_file $exefile
1984 echo "$found" >> $lddlist.pkgs
1985 echo -n '.'
1986 done
1987 echo
1989 # remove packages duplicates
1990 sort -u $lddlist.pkgs > $lddlist.final
1991 sort -u $missing > $missing.final
1992 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
1993 exit 0 ;;
1994 esac
1996 # Rotate log
1997 for i in $(seq 9 -1 1); do
1998 j=$(($i - 1))
1999 [ -e $LOGS/$pkg.log.$j ] &&
2000 mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
2001 done
2002 mv $LOGS/$pkg.log $LOGS/$pkg.log.0
2004 # Check if wanted is built now so we have separate log files.
2005 for wanted in $WANTED ; do
2006 if grep -q "^$wanted$" $blocked; then
2007 _ 'WANTED package "%s" is blocked' "$wanted" | tee $LOGS/$pkg.log
2008 newline
2009 rm -f $command
2010 exit 1
2011 fi
2012 if grep -q "^$wanted$" $broken; then
2013 _ 'WANTED package "%s" is broken' "$wanted" | tee $LOGS/$pkg.log
2014 newline
2015 rm -f $command
2016 exit 1
2017 fi
2018 if [ ! -d "$WOK/$wanted/install" ]; then
2019 cook "$wanted" || exit 1
2020 fi
2021 done
2023 # Cook and pack or exit on error and log everything.
2024 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
2025 remove_deps | tee -a $LOGS/$pkg.log
2026 cookit_quality
2027 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
2028 clean_log
2030 # Exit if any error in packing.
2031 lerror=$(_n 'ERROR')
2032 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
2033 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
2034 debug_info | tee -a $LOGS/$pkg.log
2035 rm -f $command
2036 exit 1
2037 fi
2039 # Create an XML feed
2040 gen_rss
2042 # Time and summary
2043 time=$(($(date +%s) - $time))
2044 summary | tee -a $LOGS/$pkg.log
2045 newline
2047 # We may want to install/update (outside aufs jail !).
2048 [ -s /aufs-umount.sh ] ||
2049 install_package
2051 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2052 # You want automation: use the Cooker Build Bot.
2053 rm -f $command ;;
2054 esac
2056 exit 0