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