wok view tazbb/stuff/tazbb @ rev 6257

Add rpcbind
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Sep 14 12:55:26 2010 +0200 (2010-09-14)
parents 39ab2eee876a
children 5f04c6d8da47
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|check-receipt)
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 TOOLCHAIN="$(. $HG_WOK/slitaz-toolchain/receipt ; echo $DEPENDS)"
290 TOOLCHAIN="$TOOLCHAIN glibc linux" # break cook loop
291 for pkg in $HG_WOK/*
292 do
293 EXTRAVERSION=""
294 WANTED=""
295 BUILD_DEPENDS=""
296 [ -s $pkg/receipt ] || continue
297 . $pkg/receipt
298 [ "$2" = "--verbose" ] && echo "Package : $PACKAGE"
299 # Skip blocked packages.
300 if grep -qs "^$PACKAGE$" $DB_DIR/blocked; then
301 echo "Blocked : $PACKAGE ($VERSION)" && continue
302 fi
304 # Some packages may compute VERSION at cook time (bristuff)
305 if grep -q ^get_version $pkg/receipt; then
306 . $BUILD_WOK/$PACKAGE/taz/*/receipt
307 fi
309 # First check if package exit. Package naming _must_ be in the form of:
310 # $PACKAGE-$VERSION or $PACKAGE-${VERSION}$EXTRAVERSION (Kernel string).
311 if [ ! -f $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg ]; then
312 [ -z "$EXTRAVERSION" ] && EXTRAVERSION="_$KERNEL"
313 if [ ! -f $PACKAGES_REPOSITORY/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg ]; then
314 [ "$1" = "report" ] && echo "Missing : $PACKAGE ($VERSION)"
315 echo "Missing : $PACKAGE ($VERSION)" >> $DB_DIR/report
316 echo "$PACKAGE" >> $DB_DIR/cooklist
317 fi
318 else
319 # Check if package is up-to-date.
320 PKG_YEAR=`date -u -r $PACKAGES_REPOSITORY/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg '+%Y'`
321 PKG_DATE=`date -u -r $PACKAGES_REPOSITORY/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg '+%m%d%H%M'`
322 for file in `find $pkg -type f`
323 do
324 FILE_YEAR=`date -u -r $file '+%Y'`
325 FILE_DATE=`date -u -r $file '+%m%d%H%M'`
326 [ "$2" = "--verbose" ] && echo " -> Checking: $file"
327 if [ "$FILE_YEAR" -ge "$PKG_YEAR" -a "$FILE_DATE" -gt "$PKG_DATE" ] && ! grep -q $PACKAGE $DB_DIR/cooklist; then
328 [ "$1" = "report" ] && echo "Refresh : $PACKAGE ($VERSION)"
329 echo "Refresh : $PACKAGE ($VERSION)" >> $DB_DIR/report
330 echo "$PACKAGE" >> $DB_DIR/cooklist
331 fi
332 done
333 fi
334 # Now check if package is built and not already in the list.
335 if [ ! -d $BUILD_WOK/$PACKAGE/taz ] && ! grep -q $PACKAGE $DB_DIR/cooklist; then
336 [ "$1" = "report" ] && echo "Unbuilt : $PACKAGE ($VERSION)"
337 echo "Unbuilt : $PACKAGE ($VERSION)" >> $DB_DIR/report
338 echo "$PACKAGE" >> $DB_DIR/cooklist
339 fi
340 if ! grep -q $PACKAGE $DB_DIR/cooklist; then
341 case " $TOOLCHAIN " in
342 *\ $PACKAGE\ *) continue;;
343 esac
344 case "$PACKAGE" in
345 tazbb|tazwok|tazpkg) continue;;
346 esac
347 for dep in $BUILD_DEPENDS $TOOLCHAIN ; do
348 [ $BUILD_WOK/$PACKAGE/taz -nt $BUILD_WOK/$dep/taz ] && continue
349 [ "$1" = "report" ] && echo "Refresh : $PACKAGE (older than $dep)"
350 echo "Refresh : $PACKAGE (older than $dep)" >> $DB_DIR/report
351 echo "$PACKAGE" >> $DB_DIR/cooklist
352 break
353 done
354 fi
355 # Rebuild unbuilt packages list with link to log file. This list
356 # is also generated by cook_inslall to have real time stats.
357 if [ ! -d $BUILD_WOK/$PACKAGE/taz ]; then
358 echo "<a href=\"log.php?package=$(escape $PACKAGE)$LOG_SUFFIX\">$PACKAGE</a>" \
359 >> $DB_DIR/unbuilt
360 fi
361 done
362 packages_summary
363 }
365 # Create a new cooklist and summary (dont modify report) so 'tazbb cook-commit'
366 # can cook last changes.
367 check_commit()
368 {
369 echo "(checking commit)" > $DB_DIR/running
370 cd $HG_WOK
371 # Clean up last results.
372 rm -f $DB_DIR/cooklist && touch $DB_DIR/cooklist
373 # Get the name of modified packages by the revision range. +1 last
374 # commit was build by the previous build.
375 LAST_REV=$(($LAST_REV+1))
376 echo -e "Will cook from revision $LAST_REV to $NEW_REV\n"
377 for file in `hg log --rev=$LAST_REV:$NEW_REV --template '{files}\n'`
378 do
379 pkg=`echo $file | cut -d "/" -f 1`
380 if ! grep -q ^$pkg$ $DB_DIR/cooklist; then
381 . $pkg/receipt
382 echo "Commit : $PACKAGE ($VERSION)" >> $DB_DIR/report
383 echo "$PACKAGE" >> $DB_DIR/cooklist
384 fi
385 done
386 packages_summary
387 }
389 # Cook one package
390 cook_package()
391 {
392 EXTRAVERSION=""
393 DEPENDS=""
394 BUILD_DEPENDS=""
395 SOURCE=""
396 WANTED=""
397 echo "(cooking <a href=\"log.php?package=$(escape $pkg)$LOG_SUFFIX\">$pkg</a>)" > $DB_DIR/running
398 tazwok clean $pkg
399 script -c "tazbb check-receipt $pkg && echo 'install' | tazwok cook $pkg" $LOG_DIR/$pkg.log
400 # Install new package (important for new shared libs). Note
401 # that tests are done separatly with 'test_packages' and should
402 # be done by tazwok.
403 if [ -f $BUILD_WOK/$pkg/taz/*/receipt ]; then
404 TAZBB_NO_INSTALL=""
405 . $BUILD_WOK/$pkg/taz/*/receipt
406 [ -n "$TAZBB_NO_INSTALL" ] && return 0
407 echo "(installing $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg)" \
408 > $DB_DIR/running
409 script -ac "yes | tazpkg install \
410 $PACKAGES_REPOSITORY/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg --forced" \
411 $LOG_DIR/$pkg.log
412 return 0
413 fi
414 return 1
415 }
417 # Sort list according WANTED and BUILD_DEPENDS
418 sort_cook_list()
419 {
420 sort | while read pkg; do
421 echo -n "$pkg"
422 WANTED=""
423 BUILD_DEPENDS=""
424 . $BUILD_WOK/$pkg/receipt
425 MISSING=""
426 for i in $WANTED $BUILD_DEPENDS ; do
427 # Verify that the dependancy exists and is older
428 [ -f $BUILD_WOK/$i/taz/*/receipt ] &&
429 [ $BUILD_WOK/$pkg/taz/*/receipt \
430 -nt $BUILD_WOK/$i/taz/*/receipt ] && continue
431 WANTED=""
432 [ -f $BUILD_WOK/$i/receipt ] &&
433 . $BUILD_WOK/$i/receipt
434 # This dependancy may be cooked
435 # by another package
436 [ -n "$WANTED" ] && i=$WANTED
437 case " $MISSING " in
438 *\ $i\ *);;
439 *) echo -n " $i";;
440 esac
441 MISSING="$MISSING $i"
442 done
443 echo ""
444 done | awk '{ deps[$1] = $0; }
445 END {
446 k=0;
447 while (1) {
448 skipped = 0;
449 done = 0;
450 for (entry in deps) {
451 for (i = split(deps[entry], pkg, " "); i > 1; i--)
452 if (deps[pkg[i]] != "") break;
453 if (i == 1) {
454 cook[k++] = pkg[1];
455 deps[pkg[1]] = "";
456 done++;
457 }
458 else if (i > 1) skipped++;
459 }
460 if (skipped == 0) break;
461 if (done == 0) { # cross deps !!
462 for (entry in deps) {
463 if (split(deps[entry], pkg, " ") > 1)
464 print pkg[1];
465 }
466 break;
467 }
468 }
469 while (k > 0) print cook[--k];
470 }
471 '
472 }
474 # Here we cook all packages found in the cooklist.
475 cook_install()
476 {
477 echo "" > $DB_DIR/unbuilt
478 for pkg in `cat $DB_DIR/cooklist | sort_cook_list`
479 do
480 if ! cook_package $pkg; then
481 # Link to build log.
482 echo "<a href=\"log.php?package=$(escape $pkg)$LOG_SUFFIX\">$pkg</a>" >> \
483 $DB_DIR/unbuilt
484 fi
485 missing_depends="$(check_depends_pkg $pkg)"
486 if [ -n "$missing_depends" ]; then
487 cat >> $LOG_DIR/$pkg.log <<EOT
489 Update $pkg receipt for DEPENDS :
490 The package $pkg depends on packages $missing_depends
492 EOT
493 # Unbuild package
494 rm -rf $BUILD_WOK/$pkg/taz
495 # Link to build log.
496 echo "<a href=\"log.php?package=$(escape $pkg)$LOG_SUFFIX\">$pkg</a>" >> \
497 $DB_DIR/unbuilt
498 fi
499 # Remove package from the cooklist and empty lines for HTML <pre>.
500 sed -i /"^$pkg$"/d $DB_DIR/cooklist
501 sed -i '/^$/d' $DB_DIR/cooklist
502 packages_summary_update
503 done
504 }
506 # Check for misc variables
507 check_variables()
508 {
509 PACKAGE=""
510 VERSION=""
511 EXTRAVERSION=""
512 CATEGORY=""
513 SHORT_DESC=""
514 MAINTAINER=""
515 WEB_SITE=""
516 PACKED_SIZE=""
517 UNPACKED_SIZE=""
518 . $BUILD_WOK/$1/receipt
519 if [ "$PACKAGE" != "$1" ]; then
520 echo "The PACKAGE variable should be $1"
521 return 1
522 fi
523 if [ -z "$VERSION" ]; then
524 echo "No VERSION in $1"
525 return 1
526 fi
527 if [ -z "$SHORT_DESC" ]; then
528 echo "No SHORT_DESC in $1"
529 return 1
530 fi
531 case "$MAINTAINER" in
532 '') echo "No MAINTAINER in $1"
533 return 1 ;;
534 *\<*|*\>*)
535 echo "Invalid MAINTAINER in $1"
536 return 1 ;;
537 *@*) ;;
538 *) echo "No email address for MAINTAINER in $1"
539 return 1 ;;
540 esac
541 if [ -z "$WEB_SITE" ]; then
542 echo "No WEB_SITE in $1"
543 return 1
544 fi
545 if [ -n "$EXTRAVERSION" ]; then
546 echo "Hardcoded EXTRAVERSION in $1"
547 return 1
548 fi
549 if [ -n "$PACKED_SIZE" ]; then
550 echo "Hardcoded PACKED_SIZE in $1"
551 return 1
552 fi
553 if [ -n "$UNPACKED_SIZE" ]; then
554 echo "Hardcoded UNPACKED_SIZE in $1"
555 return 1
556 fi
557 case " base-system x-window utilities network graphics multimedia \
558 office development system-tools security games misc meta \
559 non-free " in
560 *\ $CATEGORY\ *);;
561 *) echo "Invalid CATEGORY in $1 : $CATEGORY"
562 return 1;
563 esac
564 return 0
565 }
567 # Check for WANTED version
568 check_wanted_version()
569 {
570 WANTED=""
571 . $BUILD_WOK/$1/receipt
572 if [ -n "$WANTED" ]; then
573 expected=$VERSION
574 VERSION=
575 . $BUILD_WOK/$WANTED/receipt
576 if [ "$VERSION" != "$expected" ]; then
577 echo "$1: expected wanted version $expected, found $VERSION"
578 return 1
579 fi
580 fi
581 return 0
582 }
584 # Check for loop in BUILD_DEPENDS/WANTED
585 check_build_depends()
586 {
587 local i
588 BUILD_DEPENDS=""
589 WANTED=""
590 . $BUILD_WOK/$1/receipt
591 for i in $BUILD_DEPENDS $WANTED ; do
592 case " $2 " in
593 *\ $i\ *) echo "Loop in BUILD_DEPENDS/WANTED chain $2 $i"
594 return 1 ;;
595 *) check_build_depends $i "$2 $1" || return 1 ;;
596 esac
597 done
598 return 0
599 }
601 # Build depends_to_skip list with packages to remove from depends_to_add list
602 # These packages are already present in depends_to_add trees
603 scan_depends_to_skip()
604 {
605 local i
606 case " $depends_to_skip " in
607 *\ $1\ *) return;;
608 esac
609 [ -d $BUILD_WOK/$1 ] || return
610 DEPENDS=""
611 . $BUILD_WOK/$1/receipt
612 for i in $DEPENDS ; do
613 case " $depends_to_add " in
614 *\ $i\ *) depends_to_skip="$depends_to_skip $i";;
615 esac
616 done
617 for i in $DEPENDS ; do
618 scan_depends_to_skip $i
619 done
620 }
622 # Reduce depends list by scanning nested depends
623 show_missing_depends()
624 {
625 local i
626 depends_to_add=""
627 depends_to_skip="$2"
628 for i in $1 ; do
629 case " $depends_to_add " in
630 *\ $i\ *) continue;;
631 esac
632 depends_to_add="$depends_to_add$i "
633 done
634 for i in $depends_to_add ; do
635 scan_depends_to_skip $i
636 done
637 for i in $depends_to_add ; do
638 case " $depends_to_skip " in
639 *\ $i\ *) continue;;
640 esac
641 echo -n "$i "
642 done
643 }
645 # Build all_depends variable
646 scan_dep()
647 {
648 local i
649 all_depends="$all_depends$PACKAGE "
650 for i in $DEPENDS $SUGGESTED ; do
651 case " $all_depends " in
652 *\ $i\ *) continue;;
653 esac
654 [ -d $BUILD_WOK/$i ] || {
655 all_depends="$all_depends$i "
656 continue
657 }
658 DEPENDS=""
659 SUGGESTED=""
660 . $BUILD_WOK/$i/receipt
661 scan_dep
662 done
663 }
665 # Check for ELF file
666 is_elf()
667 {
668 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
669 }
671 # Print shared library dependencies
672 ldd()
673 {
674 LD_PRELOAD="" LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
675 }
677 # scan a file for shared libraries and display according package names
678 check_depends_file()
679 {
680 file=$1
681 is_elf $file || continue
682 case "$file" in
683 *.o|*.ko|*.ko.gz) continue;;
684 esac
685 [ -s /tmp/files.list.tazbb$$ ] ||
686 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma >/tmp/files.list.tazbb$$
687 ldd $file | while read lib rem; do
688 case "$lib" in
689 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
690 continue;;
691 esac
692 for dep in $(grep $lib /tmp/files.list.tazbb$$ | cut -d: -f1); do
693 case " $all_depends " in
694 *\ $dep\ *) continue 2;;
695 esac
696 for vdep in $(grep $dep $PACKAGES_REPOSITORY/packages.equiv | cut -d= -f1); do
697 case " $all_depends " in
698 *\ $vdep\ *) continue 3;;
699 esac
700 done
701 done
702 [ -n "$dep" ] || dep="UNKNOWN"
703 all_depends="$all_depends $dep"
704 if [ -n "$VERBOSE" ]; then
705 echo "${file#*fs} depends on package $dep for the shared library $lib" 1>&2
706 fi
707 echo -n "$dep "
708 done
709 }
711 DEFAULT_DEPENDS="glibc-base"
713 # scan a package for shared libraries and display missing package in DEPENDS
714 check_depends_pkg()
715 {
716 pkg=$1
717 echo "(checking depends for $pkg)" > $DB_DIR/running
718 tmp=/tmp/tazbb$$
719 mkdir $tmp
720 package=$(basename $pkg)
721 if ! cd ${package%%-*}*/taz/${package%.tazpkg}/.. 2> /dev/null; then
722 cd $tmp
723 tazpkg extract $pkg > /dev/null 2>&1
724 fi
725 . */receipt
726 all_depends="$DEFAULT_DEPENDS "
727 scan_dep
728 toadd=$(find */fs -type f | while read file ; do
729 check_depends_file $file
730 done)
731 . */receipt
732 rm -rf */
733 cd - > /dev/null
734 rm -rf $tmp
735 show_missing_depends "$toadd" "$DEPENDS $SUGGESTED"
736 }
738 check_depends_this_file()
739 {
740 file=$1
741 all_depends="$DEFAULT_DEPENDS "
742 scan_dep
743 check_depends_file $file
744 }
746 # Remove old packages in the build wok and clean pkgs repository. The
747 # Hg wok is copied into the build wok so packages removed by hg must be
748 # removed. To remove old packages in the repository we look into the
749 # build wok and dont remove unbuilt packages. Clean-up will also remove
750 # all corrupted packages.
751 clean_up()
752 {
753 touch $DB_DIR/removed
754 echo -e "\nCleaning the build wok, old and corrupted packages...\n"
755 echo "(cleaning)" > $DB_DIR/running
756 for pkg in `ls $BUILD_WOK`
757 do
758 if [ ! -d $HG_WOK/$pkg ]; then
759 case $2 in
760 --dry-run)
761 echo "Removing directory : $pkg" ;;
762 --verbose)
763 echo "Removing directory : $pkg"
764 rm -rf $BUILD_WOK/$pkg ;;
765 *)
766 rm -rf $BUILD_WOK/$pkg ;;
767 esac
768 fi
769 done
770 # Build a packages list with EXTRAVERSION so we can grep into it.
771 rm -f $DB_DIR/packaged && touch $DB_DIR/packaged
772 for receipt in $BUILD_WOK/*/taz/*/receipt
773 do
774 EXTRAVERSION=""
775 . $receipt
776 echo "$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" >> $DB_DIR/packaged
777 done
778 for pkg in `cd $PACKAGES_REPOSITORY && ls *.tazpkg`
779 do
780 if ! grep -q "^$pkg$" $DB_DIR/packaged; then
781 case $2 in
782 --dry-run)
783 echo "Removing package : $pkg" ;;
784 --verbose)
785 echo "Removing package : $pkg"
786 echo "$pkg" >> $DB_DIR/removed
787 rm -f $PACKAGES_REPOSITORY/$pkg ;;
788 *)
789 echo "$pkg" >> $DB_DIR/removed
790 rm -f $PACKAGES_REPOSITORY/$pkg ;;
791 esac
792 fi
793 done
794 # Remove all corrupted packages
795 for pkg in `cat $DB_DIR/corrupted | awk '{ print $3 }'`
796 do
797 case $2 in
798 --dry-run)
799 echo "Removing corrupted: $pkg" ;;
800 --verbose)
801 echo "Removing corrupted: $pkg"
802 echo "$pkg" >> $DB_DIR/removed
803 rm -rf $PACKAGES_REPOSITORY/$pkg ;;
804 *)
805 echo "$pkg" >> $DB_DIR/removed
806 rm -rf $PACKAGES_REPOSITORY/$pkg ;;
807 esac
808 done
809 echo ""
810 # Keep the 20 last removed packages list.
811 cat $DB_DIR/removed | tail -n 20 > /tmp/removed.tail
812 mv -f /tmp/removed.tail $DB_DIR/removed
813 # Clean packages stuff/ directory
814 echo -e "\nCleaning the build wok stuff/ directories...\n"
815 for pkg in `ls $BUILD_WOK`
816 do
817 if [ -d "$BUILD_WOK/$pkg/stuff" ]; then
818 cd $BUILD_WOK/$pkg
819 for file in `find stuff -type f`
820 do
821 if [ ! -f "$HG_WOK/$pkg/$file" ]; then
822 echo "Removing: $pkg/$file"
823 rm $file
824 fi
825 done
826 fi
827 done
828 }
830 blocked_urls()
831 {
832 rm -f $DB_DIR/blocked.urls
833 for pkg in `cat $DB_DIR/blocked`
834 do
835 if [ -f $LOG_DIR/$pkg.log ]; then
836 echo "<a href=\"log.php?package=$(escape $pkg)$LOG_SUFFIX\">$pkg</a>" >> \
837 $DB_DIR/blocked.urls
838 else
839 echo "$pkg" >> $DB_DIR/blocked.urls
840 fi
841 done
842 }
844 # 4k, not a meta or a get-* package and no files = buggy package
845 test_packages()
846 {
847 echo -e "\nTesting all packages in: $PACKAGES_REPOSITORY"
848 echo "================================================================================"
849 echo "(testing packages)" > $DB_DIR/running
850 rm -f $DB_DIR/corrupted && touch $DB_DIR/corrupted
851 for pkg in $PACKAGES_REPOSITORY/*.tazpkg
852 do
853 tmp=/tmp/bb-test.$$
854 CATEGORY=""
855 if du $pkg | grep -qw '^4' && ! echo `basename $pkg` | grep -q '^get-'; then
856 mkdir -p $tmp && cd $tmp
857 cpio -i receipt >/dev/null 2>&1 < $pkg
858 . ./receipt
859 if [ "$CATEGORY" != "meta" ]; then
860 [ "$2" = "--verbose" ] && echo "Testing: $PACKAGE"
861 cpio -i fs.cpio.gz >/dev/null 2>&1 < $pkg
862 cpio -i fs.cpio.lzma >/dev/null 2>&1 < $pkg
863 if [ ! -f fs.cpio.gz -a ! -f fs.cpio.lzma ]; then
864 echo "Missing filesystem `basename $pkg`"
865 if [ -f $LOG_DIR/$PACKAGE.log ];then
866 echo "Missing filesystem `basename $pkg` <a href=\"log.php?package=$(escape $PACKAGE)$LOG_SUFFIX\">Log</a>" \
867 >> $DB_DIR/corrupted
868 else
869 echo "Missing filesystem `basename $pkg`" \
870 >> $DB_DIR/corrupted
871 fi
872 else
873 ( zcat fs.cpio.gz 2> /dev/null || \
874 unlzma -c fs.cpio.lzma ) | \
875 cpio -id >/dev/null 2>&1
876 files=`find fs -type f -o -type l`
877 if [ -z "$files" ]; then
878 echo "Empty filesystem `basename $pkg`"
879 if [ -f $LOG_DIR/$PACKAGE.log ]; then
880 echo "Empty filesystem `basename $pkg` <a href=\"log.php?package=$(escape $PACKAGE)$LOG_SUFFIX\">Log</a>" \
881 >> $DB_DIR/corrupted
882 else
883 echo "Empty filesystem `basename $pkg`" \
884 >> $DB_DIR/corrupted
885 fi
886 fi
887 fi
888 fi
889 cd .. && rm -rf $tmp
890 fi
891 done
892 packages_summary_update
893 echo ""
894 }
896 # Generate flavor list
897 gen_flavor_list()
898 {
899 cd $PACKAGES_REPOSITORY
900 noheader=""
901 for i in *.flavor; do
902 tazlito show-flavor $i --brief $noheader
903 noheader="--noheader"
904 done > flavors.list
905 cd - > /dev/null
906 }
908 case "$1" in
909 list-pkgs)
910 # List last cooked packages.
911 list_packages ;;
912 report)
913 # Run in report mode. If an update is done we must cook-all to
914 # rebuild all updated packages.
915 [ "$2" == "--update" ] && update_wok $@ || echo ""
916 check_wok $@
917 check_flavors $@
918 test_packages $@
919 show_report ;;
920 cook)
921 # Cook, install and log a single package build.
922 if [ -z $2 ]; then
923 echo "Please specify a package on the command line."
924 rm -f $LOCK_FILE && exit 0
925 fi
926 pkg=$2
927 echo "Starting to cook and install: $pkg"
928 if ! cook_package $pkg; then
929 echo "Unable to install: $pkg"
930 fi ;;
931 cook-all)
932 # Update wok, gen report (with cooklist), cook all packages, test,
933 # clean, gen new report and lists.
934 update_wok $@
935 check_wok $@
936 cook_install
937 test_packages $@
938 check_flavors $@
939 pack_flavors
940 clean_up $@
941 check_wok $@
942 echo "(generating lists)" > $DB_DIR/running
943 tazwok gen-list --text
944 check_flavors $@
945 gen_flavor_list
946 echo "" ;;
947 cook-commit)
948 # Cook all packages affected by the last commits in the wok.
949 # Clean up is done only by cook-all to avoid rebuild of corrupted
950 # packages on each commit.
951 update_wok $@
952 check_commit
953 cook_install
954 test_packages $@
955 check_flavors $@
956 pack_flavors
957 check_wok $@
958 check_flavors $@
959 echo "(generating lists)" > $DB_DIR/running
960 tazwok gen-list --text
961 gen_flavor_list
962 echo "" ;;
963 block)
964 # Add a pkg name to the list of blocked packages.
965 echo ""
966 if grep -qs "^$2$" $DB_DIR/blocked; then
967 echo -e "$2 is already in the blocked packages list."
968 else
969 echo -n "Adding $2 to : $DB_DIR/blocked... "
970 echo "$2" >> $DB_DIR/blocked && echo "Done"
971 if grep -q "^$2$" $DB_DIR/cooklist; then
972 echo -n "Removing $2 from : $DB_DIR/cooklist... "
973 sed -i /"^$2$"/d $DB_DIR/cooklist && echo "Done"
974 packages_summary_update
975 fi
976 fi
977 blocked_urls
978 echo "" ;;
979 unblock)
980 # Remove a pkg name from the list of blocked packages.
981 echo ""
982 if grep -qs "^$2$" $DB_DIR/blocked; then
983 echo -n "Removing $2 from : $DB_DIR/blocked... "
984 sed -i /"^$2$"/d $DB_DIR/blocked
985 sed -i '/^$/d' $DB_DIR/blocked && echo "Done"
986 echo -n "Adding $2 to : $DB_DIR/cooklist... "
987 echo "$2" >> $DB_DIR/cooklist && echo "Done"
988 packages_summary_update
989 else
990 echo -e "$2 is not in the blocked packages list."
991 fi
992 blocked_urls
993 echo "" ;;
994 test-pkgs)
995 # Start a test suite on all builded packages.
996 test_packages $@ ;;
997 test-suite)
998 # Start a test suite on all builded package and the wok using
999 # the great 'tazwok check'.
1001 # test_packages > $LOG_DIR/test-suite.log
1002 # tazwok check >> $LOG_DIR/test-suite.log
1004 test_packages $@
1005 script -c "tazwok check" $LOG_DIR/test-suite.log ;;
1006 mail)
1007 # Tazbbmail Pythom script wrapper.
1008 PACKAGE=$2
1009 tazbbmail $PACKAGE ;;
1010 clean-up)
1011 # Remove old packages and generate new packages lists.
1012 update_wok $@
1013 clean_up $@
1014 packages_summary_update
1015 [ "$2" != "--dry-run" ] && tazwok gen-list --text ;;
1016 clean-log)
1017 logs=`ls $LOG_DIR | wc -l`
1018 echo -n "Cleaning: $LOG_DIR... "
1019 rm -rf $LOG_DIR/*
1020 echo "$logs log removed" ;;
1021 check-receipt)
1022 check_variables $2 &&
1023 check_wanted_version $2 &&
1024 check_build_depends $2 ""
1025 exit $? ;;
1026 check-depends)
1027 case "$2" in
1028 wok)
1029 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
1030 missing_depends="$(check_depends_pkg $pkg)"
1031 [ -n "$missing_depends" ] &&
1032 echo "The package $pkg depends on $missing_depends."
1033 done ;;
1034 package)
1035 pkg=$3
1036 VERBOSE=$4
1037 missing_depends="$(check_depends_pkg $pkg)"
1038 [ -n "$missing_depends" ] &&
1039 echo "The package $pkg depends on $missing_depends."
1040 ;;
1041 file)
1042 file=3
1043 VERBOSE=$4
1044 missing_depends="$(check_depends_this_file $file)"
1045 [ -n "$missing_depends" ] &&
1046 echo "The file $file depends on $missing_depends."
1047 ;;
1048 *) cat <<EOT
1049 check-depends wok check every package in wok.
1050 check-depends package <pkg> check one package.
1051 check-depends file <filename> check one file only.
1052 EOT
1053 ;;
1054 esac ;;
1055 *)
1056 usage ;;
1057 esac
1059 echo "" > $DB_DIR/running
1060 rm -f $LOCK_FILE /tmp/files.list.tazbb$$
1062 exit 0