cookutils view cook @ rev 34
cook: improve debug info and function
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri May 06 19:12:33 2011 +0200 (2011-05-06) |
parents | 62bf9ac888b1 |
children | e1a3c5900648 |
line source
1 #!/bin/sh
2 #
3 # Cook - A tool to cook and generate SliTaz packages. Read the README
4 # before adding or modifing any code in cook!
5 #
6 # Copyright (C) SliTaz GNU/Linux - GNU gpl v3
7 # Author: Christophe Lincoln <pankso@slitaz.org>
8 #
10 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
11 [ -f "cook.conf" ] && . ./cook.conf
13 # Share DB and status with the Cooker.
14 activity="$CACHE/activity"
15 command="$CACHE/command"
16 broken="$CACHE/broken"
18 #
19 # Functions
20 #
22 usage() {
23 cat << EOT
25 $(echo -e "\033[1m$(gettext "Usage:")\033[0m") cook [package|command|list] [--option]
27 $(echo -e "\033[1m$(gettext "Commands:")\033[0m")
28 usage|help $(gettext "Display this short usage.")
29 list-wok $(gettext "List packages in the wok.")
30 setup $(gettext "Setup your build environment.")
31 test $(gettext "Test environment and cook a package.")
32 new $(gettext "Create a new package with receipt".)
33 list $(gettext "Cook a list of packages.")
34 clean-wok $(gettext "Clean-up all packages files.")
35 clean-src $(gettext "Clean-up all packages source.")
36 pkglist $(gettext "Create all packages.* lists.")
38 $(echo -e "\033[1m$(gettext "Options:")\033[0m")
39 --clean|-c Cook : $(gettext "clean the package in the wok.")
40 --install|-i Cook : $(gettext "and install the package.")
41 --wok|-w Setup: $(gettext "create also a wok from Hg repo.")
43 EOT
44 exit 0
45 }
47 # Be sure we root.
48 check_root() {
49 [ $(id -u) != 0 ] && gettext -e "\nYou must be root to cook.\n\n" && exit 0
50 }
52 separator() {
53 echo "================================================================================"
54 }
56 status() {
57 echo -en "\\033[70G[ "
58 if [ $? = 0 ]; then
59 echo -en "\\033[1;32mOK"
60 else
61 echo -en "\\033[1;31mFailed"
62 fi
63 echo -e "\\033[0;39m ]"
64 }
66 # Log activities, we want first letter capitalized.
67 log() {
68 grep ^[A-Z] | \
69 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
70 }
72 # We dont want those escape in web interface.
73 clean_log() {
74 sed -i -e s'|\[70G\[ \[1;32m| |' \
75 -e s'|\[0;39m \]||' $LOGS/$pkg.log
76 }
78 # Log broken packages.
79 broken() {
80 echo "$pkg" >> $broken
81 }
83 # Be sure package exist in wok.
84 check_pkg_in_wok() {
85 if [ ! -d "$WOK/$pkg" ]; then
86 gettext -e "\nUnable to find package in the wok:"
87 echo -e " $pkg\n" && exit 1
88 fi
89 }
91 if_empty_value() {
92 if [ -z "$value" ]; then
93 gettext "QA: empty variable:"; echo -e " ${var}=\"\"\n"
94 exit 1
95 fi
96 }
98 # QA: check a receip consistency befor building.
99 receipt_quality() {
100 gettext -e "QA: checking package receipt...\n"
101 unset online
102 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
103 online="online"
104 fi
105 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE
106 do
107 unset value
108 value=$(grep ^$var= receipt | cut -d \" -f 2)
109 case "$var" in
110 PACKAGE|VERSION|SHORT_DESC)
111 if_empty_value ;;
112 CATEGORY)
113 [ -z "$value" ] && value="empty"
114 valid="base-system x-window utilities network graphics \
115 multimedia office development system-tools security games \
116 misc meta non-free"
117 if ! echo "$valid" | grep -q -w "$value"; then
118 gettext "QA: unknow category:"; echo -e " $value\n"
119 exit 1
120 fi ;;
121 WEB_SITE)
122 # We dont check WGET_URL since if dl is needed it will fail.
123 # Break also if we not online. Here error is not fatal.
124 if_empty_value
125 [ -z "$online" ] || break
126 if ! busybox wget -s $value 2>/dev/null; then
127 gettext "QA: Unable to reach:"; echo -e " $value\n"
128 fi ;;
129 esac
130 done
131 }
133 # Executed before sourcing a receipt.
134 unset_receipt() {
135 unset DEPENDS BUILD_DEPENDS WANTED EXTRAVERSION WGET_URL PROVIDE TARBALL
136 }
138 # Path's used in receipt and by cook itself.
139 set_paths() {
140 pkgdir=$WOK/$PACKAGE
141 src=$pkgdir/source/$PACKAGE-$VERSION
142 pack=$pkgdir/taz/$PACKAGE-${VERSION}${EXTRAVERSION}
143 fs=$pack/fs
144 stuff=$pkgdir/stuff
145 install=$pkgdir/install
146 if [ "$WANTED" ]; then
147 src=$WOK/$WANTED/source/$WANTED-$VERSION
148 install=$WOK/$WANTED/install
149 fi
150 # Old way compatibility.
151 _pkg=$install
152 }
154 # Get package source.
155 get_source() {
156 case "$WGET_URL" in
157 http://*|ftp://*)
158 # Busybox Wget is better!
159 busybox wget -c -P $SRC $WGET_URL || \
160 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
161 hg*|mercurial*)
162 # We are in cache so clone here and create a tarball
163 pwd=$(pwd)
164 if $(echo "$WGET_URL" | fgrep -q "hg|"); then
165 url=${WGET_URL#hg|}
166 else
167 url=${WGET_URL#mercurial|}
168 fi
169 pkgsrc=${SOURCE:-$PACKAGE}-$VERSION
170 tarball=$pkgsrc.tar.bz2
171 gettext "Getting source from Hg: "; echo $url
172 gettext "Cloning to: "; echo "$pwd/$pkgsrc"
173 hg clone $url $pkgsrc || (echo "ERROR: hg clone $url" && exit 1)
174 gettext "Creating tarball: "; echo "$tarball"
175 tar cjf $tarball $pkgsrc || exit 1
176 mv $tarball $SRC && rm -rf $pkgsrc ;;
177 git*)
178 echo "TODO: git implementation in cook" && exit 1 ;;
179 svn*)
180 echo "TODO: svn implementation in cook" && exit 1 ;;
181 *)
182 gettext -e "\nERROR: Unable to handle:"; echo -e " $WGET_URL \n" | \
183 tee -a $LOGS/$PACKAGE.log
184 exit 1 ;;
185 esac
186 }
188 # Extract source package.
189 extract_source() {
190 gettext "Extracting:"; echo " $TARBALL"
191 case "$TARBALL" in
192 *.tar.gz|*.tgz) tar xzf $SRC/$TARBALL ;;
193 *.tar.bz2) tar xjf $SRC/$TARBALL ;;
194 *.tar.lzma) tar xaf $SRC/$TARBALL ;;
195 *.zip) unzip $SRC/$TARBALL ;;
196 esac
197 }
199 # Display cooked package summary.
200 summary() {
201 cd $WOK/$pkg
202 [ -d install ] && prod=$(du -sh install | awk '{print $1}' 2>/dev/null)
203 fs=$(du -sh taz/* | awk '{print $1}')
204 size=$(du -sh $PKGS/$PACKAGE-${VERSION}*.tazpkg | awk '{print $1}')
205 files=$(cat taz/$PACKAGE-*/files.list | wc -l)
206 cookdate=$(date "+%Y-%m-%d %H:%M")
207 gettext "Summary for:"; echo " $PACKAGE $VERSION"
208 separator
209 [ "$prod" ] && echo "Produce : $prod"
210 cat << EOT
211 Packed : $fs
212 Compressed : $size
213 Files : $files
214 Cook time : ${time}s
215 Cook date : $cookdate
216 $(separator)
218 EOT
219 }
221 # Display debugging erroe info.
222 debug_info() {
223 echo -e "\nDebug information"
224 separator
225 for error in ERROR "No package" "cp: can't stat" "can't open"
226 do
227 fgrep "$error" $LOGS/$pkg.log
228 done
229 separator && echo ""
230 }
232 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
233 # so some packages need to copy these files with the receipt and genpkg_rules.
234 copy_generic_files()
235 {
236 # $LOCALE is set in cook.conf
237 if [ "$LOCALE" ]; then
238 if [ -d "$_pkg/usr/share/locale" ]; then
239 mkdir -p $fs/usr/share/locale
240 for i in $LOCALE
241 do
242 if [ -d "$_pkg/usr/share/locale/$i" ]; then
243 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
244 fi
245 done
246 fi
247 fi
249 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
250 if [ "$GENERIC_PIXMAPS" != "no" ]; then
251 if [ -d "$_pkg/usr/share/pixmaps" ]; then
252 mkdir -p $fs/usr/share/pixmaps
253 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
254 $fs/usr/share/pixmaps 2>/dev/null
255 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
256 $fs/usr/share/pixmaps 2>/dev/null
257 fi
259 # Custom or homemade PNG pixmap can be in stuff.
260 if [ -f "$stuff/$PACKAGE.png" ]; then
261 mkdir -p $fs/usr/share/pixmaps
262 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
263 fi
264 fi
266 # Desktop entry (.desktop).
267 if [ -d "$_pkg/usr/share/applications" ]; then
268 cp -a $_pkg/usr/share/applications $fs/usr/share
269 fi
271 # Homemade desktop file(s) can be in stuff.
272 if [ -d "$stuff/applications" ]; then
273 mkdir -p $fs/usr/share
274 cp -a $stuff/applications $fs/usr/share
275 fi
276 if [ -f "$stuff/$PACKAGE.desktop" ]; then
277 mkdir -p $fs/usr/share/applications
278 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
279 fi
280 }
282 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
283 strip_package()
284 {
285 gettext "Executing strip on all files"
286 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
287 do
288 if [ -d "$dir" ]; then
289 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
290 fi
291 done
292 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
293 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
294 status
295 }
297 # Remove installed deps.
298 remove_deps() {
299 # Now remove installed build deps.
300 diff="$CACHE/installed.diff"
301 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
302 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
303 if [ -s "$CACHE/installed.diff" ]; then
304 gettext "Build dependencies to remove:"; echo " $nb"
305 gettext "Removing:"
306 for dep in $deps
307 do
308 echo -n " $dep"
309 yes | tazpkg remove $dep >/dev/null
310 done
311 echo -e "\n"
312 mv -f $CACHE/installed.diff $CACHE/installed.last.diff
313 fi
314 }
316 # The main cook function.
317 cookit() {
318 echo "Cook: $PACKAGE $VERSION"
319 separator
320 set_paths
321 [ "$QA" ] && receipt_quality
322 rm -rf install taz source
324 # Disable -pipe if less than 512Mb free RAM.
325 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
326 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
327 gettext -e "Disabling -pipe compile flag: $free RAM\n"
328 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
329 CXXFLAGS="${CXXFLAGS/-pipe}" && CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
330 fi
331 unset free
333 # Export flags and path to be used by make
334 DESTDIR=$WOK/$PACKAGE/install
335 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS BUILD_HOST CONFIG_SITE
336 local LC_ALL=POSIX LANG=POSIX
338 # Check for build dep.
339 cd $INSTALLED && ls -1 > $CACHE/installed.list
340 [ "$DEPENDS" ] && gettext -e "Checking build dependencies...\n"
341 for dep in $BUILD_DEPENDS
342 do
343 if [ ! -d "$INSTALLED/$dep" ]; then
344 # Try local package first
345 if [ -f "$PKGS/$dep-*.tazpkg" ]; then
346 gettext "Installing dep (local):"; echo " $dep"
347 cd $PKGS && tazpkg install $dep-*.tazpkg >/dev/null
348 else
349 gettext "Installing dep (web/cache):"; echo " $dep"
350 tazpkg get-install $dep >/dev/null
351 fi
352 fi
353 done
354 ls -1 > $CACHE/installed.cook && cd $CACHE
356 # If a cook failed deps are not remove since we exit 1.
357 [ ! -s "installed.diff" ] && \
358 diff installed.list installed.cook > installed.diff
359 deps=$(cat installed.diff | grep ^+[a-zA-Z0-9] | wc -l)
361 # Get source tarball and make sure we have source dir named:
362 # $PACKAGE-$VERSION to be standard in receipts. Her we use tar.lzma
363 # tarball if it exist.
364 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
365 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
366 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
367 else
368 get_source || exit 1
369 fi
370 fi
371 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
372 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
373 extract_source || exit 1
374 mv * ../$PACKAGE-$VERSION
375 cd .. && rm -rf tmp
376 fi
378 # Execute receipt rules.
379 if grep -q ^compile_rules $pkgdir/receipt; then
380 gettext -e "Executing: compile_rules\n"
381 [ -d "$src" ] && cd $src
382 compile_rules || echo "" && exit 1
383 # Stay compatible with _pkg
384 [ -d $src/_pkg ] && mv $src/_pkg $install
385 # QA: compile_rules success so valid.
386 mkdir -p $install
387 else
388 # QA: No compile_rules so no error, valid.
389 mkdir -p $install
390 fi
391 separator && echo ""
392 }
394 # Cook quality assurance.
395 cookit_quality() {
396 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
397 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
398 fi
399 # ERROR can be echoed any time in cookit()
400 if fgrep -q ERROR: $LOGS/$pkg.log; then
401 debug_info | tee -a $LOGS/$pkg.log
402 rm -f $command && exit 1
403 fi
404 }
406 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
407 # but it dont handle EXTRAVERSION.
408 packit() {
409 set_paths
410 echo "Packing: $PACKAGE $VERSION"
411 separator
412 if grep -q ^genpkg_rules $pkgdir/receipt; then
413 gettext -e "Executing: genpkg_rules\n"
414 cd $pkgdir
415 mkdir -p $fs && genpkg_rules || (echo -e \
416 "\nERROR: genpkg_rules failed\n" >> $LOGS/$pkg.log && exit 1)
417 fi
418 packit_quality
419 cd $pkgdir/taz
420 strip_package
421 for file in receipt description.txt
422 do
423 [ ! -f "../$file" ] && continue
424 gettext "Copying"; echo -n " $file..."
425 cp -f ../$file $pack && chown 0.0 $pack/$file && status
426 done
427 copy_generic_files
429 # Create files.list with redirecting find outpout.
430 gettext "Creating the list of files..." && cd $fs
431 find . -type f -print > ../files.list
432 find . -type l -print >> ../files.list
433 cd .. && sed -i s/'^.'/''/ files.list
434 status
435 gettext "Creating md5sum of files..."
436 while read file; do
437 [ -L "fs$file" ] && continue
438 [ -f "fs$file" ] || continue
439 case "$file" in
440 /lib/modules/*/modules.*|*.pyc) continue;;
441 esac
442 md5sum "fs$file" | sed 's/ fs/ /'
443 done < files.list > md5sum
444 status
445 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
446 description.txt 2> /dev/null | awk \
447 '{ sz=$1 } END { print sz }')
449 # Build cpio archives.
450 gettext "Compressing the fs... "
451 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
452 rm -rf fs
453 status
454 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
455 md5sum description.txt 2> /dev/null | awk \
456 '{ sz=$1 } END { print sz }')
457 gettext "Updating receipt sizes..."
458 sed -i s/^PACKED_SIZE.*$// receipt
459 sed -i s/^UNPACKED_SIZE.*$// receipt
460 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
461 status
463 # Set extra version.
464 if [ "$EXTRAVERSION" ]; then
465 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
466 sed -i s/^EXTRAVERSION.*$// receipt
467 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
468 status
469 fi
471 # Compress.
472 gettext "Creating full cpio archive... "
473 find . -print | cpio -o -H newc --quiet > \
474 ../$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
475 status
476 gettext "Restoring original package tree... "
477 unlzma -c fs.cpio.lzma | cpio -idm --quiet
478 status
479 rm fs.cpio.lzma && cd ..
480 separator && gettext "Package: "
481 du -sh $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
482 echo ""
483 }
485 # Verify package quality and consitensy.
486 packit_quality() {
487 if fgrep -q ERROR: $LOGS/$pkg.log; then
488 rm -f $command && exit 1
489 fi
490 if ! grep -q ^/ $WOK/$pkg/taz/$pkg-*/files.list; then
491 echo -e "ERROR: empty package\n" | tee -a $LOGS/$pkg.log
492 rm -f $command && exit 1
493 else
494 mv -f $WOK/$pkg/taz/$pkg-*.tazpkg $PKGS
495 sed -i /^${pkg}$/d $broken
496 fi
497 }
499 #
500 # Commands
501 #
503 case "$1" in
504 usage|help|-u|-h)
505 usage ;;
506 list-wok)
507 gettext "List of packages in:"; echo " $WOK"
508 separator
509 cd $WOK && ls -1
510 separator
511 echo -n "Packages: " && ls | wc -l
512 echo "" ;;
513 setup)
514 # Setup a build environment
515 check_root
516 echo "Cook: setting up the environment" | log
517 gettext -e "\nSetting up your environment\n"
518 separator && cd $SLITAZ
519 gettext "Creating directories structure in:"; echo " $SLITAZ"
520 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS
521 gettext -e "Checking for packages to install...\n"
522 for pkg in $SETUP_PKGS
523 do
524 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
525 done
527 # Handle --options
528 case "$2" in
529 --wok)
530 [ ! -d "$INSTALLED/mercurial" ] && tazpkg get-install mercurial
531 [ -d "$WOK" ] && echo -e "A wok already exist.\n" && exit 1
532 hg clone $HG_URL ;;
533 --chroot)
534 echo "TODO: create a chroot with tazdev" ;;
535 esac
537 # SliTaz group and permissions
538 if ! grep -q ^slitaz /etc/group; then
539 gettext -e "Adding group: slitaz\n"
540 addgroup slitaz
541 fi
542 gettext -e "Setting permissions for slitaz group...\n"
543 chown -R root.slitaz $SLITAZ
544 chmod -R g+w $SLITAZ
545 separator
546 gettext -e "All done, ready to cook packages :-)\n\n" ;;
547 test)
548 # Test a cook environment.
549 echo "Cook test: testing the cook environment" | log
550 [ ! -d "$WOK" ] && exit 1
551 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
552 cook cooktest ;;
553 new)
554 # Create the package folder and an empty receipt.
555 pkg="$2"
556 [ "$pkg" ] || usage
557 echo ""
558 if [ -d "$WOK/$pkg" ]; then
559 echo -n "$pkg " && gettext "package already exist."
560 echo -e "\n" && exit 1
561 fi
562 gettext "Creating"; echo -n " $WOK/$pkg"
563 mkdir $WOK/$pkg && cd $WOK/$pkg && status
564 gettext "Preparing the package receipt..."
565 cp $DATA/receipt .
566 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
567 status && echo "" ;;
568 list)
569 # Cook a list of packages (better use the Cooker since it will order
570 # packages before executing cook).
571 check_root
572 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
573 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
574 echo -e " $2\n" && exit 1
575 echo "Cook list starting: $2" | log
576 for pkg in $(cat $2)
577 do
578 cook $pkg || broken
579 done ;;
580 clean-wok)
581 check_root
582 gettext -e "\nCleaning all packages files..."
583 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
584 status && echo "" ;;
585 clean-src)
586 check_root
587 gettext -e "\nCleaning all packages source..."
588 rm -rf $WOK/*/source
589 status && echo "" ;;
590 pkglist)
591 # Create suitable packages list for TazPKG and only for builded packages.
592 [ "$2" ] && PKGS="$2"
593 [ ! -d "$PKGS" ] && \
594 gettext -e "\nPackages directory dont exist\n\n" && exit 1
595 cd $PKGS
596 echo "Cook pkglist: Creating all packages list" | log
597 gettext -e "\nCreating lists for:"; echo " $PKGS"
598 separator
599 rm -f packages.* files.list*
600 gettext -e "Creating: packages.list\n"
601 ls -1 | sed s'/.tazpkg//' > $PKGS/packages.list
602 gettext -e "Creating: packages.md5\n"
603 md5sum *.tazpkg > $PKGS/packages.md5
604 gettext -e "Creating: packages.desc\n"
605 gettext -e "Creating: packages.equiv\n"
606 cd $WOK
607 for pkg in *
608 do
609 unset_receipt
610 . $pkg/receipt
611 # packages.desc let us search easily in DB
612 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
613 cat >> $PKGS/packages.desc << EOT
614 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
615 EOT
616 # Packages.equiv is used by tazpkg install to check depends.
617 for i in $PROVIDE; do
618 DEST=""
619 echo $i | fgrep -q : && DEST="${i#*:}:"
620 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
621 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
622 $PKGS/packages.equiv
623 else
624 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
625 fi
626 done
627 fi
628 done
629 # files.list.lzma
630 #lzma e files.list files.list.lzma
631 separator
632 nb=$(ls $PKGS/*.tazpkg | wc -l)
633 echo -e "Packages: $nb\n" ;;
634 *)
635 # Just cook and generate a package.
636 check_root
637 time=$(date +%s)
638 pkg="$1"
639 [ -z "$pkg" ] && usage
640 check_pkg_in_wok && echo ""
641 echo "cook:$pkg" > $command
642 unset inst
643 unset_receipt
644 cd $WOK/$pkg && . ./receipt
646 # Handle --options
647 case "$2" in
648 --clean|-c)
649 gettext -e "Cleaning package:"; echo -n " $pkg"
650 cd $WOK/$pkg && rm -rf install taz source
651 status && echo "" && exit 0 ;;
652 --install|-i)
653 inst='yes' ;;
654 esac
656 # Check if wanted is build now so we have separate log files.
657 if [ "$WANTED" ] && [ ! -d "$WOK/$WANTED/install" ]; then
658 cook "$WANTED"
659 fi
661 # Cook and pack or exit on error and log everything.
662 cookit 2>&1 | tee $LOGS/$pkg.log
663 remove_deps | tee -a $LOGS/$pkg.log
664 cookit_quality
665 packit 2>&1 | tee -a $LOGS/$pkg.log
666 clean_log
668 # Exit if any error in packing.
669 if grep -q ^ERROR $LOGS/$pkg.log; then
670 debug_info | tee -a $LOGS/$pkg.log
671 rm -f $command && exit 1
672 fi
674 # Time and summary
675 time=$(($(date +%s) - $time))
676 summary | tee -a $LOGS/$pkg.log
678 # Install package if requested
679 if [ "$inst" ]; then
680 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
681 cd $PKGS && tazpkg install \
682 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
683 else
684 gettext -e "Unable to install package, build have failed.\n\n"
685 exit 1
686 fi
687 fi
688 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
689 # You want automation: use the Cooker Build Bot.
690 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
691 rm -f $command ;;
692 esac
694 exit 0