cookutils view cook @ rev 101

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