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