wok view tazbb/stuff/tazbb @ rev 5823

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