cookutils view cook @ rev 830
Update fr.po
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Mon Sep 19 12:58:15 2016 +0200 (2016-09-19) |
parents | 5d200ccc3cee |
children | 54bbb76536a8 |
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
1001 }
1004 # Reverse "cat" command: prints input lines in the reverse order
1006 tac() {
1007 sed '1!G;h;$!d' $1
1008 }
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
1041 }
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*
1051 }
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
1098 }
1101 # Encode predefined XML entities
1103 xml_ent() {
1104 sed -e 's|&|\&|g; s|<|\<|g; s|>|\>|g; s|"|\"|g' -e "s|'|\'|g"
1105 }
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
1121 }
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
1132 }
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
1139 }
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
1153 }
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}"
1165 }
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
1196 }
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"}'
1203 }
1206 #
1207 # Receipt functions to ease packaging
1208 #
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
1217 }
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
1233 }
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"
1254 }
1257 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1259 cook_copy_files() {
1260 action 'Copying files...'
1261 cd $install
1262 local i j
1263 for i in $@; do
1264 for j in $(find . -name $i ! -type d); do
1265 mkdir -p $fs$(dirname ${j#.})
1266 cp -a $j $fs/${j#.}
1267 done
1268 done
1269 cd - >/dev/null
1270 status
1271 }
1274 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1275 # (default: 16 and 48) from $install to $fs
1277 cook_copy_icons() {
1278 local sizes=$@
1279 action 'Copying hicolor icons...'
1280 mkdir -p $fs/usr/share/icons/hicolor
1281 for i in ${sizes:-16 48}; do
1282 [ -e "$install/usr/share/icons/hicolor/${i}x$i" ] &&
1283 cp -a $install/usr/share/icons/hicolor/${i}x$i \
1284 $fs/usr/share/icons/hicolor
1285 done
1286 status
1287 }
1289 dblog() { tee -a $LOGS/pkgdb.log; }
1294 #
1295 # Commands
1296 #
1298 case "$1" in
1299 usage|help|-u|-h)
1300 usage ;;
1302 list-wok)
1303 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1304 cd $WOK
1305 if [ "$ARCH" != 'i486' ]; then
1306 count=0
1307 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1308 do
1309 unset HOST_ARCH
1310 . $pkg
1311 count=$(($count + 1))
1312 colorize 34 "$PACKAGE"
1313 done
1314 else
1315 count=$(ls | wc -l)
1316 ls -1
1317 fi
1318 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1319 ;;
1321 activity)
1322 cat $activity ;;
1324 search)
1325 # Just a simple search function, we dont need more actually.
1326 query="$2"
1327 title 'Search results for "%s"' "$query"
1328 cd $WOK; ls -1 | grep "$query"
1329 footer ;;
1331 setup)
1332 # Setup a build environment
1333 check_root
1334 _ 'Cook: setup environment' | log
1335 title 'Setting up your environment'
1336 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1337 cd $SLITAZ
1338 init_db_files
1339 _ 'Checking for packages to install...'
1340 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1341 # ARCH-setup or 'cross check' should be used before: cook setup
1342 case "$ARCH" in
1343 arm*|x86_64)
1344 if [ ! -x '/usr/bin/cross' ]; then
1345 _ 'ERROR: %s is not installed' 'cross'
1346 exit 1
1347 fi
1348 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1349 . /etc/slitaz/cross.conf ;;
1350 esac
1351 for pkg in $SETUP_PKGS; do
1352 if [ -n "$forced" ]; then
1353 tazpkg -gi $pkg --forced
1354 else
1355 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1356 fi
1357 done
1359 # Handle --options
1360 case "$2" in
1361 --wok) hg clone $WOK_URL wok || exit 1 ;;
1362 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1363 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1364 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1365 esac
1367 # SliTaz group and permissions
1368 if ! grep -q ^slitaz /etc/group; then
1369 _ 'Adding group "%s"' 'slitaz'
1370 addgroup slitaz
1371 fi
1372 _ 'Setting permissions for group "%s"...' 'slitaz'
1373 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1374 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1375 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1377 *-setup)
1378 # Setup for cross compiling.
1379 arch="${1%-setup}"
1380 check_root
1381 . /etc/slitaz/cook.conf
1382 for pkg in $CROSS_SETUP; do
1383 if [ -n "$forced" ]; then
1384 tazpkg -gi $pkg --forced
1385 else
1386 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1387 fi
1388 done
1390 _ 'Cook: setup %s cross environment' "$arch" | log
1391 title 'Setting up your %s cross environment' "$arch"
1392 init_db_files
1393 sed -i \
1394 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1395 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1396 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1397 /etc/slitaz/cook.conf
1398 case "$arch" in
1399 arm)
1400 flags='-O2 -march=armv6'
1401 host="$ARCH-slitaz-linux-gnueabi" ;;
1402 armv6hf)
1403 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1404 host="$ARCH-slitaz-linux-gnueabi" ;;
1405 armv7)
1406 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1407 host="$ARCH-slitaz-linux-gnueabi" ;;
1408 x86_64)
1409 flags='-O2 -mtune=generic -pipe'
1410 host="$ARCH-slitaz-linux" ;;
1411 esac
1412 sed -i \
1413 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1414 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1415 . /etc/slitaz/cook.conf
1416 sysroot="$CROSS_TREE/sysroot"
1417 tools="/cross/$arch/tools"
1418 root="$sysroot"
1419 # L10n: keep the same width of translations to get a consistent view
1420 _ 'Target arch : %s' "$ARCH"
1421 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1422 _ 'Build flags : %s' "$flags"
1423 _ 'Arch sysroot : %s' "$sysroot"
1424 _ 'Tools prefix : %s' "$tools/bin"
1425 # Tell the packages manager where to find packages.
1426 _ 'Packages DB : %s' "$root$DB"
1427 mkdir -p $root$INSTALLED
1428 cd $root$DB; rm -f *.bak
1429 for list in packages.list packages.desc packages.equiv packages.md5; do
1430 rm -f $list
1431 ln -s $SLITAZ/packages/$list $list
1432 done
1433 # We must have the cross compiled glibc-base installed or default
1434 # i486 package will be used as dep by tazpkg and then break the
1435 # cross environment
1436 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1437 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1438 fi
1439 # Show GCC version or warn if not yet compiled.
1440 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1441 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1442 else
1443 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1444 _ 'Run "%s" to cook a toolchain' 'cross compile'
1445 fi
1446 footer ;;
1448 test)
1449 # Test a cook environment.
1450 _ 'Cook test: testing the cook environment' | log
1451 [ ! -d "$WOK" ] && exit 1
1452 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1453 cook cooktest ;;
1455 new)
1456 # Create the package folder and an empty receipt.
1457 pkg="$2"
1458 [ -z "$pkg" ] && usage
1459 newline
1460 if [ -d "$WOK/$pkg" ]; then
1461 _ 'Package "%s" already exists.' "$pkg"
1462 exit 1
1463 fi
1465 action 'Creating folder "%s"' "$WOK/$pkg"
1466 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1468 action 'Preparing the package receipt...'
1469 cp $DATA/receipt .
1470 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1471 status; newline
1473 # Interactive mode, asking and seding.
1474 case "$3" in
1475 --interactive|-x)
1476 _ 'Entering interactive mode...'
1477 separator
1478 _ 'Package : %s' "$pkg"
1480 _n 'Version : ' ; read answer
1481 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1483 _n 'Category : ' ; read answer
1484 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1486 # L10n: Short description
1487 _n 'Short desc : ' ; read answer
1488 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1490 _n 'Maintainer : ' ; read answer
1491 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1493 _n 'License : ' ; read answer
1494 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1496 _n 'Web site : ' ; read answer
1497 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1498 newline
1500 # Wget URL.
1501 _ 'Wget URL to download source tarball.'
1502 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1503 _n 'Wget url : ' ; read answer
1504 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1506 # Ask for a stuff dir.
1507 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1508 if [ "$?" -eq 0 ]; then
1509 action 'Creating the stuff directory...'
1510 mkdir $WOK/$pkg/stuff; status
1511 fi
1513 # Ask for a description file.
1514 confirm "$(_n 'Are you going to write a description? (y/N)')"
1515 if [ "$?" -eq 0 ]; then
1516 action 'Creating the "%s" file...' 'description.txt'
1517 touch $WOK/$pkg/description.txt; status
1518 fi
1520 footer "$(_ 'Receipt is ready to use.')" ;;
1521 esac ;;
1523 list)
1524 # Cook a list of packages (better use the Cooker since it will order
1525 # packages before executing cook).
1526 check_root
1527 if [ -z "$2" ]; then
1528 newline; _ 'No list in argument.'; newline
1529 exit 1
1530 fi
1531 if [ ! -f "$2" ]; then
1532 newline; _ 'List "%s" not found.' "$2"; newline
1533 exit 1
1534 fi
1536 _ 'Starting cooking the list "%s"' "$2" | log
1538 for pkg in $(cat $2); do
1539 cook $pkg || broken
1540 done ;;
1542 clean-wok)
1543 check_root
1544 newline; action 'Cleaning all packages files...'
1545 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1546 status; newline ;;
1548 clean-src)
1549 check_root
1550 newline; action 'Cleaning all packages sources...'
1551 rm -rf $WOK/*/source
1552 status; newline ;;
1554 uncook)
1555 cd $WOK
1556 count=0
1557 title 'Checking for uncooked packages'
1559 for pkg in *; do
1560 unset HOST_ARCH EXTRAVERSION
1561 [ ! -e $pkg/receipt ] && continue
1562 . $pkg/receipt
1563 # Source cooked pkg receipt to get EXTRAVERSION
1564 if [ -d "$WOK/$pkg/taz" ]; then
1565 cd $WOK/$pkg/taz/$pkg-*
1566 . receipt; cd $WOK
1567 fi
1568 case "$ARCH" in
1569 i486)
1570 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1571 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1572 count=$(($count + 1))
1573 colorize 34 "$pkg"
1574 fi ;;
1575 arm*)
1576 # Check only packages included in arch
1577 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1578 # *.tazpkg
1579 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1580 count=$(($count + 1))
1581 colorize 34 "$pkg"
1582 fi
1583 fi ;;
1584 esac
1585 done
1587 if [ "$count" -gt "0" ]; then
1588 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1589 else
1590 _ 'All packages are cooked :-)'
1591 newline
1592 fi
1593 ;;
1595 pkgdb)
1596 # Create suitable packages list for TazPKG and only for built packages
1597 # as well as flavors files for TazLiTo. We dont need logs since we do it
1598 # manually to ensure everything is fine before syncing the mirror.
1600 rm $LOGS/pkgdb.log 2>/dev/null
1602 case "$2" in
1603 --flavors|--rmpkg) ;;
1604 *)
1605 [ -n "$2" ] && PKGS="$2"
1606 if [ ! -d "$PKGS" ]; then
1607 { newline; _ "Packages directory \"%s\" doesn't exist" "$PKGS"; newline; } | dblog
1608 exit 1
1609 fi ;;
1610 esac
1612 time=$(date +%s)
1613 flavors="$SLITAZ/flavors"
1614 live="$SLITAZ/live"
1616 echo 'cook:pkgdb' > $command
1617 _ 'Cook pkgdb: Creating all packages lists' | log
1618 newline; { _ 'Creating lists for "%s"' "$PKGS"; separator; } | dblog
1620 { _ 'Cook pkgdb started: %s' "$(date "$(_ '+%%F %%R')")"; newline; } | dblog
1622 cd $PKGS
1623 rm -f packages.* extra.list
1624 touch packages.equiv
1626 _n 'Creating file "%s"' 'packages.list' | dblog
1627 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1628 echo " ($(filesize $PKGS/packages.list))" | dblog
1630 _n 'Creating file "%s"' 'packages.md5' | dblog
1631 md5sum *.tazpkg > $PKGS/packages.md5
1632 echo " ($(filesize $PKGS/packages.md5))" | dblog
1633 cp $PKGS/packages.md5 $PKGS/packages.toremove # list of duplicates
1635 md5sum packages.md5 | cut -d' ' -f1 > ID
1636 ( cat ./ID | tr $'\n' ' '; date -ur ./ID +%s ) > IDs # md5 and timestamp
1638 _n 'Creating file "%s"' 'descriptions.txt' | dblog
1639 rm $PKGS/descriptions.txt 2>/dev/null
1640 for i in $(ls $WOK | sort); do
1641 if [ -e "$WOK/$i/description.txt" ]; then
1642 echo "$i" >> descriptions.txt
1643 cat "$WOK/$i/description.txt" | sed 's|^$| |' >> descriptions.txt
1644 echo >> descriptions.txt
1645 fi
1646 done
1647 echo " ($(filesize $PKGS/descriptions.txt))" | dblog
1650 _ 'Creating lists from "%s"' "$WOK" | dblog
1651 cd $WOK
1652 for pkg in *; do
1653 unset_receipt
1654 . $pkg/receipt
1655 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1656 [ -s $pkg/taz/*/receipt ] && . $pkg/taz/*/receipt
1658 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ] || \
1659 [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1661 # packages.desc lets us search easily in DB
1662 cat >> $PKGS/packages.desc <<EOT
1663 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1664 EOT
1666 # packages.txt used by tazpkg and tazpkg-web also to provide
1667 # a human readable package list with version and description.
1668 cat >> $PKGS/packages.txt <<EOT
1669 $PACKAGE
1670 $VERSION$EXTRAVERSION
1671 $SHORT_DESC
1672 $PACKED_SIZE ($UNPACKED_SIZE installed)
1674 EOT
1676 # packages.info combines TazPkg separate files
1677 # and will substitute them all
1678 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1679 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
1680 MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" $PKGS/packages.md5 | awk '{print $1}')"
1681 cat >> $PKGS/packages.info <<EOT
1682 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5
1683 EOT
1685 # packages.equiv is used by tazpkg install to check depends.
1686 for i in $PROVIDE; do
1687 DEST=''
1688 echo $i | fgrep -q : && DEST="${i#*:}:"
1689 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1690 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1691 $PKGS/packages.equiv
1692 else
1693 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1694 fi
1695 done
1697 # files.list provides a list of all packages files.
1698 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1699 $PKGS/files.list
1701 # list of duplicates
1702 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg/d" $PKGS/packages.toremove
1703 else
1704 # if receipt variable HOST_ARCH absent/empty or contains ARCH
1705 if [ -z "$HOST_ARCH" -o "${HOST_ARCH/$ARCH/}" != "$HOST_ARCH" ]; then
1706 _ ' - absent: %s (%s)' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$ARCH" | dblog
1707 fi
1708 fi
1709 done
1711 # Display list size.
1712 _ 'Done: %s (%s)' 'packages.desc' "$(filesize $PKGS/packages.desc)" | dblog
1713 _ 'Done: %s (%s)' 'packages.txt' "$(filesize $PKGS/packages.txt)" | dblog
1714 _ 'Done: %s (%s)' 'packages.info' "$(filesize $PKGS/packages.info)" | dblog
1715 _ 'Done: %s (%s)' 'packages.equiv' "$(filesize $PKGS/packages.equiv)" | dblog
1717 cd $PKGS
1720 # Check package duplicates
1721 if [ -s "$PKGS/packages.toremove" ]; then
1722 newline | dblog
1723 _ 'Removing duplicates:' | dblog
1724 while read pkgsum pkgfile; do
1725 echo " - $pkgfile" | dblog
1726 sed -i "/${pkgfile%.tazpkg}/d" $PKGS/packages.list
1727 sed -i "/ $pkgfile/d" $PKGS/packages.md5
1728 [ -n "$rmpkg" ] && rm $PKGS/$pkgfile # remove packages only with --rmpkg
1729 done < $PKGS/packages.toremove
1730 newline | dblog
1731 fi
1732 rm $PKGS/packages.toremove
1735 # files.list.lzma
1736 _n 'Creating file "%s"' 'files.list.lzma' | dblog
1737 touch files.list
1738 # pkgs.slitaz.org strongly depends on list sorted by packages names
1739 lzma e files.list files.list.lzma
1740 echo " ($(filesize $PKGS/files.list.lzma))" | dblog
1742 # Pre-sorting filenames causes 10% smaller resulting lzma file
1743 _n 'Creating file "%s"' 'files-list.lzma' | dblog
1744 cat files.list | sort -k2 -o files.list.sorted
1745 lzma e files.list.sorted files-list.lzma
1746 rm -f files.list files.list.sorted
1747 echo " ($(filesize $PKGS/files-list.lzma))" | dblog
1749 [ -e files.list.md5 ] && rm files.list.md5
1750 md5sum files-list.lzma | cut -d' ' -f1 | tr -d $'\n' > files-list.md5
1752 # packages.info.lzma
1753 PI=packages.info
1754 _n 'Creating file "%s"' 'packages.info.lzma' | dblog
1755 touch $PI
1756 lzma e $PI $PI.lzma
1757 echo " ($(filesize $PKGS/packages.info.lzma))" | dblog
1759 # Make bundle to fast recharge
1760 _n 'Creating file "%s"' 'bundle.tar.lzma' | dblog
1761 [ -f bundle.tar.lzma ] && rm bundle.tar.lzma
1762 # Make sure to get "mirrors" file
1763 until [ -e 'mirrors' ]; do
1764 wget -q http://mirror1.slitaz.org/mirrors
1765 echo -n '.' | dblog; sleep 5
1766 done
1767 # Make sure to get "extra.list" file
1768 until [ -e 'extra.list' ]; do
1769 wget -q -O extra.list http://mirror1.slitaz.org/packages/get.list
1770 echo -n '.' | dblog; sleep 5
1771 done
1772 busybox tar -chaf bundle.tar.lzma \
1773 mirrors extra.list files-list.md5 packages.info descriptions.txt \
1774 packages.desc packages.md5 packages.txt packages.list packages.equiv
1775 rm ./mirrors
1776 echo " ($(filesize $PKGS/bundle.tar.lzma))" | dblog
1778 # Display some info.
1779 separator | dblog
1780 nb=$(ls $PKGS/*.tazpkg | wc -l)
1781 time=$(($(date +%s) - $time))
1782 # L10n: 's' is for seconds (cooking time)
1783 { _ 'Packages: %s - Time: %ss' "$nb" "$time"; newline; } | dblog
1786 # Create all flavors files at once. Do we really need code to monitor
1787 # flavors changes? Lets just build them with packages lists before
1788 # syncing the mirror.
1789 [ "$2" != '--flavors' ] && exit 1
1791 if [ ! -d "$flavors" ]; then
1792 { _ 'Missing flavors folder "%s"' "$flavors"; newline; } | dblog
1793 exit 1
1794 fi
1796 [ ! -d "$live" ] && mkdir -p $live
1797 _ 'Creating flavors files in "%s"' "$live" | dblog
1798 _ 'Cook pkgdb: Creating all flavors' | log
1799 separator | dblog
1801 _ 'Recharging lists to use latest packages...' | dblog
1802 tazpkg recharge >/dev/null 2>/dev/null
1804 # We need a custom tazlito config to set working dir to /home/slitaz.
1805 if [ ! -f "$live/tazlito.conf" ]; then
1806 _ 'Creating configuration file "%s"' 'tazlito.conf' | dblog
1807 cp /etc/tazlito/tazlito.conf $live
1808 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1809 $live/tazlito.conf
1810 fi
1812 # Update Hg flavors repo and pack.
1813 if [ -d "$flavors/.hg" ]; then
1814 cd $flavors; hg pull -u
1815 fi
1817 cd $live
1818 _ 'Starting to generate flavors...' | dblog
1819 rm -f flavors.list *.flavor
1820 for i in $flavors/*; do
1821 fl=$(basename $i)
1822 _ 'Packing flavor "%s"' "$fl" | dblog
1823 tazlito pack-flavor $fl >/dev/null || exit 1
1824 tazlito show-flavor $fl --brief --noheader 2>/dev/null >> flavors.list
1825 done
1826 cp -f $live/*.flavor $live/flavors.list $PKGS
1827 separator | dblog
1828 { _ 'Total flavors size: %s' "$(du -sh $live | awk '{print $1}')"; newline; } | dblog
1829 rm -f $command
1830 separator | dblog
1831 _ 'Cook pkgdb end: %s' "$(date "$(_ '+%%F %%R')")" | dblog
1832 ;;
1834 *)
1835 # Just cook and generate a package.
1836 check_root
1837 time=$(date +%s)
1838 pkg="$1"
1839 [ -z "$pkg" ] && usage
1840 lastcooktime=$(sed '/^Cook time/!d;s|.*: *\([0-9]*\)s.*|\1|' \
1841 $LOGS/$pkg.log 2> /dev/null | sed '$!d')
1842 receipt="$WOK/$pkg/receipt"
1843 check_pkg_in_wok
1844 newline
1846 unset inst
1847 unset_receipt
1848 . $receipt
1850 # Handle cross compilation.
1851 case "$ARCH" in
1852 arm*)
1853 if [ -z "$HOST_ARCH" ]; then
1854 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1855 error="$(_ 'package "%s" 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 newline
1860 exit 1
1861 fi ;;
1862 esac
1864 # Some packages are not included in some arch or fail to cross compile.
1865 : ${HOST_ARCH=i486}
1866 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1867 # Handle arm{v6hf,v7,..}
1868 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1869 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1870 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1871 _ 'cook: %s' "error"
1872 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1873 _ 'Cook skip: %s' "$error" | log
1874 sed -i /^${pkg}$/d $broken
1875 newline
1876 exit 0
1877 fi
1879 # Skip blocked, 3 lines also for the Cooker.
1880 if grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ]; then
1881 _ 'Package "%s" is blocked' "$pkg"; newline
1882 exit 0
1883 fi
1885 try_aufs_chroot "$@"
1887 # Log and source receipt.
1888 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1889 echo "cook:$pkg" > $command
1890 [ "$lastcooktime" ] &&
1891 echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1892 while read cmd duration start; do
1893 [ $(($start + $duration)) -lt $(date +%s) ] &&
1894 echo "sed -i '/^$cmd $duration/d' $cooktime"
1895 done < $cooktime | sh
1897 # Display and log info if cook process stopped.
1898 # FIXME: gettext not working (in single quotes) here!
1899 trap '_ "\n\nCook stopped: control-C\n\n" | \
1900 tee -a $LOGS/$pkg.log' INT
1902 # Handle --options
1903 case "$2" in
1904 --clean|-c)
1905 action 'Cleaning "%s"' "$pkg"
1906 cd $WOK/$pkg; rm -rf install taz source
1907 status; newline
1908 exit 0 ;;
1910 --install|-i)
1911 inst='yes' ;;
1913 --getsrc|-gs)
1914 title 'Getting source for "%s"' "$pkg"
1915 get_source
1916 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1917 exit 0 ;;
1919 --block|-b)
1920 action 'Blocking package "%s"' "$pkg"
1921 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1922 status; newline
1923 exit 0 ;;
1925 --unblock|-ub)
1926 action 'Unblocking package "%s"' "$pkg"
1927 sed -i "/^${pkg}$/"d $blocked
1928 status; newline
1929 exit 0 ;;
1931 --pack)
1932 if [ -d $WOK/$pkg/taz ]; then
1933 rm -rf $WOK/$pkg/taz
1934 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1935 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1936 clean_log
1937 else
1938 _ 'Need to build "%s"' "$pkg"
1939 exit 0
1940 fi
1941 exit 0 ;;
1943 --cdeps)
1944 if [ ! -d $WOK/$pkg/taz ]; then
1945 _ 'Need to build "%s"' "$pkg"
1946 exit 0
1947 fi
1949 title 'Checking depends'
1950 lddlist='/tmp/lddlist'; touch $lddlist
1951 missing='/var/cache/missing.file'
1953 # find all deps using ldd
1954 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
1955 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
1956 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
1957 done #"
1959 # remove exe/so duplicates
1960 sort -u $lddlist > $lddlist.sorted
1962 # search packages
1963 for exefile in $(cat $lddlist.sorted); do
1964 search_file $exefile
1965 echo "$found" >> $lddlist.pkgs
1966 echo -n '.'
1967 done
1968 echo
1970 # remove packages duplicates
1971 sort -u $lddlist.pkgs > $lddlist.final
1972 sort -u $missing > $missing.final
1973 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
1974 exit 0 ;;
1975 esac
1977 # Rotate log
1978 for i in $(seq 9 -1 1); do
1979 j=$(($i - 1))
1980 [ -e $LOGS/$pkg.log.$j ] &&
1981 mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
1982 done
1983 mv $LOGS/$pkg.log $LOGS/$pkg.log.0
1985 # Check if wanted is built now so we have separate log files.
1986 for wanted in $WANTED ; do
1987 if grep -q "^$wanted$" $blocked; then
1988 _ 'WANTED package "%s" is blocked' "$wanted" | tee $LOGS/$pkg.log
1989 newline
1990 rm -f $command
1991 exit 1
1992 fi
1993 if grep -q "^$wanted$" $broken; then
1994 _ 'WANTED package "%s" is broken' "$wanted" | tee $LOGS/$pkg.log
1995 newline
1996 rm -f $command
1997 exit 1
1998 fi
1999 if [ ! -d "$WOK/$wanted/install" ]; then
2000 cook "$wanted" || exit 1
2001 fi
2002 done
2004 # Cook and pack or exit on error and log everything.
2005 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
2006 remove_deps | tee -a $LOGS/$pkg.log
2007 cookit_quality
2008 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
2009 clean_log
2011 # Exit if any error in packing.
2012 lerror=$(_n 'ERROR')
2013 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
2014 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
2015 debug_info | tee -a $LOGS/$pkg.log
2016 rm -f $command
2017 exit 1
2018 fi
2020 # Create an XML feed
2021 gen_rss
2023 # Time and summary
2024 time=$(($(date +%s) - $time))
2025 summary | tee -a $LOGS/$pkg.log
2026 newline
2028 # We may want to install/update (outside aufs jail !).
2029 [ -s /aufs-umount.sh ] ||
2030 install_package
2032 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2033 # You want automation: use the Cooker Build Bot.
2034 rm -f $command ;;
2035 esac
2037 exit 0