cookutils view cook @ rev 221

cook: improve log when WANTED is blocked/broken (again)
author Christophe Lincoln <pankso@slitaz.org>
date Tue May 24 03:46:17 2011 +0200 (2011-05-24)
parents baf824b59da2
children 39f461c74940
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 --interactive|-x Cook : $(gettext "create a receipt interactively.")
50 --wok|-w Setup: $(gettext "create also a wok from Hg repo.")
52 EOT
53 exit 0
54 }
56 # Be sure we're root.
57 check_root() {
58 [ $(id -u) != 0 ] && gettext -e "\nYou must be root to cook.\n\n" && exit 0
59 }
61 separator() {
62 echo "================================================================================"
63 }
65 status() {
66 echo -en "\\033[70G[ "
67 if [ $? = 0 ]; then
68 echo -en "\\033[1;32mOK"
69 else
70 echo -en "\\033[1;31mFailed"
71 fi
72 echo -e "\\033[0;39m ]"
73 }
75 # Log activities, we want first letter capitalized.
76 log() {
77 grep ^[A-Z] | \
78 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
79 }
81 # We don't want these escapes in web interface.
82 clean_log() {
83 sed -i -e s'|\[70G\[ \[1;32m| |' \
84 -e s'|\[0;39m \]||' $LOGS/$pkg.log
85 }
87 # Log broken packages.
88 broken() {
89 if ! grep -q "^$pkg$" $broken; then
90 echo "$pkg" >> $broken
91 fi
92 }
94 # Be sure package exists in wok.
95 check_pkg_in_wok() {
96 if [ ! -d "$WOK/$pkg" ]; then
97 gettext -e "\nUnable to find package in the wok:"
98 echo -e " $pkg\n" && exit 1
99 fi
100 }
102 if_empty_value() {
103 if [ -z "$value" ]; then
104 gettext "QA: empty variable:"; echo -e " ${var}=\"\"\n"
105 exit 1
106 fi
107 }
109 # Initialize files used in $CACHE
110 init_db_files() {
111 gettext "Creating directories structure in:"; echo " $SLITAZ"
112 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS
113 gettext "Creating DB files in:"; echo " $CACHE"
114 for f in $activity $command $broken $blocked
115 do
116 touch $f
117 done
118 }
120 # QA: check a receipt consistency before building.
121 receipt_quality() {
122 gettext -e "QA: checking package receipt...\n"
123 unset online
124 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
125 online="online"
126 fi
127 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE
128 do
129 unset value
130 value=$(grep ^$var= $receipt | cut -d \" -f 2)
131 case "$var" in
132 PACKAGE|VERSION|SHORT_DESC)
133 if_empty_value ;;
134 CATEGORY)
135 [ -z "$value" ] && value="empty"
136 valid="base-system x-window utilities network graphics \
137 multimedia office development system-tools security games \
138 misc meta non-free"
139 if ! echo "$valid" | grep -q -w "$value"; then
140 gettext "QA: unknown category:"; echo -e " $value\n"
141 exit 1
142 fi ;;
143 WEB_SITE)
144 # We don't check WGET_URL since if dl is needed it will fail.
145 # Break also if we're not online. Here error is not fatal.
146 if_empty_value
147 [ -z "$online" ] || break
148 if ! busybox wget -T 12 -s $value 2>/dev/null; then
149 gettext "QA: Unable to reach:"; echo -e " $value"
150 fi ;;
151 esac
152 done
153 }
155 # Executed before sourcing a receipt.
156 unset_receipt() {
157 unset DEPENDS BUILD_DEPENDS WANTED EXTRAVERSION WGET_URL PROVIDE TARBALL
158 }
160 # Paths used in receipt and by cook itself.
161 set_paths() {
162 pkgdir=$WOK/$PACKAGE
163 src=$pkgdir/source/$PACKAGE-$VERSION
164 taz=$pkgdir/taz
165 pack=$taz/$PACKAGE-${VERSION}${EXTRAVERSION}
166 fs=$pack/fs
167 stuff=$pkgdir/stuff
168 install=$pkgdir/install
169 if [ "$WANTED" ]; then
170 src=$WOK/$WANTED/source/$WANTED-$VERSION
171 install=$WOK/$WANTED/install
172 wanted_stuff=$WOK/$WANTED/stuff
173 fi
174 # Old way compatibility.
175 _pkg=$install
176 }
178 # Create source tarball when URL is a SCM.
179 create_tarball() {
180 gettext "Creating tarball: "; echo "$tarball"
181 if [ "$LZMA_SRC" ]; then
182 tar -c $pkgsrc | lzma e $SRC/$tarball -si || exit 1
183 else
184 tar cjf $tarball $pkgsrc || exit 1
185 mv $tarball $SRC && rm -rf $pkgsrc
186 fi
187 }
189 # Get package source. For SCM we are in cache so clone here and create a
190 # tarball here.
191 get_source() {
192 pwd=$(pwd)
193 pkgsrc=${SOURCE:-$PACKAGE}-$VERSION
194 tarball=$pkgsrc.tar.bz2
195 [ "$LZMA_SRC" ] && tarball=$pkgsrc.tar.lzma
196 case "$WGET_URL" in
197 http://*|ftp://*)
198 # Busybox Wget is better!
199 busybox wget -T 12 -c -P $SRC $WGET_URL || \
200 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
201 https://*)
202 wget -c --no-check-certificate -P $SRC $WGET_URL || \
203 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
204 hg*|mercurial*)
205 if $(echo "$WGET_URL" | fgrep -q "hg|"); then
206 url=${WGET_URL#hg|}
207 else
208 url=${WGET_URL#mercurial|}
209 fi
210 gettext -e "Getting source from Hg...\n"
211 echo "URL: $url"
212 gettext "Cloning to: "; echo "$pwd/$pkgsrc"
213 hg clone $url $pkgsrc || (echo "ERROR: hg clone $url" && exit 1)
214 create_tarball ;;
215 git*)
216 url=${WGET_URL#git|}
217 gettext -e "Getting source from Git...\n"
218 echo "URL: $url"
219 git clone $url $pkgsrc || (echo "ERROR: git clone $url" && exit 1)
220 if [ "$BRANCH" ]; then
221 echo "Git branch: $BRANCH"
222 cd $pkgsrc && git checkout $BRANCH && cd ..
223 fi
224 create_tarball ;;
225 cvs*)
226 url=${WGET_URL#cvs|}
227 mod=$PACKAGE
228 [ "$CVS_MODULE" ] && mod=$CVS_MODULE
229 gettext -e "Getting source from CVS...\n"
230 echo "URL: $url"
231 [ "$CVS_MODULE" ] && echo "CVS module: $mod"
232 gettext "Cloning to: "; echo "$pwd/$mod"
233 cvs -d:$url co $mod && mv $mod $pkgsrc
234 create_tarball ;;
235 svn*|subversion*)
236 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
237 url=${WGET_URL#svn|}
238 else
239 url=${WGET_URL#subversion|}
240 fi
241 gettext -e "Getting source from SVN...\n"
242 echo "URL: $url"
243 if [ "$BRANCH" ]; then
244 echo t | svn co $url -r $BRANCH $pkgsrc
245 else
246 echo t | svn co $url $pkgsrc
247 fi
248 create_tarball ;;
249 *)
250 gettext -e "\nERROR: Unable to handle:"; echo -e " $WGET_URL \n" | \
251 tee -a $LOGS/$PACKAGE.log
252 exit 1 ;;
253 esac
254 }
256 # Extract source package.
257 extract_source() {
258 if [ ! -s "$SRC/$TARBALL" ]; then
259 local url
260 url="http://mirror.slitaz.org/sources/packages"
261 url=$url/${TARBALL:0:1}/$TARBALL
262 gettext "Getting source from mirror:"; echo " $url"
263 busybox wget -c -P $SRC $url || echo -e "ERROR: wget $url"
264 fi
265 gettext "Extracting:"; echo " $TARBALL"
266 case "$TARBALL" in
267 *.tar.gz|*.tgz) tar xzf $SRC/$TARBALL 2>/dev/null ;;
268 *.tar.bz2|*.tbz|*.tbz2) tar xjf $SRC/$TARBALL 2>/dev/null ;;
269 *.tar.lzma) tar xaf $SRC/$TARBALL ;;
270 *.tar) tar xf $SRC/$TARBALL ;;
271 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
272 *.xz) unxz -c $SRC/$TARBALL | tar xf - ;;
273 *.Z) uncompress -c $SRC/$TARBALL | tar xf - ;;
274 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
275 *) cp $SRC/$TARBALL $(pwd) ;;
276 esac
277 }
279 # Display cooked package summary.
280 summary() {
281 cd $WOK/$pkg
282 [ -d install ] && prod=$(du -sh install | awk '{print $1}' 2>/dev/null)
283 fs=$(du -sh taz/* | awk '{print $1}')
284 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
285 files=$(cat taz/$pkg-*/files.list | wc -l)
286 cookdate=$(date "+%Y-%m-%d %H:%M")
287 sec=$time
288 div=$(($time / 60))
289 [ "$div" != 0 ] && min="~ ${div}m"
290 gettext "Summary for:"; echo " $PACKAGE $VERSION"
291 separator
292 [ "$prod" ] && echo "Produced : $prod"
293 cat << EOT
294 Packed : $fs
295 Compressed : $size
296 Files : $files
297 Cook time : ${sec}s $min
298 Cook date : $cookdate
299 $(separator)
300 EOT
301 }
303 # Display debugging error info.
304 debug_info() {
305 echo -e "\nDebug information"
306 separator
307 echo "Cook date: $(date '+%Y-%m-%d %H:%M')"
308 for error in \
309 ERROR "No package" "cp: can't" "can't open" "can't cd" \
310 "error:" "fatal error:"
311 do
312 fgrep "$error" $LOGS/$pkg.log
313 done
314 separator && echo ""
315 }
317 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
318 # so some packages need to copy these files with the receipt and genpkg_rules.
319 copy_generic_files()
320 {
321 # $LOCALE is set in cook.conf
322 if [ "$LOCALE" ]; then
323 if [ -d "$_pkg/usr/share/locale" ]; then
324 mkdir -p $fs/usr/share/locale
325 for i in $LOCALE
326 do
327 if [ -d "$_pkg/usr/share/locale/$i" ]; then
328 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
329 fi
330 done
331 fi
332 fi
334 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
335 if [ "$GENERIC_PIXMAPS" != "no" ]; then
336 if [ -d "$_pkg/usr/share/pixmaps" ]; then
337 mkdir -p $fs/usr/share/pixmaps
338 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
339 $fs/usr/share/pixmaps 2>/dev/null
340 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
341 $fs/usr/share/pixmaps 2>/dev/null
342 fi
344 # Custom or homemade PNG pixmap can be in stuff.
345 if [ -f "$stuff/$PACKAGE.png" ]; then
346 mkdir -p $fs/usr/share/pixmaps
347 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
348 fi
349 fi
351 # Desktop entry (.desktop).
352 if [ -d "$_pkg/usr/share/applications" ]; then
353 cp -a $_pkg/usr/share/applications $fs/usr/share
354 fi
356 # Homemade desktop file(s) can be in stuff.
357 if [ -d "$stuff/applications" ]; then
358 mkdir -p $fs/usr/share
359 cp -a $stuff/applications $fs/usr/share
360 fi
361 if [ -f "$stuff/$PACKAGE.desktop" ]; then
362 mkdir -p $fs/usr/share/applications
363 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
364 fi
365 }
367 # Find and strip : --strip-all (-s) or --strip-debug on static libs as well
368 # as removing uneeded files like in Python packages.
369 strip_package()
370 {
371 gettext "Executing strip on all files..."
372 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
373 do
374 if [ -d "$dir" ]; then
375 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
376 fi
377 done
378 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
379 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
380 status
382 # Remove Python .pyc and .pyo from packages.
383 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
384 gettext "Removing Python compiled files..."
385 find $fs -type f -name "*.pyc" -delete 2>/dev/null
386 find $fs -type f -name "*.pyo" -delete 2>/dev/null
387 status
388 fi
390 # Remove Perl perllocal.pod and .packlist from packages.
391 if echo "$DEPENDS" | fgrep -q "perl"; then
392 gettext "Removing Perl compiled files..."
393 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
394 find $fs -type f -name ".packlist" -delete 2>/dev/null
395 status
396 fi
397 }
399 # Remove installed deps.
400 remove_deps() {
401 # Now remove installed build deps.
402 diff="$CACHE/installed.cook.diff"
403 if [ -s "$CACHE/installed.cook.diff" ]; then
404 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
405 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
406 gettext "Build dependencies to remove:"; echo " $nb"
407 gettext "Removing:"
408 for dep in $deps
409 do
410 echo -n " $dep"
411 echo 'y' | tazpkg remove $dep >/dev/null
412 done
413 echo -e "\n"
414 # Keep the last diff for debug and info.
415 mv -f $CACHE/installed.cook.diff $CACHE/installed.diff
416 fi
417 }
419 # The main cook function.
420 cookit() {
421 echo "Cook: $PACKAGE $VERSION"
422 separator
423 set_paths
424 [ "$QA" ] && receipt_quality
425 cd $pkgdir
426 rm -rf install taz source
428 # Disable -pipe if less than 512Mb free RAM.
429 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
430 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
431 gettext -e "Disabling -pipe compile flag: $free RAM\n"
432 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
433 CXXFLAGS="${CXXFLAGS/-pipe}" && \
434 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
435 fi
436 unset free
438 # Export flags and path to be used by make
439 DESTDIR=$pkgdir/install
440 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
442 # Check for build deps and handle implicit depends of *-dev packages
443 # (ex: libusb-dev :: libusb).
444 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
445 touch $CACHE/installed.local $CACHE/installed.web
446 [ "$BUILD_DEPENDS" ] && gettext -e "Checking build dependencies...\n"
447 for dep in $BUILD_DEPENDS
448 do
449 implicit=${dep%-dev}
450 for i in $dep $implicit
451 do
452 if [ ! -f "$INSTALLED/$i/receipt" ]; then
453 # Try local package first. In some cases implicit doesn't exist, ex:
454 # libboost-dev exists but not libboost, so check if we got vers.
455 unset vers
456 vers=$(grep ^VERSION= $WOK/$i/receipt 2>/dev/null | cut -d '"' -f 2)
457 if [ -f "$PKGS/$i-$vers.tazpkg" ]; then
458 echo $i-$vers.tazpkg >> $CACHE/installed.local
459 else
460 if [ "$vers" ]; then
461 if fgrep -q $i-$vers $DB/packages.list; then
462 echo $i >> $CACHE/installed.web
463 else
464 # So package exists in wok but not available.
465 gettext "Missing dep (wok/pkg):"; echo " $i $vers"
466 echo $i >> $CACHE/missing.dep
467 fi
468 fi
469 fi
470 fi
471 done
472 done
474 # Get the list of installed packages
475 cd $INSTALLED && ls -1 > $CACHE/installed.list
477 # Have we a missing build dep to cook ?
478 if [ -s "$CACHE/missing.dep" ] && [ "$AUTO_COOK" ]; then
479 gettext -e "Auto cook config is set : AUTO_COOK\n"
480 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
481 for i in $(cat $CACHE/missing.dep)
482 do
483 (gettext "Building dep (wok/pkg) :"; echo " $i $vers") | \
484 tee -a $LOGS/$PACKAGE.log.$$
485 cook $i || (echo -e "ERROR: can't cook dep '$i'\n" && \
486 fgrep "remove: " $LOGS/$i.log && \
487 fgrep "Removing: " $LOGS/$i.log && echo "") | \
488 tee -a $LOGS/$PACKAGE.log.$$ && break
489 done
490 rm -f $CACHE/missing.dep
491 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
492 fi
494 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
495 # is enabled and cook fails we have ERROR in log, if no auto cook we have
496 # missing dep in cached file.
497 if fgrep -q "ERROR:" $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
498 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
499 echo "ERROR: missing dep $nb" && exit 1
500 fi
502 # Install local packages.
503 cd $PKGS
504 for i in $(cat $CACHE/installed.local)
505 do
506 gettext "Installing dep (pkg/local):"; echo " $i $vers"
507 tazpkg install $i >/dev/null
508 done
510 # Install web or cached packages (if mirror is set to $PKGS we only
511 # use local packages).
512 for i in $(cat $CACHE/installed.web)
513 do
514 gettext "Installing dep (web/cache):"; echo " $i $vers"
515 tazpkg get-install $i >/dev/null
516 done
518 # If a cook failed deps are removed.
519 cd $INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
520 [ ! -s "installed.cook.diff" ] && \
521 busybox diff installed.list installed.cook > installed.cook.diff
522 deps=$(cat installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
524 # Get source tarball and make sure we have source dir named:
525 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
526 # tarball if it exists.
527 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
528 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
529 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
530 LZMA_SRC=""
531 else
532 get_source || exit 1
533 fi
534 fi
535 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
536 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
537 extract_source || exit 1
538 if [ "$LZMA_SRC" ]; then
539 cd $pkgdir/source
540 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
541 mv tmp tmp-1 && mkdir tmp
542 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
543 fi
544 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
545 cd tmp && tar -c * | lzma e $SRC/$TARBALL -si
546 fi
547 fi
548 cd $pkgdir/source/tmp
549 # Some archives are not well done and don't extract to one dir (ex lzma).
550 files=$(ls | wc -l)
551 [ "$files" == 1 ] && mv * ../$PACKAGE-$VERSION
552 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
553 mv * ../$PACKAGE-$VERSION
554 cd .. && rm -rf tmp
555 fi
557 # Execute receipt rules.
558 if grep -q ^compile_rules $receipt; then
559 gettext -e "Executing: compile_rules\n"
560 [ -d "$src" ] && cd $src
561 compile_rules $@ || exit 1
562 # Stay compatible with _pkg
563 [ -d "$src/_pkg" ] && mv $src/_pkg $install
564 # QA: compile_rules success so valid.
565 mkdir -p $install
566 else
567 # QA: No compile_rules so no error, valid.
568 mkdir -p $install
569 fi
570 separator && echo ""
571 }
573 # Cook quality assurance.
574 cookit_quality() {
575 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
576 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
577 fi
578 # ERROR can be echoed any time in cookit()
579 if fgrep -q ERROR: $LOGS/$pkg.log; then
580 debug_info | tee -a $LOGS/$pkg.log
581 rm -f $command && exit 1
582 fi
583 }
585 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
586 # but it doesn't handle EXTRAVERSION.
587 packit() {
588 set_paths
589 echo "Pack: $PACKAGE $VERSION"
590 separator
591 if grep -q ^genpkg_rules $receipt; then
592 gettext -e "Executing: genpkg_rules\n"
593 cd $pkgdir
594 mkdir -p $fs && ( set -e; genpkg_rules ) || echo -e \
595 "\nERROR: genpkg_rules failed\n" >> $LOGS/$pkg.log
596 fi
598 # First QA check to stop now if genpkg_rules failed.
599 if fgrep -q ERROR: $LOGS/$pkg.log; then
600 exit 1
601 fi
603 cd $taz
604 for file in receipt description.txt
605 do
606 [ ! -f "../$file" ] && continue
607 gettext "Copying"; echo -n " $file..."
608 cp -f ../$file $pack && chown 0.0 $pack/$file && status
609 done
610 copy_generic_files
612 # Create files.list with redirecting find output.
613 gettext "Creating the list of files..." && cd $fs
614 find . -type f -print > ../files.list
615 find . -type l -print >> ../files.list
616 cd .. && sed -i s/'^.'/''/ files.list
617 status
619 # Strip and stuff files.
620 strip_package
622 # Md5sum of files.
623 gettext "Creating md5sum of files..."
624 while read file; do
625 [ -L "fs$file" ] && continue
626 [ -f "fs$file" ] || continue
627 case "$file" in
628 /lib/modules/*/modules.*|*.pyc) continue;;
629 esac
630 md5sum "fs$file" | sed 's/ fs/ /'
631 done < files.list > md5sum
632 status
633 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
634 description.txt 2> /dev/null | awk \
635 '{ sz=$1 } END { print sz }')
637 # Build cpio archives.
638 gettext "Compressing the fs... "
639 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
640 rm -rf fs
641 status
642 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
643 md5sum description.txt 2> /dev/null | awk \
644 '{ sz=$1 } END { print sz }')
645 gettext "Updating receipt sizes..."
646 sed -i s/^PACKED_SIZE.*$// receipt
647 sed -i s/^UNPACKED_SIZE.*$// receipt
648 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
649 status
651 # Set extra version.
652 if [ "$EXTRAVERSION" ]; then
653 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
654 sed -i s/^EXTRAVERSION.*$// receipt
655 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
656 status
657 fi
659 # Compress.
660 gettext "Creating full cpio archive... "
661 find . -print | cpio -o -H newc --quiet > \
662 ../$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
663 status
664 gettext "Restoring original package tree... "
665 unlzma -c fs.cpio.lzma | cpio -idm --quiet
666 status
667 rm fs.cpio.lzma && cd ..
669 # QA and give info.
670 tazpkg=$(ls *.tazpkg)
671 packit_quality
672 separator && gettext "Package:"; echo -e " $tazpkg\n"
673 }
675 # Verify package quality and consistency.
676 packit_quality() {
677 #gettext "QA: Checking for broken link..."
678 #link=$(find $fs/usr -type l -follow)
679 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
680 #status
682 # Exit if any error found in log file.
683 if fgrep -q ERROR: $LOGS/$pkg.log; then
684 rm -f $command && exit 1
685 fi
687 gettext "QA: Checking for empty package..."
688 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
689 if [ "$files" -lt 0 ] && [ "$CATEGORY" != "meta" ]; then
690 echo -e "\nERROR: empty package"
691 rm -f $command && exit 1
692 else
693 # Ls sort by name so the first file is the one we want.
694 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
695 status
696 if [ -f "$old" ]; then
697 echo -n "Removing old: $(basename $old)"
698 rm -f $old && status
699 fi
700 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
701 sed -i /^${pkg}$/d $broken
702 fi
703 }
705 #
706 # Commands
707 #
709 case "$1" in
710 usage|help|-u|-h)
711 usage ;;
712 list-wok)
713 gettext -e "\nList of packages in:"; echo " $WOK"
714 separator
715 cd $WOK && ls -1
716 separator
717 echo -n "Packages: " && ls | wc -l
718 echo "" ;;
719 search)
720 # Just a simple search function, we dont need more actually.
721 query="$2"
722 gettext -e "\nSearch results for:"; echo " $query"
723 separator
724 cd $WOK && ls -1 | grep "$query"
725 separator && echo "" ;;
726 setup)
727 # Setup a build environment
728 check_root
729 echo "Cook: setting up the environment" | log
730 gettext -e "\nSetting up your environment\n"
731 separator && cd $SLITAZ
732 init_db_files
733 gettext -e "Checking for packages to install...\n"
734 for pkg in $SETUP_PKGS
735 do
736 [ ! -f "$INSTALLED/$pkg/receipt" ] && tazpkg get-install $pkg
737 done
739 # Handle --options
740 case "$2" in
741 --wok|-w)
742 [ ! -f "$INSTALLED/mercurial/receipt" ] && \
743 tazpkg get-install mercurial
744 [ -d "$WOK" ] && echo -e "A wok already exists.\n" && exit 1
745 hg clone $WOK_URL ;;
746 esac
748 # SliTaz group and permissions
749 if ! grep -q ^slitaz /etc/group; then
750 gettext -e "Adding group: slitaz\n"
751 addgroup slitaz
752 fi
753 gettext -e "Setting permissions for slitaz group...\n"
754 chown -R root.slitaz $SLITAZ
755 chmod -R g+w $SLITAZ
756 separator
757 gettext -e "All done, ready to cook packages :-)\n\n" ;;
758 test)
759 # Test a cook environment.
760 echo "Cook test: testing the cook environment" | log
761 [ ! -d "$WOK" ] && exit 1
762 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
763 cook cooktest ;;
764 new)
765 # Create the package folder and an empty receipt.
766 pkg="$2"
767 [ "$pkg" ] || usage
768 echo ""
769 if [ -d "$WOK/$pkg" ]; then
770 echo -n "$pkg " && gettext "package already exists."
771 echo -e "\n" && exit 1
772 fi
773 gettext "Creating"; echo -n " $WOK/$pkg"
774 mkdir $WOK/$pkg && cd $WOK/$pkg && status
775 gettext "Preparing the package receipt..."
776 cp $DATA/receipt .
777 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
778 status && echo ""
780 # Interactive mode, asking and seding.
781 case "$3" in
782 --interactive|-x)
783 gettext -e "Entering interactive mode...\n"
784 separator
785 echo "Package : $pkg"
786 # Version.
787 echo -n "Version : " ; read anser
788 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
789 # Category.
790 echo -n "Category : " ; read anser
791 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
792 # Short description.
793 echo -n "Short desc : " ; read anser
794 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
795 # Maintainer.
796 echo -n "Maintainer : " ; read anser
797 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
798 # Web site.
799 echo -n "Web site : " ; read anser
800 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
801 echo ""
802 # Wget URL.
803 echo "Wget URL to download source tarball."
804 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
805 echo -n "Wget url : " ; read anser
806 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$anser\""# receipt
807 # Ask for a stuff dir.
808 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
809 if [ "$anser" = "y" ]; then
810 echo -n "Creating the stuff directory..."
811 mkdir $WOK/$pkg/stuff && status
812 fi
813 # Ask for a description file.
814 echo -n "Are you going to write a description ? (y/N) : " ; read anser
815 if [ "$anser" = "y" ]; then
816 echo -n "Creating the description.txt file..."
817 echo "" > $WOK/$pkg/description.txt && status
818 fi
819 separator
820 gettext -e "Receipt is ready to use.\n"
821 echo "" ;;
822 esac ;;
823 list)
824 # Cook a list of packages (better use the Cooker since it will order
825 # packages before executing cook).
826 check_root
827 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
828 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
829 echo -e " $2\n" && exit 1
830 echo "Cook list starting: $2" | log
831 for pkg in $(cat $2)
832 do
833 cook $pkg || broken
834 done ;;
835 clean-wok)
836 check_root
837 gettext -e "\nCleaning all packages files..."
838 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
839 status && echo "" ;;
840 clean-src)
841 check_root
842 gettext -e "\nCleaning all packages sources..."
843 rm -rf $WOK/*/source
844 status && echo "" ;;
845 pkglist)
846 # Create suitable packages list for TazPKG and only for built packages.
847 [ "$2" ] && PKGS="$2"
848 [ ! -d "$PKGS" ] && \
849 gettext -e "\nPackages directory doesn't exist\n\n" && exit 1
850 echo "cook:pkglist" > $command
851 echo "Cook pkglist: Creating all packages lists" | log
852 gettext -e "\nCreating lists for:"; echo " $PKGS"
853 separator
854 cd $PKGS
855 rm -f packages.*
856 gettext "Creating: packages.list: "
857 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
858 echo $(du -sh $PKGS/packages.list | awk '{print $1}')
859 gettext "Creating: packages.md5: "
860 md5sum *.tazpkg > $PKGS/packages.md5
861 echo $(du -sh $PKGS/packages.md5 | awk '{print $1}')
862 gettext -e "Creating lists from:"; echo " $WOK"
863 cd $WOK
864 for pkg in *
865 do
866 unset_receipt
867 . $pkg/receipt
868 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
869 # packages.desc lets us search easily in DB
870 cat >> $PKGS/packages.desc << EOT
871 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
872 EOT
873 # packages.txt used by tazpkg and tazpkg-web also to provide
874 # a human readable package list with version and description.
875 cat >> $PKGS/packages.txt << EOT
876 $PACKAGE
877 ${VERSION}$EXTRAVERSION
878 $SHORT_DESC
879 $PACKED_SIZE ($UNPACKED_SIZE installed)
881 EOT
882 # packages.equiv is used by tazpkg install to check depends.
883 for i in $PROVIDE; do
884 DEST=""
885 echo $i | fgrep -q : && DEST="${i#*:}:"
886 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
887 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
888 $PKGS/packages.equiv
889 else
890 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
891 fi
892 done
893 # files.list provides a list of all packages files.
894 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
895 $PKGS/files.list
896 fi
897 done
898 cd $PKGS
900 # Display list size.
901 gettext "Done: packages.desc: "
902 echo $(du -sh $PKGS/packages.desc | awk '{print $1}')
903 gettext "Done: packages.txt: "
904 echo $(du -sh $PKGS/packages.txt | awk '{print $1}')
905 gettext "Done: packages.equiv: "
906 echo $(du -sh $PKGS/packages.equiv | awk '{print $1}')
908 # files.list.lzma
909 gettext "Creating: files.list.lzma: "
910 lzma e files.list files.list.lzma
911 rm -f files.list
912 echo $(du -sh $PKGS/files.list.lzma | awk '{print $1}')
914 separator
915 nb=$(ls $PKGS/*.tazpkg | wc -l)
916 echo -e "Packages: $nb\n"
917 rm -f $command ;;
918 *)
919 # Just cook and generate a package.
920 check_root
921 time=$(date +%s)
922 pkg="$1"
923 [ -z "$pkg" ] && usage
924 receipt="$WOK/$pkg/receipt"
925 check_pkg_in_wok && echo ""
927 # Display and log info if cook process stopped.
928 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
929 tee -a $LOGS/$pkg.log' INT
931 # Skip blocked, 3 lines also for the Cooker.
932 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
933 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
934 fi
936 # Log and source receipt.
937 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
938 echo "cook:$pkg" > $command
939 unset inst
940 unset_receipt
941 . $receipt
943 # Handle --options
944 case "$2" in
945 --clean|-c)
946 gettext -e "Cleaning:"; echo -n " $pkg"
947 cd $WOK/$pkg && rm -rf install taz source
948 status && echo "" && exit 0 ;;
949 --install|-i)
950 inst='yes' ;;
951 --getsrc|-gs)
952 gettext "Getting source for:"; echo " $pkg"
953 separator && get_source
954 echo -e "Tarball: $SRC/$TARBALL\n" && exit 0 ;;
955 --block|-b)
956 gettext "Blocking:"; echo -n " $pkg"
957 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
958 status && echo "" && exit 0 ;;
959 --unblock|-ub)
960 gettext "Unblocking:"; echo -n " $pkg"
961 sed -i "/^${pkg}$/"d $blocked
962 status && echo "" && exit 0 ;;
964 esac
966 # Check if wanted is built now so we have separate log files.
967 if [ "$WANTED" ]; then
968 if grep -q "^$WANTED$" $blocked; then
969 echo "WANTED package is blocked: $WANTED" | tee $LOGS/$pkg.log
970 echo "" && rm -f $command && exit 1
971 fi
972 if grep -q "^$WANTED$" $broken; then
973 echo "WANTED package is broken: $WANTED" | tee $LOGS/$pkg.log
974 echo "" && rm -f $command && exit 1
975 fi
976 if [ ! -d "$WOK/$WANTED/install" ]; then
977 cook "$WANTED" || exit 1
978 fi
979 fi
981 # Cook and pack or exit on error and log everything.
982 cookit $@ 2>&1 | tee $LOGS/$pkg.log
983 remove_deps | tee -a $LOGS/$pkg.log
984 cookit_quality
985 packit 2>&1 | tee -a $LOGS/$pkg.log
986 clean_log
988 # Exit if any error in packing.
989 if grep -q ^ERROR $LOGS/$pkg.log; then
990 debug_info | tee -a $LOGS/$pkg.log
991 rm -f $command && exit 1
992 fi
994 # Time and summary
995 time=$(($(date +%s) - $time))
996 summary | tee -a $LOGS/$pkg.log
997 echo ""
999 # Install package if requested
1000 if [ "$inst" ]; then
1001 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1002 cd $PKGS && tazpkg install \
1003 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
1004 else
1005 gettext -e "Unable to install package, build has failed.\n\n"
1006 exit 1
1007 fi
1008 fi
1009 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
1010 # You want automation: use the Cooker Build Bot.
1011 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
1012 rm -f $command ;;
1013 esac
1015 exit 0