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