cookutils view cook @ rev 174

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