wok-6.x view tazbb/stuff/tazbb @ rev 5034
tazbb: clean flavor status
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Mar 03 11:58:08 2010 +0100 (2010-03-03) |
parents | d6cd66a2b5fc |
children | 8c1a39e4682c |
line source
1 #!/bin/sh
2 # Tazbb - SliTaz Build Bot.
3 # System wide config file: /etc/slitaz/tazbb.conf
4 #
5 # Tazbb is a tool to automate package building, it can be run manually
6 # or via a cron job. On SliTaz build host, tazbb is run in a chroot env.
7 #
8 # (c) 2009 SliTaz GNU/Linux project - GNU gpl v3
9 #
11 # Include config file or exit if no file found.
12 if [ -f "./tazbb.conf" ]; then
13 . ./tazbb.conf
14 elif [ -f "/etc/slitaz/tazbb.conf" ]; then
15 . /etc/slitaz/tazbb.conf
16 else
17 echo -e "\nNo config file found: tazbb.conf...\n" && exit 0
18 fi
20 # Tazbb is only for root.
21 if test $(id -u) != 0 ; then
22 echo -e "\nYou must be root to run: `basename $0`.\n" && exit 0
23 fi
25 # Let tazbb finish is work and make sure needed files exist.
26 if [ -f $LOCK_FILE ]; then
27 case $1 in
28 usage|list-*|*block)
29 continue ;;
30 *)
31 echo -e "\nTazbb is already running and locked...\n"
32 exit 0 ;;
33 esac
34 else
35 mkdir -p $DB_DIR $LOG_DIR
36 touch $LOCK_FILE $DB_DIR/blocked
37 fi
39 # Set KERNEL variable
40 if [ -s $BUILD_WOK/linux/receipt ]; then
41 . $BUILD_WOK/linux/receipt
42 KERNEL=$VERSION
43 fi
45 usage()
46 {
47 echo -e "\nSliTaz developers and build host tool\n
48 \033[1mUsage: \033[0m `basename $0` [command] [--option]
49 \033[1mCommands: \033[0m\n
50 usage Print this short usage and command list.
51 list-pkgs List last cooked packages with date.
52 report Run in report mode and dont cook anything [--verbose].
53 cook Cook, install and log a single package build.
54 cook-all Cook all missing, modified or unbuilt packages.
55 cook-commit Cook all packages affected by a commit in the last update.
56 test-pkgs Execute a test suite on all packages [--verbose].
57 [un]block Block or unblock a package to skip or enable building.
58 mail Send mail to package maintainer with tazbbmail.
59 check-depends Verify DEPENDS value with library needs [--verbose].
60 clean-up Remove old packages [--verbose|--dry-run].
61 clean-log Remove all generated build log files.\n"
62 }
64 status()
65 {
66 local CHECK=$?
67 echo -en "\033[70G"
68 if [ $CHECK = 0 ]; then
69 echo "Done"
70 else
71 echo "Failed"
72 fi
73 return $CHECK
74 }
76 top_summary()
77 {
78 cat > $DB_DIR/summary << _EOT_
79 Update : `date`
80 Revision : $NEW_REV (<a href="$HG_URL/log/$NEW_REV">changelog</a>)
81 _EOT_
82 }
84 packages_summary()
85 {
86 if ! grep -q "^Packages" $DB_DIR/summary; then
87 cat >> $DB_DIR/summary << _EOT_
88 Packages : `ls $BUILD_WOK | wc -l` in the wok, `cat $DB_DIR/cooklist | wc -l` to cook, \
89 `cat $DB_DIR/blocked | wc -l` blocked, `cat $DB_DIR/corrupted | wc -l` corrupted
90 _EOT_
91 fi
92 }
94 VERBOSE=""
96 packages_summary_update()
97 {
98 sed -i s/"[0-9]* in the wok"/"`ls $BUILD_WOK | wc -l` in the wok"/ \
99 $DB_DIR/summary
100 sed -i s/"[0-9]* to cook"/"`cat $DB_DIR/cooklist | wc -l` to cook"/ \
101 $DB_DIR/summary
102 sed -i s/"[0-9]* blocked"/"`cat $DB_DIR/blocked | wc -l` blocked"/ \
103 $DB_DIR/summary
104 sed -i s/"[0-9]* corrupted"/"`cat $DB_DIR/corrupted | wc -l` corrupted"/ \
105 $DB_DIR/summary
106 }
108 list_packages()
109 {
110 cd $PACKAGES_REPOSITORY
111 ls -1t *.tazpkg | head -20 | \
112 while read file
113 do
114 echo -n $(stat -c '%y' $PACKAGES_REPOSITORY/$file | cut -d. -f1)
115 echo " $file"
116 done
117 }
119 show_report()
120 {
121 echo "Cooklist"
122 echo "================================================================================"
123 cat $DB_DIR/cooklist && echo ""
124 echo "Packlist"
125 echo "================================================================================"
126 cat $DB_DIR/packlist && echo ""
127 echo "Blocked"
128 echo "================================================================================"
129 cat $DB_DIR/blocked && echo ""
130 echo ""
131 }
133 # URL encoding
134 escape()
135 {
136 echo $1 | sed -e 's/+/%2B/g' -e 's|/|%2F|g' -e 's/:/%3A/g'
137 }
139 update_wok()
140 {
141 local forced
142 forced=""
143 echo ""
144 echo "(updating flavors)" > $DB_DIR/running
145 cd $HG_FLAVORS
146 LAST_REV=`hg head --template '{rev}\n'`
147 hg pull && hg update
148 NEW_REV=`hg head --template '{rev}\n'`
149 if [ "$NEW_REV" != "$LAST_REV" ]; then
150 size=`du -sh $HG_FLAVORS | awk '{ print $1 }'`
151 echo -n "Copying Hg flavors to the build flavors ($size)... "
152 cp -a $HG_FLAVORS/* $BUILD_FLAVORS
153 cp -a $HG_FLAVORS/.hg $BUILD_FLAVORS
154 echo -e "Done\n"
155 forced="yes"
156 fi
157 echo "(updating wok)" > $DB_DIR/running
158 cd $HG_WOK
159 LAST_REV=`hg head --template '{rev}\n'`
160 hg pull && hg update
161 NEW_REV=`hg head --template '{rev}\n'`
162 # Gen a new summary and link last revision for the web interface.
163 echo -e "\nHg wok : $HG_WOK ($NEW_REV)"
164 echo -e "Build wok : $BUILD_WOK ($LAST_REV)\n"
165 top_summary
166 # Copy Hg wok if new revision or exit to stop process since nothing
167 # have change (--forced can be used).
168 if [ "$NEW_REV" != "$LAST_REV" ]; then
169 size=`du -sh $HG_WOK | awk '{ print $1 }'`
170 echo -n "Copying Hg wok to the build wok ($size)... "
171 #rsync -r -n -t $HG_WOK/ $BUILD_WOK/
172 cp -a $HG_WOK/* $BUILD_WOK
173 cp -a $HG_WOK/.hg $BUILD_WOK
174 echo -e "Done\n"
175 else
176 if [ "$1" = "cook-all" ] || [ "$1" = "cook-commit" ]; then
177 if [ "$2" != "--forced" -a -z "$forced" ]; then
178 echo -e "Nothing to cook...\n"
179 packages_summary
180 rm -f $LOCK_FILE && exit 0
181 fi
182 fi
183 fi
184 }
186 # Running 'tazbb report' should not pack anything and --verbose option
187 # can be used to display more messages.
188 check_flavors()
189 {
190 # Clean up last results.
191 rm -f $DB_DIR/packlist && touch $DB_DIR/packlist
192 echo ""
193 echo "Checking all files in: $HG_FLAVORS"
194 echo "================================================================================"
195 echo "(checking flavors)" > $DB_DIR/running
196 for flavor in $(cd $HG_FLAVORS ; ls)
197 do
198 [ "$2" = "--verbose" ] && echo "Flavor : $flavor"
199 if [ ! -s $PACKAGES_REPOSITORY/$flavor.flavor ]; then
200 echo $flavor >> $DB_DIR/packlist
201 [ "$1" = "report" ] && echo "Missing : $flavor"
202 echo "Missing flavor : $flavor" >> $DB_DIR/report
203 continue
204 fi
205 for i in $(find $HG_FLAVORS/$flavor -type f); do
206 [ $PACKAGES_REPOSITORY/$flavor.flavor -nt \
207 $i ] && continue
208 echo $flavor >> $DB_DIR/packlist
209 [ "$1" = "report" ] && echo "Refresh : $flavor for $i"
210 echo "Refresh flavor : $flavor" >> $DB_DIR/report
211 continue 2
212 done
213 [ -s $HG_FLAVORS/$flavor/packages.list ] &&
214 for i in $(cat $HG_FLAVORS/$flavor/packages.list); do
215 if [ ! -d $BUILD_WOK/$i ]; then
216 [ "$1" = "report" ] &&
217 echo "Fix flavor for $i: $flavor"
218 echo "Fix flavor for $i: $flavor" >> $DB_DIR/report
219 continue
220 fi
221 [ $PACKAGES_REPOSITORY/$flavor.flavor -nt \
222 $BUILD_WOK/$i/taz ] && continue
223 echo $flavor >> $DB_DIR/packlist
224 [ "$1" = "report" ] && echo "Repack : $flavor for $i"
225 echo "Repack flavor : $flavor" >> $DB_DIR/report
226 continue 2
227 done
228 done
230 # Check for meta flavors
231 for flavor in $(cd $HG_FLAVORS ; ls)
232 do
233 grep -q ^ROOTFS_SELECTION $HG_FLAVORS/$flavor/receipt || continue
234 . $HG_FLAVORS/$flavor/receipt
235 set -- $ROOTFS_SELECTION
236 if [ $PACKAGES_REPOSITORY/$2.flavor -nt \
237 $PACKAGES_REPOSITORY/$flavor.flavor ]; then
238 echo $flavor >> $DB_DIR/packlist
239 [ "$1" = "report" ] && echo "Refresh : $flavor for $2"
240 echo "Refresh meta flavor : $flavor" >> $DB_DIR/report
241 continue
242 fi
243 if grep -q ^$2$ $DB_DIR/packlist ; then
244 echo $flavor >> $DB_DIR/packlist
245 [ "$1" = "report" ] && echo "Repack : $flavor for $2"
246 echo "Repack meta flavor : $flavor" >> $DB_DIR/report
247 continue
248 fi
249 done
250 }
252 # Here we pack all flavors found in the packlist.
253 pack_flavors()
254 {
255 [ -s $DB_DIR/packlist ] || return
256 [ $PACKAGES_REPOSITORY/packages.list -nt /var/lib/tazpkg/packages.list ] &&
257 cp -a $PACKAGES_REPOSITORY/packages.list /var/lib/tazpkg/packages.list
258 cd $PACKAGES_REPOSITORY
259 for flavor in $(cat $DB_DIR/packlist)
260 do
261 tazlito pack-flavor $flavor
262 # Remove flavor from the packlist and empty lines for HTML <pre>.
263 sed -i /"^$flavor$"/d $DB_DIR/packlist
264 sed -i '/^$/d' $DB_DIR/packlist
265 done
266 cd - > /dev/null
267 }
269 # Running 'tazbb report' should not cook anything and --verbose option
270 # can be used to display more messages.
271 check_wok()
272 {
273 # Clean up last results.
274 rm -f $DB_DIR/cooklist && touch $DB_DIR/cooklist
275 rm -f $DB_DIR/report && touch $DB_DIR/report
276 rm -f $DB_DIR/unbuilt && touch $DB_DIR/unbuilt
277 echo "Checking all files in: $HG_WOK"
278 echo "================================================================================"
279 echo "(checking wok)" > $DB_DIR/running
280 for pkg in $HG_WOK/*
281 do
282 EXTRAVERSION=""
283 WANTED=""
284 . $pkg/receipt
285 [ "$2" = "--verbose" ] && echo "Package : $PACKAGE"
286 # Skip blocked packages.
287 if grep -qs "^$PACKAGE$" $DB_DIR/blocked; then
288 echo "Blocked : $PACKAGE ($VERSION)" && continue
289 fi
291 # Some packages may compute VERSION at cook time (bristuff)
292 if grep -q ^get_version $pkg/receipt; then
293 . $BUILD_WOK/$PACKAGE/taz/*/receipt
294 fi
296 # First check if package exit. Package naming _must_ be in the form of:
297 # $PACKAGE-$VERSION or $PACKAGE-${VERSION}$EXTRAVERSION (Kernel string).
298 if [ ! -f $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg ]; then
299 [ -z "$EXTRAVERSION" ] && EXTRAVERSION="_$KERNEL"
300 if [ ! -f $PACKAGES_REPOSITORY/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg ]; then
301 [ "$1" = "report" ] && echo "Missing : $PACKAGE ($VERSION)"
302 echo "Missing : $PACKAGE ($VERSION)" >> $DB_DIR/report
303 echo "$PACKAGE" >> $DB_DIR/cooklist
304 fi
305 else
306 # Check if package is up-to-date.
307 PKG_DATE=`date -u -r $PACKAGES_REPOSITORY/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg '+%Y%m%d%H%M'`
308 for file in `find $pkg -type f`
309 do
310 FILE_DATE=`date -u -r $file '+%Y%m%d%H%M'`
311 [ "$2" = "--verbose" ] && echo " -> Checking: $file"
312 if [ "$FILE_DATE" -gt "$PKG_DATE" ] && ! grep -q $PACKAGE $DB_DIR/cooklist; then
313 [ "$1" = "report" ] && echo "Refresh : $PACKAGE ($VERSION)"
314 echo "Refresh : $PACKAGE ($VERSION)" >> $DB_DIR/report
315 echo "$PACKAGE" >> $DB_DIR/cooklist
316 fi
317 done
318 fi
319 # Now check if package is built and not already in the list.
320 if [ ! -d $BUILD_WOK/$PACKAGE/taz ] && ! grep -q $PACKAGE $DB_DIR/cooklist; then
321 [ "$1" = "report" ] && echo "Unbuilt : $PACKAGE ($VERSION)"
322 echo "Unbuilt : $PACKAGE ($VERSION)" >> $DB_DIR/report
323 echo "$PACKAGE" >> $DB_DIR/cooklist
324 fi
325 # Rebuild unbuilt packages list with link to log file. This list
326 # is also generated by cook_inslall to have real time stats.
327 if [ ! -d $BUILD_WOK/$PACKAGE/taz ]; then
328 echo "<a href=\"log.php?package=$(escape $PACKAGE)\">$PACKAGE</a>" \
329 >> $DB_DIR/unbuilt
330 fi
331 done
332 packages_summary
333 }
335 # Create a new cooklist and summary (dont modify report) so 'tazbb cook-commit'
336 # can cook last changes.
337 check_commit()
338 {
339 echo "(checking commit)" > $DB_DIR/running
340 cd $HG_WOK
341 # Clean up last results.
342 rm -f $DB_DIR/cooklist && touch $DB_DIR/cooklist
343 # Get the name of modified packages by the revision range. +1 last
344 # commit was build by the previous build.
345 LAST_REV=$(($LAST_REV+1))
346 echo -e "Will cook from revision $LAST_REV to $NEW_REV\n"
347 for file in `hg log --rev=$LAST_REV:$NEW_REV --template '{files}\n'`
348 do
349 pkg=`echo $file | cut -d "/" -f 1`
350 if ! grep -q ^$pkg$ $DB_DIR/cooklist; then
351 . $pkg/receipt
352 echo "Commit : $PACKAGE ($VERSION)" >> $DB_DIR/report
353 echo "$PACKAGE" >> $DB_DIR/cooklist
354 fi
355 done
356 packages_summary
357 }
359 # Cook one package
360 cook_package()
361 {
362 EXTRAVERSION=""
363 DEPENDS=""
364 BUILD_DEPENDS=""
365 SOURCE=""
366 WANTED=""
367 echo "(cooking <a href=\"log.php?package=$(escape $pkg)\">$pkg</a>)" > $DB_DIR/running
368 tazwok clean $pkg
369 script -c "echo 'install' | tazwok cook $pkg" $LOG_DIR/$pkg.log
370 # Install new package (important for new shared libs). Note
371 # that tests are done separatly with 'test_packages' and should
372 # be done by tazwok.
373 if [ -f $BUILD_WOK/$pkg/taz/*/receipt ]; then
374 TAZBB_NO_INSTALL=""
375 . $BUILD_WOK/$pkg/taz/*/receipt
376 [ -n "$TAZBB_NO_INSTALL" ] && return 0
377 echo "(installing $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg)" \
378 > $DB_DIR/running
379 yes | tazpkg install \
380 $PACKAGES_REPOSITORY/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg \
381 --forced
382 return 0
383 fi
384 return 1
385 }
387 # Sort list according WANTED and BUILD_DEPENDS
388 sort_cook_list()
389 {
390 sort | while read pkg; do
391 echo -n "$pkg"
392 WANTED=""
393 BUILD_DEPENDS=""
394 . $BUILD_WOK/$pkg/receipt
395 MISSING=""
396 for i in $WANTED $BUILD_DEPENDS ; do
397 if [ ! -f $BUILD_WOK/$i/taz/*/receipt ]; then
398 case " $MISSING " in
399 *\ $i\ *);;
400 *) echo -n " $i";;
401 esac
402 MISSING="$MISSING $i"
403 fi
404 done
405 echo ""
406 done | awk '
407 function show(name)
408 {
409 print name;
410 got[name]++;
411 if (revdepcnt[name] > 0)
412 for (i = split(revdep[name], pkg, " "); i > 0; i--)
413 if (--depcnt[pkg[i]] == 0) show(pkg[i]);
414 }
416 {
417 if ($2 == "") show($1);
418 else {
419 depcnt[$1] = NF - 1;
420 unres = unres " " $1;
421 for (i = 2; i <= NF; i++) {
422 if (got[$i] > 0) continue;
423 revdepcnt[$i]++;
424 revdep[$i] = revdep[$i] " " $1;
425 }
426 }
427 }
428 END {
429 for (i = split(unres, pkg, " "); i > 0; i--)
430 if (depcnt[pkg[i]] > 0) print pkg[i];
431 }
432 '
433 }
435 # Here we cook all packages found in the cooklist.
436 cook_install()
437 {
438 echo "" > $DB_DIR/unbuilt
439 for pkg in `cat $DB_DIR/cooklist | sort_cook_list`
440 do
441 if ! cook_package $pkg; then
442 # Link to build log.
443 echo "<a href=\"log.php?package=$(escape $pkg)\">$pkg</a>" >> \
444 $DB_DIR/unbuilt
445 fi
446 missing_depends="$(check_depends_pkg $pkg)"
447 if [ -n "$missing_depends" ]; then
448 cat >> $LOG_DIR/$pkg.log <<EOT
450 Update $pkg receipt for DEPENDS :
451 The package $pkg depends on packages $missing_depends
453 EOT
454 # Unbuild package
455 rm -rf $BUILD_WOK/$pkg/taz
456 # Link to build log.
457 echo "<a href=\"log.php?package=$(escape $pkg)\">$pkg</a>" >> \
458 $DB_DIR/unbuilt
459 fi
460 # Remove package from the cooklist and empty lines for HTML <pre>.
461 sed -i /"^$pkg$"/d $DB_DIR/cooklist
462 sed -i '/^$/d' $DB_DIR/cooklist
463 packages_summary_update
464 done
465 }
467 # Build depends_to_skip list with packages to remove from depends_to_add list
468 # These packages are already present in depends_to_add trees
469 scan_depends_to_skip()
470 {
471 local i
472 case " $depends_to_skip " in
473 *\ $1\ *) return;;
474 esac
475 [ -d $BUILD_WOK/$1 ] || return
476 DEPENDS=""
477 . $BUILD_WOK/$1/receipt
478 for i in $DEPENDS ; do
479 case " $depends_to_add " in
480 *\ $i\ *) depends_to_skip="$depends_to_skip $i";;
481 esac
482 done
483 for i in $DEPENDS ; do
484 scan_depends_to_skip $i
485 done
486 }
488 # Reduce depends list by scanning nested depends
489 show_missing_depends()
490 {
491 local i
492 depends_to_add=""
493 depends_to_skip="$2"
494 for i in $1 ; do
495 case " $depends_to_add " in
496 *\ $i\ *) continue;;
497 esac
498 depends_to_add="$depends_to_add$i "
499 done
500 for i in $depends_to_add ; do
501 scan_depends_to_skip $i
502 done
503 for i in $depends_to_add ; do
504 case " $depends_to_skip " in
505 *\ $i\ *) continue;;
506 esac
507 echo -n "$i "
508 done
509 }
511 # Build all_depends variable
512 scan_dep()
513 {
514 local i
515 all_depends="$all_depends$PACKAGE "
516 for i in $DEPENDS $SUGGESTED ; do
517 case " $all_depends " in
518 *\ $i\ *) continue;;
519 esac
520 [ -d $BUILD_WOK/$i ] || {
521 all_depends="$all_depends$i "
522 continue
523 }
524 DEPENDS=""
525 SUGGESTED=""
526 . $BUILD_WOK/$i/receipt
527 scan_dep
528 done
529 }
531 # Check for ELF file
532 is_elf()
533 {
534 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
535 }
537 # Print shared library dependencies
538 ldd()
539 {
540 LD_PRELOAD="" LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
541 }
543 # scan a file for shared libraries and display according package names
544 check_depends_file()
545 {
546 file=$1
547 is_elf $file || continue
548 case "$file" in
549 *.o|*.ko|*.ko.gz) continue;;
550 esac
551 [ -s /tmp/files.list.tazbb$$ ] ||
552 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma >/tmp/files.list.tazbb$$
553 ldd $file | while read lib rem; do
554 case "$lib" in
555 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
556 continue;;
557 esac
558 for dep in $(grep $lib /tmp/files.list.tazbb$$ | cut -d: -f1); do
559 case " $all_depends " in
560 *\ $dep\ *) continue 2;;
561 esac
562 for vdep in $(grep $dep $PACKAGES_REPOSITORY/packages.equiv | cut -d= -f1); do
563 case " $all_depends " in
564 *\ $vdep\ *) continue 3;;
565 esac
566 done
567 done
568 [ -n "$dep" ] || dep="UNKNOWN"
569 all_depends="$all_depends $dep"
570 if [ -n "$VERBOSE" ]; then
571 echo "${file#*fs} depends on package $dep for the shared library $lib" 1>&2
572 fi
573 echo -n "$dep "
574 done
575 }
577 DEFAULT_DEPENDS="glibc-base"
579 # scan a package for shared libraries and display missing package in DEPENDS
580 check_depends_pkg()
581 {
582 pkg=$1
583 echo "(checking depends for $pkg)" > $DB_DIR/running
584 tmp=/tmp/tazbb$$
585 mkdir $tmp
586 package=$(basename $pkg)
587 if ! cd ${package%%-*}*/taz/${package%.tazpkg}/.. 2> /dev/null; then
588 cd $tmp
589 tazpkg extract $pkg > /dev/null 2>&1
590 fi
591 . */receipt
592 all_depends="$DEFAULT_DEPENDS "
593 scan_dep
594 toadd=$(find */fs -type f | while read file ; do
595 check_depends_file $file
596 done)
597 . */receipt
598 rm -rf */
599 cd - > /dev/null
600 rm -rf $tmp
601 show_missing_depends "$toadd" "$DEPENDS $SUGGESTED"
602 }
604 check_depends_this_file()
605 {
606 file=$1
607 all_depends="$DEFAULT_DEPENDS "
608 scan_dep
609 check_depends_file $file
610 }
612 # Remove old packages in the build wok and clean pkgs repository. The
613 # Hg wok is copied into the build wok so packages removed by hg must be
614 # removed. To remove old packages in the repository we look into the
615 # build wok and dont remove unbuilt packages. Clean-up will also remove
616 # all corrupted packages.
617 clean_up()
618 {
619 touch $DB_DIR/removed
620 echo -e "\nCleaning the build wok, old and corrupted packages...\n"
621 echo "(cleaning)" > $DB_DIR/running
622 for pkg in `ls $BUILD_WOK`
623 do
624 if [ ! -d $HG_WOK/$pkg ]; then
625 case $2 in
626 --dry-run)
627 echo "Removing directory : $pkg" ;;
628 --verbose)
629 echo "Removing directory : $pkg"
630 rm -rf $BUILD_WOK/$pkg ;;
631 *)
632 rm -rf $BUILD_WOK/$pkg ;;
633 esac
634 fi
635 done
636 # Build a packages list with EXTRAVERSION so we can grep into it.
637 rm -f $DB_DIR/packaged && touch $DB_DIR/packaged
638 for receipt in $BUILD_WOK/*/taz/*/receipt
639 do
640 EXTRAVERSION=""
641 . $receipt
642 echo "$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" >> $DB_DIR/packaged
643 done
644 for pkg in `cd $PACKAGES_REPOSITORY && ls *.tazpkg`
645 do
646 if ! grep -q "^$pkg$" $DB_DIR/packaged; then
647 case $2 in
648 --dry-run)
649 echo "Removing package : $pkg" ;;
650 --verbose)
651 echo "Removing package : $pkg"
652 echo "$pkg" >> $DB_DIR/removed
653 rm -f $PACKAGES_REPOSITORY/$pkg ;;
654 *)
655 echo "$pkg" >> $DB_DIR/removed
656 rm -f $PACKAGES_REPOSITORY/$pkg ;;
657 esac
658 fi
659 done
660 # Remove all corrupted packages
661 for pkg in `cat $DB_DIR/corrupted | awk '{ print $3 }'`
662 do
663 case $2 in
664 --dry-run)
665 echo "Removing corrupted: $pkg" ;;
666 --verbose)
667 echo "Removing corrupted: $pkg"
668 echo "$pkg" >> $DB_DIR/removed
669 rm -rf $PACKAGES_REPOSITORY/$pkg ;;
670 *)
671 echo "$pkg" >> $DB_DIR/removed
672 rm -rf $PACKAGES_REPOSITORY/$pkg ;;
673 esac
674 done
675 echo ""
676 # Keep the 20 last removed packages list.
677 cat $DB_DIR/removed | tail -n 20 > /tmp/removed.tail
678 mv -f /tmp/removed.tail $DB_DIR/removed
679 }
681 blocked_urls()
682 {
683 rm -f $DB_DIR/blocked.urls
684 for pkg in `cat $DB_DIR/blocked`
685 do
686 if [ -f $LOG_DIR/$pkg.log ]; then
687 echo "<a href=\"log.php?package=$(escape $pkg)\">$pkg</a>" >> \
688 $DB_DIR/blocked.urls
689 else
690 echo "$pkg" >> $DB_DIR/blocked.urls
691 fi
692 done
693 }
695 # 4k, not a meta or a get-* package and no files = buggy package
696 test_packages()
697 {
698 echo -e "\nTesting all packages in: $PACKAGES_REPOSITORY"
699 echo "================================================================================"
700 echo "(testing packages)" > $DB_DIR/running
701 rm -f $DB_DIR/corrupted && touch $DB_DIR/corrupted
702 for pkg in $PACKAGES_REPOSITORY/*.tazpkg
703 do
704 tmp=/tmp/bb-test.$$
705 CATEGORY=""
706 if du $pkg | grep -qw '^4' && ! echo `basename $pkg` | grep -q '^get-'; then
707 mkdir -p $tmp && cd $tmp
708 cpio -i receipt >/dev/null 2>&1 < $pkg
709 . ./receipt
710 if [ "$CATEGORY" != "meta" ]; then
711 [ "$2" = "--verbose" ] && echo "Testing: $PACKAGE"
712 cpio -i fs.cpio.gz fs.cpio.lzma >/dev/null 2>&1 < $pkg
713 if [ ! -f fs.cpio.gz -a ! -f fs.cpio.lzma ]; then
714 echo "Missing filesystem `basename $pkg`"
715 if [ -f $LOG_DIR/$PACKAGE.log ];then
716 echo "Missing filesystem `basename $pkg` <a href=\"log.php?package=$(escape $PACKAGE)\">Log</a>" \
717 >> $DB_DIR/corrupted
718 else
719 echo "Missing filesystem `basename $pkg`" \
720 >> $DB_DIR/corrupted
721 fi
722 else
723 ( zcat fs.cpio.gz 2> /dev/null || \
724 unlzma -c fs.cpio.lzma ) | \
725 cpio -id >/dev/null 2>&1
726 files=`find fs -type f -o -type l`
727 if [ -z "$files" ]; then
728 echo "Empty filesystem `basename $pkg`"
729 if [ -f $LOG_DIR/$PACKAGE.log ]; then
730 echo "Empty filesystem `basename $pkg` <a href=\"log.php?package=$(escape $PACKAGE)\">Log</a>" \
731 >> $DB_DIR/corrupted
732 else
733 echo "Empty filesystem `basename $pkg`" \
734 >> $DB_DIR/corrupted
735 fi
736 fi
737 fi
738 fi
739 cd .. && rm -rf $tmp
740 fi
741 done
742 packages_summary_update
743 echo ""
744 }
746 # Generate flavor list
747 gen_flavor_list()
748 {
749 cd $PACKAGES_REPOSITORY
750 noheader=""
751 for i in *.flavor; do
752 tazlito show-flavor $i --brief $noheader
753 noheader="--noheader"
754 done > flavors.list
755 cd - > /dev/null
756 }
758 case "$1" in
759 list-pkgs)
760 # List last cooked packages.
761 list_packages ;;
762 report)
763 # Run in report mode. If an update is done we must cook-all to
764 # rebuild all updated packages.
765 [ "$2" == "--update" ] && update_wok $@ || echo ""
766 check_wok $@
767 check_flavors $@
768 test_packages $@
769 show_report ;;
770 cook)
771 # Cook, install and log a single package build.
772 if [ -z $2 ]; then
773 echo "Please specify a package on the command line."
774 rm -f $LOCK_FILE && exit 0
775 fi
776 pkg=$2
777 echo "Starting to cook and install: $pkg"
778 if ! cook_package $pkg; then
779 echo "Unable to install: $pkg"
780 fi ;;
781 cook-all)
782 # Update wok, gen report (with cooklist), cook all packages, test,
783 # clean, gen new report and lists.
784 update_wok $@
785 check_wok $@
786 cook_install
787 test_packages $@
788 check_flavors $@
789 pack_flavors
790 clean_up $@
791 check_wok $@
792 echo "(generating lists)" > $DB_DIR/running
793 tazwok gen-list --text
794 check_flavors $@
795 gen_flavor_list
796 echo "" ;;
797 cook-commit)
798 # Cook all packages affected by the last commits in the wok.
799 # Clean up is done only by cook-all to avoid rebuild of corrupted
800 # packages on each commit.
801 update_wok $@
802 check_commit
803 cook_install
804 test_packages $@
805 check_flavors $@
806 pack_flavors
807 check_wok $@
808 check_flavors $@
809 echo "(generating lists)" > $DB_DIR/running
810 tazwok gen-list --text
811 gen_flavor_list
812 echo "" ;;
813 block)
814 # Add a pkg name to the list of blocked packages.
815 echo ""
816 if grep -qs "^$2$" $DB_DIR/blocked; then
817 echo -e "$2 is already in the blocked packages list."
818 else
819 echo -n "Adding $2 to : $DB_DIR/blocked... "
820 echo "$2" >> $DB_DIR/blocked && echo "Done"
821 if grep -q "^$2$" $DB_DIR/cooklist; then
822 echo -n "Removing $2 from : $DB_DIR/cooklist... "
823 sed -i /"^$2$"/d $DB_DIR/cooklist && echo "Done"
824 packages_summary_update
825 fi
826 fi
827 blocked_urls
828 echo "" ;;
829 unblock)
830 # Remove a pkg name from the list of blocked packages.
831 echo ""
832 if grep -qs "^$2$" $DB_DIR/blocked; then
833 echo -n "Removing $2 from : $DB_DIR/blocked... "
834 sed -i /"^$2$"/d $DB_DIR/blocked
835 sed -i '/^$/d' $DB_DIR/blocked && echo "Done"
836 echo -n "Adding $2 to : $DB_DIR/cooklist... "
837 echo "$2" >> $DB_DIR/cooklist && echo "Done"
838 packages_summary_update
839 else
840 echo -e "$2 is not in the blocked packages list."
841 fi
842 blocked_urls
843 echo "" ;;
844 test-pkgs)
845 # Start a test suite on all builded packages.
846 test_packages $@ ;;
847 test-suite)
848 # Start a test suite on all builded package and the wok using
849 # the great 'tazwok check'.
850 #
851 # test_packages > $LOG_DIR/test-suite.log
852 # tazwok check >> $LOG_DIR/test-suite.log
853 #
854 test_packages $@
855 script -c "tazwok check" $LOG_DIR/test-suite.log ;;
856 mail)
857 # Tazbbmail Pythom script wrapper.
858 PACKAGE=$2
859 tazbbmail $PACKAGE ;;
860 clean-up)
861 # Remove old packages and generate new packages lists.
862 update_wok $@
863 clean_up $@
864 packages_summary_update
865 [ "$2" != "--dry-run" ] && tazwok gen-list --text ;;
866 clean-log)
867 logs=`ls $LOG_DIR | wc -l`
868 echo -n "Cleaning: $LOG_DIR... "
869 rm -rf $LOG_DIR/*
870 echo "$logs log removed" ;;
871 check-depends)
872 case "$2" in
873 wok)
874 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
875 missing_depends="$(check_depends_pkg $pkg)"
876 [ -n "$missing_depends" ] &&
877 echo "The package $pkg depends on $missing_depends."
878 done ;;
879 package)
880 pkg=$3
881 VERBOSE=$4
882 missing_depends="$(check_depends_pkg $pkg)"
883 [ -n "$missing_depends" ] &&
884 echo "The package $pkg depends on $missing_depends."
885 ;;
886 file)
887 file=3
888 VERBOSE=$4
889 missing_depends="$(check_depends_this_file $file)"
890 [ -n "$missing_depends" ] &&
891 echo "The file $file depends on $missing_depends."
892 ;;
893 *) cat <<EOT
894 check-depends wok check every package in wok.
895 check-depends package <pkg> check one package.
896 check-depends file <filename> check one file only.
897 EOT
898 ;;
899 esac ;;
900 *)
901 usage ;;
902 esac
904 echo "" > $DB_DIR/running
905 rm -f $LOCK_FILE /tmp/files.list.tazbb$$
907 exit 0