wok view tazbb/stuff/tazbb @ rev 5987

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