cookutils view lib/libcookorder.sh @ rev 543

libcookiso.sh: Add some more comments.
author Christopher Rogers <slaxemulator@gmail.com>
date Mon Oct 15 16:28:45 2012 +0000 (2012-10-15)
parents 8da5f7cbd5c0
children ad9af7bfcc78
line source
1 #!/bin/sh
3 # Define & create a temporary directory as it's used by report.
4 tmp=/tmp/$(basename $0)-$$
5 mkdir -p $tmp
7 log_command="$0 $@"
9 ########################################################################
10 # EXIT FUNCTIONS
11 ########################
12 # run_on_exit commands are executed when apps exit (whatever the reason)
13 # run_on_kill commands are executed only when apps are killed (or Ctrl+C)
14 # Note : one command per line in the variable.
15 run_on_exit="rm -rf $tmp"
16 run_on_kill=""
17 trap run_on_exit EXIT
18 trap run_on_kill INT KILL
20 run_on_exit()
21 {
22 echo "$run_on_exit" | while read c; do
23 run_on_exit=$(echo "$run_on_exit" | sed 1d)
24 $c
25 done
26 trap - EXIT
27 exit
28 }
30 run_on_kill()
31 {
32 echo "$run_on_kill" | while read c; do
33 run_on_kill=$(echo "$run_on_kill" | sed 1d)
34 $c
35 done
36 trap - INT KILL
37 run_on_exit
38 }
40 # List packages providing a virtual package.
41 whoprovide()
42 {
43 local i;
44 for i in $(fgrep -l PROVIDE $WOK/*/receipt); do
45 . $i
46 case " $PROVIDE " in
47 *\ $1\ *|*\ $1:*) echo $(basename $(dirname $i));;
48 esac
49 done
50 }
52 # Be sure package exists in wok.
53 check_pkg_in_wok() {
54 [ -f $receipt ] && return
55 [ -f $WOK/$(whoprovide $PACKAGE)/receipt ] && return 1
56 gettext -e "\nUnable to find package in the wok:"
57 echo -e " $pkg\n" && exit 1
58 }
60 rsync_wok() {
61 if [ -d "$WOKHG" ]; then
62 echo "Updating build wok"
63 rsync -r -t -l -u --force -v -D -E --delete --exclude-from "/usr/share/cook/exclude.txt" $WOKHG/ $WOK/ | \
64 sed '/^$/'d
65 for i in $(ls $WOK); do
66 [ ! -f $WOKHG/$i/receipt ] || continue
67 if [ -d $WOK/$i ]; then
68 echo "Deleting $i"
69 rm -rf $WOK/$i
70 fi
71 done
72 fi
73 }
75 # Store -- options in a variable.
76 # Test phase.
77 # Need to add something to filter options and report errors in case option is not
78 # listed and used by the command.
79 get_options()
80 {
81 if echo "$log_command" | fgrep -q ' '--help; then
82 echo "Available options for $(echo `basename "$log_command"` | cut -d ' ' -f 1,2) : $get_options_list"
83 exit 0
84 fi
85 for get_option in $(echo "$log_command" | tr ' ' '\n' | grep ^-- | sed 's/^--//'); do
86 if [ "${get_options_list/${get_option%%=*}}" = "$get_options_list" ]; then
87 echo "Option ${get_option%%=*} is incorrect, valid options are : $get_options_list". >&2
88 exit 1
89 fi
90 if [ "$get_option" = "${get_option/=}" ]; then
91 export $get_option=yes
92 export opts="$opts --$get_option"
93 else
94 export $get_option
95 export opts="$opts --$get_option"
96 fi
97 done
98 }
100 gen_wan_db()
101 {
102 local receipt
103 [ -f $wan_db ] && rm $wan_db
104 for receipt in $(grep -l ^WANTED= $WOK/*/receipt); do
105 unset WANTED DEPENDS
106 [ -f $receipt ] || continue
107 source $receipt
108 [ "$WANTED" ] || continue
109 echo -e $PACKAGE"\t"$WANTED >> $wan_db
110 done
111 if [ "$wan_db" = "$INCOMING/wanted.txt" ]; then
112 cp -a $wan_db $PKGS/wanted.txt
113 fi
114 }
116 gen_dep_db()
117 {
118 local pkg receipt
119 [ -f $dep_db ] && rm $dep_db
120 for pkg in $(ls $WOK); do
121 unset DEPENDS BUILD_DEPENDS
122 receipt=$WOK/$pkg/receipt
123 if [ -f $receipt ]; then
124 source $receipt
125 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
126 fi
127 done
128 if [ "$dep_db" = "$INCOMING/depends.txt" ]; then
129 cp -a $dep_db $PKGS/depends.txt
130 fi
131 }
133 gen_wok_db()
134 {
135 echo "Generating wok database"
136 echo "Removing old files"
137 for file in $wan_db $dep_db $fullco; do
138 [ -f $file ] && rm $file
139 done
140 echo "Generating $(basename $wan_db)"
141 gen_wan_db
142 echo "Generating $(basename $dep_db)"
143 gen_dep_db
144 echo "Generating $(basename $fullco)"
145 sort_db
146 }
148 look_for_dep()
149 {
150 grep -m1 ^$PACKAGE$'\t' $dep_db | \
151 cut -f 2
152 }
154 look_for_all()
155 {
156 grep -m1 ^$PACKAGE$'\t' $dep_db | \
157 cut -f 2,3 | sed 's/ / /'
158 }
160 look_for_bdep()
161 {
162 look_for_all
163 }
165 look_for_rdep()
166 {
167 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1
168 }
170 look_for_rbdep()
171 {
172 fgrep ' '$PACKAGE' ' $dep_db | \
173 cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
174 }
176 look_for_wanted()
177 {
178 grep -m1 ^$PACKAGE$'\t' $wan_db | cut -f 2
179 }
181 look_for_rwanted()
182 {
183 for rwanted in $(grep $'\t'$PACKAGE$ $wan_db | cut -f 1); do
184 if [ -f "$WOK/$rwanted/receipt" ]; then
185 echo "$rwanted"
186 fi
187 done
188 }
190 look_for_dev()
191 {
192 WANTED=$(look_for_wanted)
193 if [ "$WANTED" ]; then
194 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
195 fi
196 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
197 }
199 with_dev()
200 {
201 for PACKAGE in $(cat); do
202 echo $PACKAGE
203 look_for_dev
204 done
205 }
207 with_wanted()
208 {
209 for PACKAGE in $(cat); do
210 echo $PACKAGE
211 look_for_wanted
212 done
213 }
215 use_wanted()
216 {
217 for input in $(cat); do
218 { grep ^$input$'\t' $wan_db || echo $input
219 }
220 done | sed 's/.*\t//'
221 }
223 # We use md5 of cooking stuff in the packaged receipt to check
224 # commit. We look consecutively in 3 different locations :
225 # - in the wok/PACKAGE/taz/* folder
226 # - in the receipt in the package in incoming repository
227 # - in the receipt in the package in packages repository
228 # If md5sums match, there's no commit.
229 check_for_commit_using_md5sum()
230 {
231 if [ ! -f $WOK/$PACKAGE/md5 ]; then
232 sed -n '/# md5sum of cooking stuff :/,$p' receipt | \
233 sed -e 1d -e 's/^# //' > $WOK/$PACKAGE/md5
234 cd $WOK/$PACKAGE
235 fi
237 if [ -s md5 ]; then
238 if md5sum -cs md5; then
239 # If md5sum check if ok, check for new/missing files in
240 # cooking stuff.
241 for file in $([ -f receipt ] && echo receipt; \
242 [ -f description.txt ] && echo description.txt; \
243 [ -d stuff ] && find stuff); do
244 if ! fgrep -q " $file" md5; then
245 set_commited
246 fi
247 done
248 else
249 set_commited
250 fi
251 else
252 set_commited
253 fi
254 }
256 set_commited()
257 {
258 grep -q ^$PACKAGE$ $commits || echo $PACKAGE >> $commits
259 gen_cookmd5
260 update_dep_db
261 }
263 gen_cookmd5()
264 {
265 # md5sum of cooking stuff make tazwok able to check for changes
266 # without hg.
267 md5sum $WOK/$PACKAGE/receipt > $WOK/$PACKAGE/md5
268 [ -f $WOK/$PACKAGE/description.txt ] && md5sum $WOK/$PACKAGE/description.txt >> $WOK/$PACKAGE/md5
269 if [ -d $WOK/$PACKAGE/stuff ]; then
270 find $WOK/$PACKAGE/stuff -type f | while read file; do
271 md5sum $file >> $WOK/$PACKAGE/md5
272 done
273 fi
274 sed -i "s|$WOK/$PACKAGE/||g" $WOK/$PACKAGE/md5
275 }
277 check_for_commit()
278 {
279 if ! check_pkg_in_wok; then
280 [ "$?" = 2 ] && return 1
281 return
282 fi
283 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
284 RECEIPT=$WOK/$PACKAGE/receipt
285 unset_receipt
286 [ -f $RECEIPT ] || continue
287 source $RECEIPT
289 taz_dir=$(echo $WOK/$PACKAGE/taz/$PACKAGE-* | fgrep -v '*')
290 if [ -f $WOK/$PACKAGE/md5 ]; then
291 cd $WOK/$PACKAGE
292 check_for_commit_using_md5sum
293 elif [ "$taz_dir" ]; then
294 cd $taz_dir
295 check_for_commit_using_md5sum
296 else
297 pkgfile=$(echo $INCOMING/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
298 [ "$pkgfile" ] || pkgfile=$(echo $PKGS/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
299 if [ "$pkgfile" ]; then
300 get_pkg_files $pkgfile
301 check_for_commit_using_md5sum
302 rm -r $pkg_files_dir
303 else
304 set_commited
305 fi
306 fi
307 [ "$forced" ] || echo $PACKAGE >> $tmp/checked
308 unset pkgfile
309 done
310 }
312 ########################################################################
313 # SCAN
314 ########################
315 # Use wanted.txt and depeds.txt to scan depends.
316 # Option in command line (must be first arg) :
317 # --look_for=bdep/rbdep - Look for depends or reverse depends.
318 # --with_dev - Add development packages (*-dev) in the result.
319 # --with_wanted - Add package+reverse wanted in the result.
320 # --with_args - Include packages in argument in the result.
322 scan()
323 {
324 # Get packages in argument.
325 local PACKAGE=$PACKAGE WANTED=$WANTED pkg_list=
326 for arg in $@; do
327 [ "$arg" = "${arg#--}" ] || continue
328 pkg_list="$pkg_list $arg"
329 done
331 # Get options.
332 [ "$pkg_list" ] || return
333 local cooklist= look_for= with_dev= with_wanted= with_args= log_command="$0 $@" \
334 get_options_list="look_for with_dev with_wanted with_args cooklist use_wanted"
335 get_options
337 # Get db md5 to be able to check for changes latter.
338 db_md5=$(md5sum $dep_db $wan_db)
340 # Cooklist is a special case where we need to modify a little
341 # scan behavior
342 if [ "$cooklist" ]; then
343 gen_wan_db
344 look_for=all && with_args=yes && with_dev= && with_wanted=
345 filter=use_wanted
346 if [ "$COMMAND" = gen-cooklist ]; then
347 for PACKAGE in $pkg_list; do
348 grep -q ^$PACKAGE$'\t' $dep_db && continue
349 [ -d "$WOK/$p" ] || continue
350 check_for_missing
351 done
352 append_to_dep()
353 {
354 if grep -q ^$PACKAGE$'\t' $dep_db; then
355 echo $PACKAGE >> $tmp/dep
356 else
357 check_for_missing && echo $PACKAGE >> $tmp/dep
358 fi
359 }
360 else
361 append_to_dep()
362 {
363 check_for_commit && echo $PACKAGE >> $tmp/dep
364 }
365 fi
366 else
367 append_to_dep()
368 {
369 echo $PACKAGE >> $tmp/dep
370 }
371 # If requested packages are not in dep_db, partial generation of this db is needed.
372 for PACKAGE in $pkg_list; do
373 grep -q ^$PACKAGE$'\t' $dep_db && continue
374 [ -d "$WOK/$p" ] || continue
375 plan_check_for_missing=yes
376 check_for_missing
377 done
378 if [ "$plan_check_for_missing" ]; then
379 append_to_dep()
380 {
381 if grep -q ^$PACKAGE$'\t' $dep_db; then
382 echo $PACKAGE >> $tmp/dep
383 else
384 check_for_missing && echo $PACKAGE >> $tmp/dep
385 fi
386 }
387 unset plan_check_for_missing
388 fi
389 fi
391 [ "$with_dev" ] && filter=with_dev
392 [ "$with_wanted" ] && filter=with_wanted
393 if [ "$filter" ]; then
394 pkg_list=$(echo $pkg_list | $filter | sort -u)
395 scan_pkg()
396 {
397 look_for_$look_for | $filter
398 }
399 else
400 scan_pkg()
401 {
402 look_for_$look_for
403 }
404 fi
405 touch $tmp/dep
406 for PACKAGE in $pkg_list; do
407 [ "$with_args" ] && append_to_dep
408 scan_pkg
409 done | tr ' ' '\n' | sort -u > $tmp/list
410 [ "$look_for" = bdep ] && look_for=dep
411 while [ -s $tmp/list ]; do
412 PACKAGE=$(sed 1!d $tmp/list)
413 sed 1d -i $tmp/list
414 append_to_dep
415 for pkg in $(scan_pkg); do
416 grep -q ^$pkg$ $tmp/list $tmp/dep || echo $pkg >> $tmp/list
417 done
418 done
419 if [ "$cooklist" ]; then
420 mv $tmp/dep $tmp/cooklist
421 else
422 cat $tmp/dep | sort -u
423 fi
424 rm -f $tmp/dep $tmp/list
425 sort -o $dep_db $dep_db
426 sort -o $wan_db $wan_db
427 if [ "$db_md5" != "$(md5sum $dep_db $wan_db)" ]; then
428 grep -q "^#" $fullco || sed 1i"#PlanSort" -i $fullco
429 fi
430 }
432 update_wan_db()
433 {
434 local PACKAGE=$PACKAGE
435 wanted_list=$(fgrep WANTED=\"$PACKAGE\" $WOK/*/receipt | cut -f1 -d ':')
436 grep $'\t'$PACKAGE$ $wan_db | cut -f 1 | while read wan; do
437 echo "$wanted_list" | fgrep -q $WOK/$wan/receipt && continue
438 sed "/^$wan\t/d" -i $wan_db
439 done
440 for RECEIPT in $wanted_list; do
441 unset WANTED PACKAGE
442 [ -f $RECEIPT ] || continue
443 source $RECEIPT
444 [ "$WANTED" ] || continue
445 sed "/^$PACKAGE\t/d" -i $wan_db
446 echo -e $PACKAGE"\t"$WANTED >> $wan_db
447 done
448 unset wanted_list
449 }
451 update_dep_db()
452 {
453 sed "/^$PACKAGE\t/d" -i $dep_db
454 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
455 }
457 sort_db()
458 {
459 #echo "Generating full cookorder (fullco)"
460 sed 's/ \t / /' $dep_db | while read PACKAGE BUILD_DEPENDS; do
461 grep -q ^$PACKAGE$'\t' $wan_db && continue
463 # Replace each BUILD_DEPENDS with a WANTED package by it's
464 # WANTED package.
465 echo -e $PACKAGE"\t $(echo $BUILD_DEPENDS | use_wanted | \
466 sort -u | sed "/^$PACKAGE$/d" | tr '\n' ' ') "
467 done > $tmp/db
468 while [ -s "$tmp/db" ]; do
469 status=start
470 for pkg in $(cut -f 1 $tmp/db); do
471 if ! fgrep -q ' '$pkg' ' $tmp/db; then
472 echo $pkg >> $tmp/fullco
473 sed -e "/^$pkg\t/d" -e "s/ $pkg / /g" -i $tmp/db
474 status=proceed
475 fi
476 done
477 if [ "$status" = start ]; then
478 cp -f $tmp/db /tmp/remain-depends.txt
479 echo "Can't go further because of dependency loop(s). The remaining packages will be commented in the cookorder and will be unbuilt in case of major updates until the problem is solved." >&2
480 for remaining in $(cut -f 1 $tmp/db); do
481 if ! grep -q ^$remaining $blocked; then
482 echo "$remaining" >> $blocked
483 fi
484 done
485 break
486 fi
487 done
488 [ -s $tmp/fullco ] || touch $tmp/fullco
490 # The toolchain packages are moved in first position.
491 grep $(for pkg in `scan "$TOOLCHAIN $TOOLCHAIN_EXTRA" \
492 --look_for=all --with_args`; do echo " -e ^$pkg$"; done) \
493 $tmp/fullco | tac > $fullco
494 for pkg in $(cat $fullco); do
495 sed "/^$pkg$/d" -i $tmp/fullco
496 done
498 tac $tmp/fullco >> $fullco
499 }
501 check_for_missing()
502 {
503 local PACKAGE=$PACKAGE
504 if ! check_pkg_in_wok; then
505 [ "$?" = 2 ] && return 1
506 return
507 fi
508 RECEIPT=$WOK/$PACKAGE/receipt
509 [ -f $RECEIPT ] || continue
510 source $RECEIPT
511 PACKAGE=${WANTED:-$PACKAGE}
512 update_wan_db
513 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
514 RECEIPT=$WOK/$PACKAGE/receipt
515 [ -f $RECEIPT ] || continue
516 source $RECEIPT
517 update_dep_db
518 done
519 }
521 look_for_missing_pkg()
522 {
523 for pkg in $(cat $1); do
524 grep -q ^$pkg$ $INCOMING/packages.txt \
525 $PKGS/packages.txt || \
526 continue
527 echo $pkg
528 done
529 }
531 # Output $VERSION-$EXTRAVERSION using packages.txt
532 get_pkg_version()
533 {
534 [ "$PACKAGE" ] || return
535 grep -m1 -A1 -sh ^$PACKAGE$ $1/packages.txt | tail -1 | sed 's/ *//'
536 }
538 remove_previous_package()
539 {
540 if [ "$prev_VERSION" ] && [ "$VERSION$EXTRAVERSION" != "$prev_VERSION" ]; then
541 rm -f $1/$PACKAGE-$prev_VERSION.tazpkg
542 fi
543 return 0
544 }
546 gen_cook_list()
547 {
548 #echo "Scanning wok"
549 if [ "$pkg" ]; then
550 scan $pkg --cooklist
551 elif [ "$LIST" ]; then
552 scan `cat $LIST` --cooklist
553 else
554 scan `cat $cooklist` --cooklist
555 fi
557 [ -s $tmp/checked ] || [ -s $tmp/cooklist ] || return
559 # Core toolchain should not be cooked unless cook-toolchain is used.
560 if [ "$COMMAND" != "toolchain" ] ; then
561 for PACKAGE in $(scan slitaz-toolchain --look_for=all --with_args --with_wanted); do
562 grep -q ^$PACKAGE$ $blocked || \
563 echo $PACKAGE >> $blocked
564 done
565 fi
567 if [ -s $commits ] && [ "$COMMAND" != gen-cooklist ]; then
568 for PACKAGE in $(cat $commits); do
569 WANTED="$(look_for_wanted)"
570 if [ "$WANTED" ]; then
571 grep -q ^$WANTED$ $broken $cooklist $blocked $commits && continue
572 fi
573 grep -q ^$PACKAGE$ $blocked $cooklist && continue
574 echo $PACKAGE >> $cooklist
575 done
576 fi
577 sort_cooklist
578 }
580 sort_cooklist()
581 {
582 if [ "$(sed 1!d $fullco)" = "#PlanSort" ]; then
583 sed 1d -i $fullco
584 sort_db
585 fi
586 #echo "Generating cooklist"
587 if [ -f "$tmp/checked" ]; then
588 rm -f $tmp/cooklist
589 cat $tmp/checked | while read PACKAGE; do
590 grep -q ^$PACKAGE$ $cooklist && echo $PACKAGE >> $tmp/cooklist
591 done
592 elif ! [ "$COMMAND" = gen-cooklist ]; then
593 cat $blocked | while read PACKAGE; do
594 sed "/^$PACKAGE/d" -i $tmp/cooklist
595 done
596 fi
597 [ -s $tmp/cooklist ] || return
599 #echo "Sorting cooklist"
600 for PACKAGE in $(cat $tmp/cooklist); do
601 WANTED="$(look_for_wanted)"
602 [ "$WANTED" ] || continue
603 if grep -q ^$WANTED$ $broken $tmp/cooklist; then
604 sed "/^$PACKAGE$/d" -i $tmp/cooklist
605 elif [ ! -d $WOK/$WANTED/install ]; then
606 sed "/^$PACKAGE$/d" -i $tmp/cooklist
607 echo $WANTED >> $tmp/cooklist
608 fi
609 done
611 # Use cookorder.txt to sort cooklist.
612 if [ -s $tmp/cooklist ]; then
613 cat $fullco | while read PACKAGE; do
614 if grep -q ^$PACKAGE$ $tmp/cooklist; then
615 sed "/^$PACKAGE$/d" -i $tmp/cooklist
616 echo $PACKAGE >> $tmp/cooklist.tmp
617 fi
618 done
620 # Remaining packages in cooklist are those without compile_rules.
621 # They can be cooked first in any order.
622 if [ -f $tmp/cooklist.tmp ]; then
623 cat $tmp/cooklist.tmp >> $tmp/cooklist
624 rm $tmp/cooklist.tmp
625 fi
627 cat $tmp/cooklist
628 [ "$LIST" ] || cat $tmp/cooklist > $cooklist
629 fi
630 }
632 # Check $COOK_OPT; usage : get_cookopt particular_opt
633 # Return error if not found
634 # Return args if the opt is in the format opt=arg1:arg2:etc
635 look_for_cookopt()
636 {
637 for arg in $COOK_OPT; do
638 case $arg in
639 $1=*)
640 arg=${arg#$1=}
641 while [ "$arg" ]; do
642 echo "${arg%%:*}"
643 [ "${arg/:}" = "$arg" ] && return
644 arg=${arg#*:}
645 done
646 ;;
647 $1)
648 return
649 ;;
650 esac
651 done
652 return 1
653 }
655 check_for_incoming()
656 {
657 echo "Checking that all packages were cooked OK"
658 [ -s $INCOMING/packages.desc ] || {
659 echo "No packages in $INCOMING."
660 return; }
661 if [ -s $broken ]; then
662 missingpkg=$(look_for_missing_pkg $broken)
663 if [ "$missingpkg" ]; then
664 echo "Don't move incoming packages to main repository because these ones are broken:" >&2
665 echo "$missingpkg"
666 return 1
667 fi
668 fi
669 if [ -s $cooklist ]; then
670 missingpkg=$(look_for_missing_pkg $cooklist)
671 if [ "$missingpkg" ]; then
672 echo "Don't move incoming packages to main repository because these ones need to be cooked:" >&2
673 echo "$missingpkg"
674 return 1
675 fi
676 fi
677 incoming_pkgs="$(cut -f 1 -d '|' $INCOMING/packages.desc)"
678 if ! [ "$forced" ]; then
679 cooklist=$CACHE/cooklist
680 pkg="$incoming_pkgs"
681 gen_cook_list
682 if [ -s $cooklist ]; then
683 missingpkg=$(look_for_missing_pkg $cooklist)
684 if [ "$missingpkg" ]; then
685 echo "Don't move incoming packages to main repository because these ones need to be cooked:" >&2
686 echo "$missingpkg"
687 return 1
688 fi
689 fi
690 fi
692 echo "Moving incoming packages to main repository"
693 unset EXTRAVERSION
694 for PACKAGE in $incoming_pkgs; do
695 prev_VERSION=$(get_pkg_version $PKGS)
696 VERSION=$(get_pkg_version $INCOMING)
697 if [ -f $INCOMING/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg ]; then
698 remove_previous_package $PKGS
699 echo "Moving $PACKAGE..."
700 mv -f $INCOMING/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg $PKGS
701 touch $PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
702 else
703 echo "$PACKAGE doesn't exist"
704 fi
705 if [ "$AUTO_PURGE_SRC" ]; then
706 previous_tarball=$(grep ^$PACKAGE:main $SRC/sources.list | cut -f2)
707 sed -e "/^$PACKAGE:main/d" \
708 -e "s/^$PACKAGE:incoming/$PACKAGE:main/" \
709 -i $SRC/sources.list
710 if [ "$previous_tarball" ]; then
711 grep -q $'\t'$previous_tarball$ $SRC/sources.list || \
712 rm -f $SRC/$previous_tarball
713 fi
714 fi
715 done
716 for file in packages.list packages.equiv packages.md5 packages.desc \
717 packages.txt; do
718 echo -n "" > $INCOMING/$file
719 done
720 [ -f "$INCOMING/files.list.lzma" ] && rm -r $INCOMING/files.list.lzma
721 pkg_repository=$PKGS && gen_packages_db
723 }
725 # help gen sources.list file from scranch
726 gen_sources_list()
727 {
728 local src_repository=$1
729 [ -f $src_repository/sources.list ] && rm -f $src_repository/sources.list
730 for i in $WOK/*; do
731 unset PACKAGE SOURCE KBASEVER VERSION WGET_URL TARBALL WANTED
732 [ -f $i/receipt ] && source $i/receipt
733 [ "$WGET_URL" ] || continue
734 if grep -q "^$PACKAGE | $VERSION" $PKGS/packages.desc; then
735 main_version="$VERSION"
736 if [ -f $src_repository/${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}.tar.lzma ]; then
737 echo -e "$PACKAGE:main\t${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}.tar.lzma" >> $src_repository/sources.list
738 elif [ -f "$src_repository/$TARBALL" ]; then
739 echo -e "$PACKAGE:main\t$TARBALL" >> $src_repository/sources.list
740 fi
741 else
742 # May not works if package use extraversion.
743 main_version=$(grep -m1 -A1 -sh ^$PACKAGE$ $PKGS/packages.txt | tail -1 | sed 's/ *//')
744 if [ -f $src_repository/${SOURCE:-$PACKAGE}-${KBASEVER:-$main_version}.tar.lzma ]; then
745 echo -e "$PACKAGE:main\t${SOURCE:-$PACKAGE}-${KBASEVER:-$main_version}.tar.lzma" >> $src_repository/sources.list
746 else
747 unset main_version
748 fi
749 fi
750 if [ ! "$main_version" ] || [ $(grep -q "^$PACKAGE | $VERSION" $INCOMING/packages.desc 2>/dev/null) ]; then
751 if [ -f $src_repository/${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}.tar.lzma ]; then
752 echo -e "$PACKAGE:incoming\t${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}.tar.lzma" >> $src_repository/sources.list
753 elif [ -f "$src_repository/$TARBALL" ]; then
754 echo -e "$PACKAGE:incoming\t$TARBALL" >> $src_repository/sources.list
755 fi
756 fi
757 done
758 }
760 get_pkg_files()
761 {
762 pkg_files_dir=/tmp/cook/$(basename ${1%.tazpkg})
763 mkdir -p $pkg_files_dir && \
764 cd $pkg_files_dir && \
765 cpio --quiet -idm receipt < $1 2>/dev/null && \
766 cpio --quiet -idm files.list < $1 2>/dev/null && \
767 cpio --quiet -idm library.list < $1 2>/dev/null
768 }
770 check_so_files()
771 {
772 pwd=$(pwd)
773 for rep in $PKGS $INCOMING; do
774 prev_VERSION=$(get_pkg_version $rep)
775 [ "$prev_VERSION" ] && pkg_file=$rep/$PACKAGE-$prev_VERSION.tazpkg && break
776 done
777 if [ "$pkg_file" ]; then
778 gettext -e "Looking for major/minor updates in libraries\n"
779 get_pkg_files $pkg_file
780 if [ -d $WOK/$PACKAGE/taz/$PACKAGE-${VERSION}${EXTRAVERSION} ]; then
781 cd $WOK/$PACKAGE/taz/$PACKAGE-${VERSION}${EXTRAVERSION}
782 else
783 cd $WOK/$PACKAGE/taz/$PACKAGE-$VERSION
784 fi
786 pkg_to_check=$(diff $pkg_files_dir/files.list files.list | \
787 grep '^-/.*\.so' | while read lib; do
788 pkg=$(fgrep " ${lib##*/} " $lib_db | cut -f1)
789 for i in $pkg; do
790 [ -f $WOK/$i/receipt ] || continue
791 wanted=$(grep ^WANTED= $WOK/$i/receipt | cut -d "=" -f2 | sed -e 's/"//g')
792 if [ "$wanted" ]; then
793 echo $wanted
794 else
795 echo $i
796 fi
797 done
798 done | sort -u)
800 if [ "$pkg_to_check" ]; then
801 for rdep in $(scan $PACKAGE --look_for=rdep | use_wanted); do
802 echo "$pkg_to_check" | grep -q ^$rdep$ || continue
803 [ "$rdep" = "${WANTED:-$PACKAGE}" ] && continue
804 grep -q ^$rdep$ $blocked $cooklist && continue
805 echo "Plan to recook $rdep"
806 echo $rdep >> $cooklist
807 regen_cooklist=yes
808 done
809 fi
810 update_lib_db
811 rm -r $pkg_files_dir
812 unset pkg_file pkg_file_dir pkg_to_check
813 cd $pwd
814 else
815 if [ -d $WOK/$PACKAGE/taz/$PACKAGE-${VERSION}${EXTRAVERSION} ]; then
816 cd $WOK/$PACKAGE/taz/$PACKAGE-${VERSION}${EXTRAVERSION}
817 else
818 cd $WOK/$PACKAGE/taz/$PACKAGE-$VERSION
819 fi
820 update_lib_db
821 cd $pwd
822 fi
823 }
825 check_recook_rdeps()
826 {
827 # Recook of reverse-depends if package was broken.
828 if grep -q "^$PACKAGE$" $broken; then
829 echo "Planning a re-try cook of reverse depends"
830 sed "/^$PACKAGE$/d" -i $broken
831 for rdep in $(look_for_rdep); do
832 grep -q "^$rdep$" $broken || continue
833 grep -q "^$rdep$" $cooklist && continue
834 echo "Adding $rdep to the cooklist"
835 echo $rdep >> $cooklist
836 regen_cooklist=t
837 done
838 fi
839 sed "/^$PACKAGE$/d" -i $commits
840 sed "/^$PACKAGE$/d" -i $cooklist
841 }
843 remove_src()
844 {
845 [ "$WANTED" ] && return
846 look_for_cookopt !remove_src && return
848 # Don't remove sources if a package uses src variable in its
849 # genpkg_rules: it maybe needs something inside.
850 for i in $PACKAGE $(look_for_rwanted); do
851 sed -n '/^genpkg_rules\(\)/','/^}/'p $WOK/$i/receipt | \
852 fgrep -q '$src' && gettext -e "Sources will not be removed \
853 because $i uses \$src in its receipt.\n" && return
854 done
856 gettext -e "Removing sources directory"
857 echo ""
858 rm -fr "$src"
859 [ -d $WOK/$PACKAGE/source ] && rm -rf $WOK/$PACKAGE/source
860 }
862 check_for_var_modification()
863 {
864 for var in $@; do
865 for pkg in $PACKAGE $(look_for_wanted) $(look_for_rwanted); do
866 [ -f $WOK/$pkg/receipt ] || continue
867 fgrep -q "$var=" $WOK/$pkg/receipt && return 1
868 done
869 done
871 # Tweak to make if; then...; fi function working with this one.
872 echo -n ""
873 }
875 clean()
876 {
877 cd $WOK/$PACKAGE
878 ls -A $WOK/$PACKAGE | grep -q -v -e ^receipt$ -e ^description.txt$ \
879 -e ^stuff$ || return
881 [ "$COMMAND" = clean-wok ] || echo "Cleaning $PACKAGE"
882 # Check for clean_wok function.
883 if grep -q ^clean_wok $RECEIPT; then
884 clean_wok
885 fi
886 # Clean should only have a receipt, stuff and optionals desc/md5.
887 for f in `ls .`
888 do
889 case $f in
890 receipt|stuff|description.txt|md5)
891 continue ;;
892 *)
893 rm -rf $f ;;
894 esac
895 done
896 }
898 set_pkg_broken()
899 {
900 grep -q ^$PACKAGE$ $broken || echo $PACKAGE >> $broken
902 # Remove pkg from cooklist to avoid re-cook it if no changes happen
903 # in the cook stuff.
904 sed "/^$PACKAGE$/d" -i $cooklist $commits
906 gen_cookmd5
908 # Return 1 to make report know that its mother-function failed.
909 return 1
910 }
912 # Log broken packages.
913 broken() {
914 unset cook_code
915 for PACKAGE in $(look_for_wanted) $PACKAGE; do
916 set_pkg_broken
917 done
918 cook_code=1
919 }
921 packages_db_start()
922 {
923 if [ ! -s packages.txt ]; then
924 echo "# SliTaz GNU/Linux - Packages list
925 #
926 # Packages : unknown
927 # Date : $(date +%Y-%m-%d\ \%H:%M:%S)
928 #
929 " > packages.txt
930 else
931 sed -e 's/^# Packages :.*/# Packages : unknown/' \
932 -e "s/# Date :.*/# Date : $(date +%Y-%m-%d\ \%H:%M:%S)/" \
933 -i packages.txt
934 fi
936 # If $packages_repository is the main one, configure few functions
937 # to act as they should, without having loop on them (speed-up)
938 if [ "$pkg_repository" = "$PKGS" ]; then
939 erase_package_info_extracmd="erase_package_info_main"
940 get_packages_info_extracmd="get_packages_info_main"
941 fi
942 }
944 erase_package_info()
945 {
946 cd $pkg_repository
947 sed "/^$PACKAGE$/,/^$/d" -i packages.txt
948 sed "/^$PACKAGE /d" -i packages.desc
949 sed -e "s/=$PACKAGE /= /" -e "s/ $PACKAGE / /" -e "s/ $PACKAGE$//" \
950 -e "/=$PACKAGE$/d" -e "s/=[0-9,a-z,A-Z]:$PACKAGE /= /" \
951 -e "s/ [0-9,a-z,A-Z]:$PACKAGE / /" -e "s/ [0-9,a-z,A-Z]:$PACKAGE$/ /" \
952 -e "/=[0-9,a-z,A-Z]:$PACKAGE$/d" \
953 -i packages.equiv
954 sed "/^$PACKAGE:/d" -i files.list
955 sed "/^$(basename ${pkg%.tazpkg})$/d" -i packages.list
956 sed "/ $(basename $pkg)$/d" -i packages.$SUM
957 $erase_package_info_extracmd
958 }
960 packages_db_end()
961 {
962 cd $pkg_repository
963 pkgs=$(wc -l packages.list | sed 's/ .*//')
964 sed "s/# Packages : .*/# Packages : $pkgs/" -i packages.txt
966 # If lists were updated it's generally needed to sort them well.
967 echo "Sorting packages lists"
968 files_list="packages.list packages.desc packages.equiv wanted.txt depends.txt libraries.txt"
969 for file in $files_list; do
970 [ -f $file ] || continue
971 sort -o $file $file
972 done
974 $CHECKSUM packages.$SUM | cut -f1 -d' ' > ID
975 [ -s ID ] || echo null > ID
977 # Dont log this because lzma always output errors.
978 lzma e files.list files.list.lzma
979 rm -f files.list
980 [ -f packages.equiv ] || touch packages.equiv
981 }
983 get_packages_info()
984 {
985 # If there's no taz folder in the wok, extract info from the
986 # package.
987 get_pkg_files $pkg
988 unset_receipt
989 . $pkg_files_dir/receipt
991 #[ "$COMMAND" = "check-incoming" ] && gettext -e "Getting data from ${PACKAGE} \n"
993 cat >> $pkg_repository/packages.txt << _EOT_
994 $PACKAGE
995 $VERSION$EXTRAVERSION
996 $SHORT_DESC
997 _EOT_
998 if [ "$PACKED_SIZE" ]; then
999 cat >> $pkg_repository/packages.txt << _EOT_
1000 $PACKED_SIZE ($UNPACKED_SIZE installed)
1002 _EOT_
1003 else
1004 echo "" >> $pkg_repository/packages.txt
1005 fi
1007 # Packages.desc is used by Tazpkgbox <tree>.
1008 echo "$PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> $pkg_repository/packages.desc
1010 # Packages.equiv is used by tazpkg install to check depends.
1011 for i in $PROVIDE; do
1012 DEST=""
1013 echo $i | fgrep -q : && DEST="${i#*:}:"
1014 if grep -qs ^${i%:*}= $pkg_repository/packages.equiv; then
1015 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" $pkg_repository/packages.equiv
1016 else
1017 echo "${i%:*}=$DEST$PACKAGE" >> $pkg_repository/packages.equiv
1018 fi
1019 done
1021 if [ -f files.list ]; then
1022 { echo "$PACKAGE"; cat files.list; } | awk '
1023 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }' >> $pkg_repository/files.list
1024 fi
1026 if [ -f library.list ]; then
1027 sed "/^$PACKAGE\t/d" -i $pkg_repository/libraries.txt
1028 cat library.list >> $pkg_repository/libraries.txt
1029 fi
1031 cd .. && rm -r "$pkg_files_dir"
1033 cd $pkg_repository
1034 echo $(basename ${pkg%.tazpkg}) >> packages.list
1035 $CHECKSUM $(basename $pkg) >> packages.$SUM
1036 $get_packages_info_extracmd
1039 gen_packages_db()
1041 [ "$pkg_repository" ] || pkg_repository=$PKGS
1042 cd $pkg_repository
1043 gettext -e "Generating packages lists: $pkg_repository\n"
1044 gettext -e "Removing old files\n"
1045 for file in files.list.lzma packages.list packages.txt \
1046 packages.desc packages.equiv packages.$SUM; do
1047 [ -f $file ] && rm $file
1048 done
1049 touch files.list
1050 [ -f libraries.txt ] && rm -f libraries.txt
1051 if [ "$pkg_repository" == "$INCOMING" ]; then
1052 if [ -f "$PKGS/libraries.txt" ]; then
1053 cp -a $PKGS/libraries.txt $INCOMING/libraries.txt
1054 fi
1055 fi
1056 touch libraries.txt
1057 touch depends.txt
1058 touch wanted.txt
1060 packages_db_start
1061 unset_receipt
1062 gettext -e "Reading data from all packages\n"
1063 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1064 get_packages_info
1065 done
1066 packages_db_end
1069 update_packages_db()
1071 [ "$pkg_repository" ] || pkg_repository=$PKGS
1072 cd $pkg_repository
1073 for file in packages.list packages.equiv packages.$SUM \
1074 packages.desc packages.txt; do
1075 if [ ! -f "$file" ]; then
1076 gen_packages_db
1077 return
1078 fi
1079 done
1080 if [ -f files.list.lzma ]; then
1081 lzma d files.list.lzma files.list
1082 else
1083 gen_packages_db
1084 return
1085 fi
1086 gettext -e "Updating packages lists: $pkg_repository\n"
1087 echo ""
1088 packages_db_start
1090 # Look for removed/update packages.
1091 touch stamp -r packages.list
1092 for PACKAGE in $(grep ^[0-9,a-z,A-Z] packages.txt); do
1093 pkg="$pkg_repository/$(grep -m1 ^$PACKAGE- packages.list).tazpkg"
1094 if [ ! -f "$pkg" ]; then
1095 erase_package_info
1096 else
1097 if [ "$pkg" -nt "stamp" ]; then
1098 updated_pkg="$updated_pkg
1099 $PACKAGE $pkg"
1100 elif [ ! -f $WOK/$PACKAGE/receipt ] && \
1101 [ "$COMMAND" = check-incoming -o "$pkg_repository" = "$INCOMING" ]; then
1102 erase_package_info
1103 gettext -e "Removing $PACKAGE from $pkg_repository.\n"
1104 rm $pkg
1105 if [ "$pkg_repository" = "$INCOMING_REPOSITORY" ]; then
1106 [ -d $WOK/$PACKAGE ] && rm -r $WOK/$PACKAGE
1107 sed "/^$PACKAGE\t/d" -i $wan_db $dep_db
1108 for i in $fullco $cookorder $cooklist $commits $blocked $broken; do
1109 sed "/^$PACKAGE$/d" -i $i
1110 done
1111 [ -f $LOGS/$pkg.log ] && rm -f $LOGS/$pkg.log
1112 if [ "$(sed 1!d $fullco)" != "#PlanSort" ]; then
1113 sed 1i"#PlanSort" -i $fullco
1114 regen_cooklist=yes
1115 fi
1116 else
1117 echo "$PACKAGE" >> $CACHE/removed
1118 sed -n '1,10p' -i $CACHE/removed
1119 fi
1120 fi
1121 fi
1122 done
1123 rm stamp
1124 echo "$updated_pkg" | sed 1d | while read PACKAGE pkg; do
1125 erase_package_info
1126 get_packages_info
1127 done
1128 unset updated_pkg
1130 # Look for new packages.
1131 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1132 if ! fgrep -q " ${pkg##*/}" packages.$SUM; then
1133 get_packages_info
1134 fi
1135 done
1136 packages_db_end
1139 pkgdb()
1141 case "$1" in
1142 incoming)
1143 PKGSDB="incoming" ;;
1144 packages)
1145 PKGSDB="packages" ;;
1146 *)
1147 [ "$1" ] && PKGSDB="$1"
1148 [ ! -d "$PKGSDB" ] && \
1149 gettext -e "\nPackages directory doesn't exist\n\n" && exit 1 ;;
1150 esac
1151 time=$(date +%s)
1152 echo "cook:pkgdb" > $command
1153 echo "Cook pkgdb: Creating all packages lists" | log
1154 echo ""
1155 gettext "Creating lists for: "; echo "$PKGSDB"
1156 separator
1157 gettext "Cook pkgdb started: "; date "+%Y-%m-%d %H:%M"
1158 if [ "$PKGSDB" = packages ]; then
1159 # Packages package db
1160 pkg_repository=$PKGS && gen_packages_db
1161 nb=$(ls $PKGS/*.tazpkg | wc -l)
1162 time=$(($(date +%s) - $time))
1163 echo -e "Packages: $nb - Time: ${time}s\n"
1164 elif [ "$PKGSDB" = incoming ]; then
1165 # Incoming package db
1166 pkg_repository=$INCOMING && gen_packages_db
1167 nb=$(ls $INCOMING/*.tazpkg | wc -l)
1168 time=$(($(date +%s) - $time))
1169 echo -e "Packages: $nb - Time: ${time}s\n"
1170 elif [ -d "$PKGSDB" ]; then
1171 # User path for package db
1172 pkg_repository=$PKGSDB && gen_packages_db
1173 nb=$(ls $PKGSDB/*.tazpkg | wc -l)
1174 time=$(($(date +%s) - $time))
1175 echo -e "Packages: $nb - Time: ${time}s\n"
1176 else
1177 pkg_repository=$PKGS && gen_packages_db
1178 nb=$(ls $PKGS/*.tazpkg | wc -l)
1179 time=$(($(date +%s) - $time))
1180 echo -e "Packages: $nb - Time: ${time}s\n"
1181 pkg_repository=$INCOMING && gen_packages_db
1182 incoming_nb=$(ls $INCOMING/*.tazpkg | wc -l)
1183 time=$(($(date +%s) - $time))
1184 echo -e "Incoming: $incoming_nb - Time: ${time}s\n"
1185 fi
1187 echo "" && rm -f $command
1190 clean_chroot()
1192 # Remove packages which was not in the chroot at creation time.
1193 if [ -f "$CACHE/chroot-pkgs" ]; then
1194 for pkg in $(ls ${root}${INSTALLED}); do
1195 [ -f ${root}${INSTALLED}/$pkg/receipt ] || continue
1196 [ "$(grep ^$pkg$ $CACHE/chroot-pkgs)" ] || tazpkg remove $pkg --auto --root=$root
1197 done
1199 for pkg in $(ls ${root}${INSTALLED}); do
1200 if [ -d ${root}${INSTALLED}/$pkg -a ! -f ${root}${INSTALLED}/$pkg/receipt ]; then
1201 echo "empty: $pkg"
1202 rm -rf ${root}${INSTALLED}/$pkg
1203 fi
1204 done
1206 for pkg in $(cat $CACHE/chroot-pkgs); do
1207 if [ ! -d ${root}${INSTALLED}/$pkg ]; then
1208 echo "Reinstalling $pkg"
1209 tazpkg get-install $pkg --root=$root --forced
1210 fi
1211 done
1212 fi
1215 update_lib_db()
1217 # Update lib_db
1218 libs=$(for file in $(find * -type f -not -name "*.o" -not -name "*.ko" -not -name "*.a"); do
1219 [ "$(dd if=$file bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ] || continue
1220 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $PWD/$file
1221 done | { cut -f 1 -d ' ' | tr -d '\t' | sort -u | \
1222 sed -e 's/^linux-gate.so.*$/SLIB/' -e 's~^/lib/ld-.*$~SLIB~' \
1223 -e '/^statically$/d' | tr '\n' ' '; })
1225 if [ "$libs" ]; then
1226 libs=$(echo " $libs" | sed -r 's/( SLIB)+ / /g')
1227 echo -e "$PACKAGE\t$libs" >> $lib_db
1228 sort -o $lib_db $lib_db
1229 echo -e "$PACKAGE\t$libs" >> library.list
1230 sort -o library.list library.list
1231 fi
1232 unset libs
1235 # Check for a specified file list on cmdline.
1236 check_for_list()
1238 if [ ! "$LIST" ]; then
1239 echo -e "\nPlease specify the path to the list of packages to cook.\n" >&2
1240 exit 1
1241 elif ! [ -f "$LIST" ]; then
1242 echo -e "\nUnable to find $LIST packages list.\n" >&2
1243 exit 1
1244 elif ! [ -s "$LIST" ]; then
1245 echo -e "\nList is empty.\n" >&2
1246 exit 1
1247 fi
1250 get_packages_info_main()
1252 erase_package_info_main
1253 [ "$WANTED" ] && echo -e "$PACKAGE\t$WANTED" >> wanted.txt
1254 echo -e "$PACKAGE\t "$DEPENDS" \t "$BUILD_DEPENDS" " >> depends.txt
1257 erase_package_info_main()
1259 for i in wanted.txt depends.txt; do
1260 [ -f $i ] || continue
1261 sed "/^$PACKAGE\t/d" -i $i
1262 done