wok view tazbb/stuff/tazbb @ rev 5187

syslinux: msg for 3.0 and up splash image
author Christophe Lincoln <pankso@slitaz.org>
date Sun Mar 28 00:46:39 2010 +0100 (2010-03-28)
parents 7dc01a8df1df
children 65fc029b99f2
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 # Clean packages stuff/ directory
680 echo -e "\nCleaning the build wok stuff/ directories...\n"
681 for pkg in `ls $BUILD_WOK`
682 do
683 if [ -d "$BUILD_WOK/$pkg/stuff" ]; then
684 cd $BUILD_WOK/$pkg
685 for file in `find stuff -type f`
686 do
687 if [ ! -f "$HG_WOK/$pkg/$file" ]; then
688 echo "Removing: $pkg/$file"
689 rm $file
690 fi
691 done
692 fi
693 done
694 }
696 blocked_urls()
697 {
698 rm -f $DB_DIR/blocked.urls
699 for pkg in `cat $DB_DIR/blocked`
700 do
701 if [ -f $LOG_DIR/$pkg.log ]; then
702 echo "<a href=\"log.php?package=$(escape $pkg)\">$pkg</a>" >> \
703 $DB_DIR/blocked.urls
704 else
705 echo "$pkg" >> $DB_DIR/blocked.urls
706 fi
707 done
708 }
710 # 4k, not a meta or a get-* package and no files = buggy package
711 test_packages()
712 {
713 echo -e "\nTesting all packages in: $PACKAGES_REPOSITORY"
714 echo "================================================================================"
715 echo "(testing packages)" > $DB_DIR/running
716 rm -f $DB_DIR/corrupted && touch $DB_DIR/corrupted
717 for pkg in $PACKAGES_REPOSITORY/*.tazpkg
718 do
719 tmp=/tmp/bb-test.$$
720 CATEGORY=""
721 if du $pkg | grep -qw '^4' && ! echo `basename $pkg` | grep -q '^get-'; then
722 mkdir -p $tmp && cd $tmp
723 cpio -i receipt >/dev/null 2>&1 < $pkg
724 . ./receipt
725 if [ "$CATEGORY" != "meta" ]; then
726 [ "$2" = "--verbose" ] && echo "Testing: $PACKAGE"
727 cpio -i fs.cpio.gz fs.cpio.lzma >/dev/null 2>&1 < $pkg
728 if [ ! -f fs.cpio.gz -a ! -f fs.cpio.lzma ]; then
729 echo "Missing filesystem `basename $pkg`"
730 if [ -f $LOG_DIR/$PACKAGE.log ];then
731 echo "Missing filesystem `basename $pkg` <a href=\"log.php?package=$(escape $PACKAGE)\">Log</a>" \
732 >> $DB_DIR/corrupted
733 else
734 echo "Missing filesystem `basename $pkg`" \
735 >> $DB_DIR/corrupted
736 fi
737 else
738 ( zcat fs.cpio.gz 2> /dev/null || \
739 unlzma -c fs.cpio.lzma ) | \
740 cpio -id >/dev/null 2>&1
741 files=`find fs -type f -o -type l`
742 if [ -z "$files" ]; then
743 echo "Empty filesystem `basename $pkg`"
744 if [ -f $LOG_DIR/$PACKAGE.log ]; then
745 echo "Empty filesystem `basename $pkg` <a href=\"log.php?package=$(escape $PACKAGE)\">Log</a>" \
746 >> $DB_DIR/corrupted
747 else
748 echo "Empty filesystem `basename $pkg`" \
749 >> $DB_DIR/corrupted
750 fi
751 fi
752 fi
753 fi
754 cd .. && rm -rf $tmp
755 fi
756 done
757 packages_summary_update
758 echo ""
759 }
761 # Generate flavor list
762 gen_flavor_list()
763 {
764 cd $PACKAGES_REPOSITORY
765 noheader=""
766 for i in *.flavor; do
767 tazlito show-flavor $i --brief $noheader
768 noheader="--noheader"
769 done > flavors.list
770 cd - > /dev/null
771 }
773 case "$1" in
774 list-pkgs)
775 # List last cooked packages.
776 list_packages ;;
777 report)
778 # Run in report mode. If an update is done we must cook-all to
779 # rebuild all updated packages.
780 [ "$2" == "--update" ] && update_wok $@ || echo ""
781 check_wok $@
782 check_flavors $@
783 test_packages $@
784 show_report ;;
785 cook)
786 # Cook, install and log a single package build.
787 if [ -z $2 ]; then
788 echo "Please specify a package on the command line."
789 rm -f $LOCK_FILE && exit 0
790 fi
791 pkg=$2
792 echo "Starting to cook and install: $pkg"
793 if ! cook_package $pkg; then
794 echo "Unable to install: $pkg"
795 fi ;;
796 cook-all)
797 # Update wok, gen report (with cooklist), cook all packages, test,
798 # clean, gen new report and lists.
799 update_wok $@
800 check_wok $@
801 cook_install
802 test_packages $@
803 check_flavors $@
804 pack_flavors
805 clean_up $@
806 check_wok $@
807 echo "(generating lists)" > $DB_DIR/running
808 tazwok gen-list --text
809 check_flavors $@
810 gen_flavor_list
811 echo "" ;;
812 cook-commit)
813 # Cook all packages affected by the last commits in the wok.
814 # Clean up is done only by cook-all to avoid rebuild of corrupted
815 # packages on each commit.
816 update_wok $@
817 check_commit
818 cook_install
819 test_packages $@
820 check_flavors $@
821 pack_flavors
822 check_wok $@
823 check_flavors $@
824 echo "(generating lists)" > $DB_DIR/running
825 tazwok gen-list --text
826 gen_flavor_list
827 echo "" ;;
828 block)
829 # Add a pkg name to the list of blocked packages.
830 echo ""
831 if grep -qs "^$2$" $DB_DIR/blocked; then
832 echo -e "$2 is already in the blocked packages list."
833 else
834 echo -n "Adding $2 to : $DB_DIR/blocked... "
835 echo "$2" >> $DB_DIR/blocked && echo "Done"
836 if grep -q "^$2$" $DB_DIR/cooklist; then
837 echo -n "Removing $2 from : $DB_DIR/cooklist... "
838 sed -i /"^$2$"/d $DB_DIR/cooklist && echo "Done"
839 packages_summary_update
840 fi
841 fi
842 blocked_urls
843 echo "" ;;
844 unblock)
845 # Remove a pkg name from the list of blocked packages.
846 echo ""
847 if grep -qs "^$2$" $DB_DIR/blocked; then
848 echo -n "Removing $2 from : $DB_DIR/blocked... "
849 sed -i /"^$2$"/d $DB_DIR/blocked
850 sed -i '/^$/d' $DB_DIR/blocked && echo "Done"
851 echo -n "Adding $2 to : $DB_DIR/cooklist... "
852 echo "$2" >> $DB_DIR/cooklist && echo "Done"
853 packages_summary_update
854 else
855 echo -e "$2 is not in the blocked packages list."
856 fi
857 blocked_urls
858 echo "" ;;
859 test-pkgs)
860 # Start a test suite on all builded packages.
861 test_packages $@ ;;
862 test-suite)
863 # Start a test suite on all builded package and the wok using
864 # the great 'tazwok check'.
865 #
866 # test_packages > $LOG_DIR/test-suite.log
867 # tazwok check >> $LOG_DIR/test-suite.log
868 #
869 test_packages $@
870 script -c "tazwok check" $LOG_DIR/test-suite.log ;;
871 mail)
872 # Tazbbmail Pythom script wrapper.
873 PACKAGE=$2
874 tazbbmail $PACKAGE ;;
875 clean-up)
876 # Remove old packages and generate new packages lists.
877 update_wok $@
878 clean_up $@
879 packages_summary_update
880 [ "$2" != "--dry-run" ] && tazwok gen-list --text ;;
881 clean-log)
882 logs=`ls $LOG_DIR | wc -l`
883 echo -n "Cleaning: $LOG_DIR... "
884 rm -rf $LOG_DIR/*
885 echo "$logs log removed" ;;
886 check-depends)
887 case "$2" in
888 wok)
889 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
890 missing_depends="$(check_depends_pkg $pkg)"
891 [ -n "$missing_depends" ] &&
892 echo "The package $pkg depends on $missing_depends."
893 done ;;
894 package)
895 pkg=$3
896 VERBOSE=$4
897 missing_depends="$(check_depends_pkg $pkg)"
898 [ -n "$missing_depends" ] &&
899 echo "The package $pkg depends on $missing_depends."
900 ;;
901 file)
902 file=3
903 VERBOSE=$4
904 missing_depends="$(check_depends_this_file $file)"
905 [ -n "$missing_depends" ] &&
906 echo "The file $file depends on $missing_depends."
907 ;;
908 *) cat <<EOT
909 check-depends wok check every package in wok.
910 check-depends package <pkg> check one package.
911 check-depends file <filename> check one file only.
912 EOT
913 ;;
914 esac ;;
915 *)
916 usage ;;
917 esac
919 echo "" > $DB_DIR/running
920 rm -f $LOCK_FILE /tmp/files.list.tazbb$$
922 exit 0