tazwok view tazwok @ rev 451

tazwok: ensure repository ID is up-to-date after a cook command
author Antoine Bodin <gokhlayeh@slitaz.org>
date Tue Mar 15 05:47:21 2011 +0100 (2011-03-15)
parents 10a0f496be28
children 954023be2d07
line source
1 #!/bin/sh
2 # Tazwok - SliTaz source compiler and binary packages generator/cooker.
3 #
4 # Tazwok can compile source packages and create binary packages suitable for
5 # Tazpkg (Tiny Autonomous zone package manager). You can build individual
6 # packages or a list of packages with one command, rebuild the full distro,
7 # generate a packages repository and also list and get info about packages.
8 #
9 # (C) 2007-2009 SliTaz - GNU General Public License.
10 #
12 VERSION=4.3
13 . /usr/lib/slitaz/libtaz
14 source_lib commons
16 # Use text instead of numbers, don't get $2 here if it's an option.
17 [ "$2" = "${2#--}" ] && PACKAGE=$2 && LIST=$2 && ARG=$2
18 COMMAND=$1
20 ########################################################################
21 # TAZWOK USAGE
22 ########################
23 # Print the usage (English).
25 usage()
26 {
27 echo -e "\nSliTaz sources compiler and packages generator - Version: $VERSION\n
28 \033[1mUsage: \033[0m `basename $0` [command] [package|list|category|dir|id] [--option]
29 \033[1mCommands: \033[0m\n
30 usage Print this short usage.
31 stats Print Tazwok statistics from the config file and the wok.
32 edit Edit a package receipt in the current wok.
33 build-depends Generate a list of packages to build a wok.
34 list List all packages in the wok tree or by category.
35 info Get information about a package in the wok.
36 report Display commit/cooklist/broken/blocked.
37 check Check every receipt for common errors.
38 check-log Check the process log file of a package.
39 check-depends* Check every receipt for DEPENDS - doesn't scan ELF files.
40 check-src Check upstream tarball for package in the wok.
41 search Search for a package in the wok by pattern or name.
42 compile Configure and build a package using the receipt rules.
43 genpkg Generate a suitable package for Tazpkg with the rules.
44 cook Compile and generate a package directly.
45 cook-list Cook all packages specified in the list by order.
46 cook-commit Cook all modified receipts.
47 cook-all Cook all packages except toolchain.
48 cook-toolchain Cook the toolchain packages.
49 gen-cooklist Generate a sorted cooklist using packages or list.
50 sort-cooklist Sort the cooklist given in argument.
51 get-src Download the tarball of the package given in argument.
52 clean Clean all generated files in the package tree.
53 new-tree Prepare a new package tree and receipt (--interactive).
54 gen-list (Re-)Generate a packages list for a repository.
55 check-list Update packages lists for a repository.
56 gen-wok-db (Re-)Generate wok lists with depends and wanted data.
57 gen-clean-wok Generate a clean wok in a dir.
58 clean-wok Clean entirely the wok.
59 clean-src Remove old/unrelated-to-wok sources.
60 remove Remove a package from the wok.
61 webserver Enable/disable webserver on localhost.
62 update-wok Update the wok.
63 maintainers List all maintainers in the wok.
64 maintained-by List packages maintained by a contributor.
65 tags List all tags used in wok receipts.
66 block Add package from the blocked list to prevent cooking it.
67 unblock Remove package from the blocked list.\n
69 You can use `basename $0` command --help to list available options.
70 \033[1mImportant - *: \033[0m Commands which need a rewrite."
71 }
73 # This function displays an error message without returning any error code.
74 # It also logs the message in source package's warnings.txt; this file can be
75 # used on an eventual package page on website to display cooking warnings.
76 tazwok_warning()
77 {
78 echo -e "tazwok: $1" >&2
79 echo -e "$1" >> $WOK/${WANTED:-$PACKAGE}/warning.txt
80 return
81 }
83 ########################################################################
84 # TAZWOK VARIABLES & INITIAL CONFIGURATION
85 ########################
87 # Check if all packages are up to date into build environnement
88 check_env_status()
89 {
90 { [ "${COMMAND#cook}" = "$COMMAND" ] || \
91 [ "$COMMAND" = cook-toolchain ] ; } && return
92 MIRROR_path=$(grep -l "^$1$" $LOCALSTATE/mirror $LOCALSTATE/undigest/*/mirror)
94 if [ ! "$MIRROR_path" ]; then
95 echo "You are trying to cook something but you don't use $1 repository, which is \
96 needed for this operation." | fold -s >&2
97 exit 1
98 fi
100 LOCALSTATE_path=${MIRROR_path%/mirror}
102 # Check is possible only if repository use ID.
103 if [ "${MIRROR_path:0:1}" = '/' ]; then
104 [ -f "$MIRROR_path/ID" ] || return
105 else
106 wget -a -s $MIRROR_path/ID 2>/dev/null || return
107 fi
109 [ -f $LOCALSTATE_path/ID ] && ID=$(cat $LOCALSATE_path/ID)
111 if [ "$LOCALSTATE_path" = "$LOCALSTATE" ]; then
112 tazpkg recharge main
113 else
114 tazpkg recharge ${LOCALSTATE_path##*/}
115 fi
117 [ "$(cat $LOCALSTATE_path/ID)" = "$ID" ] || env_status=1
118 }
120 get_tazwok_config()
121 {
122 # Get configuration file.
123 get_config
125 # Define & get options.
126 get_options_list="$get_options_list SLITAZ_DIR SLITAZ_VERSION undigest"
127 get_options
129 LOCAL_REPOSITORY=$SLITAZ_DIR/${undigest:-$SLITAZ_VERSION}
131 if ! [ "$save_dir" ]; then
132 if [ -f $LOCAL_REPOSITORY/tazwok.conf ] || [ -f $LOCAL_REPOSITORY/slitaz.conf ]; then
133 save_dir=$LOCAL_REPOSITORY
134 [ -f $LOCAL_REPOSITORY/slitaz.conf ] && source $LOCAL_REPOSITORY/slitaz.conf
135 cd $save_dir
136 get_tazwok_config
137 unset save_dir
138 return
139 fi
140 fi
142 set_common_path
144 # Check that packages are up to date if user intend to cook.
145 check_env_status ${USE_ONLINE_PKG:-$PACKAGES_REPOSITORY}
146 check_env_status $INCOMING_REPOSITORY
148 # In case undigest is used, we need to upgrade system.
149 if [ "$undigest" ]; then
150 use_undigest_scan_core
151 ref_PACKAGES_REPOSITORY=$SLITAZ_DIR/$SLITAZ_VERSION/packages
152 if [ -f $SLITAZ_DIR/$SLITAZ_VERSION/tazwok.conf ] && \
153 grep -q ^USE_ONLINE_PKG $SLITAZ_DIR/$SLITAZ_VERSION/tazwok.conf; then
154 ref_USE_ONLINE_PKG=$(source $SLITAZ_DIR/$SLITAZ_VERSION/tazwok.conf && \
155 echo $USE_ONLINE_PKG)
156 fi
158 check_env_status ${ref_USE_ONLINE_PKG:-$ref_PACKAGES_REPOSITORY}
159 cd $ref_PACKAGES_REPOSITORY
160 if [ "$ref_USE_ONLINE_PKG" ]; then
161 ref_dep_db=$LOCALSTATE_path/wok-depends.txt
162 ref_wan_db=$LOCALSTATE_path/wok-wanted.txt
163 ref_lib_db=$LOCALSTATE_path/libraries.txt
164 else
165 ref_dep_db=$ref_PACKAGES_REPOSITORY/wok-depends.txt
166 ref_wan_db=$ref_PACKAGES_REPOSITORY/wok-wanted.txt
167 ref_lib_db=$ref_PACKAGES_REPOSITORY/libraries.txt
168 fi
170 for file in $ref_dep_db $ref_wan_db $ref_lib_db; do
171 [ -f "$file" ] && continue
172 missing_file=t
173 echo "$file is missing." >&2
174 done
175 if [ "$missing_file" ]; then
176 echo "
177 Theses files are needed to get datas about packages from the reference repository $SLITAZ_VERSION. \
178 If you don't intend to build this reference repository yourself, you should set USE_ONLINE_PKG variable \
179 into tazwok.conf of this reference repository. How-to:" | fold -s >&2
180 echo "echo 'USE_ONLINE_PKG=\"packages_repository_url\"' >> $SLITAZ_DIR/$SLITAZ_VERSION/tazwok.conf"
181 echo ""
182 exit 1
183 fi
184 fi
186 # If $env_status exists, it means an upgrade may be needed.
187 if [ "$env_status" ]; then
188 if [ -x /usr/bin/clean-chroot ]; then
189 echo y | tazpkg upgrade
190 else
191 echo "\e[0;31mWarning: \e[m"
192 echo "You're environnement may need a package upgrade."
193 echo "Upgrading is highly recommanded to ensure repository consistency."
194 echo "You can (E)xit, (U)pgrade, or (C)ontinue."
195 echo -n "What do you want to do ?"
196 read answer
197 case $answer in
198 [Cc]*) ;;
199 [Uu]*) echo y | tazpkg upgrade ;;
200 *) exit
201 esac
202 fi
203 fi
205 # Check commons directories, create them if user is root.
206 if test $(id -u) = 0 ; then
207 check_dir $WOK || chmod 777 $WOK
208 check_dir $LOCAL_REPOSITORY/clean-wok || chmod 777 $LOCAL_REPOSITORY/clean-wok
209 check_dir $PACKAGES_REPOSITORY
210 check_dir $SOURCES_REPOSITORY
211 check_dir $INCOMING_REPOSITORY
212 check_dir $LOCAL_REPOSITORY/log
213 for file in $dep_db $wan_db $cookorder $commit $cooklist \
214 $broken $blocked $SOURCES_REPOSITORY/sources.list $lib_db
215 do
216 [ -f $file ] || touch $file
217 done
218 fi
220 # Limit memory usage.
221 ulimit -v $(awk '/MemTotal|SwapTotal/ { n+=$2 } END { print int((n*80)/100) }' < /proc/meminfo)
222 }
224 # The path to the most important files/dir used by Tazwok.
225 set_common_path()
226 {
227 PACKAGES_REPOSITORY=$LOCAL_REPOSITORY/packages
228 WOK=$LOCAL_REPOSITORY/wok
229 INCOMING_REPOSITORY=$LOCAL_REPOSITORY/packages-incoming
230 SOURCES_REPOSITORY=$LOCAL_REPOSITORY/src
231 RECEIPT="$WOK/$PACKAGE/receipt"
232 LOG="$WOK/$PACKAGE/process.log"
233 dep_db=$INCOMING_REPOSITORY/wok-depends.txt
234 wan_db=$INCOMING_REPOSITORY/wok-wanted.txt
235 lib_db=$INCOMING_REPOSITORY/libraries.txt
236 cookorder=$PACKAGES_REPOSITORY/cookorder.txt
237 commit=$PACKAGES_REPOSITORY/commit
238 cooklist=$PACKAGES_REPOSITORY/cooklist
239 broken=$PACKAGES_REPOSITORY/broken
240 blocked=$PACKAGES_REPOSITORY/blocked
242 # log steps for webserver.
243 log_step="$LOCAL_REPOSITORY/log/step"
244 run_on_exit="$run_on_exit
245 rm -f $LOCAL_REPOSITORY/log/step
246 rm -f $LOCAL_REPOSITORY/log/package"
247 }
249 ########################################################################
250 # TAZWOK CHECK FUNCTIONS
251 ########################
253 # Check for a package name on cmdline.
254 check_for_package_on_cmdline()
255 {
256 if [ ! "$PACKAGE" ]; then
257 echo -e "\nYou must specify a package name on the command line." >&2
258 echo -e "Example : tazwok $COMMAND package\n" >&2
259 exit 1
260 fi
261 }
263 # Check for the receipt of a package used to cook.
264 check_for_receipt()
265 {
266 if [ ! -f "$RECEIPT" ]; then
267 echo -e "\nUnable to find the receipt : $RECEIPT\n" >&2
268 exit 1
269 fi
270 }
272 # Check for a specified file list on cmdline.
273 check_for_list()
274 {
275 if [ ! "$LIST" ]; then
276 echo -e "\nPlease specify the path to the list of packages to cook.\n" >&2
277 exit 1
278 elif ! [ -f "$LIST" ]; then
279 echo -e "\nUnable to find $LIST packages list.\n" >&2
280 exit 1
281 elif ! [ -s "$LIST" ]; then
282 echo -e "\nList is empty.\n" >&2
283 exit 1
284 fi
285 }
287 ########################################################################
288 # TAZWOK CORE FUNCTIONS
289 ########################
291 remove_src()
292 {
293 [ "$WANTED" ] && return
294 look_for_cookopt !remove_src && return
295 if [ ! -d $WOK/$PACKAGE/install ] && [ "$src" ] && [ -d "$src/_pkg" ]; then
296 check_for_var_modification _pkg src || return
297 mv "$src/_pkg" $WOK/$PACKAGE/install
298 fi
300 # Don't remove sources if a package uses src variable in its
301 # genpkg_rules: it maybe needs something inside.
302 for i in $PACKAGE $(look_for_rwanted); do
303 sed -n '/^genpkg_rules\(\)/','/}/'p $WOK/$i/receipt | \
304 fgrep -q '$src' && tazwok_warning "Sources will not be removed \
305 because $i uses \$src in its receipt." && return
306 done
308 report step "Removing sources directory"
309 rm -fr "$src"
310 report end-step
311 }
313 # Check $COOK_OPT; usage : get_cookopt particular_opt
314 # Return error if not found
315 # Return args if the opt is in the format opt=arg1:arg2:etc
316 look_for_cookopt()
317 {
318 for arg in $COOK_OPT; do
319 case $arg in
320 $1=*)
321 arg=${arg#$1=}
322 while [ "$arg" ]; do
323 echo "${arg%%:*}"
324 [ "${arg/:}" = "$arg" ] && return
325 arg=${arg#*:}
326 done
327 ;;
328 $1)
329 return
330 ;;
331 esac
332 done
333 return 1
334 }
336 # Check for the wanted package if specified in WANTED
337 # receipt variable. Set the $src/$_pkg variable to help compile
338 # and generate packages.
339 check_for_wanted()
340 {
341 if [ "$WANTED" ]; then
342 report "Checking for the wanted package"
343 if [ ! -d "$WOK/$WANTED" ]; then
344 report exit "\nWanted package is missing in the work directory.\n"
345 fi
347 # Checking for buildtree of Wanted package
348 if [ ! -d "$WOK/$WANTED/taz" ]; then
349 echo -e "\n\nSource files of wanted package is missing in the work directory."
350 echo -n "Would you like to build the missing package (y/N) ? " ; read anser
351 if [ "$anser" == "y" ]; then
352 tazwok cook $WANTED
353 else
354 report exit "\nWanted package source tree is missing in the work directory.\n"
355 fi
356 fi
357 report end-step
359 # Set wanted src path.
360 set_src_path && set_pkg_path
362 fi
363 }
365 # Check for build dependencies, notify user and install if specified.
366 check_for_build_depends()
367 {
368 [ "$WANTED" ] && return
369 [ "$CATEGORY" = meta ] && ! fgrep -q compile_rules $RECEIPT && return
370 [ ! "$BUILD_DEPENDS" ] && ! fgrep -q compile_rules $RECEIPT && return
371 report step "Looking for build dependencies"
373 # Keep the list of previously installed build_depends then compare
374 # it with new build_depends to know what to install and what to
375 # what to remove.
376 plan_remove=" $MISSING_PACKAGE $remove_later "
377 [ ! "${plan_remove// }" ] && unset plan_remove
378 unset MISSING_PACKAGE remove_later
379 rwanted=$(look_for_rwanted)
381 for pkg in $(scan $PACKAGE --look_for=bdep --with_dev | \
382 grep -v $(for i in $(look_for_rwanted) $PACKAGE; do echo " -e ^$i$"; done))
383 do
385 # Delay the removing of previous cook depends if they are needed
386 # for next cook too.
387 if [ ! -d "$INSTALLED/$pkg" ] ; then
388 MISSING_PACKAGE="$MISSING_PACKAGE $pkg"
389 fi
390 if [ "$plan_remove" != "${plan_remove/ $pkg }" ]; then
391 plan_remove="${plan_remove/ $pkg / }"
392 remove_later="$remove_later $pkg"
393 fi
394 grep -q ^$pkg$ $broken && broken_pkg="$broken_pkg$pkg "
395 done
397 # Don't cook if a depend is broken.
398 if [ "$broken_pkg" ]; then
399 MISSING_PACKAGE=$plan_remove
400 echo "Can't cook $PACKAGE because of broken depend(s) : $broken" >&2
401 unset plan_remove broken
403 # Set report step to failed.
404 report_return_code=1
405 report end-step
406 return 1
407 fi
408 if [ "$MISSING_PACKAGE" ]; then
409 install_missing()
410 {
411 echo "Installing missing packages : $MISSING_PACKAGE"
412 for pkg in $MISSING_PACKAGE; do
413 [ -d "$INSTALLED/$pkg" ] || tazpkg get-install $pkg
414 done
415 }
416 if [ "$auto_install" = yes ]; then
417 install_missing
418 else
419 echo "================================================================================"
420 for pkg in $MISSING_PACKAGE
421 do
422 echo "Missing : $pkg"
423 done
424 echo "================================================================================"
425 echo "You can continue, exit or install missing dependencies."
426 echo -n "Install, continue or exit (install/y/N) ? "; read answer
427 case $answer in
428 install)
429 install_missing ;;
430 y|yes)
431 unset MISSING_PACKAGE;;
432 *)
433 report stop
434 exit 0 ;;
435 esac
436 fi
437 fi
438 report end-step
439 remove_build_depends $plan_remove
440 unset plan_remove
441 }
443 remove_build_depends()
444 {
445 [ "$1" ] || return
446 report step "Removing previous build dependencies"
447 echo "Removing these packages : $@"
448 for pkg in $@; do
449 [ -f "$INSTALLED/$pkg/receipt" ] && tazpkg remove $pkg --auto
450 done
451 cd $PWD
452 report end-step
453 }
455 # Check if we can use the new way to handle tarball
456 # or if we keep the previous method by checking for
457 # _pkg=/src= in receipt and reverse-wanted.
458 check_for_var_modification()
459 {
460 for var in $@; do
461 for pkg in $PACKAGE $(look_for_wanted) $(look_for_rwanted); do
462 [ -f $WOK/$pkg/receipt ] || continue
463 fgrep -q "$var=" $WOK/$pkg/receipt && return 1
464 done
465 done
467 # Tweak to make if; then...; fi function working with this one.
468 echo -n ""
469 }
471 set_src_path()
472 {
473 if check_for_var_modification src _pkg; then
474 src=$WOK/${WANTED:-$PACKAGE}/${WANTED:-$PACKAGE}-$VERSION
475 else
476 tazwok_warning "Use original name or tarball root directory because src/_pkg is defined in the receipt (this is no longer needed!)."
477 src=$WOK/${WANTED:-$PACKAGE}/${SOURCE:-${WANTED:-$PACKAGE}}-$VERSION
478 fi
479 stuff=$WOK/$PACKAGE/stuff
480 [ "$WANTED" ] && wanted_stuff=$WOK/$WANTED/stuff
481 }
483 set_pkg_path()
484 {
485 if [ -d $WOK/${WANTED:-$PACKAGE}/install ] ; then
486 _pkg=$WOK/${WANTED:-$PACKAGE}/install
487 else
488 _pkg=$src/_pkg
489 fi
490 }
492 # Output $VERSION-$EXTRAVERSION using packages.txt
493 get_pkg_version()
494 {
495 [ "$PACKAGE" ] || return
496 grep -m1 -A1 -sh ^$PACKAGE$ $1/packages.txt | tail -1 | sed 's/ *//'
497 }
499 remove_previous_package()
500 {
501 [ "$prev_VERSION" ] || return
502 if [ "$VERSION$EXTRAVERSION" != "$prev_VERSION" ]; then
503 rm -f $1/$PACKAGE-$prev_VERSION.tazpkg
504 fi
505 return 0
506 }
508 # Check for src tarball and wget if needed.
509 check_for_tarball()
510 {
511 [ "$WGET_URL" ] || return 0
512 look_for_cookopt !unpack && nounpack=yes
513 report step "Checking for source tarball: $PACKAGE"
514 local repack_src=$repack_src TARBALL=$TARBALL
515 if [ "$repack_src" = yes ] && look_for_cookopt !repack_src; then
516 repack_src=no
517 fi
518 if [ "$target" ]; then
519 src="$target"
520 else
521 set_src_path
522 fi
523 tmp_src=$tmp/tarball-$$
524 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ] && \
525 [ ! -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ] ; then
526 cd $SOURCES_REPOSITORY
527 if [ "$SOURCE" ]; then
528 alt_url="http://mirror.slitaz.org/sources/packages/${SOURCE:0:1}/$SOURCE-$VERSION.tar.lzma"
529 else
530 alt_url="http://mirror.slitaz.org/sources/packages/${PACKAGE:0:1}/$PACKAGE-$VERSION.tar.lzma"
531 fi
532 download $WGET_URL $alt_url http://mirror.slitaz.org/sources/packages/${TARBALL:0:1}/$TARBALL
533 unset alt_url
534 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ] && \
535 [ ! -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ] && \
536 [ ! -d $tmp_src ]; then
537 echo -e "\nDownload failed, exiting. Please check WGET_URL variable.\n" >&2
538 report end-step
539 return 1
540 fi
541 fi
542 report end-step
543 if { [ -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ] && [ "$nounpack" ] ; } || \
544 { [ -f "$SOURCES_REPOSITORY/$TARBALL" ] && [ "$repack_src" != yes ] && [ "$nounpack" ] ; }; then
545 [ -d "$tmp_src" ] && rm -r $tmp_src
546 return 0
547 fi
549 # Untaring source if necessary. We don't need to extract source if
550 # the package is built with a wanted source package.
551 if [ "$WANTED" ]; then
552 [ -d "$tmp_src" ] && rm -r $tmp_src
553 return
554 fi
556 report step "Untaring source tarball"
558 # Log process.
559 echo "untaring source tarball" >> $LOG
561 # If $tmp_src exists, there's already a unpacked tarball in it.
562 if ! [ -d $tmp_src ]; then
563 mkdir $tmp_src
564 if [ -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ] && [ "$repack_src" = yes ]; then
565 lzma d $SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma -so | \
566 tar xf - -C $tmp_src
567 repack_src=no
568 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
569 elif [ -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
570 case "$TARBALL" in
571 *zip|*xpi) cd $tmp_src && unzip -o $SOURCES_REPOSITORY/$TARBALL ;;
572 *bz2|*tbz|*gem) tar xjf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
573 *tar) tar xf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
574 *lzma|*lz) unlzma -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
575 *xz) unxz -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
576 *Z|*taz) uncompress -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
577 *gz) tar xzf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
578 *rpm) cd $tmp_src && rpm2cpio $SOURCES_REPOSITORY/$TARBALL | cpio -idm --quiet;;
580 # It's a plain file or something receipt unpack itself.
581 *)
582 mkdir $tmp_src/${SOURCE:-$PACKAGE}-$VERSION
583 cp $SOURCES_REPOSITORY/$TARBALL $tmp_src/${src##*/}
584 ;;
586 esac || { report end-step
587 rm -f $SOURCES_REPOSITORY/$TARBALL
588 rm -r $tmp_src
589 return 1
590 }
591 fi
593 # Check if uncompressed tarball is in a root dir or not.
594 if [ "$(ls -A $tmp_src | wc -l)" -gt 1 ] || [ -f $(echo $tmp_src/*) ]; then
595 if check_for_var_modification src _pkg; then
596 mv $tmp_src $tmp_src-1
597 mkdir $tmp_src
598 mv $tmp_src-1 $tmp_src/${SOURCE:-$PACKAGE}-$VERSION
599 else
600 mv $tmp_src/* $WOK/$PACKAGE
601 repack_src=no
602 rm -r $tmp_src
603 tazwok_warning "Putting all files in $WOK/$PACKAGE; not sure about how to handle this tarball (no root dir)... Please try to remove src/_pkg definition from the receipt if you encounter any problems."
604 fi
605 fi
606 fi
608 if [ "$repack_src" = yes ]; then
609 report step "Repacking sources in .tar.lzma format"
610 [ "$TARBALL" ] && rm -f $SOURCES_REPOSITORY/$TARBALL
611 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
612 cd $tmp_src
613 tar -c * | lzma e $SOURCES_REPOSITORY/$TARBALL -si
614 fi
616 # Remove previous tarball if no other package needs it. We take care to
617 # keep tarball if the same package uses it in the main repository.
618 if [ "$TARBALL" ]; then
619 previous_tarball=$(grep ^$PACKAGE:incoming $SOURCES_REPOSITORY/sources.list | cut -f2)
620 if [ "$previous_tarball" ]; then
621 sed "/^$PACKAGE:incoming/ s/.*/$PACKAGE:incoming\t$TARBALL/" \
622 -i $SOURCES_REPOSITORY/sources.list
623 grep -q $'\t'$previous_tarball$ $SOURCES_REPOSITORY/sources.list || \
624 rm -f $SOURCES_REPOSITORY/$previous_tarball
625 else
626 echo -e "$PACKAGE:incoming\t$TARBALL" >> $SOURCES_REPOSITORY/sources.list
627 fi
628 fi
630 if [ "$nounpack" ]; then
631 [ -d "$tmp_src" ] && rm -r $tmp_src
632 report end-step
633 return
634 fi
635 if [ ! -d "$src" ]|| [ "$target" ]; then
636 # Permissions settings.
637 chown -R root.root "$tmp_src"
638 if [ -d "$src" ]; then
639 mkdir -p $src
640 for f in $tmp_src/*/*; do
641 cp -a $f $src || { report end-step; rm -r $tmp_src; return 1; }
642 done
643 else
644 if ! check_for_var_modification src _pkg && ! [ "$target" ]; then
645 src="${src%/*}/$(ls $tmp_src)"
646 fi
647 mv $(echo $tmp_src/*) "$src" || { report end-step; rm -r $tmp_src; return 1; }
648 fi
649 rm -r $tmp_src
650 else
651 [ -d "$tmp_src" ] && rm -r $tmp_src
652 echo "There's already something at $src. Abort." >&2
653 fi
654 report end-step
655 }
657 # Log and execute compile_rules function if it exists, to configure and
658 # make the package if it exists.
659 check_for_compile_rules()
660 {
661 if grep -q ^compile_rules $RECEIPT; then
662 echo "executing compile_rules" >> $LOG
663 report step "Executing compile_rules"
664 cd $WOK/$PACKAGE
665 rm -f /tmp/config.site
666 ulimit -d unlimited
667 ulimit -m unlimited
669 # Free some RAM by cleaning cache if option is enabled.
670 freeram=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
672 # Disable -pipe in CFLAGS/CXXFLAGS if less than 512Mb of free
673 # RAM are available.
674 if [ "$freeram" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" -o \
675 "$CXXFLAGS" != "${CXXFLAGS/-pipe}" ]; then
676 tazwok_warning "Disabling -pipe compile flag because only ${freeram}b of RAM is available."
677 CFLAGS="${CFLAGS/-pipe}"
678 CXXFLAGS="${CXXFLAGS/-pipe}"
679 fi
680 unset freeram
682 # Set cook environement variables.
683 [ "$src" ] || set_src_path
684 [ "$DESTDIR" ] || DESTDIR="$WOK/$PACKAGE/install"
685 [ "$CONFIG_SITE" ] || CONFIG_SITE=/etc/config.site
686 export CFLAGS CXXFLAGS MAKEFLAGS DESTDIR BUILD_HOST \
687 CONFIG_SITE default_prefix \
688 default_datarootdir default_datadir default_localedir \
689 default_infodir default_mandir default_build default_host
690 local LC_ALL=POSIX LANG=POSIX
691 compile_rules
693 # Check if config.site has been used.
694 # /!\ disabled since it screws the return_code of the step.
695 #if [ -f /tmp/config.site ]; then
696 # rm /tmp/config.site
697 #else
698 # tazwok_warning "config.site hasn't been used during \
699 #the configuration process."
700 #fi
701 report end-step
702 fi
703 }
705 # Check for loop in deps tree. /!\ can be removed.
706 check_for_deps_loop()
707 {
708 local list
709 local pkg
710 local deps
711 pkg=$1
712 shift
713 [ -n "$1" ] || return
714 list=""
716 # Filter out already processed deps.
717 for i in $@; do
718 case " $ALL_DEPS" in
719 *\ $i\ *);;
720 *) list="$list $i";;
721 esac
722 done
723 ALL_DEPS="$ALL_DEPS$list "
724 for i in $list; do
725 [ -f $i/receipt ] || continue
726 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
727 case " $deps " in
728 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
729 *) check_for_deps_loop $pkg $deps;;
730 esac
731 done
732 }
734 # Function used by download().
735 revert_vcs_failure()
736 {
737 cd $SOURCES_REPOSITORY
738 rm -r $tmp_src
739 }
741 download()
742 {
743 if [ "$COMMAND" = get-src ]; then
744 if [ "${DEPENDS/tar}" != "$DEPENDS" ] || [ "${BUILD_DEPENDS/tar}" != "$BUILD_DEPENDS" ]; then
745 [ -f $INSTALLED/tar/receipt ] || tazpkg get-install tar --forced
746 fi
747 fi
748 for file in $@; do
749 echo "Downloading from ${file#*|}..."
750 case "$file" in
751 git\|*)
752 file=${file#git|}
753 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/git/receipt ] && tazpkg get-install git --forced
754 if [ -f $INSTALLED/git/receipt ]; then
755 mkdir $tmp_src
756 cd $tmp_src
757 if [ "$BRANCH" ]; then
758 git clone $file ${src##*/} && cd ${src##*/} && \
759 git checkout $BRANCH && rm -rf .git* && break
760 else
761 git clone $file ${src##*/} && rm -rf ${src##*/}/.git* && break
762 fi
763 revert_vcs_failure
764 else
765 tazwok_warning "Needs git to download the source tarball from $file, please add it as a build-depend."
766 continue
767 fi
768 ;;
769 bazaar\|*)
770 file=${file#bazaar|}
771 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/bazaar/receipt ] && tazpkg get-install bazaar --forced
772 if [ -f $INSTALLED/bazaar/receipt ]; then
773 mkdir $tmp_src
774 cd $tmp_src
775 if [ "$BRANCH" ]; then
776 bzr co $file -r $BRANCH ${src##*/} && rm -rf ${src##*/}/.bzr* && break
777 else
778 bzr co $file ${src##*/} && rm -rf ${src##*/}/.bzr* && break
779 fi
780 revert_vcs_failure
781 else
782 tazwok_warning "Needs bazaar to download the source tarball from $file, please add it as a build-depend."
783 continue
784 fi
785 ;;
786 subversion\|*)
787 file=${file#subversion|}
788 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/subversion/receipt ] && tazpkg get-install subversion --forced
789 if [ -f $INSTALLED/subversion/receipt ]; then
790 mkdir $tmp_src
791 cd $tmp_src
792 if [ "$BRANCH" ]; then
793 echo t | svn co $file -r $BRANCH ${src##*/} && rm -rf ${src##*/}/.svn* && break
794 else
795 echo t | svn co $file ${src##*/} && rm -rf ${src##*/}/.svn* && break
796 fi
797 revert_vcs_failure
798 else
799 tazwok_warning "Needs subversion to download the source tarball from $file, please add it as a build-depend."
800 continue
801 fi
802 ;;
803 mercurial\|*)
804 file=${file#mercurial|}
805 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/mercurial/receipt ] && tazpkg get-install mercurial --forced
806 if [ -f $INSTALLED/mercurial/receipt ]; then
807 mkdir $tmp_src
808 cd $tmp_src
809 if [ "$BRANCH" ]; then
810 hg clone $file --rev $BRANCH ${src##*/} && rm -rf ${src##*/}/.hg* && break
811 else
812 hg clone $file ${src##*/} && rm -rf ${src##*/}/.hg* && break
813 fi
814 revert_vcs_failure
815 else
816 tazwok_warning "Needs mercurial to download the source tarball from $file, please add it as a build-depend."
817 continue
818 fi
819 ;;
820 https*)
821 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/wget/receipt ] && tazpkg get-install wget --forced
822 if [ -d $INSTALLED/wget ]; then
823 if [ "${WGET_URL%$TARBALL}" = "$WGET_URL" ] && [ "$file" = "$WGET_URL" ]; then
824 wget -q --no-check-certificate -O $TARBALL $file && break
825 else
826 wget -q --no-check-certificate $file && break
827 fi
828 else
829 tazwok_warning "Needs wget to download the source tarball from $file, please add it as a build-depend."
830 continue
831 fi
832 ;;
833 http*|ftp*)
834 # Handle crappy URL.
835 if [ "$COMMAND" = get-src ]; then
836 if [ "${DEPENDS/wget}" != "$DEPENDS" ] || [ "${BUILD_DEPENDS/wget}" != "$BUILD_DEPENDS" ]; then
837 [ -f $INSALLED/wget/receipt ] || tazpkg get-install wget --forced
838 fi
839 fi
840 if [ "${WGET_URL%$TARBALL}" = "$WGET_URL" ] && [ "$file" = "$WGET_URL" ]; then
841 wget -q -O $TARBALL $file && break
842 else
843 wget -q $file && break
844 fi
845 ;;
846 esac
847 done
848 }
850 # Regenerate every package that wants a PACKAGE compiled.
851 refresh_packages_from_compile()
852 {
853 # make tazwok genpkg happy.
854 mkdir $WOK/$PACKAGE/taz
856 # Cook rwanted in default or specied order.
857 genlist=" $(look_for_rwanted | tr '\n' ' ') "
858 for i in $(look_for_cookopt genpkg | tac); do
859 [ "${genlist/ $i }" = "$genlist" ] && continue
860 genlist=" $i${genlist/ $i / }"
861 done
862 if [ "$genlist" ]; then
863 local PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
864 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
865 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
866 src _pkg DESTDIR CONFIG_SITE RECEIPT LOG stuff wanted_stuff
867 for PACKAGE in $genlist; do
868 set_common_path
869 gen_package
870 done
871 fi
872 }
874 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
875 # so some packages need to copy these files with the receipt and genpkg_rules.
876 # This function is executed by gen_package when 'tazwok genpkg'.
877 copy_generic_files()
878 {
879 # In most cases, locales are in $_pkg/usr/share/locale so we copy files
880 # using generic variables and $LOCALE from Tazwok config file.
881 if [ "$LOCALE" ]; then
882 if [ -d "$_pkg/usr/share/locale" ]; then
883 for i in $LOCALE
884 do
885 if [ -d "$_pkg/usr/share/locale/$i" ]; then
886 mkdir -p $fs/usr/share/locale
887 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
888 fi
889 done
890 fi
891 fi
893 # Pixmaps (PNG or/and XPM only). Some icons/images can be added through
894 # genpkg_rules and generic copy can be disabled with GENERIC_PIXMAPS="no"
895 # in pkg receipt.
896 if [ "$GENERIC_PIXMAPS" != "no" ]; then
897 if [ -d "$_pkg/usr/share/pixmaps" ]; then
898 mkdir -p $fs/usr/share/pixmaps
899 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
900 $fs/usr/share/pixmaps 2>/dev/null
901 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
902 $fs/usr/share/pixmaps 2>/dev/null
903 fi
905 # Custom or homemade PNG pixmap can be in stuff.
906 if [ -f "stuff/$PACKAGE.png" ]; then
907 mkdir -p $fs/usr/share/pixmaps
908 cp -a stuff/$PACKAGE.png $fs/usr/share/pixmaps
909 fi
910 fi
912 # Desktop entry (.desktop).
913 if [ -d "$_pkg/usr/share/applications" ]; then
914 cp -a $_pkg/usr/share/applications $fs/usr/share
915 fi
917 # Homemade desktop file(s) can be in stuff.
918 if [ -d "stuff/applications" ]; then
919 mkdir -p $fs/usr/share
920 cp -a stuff/applications $fs/usr/share
921 fi
922 if [ -f "stuff/$PACKAGE.desktop" ]; then
923 mkdir -p $fs/usr/share/applications
924 cp -a stuff/$PACKAGE.desktop $fs/usr/share/applications
925 fi
926 }
928 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
929 strip_package()
930 {
931 report step "Executing strip on all files"
933 # Binaries.
934 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
935 do
936 if [ -d "$dir" ]; then
937 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
938 fi
939 done
941 # Libraries.
942 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
943 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
944 report end-step
945 }
947 # Remove .pyc and .pyo files from packages.
948 py_compiled_files_remove()
949 {
950 report step "Removing all .pyc and .pyo files from package"
951 find $fs -type f -name "*.pyc" -delete 2>/dev/null
952 find $fs -type f -name "*.pyo" -delete 2>/dev/null
953 report end-step
954 }
956 # Check FSH in a slitaz package (Path: /:/usr)
957 check_fsh()
958 {
959 cd $WOK/$PACKAGE/taz/*/fs
960 if [ -z "$(find * ! -type d)" ] && [ "$CATEGORY" != meta ]; then
961 echo "$PACKAGE fs is empty." >&2
962 cd $WOK/$PACKAGE && rm -rf taz
963 return 1
964 fi
965 [ -n "$FSH" ] || FSH="bin boot dev etc home init lib media mnt proc \
966 root sbin share sys tmp usr var vz usr/bin usr/games usr/include usr/lib \
967 usr/local usr/sbin usr/share usr/src"
968 for i in `ls -d * usr/* 2>/dev/null`
969 do
970 if ! echo $FSH | fgrep -q $i; then
971 echo "Wrong path: /$i" >&2
972 error=1
973 fi
974 done
975 if [ "$error" = "1" ]; then
976 cat << _EOT_
978 Package will install files in a non standard directory and won't be generated.
979 You may have a wrong copy path in genpkg_rules or need to add some options to
980 configure in compile_rules. Some valid options for SliTaz (Linux FSH):
982 --prefix=/usr
983 --sysconfdir=/etc
984 --libexecdir=/usr/lib/(pkgname)
985 --localstatedir=/var
986 --mandir=/usr/share/man
987 --infodir=/usr/share/info
989 For more information please read SliTaz docs and run: ./configure --help
990 ================================================================================
991 $PACKAGE package generation aborted.
993 _EOT_
995 # Dont generate a corrupted package.
996 cd $WOK/$PACKAGE && rm -rf taz
997 return 1
998 fi
999 return 0
1002 gen_cookmd5()
1004 # md5sum of cooking stuff make tazwok able to check for changes
1005 # without hg.
1006 cd $WOK/$PACKAGE
1007 md5sum receipt > md5
1008 [ -f description.txt ] && md5sum description.txt >> md5
1009 if [ -d stuff ]; then
1010 find stuff | while read file; do
1011 md5sum $file >> md5
1012 done
1013 fi
1016 set_pkg_broken()
1018 grep -q ^$PACKAGE$ $broken || echo $PACKAGE >> $broken
1020 # Remove pkg from cooklist to avoid re-cook it if no changes happen
1021 # in the cook stuff.
1022 sed "/^$PACKAGE$/d" -i $cooklist $commit
1024 gen_cookmd5
1026 # Return 1 to make report know that its mother-function failed.
1027 return 1
1030 # Create a package tree and build the gziped cpio archive
1031 # to make a SliTaz (.tazpkg) package.
1032 gen_package()
1034 check_root
1035 check_for_package_on_cmdline
1036 check_for_receipt
1037 source_receipt
1039 # May compute VERSION
1040 if grep -q ^get_version $RECEIPT; then
1041 get_version
1042 fi
1043 check_for_wanted
1044 cd $WOK/$PACKAGE
1046 # Remove old Tazwok package files.
1047 [ -d "taz" ] && rm -rf taz
1049 # Create the package tree and set useful variables.
1050 fs=$WOK/$PACKAGE/taz/$PACKAGE-$VERSION/fs
1051 mkdir -p $fs
1053 # Set $src for standard package and $_pkg variables.
1054 set_src_path
1055 set_pkg_path
1057 # Execute genpkg_rules, check package and copy generic files to build
1058 # the package.
1059 report step "Building $PACKAGE with the receipt"
1060 report open-bloc
1061 if look_for_cookopt !fs; then
1063 elif grep -q ^genpkg_rules $RECEIPT; then
1065 # Log process.
1066 echo "executing genpkg_rules" >> $LOG
1067 report step "Executing genpkg_rules"
1068 ( set -e; genpkg_rules ) || { set_pkg_broken; report close-bloc; return 1; }
1069 check_fsh || { set_pkg_broken; report close-bloc; return 1; }
1070 cd $WOK/$PACKAGE
1071 report end-step
1073 # Skip generic files for packages with a WANTED variable
1074 # (dev and split pkgs).
1075 if [ ! "$WANTED" ]; then
1076 copy_generic_files
1077 fi
1078 look_for_cookopt !strip || strip_package
1079 py_compiled_files_remove
1080 else
1081 echo "No package rules to gen $PACKAGE..." >&2
1082 set_pkg_broken
1083 report close-bloc
1084 return 1
1085 fi
1087 # Copy the receipt and description (if exists) into the binary package tree.
1088 cd $WOK/$PACKAGE
1089 report step "Copying the receipt"
1090 cp receipt taz/$PACKAGE-$VERSION
1091 report end-step
1092 if grep -q ^get_version $RECEIPT; then
1093 report step "Updating version in receipt"
1094 sed -i "s/^VERSION=.*/VERSION=\"$VERSION\"/" \
1095 taz/$PACKAGE-$VERSION/receipt
1096 report end-step
1097 fi
1098 if [ -f "description.txt" ]; then
1099 report step "Copying the description file"
1100 cp description.txt taz/$PACKAGE-$VERSION
1101 report end-step
1102 fi
1104 # Generate md5 of cooking stuff to look for commit later.
1105 gen_cookmd5
1106 echo -e "\n# md5sum of cooking stuff :" >> taz/$PACKAGE-$VERSION/receipt
1107 cat md5 | sed 's/^/# /' >> taz/$PACKAGE-$VERSION/receipt
1109 # Create the files.list by redirecting find output.
1110 report step "Creating the list of files"
1111 cd taz/$PACKAGE-$VERSION
1112 LAST_FILE=""
1113 { find fs -print; echo; } | while read file; do
1114 if [ "$LAST_FILE" ]; then
1115 case "$file" in
1116 $LAST_FILE/*)
1117 case "$(ls -ld "$LAST_FILE")" in
1118 drwxr-xr-x\ *\ root\ *\ root\ *);;
1119 *) echo ${LAST_FILE#fs};;
1120 esac;;
1121 *) echo ${LAST_FILE#fs};;
1122 esac
1123 fi
1124 LAST_FILE="$file"
1125 done > files.list
1127 # Next, check if something has changed in lib files.
1128 # Plan to recook each packages which depends on libs
1129 # which doesn't exists anymore.
1130 libs=$(for file in $(find * -type f); do
1131 [ "$(dd if=$file bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ] || continue
1132 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $PWD/$file
1133 done | { cut -f 1 -d ' ' | tr -d '\t' | sort -u | \
1134 sed -e 's/^linux-gate.so.*$/SLIB/' -e 's~^/lib/ld-.*$~SLIB~' \
1135 -e '/^statically$/d' | tr '\n' ' '; })
1136 libs=$(echo " $libs" | sed -r 's/( SLIB)+ / /g')
1137 old_libs=$(grep -m1 ^$PACKAGE$'\t' $lib_db | cut -f 2)
1138 if [ "$old_libs" ]; then
1139 report step "Looking if reverse depends needs to be refreshed"
1140 for i in $old_libs; do
1141 [ "${libs/ $i }" = "$libs" ] || continue
1142 fgrep " $i " $lib_db | cut -f 1
1143 done | sort -u | while read rdep; do
1144 [ "$rdep" = "${WANTED:-$PACKAGE}" ] && continue
1145 grep -q ^$rdep$ $blocked $cooklist && continue
1146 echo "Plan to recook $rdep"
1147 echo $rdep >> $cooklist
1148 done
1149 sed "/^$PACKAGE\t/d" -i $lib_db
1150 report end-step
1151 fi
1152 if [ "$libs" ]; then
1153 echo -e "$PACKAGE\t$libs" >> $lib_db
1154 sort -o $lib_db $lib_db
1155 fi
1157 if [ ! "$EXTRAVERSION" ]; then
1158 case "$PACKAGE" in
1159 linux*);;
1160 *) EXTRAVERSION="$(grep '/lib/modules/.*-slitaz/' files.list |\
1161 head -1 | sed 's|/lib/modules/\(.*\)-slitaz/.*|_\1|')";;
1162 esac
1163 fi
1164 rm -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg 2> /dev/null
1165 report step "Creating md5sum of files"
1166 while read file; do
1167 [ -L "fs$file" ] && continue
1168 [ -f "fs$file" ] || continue
1169 md5sum "fs$file" | sed 's/ fs/ /'
1170 done < files.list > md5sum
1171 report end-step
1172 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
1173 2> /dev/null | awk '{ sz=$1 } END { print sz }')
1175 # Build cpio archives. Find, cpio and gzip the fs, finish by
1176 # removing the fs tree.
1177 # Don't log this because compression always outputs error messages.
1178 find fs -print | cpio -o -H newc | case "$PACKAGE-$COMPRESSION" in
1179 tazpkg-lzma) gzip > fs.cpio.gz;;
1180 *-lzma) lzma e fs.cpio.lzma -si;;
1181 *) gzip > fs.cpio.gz;;
1182 esac && rm -rf fs
1183 PACKED_SIZE=$(du -chs fs.cpio.* receipt files.list md5sum \
1184 description.txt 2> /dev/null | awk '{ sz=$1 } END { print sz }')
1185 report step "Updating receipt sizes"
1186 sed -i '/^PACKED_SIZE/d' receipt
1187 sed -i '/^UNPACKED_SIZE/d' receipt
1188 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1189 sed -i "s/^VERSION=$/VERSION=\"$VERSION\"/" receipt
1190 report end-step
1191 if [ "$EXTRAVERSION" ]; then
1192 report step "Updating receipt EXTRAVERSION"
1193 sed -i s/^EXTRAVERSION.*$// receipt
1194 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
1195 fi
1196 prev_VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
1197 remove_previous_package $INCOMING_REPOSITORY
1198 report step "Creating full cpio archive"
1199 find . -print | cpio -o -H newc > $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1201 # Restore package tree in case we want to browse it.
1202 report step "Restoring original package tree"
1203 { zcat fs.cpio.gz 2> /dev/null || unlzma -c fs.cpio.lzma; } | cpio --quiet -id
1204 rm fs.cpio.* && cd ..
1206 # Save receipts if save_wok is enabled.
1207 [ "$save_wok" ] && copy_cooking_stuff $WOK $PACKAGE $INCOMING_REPOSITORY/wok
1209 # Recook of reverse-depends if package was broken.
1210 if grep -q "^$PACKAGE$" $broken; then
1211 report step "Planning a re-try cook of reverse depends"
1212 sed "/^$PACKAGE$/d" -i $broken
1213 for rdep in $(look_for_rdep); do
1214 grep -q "^$rdep$" $broken || continue
1215 grep -q "^$rdep$" $cooklist && continue
1216 echo "Adding $rdep to the cooklist"
1217 echo $rdep >> $cooklist
1218 regen_cooklist=t
1219 done
1220 report end-step
1221 fi
1222 sed "/^$PACKAGE$/d" -i $commit $cooklist
1224 # Log process.
1225 echo "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg (done)" >> $LOG
1226 report close-bloc
1227 echo "Package $PACKAGE ($VERSION$EXTRAVERSION) generated."
1228 echo "Size : `du -sh $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
1229 echo ""
1232 ########################################################################
1233 # This section contains functions used by several other functions
1234 # below.
1235 ########################
1237 # Look for receipt/files.list in wok. If they can't be found, get them
1238 # from package. Accept one argument : absolute path to package.
1239 get_pkg_files()
1241 pkg_files_dir=$tmp/$(basename ${1%.tazpkg})
1242 mkdir -p $pkg_files_dir && \
1243 cd $pkg_files_dir && \
1244 cpio --quiet -idm receipt < $1 && \
1245 cpio --quiet -idm files.list < $1
1248 ########################################################################
1249 # This section contains functions to generate packages databases.
1250 ########################
1253 gen_packages_db()
1255 # pkg_repository can be $PACKAGES_REPOSITORY or $INCOMING_REPOSITORY.
1256 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1257 cd $pkg_repository
1258 report step "Generating packages lists: $pkg_repository"
1259 report open-bloc
1260 report step "Removing old files"
1261 for file in files.list.lzma packages.list packages.txt \
1262 packages.desc packages.equiv packages.md5; do
1263 rm -rf $file
1264 done
1265 touch files.list
1267 packages_db_start
1268 unset RECEIPT
1269 report step "Reading data from all packages"
1270 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1271 get_packages_info
1272 done
1273 report end-step
1274 packages_db_end
1275 report close-bloc
1278 update_packages_db()
1280 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1281 cd $pkg_repository
1282 for file in packages.list packages.equiv packages.md5 packages.desc \
1283 packages.txt; do
1284 if [ ! -f "$file" ]; then
1285 gen_packages_db
1286 return
1287 fi
1288 done
1289 if [ -f files.list.lzma ]; then
1290 lzma d files.list.lzma files.list
1291 else
1292 gen_packages_db
1293 return
1294 fi
1295 report step "Updating packages lists: $pkg_repository"
1296 packages_db_start
1298 # Look for removed/update packages.
1299 touch stamp -r packages.list
1300 for PACKAGE in $(grep ^[0-9,a-z,A-Z] packages.txt); do
1301 pkg="$pkg_repository/$(grep -m1 ^$PACKAGE- packages.list).tazpkg"
1302 if ! [ -f "$pkg" ]; then
1303 erase_package_info
1304 else
1305 if [ "$pkg" -nt "stamp" ]; then
1306 updated_pkg="$updated_pkg
1307 $PACKAGE $pkg"
1308 elif [ ! -f $WOK/$PACKAGE/receipt ] && \
1309 [ "$COMMAND" = check-incoming -o "$pkg_repository" = "$INCOMING_REPOSITORY" ]; then
1310 erase_package_info
1311 echo "Removing $PACKAGE from $pkg_repository."
1312 rm $pkg
1313 [ "$save_wok" ] && rm -rf $pkg_repository/wok/$PACKAGE
1314 if [ "$pkg_repository" = "$INCOMING_REPOSITORY" ]; then
1315 rm -rf $WOK/$PACKAGE
1316 sed "/^$PACKAGE\t/d" -i $wan_db $dep_db $cookorder
1317 sed "/^$PACKAGE$/d" -i $cooklist $commit $blocked $broken
1318 rm -f $LOCAL_REPOSITORY/log/$PACKAGE.html
1319 if [ "$(sed 1!d $cookorder)" != "#PlanSort" ]; then
1320 sed 1i"#PlanSort" -i $cookorder
1321 regen_cooklist=yes
1322 fi
1323 else
1324 echo "$PACKAGE" >> removed
1325 sed -n '1,10p' -i removed
1326 fi
1327 fi
1328 fi
1329 done
1330 rm stamp
1331 echo "$updated_pkg" | sed 1d | while read PACKAGE pkg; do
1332 erase_package_info
1333 get_packages_info
1334 done
1335 unset updated_pkg
1337 # Look for new packages.
1338 for pkg in $pkg_repository/*.tazpkg; do
1339 fgrep -q " ${pkg##*/}" packages.md5 || get_packages_info
1340 done
1341 report end-step
1342 packages_db_end
1345 packages_db_start()
1347 if [ -s packages.txt ]; then
1348 sed -e 's/^# Packages :.*/# Packages : unknown/' \
1349 -e "s/# Date :.*/# Date : $(date +%Y-%m-%d\ \%H:%M:%S)/" \
1350 -i packages.txt
1351 else
1352 echo "# SliTaz GNU/Linux - Packages list
1354 # Packages : unknown
1355 # Date : $(date +%Y-%m-%d\ \%H:%M:%S)
1357 " > packages.txt
1358 fi
1360 # Needed in some cases as tazwok defines RECEIPT at configuration time
1361 # in this particular case it can break the script.
1362 unset RECEIPT
1364 # If $packages_repository is the main one, configure few functions
1365 # to act as they should, without having loop on them (speed-up)
1366 if [ "${pkg_repository##*/}" = packages ]; then
1367 erase_package_info_extracmd="erase_package_info_main"
1368 get_packages_info_extracmd="erase_package_info_main"
1369 fi
1372 erase_package_info()
1374 cd $pkg_repository
1375 sed "/^$PACKAGE$/,/^$/d" -i packages.txt
1376 sed "/^$PACKAGE /d" -i packages.desc
1377 sed -e "s/=$PACKAGE /= /" -e "s/ $PACKAGE / /" -e "s/ $PACKAGE$//" \
1378 -e "/=$PACKAGE$/d" -e "s/=[0-9,a-z,A-Z]:$PACKAGE /= /" \
1379 -e "s/ [0-9,a-z,A-Z]:$PACKAGE / /" -e "s/ [0-9,a-z,A-Z]:$PACKAGE$/ /" \
1380 -e "/=[0-9,a-z,A-Z]:$PACKAGE$/d" \
1381 -i packages.equiv
1382 sed "/^$PACKAGE:/d" -i files.list
1383 sed "/^$(basename ${pkg%.tazpkg})$/d" -i packages.list
1384 sed "/ $(basename $pkg)$/d" -i packages.md5
1385 $erase_package_info_extracmd
1388 erase_package_info_main()
1390 for i in wanted.txt depends.txt libraries.txt; do
1391 [ -f $i ] || continue
1392 sed "/^$PACKAGE\t/d" -i $i
1393 done
1396 get_packages_info()
1398 # If there's no taz folder in the wok, extract info from the
1399 # package.
1400 get_pkg_files $pkg
1401 source_receipt
1402 echo "Getting data from $PACKAGE"
1404 cat >> $pkg_repository/packages.txt << _EOT_
1405 $PACKAGE
1406 $VERSION$EXTRAVERSION
1407 $SHORT_DESC
1408 _EOT_
1409 if [ "$PACKED_SIZE" ]; then
1410 cat >> $pkg_repository/packages.txt << _EOT_
1411 $PACKED_SIZE ($UNPACKED_SIZE installed)
1413 _EOT_
1414 else
1415 echo "" >> $pkg_repository/packages.txt
1416 fi
1418 # Packages.desc is used by Tazpkgbox <tree>.
1419 echo "$PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> $pkg_repository/packages.desc
1421 # Packages.equiv is used by tazpkg install to check depends.
1422 for i in $PROVIDE; do
1423 DEST=""
1424 echo $i | fgrep -q : && DEST="${i#*:}:"
1425 if grep -qs ^${i%:*}= $pkg_repository/packages.equiv; then
1426 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" $pkg_repository/packages.equiv
1427 else
1428 echo "${i%:*}=$DEST$PACKAGE" >> $pkg_repository/packages.equiv
1429 fi
1430 done
1432 if [ -f files.list ]; then
1433 { echo "$PACKAGE"; cat files.list; } | awk '
1434 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }' >> $pkg_repository/files.list
1435 fi
1437 cd .. && rm -r "$pkg_files_dir"
1439 cd $pkg_repository
1440 echo $(basename ${pkg%.tazpkg}) >> packages.list
1441 md5sum $(basename $pkg) >> packages.md5
1442 $get_packages_info_extracmd
1445 get_packages_info_main()
1447 [ "$WANTED" ] && echo -e "$PACKAGE\t$WANTED" >> wanted.txt
1448 echo -e "$PACKAGE\t "$DEPENDS" \t "$BUILD_DEPENDS" " >> package.txt
1449 libs=$(grep -m1 ^$PACKAGE$'\t' $lib_db | cut -f 2)
1450 [ "$libs" ] && echo "$libs" >> libraries.txt
1453 source_receipt()
1455 unset PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
1456 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
1457 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
1458 src _pkg DESTDIR CONFIG_SITE BRANCH TARBALL stuff wanted_stuff
1459 . ${RECEIPT:-$PWD/receipt}
1462 packages_db_end()
1464 cd $pkg_repository
1465 pkgs=$(wc -l packages.list | sed 's/ .*//')
1466 sed "s/# Packages : .*/# Packages : $pkgs/" -i packages.txt
1468 # If lists were updated it's generally needed to sort them well.
1469 if ! sort -c packages.list 2> /dev/null; then
1470 report step "Sorting packages lists"
1471 files_list="packages.list packages.desc packages.equiv"
1472 [ "${pkg_repository##*/}" = packages ] && \
1473 files_list="$files_list wanted.txt depends.txt libraries.txt"
1474 for file in $files_list; do
1475 [ -f $file ] || continue
1476 sort -o $file $file
1477 done
1478 md5sum packages.md5 | cut -f1 -d' ' > ID
1479 report end-step
1480 fi
1482 # Dont log this because lzma always output errors.
1483 lzma e files.list files.list.lzma
1484 rm -f files.list
1485 [ -f packages.equiv ] || touch packages.equiv
1488 ########################################################################
1489 # This section contains functions to generate wok database.
1490 ########################
1492 gen_wok_db()
1494 report step "Generating wok database"
1495 report open-bloc
1496 report step "Removing old files"
1497 for file in $wan_db $dep_db $cookorder; do
1498 [ -f $file ] && rm $file
1499 done
1500 report step "Generating wok-wanted.txt"
1501 gen_wan_db
1502 report step "Generating wok-depends.txt"
1503 for PACKAGE in $(cut -f1 -d '|' $PACKAGES_REPOSITORY/packages.desc \
1504 $INCOMING_REPOSITORY/packages.desc | sort -u); do
1505 RECEIPT=$WOK/$PACKAGE/receipt
1506 if [ -s $RECEIPT ]; then
1507 source_receipt
1508 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
1509 fi
1510 done
1511 sort_db
1512 report close-bloc
1515 gen_wan_db()
1517 for RECEIPT in $(fgrep -l WANTED $WOK/*/receipt); do
1518 WANTED=
1519 source $RECEIPT
1520 [ "$WANTED" ] || continue
1521 echo -e $PACKAGE"\t"$WANTED >> $tmp/wan_db
1522 done
1523 if ! [ -f $wan_db ] || [ "$(diff -q $tmp/wan_db $wan_db)" ]; then
1524 mv -f $tmp/wan_db $wan_db
1525 plan_regen_cookorder=yes
1526 else
1527 rm $tmp/wan_db
1528 fi
1531 update_wan_db()
1533 local PACKAGE=$PACKAGE
1534 wanted_list=$(fgrep WANTED=\"$PACKAGE\" $WOK/*/receipt | cut -f1 -d ':')
1535 grep $'\t'$PACKAGE $wan_db | cut -f 1 | while read wan; do
1536 echo "$wanted_list" | fgrep -q /$wan/receipt && continue
1537 sed "/^$wan\t/d" -i $wan_db
1538 plan_regen_cookorder=yes
1539 done
1540 for RECEIPT in $wanted_list; do
1541 WANTED=
1542 source $RECEIPT
1543 [ "$WANTED" ] || continue
1544 wan_info=$(echo -e $PACKAGE"\t"$WANTED)
1545 [ "$wan_info" = "$(grep -m1 ^$PACKAGE$'\t' $wan_db 2>/dev/null)" ] && continue
1546 sed "/^$PACKAGE\t/d" -i $wan_db
1547 echo "$wan_info" >> $wan_db
1548 plan_regen_cookorder=yes
1549 plan_sort_wandb=yes
1550 done
1551 unset wanted_list
1554 update_dep_db()
1556 dep_info=$(echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ')
1557 [ "$dep_info" = "$(grep -m1 ^$PACKAGE$'\t' $dep_db 2>/dev/null)" ] && return
1558 sed "/^$PACKAGE\t/d" -i $dep_db
1559 echo "$dep_info" >> $dep_db
1560 plan_regen_cookorder=yes
1561 plan_sort_depdb=yes
1564 sort_db()
1566 report step "Generating cookorder.txt"
1567 sed 's/ \t / /' $dep_db | while read PACKAGE BUILD_DEPENDS; do
1568 grep -q ^$PACKAGE$'\t' $wan_db && continue
1570 # Replace each BUILD_DEPENDS with a WANTED package by it's
1571 # WANTED package.
1572 echo -e $PACKAGE"\t $(echo $BUILD_DEPENDS | use_wanted | \
1573 sort -u | sed "/^$PACKAGE$/d" | tr '\n' ' ') "
1574 done > $tmp/db
1575 while [ -s "$tmp/db" ]; do
1576 status=start
1577 for pkg in $(cut -f 1 $tmp/db); do
1578 if ! fgrep -q ' '$pkg' ' $tmp/db; then
1579 echo $pkg >> $tmp/cookorder
1580 sed -e "/^$pkg\t/d" -e "s/ $pkg / /g" -i $tmp/db
1581 status=proceed
1582 fi
1583 done
1584 if [ "$status" = start ]; then
1585 cp -f $tmp/db /tmp/remain-depends.txt
1586 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
1587 for remaining in $(cut -f 1 $tmp/db); do
1588 echo "$remaining" >> $blocked
1589 done
1590 break
1591 fi
1592 done
1593 [ -s $tmp/cookorder ] || touch $tmp/cookorder
1595 # The toolchain packages are moved in first position.
1596 grep $(for pkg in `scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
1597 --look_for=all --with_args`; do echo " -e ^$pkg$"; done) \
1598 $tmp/cookorder | tac > $cookorder
1599 for pkg in $(cat $cookorder); do
1600 sed "/^$pkg$/d" -i $tmp/cookorder
1601 done
1603 tac $tmp/cookorder >> $cookorder
1604 unset plan_regen_cookorder
1605 report end-step
1608 ########################################################################
1609 # SCAN CORE
1610 ########################
1611 # Includes various scan core-functions. It's not intended to be used
1612 # directly : prefer scan wrappers in next section.
1614 look_for_dep()
1616 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2
1619 look_for_bdep()
1621 look_for_all
1624 look_for_all()
1626 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2,3 | sed 's/ / /'
1629 look_for_rdep()
1631 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1
1634 look_for_rbdep()
1636 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1639 # Return WANTED if it exists.
1640 look_for_wanted()
1642 grep -m1 ^$PACKAGE$'\t' $wan_db | cut -f 2
1645 # Return packages which wants PACKAGE.
1646 look_for_rwanted()
1648 grep $'\t'$PACKAGE$ $wan_db | cut -f 1
1651 look_for_dev()
1653 WANTED=$(look_for_wanted)
1654 if [ "$WANTED" ]; then
1655 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1656 fi
1657 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1660 with_dev()
1662 for PACKAGE in $(cat); do
1663 echo $PACKAGE
1664 look_for_dev
1665 done
1668 with_wanted()
1670 for PACKAGE in $(cat); do
1671 echo $PACKAGE
1672 look_for_wanted
1673 done
1676 use_wanted()
1678 for input in $(cat); do
1679 { grep ^$input$'\t' $wan_db || echo $input
1681 done | sed 's/.*\t//'
1684 check_for_pkg_in_wok()
1686 [ -f $WOK/$PACKAGE/receipt ] && return
1687 echo "Can't find $PACKAGE in wok or mirror" >&2
1688 return 2
1691 # Define how theses functions should act when using --undigest.
1692 use_undigest_scan_core()
1694 look_for_dep()
1696 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1697 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2
1698 else
1699 grep -m1 ^$PACKAGE$'\t' $ref_dep_db | cut -f 2
1700 fi
1703 look_for_all()
1705 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1706 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2,3 | sed 's/ / /'
1707 else
1708 grep -m1 ^$PACKAGE$'\t' $ref_dep_db | cut -f 2,3 | sed 's/ / /'
1709 fi
1712 look_for_rdep()
1714 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1
1715 for rdep in $(fgrep ' '$PACKAGE' ' $ref_dep_db | cut -f 1); do
1716 [ -f "WOK$/$rdep/receipt" ] || echo "$rdep"
1717 done
1720 look_for_rbdep()
1722 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1723 for rdep in $(fgrep ' '$PACKAGE' ' $ref_dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1); do
1724 [ -f "WOK$/$rdep/receipt" ] || echo "$rdep"
1725 done
1728 look_for_wanted()
1730 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1731 grep -m1 ^$PACKAGE$'\t' $wan_db | cut -f 2
1732 else
1733 grep -m1 ^$PACKAGE$'\t' $ref_wan_db | cut -f 2
1734 fi
1737 look_for_rwanted()
1739 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1740 grep $'\t'$PACKAGE$ $wan_db | cut -f 1
1741 else
1742 grep $'\t'$PACKAGE$ $ref_wan_db | cut -f 1
1743 fi
1746 look_for_dev()
1748 WANTED=$(look_for_wanted)
1749 if [ "$WANTED" ]; then
1750 if [ -f "$WOK/$WANTED/receipt" ]; then
1751 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1752 else
1753 grep -q ^$WANTED-dev$'\t' $ref_dep_db && echo $WANTED-dev
1754 fi
1755 fi
1756 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1757 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1758 else
1759 grep -q ^$PACKAGE-dev$'\t' $ref_dep_db && echo $PACKAGE-dev
1760 fi
1763 check_for_pkg_in_wok()
1765 [ -f $WOK/$PACKAGE/receipt ] && return
1766 grep -q ^$PACKAGE'$\t' $ref_dep_db && return 1
1767 echo "Can't find $PACKAGE in wok or mirror" >&2
1768 return 2
1772 ########################################################################
1773 # SCAN
1774 ########################
1775 # Use wok-wanted.txt and wok-depeds.txt to scan depends.
1776 # Option in command line (must be first arg) :
1777 # --look_for=bdep/rbdep - Look for depends or reverse depends.
1778 # --with_dev - Add development packages (*-dev) in the result.
1779 # --with_wanted - Add package+reverse wanted in the result.
1780 # --with_args - Include packages in argument in the result.
1782 scan()
1784 # Get packages in argument.
1785 local PACKAGE=$PACKAGE WANTED=$WANTED pkg_list=
1786 for arg in $@; do
1787 [ "$arg" = "${arg#--}" ] || continue
1788 pkg_list="$pkg_list $arg"
1789 done
1791 # Get options.
1792 [ "$pkg_list" ] || return
1793 local cooklist= look_for= with_dev= with_wanted= with_args= log_command="$0 $@" \
1794 get_options_list="look_for with_dev with_wanted with_args cooklist use_wanted"
1795 get_options
1797 # Cooklist is a special case where we need to modify a little
1798 # scan behavior
1799 if [ "$cooklist" ]; then
1800 gen_wan_db
1801 look_for=all && with_args=yes && with_dev= && with_wanted=
1802 filter=use_wanted
1803 if [ "$COMMAND" = gen-cooklist ]; then
1804 for PACKAGE in $pkg_list; do
1805 grep -q ^$PACKAGE$'\t' $dep_db && continue
1806 [ -d "$WOK/$p" ] || continue
1807 check_for_missing
1808 done
1809 append_to_dep()
1811 if grep -q ^$PACKAGE$'\t' $dep_db; then
1812 echo $PACKAGE >> $tmp/dep
1813 else
1814 check_for_missing && echo $PACKAGE >> $tmp/dep
1815 fi
1817 else
1818 append_to_dep()
1820 check_for_commit && echo $PACKAGE >> $tmp/dep
1822 fi
1823 else
1824 append_to_dep()
1826 echo $PACKAGE >> $tmp/dep
1828 # If requested packages are not in dep_db, partial generation of this db is needed.
1829 for PACKAGE in $pkg_list; do
1830 grep -q ^$PACKAGE$'\t' $dep_db && continue
1831 [ -d "$WOK/$p" ] || continue
1832 plan_check_for_missing=yes
1833 check_for_missing
1834 done
1835 if [ "$plan_check_for_missing" ]; then
1836 append_to_dep()
1838 if grep -q ^$PACKAGE$'\t' $dep_db; then
1839 echo $PACKAGE >> $tmp/dep
1840 else
1841 check_for_missing && echo $PACKAGE >> $tmp/dep
1842 fi
1844 check_db_status=yes
1845 unset plan_check_for_missing
1846 fi
1847 fi
1849 [ "$with_dev" ] && filter=with_dev
1850 [ "$with_wanted" ] && filter=with_wanted
1851 if [ "$filter" ]; then
1852 pkg_list=$(echo $pkg_list | $filter | sort -u)
1853 scan_pkg()
1855 look_for_$look_for | $filter
1857 else
1858 scan_pkg()
1860 look_for_$look_for
1862 fi
1863 touch $tmp/dep
1864 for PACKAGE in $pkg_list; do
1865 [ "$with_args" ] && append_to_dep
1866 scan_pkg
1867 done | tr ' ' '\n' | sort -u > $tmp/list
1868 [ "$look_for" = bdep ] && look_for=dep
1869 while [ -s $tmp/list ]; do
1870 PACKAGE=$(sed 1!d $tmp/list)
1871 sed 1d -i $tmp/list
1872 append_to_dep
1873 for pkg in $(scan_pkg); do
1874 grep -q ^$pkg$ $tmp/list $tmp/dep || echo $pkg >> $tmp/list
1875 done
1876 done
1877 if [ "$cooklist" ]; then
1878 mv $tmp/dep $tmp/cooklist
1879 else
1880 cat $tmp/dep | sort -u
1881 fi
1882 rm -f $tmp/dep $tmp/list
1883 if [ "$check_db_status" ]; then
1884 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
1885 [ "$plan_sort_wandb" ] && sort -o $wan_db $wan_db && unset plan_sort_wandb
1886 if [ "$plan_regen_cookorder" ] && \
1887 [ "$(sed 1!d $cookorder)" != "#PlanSort" ]; then
1888 grep -q "^#" $cookorder || sed 1i"#PlanSort" -i $cookorder
1889 fi
1890 fi
1893 ########################################################################
1894 # This section contains functions to check the package repository and
1895 # find which packages to cook.
1896 ########################
1898 check_for_missing()
1900 local PACKAGE=$PACKAGE
1901 if ! check_for_pkg_in_wok; then
1902 [ "$?" = 2 ] && return 1
1903 return
1904 fi
1905 RECEIPT=$WOK/$PACKAGE/receipt
1906 source_receipt
1907 PACKAGE=${WANTED:-$PACKAGE}
1908 update_wan_db
1909 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1910 RECEIPT=$WOK/$PACKAGE/receipt
1911 source_receipt
1912 update_dep_db
1913 done
1916 check_for_commit()
1918 if ! check_for_pkg_in_wok; then
1919 [ "$?" = 2 ] && return 1
1920 return
1921 fi
1922 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1923 RECEIPT=$WOK/$PACKAGE/receipt
1924 source_receipt
1926 # We use md5 of cooking stuff in the packaged receipt to check
1927 # commit. We look consecutively in 3 different locations :
1928 # - in the wok/PACKAGE/taz/* folder
1929 # - in the receipt in the package in incoming repository
1930 # - in the receipt in the package in packages repository
1931 # If md5sums match, there's no commit.
1932 check_for_commit_using_md5sum()
1934 if [ ! -f $WOK/$PACKAGE/md5 ]; then
1935 sed -n '/# md5sum of cooking stuff :/,$p' receipt | \
1936 sed -e 1d -e 's/^# //' > $WOK/$PACKAGE/md5
1937 cd $WOK/$PACKAGE
1938 fi
1940 if [ -s md5 ]; then
1941 if md5sum -cs md5; then
1943 # If md5sum check if ok, check for new/missing files in
1944 # cooking stuff.
1945 for file in $([ -f receipt ] && echo receipt; \
1946 [ -f description.txt ] && echo description.txt; \
1947 [ -d stuff ] && find stuff); do
1948 if ! fgrep -q " $file" md5; then
1949 set_commited
1950 fi
1951 done
1952 else
1953 set_commited
1954 fi
1955 else
1956 set_commited
1957 fi
1959 set_commited()
1961 grep -q ^$PACKAGE$ $commit || echo $PACKAGE >> $commit
1962 gen_cookmd5
1963 update_dep_db
1965 taz_dir=$(echo $WOK/$PACKAGE/taz/$PACKAGE-* | fgrep -v '*')
1966 if [ -f $WOK/$PACKAGE/md5 ]; then
1967 cd $WOK/$PACKAGE
1968 check_for_commit_using_md5sum
1969 elif [ "$taz_dir" ]; then
1970 cd $taz_dir
1971 check_for_commit_using_md5sum
1972 else
1973 pkg=$(echo $INCOMING_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
1974 [ "$pkg" ] || pkg=$(echo $PACKAGES_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
1975 if [ "$pkg" ]; then
1976 get_pkg_files $pkg
1977 check_for_commit_using_md5sum
1978 rm -r $pkg_files_dir
1979 else
1980 set_commited
1981 fi
1982 fi
1983 [ "$forced" ] || echo $PACKAGE >> $tmp/checked
1984 done
1985 return
1988 gen_cook_list()
1990 report step "Scanning wok"
1991 if [ "$pkg" ]; then
1992 scan $pkg --cooklist
1993 elif [ "$LIST" ]; then
1994 scan `cat $LIST` --cooklist
1995 else
1996 scan `cat $cooklist` --cooklist
1997 fi
1998 report end-step
2000 [ -s $tmp/checked ] || [ -s $tmp/cooklist ] || return
2002 # Core toolchain should not be cooked unless cook-toolchain is used.
2003 if ! [ -f /etc/config.site.tmptoolchain ] ; then
2004 for PACKAGE in $(scan gcc --look_for=all --with_args --with_wanted); do
2005 grep -q ^$PACKAGE$ $blocked || echo $PACKAGE >> $blocked
2006 done
2007 fi
2009 if [ -s $commit ] && [ "$COMMAND" != gen-cooklist ]; then
2010 for PACKAGE in $(cat $commit); do
2011 WANTED="$(look_for_wanted)"
2012 if [ "$WANTED" ]; then
2013 grep -q ^$WANTED$ $broken $cooklist $blocked $commit && continue
2014 fi
2015 grep -q ^$PACKAGE$ $blocked $cooklist && continue
2016 echo $PACKAGE >> $cooklist
2017 done
2018 fi
2019 sort_cooklist
2022 sort_cooklist()
2024 if [ "$(sed 1!d $cookorder)" = "#PlanSort" ]; then
2025 sed 1d -i $cookorder
2026 plan_regen_cookorder=yes
2027 fi
2028 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
2029 [ "$plan_regen_cookorder" ] && sort_db
2030 report step "Generating cooklist"
2031 if [ -f "$tmp/checked" ]; then
2032 rm -f $tmp/cooklist
2033 cat $tmp/checked | while read PACKAGE; do
2034 grep -q ^$PACKAGE$ $cooklist && echo $PACKAGE >> $tmp/cooklist
2035 done
2036 elif ! [ "$COMMAND" = gen-cooklist ]; then
2037 cat $blocked | while read PACKAGE; do
2038 sed "/^$PACKAGE/d" -i $tmp/cooklist
2039 done
2040 fi
2041 report end-step
2042 [ -s $tmp/cooklist ] || return
2044 report step "Sorting cooklist"
2045 for PACKAGE in $(cat $tmp/cooklist); do
2046 WANTED="$(look_for_wanted)"
2047 [ "$WANTED" ] || continue
2048 if grep -q ^$WANTED$ $broken $tmp/cooklist; then
2049 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2050 elif [ ! -d $WOK/$WANTED/install ]; then
2051 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2052 echo $WANTED >> $tmp/cooklist
2053 fi
2054 done
2056 # Use cookorder.txt to sort cooklist.
2057 if [ -s $tmp/cooklist ]; then
2058 cat $cookorder | while read PACKAGE; do
2059 if grep -q ^$PACKAGE$ $tmp/cooklist; then
2060 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2061 echo $PACKAGE >> $tmp/cooklist.tmp
2062 fi
2063 done
2065 # Remaining packages in cooklist are those without compile_rules.
2066 # They can be cooked first in any order.
2067 if [ -f $tmp/cooklist.tmp ]; then
2068 cat $tmp/cooklist.tmp >> $tmp/cooklist
2069 rm $tmp/cooklist.tmp
2070 fi
2072 cat $tmp/cooklist
2073 [ "$LIST" ] || cat $tmp/cooklist > $cooklist
2074 fi
2076 report end-step
2079 look_for_missing_pkg()
2081 for pkg in $(cat $PACKAGES_REPOSITORY/$1); do
2082 grep -q ^$pkg$ $INCOMING_REPOSITORY/packages.txt \
2083 $PACKAGES_REPOSITORY/packages.txt || \
2084 continue
2085 echo $pkg
2086 done
2089 check_for_incoming()
2091 report step "Checking that all packages were cooked OK"
2092 [ -s $INCOMING_REPOSITORY/packages.desc ] || {
2093 echo "No packages in $INCOMING_REPOSITORY."
2094 report end-step; return; }
2095 if [ -s $broken ]; then
2096 missingpkg=$(look_for_missing_pkg broken)
2097 if [ "$missingpkg" ]; then
2098 echo "Don't move incoming packages to main repository because these ones are broken:" >&2
2099 echo "$missingpkg"
2100 report end-step
2101 return 1
2102 fi
2103 fi
2104 if [ -s $cooklist ]; then
2105 missingpkg=$(look_for_missing_pkg cooklist)
2106 if [ "$missingpkg" ]; then
2107 echo "Don't move incoming packages to main repository because these ones need to be cooked:" >&2
2108 echo "$missingpkg"
2109 report end-step
2110 return 1
2111 fi
2112 fi
2113 incoming_pkgs="$(cut -f 1 -d '|' $INCOMING_REPOSITORY/packages.desc)"
2114 if ! [ "$forced" ]; then
2115 cooklist=$PACKAGES_REPOSITORY/cooklist
2116 pkg="$incoming_pkgs"
2117 gen_cook_list
2118 if [ -s $cooklist ]; then
2119 missingpkg=$(look_for_missing_pkg cooklist)
2120 if [ "$missingpkg" ]; then
2121 echo "Don't move incoming packages to main repository because these ones need to be cooked:" >&2
2122 echo "$missingpkg"
2123 report end-step
2124 return 1
2125 fi
2126 fi
2127 fi
2129 report step "Moving incoming packages to main repository"
2130 [ "save_wok" ] && mkdir -p $PACKAGES_REPOSITORY/wok
2131 unset EXTRAVERSION
2132 for PACKAGE in $incoming_pkgs; do
2133 prev_VERSION=$(get_pkg_version $PACKAGES_REPOSITORY)
2134 VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
2135 remove_previous_package $PACKAGES_REPOSITORY
2136 echo "Moving $PACKAGE..."
2137 mv -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION.tazpkg $PACKAGES_REPOSITORY
2138 touch $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
2139 previous_tarball=$(grep -m1 ^$PACKAGE:main $SOURCES_REPOSITORY/sources.list | cut -f2)
2140 sed -e "/^$PACKAGE:main/d" \
2141 -e "s/^$PACKAGE:incoming/$PACKAGE:main/" \
2142 -i $SOURCES_REPOSITORY/sources.list
2143 if [ "$previous_tarball" ]; then
2144 grep -q $'\t'$previous_tarball$ $SOURCES_REPOSITORY/sources.list || \
2145 rm -f $SOURCES_REPOSITORY/$previous_tarball
2146 fi
2147 [ "$save_wok" ] &&
2148 copy_cooking_stuff $INCOMING_REPOSITORY/wok $PACKAGE $PACKAGES_REPOSITORY/wok
2149 done
2151 if [ "$save_wok" = tarball ]; then
2152 rm -f $PACKAGES_REPOSITORY/wok.tar.lzma
2153 cd $PACKAGES_REPOSITORY/wok
2154 report step "Generating safe-wok tarball"
2155 tar -c * | lzma e $PACKAGES_REPOSITORY/wok.tar.lzma
2156 report end-step
2157 fi
2159 for file in packages.list packages.equiv packages.md5 packages.desc \
2160 packages.txt; do
2161 echo -n "" > $INCOMING_REPOSITORY/$file
2162 done
2163 rm -r $INCOMING_REPOSITORY/files.list.lzma
2164 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2166 report step "Updating flavors"
2167 if [ -x /usr/bin/tazlito ] || [ -x /usr/bin/clean-chroot ]; then
2168 if ! [ -x /usr/bin/tazlito ]; then
2169 tazpkg get-install tazlito
2170 fi
2172 # Handle cases where tazwok is used into main system;
2173 # Handle cases where SLITAZ_DIR is not /home/slitaz.
2174 [ -L /home/slitaz/flavors ] && rm /home/slitaz/flavors
2175 mkdir -p /home/slitaz
2176 ln -s $LOCAL_REPOSITORY/flavors /home/slitaz/flavors
2178 cd $LOCAL_REPOSITORY/packages
2179 for i in $LOCAL_REPOSITORY/flavors/*; do
2180 [ -d "$i" ] || continue
2181 tazlito pack-flavor ${i##*/}
2182 done
2184 noheader=""
2185 for i in *.flavor; do
2186 tazlito show-flavor $i --brief $noheader
2187 noheader="--noheader"
2188 done > flavors.list
2189 [ -x /usr/bin/clean-chroot ] && clean-chroot
2190 else
2191 echo "Can't create up-to-date flavors because the tazlito package is missing." >&2
2192 fi
2193 report end-step
2196 # Usage: move_cooking_stuff source receipt destination
2197 # Make the argument check before calling it!
2198 copy_cooking_stuff()
2200 rm -rf $3/$2
2201 mkdir -p $3/$2
2202 cp -a $1/$2/receipt $3/$2
2203 [ -f $1/$2/description.txt ] && \
2204 cp -a $1/$2/description.txt $3/$2
2205 if [ -d "$1/$2/stuff" ]; then
2206 cp -a $1/$2/stuff $3/$2
2207 fi
2210 ########################################################################
2211 # TAZWOK MAIN FUNCTIONS
2212 ########################
2214 clean()
2216 cd $WOK/$PACKAGE
2217 ls -A $WOK/$PACKAGE | grep -q -v -e ^receipt$ -e ^description.txt$ \
2218 -e ^stuff$ || return
2220 [ "$COMMAND" = clean-wok ] || report step "Cleaning $PACKAGE"
2221 # Check for clean_wok function.
2222 if grep -q ^clean_wok $RECEIPT; then
2223 clean_wok
2224 fi
2225 # Clean should only have a receipt, stuff and optionals desc/md5.
2226 for f in `ls .`
2227 do
2228 case $f in
2229 receipt|stuff|description.txt|md5)
2230 continue ;;
2231 *)
2232 rm -rf $f ;;
2233 esac
2234 done
2235 [ "$COMMAND" != clean-wok ] && report end-step
2238 # Configure and make a package with the receipt.
2239 compile_package()
2241 check_for_package_on_cmdline
2243 # Include the receipt to get all needed variables and functions
2244 # and cd into the work directory to start the work.
2245 check_for_receipt
2246 source_receipt
2248 # Log the package name and date.
2249 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
2250 echo "package $PACKAGE (compile)" >> $LOG
2252 # Set wanted $src variable to help compiling.
2253 [ ! "$src" ] && set_src_path
2254 check_for_build_depends || return 1
2255 check_for_wanted
2256 unset target
2257 check_for_tarball && check_for_compile_rules
2260 # Cook command also include all features to manage lists which keep
2261 # track of wok/packages state.
2262 cook()
2264 cook_code=
2265 set_common_path
2266 check_for_receipt
2267 source_receipt
2269 # Define log path and start report.
2270 for i in $(look_for_rwanted) $PACKAGE; do
2271 rm -f $LOCAL_REPOSITORY/log/$i.html
2272 done
2273 report sublog $LOCAL_REPOSITORY/log/$PACKAGE.html
2274 echo "$PACKAGE" > $LOCAL_REPOSITORY/log/package
2275 report step "Cooking $PACKAGE"
2276 report open-bloc
2278 clean $PACKAGE
2279 [ -s $tmp/cooklist ] && sed "/^$PACKAGE$/d" -i $tmp/cooklist
2281 if compile_package; then
2282 remove_src
2283 refresh_packages_from_compile
2284 gen_package
2286 # Update packages-incoming repository.
2287 store_pkgname=$PACKAGE
2288 pkg_repository=$INCOMING_REPOSITORY
2289 update_packages_db
2291 PACKAGE=$store_pkgname
2292 unset store_pkgname
2294 # Upgrade to cooked packages if it was previously installed.
2295 report step "Looking for package(s) to upgrade"
2296 for pkg in $(look_for_rwanted) $PACKAGE; do
2297 if [ -f $INSTALLED/$pkg/receipt ]; then
2298 tazpkg get-install $pkg --forced
2299 fi
2300 done
2301 report end-step
2302 else
2303 set_pkg_broken
2304 cook_code=1
2305 fi
2307 # Remove build_depends in cook mode (if in cooklist, it's done when
2308 # checking build_depends of next package and we remove only unneeded
2309 # packages to keep chroot minimal and gain some time).
2310 if [ "$COMMAND" = cook ]; then
2311 remove_build_depends $MISSING_PACKAGE
2312 [ -x /usr/bin/clean-chroot ] && clean-chroot
2313 fi
2315 # Regen the cooklist if it was planned and command is not cook.
2316 [ "$regen_cooklist" ] && unset regen_cooklist &&
2317 [ "$COMMAND" != cook ] && sort_cooklist
2319 # Some hacks to set the bloc & function status as failed if cook has
2320 # failed.
2321 report_return_code=$cook_code
2322 report close-bloc
2323 report end-sublog
2324 rm -f $LOCAL_REPOSITORY/log/package
2325 return $cook_code
2328 cook_list()
2330 if [ -s $tmp/cooklist ]; then
2331 if [ -f /usr/bin/tazchroot ]; then
2332 # Note : options -main variables- are automatically kept by
2333 # the sub-applications tazchroot/tazwok; as well as report data.
2334 cd $LOCAL_REPOSITORY
2335 [ ! -f tazchroot.conf ] && configure_tazchroot
2336 tazchroot tazwok cook-list --SLITAZ_DIR=$SLITAZ_DIR --SLITAZ_VERSION=$SLITAZ_VERSION ${undigest:+ --undigest=$undigest}
2337 return
2338 fi
2339 while [ -s $tmp/cooklist ]; do
2340 PACKAGE=$(sed 1!d $tmp/cooklist)
2341 cook
2342 done
2343 remove_build_depends $MISSING_PACKAGE $remove_later
2344 [ -x /usr/bin/clean-chroot ] && clean-chroot
2345 else
2346 echo "Nothing to cook."
2347 return
2348 fi
2351 configure_tazchroot()
2353 cat > $LOCAL_REPOSITORY/tazchroot.conf << EOF
2354 # Tazchroot configuration file - created by tazwok.
2356 # Local repository definition.
2357 SLITAZ_DIR=$SLITAZ_DIR
2358 SLITAZ_VERSION=$SLITAZ_VERSION
2359 LOCAL_REPOSITORY=$SLITAZ_DIR/${undigest:-$SLITAZ_VERSION}
2360 ${USE_ONLINE_PKG:+USE_ONLINE_PKG=$USE_ONLINE_PKG}
2361 ${undigest:+undigest=$undigest}
2362 ${ref_USE_ONLINE_PKG:+ref_USE_ONLINE_PKG=$ref_USE_ONLINE_PKG}
2364 # Chroot path.
2365 # You can use a chroot into /tmp if it's mounted in RAM
2366 # to speed-up the process, be sure you have a free GB.
2367 # (minimal chroot is like 150~200MB, can be a lot more during cook)
2368 # chroot_dir=/tmp/chroot-${undigest:-$SLITAZ_VERSION}
2369 chroot_dir=\$LOCAL_REPOSITORY/chroot
2371 # Default scripts path (these scripts are added to the
2372 # $chroot_dir/usr/bin and can be called with tazchroot script).
2373 script_dir=/usr/lib/slitaz/chroot-scripts/tazwok
2375 # List of directories to mount.
2376 list_dir="$LOCAL_REPOSITORY
2377 $SLITAZ_LOG$( [ "$undigest" ] && echo -e "\n$SLITAZ_DIR/$SLITAZ_VERSION/packages" )"
2379 create_chroot()
2381 mkdir -p \$chroot_dir
2382 for pkg in \$(tazwok build-depends toolchain --SLITAZ_DIR=\$SLITAZ_DIR --SLITAZ_VERSION=\$SLITAZ_VERSION${undigest:+ --undigest=\$undigest}); do
2383 tazpkg get-install \$pkg --root="\$chroot_dir"
2384 done
2386 # Store list of installed packages needed by cleanchroot.
2387 ls -1 \$chroot_dir/\$INSTALLED > \$chroot_dir/\$LOCALSTATE/chroot-pkgs
2389 sed -e "s~^SLITAZ_DIR=.*~SLITAZ_DIR=\$SLITAZ_DIR~" \\
2390 -e "s/^SLITAZ_VERSION=.*/SLITAZ_VERSION=\$SLITAZ_VERSION/" \\
2391 -i \$chroot_dir/etc/slitaz/slitaz.conf
2392 echo \$SLITAZ_VERSION > \$chroot_dir/etc/slitaz-release
2393 $( [ "$undigest" ] && echo ' echo "undigest='"$undigest"'" >> $chroot_dir/etc/slitaz/tazwok.conf')
2394 sed 's/LC_ALL/LC_ALL=POSIX/' -i \$chroot_dir/etc/profile
2396 # The build bot may run in a sandbox: link sandbox lockfile.
2397 ln -s \$LOCAL_REPOSITORY/sandbox/proc/1 \$chroot_dir/proc/1
2400 mount_chroot()
2402 cp -a /etc/resolv.conf \$chroot_dir/etc/resolv.conf
2403 $( if [ "$USE_ONLINE_PKG" ]; then
2404 echo ' echo "$USE_ONLINE_PKG" > $chroot_dir$LOCALSTATE/mirror'
2405 else
2406 echo ' echo $LOCAL_REPOSITORY/packages" > $chroot_dir$LOCALSTATE/mirror'
2407 fi
2409 mkdir -p \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming
2410 echo "\$LOCAL_REPOSITORY/packages-incoming" > \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming/mirror
2411 $( if [ "$undigest" ]; then
2412 echo ' mkdir -p $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION'
2413 if [ "$ref_USE_ONLINE_PKG" ]; then
2414 echo ' echo "$ref_USE_ONLINE_PKG" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror'
2415 else
2416 echo ' echo "$ref_LOCAL_REPOSITORY/packages" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror'
2417 fi
2418 fi )
2419 echo -e "\${LOCAL_REPOSITORY##*/}-incoming\nmain" > \$chroot_dir\$LOCALSTATE/priority
2420 mount -o bind /proc \$chroot_dir/proc
2421 mount -o bind /sys \$chroot_dir/sys
2422 mount -o bind /dev/pts \$chroot_dir/dev/pts
2423 mount -o bind /dev/shm \$chroot_dir/dev/shm
2424 for dir in \$list_dir; do
2425 mkdir -p \$dir \$chroot_dir\$dir
2426 mount \$dir \$chroot_dir\$dir
2427 done
2430 umount_chroot()
2432 for dir in \$list_dir; do
2433 umount \$chroot_dir\$dir
2434 done
2435 umount \$chroot_dir/dev/shm
2436 umount \$chroot_dir/dev/pts
2437 umount \$chroot_dir/sys
2438 umount \$chroot_dir/proc
2440 EOF
2443 ########################################################################
2444 ######################### END OF NEW FUNCTIONS #########################
2445 ########################################################################
2447 # List packages providing a virtual package.
2448 whoprovide()
2450 local i;
2451 for i in $(fgrep -l PROVIDE $WOK/*/receipt); do
2452 . $i
2453 case " $PROVIDE " in
2454 *\ $1\ *|*\ $1:*) echo $(basename $(dirname $i));;
2455 esac
2456 done
2459 ########################################################################
2460 # TAZWOK COMMANDS
2461 ########################
2463 case "$COMMAND" in
2464 stats)
2465 # Tazwok general statistics from the wok config file.
2467 get_tazwok_config
2468 echo -e "\n\033[1mTazwok configuration statistics\033[0m
2469 ================================================================================
2470 Wok directory : $WOK
2471 Packages repository : $PACKAGES_REPOSITORY
2472 Incoming repository : $INCOMING_REPOSITORY
2473 Sources repository : $SOURCES_REPOSITORY
2474 Log directory : $LOCAL_REPOSITORY/log
2475 Packages in the wok : `ls -1 $WOK | wc -l`
2476 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2477 Incoming packages : `ls -1 $INCOMING_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2478 ================================================================================\n"
2479 ;;
2480 edit)
2481 get_tazwok_config
2482 check_for_package_on_cmdline
2483 check_for_receipt
2484 $EDITOR $WOK/$PACKAGE/receipt
2485 ;;
2486 build-depends)
2487 # List dependencies to rebuild wok, or only a package.
2488 get_tazwok_config
2489 report(){ : ; }
2490 if [ ! "$PACKAGE" ] || [ "$PACKAGE" = toolchain ]; then
2491 scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
2492 --look_for=dep --with_dev --with_args
2493 else
2494 check_for_package_on_cmdline
2495 scan $PACKAGE --look_for=bdep --with_dev
2496 fi
2497 ;;
2498 gen-cooklist)
2499 check_root
2500 get_options_list="pkg"
2501 get_tazwok_config
2502 report(){ : ; }
2503 if ! [ "$pkg" ]; then
2504 if [ ! "$LIST" ] || [ "$LIST" = toolchain ]; then
2505 pkg="$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA"
2506 else
2507 check_for_list
2508 fi
2509 fi
2510 gen_cook_list
2511 ;;
2512 check-depends)
2513 # Check package depends /!\.
2514 get_tazwok_config
2515 echo ""
2516 echo -e "\033[1mCheck every receipt for DEPENDS - doesn't scan ELF files\033[0m
2517 ================================================================================"
2518 TMPDIR=/tmp/tazwok$$
2519 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
2521 # Build ALL_DEPENDS variable.
2522 scan_dep()
2524 local i
2525 ALL_DEPENDS="$ALL_DEPENDS$PACKAGE "
2526 for i in $DEPENDS $SUGGESTED ; do
2527 case " $ALL_DEPENDS " in
2528 *\ $i\ *) continue;;
2529 esac
2530 [ -d $WOK/$i ] || {
2531 ALL_DEPENDS="$ALL_DEPENDS$i "
2532 continue
2534 DEPENDS=""
2535 SUGGESTED=""
2536 . $WOK/$i/receipt
2537 scan_dep
2538 done
2541 # Check for ELF file.
2542 is_elf()
2544 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
2547 # Print shared library dependencies.
2548 ldd()
2550 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
2553 mkdir $TMPDIR
2554 cd $TMPDIR
2555 for i in $LOCALSTATE/files.list.lzma \
2556 $LOCALSTATE/undigest/*/files.list.lzma ; do
2557 [ -f $i ] && lzma d $i -so >> files.list
2558 done
2559 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
2560 tazpkg extract $pkg > /dev/null 2>&1
2561 . */receipt
2562 ALL_DEPENDS="$DEFAULT_DEPENDS "
2563 scan_dep
2564 find */fs -type f | while read file ; do
2565 is_elf $file || continue
2566 case "$file" in
2567 *.o|*.ko|*.ko.gz) continue;;
2568 esac
2569 ldd $file | while read lib rem; do
2570 case "$lib" in
2571 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
2572 continue;;
2573 esac
2574 for dep in $(fgrep $lib files.list | cut -d: -f1); do
2575 case " $ALL_DEPENDS " in
2576 *\ $dep\ *) continue 2;;
2577 esac
2578 for vdep in $(fgrep $dep $LOCALSTATE/packages.equiv | cut -d= -f1); do
2579 case " $ALL_DEPENDS " in
2580 *\ $vdep\ *) continue 3;;
2581 esac
2582 done
2583 done
2584 [ -n "$dep" ] || dep="UNKNOWN"
2585 echo "$(basename $pkg): ${file#*fs} depends on package $dep for the shared library $lib"
2586 done
2587 done
2588 rm -rf */
2589 done
2590 cd /tmp
2591 rm -rf $TMPDIR
2592 ;;
2593 check)
2594 # Check wok consistency.
2595 get_tazwok_config
2596 echo ""
2597 echo -e "\033[1mWok and packages checking\033[0m
2598 ================================================================================"
2599 cd $WOK
2600 for pkg in $(ls)
2601 do
2602 [ -f $pkg/receipt ] || continue
2603 RECEIPT= $pkg/receipt
2604 source_receipt
2605 [ "$PACKAGE" = "$pkg" ] || echo "Package $PACKAGE should be $pkg" >&2
2606 [ -n "$VERSION" ] || echo "Package $PACKAGE has no VERSION" >&2
2607 [ -n "$PACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded PACKED_SIZE" >&2
2608 [ -n "$UNPACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded UNPACKED_SIZE" >&2
2609 [ -n "$EXTRAVERSION" ] && echo "Package $PACKAGE has hardcoded EXTRAVERSION" >&2
2610 if [ -n "$WANTED" ]; then
2611 if [ ! -f $WANTED/receipt ]; then
2612 echo "Package $PACKAGE wants unknown $WANTED package" >&2
2613 else
2614 BASEVERSION=$(. $WANTED/receipt ; echo $VERSION)
2615 if [ "$VERSION" = "$WANTED" ]; then
2616 # BASEVERSION is computed in receipt
2617 fgrep -q '_pkg=' $pkg/receipt &&
2618 BASEVERSION=$VERSION
2619 fi
2620 if [ "$VERSION" != "$BASEVERSION" ]; then
2621 echo "Package $PACKAGE ($VERSION) wants $WANTED ($BASEVERSION)" >&2
2622 fi
2623 fi
2624 fi
2626 if [ -n "$CATEGORY" ]; then
2627 case " $(echo $CATEGORIES) " in
2628 *\ $CATEGORY\ *);;
2629 *) echo "Package $PACKAGE has an invalid CATEGORY" >&2;;
2630 esac
2631 else
2632 echo"Package $PACKAGE has no CATEGORY" >&2
2633 fi
2634 [ -n "$SHORT_DESC" ] || echo "Package $PACKAGE has no SHORT_DESC" >&2
2635 [ -n "$MAINTAINER" ] || echo "Package $PACKAGE has no MAINTAINER" >&2
2636 case "$WGET_URL" in
2637 ftp*|http*) busybox wget -s $WGET_URL 2> /dev/null ||
2638 echo "Package $PACKAGE has a wrong WGET_URL" >&2;;
2639 '') ;;
2640 *) echo "Package $PACKAGE has an invalid WGET_URL" >&2;;
2641 esac
2642 case "$WEB_SITE" in
2643 ftp*|http*);;
2644 '') echo "Package $PACKAGE has no WEB_SITE" >&2;;
2645 *) echo "Package $PACKAGE has an invalid WEB_SITE" >&2;;
2646 esac
2647 case "$MAINTAINER" in
2648 *\<*|*\>*) echo "Package $PACKAGE has an invalid MAINTAINER: $MAINTAINER" >&2;;
2649 esac
2650 case "$MAINTAINER" in
2651 *@*);;
2652 *) echo "Package $PACKAGE MAINTAINER is not an email address" >&2;;
2653 esac
2654 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2655 for i in $DEPENDS; do
2656 [ -d $i ] && continue
2657 [ -n "$(whoprovide $i)" ] && continue
2658 echo -e "$MSG $i"
2659 MSG=""
2660 done
2661 MSG="Missing build dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2662 for i in $BUILD_DEPENDS; do
2663 [ -d $i ] && continue
2664 [ -n "$(whoprovide $i)" ] && continue
2665 echo -e "$MSG $i"
2666 MSG=""
2667 done
2668 MSG="Dependency loop between $PACKAGE and :\n"
2669 ALL_DEPS=""
2670 check_for_deps_loop $PACKAGE $DEPENDS
2671 [ -d $WOK/$pkg/taz ] && for i in $BUILD_DEPENDS; do
2672 [ $WOK/$pkg/taz -nt $INSTALLED/$i/files.list ] && continue
2673 echo "$pkg should be rebuilt after $i installation"
2674 done
2675 done
2676 ;;
2677 list)
2678 # List packages in wok directory. User can specify a category.
2680 get_tazwok_config
2681 if [ "$2" = "category" ]; then
2682 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
2683 exit 0
2684 fi
2685 # Check for an asked category.
2686 if [ -n "$2" ]; then
2687 ASKED_CATEGORY=$2
2688 echo ""
2689 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
2690 echo "================================================================================"
2691 for pkg in $WOK/*
2692 do
2693 [ ! -f $pkg/receipt ] && continue
2694 . $pkg/receipt
2695 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
2696 echo -n "$PACKAGE"
2697 echo -e "\033[28G $VERSION"
2698 packages=$(($packages+1))
2699 fi
2700 done
2701 echo "================================================================================"
2702 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
2703 else
2704 # By default list all packages and version.
2705 echo ""
2706 echo -e "\033[1mList of packages in the wok\033[0m"
2707 echo "================================================================================"
2708 for pkg in $WOK/*
2709 do
2710 [ ! -f $pkg/receipt ] && continue
2711 . $pkg/receipt
2712 echo -n "$PACKAGE"
2713 echo -en "\033[28G $VERSION"
2714 echo -e "\033[42G $CATEGORY"
2715 packages=$(($packages+1))
2716 done
2717 echo "================================================================================"
2718 echo -e "$packages packages available in the wok.\n"
2719 fi
2720 ;;
2721 info)
2722 # Information about a package.
2724 get_tazwok_config
2725 check_for_package_on_cmdline
2726 check_for_receipt
2727 . $WOK/$PACKAGE/receipt
2728 echo ""
2729 echo -e "\033[1mTazwok package information\033[0m
2730 ================================================================================
2731 Package : $PACKAGE
2732 Version : $VERSION
2733 Category : $CATEGORY
2734 Short desc : $SHORT_DESC
2735 Maintainer : $MAINTAINER"
2736 if [ ! "$WEB_SITE" = "" ]; then
2737 echo "Web site : $WEB_SITE"
2738 fi
2739 if [ ! "$DEPENDS" = "" ]; then
2740 echo "Depends : $DEPENDS"
2741 fi
2742 if [ ! "$WANTED" = "" ]; then
2743 echo "Wanted src : $WANTED"
2744 fi
2745 echo "================================================================================"
2746 echo ""
2747 ;;
2748 check-log)
2749 # We just cat the file log to view process info.
2751 get_tazwok_config
2752 if [ ! -f "$LOG" ]; then
2753 echo -e "\nNo process log found. The package is probably not cooked.\n" >&2
2754 exit 1
2755 else
2756 echo ""
2757 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
2758 echo "================================================================================"
2759 cat $LOG
2760 echo "================================================================================"
2761 echo ""
2762 if [ -s "$WOK/$PACKAGE/warning.txt" ]; then
2763 echo -e "\033[1mCook warning(s) for :\033[0m $PACKAGE"
2764 echo "================================================================================"
2765 cat "$WOK/$PACKAGE/warning.txt"
2766 echo "================================================================================"
2767 echo ""
2768 fi
2769 fi
2770 ;;
2771 search)
2772 # Search for a package by pattern or name.
2774 get_tazwok_config
2775 if [ -z "$2" ]; then
2776 echo -e "\nPlease specify a pattern or a package name to search." >&2
2777 echo -e "Example : 'tazwok search gcc'.\n" >&2
2778 exit 1
2779 fi
2780 echo ""
2781 echo -e "\033[1mSearch result for :\033[0m $2"
2782 echo "================================================================================"
2783 list=`ls -1 $WOK | fgrep $2`
2784 for pkg in $list
2785 do
2786 . $WOK/$pkg/receipt
2787 echo -n "$PACKAGE "
2788 echo -en "\033[24G $VERSION"
2789 echo -e "\033[42G $CATEGORY"
2790 packages=$(($PACKAGEs+1))
2791 done
2792 echo "================================================================================"
2793 echo "$packages packages found for : $2"
2794 echo ""
2795 ;;
2796 compile)
2797 # Configure and make a package with the receipt.
2799 get_tazwok_config
2800 source_lib report
2801 report start
2802 compile_package
2803 ;;
2804 genpkg)
2805 # Generate a package.
2807 get_tazwok_config
2808 source_lib report
2809 report start
2810 gen_package
2811 ;;
2812 cook)
2813 # Compile and generate a package. Just execute tazwok with
2814 # the good commands.
2816 check_root
2817 get_tazwok_config
2818 source_lib report
2819 report start
2820 update_wan_db
2821 check_for_commit
2822 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
2823 [ "$plan_sort_wandb" ] && sort -o $wan_db $wan_db && unset plan_sort_wandb
2824 if [ "$plan_regen_cookorder" ]; then
2825 [ "$(sed 1!d $cookorder)" = "#PlanSort" ] || \
2826 sed 1i"#PlanSort" -i $cookorder
2827 fi
2828 cook
2829 ;;
2830 sort-cooklist)
2831 check_root
2832 get_tazwok_config
2833 check_for_list
2834 report(){ : ; }
2835 # When using sort-cooklist, the script should behave as for gen-cooklist
2836 # The only difference between these two is where the output is sent.
2837 COMMAND=gen-cooklist
2838 gen_cook_list
2839 cp -af $tmp/cooklist $LIST
2840 ;;
2841 cook-list)
2842 # Cook all packages listed in a file or in default cooklist.
2843 check_root
2844 get_options_list="pkg forced"
2845 get_tazwok_config
2846 source_lib report
2847 report start
2848 if ! [ "$pkg" ]; then
2849 [ "$LIST" ] && check_for_list
2850 fi
2851 gen_cook_list
2852 cook_list
2853 ;;
2854 clean)
2855 # Clean up a package work directory + those which want it.
2857 get_tazwok_config
2858 check_for_package_on_cmdline
2859 check_for_receipt
2860 source_lib report
2861 report start
2862 . $RECEIPT
2863 clean
2864 ;;
2865 gen-clean-wok)
2866 # Generate a clean wok from the current wok by copying all receipts
2867 # and stuff directory.
2869 get_tazwok_config
2870 source_lib report
2871 report start
2872 if [ -z "$ARG" ]; then
2873 echo -e "\nPlease specify the destination for the new clean wok.\n" >&2
2874 exit 1
2875 else
2876 dest=$ARG
2877 mkdir -p $dest
2878 fi
2879 report step "Creating clean wok in : $dest"
2880 for pkg in `ls -1 $WOK`
2881 do
2882 copy_cooking_stuff $WOK $pkg $dest
2883 done
2884 [ -d $WOK/.hg ] && cp -a $WOK/.hg $dest
2885 report end-step
2886 echo "Packages cleaned : `ls -1 $dest | wc -l`"
2887 echo ""
2888 ;;
2889 clean-wok)
2890 # Clean all packages in the work directory.
2892 get_tazwok_config
2893 source_lib report
2894 report start
2895 report step "Cleaning wok"
2896 for PACKAGE in `ls -1 $WOK`
2897 do
2898 set_common_path
2899 source_receipt
2900 clean
2901 done
2902 echo "`ls -1 $WOK | wc -l` packages cleaned."
2903 ;;
2904 clean-src)
2905 # Remove tarball unrelated to wok receipts from src repo.
2906 check_root
2907 get_options_list="forced"
2908 get_tazwok_config
2909 cd $SOURCES_REPOSITORY
2910 echo -n "Checking $SOURCES_REPOSITORY..."
2911 for TARBALL in *; do
2912 [ "$TARBALL" = sources.list ] && continue
2913 grep -q $'\t'$TARBALL$ $SOURCES_REPOSITORY/sources.list || \
2914 echo $TARBALL >> $tmp/obsolete
2915 done
2916 status
2917 if ! [ -f $tmp/obsolete ]; then
2918 echo "No sources need to be removed."
2919 exit 1
2920 fi
2921 echo ""
2922 echo -e "\033[1mObsolete/unrelated-to-wok sources :\033[0m"
2923 horizontal_line
2924 cat $tmp/obsolete
2925 horizontal_line
2926 echo "$(wc -l $tmp/obsolete | cut -f1 -d' ') tarballs to remove."
2927 echo ""
2928 echo -n "Please confirm before removing (type uppercase YES): "
2929 read answer
2930 if [ "$answer" = YES ]; then
2931 echo -n "Removing old sources..."
2932 cat $tmp/obsolete | while read i; do
2933 rm -f $SOURCES_REPOSITORY/$i
2934 done
2935 status
2936 fi
2937 ;;
2938 gen-list)
2939 get_tazwok_config
2940 if [ "$2" ]; then
2941 if [ -d "$2" ]; then
2942 pkg_repository=$2
2943 else
2944 echo -e "\nUnable to find directory : $2\n" >&2
2945 exit 1
2946 fi
2947 fi
2949 source_lib report
2950 report start
2951 if [ "$pkg_repository" ]; then
2952 gen_packages_db
2953 else
2954 pkg_repository=$PACKAGES_REPOSITORY && gen_packages_db
2955 pkg_repository=$INCOMING_REPOSITORY && gen_packages_db
2956 fi
2957 ;;
2958 check-list)
2959 # The directory to move into by default is the repository,
2960 # if $2 is not empty cd into $2.
2962 get_tazwok_config
2963 if [ "$2" ]; then
2964 if [ -d "$2" ]; then
2965 pkg_repository=$2
2966 else
2967 echo -e "\nUnable to find directory : $2\n" >&2
2968 exit 1
2969 fi
2970 fi
2972 source_lib report
2973 report start
2974 if [ "$pkg_repository" ]; then
2975 update_packages_db
2976 else
2977 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2978 pkg_repository=$INCOMING_REPOSITORY && update_packages_db
2979 fi
2980 ;;
2981 new-tree)
2982 # Just create a few directories and generate an empty receipt to prepare
2983 # the creation of a new package.
2985 get_tazwok_config
2986 check_for_package_on_cmdline
2987 clean_wok=$LOCAL_REPOSITORY/clean-wok
2988 if [ -d $clean_wok/$PACKAGE ]; then
2989 echo -e "\n$PACKAGE package tree already exists.\n" >&2
2990 exit 1
2991 fi
2992 echo "Creating : $clean_wok/$PACKAGE"
2993 mkdir $clean_wok/$PACKAGE
2994 cd $clean_wok/$PACKAGE
2995 echo -n "Preparing the receipt..."
2997 # Default receipt begin.
2999 echo "# SliTaz package receipt." > receipt
3000 echo "" >> receipt
3001 echo "PACKAGE=\"$PACKAGE\"" >> receipt
3002 # Finish the empty receipt.
3003 cat >> receipt << "EOF"
3004 VERSION=""
3005 CATEGORY=""
3006 SHORT_DESC=""
3007 MAINTAINER=""
3008 DEPENDS=""
3009 TARBALL="$PACKAGE-$VERSION.tar.gz"
3010 WEB_SITE=""
3011 WGET_URL=""
3013 # Rules to configure and make the package.
3014 compile_rules()
3016 cd $src
3017 ./configure && make && make install
3020 # Rules to gen a SliTaz package suitable for Tazpkg.
3021 genpkg_rules()
3023 mkdir -p $fs/usr
3024 cp -a $_pkg/usr/bin $fs/usr
3027 EOF
3029 # Default receipt end.
3031 status
3032 # Interactive mode, asking and seding.
3033 if [ "$3" = "--interactive" ]; then
3034 echo "Entering interactive mode..."
3035 echo "================================================================================"
3036 echo "Package : $PACKAGE"
3037 # Version.
3038 echo -n "Version : " ; read anser
3039 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
3040 # Category.
3041 echo -n "Category : " ; read anser
3042 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
3043 # Short description.
3044 echo -n "Short desc : " ; read anser
3045 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
3046 # Maintainer.
3047 echo -n "Maintainer : " ; read anser
3048 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
3049 # Web site.
3050 echo -n "Web site : " ; read anser
3051 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
3052 echo ""
3053 # Wget URL.
3054 echo "Wget URL to download source tarball."
3055 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
3056 echo -n "Wget url : " ; read anser
3057 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
3058 # Ask for a stuff dir.
3059 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
3060 if [ "$anser" = "y" ]; then
3061 echo -n "Creating the stuff directory..."
3062 mkdir stuff && status
3063 fi
3064 # Ask for a description file.
3065 echo -n "Are you going to write a description ? (y/N) : " ; read anser
3066 if [ "$anser" = "y" ]; then
3067 echo -n "Creating the description.txt file..."
3068 echo "" > description.txt && status
3069 fi
3070 echo "================================================================================"
3071 echo ""
3072 fi
3073 ;;
3074 remove)
3075 # Remove a package from the wok.
3077 get_tazwok_config
3078 check_for_package_on_cmdline
3079 echo ""
3080 echo -n "Please confirm deletion (y/N) : "; read anser
3081 if [ "$anser" = "y" ]; then
3082 echo -n "Removing $PACKAGE..."
3083 rm -rf $WOK/$PACKAGE && status
3084 echo ""
3085 fi
3086 ;;
3087 update-wok)
3088 # Pull and update a Hg wok.
3089 get_options_list="local"
3090 get_tazwok_config
3091 source_lib report
3092 report start
3093 clean_wok=$LOCAL_REPOSITORY/clean-wok
3094 cd $clean_wok
3095 if ! [ "$local" ]; then
3096 if [ "$WOK_UPDATE_METHOD" = hg ]; then
3097 if ! [ -f "$INSTALLED/mercurial/receipt" ]; then
3099 # Auto-install only if we are in a cook chroot.
3100 if [ -x /usr/bin/clean-chroot ]; then
3101 tazpkg get-install mercurial
3102 else
3103 echo "" >&2
3104 echo "You need to install mercurial to get wok from hg (recommended). Otherwise, you can switch wok get method to \"tarball\" into $LOCAL_REPOSITORY/tazwok.conf (per-repository configuration, if it doesn't exist) or /etc/slitaz/tazwok.conf (global configuration)." | fold -s >&2
3105 echo "">&2
3106 exit 1
3107 fi
3108 fi
3110 report step "Getting wok changes using hg"
3111 if [ -d .hg ]; then
3112 hg pull -u || exit 1
3113 else
3114 hg clone $HG_WOK . || exit 1
3115 fi
3116 report end-step
3117 [ -x /usr/bin/clean-chroot ] && clean-chroot
3118 else
3119 report step "Getting wok changes using tarball"
3120 { mkdir .tmp && cd .tmp
3121 wget "$TARBALL_WOK" &&
3122 case $TARBALL_WOK in
3123 *bz2) tar xjf *.bz2 -C wok; rm *.bz2;;
3124 *lzma) unlzma -c *.lzma | tar xf - -C wok; rm *.lzma ;;
3125 *gz) tar xzf *.gz -C wok; rm*.gz ;;
3126 esac &&
3127 rm -r $(ls -d $clean_wok/*) &&
3128 cp -a wok/* $clean_wok &&
3129 cd .. &&
3130 rm -r .tmp
3131 } || { echo "That's not cool: it fails!" >&2
3132 report end-step
3133 exit 1; }
3134 report end-step
3135 fi
3136 fi
3137 report step "Appending changes to wok"
3139 # Handle removed files/dir.
3140 cd $WOK
3141 for dir in *; do
3142 [ -d "$clean_wok/$dir" ] || rm -rf $dir
3143 done
3144 for file in */receipt */description.txt; do
3145 [ -f "$clean_wok/$file" ] || rm -rf $file
3146 done
3147 for i in $(find */stuff 2>/dev/null); do
3148 [ -e "$clean_wok/$i" ] || rm -rf $i
3149 done
3151 cp -a $clean_wok/* $WOK
3152 report end-step
3153 ;;
3154 maintainers)
3155 get_tazwok_config
3156 echo ""
3157 echo "List of maintainers for: $WOK"
3158 echo "================================================================================"
3159 touch /tmp/slitaz-maintainers
3160 for pkg in $WOK/*
3161 do
3162 . $pkg/receipt
3163 if ! fgrep -q "$MAINTAINER" /tmp/slitaz-maintainers; then
3164 echo "$MAINTAINER" >> /tmp/slitaz-maintainers
3165 echo "$MAINTAINER"
3166 fi
3167 done
3168 echo "================================================================================"
3169 echo "Maintainers: `cat /tmp/slitaz-maintainers | wc -l`"
3170 echo ""
3171 # Remove tmp files
3172 rm -f /tmp/slitaz-maintainers
3173 ;;
3174 maintained-by)
3175 # Search for packages maintained by a contributor.
3176 get_tazwok_config
3177 if [ ! -n "$2" ]; then
3178 echo "Specify a name or email of a maintainer." >&2
3179 exit 1
3180 fi
3181 echo "Maintainer packages"
3182 echo "================================================================================"
3183 for pkg in $WOK/*
3184 do
3185 . $pkg/receipt
3186 if echo "$MAINTAINER" | fgrep -q "$2"; then
3187 echo "$PACKAGE"
3188 packages=$(($PACKAGEs+1))
3189 fi
3190 done
3191 echo "================================================================================"
3192 echo "Packages maintained by $2: $PACKAGEs"
3193 echo ""
3194 ;;
3195 tags)
3196 get_tazwok_config
3197 echo -e "\n\033[1mTags list :\033[0m"
3198 horizontal_line
3199 cd $WOK
3200 for i in */receipt; do
3201 unset TAGS
3202 source $i
3203 for t in $TAGS; do
3204 grep -q ^$t$ $tmp/tags && continue
3205 echo $t | tee -a $tmp/tags
3206 done
3207 done
3208 horizontal_line
3209 echo "$(wc -l $tmp/tags | cut -f1 -d ' ') tags listed."
3210 ;;
3211 check-src)
3212 # Verify if upstream package is still available.
3214 get_tazwok_config
3215 check_for_package_on_cmdline
3216 check_for_receipt
3217 source_receipt
3218 check_src()
3220 for url in $@; do
3221 busybox wget -s $url 2>/dev/null && break
3222 done
3224 if [ "$WGET_URL" ];then
3225 echo -n "$PACKAGE : "
3226 check_src $WGET_URL
3227 status
3228 else
3229 echo "No tarball to check for $PACKAGE"
3230 fi
3231 ;;
3232 get-src)
3233 check_root
3234 get_options_list="target nounpack"
3235 get_tazwok_config
3236 check_for_package_on_cmdline
3237 check_for_receipt
3238 source_receipt
3239 if [ "$WGET_URL" ];then
3240 source_lib report
3241 report start
3242 check_for_tarball
3243 else
3244 echo "No tarball to download for $PACKAGE"
3245 fi
3246 ;;
3247 check-commit)
3248 check_root
3249 get_options_list="missing forced"
3250 get_tazwok_config
3251 source_lib report
3252 report start
3253 if [ "$forced" ]; then
3254 rm -f $WOK/*/md5
3255 unset forced
3256 fi
3257 if [ "$missing" ]; then
3258 pkg=$(ls -1 $WOK)
3259 else
3260 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3261 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3262 } | sort -u)"
3263 fi
3264 gen_cook_list
3265 ;;
3266 cook-commit)
3267 check_root
3268 get_options_list="missing forced"
3269 get_tazwok_config
3270 source_lib report
3271 report start
3272 if [ "$forced" ]; then
3273 rm -f $WOK/*/md5
3274 unset forced
3275 fi
3276 if [ "$missing" ]; then
3277 pkg=$(ls -1 $WOK)
3278 else
3279 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3280 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3281 } | sort -u)"
3282 fi
3283 gen_cook_list
3284 cook_list
3285 ;;
3286 cook-all)
3287 check_root
3288 get_options_list="forced missing"
3289 get_tazwok_config
3290 source_lib report
3291 report start
3292 if [ "$missing" ]; then
3293 pkg=$(ls -1 $WOK)
3294 else
3295 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3296 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3297 } | sort -u)"
3298 fi
3299 gen_cook_list
3300 cook_list
3301 ;;
3302 gen-wok-db)
3303 check_root
3304 get_tazwok_config
3305 source_lib report
3306 report start
3307 gen_wok_db
3308 ;;
3309 report)
3310 get_tazwok_config
3311 cd $PACKAGES_REPOSITORY
3312 if [ "$2" ]; then
3313 case $2 in
3314 commit|cooklist|incoming|broken|blocked)
3315 show="$2"
3316 ;;
3317 *)
3318 echo "usage : tazwok report [commit|cooklist|incoming|broken|blocked]" >&2
3319 exit 1
3320 ;;
3321 esac
3322 else
3323 show="commit cooklist incoming broken blocked"
3324 fi
3325 for i in $show; do
3326 if [ -s $i ]; then
3327 echo ""
3328 echo -e "\033[1m$i\033[0m"
3329 echo "================================================================================"
3330 cat $i
3331 echo "================================================================================"
3332 echo ""
3333 fi
3334 done
3335 ;;
3336 check-incoming)
3337 check_root
3338 get_options_list="forced"
3339 get_tazwok_config
3340 source_lib report
3341 report start
3342 [ -f $LOCAL_RESOSITORY/incoming ] && rm [ -f $LOCAL_REPOSITORY/incoming ]
3343 report step "Checking $INCOMING_REPOSITORY"
3344 report open-bloc
3345 [ -f $LOCAL_REPOSITORY/log/incoming.html ] && rm $LOCAL_REPOSITORY/log/incoming.html
3346 report sublog $LOCAL_REPOSITORY/log/incoming.html
3347 echo "incoming" > $LOCAL_REPOSITORY/log/package
3348 check_for_incoming
3349 report end-sublog
3350 report close-bloc
3351 ;;
3352 configure-chroot)
3353 check_root
3354 get_tazwok_config
3355 if [ -f /usr/bin/tazchroot ]; then
3356 cd $LOCAL_REPOSITORY
3357 configure_tazchroot
3358 else
3359 echo "The package tazchroot needs to be installed" >&2
3360 exit 1
3361 fi
3362 ;;
3363 chroot)
3364 check_root
3365 get_tazwok_config
3366 # Merge this and the other chroot function ?.
3367 if [ -f /usr/bin/tazchroot ]; then
3368 cd $LOCAL_REPOSITORY
3369 [ ! -f tazchroot.conf ] && configure_tazchroot
3370 tazchroot
3371 else
3372 echo "The package tazchroot needs to be installed" >&2
3373 exit 1
3374 fi
3375 ;;
3376 cook-toolchain)
3377 check_root
3378 get_tazwok_config
3379 echo -n "" > $PACKAGES_REPOSITORY/broken
3380 if [ -f /usr/bin/tazchroot ]; then
3381 cd $LOCAL_REPOSITORY
3382 [ -f tazchroot.conf ] || configure_tazchroot
3384 # Plan to recook all packages.
3385 if tazchroot cook-toolchain; then
3386 source_lib report
3387 report start
3388 pkg="$(grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt \
3389 $INCOMING_REPOSITORY/packages.txt | sort -u)"
3390 forced=yes
3391 gen_cook_list
3392 fi
3394 # Remove chroot where toolchain has been cooked.
3395 source $LOCAL_REPOSITORY/tazchroot.conf
3396 rm -r $LOCAL_REPOSITORY/chroot
3398 else
3399 echo -e "\nThe package tazchroot needs to be installed.\n" >&2
3400 exit 1
3401 fi
3402 ;;
3403 webserver)
3404 check_root
3405 get_tazwok_config
3406 if [ "$ARG" = on ]; then
3407 if [ "$WEBSERVER" ] && [ -f "$WEBSERVER/repositories.list" ] && \
3408 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3409 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3410 exit 1
3411 fi
3412 if ! [ -f $LOCAL_REPOSITORY/tazchroot.conf ]; then
3413 tazwok configure-chroot ${undigest:+--undigest=$undigest} --SLITAZ_VERSION=$SLITAZ_VERSION --SLITAZ_DIR=$SLITAZ_DIR
3414 fi
3415 for pkg in php lighttpd; do
3416 [ -d $INSTALLED/$pkg ] || missing="$missing $pkg"
3417 done
3418 if [ "$missing" ]; then
3419 echo "You need to install these packages to start webserver: $missing." >&2
3420 exit 1
3421 fi
3422 if [ ! -f "$LOCAL_REPOSITORY/tazwok.conf" ]; then
3423 echo "Copying /etc/slitaz/tazwok.conf to $LOCAL_REPOSITORY/tazwok.conf: webserver is configured repository-by-repository."
3424 cp /etc/slitaz/tazwok.conf $LOCAL_REPOSITORY
3425 fi
3426 if ! [ "$WEBSERVER" ]; then
3427 echo -n "Where to store php pages (default: /var/www/vhosts/bb)? "
3428 read WEBSERVER
3429 [ "$WEBSERVER" ] || WEBSERVER="/var/www/vhosts/bb"
3430 fi
3431 if [ -f "$WEBSERVER/repositories.list" ] && \
3432 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3433 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3434 exit 1
3435 fi
3436 mkdir -p $WEBSERVER
3437 echo "${undigest:-$SLITAZ_VERSION}" >> $WEBSERVER/repositories.list
3438 for file in index.php log.php download.php; do
3439 [ -f "$WEBSERVER/$file" ] || ln -s /usr/share/slitaz/web-bb/$file $WEBSERVER
3440 done
3441 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3442 ln -s $dir $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3443 done
3444 source $LOCAL_REPOSITORY/tazchroot.conf
3445 echo "<?php
3447 // Web interface configuration
3449 \$version=\"${undigest:-$SLITAZ_VERSION}\";
3450 \$chroot=\"$chroot_dir\";
3451 \$lockfile=\"\$chroot/proc/1/status\";
3452 \$db_dir=\"$PACKAGES_REPOSITORY\";
3453 \$log_dir=\"$LOCAL_REPOSITORY/log\";
3454 \$packages=\"$PACKAGES_REPOSITORY\";
3455 \$incoming=\"$INCOMING_REPOSITORY\";
3456 \$wok=\"$WOK\";
3458 ?>" > $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3459 [ -L "$WEBSERVER/web" ] || ln -s /usr/share/slitaz/web $WEBSERVER
3460 echo "WEBSERVER=\"$WEBSERVER\"" >> $LOCAL_REPOSITORY/tazwok.conf
3461 if [ -L "$WEBSERVER/conf.php" ]; then
3462 echo "Do you want to make ${undigest:-$SLITAZ_VERSION} the default page (y/N) ? "
3463 read answer
3464 if [ "$answer" = y ]; then
3465 rm $WEBSERVER/conf.php
3466 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3467 fi
3468 else
3469 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3470 fi
3471 elif [ "$ARG" = off ]; then
3472 if ! [ "$WEBSERVER" ]; then
3473 echo "No webserver running for ${undigest:-$SLITAZ_VERSION}" >&2
3474 exit 1
3475 fi
3476 sed '/^WEBSERVER/d' -i $LOCAL_REPOSITORY/tazwok.conf
3477 sed "/^${undigest:-$SLITAZ_VERSION}$/d" -i $WEBSERVER/repositories.list
3478 rm $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3479 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3480 rm $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3481 done
3482 if ! [ -s "$WEBSERVER/repositories.list" ]; then
3483 echo "$WEBSERVER/repositories.list is empty; tazwok doesn't remove the server automatically in case you have important stuff in it. If that's not the case, you can remove it using: rm -r $WEBSERVER"
3484 rm $WEBSERVER/conf.php
3485 elif [ "$(readlink $WEBSERVER/conf.php)" = "$WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php" ]; then
3486 echo "${undigest:-$SLITAZ_VERSION} was the default version to use; switched to : $(sed 1!d $WEBSERVER/repositories.list)"
3487 rm $WEBSERVER/conf.php
3488 ln -s $WEBSERVER/conf-$(sed 1!d $WEBSERVER/repositories.list).php $WEBSERVER/conf.php
3489 fi
3490 else
3491 echo "Usage: tazwok webserver on/off" >&2
3492 exit 1
3493 fi
3494 ;;
3495 block)
3496 # Add a pkg name to the list of blocked packages.
3497 get_tazwok_config
3498 check_root
3499 check_for_package_on_cmdline
3500 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3501 echo "Can't find $PACKAGE in wok." >&2
3502 echo ""
3503 exit 1
3504 fi
3505 echo ""
3506 if grep -qs "^$PACKAGE$" $blocked; then
3507 echo "$PACKAGE is already in the blocked packages list." >&2
3508 echo ""
3509 exit 1
3510 else
3511 echo -n "Adding $PACKAGE to : $blocked... "
3512 echo "$PACKAGE" >> $blocked
3513 status
3514 if grep -q "^$PACKAGE$" $cooklist; then
3515 echo -n "Removing $PACKAGE from : $cooklist... "
3516 sed -i /"^$PACKAGE$"/d $cooklist
3517 status
3518 fi
3519 fi
3520 echo "" ;;
3521 unblock)
3522 # Remove a pkg name from the list of blocked packages.
3523 get_tazwok_config
3524 check_root
3525 check_for_package_on_cmdline
3526 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3527 echo "Can't find $PACKAGE in wok." >&2
3528 echo ""
3529 exit 1
3530 fi
3531 echo ""
3532 if grep -qs "^$PACKAGE$" $blocked; then
3533 echo -n "Removing $PACKAGE from : $blocked... "
3534 sed -i /"^$PACKAGE$"/d $blocked
3535 sed -i '/^$/d' $blocked
3536 status
3537 else
3538 echo "$PACKAGE is not in the blocked packages list." >&2
3539 echo ""
3540 exit 1
3541 fi
3542 echo "" ;;
3543 usage|*)
3544 # Print usage also for all unknown commands.
3546 usage
3547 ;;
3548 esac
3550 # If a cook command has been used, refresh ID of the repository to avoid
3551 # useless upgrade at next cook command.
3552 case $COMMAND in
3553 cook*)
3554 for repo in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY \
3555 $( [ "$undigest" -a ! "$ref_USE_ONLINE_PKG" ] && echo $ref_PACKAGES_REPOSITORY ); do
3556 [ -f $repo/ID ] || continue
3557 MIRROR_path=$(grep -l "^$repo$" $LOCALSTATE/mirror $LOCALSTATE/undigest/*/mirror)
3558 LOCALSTATE_path=${MIRROR_path%/mirror}
3559 cp -a $repo/ID $LOCALSTATE_path
3560 done
3561 ;;
3562 esac
3564 report stop 2>/dev/null
3565 exit 0