tazwok view tazwok @ rev 454

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