cookutils view cook @ rev 74

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