wok view tazbb/stuff/tazbb @ rev 6123

tazbb : typo
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Sep 05 15:11:30 2010 +0200 (2010-09-05)
parents df6ec809759b
children bfd070141a36
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 yes | tazpkg install \
410 $PACKAGES_REPOSITORY/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg \
411 --forced
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 while (1) {
447 skipped = 0;
448 done = 0;
449 for (entry in deps) {
450 for (i = split(deps[entry], pkg, " "); i > 1; i--)
451 if (deps[pkg[i]] != "") break;
452 if (i == 1) {
453 print pkg[1];
454 deps[pkg[1]] = "";
455 done++;
456 }
457 else if (i > 1) skipped++;
458 }
459 if (skipped == 0) break;
460 if (done == 0) { # cross deps !!
461 for (entry in deps) {
462 if (split(deps[entry], pkg, " ") > 1)
463 print pkg[1];
464 }
465 break;
466 }
467 }
468 }
469 '
470 }
472 # Here we cook all packages found in the cooklist.
473 cook_install()
474 {
475 echo "" > $DB_DIR/unbuilt
476 for pkg in `cat $DB_DIR/cooklist | sort_cook_list`
477 do
478 if ! cook_package $pkg; then
479 # Link to build log.
480 echo "<a href=\"log.php?package=$(escape $pkg)$LOG_SUFFIX\">$pkg</a>" >> \
481 $DB_DIR/unbuilt
482 fi
483 missing_depends="$(check_depends_pkg $pkg)"
484 if [ -n "$missing_depends" ]; then
485 cat >> $LOG_DIR/$pkg.log <<EOT
487 Update $pkg receipt for DEPENDS :
488 The package $pkg depends on packages $missing_depends
490 EOT
491 # Unbuild package
492 rm -rf $BUILD_WOK/$pkg/taz
493 # Link to build log.
494 echo "<a href=\"log.php?package=$(escape $pkg)$LOG_SUFFIX\">$pkg</a>" >> \
495 $DB_DIR/unbuilt
496 fi
497 # Remove package from the cooklist and empty lines for HTML <pre>.
498 sed -i /"^$pkg$"/d $DB_DIR/cooklist
499 sed -i '/^$/d' $DB_DIR/cooklist
500 packages_summary_update
501 done
502 }
504 # Check for misc variables
505 check_variables()
506 {
507 PACKAGE=""
508 VERSION=""
509 EXTRAVERSION=""
510 CATEGORY=""
511 SHORT_DESC=""
512 MAINTAINER=""
513 WEB_SITE=""
514 PACKED_SIZE=""
515 UNPACKED_SIZE=""
516 . $BUILD_WOK/$1/receipt
517 if [ "$PACKAGE" != "$1" ]; then
518 echo "The PACKAGE variable should be $1"
519 return 1
520 fi
521 if [ -z "$VERSION" ]; then
522 echo "No VERSION in $1"
523 return 1
524 fi
525 if [ -z "$SHORT_DESC" ]; then
526 echo "No SHORT_DESC in $1"
527 return 1
528 fi
529 case "$MAINTAINER" in
530 '') echo "No MAINTAINER in $1"
531 return 1 ;;
532 *\<*|*\>*)
533 echo "Invalid MAINTAINER in $1"
534 return 1 ;;
535 *@*) ;;
536 *) echo "No email address for MAINTAINER in $1"
537 return 1 ;;
538 esac
539 if [ -z "$WEB_SITE" ]; then
540 echo "No WEB_SITE in $1"
541 return 1
542 fi
543 if [ -n "$EXTRAVERSION" ]; then
544 echo "Hardcoded EXTRAVERSION in $1"
545 return 1
546 fi
547 if [ -n "$PACKED_SIZE" ]; then
548 echo "Hardcoded PACKED_SIZE in $1"
549 return 1
550 fi
551 if [ -n "$UNPACKED_SIZE" ]; then
552 echo "Hardcoded UNPACKED_SIZE in $1"
553 return 1
554 fi
555 case " base-system x-window utilities network graphics multimedia \
556 office development system-tools security games misc meta \
557 non-free " in
558 *\ $CATEGORY\ *);;
559 *) echo "Invalid CATEGORY in $1 : $CATEGORY"
560 return 1;
561 esac
562 return 0
563 }
565 # Check for WANTED version
566 check_wanted_version()
567 {
568 WANTED=""
569 . $BUILD_WOK/$1/receipt
570 if [ -n "$WANTED" ]; then
571 expected=$VERSION
572 VERSION=
573 . $BUILD_WOK/$WANTED/receipt
574 if [ "$VERSION" != "$expected" ]; then
575 echo "$1: expected wanted version $expected, found $VERSION"
576 return 1
577 fi
578 fi
579 return 0
580 }
582 # Check for loop in BUILD_DEPENDS/WANTED
583 check_build_depends()
584 {
585 local i
586 BUILD_DEPENDS=""
587 WANTED=""
588 . $BUILD_WOK/$1/receipt
589 for i in $BUILD_DEPENDS $WANTED ; do
590 case " $2 " in
591 *\ $i\ *) echo "Loop in BUILD_DEPENDS/WANTED chain $2 $i"
592 return 1 ;;
593 *) check_build_depends $i "$2 $1" || return 1 ;;
594 esac
595 done
596 return 0
597 }
599 # Build depends_to_skip list with packages to remove from depends_to_add list
600 # These packages are already present in depends_to_add trees
601 scan_depends_to_skip()
602 {
603 local i
604 case " $depends_to_skip " in
605 *\ $1\ *) return;;
606 esac
607 [ -d $BUILD_WOK/$1 ] || return
608 DEPENDS=""
609 . $BUILD_WOK/$1/receipt
610 for i in $DEPENDS ; do
611 case " $depends_to_add " in
612 *\ $i\ *) depends_to_skip="$depends_to_skip $i";;
613 esac
614 done
615 for i in $DEPENDS ; do
616 scan_depends_to_skip $i
617 done
618 }
620 # Reduce depends list by scanning nested depends
621 show_missing_depends()
622 {
623 local i
624 depends_to_add=""
625 depends_to_skip="$2"
626 for i in $1 ; do
627 case " $depends_to_add " in
628 *\ $i\ *) continue;;
629 esac
630 depends_to_add="$depends_to_add$i "
631 done
632 for i in $depends_to_add ; do
633 scan_depends_to_skip $i
634 done
635 for i in $depends_to_add ; do
636 case " $depends_to_skip " in
637 *\ $i\ *) continue;;
638 esac
639 echo -n "$i "
640 done
641 }
643 # Build all_depends variable
644 scan_dep()
645 {
646 local i
647 all_depends="$all_depends$PACKAGE "
648 for i in $DEPENDS $SUGGESTED ; do
649 case " $all_depends " in
650 *\ $i\ *) continue;;
651 esac
652 [ -d $BUILD_WOK/$i ] || {
653 all_depends="$all_depends$i "
654 continue
655 }
656 DEPENDS=""
657 SUGGESTED=""
658 . $BUILD_WOK/$i/receipt
659 scan_dep
660 done
661 }
663 # Check for ELF file
664 is_elf()
665 {
666 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
667 }
669 # Print shared library dependencies
670 ldd()
671 {
672 LD_PRELOAD="" LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
673 }
675 # scan a file for shared libraries and display according package names
676 check_depends_file()
677 {
678 file=$1
679 is_elf $file || continue
680 case "$file" in
681 *.o|*.ko|*.ko.gz) continue;;
682 esac
683 [ -s /tmp/files.list.tazbb$$ ] ||
684 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma >/tmp/files.list.tazbb$$
685 ldd $file | while read lib rem; do
686 case "$lib" in
687 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
688 continue;;
689 esac
690 for dep in $(grep $lib /tmp/files.list.tazbb$$ | cut -d: -f1); do
691 case " $all_depends " in
692 *\ $dep\ *) continue 2;;
693 esac
694 for vdep in $(grep $dep $PACKAGES_REPOSITORY/packages.equiv | cut -d= -f1); do
695 case " $all_depends " in
696 *\ $vdep\ *) continue 3;;
697 esac
698 done
699 done
700 [ -n "$dep" ] || dep="UNKNOWN"
701 all_depends="$all_depends $dep"
702 if [ -n "$VERBOSE" ]; then
703 echo "${file#*fs} depends on package $dep for the shared library $lib" 1>&2
704 fi
705 echo -n "$dep "
706 done
707 }
709 DEFAULT_DEPENDS="glibc-base"
711 # scan a package for shared libraries and display missing package in DEPENDS
712 check_depends_pkg()
713 {
714 pkg=$1
715 echo "(checking depends for $pkg)" > $DB_DIR/running
716 tmp=/tmp/tazbb$$
717 mkdir $tmp
718 package=$(basename $pkg)
719 if ! cd ${package%%-*}*/taz/${package%.tazpkg}/.. 2> /dev/null; then
720 cd $tmp
721 tazpkg extract $pkg > /dev/null 2>&1
722 fi
723 . */receipt
724 all_depends="$DEFAULT_DEPENDS "
725 scan_dep
726 toadd=$(find */fs -type f | while read file ; do
727 check_depends_file $file
728 done)
729 . */receipt
730 rm -rf */
731 cd - > /dev/null
732 rm -rf $tmp
733 show_missing_depends "$toadd" "$DEPENDS $SUGGESTED"
734 }
736 check_depends_this_file()
737 {
738 file=$1
739 all_depends="$DEFAULT_DEPENDS "
740 scan_dep
741 check_depends_file $file
742 }
744 # Remove old packages in the build wok and clean pkgs repository. The
745 # Hg wok is copied into the build wok so packages removed by hg must be
746 # removed. To remove old packages in the repository we look into the
747 # build wok and dont remove unbuilt packages. Clean-up will also remove
748 # all corrupted packages.
749 clean_up()
750 {
751 touch $DB_DIR/removed
752 echo -e "\nCleaning the build wok, old and corrupted packages...\n"
753 echo "(cleaning)" > $DB_DIR/running
754 for pkg in `ls $BUILD_WOK`
755 do
756 if [ ! -d $HG_WOK/$pkg ]; then
757 case $2 in
758 --dry-run)
759 echo "Removing directory : $pkg" ;;
760 --verbose)
761 echo "Removing directory : $pkg"
762 rm -rf $BUILD_WOK/$pkg ;;
763 *)
764 rm -rf $BUILD_WOK/$pkg ;;
765 esac
766 fi
767 done
768 # Build a packages list with EXTRAVERSION so we can grep into it.
769 rm -f $DB_DIR/packaged && touch $DB_DIR/packaged
770 for receipt in $BUILD_WOK/*/taz/*/receipt
771 do
772 EXTRAVERSION=""
773 . $receipt
774 echo "$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" >> $DB_DIR/packaged
775 done
776 for pkg in `cd $PACKAGES_REPOSITORY && ls *.tazpkg`
777 do
778 if ! grep -q "^$pkg$" $DB_DIR/packaged; then
779 case $2 in
780 --dry-run)
781 echo "Removing package : $pkg" ;;
782 --verbose)
783 echo "Removing package : $pkg"
784 echo "$pkg" >> $DB_DIR/removed
785 rm -f $PACKAGES_REPOSITORY/$pkg ;;
786 *)
787 echo "$pkg" >> $DB_DIR/removed
788 rm -f $PACKAGES_REPOSITORY/$pkg ;;
789 esac
790 fi
791 done
792 # Remove all corrupted packages
793 for pkg in `cat $DB_DIR/corrupted | awk '{ print $3 }'`
794 do
795 case $2 in
796 --dry-run)
797 echo "Removing corrupted: $pkg" ;;
798 --verbose)
799 echo "Removing corrupted: $pkg"
800 echo "$pkg" >> $DB_DIR/removed
801 rm -rf $PACKAGES_REPOSITORY/$pkg ;;
802 *)
803 echo "$pkg" >> $DB_DIR/removed
804 rm -rf $PACKAGES_REPOSITORY/$pkg ;;
805 esac
806 done
807 echo ""
808 # Keep the 20 last removed packages list.
809 cat $DB_DIR/removed | tail -n 20 > /tmp/removed.tail
810 mv -f /tmp/removed.tail $DB_DIR/removed
811 # Clean packages stuff/ directory
812 echo -e "\nCleaning the build wok stuff/ directories...\n"
813 for pkg in `ls $BUILD_WOK`
814 do
815 if [ -d "$BUILD_WOK/$pkg/stuff" ]; then
816 cd $BUILD_WOK/$pkg
817 for file in `find stuff -type f`
818 do
819 if [ ! -f "$HG_WOK/$pkg/$file" ]; then
820 echo "Removing: $pkg/$file"
821 rm $file
822 fi
823 done
824 fi
825 done
826 }
828 blocked_urls()
829 {
830 rm -f $DB_DIR/blocked.urls
831 for pkg in `cat $DB_DIR/blocked`
832 do
833 if [ -f $LOG_DIR/$pkg.log ]; then
834 echo "<a href=\"log.php?package=$(escape $pkg)$LOG_SUFFIX\">$pkg</a>" >> \
835 $DB_DIR/blocked.urls
836 else
837 echo "$pkg" >> $DB_DIR/blocked.urls
838 fi
839 done
840 }
842 # 4k, not a meta or a get-* package and no files = buggy package
843 test_packages()
844 {
845 echo -e "\nTesting all packages in: $PACKAGES_REPOSITORY"
846 echo "================================================================================"
847 echo "(testing packages)" > $DB_DIR/running
848 rm -f $DB_DIR/corrupted && touch $DB_DIR/corrupted
849 for pkg in $PACKAGES_REPOSITORY/*.tazpkg
850 do
851 tmp=/tmp/bb-test.$$
852 CATEGORY=""
853 if du $pkg | grep -qw '^4' && ! echo `basename $pkg` | grep -q '^get-'; then
854 mkdir -p $tmp && cd $tmp
855 cpio -i receipt >/dev/null 2>&1 < $pkg
856 . ./receipt
857 if [ "$CATEGORY" != "meta" ]; then
858 [ "$2" = "--verbose" ] && echo "Testing: $PACKAGE"
859 cpio -i fs.cpio.gz >/dev/null 2>&1 < $pkg
860 cpio -i fs.cpio.lzma >/dev/null 2>&1 < $pkg
861 if [ ! -f fs.cpio.gz -a ! -f fs.cpio.lzma ]; then
862 echo "Missing filesystem `basename $pkg`"
863 if [ -f $LOG_DIR/$PACKAGE.log ];then
864 echo "Missing filesystem `basename $pkg` <a href=\"log.php?package=$(escape $PACKAGE)$LOG_SUFFIX\">Log</a>" \
865 >> $DB_DIR/corrupted
866 else
867 echo "Missing filesystem `basename $pkg`" \
868 >> $DB_DIR/corrupted
869 fi
870 else
871 ( zcat fs.cpio.gz 2> /dev/null || \
872 unlzma -c fs.cpio.lzma ) | \
873 cpio -id >/dev/null 2>&1
874 files=`find fs -type f -o -type l`
875 if [ -z "$files" ]; then
876 echo "Empty filesystem `basename $pkg`"
877 if [ -f $LOG_DIR/$PACKAGE.log ]; then
878 echo "Empty filesystem `basename $pkg` <a href=\"log.php?package=$(escape $PACKAGE)$LOG_SUFFIX\">Log</a>" \
879 >> $DB_DIR/corrupted
880 else
881 echo "Empty filesystem `basename $pkg`" \
882 >> $DB_DIR/corrupted
883 fi
884 fi
885 fi
886 fi
887 cd .. && rm -rf $tmp
888 fi
889 done
890 packages_summary_update
891 echo ""
892 }
894 # Generate flavor list
895 gen_flavor_list()
896 {
897 cd $PACKAGES_REPOSITORY
898 noheader=""
899 for i in *.flavor; do
900 tazlito show-flavor $i --brief $noheader
901 noheader="--noheader"
902 done > flavors.list
903 cd - > /dev/null
904 }
906 case "$1" in
907 list-pkgs)
908 # List last cooked packages.
909 list_packages ;;
910 report)
911 # Run in report mode. If an update is done we must cook-all to
912 # rebuild all updated packages.
913 [ "$2" == "--update" ] && update_wok $@ || echo ""
914 check_wok $@
915 check_flavors $@
916 test_packages $@
917 show_report ;;
918 cook)
919 # Cook, install and log a single package build.
920 if [ -z $2 ]; then
921 echo "Please specify a package on the command line."
922 rm -f $LOCK_FILE && exit 0
923 fi
924 pkg=$2
925 echo "Starting to cook and install: $pkg"
926 if ! cook_package $pkg; then
927 echo "Unable to install: $pkg"
928 fi ;;
929 cook-all)
930 # Update wok, gen report (with cooklist), cook all packages, test,
931 # clean, gen new report and lists.
932 update_wok $@
933 check_wok $@
934 cook_install
935 test_packages $@
936 check_flavors $@
937 pack_flavors
938 clean_up $@
939 check_wok $@
940 echo "(generating lists)" > $DB_DIR/running
941 tazwok gen-list --text
942 check_flavors $@
943 gen_flavor_list
944 echo "" ;;
945 cook-commit)
946 # Cook all packages affected by the last commits in the wok.
947 # Clean up is done only by cook-all to avoid rebuild of corrupted
948 # packages on each commit.
949 update_wok $@
950 check_commit
951 cook_install
952 test_packages $@
953 check_flavors $@
954 pack_flavors
955 check_wok $@
956 check_flavors $@
957 echo "(generating lists)" > $DB_DIR/running
958 tazwok gen-list --text
959 gen_flavor_list
960 echo "" ;;
961 block)
962 # Add a pkg name to the list of blocked packages.
963 echo ""
964 if grep -qs "^$2$" $DB_DIR/blocked; then
965 echo -e "$2 is already in the blocked packages list."
966 else
967 echo -n "Adding $2 to : $DB_DIR/blocked... "
968 echo "$2" >> $DB_DIR/blocked && echo "Done"
969 if grep -q "^$2$" $DB_DIR/cooklist; then
970 echo -n "Removing $2 from : $DB_DIR/cooklist... "
971 sed -i /"^$2$"/d $DB_DIR/cooklist && echo "Done"
972 packages_summary_update
973 fi
974 fi
975 blocked_urls
976 echo "" ;;
977 unblock)
978 # Remove a pkg name from the list of blocked packages.
979 echo ""
980 if grep -qs "^$2$" $DB_DIR/blocked; then
981 echo -n "Removing $2 from : $DB_DIR/blocked... "
982 sed -i /"^$2$"/d $DB_DIR/blocked
983 sed -i '/^$/d' $DB_DIR/blocked && echo "Done"
984 echo -n "Adding $2 to : $DB_DIR/cooklist... "
985 echo "$2" >> $DB_DIR/cooklist && echo "Done"
986 packages_summary_update
987 else
988 echo -e "$2 is not in the blocked packages list."
989 fi
990 blocked_urls
991 echo "" ;;
992 test-pkgs)
993 # Start a test suite on all builded packages.
994 test_packages $@ ;;
995 test-suite)
996 # Start a test suite on all builded package and the wok using
997 # the great 'tazwok check'.
998 #
999 # test_packages > $LOG_DIR/test-suite.log
1000 # tazwok check >> $LOG_DIR/test-suite.log
1002 test_packages $@
1003 script -c "tazwok check" $LOG_DIR/test-suite.log ;;
1004 mail)
1005 # Tazbbmail Pythom script wrapper.
1006 PACKAGE=$2
1007 tazbbmail $PACKAGE ;;
1008 clean-up)
1009 # Remove old packages and generate new packages lists.
1010 update_wok $@
1011 clean_up $@
1012 packages_summary_update
1013 [ "$2" != "--dry-run" ] && tazwok gen-list --text ;;
1014 clean-log)
1015 logs=`ls $LOG_DIR | wc -l`
1016 echo -n "Cleaning: $LOG_DIR... "
1017 rm -rf $LOG_DIR/*
1018 echo "$logs log removed" ;;
1019 check-receipt)
1020 check_variables $2 &&
1021 check_wanted_version $2 &&
1022 check_build_depends $2 ""
1023 return $? ;;
1024 check-depends)
1025 case "$2" in
1026 wok)
1027 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
1028 missing_depends="$(check_depends_pkg $pkg)"
1029 [ -n "$missing_depends" ] &&
1030 echo "The package $pkg depends on $missing_depends."
1031 done ;;
1032 package)
1033 pkg=$3
1034 VERBOSE=$4
1035 missing_depends="$(check_depends_pkg $pkg)"
1036 [ -n "$missing_depends" ] &&
1037 echo "The package $pkg depends on $missing_depends."
1038 ;;
1039 file)
1040 file=3
1041 VERBOSE=$4
1042 missing_depends="$(check_depends_this_file $file)"
1043 [ -n "$missing_depends" ] &&
1044 echo "The file $file depends on $missing_depends."
1045 ;;
1046 *) cat <<EOT
1047 check-depends wok check every package in wok.
1048 check-depends package <pkg> check one package.
1049 check-depends file <filename> check one file only.
1050 EOT
1051 ;;
1052 esac ;;
1053 *)
1054 usage ;;
1055 esac
1057 echo "" > $DB_DIR/running
1058 rm -f $LOCK_FILE /tmp/files.list.tazbb$$
1060 exit 0