cookutils view cook @ rev 67

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