cookutils view cook @ rev 65

Improve web interface, keep and show more activity and cooknote
author Christophe Lincoln <pankso@slitaz.org>
date Sat May 07 17:38:17 2011 +0200 (2011-05-07)
parents 0a7a4eb83a33
children 81fad4913719
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 a 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 sources.")
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're 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 don't want these escapes 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 exists 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 # Initialize 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 receipt consistency before 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: unknown category:"; echo -e " $value\n"
134 exit 1
135 fi ;;
136 WEB_SITE)
137 # We don't check WGET_URL since if dl is needed it will fail.
138 # Break also if we're 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"
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 # Paths 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 if $(echo "$WGET_URL" | fgrep -q "hg|"); then
180 url=${WGET_URL#hg|}
181 else
182 url=${WGET_URL#mercurial|}
183 fi
184 pkgsrc=${SOURCE:-$PACKAGE}-$VERSION
185 tarball=$pkgsrc.tar.bz2
186 gettext -e "Getting source from Hg...\n"
187 echo "URL: $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 url=${WGET_URL#git|}
195 pkgsrc=${SOURCE:-$PACKAGE}-$VERSION
196 tarball=$pkgsrc.tar.bz2
197 gettext -e "Getting source from Git...\n"
198 echo "URL: $url"
199 git clone $url $pkgsrc || (echo "ERROR: git clone $url" && exit 1)
200 if [ "$BRANCH" ]; then
201 cd $pkgsrc && git checkout $BRANCH && cd ..
202 fi
203 gettext "Creating tarball: "; echo "$tarball"
204 tar cjf $tarball $pkgsrc || exit 1
205 mv $tarball $SRC && rm -rf $pkgsrc ;;
206 svn*)
207 echo "TODO: svn implementation in cook" && exit 1 ;;
208 *)
209 gettext -e "\nERROR: Unable to handle:"; echo -e " $WGET_URL \n" | \
210 tee -a $LOGS/$PACKAGE.log
211 exit 1 ;;
212 esac
213 }
215 # Extract source package.
216 extract_source() {
217 gettext "Extracting:"; echo " $TARBALL"
218 case "$TARBALL" in
219 *.tar.gz|*.tgz) tar xzf $SRC/$TARBALL ;;
220 *.tar.bz2|*.tbz) tar xjf $SRC/$TARBALL ;;
221 *.tar.lzma) tar xaf $SRC/$TARBALL ;;
222 *.tar) tar xf $SRC/$TARBALL ;;
223 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
224 *.xz) unxz -c $SRC/$TARBALL | tar xf - ;;
225 *.Z) uncompress -c $SRC/$TARBALL | tar xf - ;;
226 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
227 esac
228 }
230 # Display cooked package summary.
231 summary() {
232 cd $WOK/$pkg
233 [ -d install ] && prod=$(du -sh install | awk '{print $1}' 2>/dev/null)
234 fs=$(du -sh taz/* | awk '{print $1}')
235 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
236 files=$(cat taz/$pkg-*/files.list | wc -l)
237 cookdate=$(date "+%Y-%m-%d %H:%M")
238 gettext "Summary for:"; echo " $PACKAGE $VERSION"
239 separator
240 [ "$prod" ] && echo "Produced : $prod"
241 cat << EOT
242 Packed : $fs
243 Compressed : $size
244 Files : $files
245 Cook time : ${time}s
246 Cook date : $cookdate
247 $(separator)
248 EOT
249 }
251 # Display debugging error info.
252 debug_info() {
253 echo -e "\nDebug information"
254 separator
255 echo "Cook date: $(date '+%Y-%m-%d %H:%M')"
256 for error in ERROR "No package" "cp: can't" "can't open" "can't cd"
257 do
258 fgrep "$error" $LOGS/$pkg.log
259 done
260 separator && echo ""
261 }
263 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
264 # so some packages need to copy these files with the receipt and genpkg_rules.
265 copy_generic_files()
266 {
267 # $LOCALE is set in cook.conf
268 if [ "$LOCALE" ]; then
269 if [ -d "$_pkg/usr/share/locale" ]; then
270 mkdir -p $fs/usr/share/locale
271 for i in $LOCALE
272 do
273 if [ -d "$_pkg/usr/share/locale/$i" ]; then
274 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
275 fi
276 done
277 fi
278 fi
280 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
281 if [ "$GENERIC_PIXMAPS" != "no" ]; then
282 if [ -d "$_pkg/usr/share/pixmaps" ]; then
283 mkdir -p $fs/usr/share/pixmaps
284 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
285 $fs/usr/share/pixmaps 2>/dev/null
286 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
287 $fs/usr/share/pixmaps 2>/dev/null
288 fi
290 # Custom or homemade PNG pixmap can be in stuff.
291 if [ -f "$stuff/$PACKAGE.png" ]; then
292 mkdir -p $fs/usr/share/pixmaps
293 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
294 fi
295 fi
297 # Desktop entry (.desktop).
298 if [ -d "$_pkg/usr/share/applications" ]; then
299 cp -a $_pkg/usr/share/applications $fs/usr/share
300 fi
302 # Homemade desktop file(s) can be in stuff.
303 if [ -d "$stuff/applications" ]; then
304 mkdir -p $fs/usr/share
305 cp -a $stuff/applications $fs/usr/share
306 fi
307 if [ -f "$stuff/$PACKAGE.desktop" ]; then
308 mkdir -p $fs/usr/share/applications
309 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
310 fi
311 }
313 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
314 strip_package()
315 {
316 gettext "Executing strip on all files"
317 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
318 do
319 if [ -d "$dir" ]; then
320 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
321 fi
322 done
323 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
324 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
325 status
326 }
328 # Remove installed deps.
329 remove_deps() {
330 # Now remove installed build deps.
331 diff="$CACHE/installed.diff"
332 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
333 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
334 if [ -s "$CACHE/installed.diff" ]; then
335 gettext "Build dependencies to remove:"; echo " $nb"
336 gettext "Removing:"
337 for dep in $deps
338 do
339 echo -n " $dep"
340 yes | tazpkg remove $dep >/dev/null
341 done
342 echo -e "\n"
343 mv -f $CACHE/installed.diff $CACHE/installed.last.diff
344 fi
345 }
347 # The main cook function.
348 cookit() {
349 echo "Cook: $PACKAGE $VERSION"
350 separator
351 set_paths
352 [ "$QA" ] && receipt_quality
353 cd $pkgdir
354 rm -rf install taz source
356 # Disable -pipe if less than 512Mb free RAM.
357 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
358 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
359 gettext -e "Disabling -pipe compile flag: $free RAM\n"
360 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
361 CXXFLAGS="${CXXFLAGS/-pipe}" && \
362 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
363 fi
364 unset free
366 # Export flags and path to be used by make
367 DESTDIR=$pkgdir/install
368 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS BUILD_HOST CONFIG_SITE
369 local LC_ALL=POSIX LANG=POSIX
371 # Check for build deps.
372 cd $INSTALLED && ls -1 > $CACHE/installed.list
373 [ "$DEPENDS" ] && gettext -e "Checking build dependencies...\n"
374 for dep in $BUILD_DEPENDS
375 do
376 if [ ! -f "$INSTALLED/$dep/receipt" ]; then
377 # Try local package first
378 if [ -f "$PKGS/$dep-*.tazpkg" ]; then
379 gettext "Installing deps (local):"; echo " $dep"
380 cd $PKGS && tazpkg install $dep-*.tazpkg >/dev/null
381 else
382 gettext "Installing deps (web/cache):"; echo " $dep"
383 tazpkg get-install $dep >/dev/null
384 fi
385 fi
386 done
387 ls -1 > $CACHE/installed.cook && cd $CACHE
389 # If a cook failed deps are not removed since we exit 1.
390 [ ! -s "installed.diff" ] && \
391 diff installed.list installed.cook > installed.diff
392 deps=$(cat installed.diff | grep ^+[a-zA-Z0-9] | wc -l)
394 # Get source tarball and make sure we have source dir named:
395 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
396 # tarball if it exists.
397 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
398 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
399 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
400 else
401 get_source || exit 1
402 fi
403 fi
404 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
405 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
406 extract_source || exit 1
407 # Some archives are not well done and don't extract to one dir (ex lzma).
408 files=$(ls | wc -l)
409 [ "$files" == 1 ] && mv * ../$PACKAGE-$VERSION
410 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
411 mv * ../$PACKAGE-$VERSION
412 cd .. && rm -rf tmp
413 fi
415 # Execute receipt rules.
416 if grep -q ^compile_rules $receipt; then
417 gettext -e "Executing: compile_rules\n"
418 [ -d "$src" ] && cd $src
419 compile_rules || exit 1
420 # Stay compatible with _pkg
421 [ -d "$src/_pkg" ] && mv $src/_pkg $install
422 # QA: compile_rules success so valid.
423 mkdir -p $install
424 else
425 # QA: No compile_rules so no error, valid.
426 mkdir -p $install
427 fi
428 separator && echo ""
429 }
431 # Cook quality assurance.
432 cookit_quality() {
433 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
434 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
435 fi
436 # ERROR can be echoed any time in cookit()
437 if fgrep -q ERROR: $LOGS/$pkg.log; then
438 debug_info | tee -a $LOGS/$pkg.log
439 rm -f $command && exit 1
440 fi
441 }
443 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
444 # but it doesn't handle EXTRAVERSION.
445 packit() {
446 set_paths
447 echo "Pack: $PACKAGE $VERSION"
448 separator
449 if grep -q ^genpkg_rules $receipt; then
450 gettext -e "Executing: genpkg_rules\n"
451 cd $pkgdir
452 mkdir -p $fs && genpkg_rules || (echo -e \
453 "\nERROR: genpkg_rules failed\n" >> $LOGS/$pkg.log && exit 1)
454 fi
455 cd $taz
456 for file in receipt description.txt
457 do
458 [ ! -f "../$file" ] && continue
459 gettext "Copying"; echo -n " $file..."
460 cp -f ../$file $pack && chown 0.0 $pack/$file && status
461 done
463 # Create files.list with redirecting find output.
464 gettext "Creating the list of files..." && cd $fs
465 find . -type f -print > ../files.list
466 find . -type l -print >> ../files.list
467 cd .. && sed -i s/'^.'/''/ files.list
468 status
470 # QA, strip and stuff files.
472 strip_package
473 copy_generic_files
475 # Md5sum of files.
476 gettext "Creating md5sum of files..."
477 while read file; do
478 [ -L "fs$file" ] && continue
479 [ -f "fs$file" ] || continue
480 case "$file" in
481 /lib/modules/*/modules.*|*.pyc) continue;;
482 esac
483 md5sum "fs$file" | sed 's/ fs/ /'
484 done < files.list > md5sum
485 status
486 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
487 description.txt 2> /dev/null | awk \
488 '{ sz=$1 } END { print sz }')
490 # Build cpio archives.
491 gettext "Compressing the fs... "
492 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
493 rm -rf fs
494 status
495 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
496 md5sum description.txt 2> /dev/null | awk \
497 '{ sz=$1 } END { print sz }')
498 gettext "Updating receipt sizes..."
499 sed -i s/^PACKED_SIZE.*$// receipt
500 sed -i s/^UNPACKED_SIZE.*$// receipt
501 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
502 status
504 # Set extra version.
505 if [ "$EXTRAVERSION" ]; then
506 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
507 sed -i s/^EXTRAVERSION.*$// receipt
508 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
509 status
510 fi
512 # Compress.
513 gettext "Creating full cpio archive... "
514 find . -print | cpio -o -H newc --quiet > \
515 ../$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
516 status
517 gettext "Restoring original package tree... "
518 unlzma -c fs.cpio.lzma | cpio -idm --quiet
519 status
520 rm fs.cpio.lzma && cd ..
522 # QA and give info.
523 tazpkg=$(ls *.tazpkg)
524 packit_quality
525 separator && gettext "Package:"; echo -e " $tazpkg\n"
526 }
528 # Verify package quality and consistency.
529 packit_quality() {
530 if fgrep -q ERROR: $LOGS/$pkg.log; then
531 rm -f $command && exit 1
532 fi
533 gettext "QA: Checking for empty package..."
534 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
535 if [ "$files" -lt 0 ] && [ "$CATEGORY" != "meta" ]; then
536 echo -e "\nERROR: empty package"
537 rm -f $command && exit 1
538 else
539 status && mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
540 sed -i /^${pkg}$/d $broken
541 fi
542 }
544 #
545 # Commands
546 #
548 case "$1" in
549 usage|help|-u|-h)
550 usage ;;
551 list-wok)
552 gettext -e "\nList of packages in:"; echo " $WOK"
553 separator
554 cd $WOK && ls -1
555 separator
556 echo -n "Packages: " && ls | wc -l
557 echo "" ;;
558 setup)
559 # Setup a build environment
560 check_root
561 echo "Cook: setting up the environment" | log
562 gettext -e "\nSetting up your environment\n"
563 separator && cd $SLITAZ
564 init_db_files
565 gettext -e "Checking for packages to install...\n"
566 for pkg in $SETUP_PKGS
567 do
568 [ ! -f "$INSTALLED/$pkg/receipt" ] && tazpkg get-install $pkg
569 done
571 # Handle --options
572 case "$2" in
573 --wok|-w)
574 [ ! -f "$INSTALLED/mercurial/receipt" ] && \
575 tazpkg get-install mercurial
576 [ -d "$WOK" ] && echo -e "A wok already exists.\n" && exit 1
577 hg clone $HG_URL ;;
578 esac
580 # SliTaz group and permissions
581 if ! grep -q ^slitaz /etc/group; then
582 gettext -e "Adding group: slitaz\n"
583 addgroup slitaz
584 fi
585 gettext -e "Setting permissions for slitaz group...\n"
586 chown -R root.slitaz $SLITAZ
587 chmod -R g+w $SLITAZ
588 separator
589 gettext -e "All done, ready to cook packages :-)\n\n" ;;
590 test)
591 # Test a cook environment.
592 echo "Cook test: testing the cook environment" | log
593 [ ! -d "$WOK" ] && exit 1
594 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
595 cook cooktest ;;
596 new)
597 # Create the package folder and an empty receipt.
598 pkg="$2"
599 [ "$pkg" ] || usage
600 [ -d "${WOK}-hg" ] && WOK=${WOK}-hg
601 echo ""
602 if [ -d "$WOK/$pkg" ]; then
603 echo -n "$pkg " && gettext "package already exists."
604 echo -e "\n" && exit 1
605 fi
606 gettext "Creating"; echo -n " $WOK/$pkg"
607 mkdir $WOK/$pkg && cd $WOK/$pkg && status
608 gettext "Preparing the package receipt..."
609 cp $DATA/receipt .
610 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
611 status && echo "" ;;
612 list)
613 # Cook a list of packages (better use the Cooker since it will order
614 # packages before executing cook).
615 check_root
616 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
617 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
618 echo -e " $2\n" && exit 1
619 echo "Cook list starting: $2" | log
620 for pkg in $(cat $2)
621 do
622 cook $pkg || broken
623 done ;;
624 clean-wok)
625 check_root
626 gettext -e "\nCleaning all packages files..."
627 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
628 status && echo "" ;;
629 clean-src)
630 check_root
631 gettext -e "\nCleaning all packages sources..."
632 rm -rf $WOK/*/source
633 status && echo "" ;;
634 pkglist)
635 # Create suitable packages list for TazPKG and only for built packages.
636 [ "$2" ] && PKGS="$2"
637 [ ! -d "$PKGS" ] && \
638 gettext -e "\nPackages directory doesn't exist\n\n" && exit 1
639 cd $PKGS
640 echo "Cook pkglist: Creating all packages lists" | log
641 gettext -e "\nCreating lists for:"; echo " $PKGS"
642 separator
643 rm -f packages.* files.list*
644 gettext -e "Creating: packages.list\n"
645 ls -1 | sed s'/.tazpkg//' > $PKGS/packages.list
646 gettext -e "Creating: packages.md5\n"
647 md5sum *.tazpkg > $PKGS/packages.md5
648 gettext -e "Creating: packages.desc\n"
649 gettext -e "Creating: packages.equiv\n"
650 cd $WOK
651 for pkg in *
652 do
653 unset_receipt
654 . $pkg/receipt
655 # packages.desc let us search easily in DB
656 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
657 cat >> $PKGS/packages.desc << EOT
658 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
659 EOT
660 # Packages.equiv is used by tazpkg install to check depends.
661 for i in $PROVIDE; do
662 DEST=""
663 echo $i | fgrep -q : && DEST="${i#*:}:"
664 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
665 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
666 $PKGS/packages.equiv
667 else
668 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
669 fi
670 done
671 fi
672 done
673 # files.list.lzma
674 #lzma e files.list files.list.lzma
675 separator
676 nb=$(ls $PKGS/*.tazpkg | wc -l)
677 echo -e "Packages: $nb\n" ;;
678 *)
679 # Just cook and generate a package.
680 check_root
681 time=$(date +%s)
682 pkg="$1"
683 [ -z "$pkg" ] && usage
684 receipt="$WOK/$pkg/receipt"
685 check_pkg_in_wok && echo ""
687 # Skip blocked, 3 lines also for the Cooker.
688 if grep -q "^$pkg$" $blocked && [ "$2" != "--*" ]; then
689 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
690 fi
692 # Log and source receipt.
693 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
694 echo "cook:$pkg" > $command
695 unset inst
696 unset_receipt
697 . $receipt
699 # Handle --options
700 case "$2" in
701 --clean|-c)
702 gettext -e "Cleaning:"; echo -n " $pkg"
703 cd $WOK/$pkg && rm -rf install taz source
704 status && echo "" && exit 0 ;;
705 --install|-i)
706 inst='yes' ;;
707 --getsrc|-gs)
708 gettext "Getting source for:"; echo " $pkg"
709 separator && get_source
710 echo -e "Tarball: $SRC/$TARBALL\n" && exit 0 ;;
711 --block|-b)
712 gettext "Blocking:"; echo -n " $pkg"
713 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
714 status && echo "" && exit 0 ;;
715 --unblock|-ub)
716 gettext "Unblocking:"; echo -n " $pkg"
717 sed -i "/^${pkg}$/"d $blocked
718 status && echo "" && exit 0 ;;
719 esac
721 # Check if wanted is built now so we have separate log files.
722 if [ "$WANTED" ] && [ ! -d "$WOK/$WANTED/install" ]; then
723 cook "$WANTED"
724 fi
726 # Cook and pack or exit on error and log everything.
727 cookit 2>&1 | tee $LOGS/$pkg.log
728 remove_deps | tee -a $LOGS/$pkg.log
729 cookit_quality
730 packit 2>&1 | tee -a $LOGS/$pkg.log
731 clean_log
733 # Exit if any error in packing.
734 if grep -q ^ERROR $LOGS/$pkg.log; then
735 debug_info | tee -a $LOGS/$pkg.log
736 rm -f $command && exit 1
737 fi
739 # Time and summary
740 time=$(($(date +%s) - $time))
741 summary | tee -a $LOGS/$pkg.log
742 echo ""
744 # Install package if requested
745 if [ "$inst" ]; then
746 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
747 cd $PKGS && tazpkg install \
748 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
749 else
750 gettext -e "Unable to install package, build has failed.\n\n"
751 exit 1
752 fi
753 fi
754 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
755 # You want automation: use the Cooker Build Bot.
756 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
757 rm -f $command ;;
758 esac
760 exit 0