cookutils view cook @ rev 70

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