cookutils view cook @ rev 42

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