cookutils view cook @ rev 144

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