cookutils view cook @ rev 98

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