cookutils view cook @ rev 115

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