cookutils view cook @ rev 800

cooker: fix a crash case (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed May 25 22:50:57 2016 +0200 (2016-05-25)
parents ac5b15a33b86
children b1245c114fec
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 }
572 # The main cook function.
574 cookit() {
575 title 'Cook: %s' "$PACKAGE $VERSION"
576 set_paths
578 # Handle cross-tools.
579 case "$ARCH" in
580 arm*|x86_64)
581 # CROSS_COMPILE is used by at least Busybox and the kernel to set
582 # the cross-tools prefix. Sysroot is the root of our target arch
583 sysroot="$CROSS_TREE/sysroot"
584 tools="$CROSS_TREE/tools"
585 # Set root path when cross compiling. ARM tested but not x86_64
586 # When cross compiling we must install build deps in $sysroot.
587 arch="-$ARCH"
588 root="$sysroot"
589 _ '%s sysroot: %s' "$ARCH" "$sysroot"
590 _ 'Adding "%s" to PATH' "$tools/bin"
591 export PATH="$PATH:$tools/bin"
592 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
593 export CROSS_COMPILE="$HOST_SYSTEM-"
594 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
595 if [ "$ARCH" == 'x86_64' ]; then
596 export CC="$HOST_SYSTEM-gcc -m64"
597 export CXX="$HOST_SYSTEM-g++ -m64"
598 else
599 export CC="$HOST_SYSTEM-gcc"
600 export CXX="$HOST_SYSTEM-g++"
601 fi
602 export AR="$HOST_SYSTEM-ar"
603 export AS="$HOST_SYSTEM-as"
604 export RANLIB="$HOST_SYSTEM-ranlib"
605 export LD="$HOST_SYSTEM-ld"
606 export STRIP="$HOST_SYSTEM-strip"
607 export LIBTOOL="$HOST_SYSTEM-libtool" ;;
608 esac
610 [ -n "$QA" ] && receipt_quality
611 cd $pkgdir
612 [ -z "$continue" ] && rm -rf source 2>/dev/null
613 rm -rf install taz 2>/dev/null
615 # Disable -pipe if less than 512Mb free RAM.
616 free=$(free | awk '/buffers:/{print $4}')
617 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
618 _ 'Disabling -pipe compile flag: %d RAM free' "$free"
619 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
620 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
621 fi
622 unset free
624 # Export flags and path to be used by make and receipt.
625 DESTDIR="$pkgdir/install"
626 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
627 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
628 #LDFLAGS
630 # Check for build deps and handle implicit depends of *-dev packages
631 # (ex: libusb-dev :: libusb).
632 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
633 touch $CACHE/installed.local $CACHE/installed.web
634 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
635 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
636 for dep in $BUILD_DEPENDS; do
637 implicit="${dep%-dev}"
638 # Don't add implicit dependency if it defined in DEPENDS
639 # echo '' $DEPENDS '' | fgrep -q " $implicit " && implicit=''
640 for i in $dep $implicit; do
641 if [ ! -f "$root$INSTALLED/$i/receipt" ]; then
642 # Try local package first. In some cases implicit doesn't exist, ex:
643 # libboost-dev exists but not libboost, so check if we got vers.
644 unset vers
645 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
646 # We may have a local package.
647 if [ -z "$vers" ]; then
648 vers=$(awk -F$'\t' -vp="$i" '$1==p{print $2; quit}' $PKGS/packages.info)
649 fi
650 debug "bdep: $i version: $vers"
651 if [ -f "$PKGS/$i-$vers$arch.tazpkg" ]; then
652 echo $i-$vers$arch.tazpkg >> $CACHE/installed.local
653 else
654 # Priority to package version in wok (maybe more up-to-date)
655 # than the mirrored one.
656 if [ -n "$vers" ]; then
657 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
658 echo $i >> $CACHE/installed.web
659 else
660 # So package exists in wok but not available.
661 _ 'Missing dep (wok/pkg): %s' "$i $vers"
662 echo $i >> $CACHE/missing.dep
663 fi
664 else
665 # Package is not in wok but may be in online repo.
666 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
667 echo $i >> $CACHE/installed.web
668 else
669 _ 'ERROR: unknown dep "%s"' "$i"
670 exit 1
671 fi
672 fi
673 fi
674 fi
675 done
676 done
678 # Get the list of installed packages
679 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
681 # Have we a missing build dep to cook?
682 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
683 _ 'Auto cook config is set: %s' "$AUTO_COOK"
684 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
685 for i in $(uniq $CACHE/missing.dep); do
686 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
687 tee -a $LOGS/$PACKAGE.log.$$
688 # programmers: next two messages are exact copy from remove_deps()
689 togrep1=$(_n 'Build dependencies to remove:')
690 togrep2=$(_n 'Removing:')
691 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
692 fgrep $togrep1 $LOGS/$i.log && \
693 fgrep $togrep2 $LOGS/$i.log && newline) | \
694 tee -a $LOGS/$PACKAGE.log.$$ && break
695 done
696 rm -f $CACHE/missing.dep
697 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
698 fi
700 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
701 # is enabled and cook fails we have ERROR in log, if no auto cook we have
702 # missing dep in cached file.
703 lerror=$(_n 'ERROR')
704 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
705 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
706 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
707 exit 1
708 fi
710 # Install local packages: package-version$arch
711 cd $PKGS
712 for i in $(uniq $CACHE/installed.local); do
713 _ 'Installing dep (pkg/local): %s' "$i"
714 tazpkg install $i --root=$root --local --quiet
715 done
717 # Install web or cached packages (if mirror is set to $PKGS we only
718 # use local packages).
719 for i in $(uniq $CACHE/installed.web); do
720 _ 'Installing dep (web/cache): %s' "$i"
721 tazpkg get-install $i --root=$root --quiet
722 done
724 update_installed_cook_diff
726 # Get source tarball and make sure we have source dir named:
727 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
728 # tarball if it exists.
729 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
730 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
731 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
732 LZMA_SRC=''
733 else
734 get_source || exit 1
735 fi
736 fi
737 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
738 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
739 if ! extract_source ; then
740 get_source
741 extract_source || exit 1
742 fi
743 if [ -n "$LZMA_SRC" ]; then
744 cd $pkgdir/source
745 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
746 mv tmp tmp-1; mkdir tmp
747 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
748 fi
749 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
750 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
751 fi
752 fi
753 cd $pkgdir/source/tmp
754 # Some archives are not well done and don't extract to one dir (ex lzma).
755 files=$(ls | wc -l)
756 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
757 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
758 mv * ../$PACKAGE-$VERSION/$TARBALL
759 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
760 mv * ../$PACKAGE-$VERSION
761 cd ..; rm -rf tmp
762 fi
764 # Libtool shared libs path hack.
765 case "$ARCH" in
766 arm*) cross libhack ;;
767 esac
769 # Execute receipt rules.
770 if grep -q ^compile_rules $receipt; then
771 _ 'Executing: %s' 'compile_rules'
772 echo "CFLAGS : $CFLAGS"
773 #echo "LDFLAGS : $LDFLAGS"
774 [ -d "$src" ] && cd $src
775 compile_rules $@ || exit 1
776 # Stay compatible with _pkg
777 [ -d "$src/_pkg" ] && mv $src/_pkg $install
778 # QA: compile_rules success so valid.
779 mkdir -p $install
780 else
781 # QA: no compile_rules so no error, valid.
782 mkdir -p $install
783 fi
784 footer
786 # Execute testsuite.
787 if grep -q ^testsuite $receipt; then
788 title 'Running testsuite'
789 testsuite $@ || exit 1
790 footer
791 fi
793 fix_desktop_files
794 update_installed_cook_diff force
795 }
798 # Cook quality assurance.
800 cookit_quality() {
801 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
802 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
803 fi
804 # ERROR can be echoed any time in cookit()
805 lerror=$(_n 'ERROR')
806 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
807 grep -Eq "(^$lerror|undefined reference to)" ; then
808 debug_info | tee -a $LOGS/$pkg.log
809 rm -f $command
810 exit 1
811 fi
812 }
815 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
816 # but it doesn't handle EXTRAVERSION.
818 packit() {
819 set_paths
821 # Handle cross compilation
822 case "$ARCH" in
823 arm*|x86_64) arch="-$ARCH" ;;
824 esac
826 title 'Pack: %s' "$PACKAGE $VERSION$arch"
828 if grep -q ^genpkg_rules $receipt; then
829 _ 'Executing: %s' 'genpkg_rules'
830 set -e; cd $pkgdir; mkdir -p $fs
831 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
832 $LOGS/$pkg.log
833 else
834 _ 'No packages rules: meta package'
835 mkdir -p $fs
836 fi
838 # First QA check to stop now if genpkg_rules failed.
839 lerror=$(_n 'ERROR')
840 if fgrep -q ^$lerror $LOGS/$pkg.log; then
841 exit 1
842 fi
844 cd $taz
845 for file in receipt description.txt; do
846 [ ! -f "../$file" ] && continue
847 action 'Copying "%s"...' "$file"
848 cp -f ../$file $pack; chown 0.0 $pack/$file; status
849 done
850 copy_generic_files
852 # Strip and stuff files.
853 strip_package
855 # Create files.list with redirecting find output.
856 action 'Creating the list of files...'
857 cd $fs
858 find . -type f -print > ../files.list
859 find . -type l -print >> ../files.list
860 cd ..; sed -i s/'^.'/''/ files.list
861 status
863 # Md5sum of files.
864 action 'Creating md5sum of files...'
865 while read file; do
866 [ -L "fs$file" ] && continue
867 [ -f "fs$file" ] || continue
868 case "$file" in
869 /lib/modules/*/modules.*|*.pyc) continue ;;
870 esac
871 md5sum "fs$file" | sed 's/ fs/ /'
872 done < files.list > md5sum
873 status
875 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
876 2>/dev/null | awk 'END{ print $1 }')
878 # Build cpio archives.
879 action 'Compressing the FS...'
880 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
881 rm -rf fs
882 status
884 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
885 2>/dev/null | awk 'END{ print $1 }')
887 action 'Updating receipt sizes...'
888 sed -i s/^PACKED_SIZE.*$// receipt
889 sed -i s/^UNPACKED_SIZE.*$// receipt
890 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
891 status
893 # Set extra version.
894 if [ -n "$EXTRAVERSION" ]; then
895 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
896 sed -i s/^EXTRAVERSION.*$// receipt
897 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
898 status
899 fi
901 # Compress.
902 action 'Creating full cpio archive...'
903 find . -print | cpio -o -H newc --quiet > \
904 ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
905 status
907 action 'Restoring original package tree...'
908 unlzma -c fs.cpio.lzma | cpio -idm --quiet
909 status
911 rm fs.cpio.lzma; cd ..
913 # QA and give info.
914 tazpkg=$(ls *.tazpkg)
915 packit_quality
916 footer "$(_ 'Package "%s" created' "$tazpkg")"
917 }
920 # Verify package quality and consistency.
922 packit_quality() {
923 #action 'QA: checking for broken link...'
924 #link=$(find $fs/usr -type l -follow)
925 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
926 #status
928 # Exit if any error found in log file.
929 lerror=$(_n 'ERROR')
930 if fgrep -q ^$lerror $LOGS/$pkg.log; then
931 rm -f $command
932 exit 1
933 fi
935 action 'QA: checking for empty package...'
936 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
937 if [ "$files" -eq 0 -a "$CATEGORY" != 'meta' ]; then
938 newline; _ 'ERROR: empty package'
939 rm -f $command
940 exit 1
941 else
942 :; status
943 # Find and remove old package(s)
944 tempd="$(mktemp -d)"; cd "$tempd"
945 for testpkg in $(ls $PKGS/$pkg-*.tazpkg 2> /dev/null); do
946 # Extract receipt from each matched package
947 cpio -F "$testpkg" -i receipt >/dev/null 2>&1
948 name=$(. receipt; echo $PACKAGE)
949 rm receipt
950 if [ "$name" == "$pkg" ]; then
951 action 'Removing old package "%s"' "$(basename "$testpkg")"
952 rm -f "$testpkg"
953 status
954 fi
955 done
956 rm -r "$tempd"
957 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
958 sed -i /^${pkg}$/d $broken
959 #action 'Removing source tree...'
960 #rm -f $WOK/$pkg/source; status
961 fi
962 }
965 # Reverse "cat" command: prints input lines in the reverse order
967 tac() {
968 sed '1!G;h;$!d' $1
969 }
972 # Install package on --install or update the chroot.
974 install_package() {
975 case "$ARCH" in
976 arm*|x86_64)
977 arch="-$ARCH"
978 root="$CROSS_TREE/sysroot" ;;
979 esac
980 # Install package if requested but skip install if target host doesn't
981 # match build system or it will break the build chroot.
982 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
983 if [ -n "$inst" ] && [ "$build" == "$ARCH" ]; then
984 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
985 cd $PKGS
986 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
987 else
988 _ 'Unable to install package, build has failed.'; newline
989 exit 1
990 fi
991 fi
993 # Install package if part of the chroot to keep env up-to-date.
994 if [ -d "$root$INSTALLED/$pkg" ]; then
995 . /etc/slitaz/cook.conf
996 . $WOK/$pkg/taz/$pkg-*/receipt
997 _ 'Updating %s chroot environment...' "$ARCH"
998 _ 'Updating chroot: %s' "$pkg ($VERSION$EXTRAVERSION$arch)" | log
999 cd $PKGS
1000 tazpkg install $pkg-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1001 fi
1005 # remove chroot jail
1007 umount_aufs() {
1008 tac ${1}rw/aufs-umount.sh | sh
1009 rm -rf ${1}rw
1010 umount ${1}root
1011 rmdir ${1}r*
1015 # Launch the cook command into a chroot jail protected by aufs.
1016 # The current filesystems are used read-only and updates are
1017 # stored in a separate branch.
1019 try_aufs_chroot() {
1021 base="/dev/shm/aufsmnt$$"
1023 # Can we setup the chroot? Is it already done?
1024 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1025 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1026 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1027 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
1028 mkdir ${base}root ${base}rw || return
1030 _ 'Setup aufs chroot...'
1032 # Sanity check
1033 for i in / /proc /sys /dev/shm /home ; do
1034 case " $AUFS_MOUNTS " in
1035 *\ $i\ *) ;;
1036 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1037 esac
1038 done
1039 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1040 mount --bind $mnt ${base}root$mnt
1041 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1042 _ 'Aufs mount failure'
1043 umount ${base}root
1044 rm -rf ${base}r*
1045 return
1046 fi
1047 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1048 done
1049 trap "umount_aufs ${base}" INT
1051 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1052 status=$?
1054 _ 'Leaving aufs chroot...'
1055 umount_aufs $base
1056 # Install package outside the aufs jail
1057 install_package
1058 exit $status
1062 # Encode predefined XML entities
1064 xml_ent() {
1065 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1069 # Create a XML feed for freshly built packages.
1071 gen_rss() {
1072 pubdate=$(date '+%a, %d %b %Y %X')
1073 cat > $FEEDS/$pkg.xml <<EOT
1074 <item>
1075 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1076 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1077 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1078 <pubDate>$pubdate</pubDate>
1079 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1080 </item>
1081 EOT
1085 # Truncate stdout log file to $1 Mb.
1087 loglimit() {
1088 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1089 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1090 else
1091 tee /dev/stderr
1092 fi
1096 # Search file in mirrored packages
1098 search_file_mirror() {
1099 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
1103 # Search file in local wok packages
1105 search_file_local() {
1106 # existing packages have precedence over the package/taz folder
1107 srch=$1
1108 { for package in $(find $PKGS -name '*.tazpkg'); do
1109 if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
1110 grep /$srch\$)" ]; then
1111 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
1112 fi
1113 done } | sort -u
1117 # Ask in multiple choice
1119 ask_multiple() {
1120 local multiples first my_choice
1121 multiples="$1"
1122 first=$(echo "$multiples" | head -n1)
1123 newline; _ 'Multiple choice:'; echo "$multiples"; newline
1124 _ 'Select one [%s]: ' "$first"; read my_choice
1125 found="${my_choice:-$first}"
1129 # Search file in local cache (fast), local wok packages, mirrored packages
1131 search_file() {
1132 local srch cache missing
1133 srch="$1"
1134 cache='/var/cache/ldsearch.cache'
1135 missing='/var/cache/missing.file'
1136 touch $cache $missing
1137 found=$(grep $srch $cache | cut -d$'\t' -f2)
1138 if [ -z "$found" ]; then
1139 found=$(search_file_local $srch)
1140 if [ -n "$found" ]; then
1141 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1142 ask_multiple "$found"
1143 fi
1144 echo -e "$srch\t$found" >> $cache
1145 else
1146 found=$(search_file_mirror $srch)
1147 if [ -n "$found" ]; then
1148 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1149 ask_multiple "$found"
1150 fi
1151 echo -e "$srch\t$found" >> $cache
1152 else
1153 echo "$srch" >> $missing
1154 fi
1155 fi
1156 fi
1160 # Return size of file in human readible format
1161 # Note, "du" in opposite returns size occupied by file on disk (4KB multiple in most cases)
1162 filesize() {
1163 busybox ls -lh "$1" | awk '{print $5 "B"}'
1168 # Receipt functions to ease packaging
1171 get_dev_files() {
1172 action 'Getting standard devel files...'
1173 mkdir -p $fs/usr/lib
1174 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1175 cp -a $install/usr/lib/*a $fs/usr/lib
1176 cp -a $install/usr/include $fs/usr
1177 status
1180 dblog() { tee -a $LOGS/pkgdb.log; }
1186 # Commands
1189 case "$1" in
1190 usage|help|-u|-h)
1191 usage ;;
1193 list-wok)
1194 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1195 cd $WOK
1196 if [ "$ARCH" != 'i486' ]; then
1197 count=0
1198 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1199 do
1200 unset HOST_ARCH
1201 . $pkg
1202 count=$(($count + 1))
1203 colorize 34 "$PACKAGE"
1204 done
1205 else
1206 count=$(ls | wc -l)
1207 ls -1
1208 fi
1209 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1210 ;;
1212 activity)
1213 cat $activity ;;
1215 search)
1216 # Just a simple search function, we dont need more actually.
1217 query="$2"
1218 title 'Search results for "%s"' "$query"
1219 cd $WOK; ls -1 | grep "$query"
1220 footer ;;
1222 setup)
1223 # Setup a build environment
1224 check_root
1225 _ 'Cook: setup environment' | log
1226 title 'Setting up your environment'
1227 cd $SLITAZ
1228 init_db_files
1229 _ 'Checking for packages to install...'
1230 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1231 # ARCH-setup or 'cross check' should be used before: cook setup
1232 case "$ARCH" in
1233 arm*|x86_64)
1234 if [ ! -x '/usr/bin/cross' ]; then
1235 _ 'ERROR: %s is not installed' 'cross'
1236 exit 1
1237 fi
1238 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1239 . /etc/slitaz/cross.conf ;;
1240 esac
1241 for pkg in $SETUP_PKGS; do
1242 if [ -n "$forced" ]; then
1243 tazpkg -gi $pkg --forced
1244 else
1245 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1246 fi
1247 done
1249 # Handle --options
1250 case "$2" in
1251 --wok) hg clone $WOK_URL wok || exit 1 ;;
1252 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1253 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1254 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1255 esac
1257 # SliTaz group and permissions
1258 if ! grep -q ^slitaz /etc/group; then
1259 _ 'Adding group "%s"' 'slitaz'
1260 addgroup slitaz
1261 fi
1262 _ 'Setting permissions for group "%s"...' 'slitaz'
1263 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1264 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1265 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1267 *-setup)
1268 # Setup for cross compiling.
1269 arch="${1%-setup}"
1270 check_root
1271 . /etc/slitaz/cook.conf
1272 for pkg in $CROSS_SETUP; do
1273 if [ -n "$forced" ]; then
1274 tazpkg -gi $pkg --forced
1275 else
1276 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1277 fi
1278 done
1280 _ 'Cook: setup %s cross environment' "$arch" | log
1281 title 'Setting up your %s cross environment' "$arch"
1282 init_db_files
1283 sed -i \
1284 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1285 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1286 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1287 /etc/slitaz/cook.conf
1288 case "$arch" in
1289 arm)
1290 flags='-O2 -march=armv6'
1291 host="$ARCH-slitaz-linux-gnueabi" ;;
1292 armv6hf)
1293 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1294 host="$ARCH-slitaz-linux-gnueabi" ;;
1295 armv7)
1296 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1297 host="$ARCH-slitaz-linux-gnueabi" ;;
1298 x86_64)
1299 flags='-O2 -mtune=generic -pipe'
1300 host="$ARCH-slitaz-linux" ;;
1301 esac
1302 sed -i \
1303 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1304 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1305 . /etc/slitaz/cook.conf
1306 sysroot="$CROSS_TREE/sysroot"
1307 tools="/cross/$arch/tools"
1308 root="$sysroot"
1309 # L10n: keep the same width of translations to get a consistent view
1310 _ 'Target arch : %s' "$ARCH"
1311 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1312 _ 'Build flags : %s' "$flags"
1313 _ 'Arch sysroot : %s' "$sysroot"
1314 _ 'Tools prefix : %s' "$tools/bin"
1315 # Tell the packages manager where to find packages.
1316 _ 'Packages DB : %s' "$root$DB"
1317 mkdir -p $root$INSTALLED
1318 cd $root$DB; rm -f *.bak
1319 for list in packages.list packages.desc packages.equiv packages.md5; do
1320 rm -f $list
1321 ln -s $SLITAZ/packages/$list $list
1322 done
1323 # We must have the cross compiled glibc-base installed or default
1324 # i486 package will be used as dep by tazpkg and then break the
1325 # cross environment
1326 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1327 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1328 fi
1329 # Show GCC version or warn if not yet compiled.
1330 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1331 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1332 else
1333 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1334 _ 'Run "%s" to cook a toolchain' 'cross compile'
1335 fi
1336 footer ;;
1338 test)
1339 # Test a cook environment.
1340 _ 'Cook test: testing the cook environment' | log
1341 [ ! -d "$WOK" ] && exit 1
1342 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1343 cook cooktest ;;
1345 new)
1346 # Create the package folder and an empty receipt.
1347 pkg="$2"
1348 [ -z "$pkg" ] && usage
1349 newline
1350 if [ -d "$WOK/$pkg" ]; then
1351 _ 'Package "%s" already exists.' "$pkg"
1352 exit 1
1353 fi
1355 action 'Creating folder "%s"' "$WOK/$pkg"
1356 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1358 action 'Preparing the package receipt...'
1359 cp $DATA/receipt .
1360 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1361 status; newline
1363 # Interactive mode, asking and seding.
1364 case "$3" in
1365 --interactive|-x)
1366 _ 'Entering interactive mode...'
1367 separator
1368 _ 'Package : %s' "$pkg"
1370 _n 'Version : ' ; read answer
1371 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1373 _n 'Category : ' ; read answer
1374 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1376 # L10n: Short description
1377 _n 'Short desc : ' ; read answer
1378 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1380 _n 'Maintainer : ' ; read answer
1381 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1383 _n 'License : ' ; read answer
1384 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1386 _n 'Web site : ' ; read answer
1387 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1388 newline
1390 # Wget URL.
1391 _ 'Wget URL to download source tarball.'
1392 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1393 _n 'Wget url : ' ; read answer
1394 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1396 # Ask for a stuff dir.
1397 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1398 if [ "$?" -eq 0 ]; then
1399 action 'Creating the stuff directory...'
1400 mkdir $WOK/$pkg/stuff; status
1401 fi
1403 # Ask for a description file.
1404 confirm "$(_n 'Are you going to write a description? (y/N)')"
1405 if [ "$?" -eq 0 ]; then
1406 action 'Creating the "%s" file...' 'description.txt'
1407 touch $WOK/$pkg/description.txt; status
1408 fi
1410 footer "$(_ 'Receipt is ready to use.')" ;;
1411 esac ;;
1413 list)
1414 # Cook a list of packages (better use the Cooker since it will order
1415 # packages before executing cook).
1416 check_root
1417 if [ -z "$2" ]; then
1418 newline; _ 'No list in argument.'; newline
1419 exit 1
1420 fi
1421 if [ ! -f "$2" ]; then
1422 newline; _ 'List "%s" not found.' "$2"; newline
1423 exit 1
1424 fi
1426 _ 'Starting cooking the list "%s"' "$2" | log
1428 for pkg in $(cat $2); do
1429 cook $pkg || broken
1430 done ;;
1432 clean-wok)
1433 check_root
1434 newline; action 'Cleaning all packages files...'
1435 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1436 status; newline ;;
1438 clean-src)
1439 check_root
1440 newline; action 'Cleaning all packages sources...'
1441 rm -rf $WOK/*/source
1442 status; newline ;;
1444 uncook)
1445 cd $WOK
1446 count=0
1447 title 'Checking for uncooked packages'
1449 for pkg in *; do
1450 unset HOST_ARCH EXTRAVERSION
1451 [ ! -e $pkg/receipt ] && continue
1452 . $pkg/receipt
1453 # Source cooked pkg receipt to get EXTRAVERSION
1454 if [ -d "$WOK/$pkg/taz" ]; then
1455 cd $WOK/$pkg/taz/$pkg-*
1456 . receipt; cd $WOK
1457 fi
1458 case "$ARCH" in
1459 i486)
1460 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1461 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1462 count=$(($count + 1))
1463 colorize 34 "$pkg"
1464 fi ;;
1465 arm*)
1466 # Check only packages included in arch
1467 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1468 # *.tazpkg
1469 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1470 count=$(($count + 1))
1471 colorize 34 "$pkg"
1472 fi
1473 fi ;;
1474 esac
1475 done
1477 if [ "$count" -gt "0" ]; then
1478 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1479 else
1480 _ 'All packages are cooked :-)'
1481 newline
1482 fi
1483 ;;
1485 pkgdb)
1486 # Create suitable packages list for TazPKG and only for built packages
1487 # as well as flavors files for TazLiTo. We dont need logs since we do it
1488 # manually to ensure everything is fine before syncing the mirror.
1490 rm $LOGS/pkgdb.log 2>/dev/null
1492 case "$2" in
1493 --flavors|--rmpkg) ;;
1494 *)
1495 [ -n "$2" ] && PKGS="$2"
1496 if [ ! -d "$PKGS" ]; then
1497 { newline; _ "Packages directory \"%s\" doesn't exist" "$PKGS"; newline; } | dblog
1498 exit 1
1499 fi ;;
1500 esac
1502 time=$(date +%s)
1503 flavors="$SLITAZ/flavors"
1504 live="$SLITAZ/live"
1506 echo 'cook:pkgdb' > $command
1507 _ 'Cook pkgdb: Creating all packages lists' | log
1508 newline; { _ 'Creating lists for "%s"' "$PKGS"; separator; } | dblog
1510 { _ 'Cook pkgdb started: %s' "$(date "$(_ '+%%F %%R')")"; newline; } | dblog
1512 cd $PKGS
1513 rm -f packages.* extra.list
1514 touch packages.equiv
1516 _n 'Creating file "%s"' 'packages.list' | dblog
1517 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1518 echo " ($(filesize $PKGS/packages.list))" | dblog
1520 _n 'Creating file "%s"' 'packages.md5' | dblog
1521 md5sum *.tazpkg > $PKGS/packages.md5
1522 echo " ($(filesize $PKGS/packages.md5))" | dblog
1523 cp $PKGS/packages.md5 $PKGS/packages.toremove # list of duplicates
1525 md5sum packages.md5 | cut -d' ' -f1 > ID
1526 ( cat ./ID | tr $'\n' ' '; date -ur ./ID +%s ) > IDs # md5 and timestamp
1528 _n 'Creating file "%s"' 'descriptions.txt' | dblog
1529 rm $PKGS/descriptions.txt 2>/dev/null
1530 for i in $(ls $WOK | sort); do
1531 if [ -e "$WOK/$i/description.txt" ]; then
1532 echo "$i" >> descriptions.txt
1533 cat "$WOK/$i/description.txt" | sed 's|^$| |' >> descriptions.txt
1534 echo >> descriptions.txt
1535 fi
1536 done
1537 echo " ($(filesize $PKGS/descriptions.txt))" | dblog
1540 _ 'Creating lists from "%s"' "$WOK" | dblog
1541 cd $WOK
1542 for pkg in *; do
1543 unset_receipt
1544 . $pkg/receipt
1545 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1546 [ -s $pkg/taz/*/receipt ] && . $pkg/taz/*/receipt
1548 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ] || \
1549 [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1551 # packages.desc lets us search easily in DB
1552 cat >> $PKGS/packages.desc <<EOT
1553 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1554 EOT
1556 # packages.txt used by tazpkg and tazpkg-web also to provide
1557 # a human readable package list with version and description.
1558 cat >> $PKGS/packages.txt <<EOT
1559 $PACKAGE
1560 $VERSION$EXTRAVERSION
1561 $SHORT_DESC
1562 $PACKED_SIZE ($UNPACKED_SIZE installed)
1564 EOT
1566 # packages.info combines TazPkg separate files
1567 # and will substitute them all
1568 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1569 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
1570 MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" $PKGS/packages.md5 | awk '{print $1}')"
1571 cat >> $PKGS/packages.info <<EOT
1572 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5
1573 EOT
1575 # packages.equiv is used by tazpkg install to check depends.
1576 for i in $PROVIDE; do
1577 DEST=''
1578 echo $i | fgrep -q : && DEST="${i#*:}:"
1579 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1580 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1581 $PKGS/packages.equiv
1582 else
1583 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1584 fi
1585 done
1587 # files.list provides a list of all packages files.
1588 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1589 $PKGS/files.list
1591 # list of duplicates
1592 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg/d" $PKGS/packages.toremove
1593 else
1594 # if receipt variable HOST_ARCH absent/empty or contains ARCH
1595 if [ -z "$HOST_ARCH" -o "${HOST_ARCH/$ARCH/}" != "$HOST_ARCH" ]; then
1596 _ ' - absent: %s (%s)' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$ARCH" | dblog
1597 fi
1598 fi
1599 done
1601 # Display list size.
1602 _ 'Done: %s (%s)' 'packages.desc' "$(filesize $PKGS/packages.desc)" | dblog
1603 _ 'Done: %s (%s)' 'packages.txt' "$(filesize $PKGS/packages.txt)" | dblog
1604 _ 'Done: %s (%s)' 'packages.info' "$(filesize $PKGS/packages.info)" | dblog
1605 _ 'Done: %s (%s)' 'packages.equiv' "$(filesize $PKGS/packages.equiv)" | dblog
1607 cd $PKGS
1610 # Check package duplicates
1611 if [ -s "$PKGS/packages.toremove" ]; then
1612 newline | dblog
1613 _ 'Removing duplicates:' | dblog
1614 while read pkgsum pkgfile; do
1615 echo " - $pkgfile" | dblog
1616 sed -i "/${pkgfile%.tazpkg}/d" $PKGS/packages.list
1617 sed -i "/ $pkgfile/d" $PKGS/packages.md5
1618 [ -n "$rmpkg" ] && rm $PKGS/$pkgfile # remove packages only with --rmpkg
1619 done < $PKGS/packages.toremove
1620 newline | dblog
1621 fi
1622 rm $PKGS/packages.toremove
1625 # files.list.lzma
1626 _n 'Creating file "%s"' 'files.list.lzma' | dblog
1627 touch files.list
1628 # pkgs.slitaz.org strongly depends on list sorted by packages names
1629 lzma e files.list files.list.lzma
1630 echo " ($(filesize $PKGS/files.list.lzma))" | dblog
1632 # Pre-sorting filenames causes 10% smaller resulting lzma file
1633 _n 'Creating file "%s"' 'files-list.lzma' | dblog
1634 cat files.list | sort -k2 -o files.list.sorted
1635 lzma e files.list.sorted files-list.lzma
1636 rm -f files.list files.list.sorted
1637 echo " ($(filesize $PKGS/files-list.lzma))" | dblog
1639 [ -e files.list.md5 ] && rm files.list.md5
1640 md5sum files-list.lzma | cut -d' ' -f1 | tr -d $'\n' > files-list.md5
1642 # packages.info.lzma
1643 PI=packages.info
1644 _n 'Creating file "%s"' 'packages.info.lzma' | dblog
1645 touch $PI
1646 lzma e $PI $PI.lzma
1647 echo " ($(filesize $PKGS/packages.info.lzma))" | dblog
1649 # Make bundle to fast recharge
1650 _n 'Creating file "%s"' 'bundle.tar.lzma' | dblog
1651 [ -f bundle.tar.lzma ] && rm bundle.tar.lzma
1652 # Make sure to get "mirrors" file
1653 until [ -e 'mirrors' ]; do
1654 wget -q http://mirror1.slitaz.org/mirrors
1655 echo -n '.' | dblog; sleep 5
1656 done
1657 # Make sure to get "extra.list" file
1658 until [ -e 'extra.list' ]; do
1659 wget -q -O extra.list http://mirror1.slitaz.org/packages/get.list
1660 echo -n '.' | dblog; sleep 5
1661 done
1662 busybox tar -chaf bundle.tar.lzma \
1663 mirrors extra.list files-list.md5 packages.info descriptions.txt \
1664 packages.desc packages.md5 packages.txt packages.list packages.equiv
1665 rm ./mirrors
1666 echo " ($(filesize $PKGS/bundle.tar.lzma))" | dblog
1668 # Display some info.
1669 separator | dblog
1670 nb=$(ls $PKGS/*.tazpkg | wc -l)
1671 time=$(($(date +%s) - $time))
1672 # L10n: 's' is for seconds (cooking time)
1673 { _ 'Packages: %s - Time: %ss' "$nb" "$time"; newline; } | dblog
1676 # Create all flavors files at once. Do we really need code to monitor
1677 # flavors changes? Lets just build them with packages lists before
1678 # syncing the mirror.
1679 [ "$2" != '--flavors' ] && exit 1
1681 if [ ! -d "$flavors" ]; then
1682 { _ 'Missing flavors folder "%s"' "$flavors"; newline; } | dblog
1683 exit 1
1684 fi
1686 [ ! -d "$live" ] && mkdir -p $live
1687 _ 'Creating flavors files in "%s"' "$live" | dblog
1688 _ 'Cook pkgdb: Creating all flavors' | log
1689 separator | dblog
1691 _ 'Recharging lists to use latest packages...' | dblog
1692 tazpkg recharge >/dev/null 2>/dev/null
1694 # We need a custom tazlito config to set working dir to /home/slitaz.
1695 if [ ! -f "$live/tazlito.conf" ]; then
1696 _ 'Creating configuration file "%s"' 'tazlito.conf' | dblog
1697 cp /etc/tazlito/tazlito.conf $live
1698 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1699 $live/tazlito.conf
1700 fi
1702 # Update Hg flavors repo and pack.
1703 if [ -d "$flavors/.hg" ]; then
1704 cd $flavors; hg pull -u
1705 fi
1707 cd $live
1708 _ 'Starting to generate flavors...' | dblog
1709 rm -f flavors.list *.flavor
1710 for i in $flavors/*; do
1711 fl=$(basename $i)
1712 _ 'Packing flavor "%s"' "$fl" | dblog
1713 tazlito pack-flavor $fl >/dev/null || exit 1
1714 tazlito show-flavor $fl --brief --noheader 2>/dev/null >> flavors.list
1715 done
1716 cp -f $live/*.flavor $live/flavors.list $PKGS
1717 separator | dblog
1718 { _ 'Total flavors size: %s' "$(du -sh $live | awk '{print $1}')"; newline; } | dblog
1719 rm -f $command
1720 separator | dblog
1721 _ 'Cook pkgdb end: %s' "$(date "$(_ '+%%F %%R')")" | dblog
1722 ;;
1724 *)
1725 # Just cook and generate a package.
1726 check_root
1727 time=$(date +%s)
1728 pkg="$1"
1729 [ -z "$pkg" ] && usage
1730 lastcooktime=$(sed '/^Cook time/!d;s|.*: *\([0-9]*\)s.*|\1|' \
1731 $LOGS/$pkg.log 2> /dev/null | sed '$!d')
1732 receipt="$WOK/$pkg/receipt"
1733 check_pkg_in_wok
1734 newline
1736 unset inst
1737 unset_receipt
1738 . $receipt
1740 # Handle cross compilation.
1741 case "$ARCH" in
1742 arm*)
1743 if [ -z "$HOST_ARCH" ]; then
1744 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1745 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1746 _ 'cook: %s' "$error"
1747 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1748 _ 'Cook skip: %s' "$error" | log
1749 newline
1750 exit 1
1751 fi ;;
1752 esac
1754 # Some packages are not included in some arch or fail to cross compile.
1755 : ${HOST_ARCH=i486}
1756 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1757 # Handle arm{v6hf,v7,..}
1758 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1759 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1760 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1761 _ 'cook: %s' "error"
1762 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1763 _ 'Cook skip: %s' "$error" | log
1764 sed -i /^${pkg}$/d $broken
1765 newline
1766 exit 0
1767 fi
1769 # Skip blocked, 3 lines also for the Cooker.
1770 if grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ]; then
1771 _ 'Package "%s" is blocked' "$pkg"; newline
1772 exit 0
1773 fi
1775 try_aufs_chroot "$@"
1777 # Log and source receipt.
1778 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1779 echo "cook:$pkg" > $command
1780 [ "$lastcooktime" ] &&
1781 echo "cook:$pkg $lastcooktime $(date +%s)" > $cooktime
1783 # Display and log info if cook process stopped.
1784 # FIXME: gettext not working (in single quotes) here!
1785 trap '_ "\n\nCook stopped: control-C\n\n" | \
1786 tee -a $LOGS/$pkg.log' INT
1788 # Handle --options
1789 case "$2" in
1790 --clean|-c)
1791 action 'Cleaning "%s"' "$pkg"
1792 cd $WOK/$pkg; rm -rf install taz source
1793 status; newline
1794 exit 0 ;;
1796 --install|-i)
1797 inst='yes' ;;
1799 --getsrc|-gs)
1800 title 'Getting source for "%s"' "$pkg"
1801 get_source
1802 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1803 exit 0 ;;
1805 --block|-b)
1806 action 'Blocking package "%s"' "$pkg"
1807 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1808 status; newline
1809 exit 0 ;;
1811 --unblock|-ub)
1812 action 'Unblocking package "%s"' "$pkg"
1813 sed -i "/^${pkg}$/"d $blocked
1814 status; newline
1815 exit 0 ;;
1817 --pack)
1818 if [ -d $WOK/$pkg/taz ]; then
1819 rm -rf $WOK/$pkg/taz
1820 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1821 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1822 clean_log
1823 else
1824 _ 'Need to build "%s"' "$pkg"
1825 exit 0
1826 fi
1827 exit 0 ;;
1829 --cdeps)
1830 if [ ! -d $WOK/$pkg/taz ]; then
1831 _ 'Need to build "%s"' "$pkg"
1832 exit 0
1833 fi
1835 title 'Checking depends'
1836 lddlist='/tmp/lddlist'; touch $lddlist
1837 missing='/var/cache/missing.file'
1839 # find all deps using ldd
1840 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
1841 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
1842 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
1843 done #"
1845 # remove exe/so duplicates
1846 sort -u $lddlist > $lddlist.sorted
1848 # search packages
1849 for exefile in $(cat $lddlist.sorted); do
1850 search_file $exefile
1851 echo "$found" >> $lddlist.pkgs
1852 echo -n '.'
1853 done
1854 echo
1856 # remove packages duplicates
1857 sort -u $lddlist.pkgs > $lddlist.final
1858 sort -u $missing > $missing.final
1859 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
1860 exit 0 ;;
1861 esac
1863 # Rotate log
1864 for i in $(seq 9 -1 1); do
1865 j=$(($i - 1))
1866 [ -e $LOGS/$pkg.log.$j ] &&
1867 mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
1868 done
1869 mv $LOGS/$pkg.log $LOGS/$pkg.log.0
1871 # Check if wanted is built now so we have separate log files.
1872 for wanted in $WANTED ; do
1873 if grep -q "^$wanted$" $blocked; then
1874 _ 'WANTED package "%s" is blocked' "$wanted" | tee $LOGS/$pkg.log
1875 newline
1876 rm -f $command
1877 exit 1
1878 fi
1879 if grep -q "^$wanted$" $broken; then
1880 _ 'WANTED package "%s" is broken' "$wanted" | tee $LOGS/$pkg.log
1881 newline
1882 rm -f $command
1883 exit 1
1884 fi
1885 if [ ! -d "$WOK/$wanted/install" ]; then
1886 cook "$wanted" || exit 1
1887 fi
1888 done
1890 # Cook and pack or exit on error and log everything.
1891 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1892 remove_deps | tee -a $LOGS/$pkg.log
1893 cookit_quality
1894 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1895 clean_log
1897 # Exit if any error in packing.
1898 lerror=$(_n 'ERROR')
1899 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1900 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
1901 debug_info | tee -a $LOGS/$pkg.log
1902 rm -f $command
1903 exit 1
1904 fi
1906 # Create an XML feed
1907 gen_rss
1909 # Time and summary
1910 time=$(($(date +%s) - $time))
1911 summary | tee -a $LOGS/$pkg.log
1912 newline
1914 # We may want to install/update (outside aufs jail !).
1915 [ -s /aufs-umount.sh ] ||
1916 install_package
1918 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1919 # You want automation: use the Cooker Build Bot.
1920 rm -f $command ;;
1921 esac
1923 exit 0