wok view tazbb/stuff/tazbb @ rev 5289

Up: libssl (1.0.0) Match openssl
author Christophe Lincoln <pankso@slitaz.org>
date Sun Apr 18 20:56:58 2010 +0200 (2010-04-18)
parents 8c1a39e4682c
children 401a6a398aeb
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 rm -rf $BUILD_WOK/$pkg/$pkg-*
370 script -c "echo 'install' | tazwok cook $pkg" $LOG_DIR/$pkg.log
371 # Install new package (important for new shared libs). Note
372 # that tests are done separatly with 'test_packages' and should
373 # be done by tazwok.
374 if [ -f $BUILD_WOK/$pkg/taz/*/receipt ]; then
375 TAZBB_NO_INSTALL=""
376 . $BUILD_WOK/$pkg/taz/*/receipt
377 [ -n "$TAZBB_NO_INSTALL" ] && return 0
378 echo "(installing $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg)" \
379 > $DB_DIR/running
380 yes | tazpkg install \
381 $PACKAGES_REPOSITORY/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg \
382 --forced
383 return 0
384 fi
385 return 1
386 }
388 # Sort list according WANTED and BUILD_DEPENDS
389 sort_cook_list()
390 {
391 sort | while read pkg; do
392 echo -n "$pkg"
393 WANTED=""
394 BUILD_DEPENDS=""
395 . $BUILD_WOK/$pkg/receipt
396 MISSING=""
397 for i in $WANTED $BUILD_DEPENDS ; do
398 if [ ! -f $BUILD_WOK/$i/taz/*/receipt ]; then
399 case " $MISSING " in
400 *\ $i\ *);;
401 *) echo -n " $i";;
402 esac
403 MISSING="$MISSING $i"
404 fi
405 done
406 echo ""
407 done | awk '
408 function show(name)
409 {
410 print name;
411 got[name]++;
412 if (revdepcnt[name] > 0)
413 for (i = split(revdep[name], pkg, " "); i > 0; i--)
414 if (--depcnt[pkg[i]] == 0) show(pkg[i]);
415 }
417 {
418 if ($2 == "") show($1);
419 else {
420 depcnt[$1] = NF - 1;
421 unres = unres " " $1;
422 for (i = 2; i <= NF; i++) {
423 if (got[$i] > 0) continue;
424 revdepcnt[$i]++;
425 revdep[$i] = revdep[$i] " " $1;
426 }
427 }
428 }
429 END {
430 for (i = split(unres, pkg, " "); i > 0; i--)
431 if (depcnt[pkg[i]] > 0) print pkg[i];
432 }
433 '
434 }
436 # Here we cook all packages found in the cooklist.
437 cook_install()
438 {
439 echo "" > $DB_DIR/unbuilt
440 for pkg in `cat $DB_DIR/cooklist | sort_cook_list`
441 do
442 if ! cook_package $pkg; then
443 # Link to build log.
444 echo "<a href=\"log.php?package=$(escape $pkg)\">$pkg</a>" >> \
445 $DB_DIR/unbuilt
446 fi
447 missing_depends="$(check_depends_pkg $pkg)"
448 if [ -n "$missing_depends" ]; then
449 cat >> $LOG_DIR/$pkg.log <<EOT
451 Update $pkg receipt for DEPENDS :
452 The package $pkg depends on packages $missing_depends
454 EOT
455 # Unbuild package
456 rm -rf $BUILD_WOK/$pkg/taz
457 # Link to build log.
458 echo "<a href=\"log.php?package=$(escape $pkg)\">$pkg</a>" >> \
459 $DB_DIR/unbuilt
460 fi
461 # Remove package from the cooklist and empty lines for HTML <pre>.
462 sed -i /"^$pkg$"/d $DB_DIR/cooklist
463 sed -i '/^$/d' $DB_DIR/cooklist
464 packages_summary_update
465 done
466 }
468 # Build depends_to_skip list with packages to remove from depends_to_add list
469 # These packages are already present in depends_to_add trees
470 scan_depends_to_skip()
471 {
472 local i
473 case " $depends_to_skip " in
474 *\ $1\ *) return;;
475 esac
476 [ -d $BUILD_WOK/$1 ] || return
477 DEPENDS=""
478 . $BUILD_WOK/$1/receipt
479 for i in $DEPENDS ; do
480 case " $depends_to_add " in
481 *\ $i\ *) depends_to_skip="$depends_to_skip $i";;
482 esac
483 done
484 for i in $DEPENDS ; do
485 scan_depends_to_skip $i
486 done
487 }
489 # Reduce depends list by scanning nested depends
490 show_missing_depends()
491 {
492 local i
493 depends_to_add=""
494 depends_to_skip="$2"
495 for i in $1 ; do
496 case " $depends_to_add " in
497 *\ $i\ *) continue;;
498 esac
499 depends_to_add="$depends_to_add$i "
500 done
501 for i in $depends_to_add ; do
502 scan_depends_to_skip $i
503 done
504 for i in $depends_to_add ; do
505 case " $depends_to_skip " in
506 *\ $i\ *) continue;;
507 esac
508 echo -n "$i "
509 done
510 }
512 # Build all_depends variable
513 scan_dep()
514 {
515 local i
516 all_depends="$all_depends$PACKAGE "
517 for i in $DEPENDS $SUGGESTED ; do
518 case " $all_depends " in
519 *\ $i\ *) continue;;
520 esac
521 [ -d $BUILD_WOK/$i ] || {
522 all_depends="$all_depends$i "
523 continue
524 }
525 DEPENDS=""
526 SUGGESTED=""
527 . $BUILD_WOK/$i/receipt
528 scan_dep
529 done
530 }
532 # Check for ELF file
533 is_elf()
534 {
535 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
536 }
538 # Print shared library dependencies
539 ldd()
540 {
541 LD_PRELOAD="" LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
542 }
544 # scan a file for shared libraries and display according package names
545 check_depends_file()
546 {
547 file=$1
548 is_elf $file || continue
549 case "$file" in
550 *.o|*.ko|*.ko.gz) continue;;
551 esac
552 [ -s /tmp/files.list.tazbb$$ ] ||
553 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma >/tmp/files.list.tazbb$$
554 ldd $file | while read lib rem; do
555 case "$lib" in
556 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
557 continue;;
558 esac
559 for dep in $(grep $lib /tmp/files.list.tazbb$$ | cut -d: -f1); do
560 case " $all_depends " in
561 *\ $dep\ *) continue 2;;
562 esac
563 for vdep in $(grep $dep $PACKAGES_REPOSITORY/packages.equiv | cut -d= -f1); do
564 case " $all_depends " in
565 *\ $vdep\ *) continue 3;;
566 esac
567 done
568 done
569 [ -n "$dep" ] || dep="UNKNOWN"
570 all_depends="$all_depends $dep"
571 if [ -n "$VERBOSE" ]; then
572 echo "${file#*fs} depends on package $dep for the shared library $lib" 1>&2
573 fi
574 echo -n "$dep "
575 done
576 }
578 DEFAULT_DEPENDS="glibc-base"
580 # scan a package for shared libraries and display missing package in DEPENDS
581 check_depends_pkg()
582 {
583 pkg=$1
584 echo "(checking depends for $pkg)" > $DB_DIR/running
585 tmp=/tmp/tazbb$$
586 mkdir $tmp
587 package=$(basename $pkg)
588 if ! cd ${package%%-*}*/taz/${package%.tazpkg}/.. 2> /dev/null; then
589 cd $tmp
590 tazpkg extract $pkg > /dev/null 2>&1
591 fi
592 . */receipt
593 all_depends="$DEFAULT_DEPENDS "
594 scan_dep
595 toadd=$(find */fs -type f | while read file ; do
596 check_depends_file $file
597 done)
598 . */receipt
599 rm -rf */
600 cd - > /dev/null
601 rm -rf $tmp
602 show_missing_depends "$toadd" "$DEPENDS $SUGGESTED"
603 }
605 check_depends_this_file()
606 {
607 file=$1
608 all_depends="$DEFAULT_DEPENDS "
609 scan_dep
610 check_depends_file $file
611 }
613 # Remove old packages in the build wok and clean pkgs repository. The
614 # Hg wok is copied into the build wok so packages removed by hg must be
615 # removed. To remove old packages in the repository we look into the
616 # build wok and dont remove unbuilt packages. Clean-up will also remove
617 # all corrupted packages.
618 clean_up()
619 {
620 touch $DB_DIR/removed
621 echo -e "\nCleaning the build wok, old and corrupted packages...\n"
622 echo "(cleaning)" > $DB_DIR/running
623 for pkg in `ls $BUILD_WOK`
624 do
625 if [ ! -d $HG_WOK/$pkg ]; then
626 case $2 in
627 --dry-run)
628 echo "Removing directory : $pkg" ;;
629 --verbose)
630 echo "Removing directory : $pkg"
631 rm -rf $BUILD_WOK/$pkg ;;
632 *)
633 rm -rf $BUILD_WOK/$pkg ;;
634 esac
635 fi
636 done
637 # Build a packages list with EXTRAVERSION so we can grep into it.
638 rm -f $DB_DIR/packaged && touch $DB_DIR/packaged
639 for receipt in $BUILD_WOK/*/taz/*/receipt
640 do
641 EXTRAVERSION=""
642 . $receipt
643 echo "$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" >> $DB_DIR/packaged
644 done
645 for pkg in `cd $PACKAGES_REPOSITORY && ls *.tazpkg`
646 do
647 if ! grep -q "^$pkg$" $DB_DIR/packaged; then
648 case $2 in
649 --dry-run)
650 echo "Removing package : $pkg" ;;
651 --verbose)
652 echo "Removing package : $pkg"
653 echo "$pkg" >> $DB_DIR/removed
654 rm -f $PACKAGES_REPOSITORY/$pkg ;;
655 *)
656 echo "$pkg" >> $DB_DIR/removed
657 rm -f $PACKAGES_REPOSITORY/$pkg ;;
658 esac
659 fi
660 done
661 # Remove all corrupted packages
662 for pkg in `cat $DB_DIR/corrupted | awk '{ print $3 }'`
663 do
664 case $2 in
665 --dry-run)
666 echo "Removing corrupted: $pkg" ;;
667 --verbose)
668 echo "Removing corrupted: $pkg"
669 echo "$pkg" >> $DB_DIR/removed
670 rm -rf $PACKAGES_REPOSITORY/$pkg ;;
671 *)
672 echo "$pkg" >> $DB_DIR/removed
673 rm -rf $PACKAGES_REPOSITORY/$pkg ;;
674 esac
675 done
676 echo ""
677 # Keep the 20 last removed packages list.
678 cat $DB_DIR/removed | tail -n 20 > /tmp/removed.tail
679 mv -f /tmp/removed.tail $DB_DIR/removed
680 # Clean packages stuff/ directory
681 echo -e "\nCleaning the build wok stuff/ directories...\n"
682 for pkg in `ls $BUILD_WOK`
683 do
684 if [ -d "$BUILD_WOK/$pkg/stuff" ]; then
685 cd $BUILD_WOK/$pkg
686 for file in `find stuff -type f`
687 do
688 if [ ! -f "$HG_WOK/$pkg/$file" ]; then
689 echo "Removing: $pkg/$file"
690 rm $file
691 fi
692 done
693 fi
694 done
695 }
697 blocked_urls()
698 {
699 rm -f $DB_DIR/blocked.urls
700 for pkg in `cat $DB_DIR/blocked`
701 do
702 if [ -f $LOG_DIR/$pkg.log ]; then
703 echo "<a href=\"log.php?package=$(escape $pkg)\">$pkg</a>" >> \
704 $DB_DIR/blocked.urls
705 else
706 echo "$pkg" >> $DB_DIR/blocked.urls
707 fi
708 done
709 }
711 # 4k, not a meta or a get-* package and no files = buggy package
712 test_packages()
713 {
714 echo -e "\nTesting all packages in: $PACKAGES_REPOSITORY"
715 echo "================================================================================"
716 echo "(testing packages)" > $DB_DIR/running
717 rm -f $DB_DIR/corrupted && touch $DB_DIR/corrupted
718 for pkg in $PACKAGES_REPOSITORY/*.tazpkg
719 do
720 tmp=/tmp/bb-test.$$
721 CATEGORY=""
722 if du $pkg | grep -qw '^4' && ! echo `basename $pkg` | grep -q '^get-'; then
723 mkdir -p $tmp && cd $tmp
724 cpio -i receipt >/dev/null 2>&1 < $pkg
725 . ./receipt
726 if [ "$CATEGORY" != "meta" ]; then
727 [ "$2" = "--verbose" ] && echo "Testing: $PACKAGE"
728 cpio -i fs.cpio.gz fs.cpio.lzma >/dev/null 2>&1 < $pkg
729 if [ ! -f fs.cpio.gz -a ! -f fs.cpio.lzma ]; then
730 echo "Missing filesystem `basename $pkg`"
731 if [ -f $LOG_DIR/$PACKAGE.log ];then
732 echo "Missing filesystem `basename $pkg` <a href=\"log.php?package=$(escape $PACKAGE)\">Log</a>" \
733 >> $DB_DIR/corrupted
734 else
735 echo "Missing filesystem `basename $pkg`" \
736 >> $DB_DIR/corrupted
737 fi
738 else
739 ( zcat fs.cpio.gz 2> /dev/null || \
740 unlzma -c fs.cpio.lzma ) | \
741 cpio -id >/dev/null 2>&1
742 files=`find fs -type f -o -type l`
743 if [ -z "$files" ]; then
744 echo "Empty filesystem `basename $pkg`"
745 if [ -f $LOG_DIR/$PACKAGE.log ]; then
746 echo "Empty filesystem `basename $pkg` <a href=\"log.php?package=$(escape $PACKAGE)\">Log</a>" \
747 >> $DB_DIR/corrupted
748 else
749 echo "Empty filesystem `basename $pkg`" \
750 >> $DB_DIR/corrupted
751 fi
752 fi
753 fi
754 fi
755 cd .. && rm -rf $tmp
756 fi
757 done
758 packages_summary_update
759 echo ""
760 }
762 # Generate flavor list
763 gen_flavor_list()
764 {
765 cd $PACKAGES_REPOSITORY
766 noheader=""
767 for i in *.flavor; do
768 tazlito show-flavor $i --brief $noheader
769 noheader="--noheader"
770 done > flavors.list
771 cd - > /dev/null
772 }
774 case "$1" in
775 list-pkgs)
776 # List last cooked packages.
777 list_packages ;;
778 report)
779 # Run in report mode. If an update is done we must cook-all to
780 # rebuild all updated packages.
781 [ "$2" == "--update" ] && update_wok $@ || echo ""
782 check_wok $@
783 check_flavors $@
784 test_packages $@
785 show_report ;;
786 cook)
787 # Cook, install and log a single package build.
788 if [ -z $2 ]; then
789 echo "Please specify a package on the command line."
790 rm -f $LOCK_FILE && exit 0
791 fi
792 pkg=$2
793 echo "Starting to cook and install: $pkg"
794 if ! cook_package $pkg; then
795 echo "Unable to install: $pkg"
796 fi ;;
797 cook-all)
798 # Update wok, gen report (with cooklist), cook all packages, test,
799 # clean, gen new report and lists.
800 update_wok $@
801 check_wok $@
802 cook_install
803 test_packages $@
804 check_flavors $@
805 pack_flavors
806 clean_up $@
807 check_wok $@
808 echo "(generating lists)" > $DB_DIR/running
809 tazwok gen-list --text
810 check_flavors $@
811 gen_flavor_list
812 echo "" ;;
813 cook-commit)
814 # Cook all packages affected by the last commits in the wok.
815 # Clean up is done only by cook-all to avoid rebuild of corrupted
816 # packages on each commit.
817 update_wok $@
818 check_commit
819 cook_install
820 test_packages $@
821 check_flavors $@
822 pack_flavors
823 check_wok $@
824 check_flavors $@
825 echo "(generating lists)" > $DB_DIR/running
826 tazwok gen-list --text
827 gen_flavor_list
828 echo "" ;;
829 block)
830 # Add a pkg name to the list of blocked packages.
831 echo ""
832 if grep -qs "^$2$" $DB_DIR/blocked; then
833 echo -e "$2 is already in the blocked packages list."
834 else
835 echo -n "Adding $2 to : $DB_DIR/blocked... "
836 echo "$2" >> $DB_DIR/blocked && echo "Done"
837 if grep -q "^$2$" $DB_DIR/cooklist; then
838 echo -n "Removing $2 from : $DB_DIR/cooklist... "
839 sed -i /"^$2$"/d $DB_DIR/cooklist && echo "Done"
840 packages_summary_update
841 fi
842 fi
843 blocked_urls
844 echo "" ;;
845 unblock)
846 # Remove a pkg name from the list of blocked packages.
847 echo ""
848 if grep -qs "^$2$" $DB_DIR/blocked; then
849 echo -n "Removing $2 from : $DB_DIR/blocked... "
850 sed -i /"^$2$"/d $DB_DIR/blocked
851 sed -i '/^$/d' $DB_DIR/blocked && echo "Done"
852 echo -n "Adding $2 to : $DB_DIR/cooklist... "
853 echo "$2" >> $DB_DIR/cooklist && echo "Done"
854 packages_summary_update
855 else
856 echo -e "$2 is not in the blocked packages list."
857 fi
858 blocked_urls
859 echo "" ;;
860 test-pkgs)
861 # Start a test suite on all builded packages.
862 test_packages $@ ;;
863 test-suite)
864 # Start a test suite on all builded package and the wok using
865 # the great 'tazwok check'.
866 #
867 # test_packages > $LOG_DIR/test-suite.log
868 # tazwok check >> $LOG_DIR/test-suite.log
869 #
870 test_packages $@
871 script -c "tazwok check" $LOG_DIR/test-suite.log ;;
872 mail)
873 # Tazbbmail Pythom script wrapper.
874 PACKAGE=$2
875 tazbbmail $PACKAGE ;;
876 clean-up)
877 # Remove old packages and generate new packages lists.
878 update_wok $@
879 clean_up $@
880 packages_summary_update
881 [ "$2" != "--dry-run" ] && tazwok gen-list --text ;;
882 clean-log)
883 logs=`ls $LOG_DIR | wc -l`
884 echo -n "Cleaning: $LOG_DIR... "
885 rm -rf $LOG_DIR/*
886 echo "$logs log removed" ;;
887 check-depends)
888 case "$2" in
889 wok)
890 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
891 missing_depends="$(check_depends_pkg $pkg)"
892 [ -n "$missing_depends" ] &&
893 echo "The package $pkg depends on $missing_depends."
894 done ;;
895 package)
896 pkg=$3
897 VERBOSE=$4
898 missing_depends="$(check_depends_pkg $pkg)"
899 [ -n "$missing_depends" ] &&
900 echo "The package $pkg depends on $missing_depends."
901 ;;
902 file)
903 file=3
904 VERBOSE=$4
905 missing_depends="$(check_depends_this_file $file)"
906 [ -n "$missing_depends" ] &&
907 echo "The file $file depends on $missing_depends."
908 ;;
909 *) cat <<EOT
910 check-depends wok check every package in wok.
911 check-depends package <pkg> check one package.
912 check-depends file <filename> check one file only.
913 EOT
914 ;;
915 esac ;;
916 *)
917 usage ;;
918 esac
920 echo "" > $DB_DIR/running
921 rm -f $LOCK_FILE /tmp/files.list.tazbb$$
923 exit 0