wok view tazbb/stuff/tazbb @ rev 5881

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