cookutils view cook @ rev 809

cook: add cook_pick_manpages(), remove cook_compress_manpages() - it is now done automatically
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Jul 05 01:48:28 2016 +0300 (2016-07-05)
parents ca8a6e2c923e
children 0fcf24dbe68e
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 ;;
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 local manpath="$install/usr/share/man" dest link
575 [ -d "$manpath" ] || return
576 action 'Compressing man pages...'
578 # We'll use only Gzip compression, so decompress other formats first
579 find $manpath -type f -name '*.bz2' -exec bunzip2 \{\} \;
580 find $manpath -type f -name '*.xz' -exec unxz \{\} \;
582 # Fast compress with gzip
583 find $manpath -type f -name '*.[1-9]' -exec gzip \{\} \;
585 # Fix symlinks
586 for i in $(find $install/usr/share/man -type l); do
587 dest=$(readlink $i | sed 's|\.[gbx]z2*$||')
588 link=$(echo $i | sed 's|\.[gbx]z2*$||')
589 rm $i; ln -s $dest.gz $link.gz
590 done
592 # Recompress with advdef (it can't compress, only recompress)
593 tazpkg -gi advancecomp --quiet
594 for i in $(find $install/usr/share/man -type f); do
595 advdef -z4q $i
596 done
598 status
599 }
602 # The main cook function.
604 cookit() {
605 title 'Cook: %s' "$PACKAGE $VERSION"
606 set_paths
608 # Handle cross-tools.
609 case "$ARCH" in
610 arm*|x86_64)
611 # CROSS_COMPILE is used by at least Busybox and the kernel to set
612 # the cross-tools prefix. Sysroot is the root of our target arch
613 sysroot="$CROSS_TREE/sysroot"
614 tools="$CROSS_TREE/tools"
615 # Set root path when cross compiling. ARM tested but not x86_64
616 # When cross compiling we must install build deps in $sysroot.
617 arch="-$ARCH"
618 root="$sysroot"
619 _ '%s sysroot: %s' "$ARCH" "$sysroot"
620 _ 'Adding "%s" to PATH' "$tools/bin"
621 export PATH="$PATH:$tools/bin"
622 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
623 export CROSS_COMPILE="$HOST_SYSTEM-"
624 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
625 if [ "$ARCH" == 'x86_64' ]; then
626 export CC="$HOST_SYSTEM-gcc -m64"
627 export CXX="$HOST_SYSTEM-g++ -m64"
628 else
629 export CC="$HOST_SYSTEM-gcc"
630 export CXX="$HOST_SYSTEM-g++"
631 fi
632 export AR="$HOST_SYSTEM-ar"
633 export AS="$HOST_SYSTEM-as"
634 export RANLIB="$HOST_SYSTEM-ranlib"
635 export LD="$HOST_SYSTEM-ld"
636 export STRIP="$HOST_SYSTEM-strip"
637 export LIBTOOL="$HOST_SYSTEM-libtool" ;;
638 esac
640 [ -n "$QA" ] && receipt_quality
641 cd $pkgdir
642 [ -z "$continue" ] && rm -rf source 2>/dev/null
643 rm -rf install taz 2>/dev/null
645 # Disable -pipe if less than 512Mb free RAM.
646 free=$(free | awk '/buffers:/{print $4}')
647 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
648 _ 'Disabling -pipe compile flag: %d RAM free' "$free"
649 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
650 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
651 fi
652 unset free
654 # Export flags and path to be used by make and receipt.
655 DESTDIR="$pkgdir/install"
656 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
657 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
658 #LDFLAGS
660 # Check for build deps and handle implicit depends of *-dev packages
661 # (ex: libusb-dev :: libusb).
662 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
663 touch $CACHE/installed.local $CACHE/installed.web
664 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
665 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
666 for dep in $BUILD_DEPENDS; do
667 implicit="${dep%-dev}"
668 # Don't add implicit dependency if it defined in DEPENDS
669 # echo '' $DEPENDS '' | fgrep -q " $implicit " && implicit=''
670 for i in $dep $implicit; do
671 if [ ! -f "$root$INSTALLED/$i/receipt" ]; then
672 # Try local package first. In some cases implicit doesn't exist, ex:
673 # libboost-dev exists but not libboost, so check if we got vers.
674 unset vers
675 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
676 # We may have a local package.
677 if [ -z "$vers" ]; then
678 vers=$(awk -F$'\t' -vp="$i" '$1==p{print $2; quit}' $PKGS/packages.info 2> /dev/null)
679 fi
680 debug "bdep: $i version: $vers"
681 if [ -f "$PKGS/$i-$vers$arch.tazpkg" ]; then
682 echo $i-$vers$arch.tazpkg >> $CACHE/installed.local
683 else
684 # Priority to package version in wok (maybe more up-to-date)
685 # than the mirrored one.
686 if [ -n "$vers" ]; then
687 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
688 echo $i >> $CACHE/installed.web
689 else
690 # So package exists in wok but not available.
691 _ 'Missing dep (wok/pkg): %s' "$i $vers"
692 echo $i >> $CACHE/missing.dep
693 fi
694 else
695 # Package is not in wok but may be in online repo.
696 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
697 echo $i >> $CACHE/installed.web
698 else
699 _ 'ERROR: unknown dep "%s"' "$i"
700 exit 1
701 fi
702 fi
703 fi
704 fi
705 done
706 done
708 # Get the list of installed packages
709 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
711 # Have we a missing build dep to cook?
712 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
713 _ 'Auto cook config is set: %s' "$AUTO_COOK"
714 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
715 for i in $(uniq $CACHE/missing.dep); do
716 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
717 tee -a $LOGS/$PACKAGE.log.$$
718 # programmers: next two messages are exact copy from remove_deps()
719 togrep1=$(_n 'Build dependencies to remove:')
720 togrep2=$(_n 'Removing:')
721 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
722 fgrep $togrep1 $LOGS/$i.log && \
723 fgrep $togrep2 $LOGS/$i.log && newline) | \
724 tee -a $LOGS/$PACKAGE.log.$$ && break
725 done
726 rm -f $CACHE/missing.dep
727 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
728 fi
730 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
731 # is enabled and cook fails we have ERROR in log, if no auto cook we have
732 # missing dep in cached file.
733 lerror=$(_n 'ERROR')
734 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
735 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
736 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
737 exit 1
738 fi
740 # Install local packages: package-version$arch
741 cd $PKGS
742 for i in $(uniq $CACHE/installed.local); do
743 _ 'Installing dep (pkg/local): %s' "$i"
744 tazpkg install $i --root=$root --local --quiet
745 done
747 # Install web or cached packages (if mirror is set to $PKGS we only
748 # use local packages).
749 for i in $(uniq $CACHE/installed.web); do
750 _ 'Installing dep (web/cache): %s' "$i"
751 tazpkg get-install $i --root=$root --quiet
752 done
754 update_installed_cook_diff
756 # Get source tarball and make sure we have source dir named:
757 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
758 # tarball if it exists.
759 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
760 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
761 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
762 LZMA_SRC=''
763 else
764 get_source || exit 1
765 fi
766 fi
767 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
768 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
769 if ! extract_source ; then
770 get_source
771 extract_source || exit 1
772 fi
773 if [ -n "$LZMA_SRC" ]; then
774 cd $pkgdir/source
775 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
776 mv tmp tmp-1; mkdir tmp
777 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
778 fi
779 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
780 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
781 fi
782 fi
783 cd $pkgdir/source/tmp
784 # Some archives are not well done and don't extract to one dir (ex lzma).
785 files=$(ls | wc -l)
786 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
787 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
788 mv * ../$PACKAGE-$VERSION/$TARBALL
789 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
790 mv * ../$PACKAGE-$VERSION
791 cd ..; rm -rf tmp
792 fi
794 # Libtool shared libs path hack.
795 case "$ARCH" in
796 arm*) cross libhack ;;
797 esac
799 # Execute receipt rules.
800 if grep -q ^compile_rules $receipt; then
801 _ 'Executing: %s' 'compile_rules'
802 echo "CFLAGS : $CFLAGS"
803 #echo "LDFLAGS : $LDFLAGS"
804 [ -d "$src" ] && cd $src
805 compile_rules $@ || exit 1
806 # Stay compatible with _pkg
807 [ -d "$src/_pkg" ] && mv $src/_pkg $install
808 # QA: compile_rules success so valid.
809 mkdir -p $install
810 else
811 # QA: no compile_rules so no error, valid.
812 mkdir -p $install
813 fi
815 # Actions to do after compiling the package
816 compress_manpages
817 footer
819 # Execute testsuite.
820 if grep -q ^testsuite $receipt; then
821 title 'Running testsuite'
822 testsuite $@ || exit 1
823 footer
824 fi
826 fix_desktop_files
827 update_installed_cook_diff force
828 }
831 # Cook quality assurance.
833 cookit_quality() {
834 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
835 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
836 fi
837 # ERROR can be echoed any time in cookit()
838 lerror=$(_n 'ERROR')
839 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
840 grep -Eq "(^$lerror|undefined reference to)" ; then
841 debug_info | tee -a $LOGS/$pkg.log
842 rm -f $command
843 exit 1
844 fi
845 }
848 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
849 # but it doesn't handle EXTRAVERSION.
851 packit() {
852 set_paths
854 # Handle cross compilation
855 case "$ARCH" in
856 arm*|x86_64) arch="-$ARCH" ;;
857 esac
859 title 'Pack: %s' "$PACKAGE $VERSION$arch"
861 if grep -q ^genpkg_rules $receipt; then
862 _ 'Executing: %s' 'genpkg_rules'
863 set -e; cd $pkgdir; mkdir -p $fs
864 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
865 $LOGS/$pkg.log
866 else
867 _ 'No packages rules: meta package'
868 mkdir -p $fs
869 fi
871 # First QA check to stop now if genpkg_rules failed.
872 lerror=$(_n 'ERROR')
873 if fgrep -q ^$lerror $LOGS/$pkg.log; then
874 exit 1
875 fi
877 cd $taz
878 for file in receipt description.txt; do
879 [ ! -f "../$file" ] && continue
880 action 'Copying "%s"...' "$file"
881 cp -f ../$file $pack; chown 0.0 $pack/$file; status
882 done
883 copy_generic_files
885 # Strip and stuff files.
886 strip_package
888 # Create files.list with redirecting find output.
889 action 'Creating the list of files...'
890 cd $fs
891 find . -type f -print > ../files.list
892 find . -type l -print >> ../files.list
893 cd ..; sed -i s/'^.'/''/ files.list
894 status
896 # Md5sum of files.
897 action 'Creating md5sum of files...'
898 while read file; do
899 [ -L "fs$file" ] && continue
900 [ -f "fs$file" ] || continue
901 case "$file" in
902 /lib/modules/*/modules.*|*.pyc) continue ;;
903 esac
904 md5sum "fs$file" | sed 's/ fs/ /'
905 done < files.list > md5sum
906 status
908 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
909 2>/dev/null | awk 'END{ print $1 }')
911 # Build cpio archives.
912 action 'Compressing the FS...'
913 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
914 rm -rf fs
915 status
917 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
918 2>/dev/null | awk 'END{ print $1 }')
920 action 'Updating receipt sizes...'
921 sed -i s/^PACKED_SIZE.*$// receipt
922 sed -i s/^UNPACKED_SIZE.*$// receipt
923 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
924 status
926 # Set extra version.
927 if [ -n "$EXTRAVERSION" ]; then
928 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
929 sed -i s/^EXTRAVERSION.*$// receipt
930 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
931 status
932 fi
934 # Compress.
935 action 'Creating full cpio archive...'
936 find . -print | cpio -o -H newc --quiet > \
937 ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
938 status
940 action 'Restoring original package tree...'
941 unlzma -c fs.cpio.lzma | cpio -idm --quiet
942 status
944 rm fs.cpio.lzma; cd ..
946 # QA and give info.
947 tazpkg=$(ls *.tazpkg)
948 packit_quality
949 footer "$(_ 'Package "%s" created' "$tazpkg")"
950 }
953 # Verify package quality and consistency.
955 packit_quality() {
956 #action 'QA: checking for broken link...'
957 #link=$(find $fs/usr -type l -follow)
958 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
959 #status
961 # Exit if any error found in log file.
962 lerror=$(_n 'ERROR')
963 if fgrep -q ^$lerror $LOGS/$pkg.log; then
964 rm -f $command
965 exit 1
966 fi
968 action 'QA: checking for empty package...'
969 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
970 if [ "$files" -eq 0 -a "$CATEGORY" != 'meta' ]; then
971 newline; _ 'ERROR: empty package'
972 rm -f $command
973 exit 1
974 else
975 :; status
976 # Find and remove old package(s)
977 tempd="$(mktemp -d)"; cd "$tempd"
978 for testpkg in $(ls $PKGS/$pkg-*.tazpkg 2> /dev/null); do
979 # Extract receipt from each matched package
980 cpio -F "$testpkg" -i receipt >/dev/null 2>&1
981 name=$(. receipt; echo $PACKAGE)
982 rm receipt
983 if [ "$name" == "$pkg" ]; then
984 action 'Removing old package "%s"' "$(basename "$testpkg")"
985 rm -f "$testpkg"
986 status
987 fi
988 done
989 rm -r "$tempd"
990 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
991 sed -i /^${pkg}$/d $broken
992 #action 'Removing source tree...'
993 #rm -f $WOK/$pkg/source; status
994 fi
995 }
998 # Reverse "cat" command: prints input lines in the reverse order
1000 tac() {
1001 sed '1!G;h;$!d' $1
1005 # Install package on --install or update the chroot.
1007 install_package() {
1008 case "$ARCH" in
1009 arm*|x86_64)
1010 arch="-$ARCH"
1011 root="$CROSS_TREE/sysroot" ;;
1012 esac
1013 # Install package if requested but skip install if target host doesn't
1014 # match build system or it will break the build chroot.
1015 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1016 if [ -n "$inst" ] && [ "$build" == "$ARCH" ]; then
1017 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1018 cd $PKGS
1019 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
1020 else
1021 _ 'Unable to install package, build has failed.'; newline
1022 exit 1
1023 fi
1024 fi
1026 # Install package if part of the chroot to keep env up-to-date.
1027 if [ -d "$root$INSTALLED/$pkg" ]; then
1028 . /etc/slitaz/cook.conf
1029 . $WOK/$pkg/taz/$pkg-*/receipt
1030 _ 'Updating %s chroot environment...' "$ARCH"
1031 _ 'Updating chroot: %s' "$pkg ($VERSION$EXTRAVERSION$arch)" | log
1032 cd $PKGS
1033 tazpkg install $pkg-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1034 fi
1038 # remove chroot jail
1040 umount_aufs() {
1041 tac ${1}rw/aufs-umount.sh | sh
1042 rm -rf ${1}rw
1043 umount ${1}root
1044 rmdir ${1}r*
1048 # Launch the cook command into a chroot jail protected by aufs.
1049 # The current filesystems are used read-only and updates are
1050 # stored in a separate branch.
1052 try_aufs_chroot() {
1054 base="/dev/shm/aufsmnt$$"
1056 # Can we setup the chroot? Is it already done?
1057 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1058 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1059 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1060 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
1061 mkdir ${base}root ${base}rw || return
1063 _ 'Setup aufs chroot...'
1065 # Sanity check
1066 for i in / /proc /sys /dev/shm /home ; do
1067 case " $AUFS_MOUNTS " in
1068 *\ $i\ *) ;;
1069 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1070 esac
1071 done
1072 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1073 mount --bind $mnt ${base}root$mnt
1074 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1075 _ 'Aufs mount failure'
1076 umount ${base}root
1077 rm -rf ${base}r*
1078 return
1079 fi
1080 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1081 done
1082 trap "umount_aufs ${base}" INT
1084 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1085 status=$?
1087 _ 'Leaving aufs chroot...'
1088 umount_aufs $base
1089 # Install package outside the aufs jail
1090 install_package
1091 exit $status
1095 # Encode predefined XML entities
1097 xml_ent() {
1098 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1102 # Create a XML feed for freshly built packages.
1104 gen_rss() {
1105 pubdate=$(date '+%a, %d %b %Y %X')
1106 cat > $FEEDS/$pkg.xml <<EOT
1107 <item>
1108 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1109 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1110 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1111 <pubDate>$pubdate</pubDate>
1112 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1113 </item>
1114 EOT
1118 # Truncate stdout log file to $1 Mb.
1120 loglimit() {
1121 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1122 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1123 else
1124 tee /dev/stderr
1125 fi
1129 # Search file in mirrored packages
1131 search_file_mirror() {
1132 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
1136 # Search file in local wok packages
1138 search_file_local() {
1139 # existing packages have precedence over the package/taz folder
1140 srch=$1
1141 { for package in $(find $PKGS -name '*.tazpkg'); do
1142 if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
1143 grep /$srch\$)" ]; then
1144 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
1145 fi
1146 done } | sort -u
1150 # Ask in multiple choice
1152 ask_multiple() {
1153 local multiples first my_choice
1154 multiples="$1"
1155 first=$(echo "$multiples" | head -n1)
1156 newline; _ 'Multiple choice:'; echo "$multiples"; newline
1157 _ 'Select one [%s]: ' "$first"; read my_choice
1158 found="${my_choice:-$first}"
1162 # Search file in local cache (fast), local wok packages, mirrored packages
1164 search_file() {
1165 local srch cache missing
1166 srch="$1"
1167 cache='/var/cache/ldsearch.cache'
1168 missing='/var/cache/missing.file'
1169 touch $cache $missing
1170 found=$(grep $srch $cache | cut -d$'\t' -f2)
1171 if [ -z "$found" ]; then
1172 found=$(search_file_local $srch)
1173 if [ -n "$found" ]; then
1174 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1175 ask_multiple "$found"
1176 fi
1177 echo -e "$srch\t$found" >> $cache
1178 else
1179 found=$(search_file_mirror $srch)
1180 if [ -n "$found" ]; then
1181 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1182 ask_multiple "$found"
1183 fi
1184 echo -e "$srch\t$found" >> $cache
1185 else
1186 echo "$srch" >> $missing
1187 fi
1188 fi
1189 fi
1193 # Return size of file in human readible format
1194 # Note, "du" in opposite returns size occupied by file on disk (4KB multiple in most cases)
1195 filesize() {
1196 busybox ls -lh "$1" | awk '{print $5 "B"}'
1201 # Receipt functions to ease packaging
1204 get_dev_files() {
1205 action 'Getting standard devel files...'
1206 mkdir -p $fs/usr/lib
1207 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1208 cp -a $install/usr/lib/*a $fs/usr/lib
1209 cp -a $install/usr/include $fs/usr
1210 status
1214 # Function to use in compile_rules() to copy man page from $src to $install
1216 cook_pick_manpages() {
1217 local name section
1218 action 'Copying man pages...'
1220 for i in $@; do
1221 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1222 section=${name##*/}; section=${section##*.}
1223 mkdir -p $install/usr/share/man/man$section
1224 cp -a $i $install/usr/share/man/man$section
1225 done
1226 status
1230 # Function to use in compile_rules() to compress all png images
1232 cook_compress_png() {
1233 action 'Compressing png images...'
1234 local size0=$(find $install -type f -name '*.png' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
1235 tazpkg -gi pngquant --quiet
1236 tazpkg -gi optipng --quiet
1237 for i in $(find $install -type f -name '*.png'); do
1238 pngquant -f --skip-if-larger --ext .png --speed 1 "$i"
1239 optipng -quiet -strip all -o7 -zm1-9 "$i"
1240 done
1241 local size1=$(find $install -type f -name '*.png' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
1242 status
1243 echo " Size: $size0 B -> $size1 B"
1247 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1249 cook_copy_files() {
1250 action 'Copying files...'
1251 cd $install
1252 local i j
1253 for i in $@; do
1254 for j in $(find . -name $i ! -type d); do
1255 mkdir -p $fs$(dirname ${j#.})
1256 cp -a $j $fs/${j#.}
1257 done
1258 done
1259 cd - >/dev/null
1260 status
1264 # Function to use in genpkg_rules() to copy hicolor icons in sizes 16 and 48 from $install to $fs
1266 cook_copy_icons() {
1267 action 'Copying hicolor icons...'
1268 mkdir -p $fs/usr/share/icons/hicolor
1269 for i in 16x16 48x48; do
1270 cp -a $install/usr/share/icons/hicolor/$i $fs/usr/share/icons/hicolor
1271 done
1272 status
1275 dblog() { tee -a $LOGS/pkgdb.log; }
1281 # Commands
1284 case "$1" in
1285 usage|help|-u|-h)
1286 usage ;;
1288 list-wok)
1289 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1290 cd $WOK
1291 if [ "$ARCH" != 'i486' ]; then
1292 count=0
1293 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1294 do
1295 unset HOST_ARCH
1296 . $pkg
1297 count=$(($count + 1))
1298 colorize 34 "$PACKAGE"
1299 done
1300 else
1301 count=$(ls | wc -l)
1302 ls -1
1303 fi
1304 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1305 ;;
1307 activity)
1308 cat $activity ;;
1310 search)
1311 # Just a simple search function, we dont need more actually.
1312 query="$2"
1313 title 'Search results for "%s"' "$query"
1314 cd $WOK; ls -1 | grep "$query"
1315 footer ;;
1317 setup)
1318 # Setup a build environment
1319 check_root
1320 _ 'Cook: setup environment' | log
1321 title 'Setting up your environment'
1322 cd $SLITAZ
1323 init_db_files
1324 _ 'Checking for packages to install...'
1325 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1326 # ARCH-setup or 'cross check' should be used before: cook setup
1327 case "$ARCH" in
1328 arm*|x86_64)
1329 if [ ! -x '/usr/bin/cross' ]; then
1330 _ 'ERROR: %s is not installed' 'cross'
1331 exit 1
1332 fi
1333 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1334 . /etc/slitaz/cross.conf ;;
1335 esac
1336 for pkg in $SETUP_PKGS; do
1337 if [ -n "$forced" ]; then
1338 tazpkg -gi $pkg --forced
1339 else
1340 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1341 fi
1342 done
1344 # Handle --options
1345 case "$2" in
1346 --wok) hg clone $WOK_URL wok || exit 1 ;;
1347 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1348 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1349 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1350 esac
1352 # SliTaz group and permissions
1353 if ! grep -q ^slitaz /etc/group; then
1354 _ 'Adding group "%s"' 'slitaz'
1355 addgroup slitaz
1356 fi
1357 _ 'Setting permissions for group "%s"...' 'slitaz'
1358 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1359 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1360 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1362 *-setup)
1363 # Setup for cross compiling.
1364 arch="${1%-setup}"
1365 check_root
1366 . /etc/slitaz/cook.conf
1367 for pkg in $CROSS_SETUP; do
1368 if [ -n "$forced" ]; then
1369 tazpkg -gi $pkg --forced
1370 else
1371 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1372 fi
1373 done
1375 _ 'Cook: setup %s cross environment' "$arch" | log
1376 title 'Setting up your %s cross environment' "$arch"
1377 init_db_files
1378 sed -i \
1379 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1380 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1381 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1382 /etc/slitaz/cook.conf
1383 case "$arch" in
1384 arm)
1385 flags='-O2 -march=armv6'
1386 host="$ARCH-slitaz-linux-gnueabi" ;;
1387 armv6hf)
1388 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1389 host="$ARCH-slitaz-linux-gnueabi" ;;
1390 armv7)
1391 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1392 host="$ARCH-slitaz-linux-gnueabi" ;;
1393 x86_64)
1394 flags='-O2 -mtune=generic -pipe'
1395 host="$ARCH-slitaz-linux" ;;
1396 esac
1397 sed -i \
1398 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1399 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1400 . /etc/slitaz/cook.conf
1401 sysroot="$CROSS_TREE/sysroot"
1402 tools="/cross/$arch/tools"
1403 root="$sysroot"
1404 # L10n: keep the same width of translations to get a consistent view
1405 _ 'Target arch : %s' "$ARCH"
1406 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1407 _ 'Build flags : %s' "$flags"
1408 _ 'Arch sysroot : %s' "$sysroot"
1409 _ 'Tools prefix : %s' "$tools/bin"
1410 # Tell the packages manager where to find packages.
1411 _ 'Packages DB : %s' "$root$DB"
1412 mkdir -p $root$INSTALLED
1413 cd $root$DB; rm -f *.bak
1414 for list in packages.list packages.desc packages.equiv packages.md5; do
1415 rm -f $list
1416 ln -s $SLITAZ/packages/$list $list
1417 done
1418 # We must have the cross compiled glibc-base installed or default
1419 # i486 package will be used as dep by tazpkg and then break the
1420 # cross environment
1421 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1422 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1423 fi
1424 # Show GCC version or warn if not yet compiled.
1425 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1426 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1427 else
1428 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1429 _ 'Run "%s" to cook a toolchain' 'cross compile'
1430 fi
1431 footer ;;
1433 test)
1434 # Test a cook environment.
1435 _ 'Cook test: testing the cook environment' | log
1436 [ ! -d "$WOK" ] && exit 1
1437 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1438 cook cooktest ;;
1440 new)
1441 # Create the package folder and an empty receipt.
1442 pkg="$2"
1443 [ -z "$pkg" ] && usage
1444 newline
1445 if [ -d "$WOK/$pkg" ]; then
1446 _ 'Package "%s" already exists.' "$pkg"
1447 exit 1
1448 fi
1450 action 'Creating folder "%s"' "$WOK/$pkg"
1451 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1453 action 'Preparing the package receipt...'
1454 cp $DATA/receipt .
1455 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1456 status; newline
1458 # Interactive mode, asking and seding.
1459 case "$3" in
1460 --interactive|-x)
1461 _ 'Entering interactive mode...'
1462 separator
1463 _ 'Package : %s' "$pkg"
1465 _n 'Version : ' ; read answer
1466 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1468 _n 'Category : ' ; read answer
1469 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1471 # L10n: Short description
1472 _n 'Short desc : ' ; read answer
1473 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1475 _n 'Maintainer : ' ; read answer
1476 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1478 _n 'License : ' ; read answer
1479 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1481 _n 'Web site : ' ; read answer
1482 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1483 newline
1485 # Wget URL.
1486 _ 'Wget URL to download source tarball.'
1487 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1488 _n 'Wget url : ' ; read answer
1489 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1491 # Ask for a stuff dir.
1492 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1493 if [ "$?" -eq 0 ]; then
1494 action 'Creating the stuff directory...'
1495 mkdir $WOK/$pkg/stuff; status
1496 fi
1498 # Ask for a description file.
1499 confirm "$(_n 'Are you going to write a description? (y/N)')"
1500 if [ "$?" -eq 0 ]; then
1501 action 'Creating the "%s" file...' 'description.txt'
1502 touch $WOK/$pkg/description.txt; status
1503 fi
1505 footer "$(_ 'Receipt is ready to use.')" ;;
1506 esac ;;
1508 list)
1509 # Cook a list of packages (better use the Cooker since it will order
1510 # packages before executing cook).
1511 check_root
1512 if [ -z "$2" ]; then
1513 newline; _ 'No list in argument.'; newline
1514 exit 1
1515 fi
1516 if [ ! -f "$2" ]; then
1517 newline; _ 'List "%s" not found.' "$2"; newline
1518 exit 1
1519 fi
1521 _ 'Starting cooking the list "%s"' "$2" | log
1523 for pkg in $(cat $2); do
1524 cook $pkg || broken
1525 done ;;
1527 clean-wok)
1528 check_root
1529 newline; action 'Cleaning all packages files...'
1530 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1531 status; newline ;;
1533 clean-src)
1534 check_root
1535 newline; action 'Cleaning all packages sources...'
1536 rm -rf $WOK/*/source
1537 status; newline ;;
1539 uncook)
1540 cd $WOK
1541 count=0
1542 title 'Checking for uncooked packages'
1544 for pkg in *; do
1545 unset HOST_ARCH EXTRAVERSION
1546 [ ! -e $pkg/receipt ] && continue
1547 . $pkg/receipt
1548 # Source cooked pkg receipt to get EXTRAVERSION
1549 if [ -d "$WOK/$pkg/taz" ]; then
1550 cd $WOK/$pkg/taz/$pkg-*
1551 . receipt; cd $WOK
1552 fi
1553 case "$ARCH" in
1554 i486)
1555 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1556 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1557 count=$(($count + 1))
1558 colorize 34 "$pkg"
1559 fi ;;
1560 arm*)
1561 # Check only packages included in arch
1562 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1563 # *.tazpkg
1564 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1565 count=$(($count + 1))
1566 colorize 34 "$pkg"
1567 fi
1568 fi ;;
1569 esac
1570 done
1572 if [ "$count" -gt "0" ]; then
1573 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1574 else
1575 _ 'All packages are cooked :-)'
1576 newline
1577 fi
1578 ;;
1580 pkgdb)
1581 # Create suitable packages list for TazPKG and only for built packages
1582 # as well as flavors files for TazLiTo. We dont need logs since we do it
1583 # manually to ensure everything is fine before syncing the mirror.
1585 rm $LOGS/pkgdb.log 2>/dev/null
1587 case "$2" in
1588 --flavors|--rmpkg) ;;
1589 *)
1590 [ -n "$2" ] && PKGS="$2"
1591 if [ ! -d "$PKGS" ]; then
1592 { newline; _ "Packages directory \"%s\" doesn't exist" "$PKGS"; newline; } | dblog
1593 exit 1
1594 fi ;;
1595 esac
1597 time=$(date +%s)
1598 flavors="$SLITAZ/flavors"
1599 live="$SLITAZ/live"
1601 echo 'cook:pkgdb' > $command
1602 _ 'Cook pkgdb: Creating all packages lists' | log
1603 newline; { _ 'Creating lists for "%s"' "$PKGS"; separator; } | dblog
1605 { _ 'Cook pkgdb started: %s' "$(date "$(_ '+%%F %%R')")"; newline; } | dblog
1607 cd $PKGS
1608 rm -f packages.* extra.list
1609 touch packages.equiv
1611 _n 'Creating file "%s"' 'packages.list' | dblog
1612 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1613 echo " ($(filesize $PKGS/packages.list))" | dblog
1615 _n 'Creating file "%s"' 'packages.md5' | dblog
1616 md5sum *.tazpkg > $PKGS/packages.md5
1617 echo " ($(filesize $PKGS/packages.md5))" | dblog
1618 cp $PKGS/packages.md5 $PKGS/packages.toremove # list of duplicates
1620 md5sum packages.md5 | cut -d' ' -f1 > ID
1621 ( cat ./ID | tr $'\n' ' '; date -ur ./ID +%s ) > IDs # md5 and timestamp
1623 _n 'Creating file "%s"' 'descriptions.txt' | dblog
1624 rm $PKGS/descriptions.txt 2>/dev/null
1625 for i in $(ls $WOK | sort); do
1626 if [ -e "$WOK/$i/description.txt" ]; then
1627 echo "$i" >> descriptions.txt
1628 cat "$WOK/$i/description.txt" | sed 's|^$| |' >> descriptions.txt
1629 echo >> descriptions.txt
1630 fi
1631 done
1632 echo " ($(filesize $PKGS/descriptions.txt))" | dblog
1635 _ 'Creating lists from "%s"' "$WOK" | dblog
1636 cd $WOK
1637 for pkg in *; do
1638 unset_receipt
1639 . $pkg/receipt
1640 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1641 [ -s $pkg/taz/*/receipt ] && . $pkg/taz/*/receipt
1643 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ] || \
1644 [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1646 # packages.desc lets us search easily in DB
1647 cat >> $PKGS/packages.desc <<EOT
1648 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1649 EOT
1651 # packages.txt used by tazpkg and tazpkg-web also to provide
1652 # a human readable package list with version and description.
1653 cat >> $PKGS/packages.txt <<EOT
1654 $PACKAGE
1655 $VERSION$EXTRAVERSION
1656 $SHORT_DESC
1657 $PACKED_SIZE ($UNPACKED_SIZE installed)
1659 EOT
1661 # packages.info combines TazPkg separate files
1662 # and will substitute them all
1663 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1664 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
1665 MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" $PKGS/packages.md5 | awk '{print $1}')"
1666 cat >> $PKGS/packages.info <<EOT
1667 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5
1668 EOT
1670 # packages.equiv is used by tazpkg install to check depends.
1671 for i in $PROVIDE; do
1672 DEST=''
1673 echo $i | fgrep -q : && DEST="${i#*:}:"
1674 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1675 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1676 $PKGS/packages.equiv
1677 else
1678 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1679 fi
1680 done
1682 # files.list provides a list of all packages files.
1683 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1684 $PKGS/files.list
1686 # list of duplicates
1687 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg/d" $PKGS/packages.toremove
1688 else
1689 # if receipt variable HOST_ARCH absent/empty or contains ARCH
1690 if [ -z "$HOST_ARCH" -o "${HOST_ARCH/$ARCH/}" != "$HOST_ARCH" ]; then
1691 _ ' - absent: %s (%s)' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$ARCH" | dblog
1692 fi
1693 fi
1694 done
1696 # Display list size.
1697 _ 'Done: %s (%s)' 'packages.desc' "$(filesize $PKGS/packages.desc)" | dblog
1698 _ 'Done: %s (%s)' 'packages.txt' "$(filesize $PKGS/packages.txt)" | dblog
1699 _ 'Done: %s (%s)' 'packages.info' "$(filesize $PKGS/packages.info)" | dblog
1700 _ 'Done: %s (%s)' 'packages.equiv' "$(filesize $PKGS/packages.equiv)" | dblog
1702 cd $PKGS
1705 # Check package duplicates
1706 if [ -s "$PKGS/packages.toremove" ]; then
1707 newline | dblog
1708 _ 'Removing duplicates:' | dblog
1709 while read pkgsum pkgfile; do
1710 echo " - $pkgfile" | dblog
1711 sed -i "/${pkgfile%.tazpkg}/d" $PKGS/packages.list
1712 sed -i "/ $pkgfile/d" $PKGS/packages.md5
1713 [ -n "$rmpkg" ] && rm $PKGS/$pkgfile # remove packages only with --rmpkg
1714 done < $PKGS/packages.toremove
1715 newline | dblog
1716 fi
1717 rm $PKGS/packages.toremove
1720 # files.list.lzma
1721 _n 'Creating file "%s"' 'files.list.lzma' | dblog
1722 touch files.list
1723 # pkgs.slitaz.org strongly depends on list sorted by packages names
1724 lzma e files.list files.list.lzma
1725 echo " ($(filesize $PKGS/files.list.lzma))" | dblog
1727 # Pre-sorting filenames causes 10% smaller resulting lzma file
1728 _n 'Creating file "%s"' 'files-list.lzma' | dblog
1729 cat files.list | sort -k2 -o files.list.sorted
1730 lzma e files.list.sorted files-list.lzma
1731 rm -f files.list files.list.sorted
1732 echo " ($(filesize $PKGS/files-list.lzma))" | dblog
1734 [ -e files.list.md5 ] && rm files.list.md5
1735 md5sum files-list.lzma | cut -d' ' -f1 | tr -d $'\n' > files-list.md5
1737 # packages.info.lzma
1738 PI=packages.info
1739 _n 'Creating file "%s"' 'packages.info.lzma' | dblog
1740 touch $PI
1741 lzma e $PI $PI.lzma
1742 echo " ($(filesize $PKGS/packages.info.lzma))" | dblog
1744 # Make bundle to fast recharge
1745 _n 'Creating file "%s"' 'bundle.tar.lzma' | dblog
1746 [ -f bundle.tar.lzma ] && rm bundle.tar.lzma
1747 # Make sure to get "mirrors" file
1748 until [ -e 'mirrors' ]; do
1749 wget -q http://mirror1.slitaz.org/mirrors
1750 echo -n '.' | dblog; sleep 5
1751 done
1752 # Make sure to get "extra.list" file
1753 until [ -e 'extra.list' ]; do
1754 wget -q -O extra.list http://mirror1.slitaz.org/packages/get.list
1755 echo -n '.' | dblog; sleep 5
1756 done
1757 busybox tar -chaf bundle.tar.lzma \
1758 mirrors extra.list files-list.md5 packages.info descriptions.txt \
1759 packages.desc packages.md5 packages.txt packages.list packages.equiv
1760 rm ./mirrors
1761 echo " ($(filesize $PKGS/bundle.tar.lzma))" | dblog
1763 # Display some info.
1764 separator | dblog
1765 nb=$(ls $PKGS/*.tazpkg | wc -l)
1766 time=$(($(date +%s) - $time))
1767 # L10n: 's' is for seconds (cooking time)
1768 { _ 'Packages: %s - Time: %ss' "$nb" "$time"; newline; } | dblog
1771 # Create all flavors files at once. Do we really need code to monitor
1772 # flavors changes? Lets just build them with packages lists before
1773 # syncing the mirror.
1774 [ "$2" != '--flavors' ] && exit 1
1776 if [ ! -d "$flavors" ]; then
1777 { _ 'Missing flavors folder "%s"' "$flavors"; newline; } | dblog
1778 exit 1
1779 fi
1781 [ ! -d "$live" ] && mkdir -p $live
1782 _ 'Creating flavors files in "%s"' "$live" | dblog
1783 _ 'Cook pkgdb: Creating all flavors' | log
1784 separator | dblog
1786 _ 'Recharging lists to use latest packages...' | dblog
1787 tazpkg recharge >/dev/null 2>/dev/null
1789 # We need a custom tazlito config to set working dir to /home/slitaz.
1790 if [ ! -f "$live/tazlito.conf" ]; then
1791 _ 'Creating configuration file "%s"' 'tazlito.conf' | dblog
1792 cp /etc/tazlito/tazlito.conf $live
1793 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1794 $live/tazlito.conf
1795 fi
1797 # Update Hg flavors repo and pack.
1798 if [ -d "$flavors/.hg" ]; then
1799 cd $flavors; hg pull -u
1800 fi
1802 cd $live
1803 _ 'Starting to generate flavors...' | dblog
1804 rm -f flavors.list *.flavor
1805 for i in $flavors/*; do
1806 fl=$(basename $i)
1807 _ 'Packing flavor "%s"' "$fl" | dblog
1808 tazlito pack-flavor $fl >/dev/null || exit 1
1809 tazlito show-flavor $fl --brief --noheader 2>/dev/null >> flavors.list
1810 done
1811 cp -f $live/*.flavor $live/flavors.list $PKGS
1812 separator | dblog
1813 { _ 'Total flavors size: %s' "$(du -sh $live | awk '{print $1}')"; newline; } | dblog
1814 rm -f $command
1815 separator | dblog
1816 _ 'Cook pkgdb end: %s' "$(date "$(_ '+%%F %%R')")" | dblog
1817 ;;
1819 *)
1820 # Just cook and generate a package.
1821 check_root
1822 time=$(date +%s)
1823 pkg="$1"
1824 [ -z "$pkg" ] && usage
1825 lastcooktime=$(sed '/^Cook time/!d;s|.*: *\([0-9]*\)s.*|\1|' \
1826 $LOGS/$pkg.log 2> /dev/null | sed '$!d')
1827 receipt="$WOK/$pkg/receipt"
1828 check_pkg_in_wok
1829 newline
1831 unset inst
1832 unset_receipt
1833 . $receipt
1835 # Handle cross compilation.
1836 case "$ARCH" in
1837 arm*)
1838 if [ -z "$HOST_ARCH" ]; then
1839 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1840 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1841 _ 'cook: %s' "$error"
1842 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1843 _ 'Cook skip: %s' "$error" | log
1844 newline
1845 exit 1
1846 fi ;;
1847 esac
1849 # Some packages are not included in some arch or fail to cross compile.
1850 : ${HOST_ARCH=i486}
1851 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1852 # Handle arm{v6hf,v7,..}
1853 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1854 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1855 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1856 _ 'cook: %s' "error"
1857 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1858 _ 'Cook skip: %s' "$error" | log
1859 sed -i /^${pkg}$/d $broken
1860 newline
1861 exit 0
1862 fi
1864 # Skip blocked, 3 lines also for the Cooker.
1865 if grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ]; then
1866 _ 'Package "%s" is blocked' "$pkg"; newline
1867 exit 0
1868 fi
1870 try_aufs_chroot "$@"
1872 # Log and source receipt.
1873 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1874 echo "cook:$pkg" > $command
1875 [ "$lastcooktime" ] &&
1876 echo "cook:$pkg $lastcooktime $(date +%s)" > $cooktime
1878 # Display and log info if cook process stopped.
1879 # FIXME: gettext not working (in single quotes) here!
1880 trap '_ "\n\nCook stopped: control-C\n\n" | \
1881 tee -a $LOGS/$pkg.log' INT
1883 # Handle --options
1884 case "$2" in
1885 --clean|-c)
1886 action 'Cleaning "%s"' "$pkg"
1887 cd $WOK/$pkg; rm -rf install taz source
1888 status; newline
1889 exit 0 ;;
1891 --install|-i)
1892 inst='yes' ;;
1894 --getsrc|-gs)
1895 title 'Getting source for "%s"' "$pkg"
1896 get_source
1897 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1898 exit 0 ;;
1900 --block|-b)
1901 action 'Blocking package "%s"' "$pkg"
1902 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1903 status; newline
1904 exit 0 ;;
1906 --unblock|-ub)
1907 action 'Unblocking package "%s"' "$pkg"
1908 sed -i "/^${pkg}$/"d $blocked
1909 status; newline
1910 exit 0 ;;
1912 --pack)
1913 if [ -d $WOK/$pkg/taz ]; then
1914 rm -rf $WOK/$pkg/taz
1915 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1916 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1917 clean_log
1918 else
1919 _ 'Need to build "%s"' "$pkg"
1920 exit 0
1921 fi
1922 exit 0 ;;
1924 --cdeps)
1925 if [ ! -d $WOK/$pkg/taz ]; then
1926 _ 'Need to build "%s"' "$pkg"
1927 exit 0
1928 fi
1930 title 'Checking depends'
1931 lddlist='/tmp/lddlist'; touch $lddlist
1932 missing='/var/cache/missing.file'
1934 # find all deps using ldd
1935 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
1936 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
1937 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
1938 done #"
1940 # remove exe/so duplicates
1941 sort -u $lddlist > $lddlist.sorted
1943 # search packages
1944 for exefile in $(cat $lddlist.sorted); do
1945 search_file $exefile
1946 echo "$found" >> $lddlist.pkgs
1947 echo -n '.'
1948 done
1949 echo
1951 # remove packages duplicates
1952 sort -u $lddlist.pkgs > $lddlist.final
1953 sort -u $missing > $missing.final
1954 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
1955 exit 0 ;;
1956 esac
1958 # Rotate log
1959 for i in $(seq 9 -1 1); do
1960 j=$(($i - 1))
1961 [ -e $LOGS/$pkg.log.$j ] &&
1962 mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
1963 done
1964 mv $LOGS/$pkg.log $LOGS/$pkg.log.0
1966 # Check if wanted is built now so we have separate log files.
1967 for wanted in $WANTED ; do
1968 if grep -q "^$wanted$" $blocked; then
1969 _ 'WANTED package "%s" is blocked' "$wanted" | tee $LOGS/$pkg.log
1970 newline
1971 rm -f $command
1972 exit 1
1973 fi
1974 if grep -q "^$wanted$" $broken; then
1975 _ 'WANTED package "%s" is broken' "$wanted" | tee $LOGS/$pkg.log
1976 newline
1977 rm -f $command
1978 exit 1
1979 fi
1980 if [ ! -d "$WOK/$wanted/install" ]; then
1981 cook "$wanted" || exit 1
1982 fi
1983 done
1985 # Cook and pack or exit on error and log everything.
1986 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1987 remove_deps | tee -a $LOGS/$pkg.log
1988 cookit_quality
1989 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1990 clean_log
1992 # Exit if any error in packing.
1993 lerror=$(_n 'ERROR')
1994 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1995 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
1996 debug_info | tee -a $LOGS/$pkg.log
1997 rm -f $command
1998 exit 1
1999 fi
2001 # Create an XML feed
2002 gen_rss
2004 # Time and summary
2005 time=$(($(date +%s) - $time))
2006 summary | tee -a $LOGS/$pkg.log
2007 newline
2009 # We may want to install/update (outside aufs jail !).
2010 [ -s /aufs-umount.sh ] ||
2011 install_package
2013 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2014 # You want automation: use the Cooker Build Bot.
2015 rm -f $command ;;
2016 esac
2018 exit 0