tazwok view tazwok @ rev 460

tazwok: various fixes about packages_db() generation
author Antoine Bodin <gokhlayeh@slitaz.org>
date Fri Mar 25 17:58:40 2011 +0100 (2011-03-25)
parents 95e4c4e04cdd
children ae0a39ba004a
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" ] && 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_REPOSITORY" ]; then
1368 erase_package_info_extracmd="erase_package_info_main"
1369 get_packages_info_extracmd="get_packages_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 grep -m1 ^$PACKAGE$'\t' $lib_db >> libraries.txt
1453 source_receipt()
1455 unset PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
1456 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
1457 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
1458 src _pkg DESTDIR CONFIG_SITE BRANCH TARBALL stuff wanted_stuff
1459 . ${RECEIPT:-$PWD/receipt}
1462 packages_db_end()
1464 cd $pkg_repository
1465 pkgs=$(wc -l packages.list | sed 's/ .*//')
1466 sed "s/# Packages : .*/# Packages : $pkgs/" -i packages.txt
1468 # If lists were updated it's generally needed to sort them well.
1469 if ! sort -c packages.list 2> /dev/null; then
1470 report step "Sorting packages lists"
1471 files_list="packages.list packages.desc packages.equiv"
1472 [ "${pkg_repository##*/}" = packages ] && \
1473 files_list="$files_list wanted.txt depends.txt libraries.txt"
1474 for file in $files_list; do
1475 [ -f $file ] || continue
1476 sort -o $file $file
1477 done
1478 report end-step
1479 fi
1481 md5sum packages.md5 | cut -f1 -d' ' > ID
1482 [ -s ID ] || echo null > ID
1484 # Dont log this because lzma always output errors.
1485 lzma e files.list files.list.lzma
1486 rm -f files.list
1487 [ -f packages.equiv ] || touch packages.equiv
1490 ########################################################################
1491 # This section contains functions to generate wok database.
1492 ########################
1494 gen_wok_db()
1496 report step "Generating wok database"
1497 report open-bloc
1498 report step "Removing old files"
1499 for file in $wan_db $dep_db $cookorder; do
1500 [ -f $file ] && rm $file
1501 done
1502 report step "Generating wok-wanted.txt"
1503 gen_wan_db
1504 report step "Generating wok-depends.txt"
1505 for PACKAGE in $(cut -f1 -d '|' $PACKAGES_REPOSITORY/packages.desc \
1506 $INCOMING_REPOSITORY/packages.desc | sort -u); do
1507 RECEIPT=$WOK/$PACKAGE/receipt
1508 if [ -s $RECEIPT ]; then
1509 source_receipt
1510 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
1511 fi
1512 done
1513 sort_db
1514 report close-bloc
1517 gen_wan_db()
1519 for RECEIPT in $(fgrep -l WANTED $WOK/*/receipt); do
1520 WANTED=
1521 source $RECEIPT
1522 [ "$WANTED" ] || continue
1523 echo -e $PACKAGE"\t"$WANTED >> $tmp/wan_db
1524 done
1525 if ! [ -f $wan_db ] || [ "$(diff -q $tmp/wan_db $wan_db)" ]; then
1526 mv -f $tmp/wan_db $wan_db
1527 plan_regen_cookorder=yes
1528 else
1529 rm $tmp/wan_db
1530 fi
1533 update_wan_db()
1535 local PACKAGE=$PACKAGE
1536 wanted_list=$(fgrep WANTED=\"$PACKAGE\" $WOK/*/receipt | cut -f1 -d ':')
1537 grep $'\t'$PACKAGE $wan_db | cut -f 1 | while read wan; do
1538 echo "$wanted_list" | fgrep -q /$wan/receipt && continue
1539 sed "/^$wan\t/d" -i $wan_db
1540 plan_regen_cookorder=yes
1541 done
1542 for RECEIPT in $wanted_list; do
1543 WANTED=
1544 source $RECEIPT
1545 [ "$WANTED" ] || continue
1546 wan_info=$(echo -e $PACKAGE"\t"$WANTED)
1547 [ "$wan_info" = "$(grep -m1 ^$PACKAGE$'\t' $wan_db 2>/dev/null)" ] && continue
1548 sed "/^$PACKAGE\t/d" -i $wan_db
1549 echo "$wan_info" >> $wan_db
1550 plan_regen_cookorder=yes
1551 plan_sort_wandb=yes
1552 done
1553 unset wanted_list
1556 update_dep_db()
1558 dep_info=$(echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ')
1559 [ "$dep_info" = "$(grep -m1 ^$PACKAGE$'\t' $dep_db 2>/dev/null)" ] && return
1560 sed "/^$PACKAGE\t/d" -i $dep_db
1561 echo "$dep_info" >> $dep_db
1562 plan_regen_cookorder=yes
1563 plan_sort_depdb=yes
1566 sort_db()
1568 report step "Generating cookorder.txt"
1569 sed 's/ \t / /' $dep_db | while read PACKAGE BUILD_DEPENDS; do
1570 grep -q ^$PACKAGE$'\t' $wan_db && continue
1572 # Replace each BUILD_DEPENDS with a WANTED package by it's
1573 # WANTED package.
1574 echo -e $PACKAGE"\t $(echo $BUILD_DEPENDS | use_wanted | \
1575 sort -u | sed "/^$PACKAGE$/d" | tr '\n' ' ') "
1576 done > $tmp/db
1577 while [ -s "$tmp/db" ]; do
1578 status=start
1579 for pkg in $(cut -f 1 $tmp/db); do
1580 if ! fgrep -q ' '$pkg' ' $tmp/db; then
1581 echo $pkg >> $tmp/cookorder
1582 sed -e "/^$pkg\t/d" -e "s/ $pkg / /g" -i $tmp/db
1583 status=proceed
1584 fi
1585 done
1586 if [ "$status" = start ]; then
1587 cp -f $tmp/db /tmp/remain-depends.txt
1588 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
1589 for remaining in $(cut -f 1 $tmp/db); do
1590 echo "$remaining" >> $blocked
1591 done
1592 break
1593 fi
1594 done
1595 [ -s $tmp/cookorder ] || touch $tmp/cookorder
1597 # The toolchain packages are moved in first position.
1598 grep $(for pkg in `scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
1599 --look_for=all --with_args`; do echo " -e ^$pkg$"; done) \
1600 $tmp/cookorder | tac > $cookorder
1601 for pkg in $(cat $cookorder); do
1602 sed "/^$pkg$/d" -i $tmp/cookorder
1603 done
1605 tac $tmp/cookorder >> $cookorder
1606 unset plan_regen_cookorder
1607 report end-step
1610 ########################################################################
1611 # SCAN CORE
1612 ########################
1613 # Includes various scan core-functions. It's not intended to be used
1614 # directly : prefer scan wrappers in next section.
1616 look_for_dep()
1618 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2
1621 look_for_bdep()
1623 look_for_all
1626 look_for_all()
1628 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2,3 | sed 's/ / /'
1631 look_for_rdep()
1633 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1
1636 look_for_rbdep()
1638 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1641 # Return WANTED if it exists.
1642 look_for_wanted()
1644 grep -m1 ^$PACKAGE$'\t' $wan_db | cut -f 2
1647 # Return packages which wants PACKAGE.
1648 look_for_rwanted()
1650 grep $'\t'$PACKAGE$ $wan_db | cut -f 1
1653 look_for_dev()
1655 WANTED=$(look_for_wanted)
1656 if [ "$WANTED" ]; then
1657 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1658 fi
1659 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1662 with_dev()
1664 for PACKAGE in $(cat); do
1665 echo $PACKAGE
1666 look_for_dev
1667 done
1670 with_wanted()
1672 for PACKAGE in $(cat); do
1673 echo $PACKAGE
1674 look_for_wanted
1675 done
1678 use_wanted()
1680 for input in $(cat); do
1681 { grep ^$input$'\t' $wan_db || echo $input
1683 done | sed 's/.*\t//'
1686 check_for_pkg_in_wok()
1688 [ -f $WOK/$PACKAGE/receipt ] && return
1689 echo "Can't find $PACKAGE in wok or mirror" >&2
1690 return 2
1693 # Define how theses functions should act when using --undigest.
1694 use_undigest_scan_core()
1696 look_for_dep()
1698 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1699 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2
1700 else
1701 grep -m1 ^$PACKAGE$'\t' $ref_dep_db | cut -f 2
1702 fi
1705 look_for_all()
1707 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1708 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2,3 | sed 's/ / /'
1709 else
1710 grep -m1 ^$PACKAGE$'\t' $ref_dep_db | cut -f 2,3 | sed 's/ / /'
1711 fi
1714 look_for_rdep()
1716 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1
1717 for rdep in $(fgrep ' '$PACKAGE' ' $ref_dep_db | cut -f 1); do
1718 [ -f "WOK$/$rdep/receipt" ] || echo "$rdep"
1719 done
1722 look_for_rbdep()
1724 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1725 for rdep in $(fgrep ' '$PACKAGE' ' $ref_dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1); do
1726 [ -f "WOK$/$rdep/receipt" ] || echo "$rdep"
1727 done
1730 look_for_wanted()
1732 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1733 grep -m1 ^$PACKAGE$'\t' $wan_db | cut -f 2
1734 else
1735 grep -m1 ^$PACKAGE$'\t' $ref_wan_db | cut -f 2
1736 fi
1739 look_for_rwanted()
1741 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1742 grep $'\t'$PACKAGE$ $wan_db | cut -f 1
1743 else
1744 grep $'\t'$PACKAGE$ $ref_wan_db | cut -f 1
1745 fi
1748 look_for_dev()
1750 WANTED=$(look_for_wanted)
1751 if [ "$WANTED" ]; then
1752 if [ -f "$WOK/$WANTED/receipt" ]; then
1753 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1754 else
1755 grep -q ^$WANTED-dev$'\t' $ref_dep_db && echo $WANTED-dev
1756 fi
1757 fi
1758 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1759 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1760 else
1761 grep -q ^$PACKAGE-dev$'\t' $ref_dep_db && echo $PACKAGE-dev
1762 fi
1765 check_for_pkg_in_wok()
1767 [ -f $WOK/$PACKAGE/receipt ] && return
1768 grep -q ^$PACKAGE'$\t' $ref_dep_db && return 1
1769 echo "Can't find $PACKAGE in wok or mirror" >&2
1770 return 2
1774 ########################################################################
1775 # SCAN
1776 ########################
1777 # Use wok-wanted.txt and wok-depeds.txt to scan depends.
1778 # Option in command line (must be first arg) :
1779 # --look_for=bdep/rbdep - Look for depends or reverse depends.
1780 # --with_dev - Add development packages (*-dev) in the result.
1781 # --with_wanted - Add package+reverse wanted in the result.
1782 # --with_args - Include packages in argument in the result.
1784 scan()
1786 # Get packages in argument.
1787 local PACKAGE=$PACKAGE WANTED=$WANTED pkg_list=
1788 for arg in $@; do
1789 [ "$arg" = "${arg#--}" ] || continue
1790 pkg_list="$pkg_list $arg"
1791 done
1793 # Get options.
1794 [ "$pkg_list" ] || return
1795 local cooklist= look_for= with_dev= with_wanted= with_args= log_command="$0 $@" \
1796 get_options_list="look_for with_dev with_wanted with_args cooklist use_wanted"
1797 get_options
1799 # Cooklist is a special case where we need to modify a little
1800 # scan behavior
1801 if [ "$cooklist" ]; then
1802 gen_wan_db
1803 look_for=all && with_args=yes && with_dev= && with_wanted=
1804 filter=use_wanted
1805 if [ "$COMMAND" = gen-cooklist ]; then
1806 for PACKAGE in $pkg_list; do
1807 grep -q ^$PACKAGE$'\t' $dep_db && continue
1808 [ -d "$WOK/$p" ] || continue
1809 check_for_missing
1810 done
1811 append_to_dep()
1813 if grep -q ^$PACKAGE$'\t' $dep_db; then
1814 echo $PACKAGE >> $tmp/dep
1815 else
1816 check_for_missing && echo $PACKAGE >> $tmp/dep
1817 fi
1819 else
1820 append_to_dep()
1822 check_for_commit && echo $PACKAGE >> $tmp/dep
1824 fi
1825 else
1826 append_to_dep()
1828 echo $PACKAGE >> $tmp/dep
1830 # If requested packages are not in dep_db, partial generation of this db is needed.
1831 for PACKAGE in $pkg_list; do
1832 grep -q ^$PACKAGE$'\t' $dep_db && continue
1833 [ -d "$WOK/$p" ] || continue
1834 plan_check_for_missing=yes
1835 check_for_missing
1836 done
1837 if [ "$plan_check_for_missing" ]; then
1838 append_to_dep()
1840 if grep -q ^$PACKAGE$'\t' $dep_db; then
1841 echo $PACKAGE >> $tmp/dep
1842 else
1843 check_for_missing && echo $PACKAGE >> $tmp/dep
1844 fi
1846 check_db_status=yes
1847 unset plan_check_for_missing
1848 fi
1849 fi
1851 [ "$with_dev" ] && filter=with_dev
1852 [ "$with_wanted" ] && filter=with_wanted
1853 if [ "$filter" ]; then
1854 pkg_list=$(echo $pkg_list | $filter | sort -u)
1855 scan_pkg()
1857 look_for_$look_for | $filter
1859 else
1860 scan_pkg()
1862 look_for_$look_for
1864 fi
1865 touch $tmp/dep
1866 for PACKAGE in $pkg_list; do
1867 [ "$with_args" ] && append_to_dep
1868 scan_pkg
1869 done | tr ' ' '\n' | sort -u > $tmp/list
1870 [ "$look_for" = bdep ] && look_for=dep
1871 while [ -s $tmp/list ]; do
1872 PACKAGE=$(sed 1!d $tmp/list)
1873 sed 1d -i $tmp/list
1874 append_to_dep
1875 for pkg in $(scan_pkg); do
1876 grep -q ^$pkg$ $tmp/list $tmp/dep || echo $pkg >> $tmp/list
1877 done
1878 done
1879 if [ "$cooklist" ]; then
1880 mv $tmp/dep $tmp/cooklist
1881 else
1882 cat $tmp/dep | sort -u
1883 fi
1884 rm -f $tmp/dep $tmp/list
1885 if [ "$check_db_status" ]; then
1886 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
1887 [ "$plan_sort_wandb" ] && sort -o $wan_db $wan_db && unset plan_sort_wandb
1888 if [ "$plan_regen_cookorder" ] && \
1889 [ "$(sed 1!d $cookorder)" != "#PlanSort" ]; then
1890 grep -q "^#" $cookorder || sed 1i"#PlanSort" -i $cookorder
1891 fi
1892 fi
1895 ########################################################################
1896 # This section contains functions to check the package repository and
1897 # find which packages to cook.
1898 ########################
1900 check_for_missing()
1902 local PACKAGE=$PACKAGE
1903 if ! check_for_pkg_in_wok; then
1904 [ "$?" = 2 ] && return 1
1905 return
1906 fi
1907 RECEIPT=$WOK/$PACKAGE/receipt
1908 source_receipt
1909 PACKAGE=${WANTED:-$PACKAGE}
1910 update_wan_db
1911 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1912 RECEIPT=$WOK/$PACKAGE/receipt
1913 source_receipt
1914 update_dep_db
1915 done
1918 check_for_commit()
1920 if ! check_for_pkg_in_wok; then
1921 [ "$?" = 2 ] && return 1
1922 return
1923 fi
1924 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1925 RECEIPT=$WOK/$PACKAGE/receipt
1926 source_receipt
1928 # We use md5 of cooking stuff in the packaged receipt to check
1929 # commit. We look consecutively in 3 different locations :
1930 # - in the wok/PACKAGE/taz/* folder
1931 # - in the receipt in the package in incoming repository
1932 # - in the receipt in the package in packages repository
1933 # If md5sums match, there's no commit.
1934 check_for_commit_using_md5sum()
1936 if [ ! -f $WOK/$PACKAGE/md5 ]; then
1937 sed -n '/# md5sum of cooking stuff :/,$p' receipt | \
1938 sed -e 1d -e 's/^# //' > $WOK/$PACKAGE/md5
1939 cd $WOK/$PACKAGE
1940 fi
1942 if [ -s md5 ]; then
1943 if md5sum -cs md5; then
1945 # If md5sum check if ok, check for new/missing files in
1946 # cooking stuff.
1947 for file in $([ -f receipt ] && echo receipt; \
1948 [ -f description.txt ] && echo description.txt; \
1949 [ -d stuff ] && find stuff); do
1950 if ! fgrep -q " $file" md5; then
1951 set_commited
1952 fi
1953 done
1954 else
1955 set_commited
1956 fi
1957 else
1958 set_commited
1959 fi
1961 set_commited()
1963 grep -q ^$PACKAGE$ $commit || echo $PACKAGE >> $commit
1964 gen_cookmd5
1965 update_dep_db
1967 taz_dir=$(echo $WOK/$PACKAGE/taz/$PACKAGE-* | fgrep -v '*')
1968 if [ -f $WOK/$PACKAGE/md5 ]; then
1969 cd $WOK/$PACKAGE
1970 check_for_commit_using_md5sum
1971 elif [ "$taz_dir" ]; then
1972 cd $taz_dir
1973 check_for_commit_using_md5sum
1974 else
1975 pkg=$(echo $INCOMING_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
1976 [ "$pkg" ] || pkg=$(echo $PACKAGES_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
1977 if [ "$pkg" ]; then
1978 get_pkg_files $pkg
1979 check_for_commit_using_md5sum
1980 rm -r $pkg_files_dir
1981 else
1982 set_commited
1983 fi
1984 fi
1985 [ "$forced" ] || echo $PACKAGE >> $tmp/checked
1986 done
1987 return
1990 gen_cook_list()
1992 report step "Scanning wok"
1993 if [ "$pkg" ]; then
1994 scan $pkg --cooklist
1995 elif [ "$LIST" ]; then
1996 scan `cat $LIST` --cooklist
1997 else
1998 scan `cat $cooklist` --cooklist
1999 fi
2000 report end-step
2002 [ -s $tmp/checked ] || [ -s $tmp/cooklist ] || return
2004 # Core toolchain should not be cooked unless cook-toolchain is used.
2005 if ! [ -f /etc/config.site.tmptoolchain ] ; then
2006 for PACKAGE in $(scan gcc --look_for=all --with_args --with_wanted); do
2007 grep -q ^$PACKAGE$ $blocked || echo $PACKAGE >> $blocked
2008 done
2009 fi
2011 if [ -s $commit ] && [ "$COMMAND" != gen-cooklist ]; then
2012 for PACKAGE in $(cat $commit); do
2013 WANTED="$(look_for_wanted)"
2014 if [ "$WANTED" ]; then
2015 grep -q ^$WANTED$ $broken $cooklist $blocked $commit && continue
2016 fi
2017 grep -q ^$PACKAGE$ $blocked $cooklist && continue
2018 echo $PACKAGE >> $cooklist
2019 done
2020 fi
2021 sort_cooklist
2024 sort_cooklist()
2026 if [ "$(sed 1!d $cookorder)" = "#PlanSort" ]; then
2027 sed 1d -i $cookorder
2028 plan_regen_cookorder=yes
2029 fi
2030 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
2031 [ "$plan_regen_cookorder" ] && sort_db
2032 report step "Generating cooklist"
2033 if [ -f "$tmp/checked" ]; then
2034 rm -f $tmp/cooklist
2035 cat $tmp/checked | while read PACKAGE; do
2036 grep -q ^$PACKAGE$ $cooklist && echo $PACKAGE >> $tmp/cooklist
2037 done
2038 elif ! [ "$COMMAND" = gen-cooklist ]; then
2039 cat $blocked | while read PACKAGE; do
2040 sed "/^$PACKAGE/d" -i $tmp/cooklist
2041 done
2042 fi
2043 report end-step
2044 [ -s $tmp/cooklist ] || return
2046 report step "Sorting cooklist"
2047 for PACKAGE in $(cat $tmp/cooklist); do
2048 WANTED="$(look_for_wanted)"
2049 [ "$WANTED" ] || continue
2050 if grep -q ^$WANTED$ $broken $tmp/cooklist; then
2051 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2052 elif [ ! -d $WOK/$WANTED/install ]; then
2053 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2054 echo $WANTED >> $tmp/cooklist
2055 fi
2056 done
2058 # Use cookorder.txt to sort cooklist.
2059 if [ -s $tmp/cooklist ]; then
2060 cat $cookorder | while read PACKAGE; do
2061 if grep -q ^$PACKAGE$ $tmp/cooklist; then
2062 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2063 echo $PACKAGE >> $tmp/cooklist.tmp
2064 fi
2065 done
2067 # Remaining packages in cooklist are those without compile_rules.
2068 # They can be cooked first in any order.
2069 if [ -f $tmp/cooklist.tmp ]; then
2070 cat $tmp/cooklist.tmp >> $tmp/cooklist
2071 rm $tmp/cooklist.tmp
2072 fi
2074 cat $tmp/cooklist
2075 [ "$LIST" ] || cat $tmp/cooklist > $cooklist
2076 fi
2078 report end-step
2081 look_for_missing_pkg()
2083 for pkg in $(cat $PACKAGES_REPOSITORY/$1); do
2084 grep -q ^$pkg$ $INCOMING_REPOSITORY/packages.txt \
2085 $PACKAGES_REPOSITORY/packages.txt || \
2086 continue
2087 echo $pkg
2088 done
2091 check_for_incoming()
2093 report step "Checking that all packages were cooked OK"
2094 [ -s $INCOMING_REPOSITORY/packages.desc ] || {
2095 echo "No packages in $INCOMING_REPOSITORY."
2096 report end-step; return; }
2097 if [ -s $broken ]; then
2098 missingpkg=$(look_for_missing_pkg broken)
2099 if [ "$missingpkg" ]; then
2100 echo "Don't move incoming packages to main repository because these ones are broken:" >&2
2101 echo "$missingpkg"
2102 report end-step
2103 return 1
2104 fi
2105 fi
2106 if [ -s $cooklist ]; then
2107 missingpkg=$(look_for_missing_pkg cooklist)
2108 if [ "$missingpkg" ]; then
2109 echo "Don't move incoming packages to main repository because these ones need to be cooked:" >&2
2110 echo "$missingpkg"
2111 report end-step
2112 return 1
2113 fi
2114 fi
2115 incoming_pkgs="$(cut -f 1 -d '|' $INCOMING_REPOSITORY/packages.desc)"
2116 if ! [ "$forced" ]; then
2117 cooklist=$PACKAGES_REPOSITORY/cooklist
2118 pkg="$incoming_pkgs"
2119 gen_cook_list
2120 if [ -s $cooklist ]; then
2121 missingpkg=$(look_for_missing_pkg cooklist)
2122 if [ "$missingpkg" ]; then
2123 echo "Don't move incoming packages to main repository because these ones need to be cooked:" >&2
2124 echo "$missingpkg"
2125 report end-step
2126 return 1
2127 fi
2128 fi
2129 fi
2131 report step "Moving incoming packages to main repository"
2132 [ "save_wok" ] && mkdir -p $PACKAGES_REPOSITORY/wok
2133 unset EXTRAVERSION
2134 for PACKAGE in $incoming_pkgs; do
2135 prev_VERSION=$(get_pkg_version $PACKAGES_REPOSITORY)
2136 VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
2137 remove_previous_package $PACKAGES_REPOSITORY
2138 echo "Moving $PACKAGE..."
2139 mv -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION.tazpkg $PACKAGES_REPOSITORY
2140 touch $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
2141 previous_tarball=$(grep -m1 ^$PACKAGE:main $SOURCES_REPOSITORY/sources.list | cut -f2)
2142 sed -e "/^$PACKAGE:main/d" \
2143 -e "s/^$PACKAGE:incoming/$PACKAGE:main/" \
2144 -i $SOURCES_REPOSITORY/sources.list
2145 if [ "$previous_tarball" ]; then
2146 grep -q $'\t'$previous_tarball$ $SOURCES_REPOSITORY/sources.list || \
2147 rm -f $SOURCES_REPOSITORY/$previous_tarball
2148 fi
2149 [ "$save_wok" ] &&
2150 copy_cooking_stuff $INCOMING_REPOSITORY/wok $PACKAGE $PACKAGES_REPOSITORY/wok
2151 done
2153 if [ "$save_wok" = tarball ]; then
2154 rm -f $PACKAGES_REPOSITORY/wok.tar.lzma
2155 cd $PACKAGES_REPOSITORY/wok
2156 report step "Generating safe-wok tarball"
2157 tar -c * | lzma e $PACKAGES_REPOSITORY/wok.tar.lzma
2158 report end-step
2159 fi
2161 for file in packages.list packages.equiv packages.md5 packages.desc \
2162 packages.txt; do
2163 echo -n "" > $INCOMING_REPOSITORY/$file
2164 done
2165 rm -r $INCOMING_REPOSITORY/files.list.lzma
2166 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2168 report step "Updating flavors"
2169 if [ -x /usr/bin/tazlito ] || [ -x /usr/bin/clean-chroot ]; then
2170 if ! [ -x /usr/bin/tazlito ]; then
2171 tazpkg get-install tazlito
2172 fi
2174 # Handle cases where tazwok is used into main system;
2175 # Handle cases where SLITAZ_DIR is not /home/slitaz.
2176 [ -L /home/slitaz/flavors ] && rm /home/slitaz/flavors
2177 mkdir -p /home/slitaz
2178 ln -s $LOCAL_REPOSITORY/flavors /home/slitaz/flavors
2180 cd $LOCAL_REPOSITORY/packages
2181 for i in $LOCAL_REPOSITORY/flavors/*; do
2182 [ -d "$i" ] || continue
2183 tazlito pack-flavor ${i##*/}
2184 done
2186 noheader=""
2187 for i in *.flavor; do
2188 tazlito show-flavor $i --brief $noheader
2189 noheader="--noheader"
2190 done > flavors.list
2191 [ -x /usr/bin/clean-chroot ] && clean-chroot
2192 else
2193 echo "Can't create up-to-date flavors because the tazlito package is missing." >&2
2194 fi
2195 report end-step
2198 # Usage: move_cooking_stuff source receipt destination
2199 # Make the argument check before calling it!
2200 copy_cooking_stuff()
2202 rm -rf $3/$2
2203 mkdir -p $3/$2
2204 cp -a $1/$2/receipt $3/$2
2205 [ -f $1/$2/description.txt ] && \
2206 cp -a $1/$2/description.txt $3/$2
2207 if [ -d "$1/$2/stuff" ]; then
2208 cp -a $1/$2/stuff $3/$2
2209 fi
2212 ########################################################################
2213 # TAZWOK MAIN FUNCTIONS
2214 ########################
2216 clean()
2218 cd $WOK/$PACKAGE
2219 ls -A $WOK/$PACKAGE | grep -q -v -e ^receipt$ -e ^description.txt$ \
2220 -e ^stuff$ || return
2222 [ "$COMMAND" = clean-wok ] || report step "Cleaning $PACKAGE"
2223 # Check for clean_wok function.
2224 if grep -q ^clean_wok $RECEIPT; then
2225 clean_wok
2226 fi
2227 # Clean should only have a receipt, stuff and optionals desc/md5.
2228 for f in `ls .`
2229 do
2230 case $f in
2231 receipt|stuff|description.txt|md5)
2232 continue ;;
2233 *)
2234 rm -rf $f ;;
2235 esac
2236 done
2237 [ "$COMMAND" != clean-wok ] && report end-step
2240 # Configure and make a package with the receipt.
2241 compile_package()
2243 check_for_package_on_cmdline
2245 # Include the receipt to get all needed variables and functions
2246 # and cd into the work directory to start the work.
2247 check_for_receipt
2248 source_receipt
2250 # Log the package name and date.
2251 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
2252 echo "package $PACKAGE (compile)" >> $LOG
2254 # Set wanted $src variable to help compiling.
2255 [ ! "$src" ] && set_src_path
2256 check_for_build_depends || return 1
2257 check_for_wanted
2258 unset target
2259 check_for_tarball && check_for_compile_rules
2262 # Cook command also include all features to manage lists which keep
2263 # track of wok/packages state.
2264 cook()
2266 cook_code=
2267 set_common_path
2268 check_for_receipt
2269 source_receipt
2271 # Define log path and start report.
2272 for i in $(look_for_rwanted) $PACKAGE; do
2273 rm -f $LOCAL_REPOSITORY/log/$i.html
2274 done
2275 report sublog $LOCAL_REPOSITORY/log/$PACKAGE.html
2276 echo "$PACKAGE" > $LOCAL_REPOSITORY/log/package
2277 report step "Cooking $PACKAGE"
2278 report open-bloc
2280 clean $PACKAGE
2281 [ -s $tmp/cooklist ] && sed "/^$PACKAGE$/d" -i $tmp/cooklist
2283 if compile_package; then
2284 remove_src
2285 refresh_packages_from_compile
2286 gen_package
2288 # Update packages-incoming repository.
2289 store_pkgname=$PACKAGE
2290 pkg_repository=$INCOMING_REPOSITORY
2291 update_packages_db
2293 PACKAGE=$store_pkgname
2294 unset store_pkgname
2296 # Upgrade to cooked packages if it was previously installed.
2297 report step "Looking for package(s) to upgrade"
2298 for pkg in $(look_for_rwanted) $PACKAGE; do
2299 if [ -f $INSTALLED/$pkg/receipt ]; then
2300 tazpkg get-install $pkg --forced
2301 fi
2302 done
2303 report end-step
2304 else
2305 set_pkg_broken
2306 cook_code=1
2307 fi
2309 # Remove build_depends in cook mode (if in cooklist, it's done when
2310 # checking build_depends of next package and we remove only unneeded
2311 # packages to keep chroot minimal and gain some time).
2312 if [ "$COMMAND" = cook ]; then
2313 remove_build_depends $MISSING_PACKAGE
2314 [ -x /usr/bin/clean-chroot ] && clean-chroot
2315 fi
2317 # Regen the cooklist if it was planned and command is not cook.
2318 [ "$regen_cooklist" ] && unset regen_cooklist &&
2319 [ "$COMMAND" != cook ] && sort_cooklist
2321 # Some hacks to set the bloc & function status as failed if cook has
2322 # failed.
2323 report_return_code=$cook_code
2324 report close-bloc
2325 report end-sublog
2326 rm -f $LOCAL_REPOSITORY/log/package
2327 return $cook_code
2330 cook_list()
2332 if [ -s $tmp/cooklist ]; then
2333 if [ -f /usr/bin/tazchroot ]; then
2334 # Note : options -main variables- are automatically kept by
2335 # the sub-applications tazchroot/tazwok; as well as report data.
2336 cd $LOCAL_REPOSITORY
2337 [ ! -f tazchroot.conf ] && configure_tazchroot
2338 tazchroot tazwok cook-list --SLITAZ_DIR=$SLITAZ_DIR --SLITAZ_VERSION=$SLITAZ_VERSION ${undigest:+ --undigest=$undigest}
2339 return
2340 fi
2341 while [ -s $tmp/cooklist ]; do
2342 PACKAGE=$(sed 1!d $tmp/cooklist)
2343 cook
2344 done
2345 remove_build_depends $MISSING_PACKAGE $remove_later
2346 [ -x /usr/bin/clean-chroot ] && clean-chroot
2347 else
2348 echo "Nothing to cook."
2349 return
2350 fi
2353 configure_tazchroot()
2355 cat > $LOCAL_REPOSITORY/tazchroot.conf << EOF
2356 # Tazchroot configuration file - created by tazwok.
2358 # Local repository definition.
2359 SLITAZ_DIR=$SLITAZ_DIR
2360 SLITAZ_VERSION=$SLITAZ_VERSION
2361 LOCAL_REPOSITORY=$SLITAZ_DIR/${undigest:-$SLITAZ_VERSION}
2362 ${USE_ONLINE_PKG:+USE_ONLINE_PKG=$USE_ONLINE_PKG}
2363 ${undigest:+undigest=$undigest}
2364 ${ref_USE_ONLINE_PKG:+ref_USE_ONLINE_PKG=$ref_USE_ONLINE_PKG}
2366 # Chroot path.
2367 # You can use a chroot into /tmp if it's mounted in RAM
2368 # to speed-up the process, be sure you have a free GB.
2369 # (minimal chroot is like 150~200MB, can be a lot more during cook)
2370 # chroot_dir=/tmp/chroot-${undigest:-$SLITAZ_VERSION}
2371 chroot_dir=\$LOCAL_REPOSITORY/chroot
2373 # Default scripts path (these scripts are added to the
2374 # $chroot_dir/usr/bin and can be called with tazchroot script).
2375 script_dir=/usr/lib/slitaz/chroot-scripts/tazwok
2377 # List of directories to mount.
2378 list_dir="$LOCAL_REPOSITORY
2379 $SLITAZ_LOG$( [ "$undigest" ] && echo -e "\n$SLITAZ_DIR/$SLITAZ_VERSION/packages" )"
2381 create_chroot()
2383 mkdir -p \$chroot_dir
2384 for pkg in \$(tazwok build-depends toolchain --SLITAZ_DIR=\$SLITAZ_DIR --SLITAZ_VERSION=\$SLITAZ_VERSION${undigest:+ --undigest=\$undigest}); do
2385 tazpkg get-install \$pkg --root="\$chroot_dir"
2386 done
2388 # Store list of installed packages needed by cleanchroot.
2389 ls -1 \$chroot_dir/\$INSTALLED > \$chroot_dir/\$LOCALSTATE/chroot-pkgs
2391 sed -e "s~^SLITAZ_DIR=.*~SLITAZ_DIR=\$SLITAZ_DIR~" \\
2392 -e "s/^SLITAZ_VERSION=.*/SLITAZ_VERSION=\$SLITAZ_VERSION/" \\
2393 -i \$chroot_dir/etc/slitaz/slitaz.conf
2394 echo \$SLITAZ_VERSION > \$chroot_dir/etc/slitaz-release
2395 $( [ "$undigest" ] && echo ' echo "undigest='"$undigest"'" >> $chroot_dir/etc/slitaz/tazwok.conf')
2396 sed 's/LC_ALL/LC_ALL=POSIX/' -i \$chroot_dir/etc/profile
2398 # The build bot may run in a sandbox: link sandbox lockfile.
2399 ln -s \$LOCAL_REPOSITORY/sandbox/proc/1 \$chroot_dir/proc/1
2402 mount_chroot()
2404 cp -a /etc/resolv.conf \$chroot_dir/etc/resolv.conf
2405 $( if [ "$USE_ONLINE_PKG" ]; then
2406 echo ' echo "$USE_ONLINE_PKG" > $chroot_dir$LOCALSTATE/mirror'
2407 else
2408 echo ' echo "$LOCAL_REPOSITORY/packages" > $chroot_dir$LOCALSTATE/mirror'
2409 fi
2411 mkdir -p \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming
2412 echo "\$LOCAL_REPOSITORY/packages-incoming" > \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming/mirror
2413 $( if [ "$undigest" ]; then
2414 echo ' mkdir -p $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION'
2415 if [ "$ref_USE_ONLINE_PKG" ]; then
2416 echo ' echo "$ref_USE_ONLINE_PKG" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror'
2417 else
2418 echo ' echo "$ref_LOCAL_REPOSITORY/packages" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror'
2419 fi
2420 fi )
2421 echo -e "\${LOCAL_REPOSITORY##*/}-incoming\nmain" > \$chroot_dir\$LOCALSTATE/priority
2422 mount -o bind /proc \$chroot_dir/proc
2423 mount -o bind /sys \$chroot_dir/sys
2424 mount -o bind /dev/pts \$chroot_dir/dev/pts
2425 mount -o bind /dev/shm \$chroot_dir/dev/shm
2426 for dir in \$list_dir; do
2427 mkdir -p \$dir \$chroot_dir\$dir
2428 mount \$dir \$chroot_dir\$dir
2429 done
2432 umount_chroot()
2434 for dir in \$list_dir; do
2435 umount \$chroot_dir\$dir
2436 done
2437 umount \$chroot_dir/dev/shm
2438 umount \$chroot_dir/dev/pts
2439 umount \$chroot_dir/sys
2440 umount \$chroot_dir/proc
2442 EOF
2445 ########################################################################
2446 ######################### END OF NEW FUNCTIONS #########################
2447 ########################################################################
2449 # List packages providing a virtual package.
2450 whoprovide()
2452 local i;
2453 for i in $(fgrep -l PROVIDE $WOK/*/receipt); do
2454 . $i
2455 case " $PROVIDE " in
2456 *\ $1\ *|*\ $1:*) echo $(basename $(dirname $i));;
2457 esac
2458 done
2461 ########################################################################
2462 # TAZWOK COMMANDS
2463 ########################
2465 case "$COMMAND" in
2466 stats)
2467 # Tazwok general statistics from the wok config file.
2469 get_tazwok_config
2470 echo -e "\n\033[1mTazwok configuration statistics\033[0m
2471 ================================================================================
2472 Wok directory : $WOK
2473 Packages repository : $PACKAGES_REPOSITORY
2474 Incoming repository : $INCOMING_REPOSITORY
2475 Sources repository : $SOURCES_REPOSITORY
2476 Log directory : $LOCAL_REPOSITORY/log
2477 Packages in the wok : `ls -1 $WOK | wc -l`
2478 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2479 Incoming packages : `ls -1 $INCOMING_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2480 ================================================================================\n"
2481 ;;
2482 edit)
2483 get_tazwok_config
2484 check_for_package_on_cmdline
2485 check_for_receipt
2486 $EDITOR $WOK/$PACKAGE/receipt
2487 ;;
2488 build-depends)
2489 # List dependencies to rebuild wok, or only a package.
2490 get_tazwok_config
2491 report(){ : ; }
2492 if [ ! "$PACKAGE" ] || [ "$PACKAGE" = toolchain ]; then
2493 scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
2494 --look_for=dep --with_dev --with_args
2495 else
2496 check_for_package_on_cmdline
2497 scan $PACKAGE --look_for=bdep --with_dev
2498 fi
2499 ;;
2500 gen-cooklist)
2501 check_root
2502 get_options_list="pkg"
2503 get_tazwok_config
2504 report(){ : ; }
2505 if ! [ "$pkg" ]; then
2506 if [ ! "$LIST" ] || [ "$LIST" = toolchain ]; then
2507 pkg="$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA"
2508 else
2509 check_for_list
2510 fi
2511 fi
2512 gen_cook_list
2513 ;;
2514 check-depends)
2515 # Check package depends /!\.
2516 get_tazwok_config
2517 echo ""
2518 echo -e "\033[1mCheck every receipt for DEPENDS - doesn't scan ELF files\033[0m
2519 ================================================================================"
2520 TMPDIR=/tmp/tazwok$$
2521 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
2523 # Build ALL_DEPENDS variable.
2524 scan_dep()
2526 local i
2527 ALL_DEPENDS="$ALL_DEPENDS$PACKAGE "
2528 for i in $DEPENDS $SUGGESTED ; do
2529 case " $ALL_DEPENDS " in
2530 *\ $i\ *) continue;;
2531 esac
2532 [ -d $WOK/$i ] || {
2533 ALL_DEPENDS="$ALL_DEPENDS$i "
2534 continue
2536 DEPENDS=""
2537 SUGGESTED=""
2538 . $WOK/$i/receipt
2539 scan_dep
2540 done
2543 # Check for ELF file.
2544 is_elf()
2546 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
2549 # Print shared library dependencies.
2550 ldd()
2552 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
2555 mkdir $TMPDIR
2556 cd $TMPDIR
2557 for i in $LOCALSTATE/files.list.lzma \
2558 $LOCALSTATE/undigest/*/files.list.lzma ; do
2559 [ -f $i ] && lzma d $i -so >> files.list
2560 done
2561 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
2562 tazpkg extract $pkg > /dev/null 2>&1
2563 . */receipt
2564 ALL_DEPENDS="$DEFAULT_DEPENDS "
2565 scan_dep
2566 find */fs -type f | while read file ; do
2567 is_elf $file || continue
2568 case "$file" in
2569 *.o|*.ko|*.ko.gz) continue;;
2570 esac
2571 ldd $file | while read lib rem; do
2572 case "$lib" in
2573 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
2574 continue;;
2575 esac
2576 for dep in $(fgrep $lib files.list | cut -d: -f1); do
2577 case " $ALL_DEPENDS " in
2578 *\ $dep\ *) continue 2;;
2579 esac
2580 for vdep in $(fgrep $dep $LOCALSTATE/packages.equiv | cut -d= -f1); do
2581 case " $ALL_DEPENDS " in
2582 *\ $vdep\ *) continue 3;;
2583 esac
2584 done
2585 done
2586 [ -n "$dep" ] || dep="UNKNOWN"
2587 echo "$(basename $pkg): ${file#*fs} depends on package $dep for the shared library $lib"
2588 done
2589 done
2590 rm -rf */
2591 done
2592 cd /tmp
2593 rm -rf $TMPDIR
2594 ;;
2595 check)
2596 # Check wok consistency.
2597 get_tazwok_config
2598 echo ""
2599 echo -e "\033[1mWok and packages checking\033[0m
2600 ================================================================================"
2601 cd $WOK
2602 for pkg in $(ls)
2603 do
2604 [ -f $pkg/receipt ] || continue
2605 RECEIPT= $pkg/receipt
2606 source_receipt
2607 [ "$PACKAGE" = "$pkg" ] || echo "Package $PACKAGE should be $pkg" >&2
2608 [ -n "$VERSION" ] || echo "Package $PACKAGE has no VERSION" >&2
2609 [ -n "$PACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded PACKED_SIZE" >&2
2610 [ -n "$UNPACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded UNPACKED_SIZE" >&2
2611 [ -n "$EXTRAVERSION" ] && echo "Package $PACKAGE has hardcoded EXTRAVERSION" >&2
2612 if [ -n "$WANTED" ]; then
2613 if [ ! -f $WANTED/receipt ]; then
2614 echo "Package $PACKAGE wants unknown $WANTED package" >&2
2615 else
2616 BASEVERSION=$(. $WANTED/receipt ; echo $VERSION)
2617 if [ "$VERSION" = "$WANTED" ]; then
2618 # BASEVERSION is computed in receipt
2619 fgrep -q '_pkg=' $pkg/receipt &&
2620 BASEVERSION=$VERSION
2621 fi
2622 if [ "$VERSION" != "$BASEVERSION" ]; then
2623 echo "Package $PACKAGE ($VERSION) wants $WANTED ($BASEVERSION)" >&2
2624 fi
2625 fi
2626 fi
2628 if [ -n "$CATEGORY" ]; then
2629 case " $(echo $CATEGORIES) " in
2630 *\ $CATEGORY\ *);;
2631 *) echo "Package $PACKAGE has an invalid CATEGORY" >&2;;
2632 esac
2633 else
2634 echo"Package $PACKAGE has no CATEGORY" >&2
2635 fi
2636 [ -n "$SHORT_DESC" ] || echo "Package $PACKAGE has no SHORT_DESC" >&2
2637 [ -n "$MAINTAINER" ] || echo "Package $PACKAGE has no MAINTAINER" >&2
2638 case "$WGET_URL" in
2639 ftp*|http*) busybox wget -s $WGET_URL 2> /dev/null ||
2640 echo "Package $PACKAGE has a wrong WGET_URL" >&2;;
2641 '') ;;
2642 *) echo "Package $PACKAGE has an invalid WGET_URL" >&2;;
2643 esac
2644 case "$WEB_SITE" in
2645 ftp*|http*);;
2646 '') echo "Package $PACKAGE has no WEB_SITE" >&2;;
2647 *) echo "Package $PACKAGE has an invalid WEB_SITE" >&2;;
2648 esac
2649 case "$MAINTAINER" in
2650 *\<*|*\>*) echo "Package $PACKAGE has an invalid MAINTAINER: $MAINTAINER" >&2;;
2651 esac
2652 case "$MAINTAINER" in
2653 *@*);;
2654 *) echo "Package $PACKAGE MAINTAINER is not an email address" >&2;;
2655 esac
2656 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2657 for i in $DEPENDS; do
2658 [ -d $i ] && continue
2659 [ -n "$(whoprovide $i)" ] && continue
2660 echo -e "$MSG $i"
2661 MSG=""
2662 done
2663 MSG="Missing build dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2664 for i in $BUILD_DEPENDS; do
2665 [ -d $i ] && continue
2666 [ -n "$(whoprovide $i)" ] && continue
2667 echo -e "$MSG $i"
2668 MSG=""
2669 done
2670 MSG="Dependency loop between $PACKAGE and :\n"
2671 ALL_DEPS=""
2672 check_for_deps_loop $PACKAGE $DEPENDS
2673 [ -d $WOK/$pkg/taz ] && for i in $BUILD_DEPENDS; do
2674 [ $WOK/$pkg/taz -nt $INSTALLED/$i/files.list ] && continue
2675 echo "$pkg should be rebuilt after $i installation"
2676 done
2677 done
2678 ;;
2679 list)
2680 # List packages in wok directory. User can specify a category.
2682 get_tazwok_config
2683 if [ "$2" = "category" ]; then
2684 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
2685 exit 0
2686 fi
2687 # Check for an asked category.
2688 if [ -n "$2" ]; then
2689 ASKED_CATEGORY=$2
2690 echo ""
2691 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
2692 echo "================================================================================"
2693 for pkg in $WOK/*
2694 do
2695 [ ! -f $pkg/receipt ] && continue
2696 . $pkg/receipt
2697 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
2698 echo -n "$PACKAGE"
2699 echo -e "\033[28G $VERSION"
2700 packages=$(($packages+1))
2701 fi
2702 done
2703 echo "================================================================================"
2704 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
2705 else
2706 # By default list all packages and version.
2707 echo ""
2708 echo -e "\033[1mList of packages in the wok\033[0m"
2709 echo "================================================================================"
2710 for pkg in $WOK/*
2711 do
2712 [ ! -f $pkg/receipt ] && continue
2713 . $pkg/receipt
2714 echo -n "$PACKAGE"
2715 echo -en "\033[28G $VERSION"
2716 echo -e "\033[42G $CATEGORY"
2717 packages=$(($packages+1))
2718 done
2719 echo "================================================================================"
2720 echo -e "$packages packages available in the wok.\n"
2721 fi
2722 ;;
2723 info)
2724 # Information about a package.
2726 get_tazwok_config
2727 check_for_package_on_cmdline
2728 check_for_receipt
2729 . $WOK/$PACKAGE/receipt
2730 echo ""
2731 echo -e "\033[1mTazwok package information\033[0m
2732 ================================================================================
2733 Package : $PACKAGE
2734 Version : $VERSION
2735 Category : $CATEGORY
2736 Short desc : $SHORT_DESC
2737 Maintainer : $MAINTAINER"
2738 if [ ! "$WEB_SITE" = "" ]; then
2739 echo "Web site : $WEB_SITE"
2740 fi
2741 if [ ! "$DEPENDS" = "" ]; then
2742 echo "Depends : $DEPENDS"
2743 fi
2744 if [ ! "$WANTED" = "" ]; then
2745 echo "Wanted src : $WANTED"
2746 fi
2747 echo "================================================================================"
2748 echo ""
2749 ;;
2750 check-log)
2751 # We just cat the file log to view process info.
2753 get_tazwok_config
2754 if [ ! -f "$LOG" ]; then
2755 echo -e "\nNo process log found. The package is probably not cooked.\n" >&2
2756 exit 1
2757 else
2758 echo ""
2759 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
2760 echo "================================================================================"
2761 cat $LOG
2762 echo "================================================================================"
2763 echo ""
2764 if [ -s "$WOK/$PACKAGE/warning.txt" ]; then
2765 echo -e "\033[1mCook warning(s) for :\033[0m $PACKAGE"
2766 echo "================================================================================"
2767 cat "$WOK/$PACKAGE/warning.txt"
2768 echo "================================================================================"
2769 echo ""
2770 fi
2771 fi
2772 ;;
2773 search)
2774 # Search for a package by pattern or name.
2776 get_tazwok_config
2777 if [ -z "$2" ]; then
2778 echo -e "\nPlease specify a pattern or a package name to search." >&2
2779 echo -e "Example : 'tazwok search gcc'.\n" >&2
2780 exit 1
2781 fi
2782 echo ""
2783 echo -e "\033[1mSearch result for :\033[0m $2"
2784 echo "================================================================================"
2785 list=`ls -1 $WOK | fgrep $2`
2786 for pkg in $list
2787 do
2788 . $WOK/$pkg/receipt
2789 echo -n "$PACKAGE "
2790 echo -en "\033[24G $VERSION"
2791 echo -e "\033[42G $CATEGORY"
2792 packages=$(($PACKAGEs+1))
2793 done
2794 echo "================================================================================"
2795 echo "$packages packages found for : $2"
2796 echo ""
2797 ;;
2798 compile)
2799 # Configure and make a package with the receipt.
2801 get_tazwok_config
2802 source_lib report
2803 report start
2804 compile_package
2805 ;;
2806 genpkg)
2807 # Generate a package.
2809 get_tazwok_config
2810 source_lib report
2811 report start
2812 gen_package
2813 ;;
2814 cook)
2815 # Compile and generate a package. Just execute tazwok with
2816 # the good commands.
2818 check_root
2819 get_tazwok_config
2820 source_lib report
2821 report start
2822 update_wan_db
2823 check_for_commit
2824 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
2825 [ "$plan_sort_wandb" ] && sort -o $wan_db $wan_db && unset plan_sort_wandb
2826 if [ "$plan_regen_cookorder" ]; then
2827 [ "$(sed 1!d $cookorder)" = "#PlanSort" ] || \
2828 sed 1i"#PlanSort" -i $cookorder
2829 fi
2830 cook
2831 ;;
2832 sort-cooklist)
2833 check_root
2834 get_tazwok_config
2835 check_for_list
2836 report(){ : ; }
2837 # When using sort-cooklist, the script should behave as for gen-cooklist
2838 # The only difference between these two is where the output is sent.
2839 COMMAND=gen-cooklist
2840 gen_cook_list
2841 cp -af $tmp/cooklist $LIST
2842 ;;
2843 cook-list)
2844 # Cook all packages listed in a file or in default cooklist.
2845 check_root
2846 get_options_list="pkg forced"
2847 get_tazwok_config
2848 source_lib report
2849 report start
2850 if ! [ "$pkg" ]; then
2851 [ "$LIST" ] && check_for_list
2852 fi
2853 gen_cook_list
2854 cook_list
2855 ;;
2856 clean)
2857 # Clean up a package work directory + those which want it.
2859 get_tazwok_config
2860 check_for_package_on_cmdline
2861 check_for_receipt
2862 source_lib report
2863 report start
2864 . $RECEIPT
2865 clean
2866 ;;
2867 gen-clean-wok)
2868 # Generate a clean wok from the current wok by copying all receipts
2869 # and stuff directory.
2871 get_tazwok_config
2872 source_lib report
2873 report start
2874 if [ -z "$ARG" ]; then
2875 echo -e "\nPlease specify the destination for the new clean wok.\n" >&2
2876 exit 1
2877 else
2878 dest=$ARG
2879 mkdir -p $dest
2880 fi
2881 report step "Creating clean wok in : $dest"
2882 for pkg in `ls -1 $WOK`
2883 do
2884 copy_cooking_stuff $WOK $pkg $dest
2885 done
2886 [ -d $WOK/.hg ] && cp -a $WOK/.hg $dest
2887 report end-step
2888 echo "Packages cleaned : `ls -1 $dest | wc -l`"
2889 echo ""
2890 ;;
2891 clean-wok)
2892 # Clean all packages in the work directory.
2894 get_tazwok_config
2895 source_lib report
2896 report start
2897 report step "Cleaning wok"
2898 for PACKAGE in `ls -1 $WOK`
2899 do
2900 set_common_path
2901 source_receipt
2902 clean
2903 done
2904 echo "`ls -1 $WOK | wc -l` packages cleaned."
2905 ;;
2906 clean-src)
2907 # Remove tarball unrelated to wok receipts from src repo.
2908 check_root
2909 get_options_list="forced"
2910 get_tazwok_config
2911 cd $SOURCES_REPOSITORY
2912 echo -n "Checking $SOURCES_REPOSITORY..."
2913 for TARBALL in *; do
2914 [ "$TARBALL" = sources.list ] && continue
2915 grep -q $'\t'$TARBALL$ $SOURCES_REPOSITORY/sources.list || \
2916 echo $TARBALL >> $tmp/obsolete
2917 done
2918 status
2919 if ! [ -f $tmp/obsolete ]; then
2920 echo "No sources need to be removed."
2921 exit 1
2922 fi
2923 echo ""
2924 echo -e "\033[1mObsolete/unrelated-to-wok sources :\033[0m"
2925 horizontal_line
2926 cat $tmp/obsolete
2927 horizontal_line
2928 echo "$(wc -l $tmp/obsolete | cut -f1 -d' ') tarballs to remove."
2929 echo ""
2930 echo -n "Please confirm before removing (type uppercase YES): "
2931 read answer
2932 if [ "$answer" = YES ]; then
2933 echo -n "Removing old sources..."
2934 cat $tmp/obsolete | while read i; do
2935 rm -f $SOURCES_REPOSITORY/$i
2936 done
2937 status
2938 fi
2939 ;;
2940 gen-list)
2941 get_tazwok_config
2942 if [ "$2" ]; then
2943 if [ -d "$2" ]; then
2944 pkg_repository=$2
2945 else
2946 echo -e "\nUnable to find directory : $2\n" >&2
2947 exit 1
2948 fi
2949 fi
2951 source_lib report
2952 report start
2953 if [ "$pkg_repository" ]; then
2954 gen_packages_db
2955 else
2956 pkg_repository=$PACKAGES_REPOSITORY && gen_packages_db
2957 pkg_repository=$INCOMING_REPOSITORY && gen_packages_db
2958 fi
2959 ;;
2960 check-list)
2961 # The directory to move into by default is the repository,
2962 # if $2 is not empty cd into $2.
2964 get_tazwok_config
2965 if [ "$2" ]; then
2966 if [ -d "$2" ]; then
2967 pkg_repository=$2
2968 else
2969 echo -e "\nUnable to find directory : $2\n" >&2
2970 exit 1
2971 fi
2972 fi
2974 source_lib report
2975 report start
2976 if [ "$pkg_repository" ]; then
2977 update_packages_db
2978 else
2979 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2980 pkg_repository=$INCOMING_REPOSITORY && update_packages_db
2981 fi
2982 ;;
2983 new-tree)
2984 # Just create a few directories and generate an empty receipt to prepare
2985 # the creation of a new package.
2987 get_tazwok_config
2988 check_for_package_on_cmdline
2989 clean_wok=$LOCAL_REPOSITORY/clean-wok
2990 if [ -d $clean_wok/$PACKAGE ]; then
2991 echo -e "\n$PACKAGE package tree already exists.\n" >&2
2992 exit 1
2993 fi
2994 echo "Creating : $clean_wok/$PACKAGE"
2995 mkdir $clean_wok/$PACKAGE
2996 cd $clean_wok/$PACKAGE
2997 echo -n "Preparing the receipt..."
2999 # Default receipt begin.
3001 echo "# SliTaz package receipt." > receipt
3002 echo "" >> receipt
3003 echo "PACKAGE=\"$PACKAGE\"" >> receipt
3004 # Finish the empty receipt.
3005 cat >> receipt << "EOF"
3006 VERSION=""
3007 CATEGORY=""
3008 SHORT_DESC=""
3009 MAINTAINER=""
3010 DEPENDS=""
3011 TARBALL="$PACKAGE-$VERSION.tar.gz"
3012 WEB_SITE=""
3013 WGET_URL=""
3015 # Rules to configure and make the package.
3016 compile_rules()
3018 cd $src
3019 ./configure && make && make install
3022 # Rules to gen a SliTaz package suitable for Tazpkg.
3023 genpkg_rules()
3025 mkdir -p $fs/usr
3026 cp -a $_pkg/usr/bin $fs/usr
3029 EOF
3031 # Default receipt end.
3033 status
3034 # Interactive mode, asking and seding.
3035 if [ "$3" = "--interactive" ]; then
3036 echo "Entering interactive mode..."
3037 echo "================================================================================"
3038 echo "Package : $PACKAGE"
3039 # Version.
3040 echo -n "Version : " ; read anser
3041 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
3042 # Category.
3043 echo -n "Category : " ; read anser
3044 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
3045 # Short description.
3046 echo -n "Short desc : " ; read anser
3047 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
3048 # Maintainer.
3049 echo -n "Maintainer : " ; read anser
3050 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
3051 # Web site.
3052 echo -n "Web site : " ; read anser
3053 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
3054 echo ""
3055 # Wget URL.
3056 echo "Wget URL to download source tarball."
3057 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
3058 echo -n "Wget url : " ; read anser
3059 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
3060 # Ask for a stuff dir.
3061 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
3062 if [ "$anser" = "y" ]; then
3063 echo -n "Creating the stuff directory..."
3064 mkdir stuff && status
3065 fi
3066 # Ask for a description file.
3067 echo -n "Are you going to write a description ? (y/N) : " ; read anser
3068 if [ "$anser" = "y" ]; then
3069 echo -n "Creating the description.txt file..."
3070 echo "" > description.txt && status
3071 fi
3072 echo "================================================================================"
3073 echo ""
3074 fi
3075 ;;
3076 remove)
3077 # Remove a package from the wok.
3079 get_tazwok_config
3080 check_for_package_on_cmdline
3081 echo ""
3082 echo -n "Please confirm deletion (y/N) : "; read anser
3083 if [ "$anser" = "y" ]; then
3084 echo -n "Removing $PACKAGE..."
3085 rm -rf $WOK/$PACKAGE && status
3086 echo ""
3087 fi
3088 ;;
3089 update-wok)
3090 # Pull and update a Hg wok.
3091 get_options_list="local"
3092 get_tazwok_config
3093 source_lib report
3094 report start
3095 clean_wok=$LOCAL_REPOSITORY/clean-wok
3096 cd $clean_wok
3097 if ! [ "$local" ]; then
3098 if [ "$WOK_UPDATE_METHOD" = hg ]; then
3099 if ! [ -f "$INSTALLED/mercurial/receipt" ]; then
3101 # Auto-install only if we are in a cook chroot.
3102 if [ -x /usr/bin/clean-chroot ]; then
3103 tazpkg get-install mercurial
3104 else
3105 echo "" >&2
3106 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
3107 echo "">&2
3108 exit 1
3109 fi
3110 fi
3112 report step "Getting wok changes using hg"
3113 if [ -d .hg ]; then
3114 hg pull -u || exit 1
3115 else
3116 hg clone $HG_WOK . || exit 1
3117 fi
3118 report end-step
3119 [ -x /usr/bin/clean-chroot ] && clean-chroot
3120 else
3121 report step "Getting wok changes using tarball"
3122 { mkdir .tmp && cd .tmp
3123 wget "$TARBALL_WOK" &&
3124 case $TARBALL_WOK in
3125 *bz2) tar xjf *.bz2 -C wok; rm *.bz2;;
3126 *lzma) unlzma -c *.lzma | tar xf - -C wok; rm *.lzma ;;
3127 *gz) tar xzf *.gz -C wok; rm*.gz ;;
3128 esac &&
3129 rm -r $(ls -d $clean_wok/*) &&
3130 cp -a wok/* $clean_wok &&
3131 cd .. &&
3132 rm -r .tmp
3133 } || { echo "That's not cool: it fails!" >&2
3134 report end-step
3135 exit 1; }
3136 report end-step
3137 fi
3138 fi
3139 report step "Appending changes to wok"
3141 # Handle removed files/dir.
3142 cd $WOK
3143 for dir in *; do
3144 [ -d "$clean_wok/$dir" ] || rm -rf $dir
3145 done
3146 for file in */receipt */description.txt; do
3147 [ -f "$clean_wok/$file" ] || rm -rf $file
3148 done
3149 for i in $(find */stuff 2>/dev/null); do
3150 [ -e "$clean_wok/$i" ] || rm -rf $i
3151 done
3153 cp -a $clean_wok/* $WOK
3154 report end-step
3155 ;;
3156 maintainers)
3157 get_tazwok_config
3158 echo ""
3159 echo "List of maintainers for: $WOK"
3160 echo "================================================================================"
3161 touch /tmp/slitaz-maintainers
3162 for pkg in $WOK/*
3163 do
3164 . $pkg/receipt
3165 if ! fgrep -q "$MAINTAINER" /tmp/slitaz-maintainers; then
3166 echo "$MAINTAINER" >> /tmp/slitaz-maintainers
3167 echo "$MAINTAINER"
3168 fi
3169 done
3170 echo "================================================================================"
3171 echo "Maintainers: `cat /tmp/slitaz-maintainers | wc -l`"
3172 echo ""
3173 # Remove tmp files
3174 rm -f /tmp/slitaz-maintainers
3175 ;;
3176 maintained-by)
3177 # Search for packages maintained by a contributor.
3178 get_tazwok_config
3179 if [ ! -n "$2" ]; then
3180 echo "Specify a name or email of a maintainer." >&2
3181 exit 1
3182 fi
3183 echo "Maintainer packages"
3184 echo "================================================================================"
3185 for pkg in $WOK/*
3186 do
3187 . $pkg/receipt
3188 if echo "$MAINTAINER" | fgrep -q "$2"; then
3189 echo "$PACKAGE"
3190 packages=$(($PACKAGEs+1))
3191 fi
3192 done
3193 echo "================================================================================"
3194 echo "Packages maintained by $2: $PACKAGEs"
3195 echo ""
3196 ;;
3197 tags)
3198 get_tazwok_config
3199 echo -e "\n\033[1mTags list :\033[0m"
3200 horizontal_line
3201 cd $WOK
3202 for i in */receipt; do
3203 unset TAGS
3204 source $i
3205 for t in $TAGS; do
3206 grep -q ^$t$ $tmp/tags && continue
3207 echo $t | tee -a $tmp/tags
3208 done
3209 done
3210 horizontal_line
3211 echo "$(wc -l $tmp/tags | cut -f1 -d ' ') tags listed."
3212 ;;
3213 check-src)
3214 # Verify if upstream package is still available.
3216 get_tazwok_config
3217 check_for_package_on_cmdline
3218 check_for_receipt
3219 source_receipt
3220 check_src()
3222 for url in $@; do
3223 busybox wget -s $url 2>/dev/null && break
3224 done
3226 if [ "$WGET_URL" ];then
3227 echo -n "$PACKAGE : "
3228 check_src $WGET_URL
3229 status
3230 else
3231 echo "No tarball to check for $PACKAGE"
3232 fi
3233 ;;
3234 get-src)
3235 check_root
3236 get_options_list="target nounpack"
3237 get_tazwok_config
3238 check_for_package_on_cmdline
3239 check_for_receipt
3240 source_receipt
3241 if [ "$WGET_URL" ];then
3242 source_lib report
3243 report start
3244 check_for_tarball
3245 else
3246 echo "No tarball to download for $PACKAGE"
3247 fi
3248 ;;
3249 check-commit)
3250 check_root
3251 get_options_list="missing forced"
3252 get_tazwok_config
3253 source_lib report
3254 report start
3255 if [ "$forced" ]; then
3256 rm -f $WOK/*/md5
3257 unset forced
3258 fi
3259 if [ "$missing" ]; then
3260 pkg=$(ls -1 $WOK)
3261 else
3262 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3263 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3264 } | sort -u)"
3265 fi
3266 gen_cook_list
3267 ;;
3268 cook-commit)
3269 check_root
3270 get_options_list="missing forced"
3271 get_tazwok_config
3272 source_lib report
3273 report start
3274 if [ "$forced" ]; then
3275 rm -f $WOK/*/md5
3276 unset forced
3277 fi
3278 if [ "$missing" ]; then
3279 pkg=$(ls -1 $WOK)
3280 else
3281 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3282 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3283 } | sort -u)"
3284 fi
3285 gen_cook_list
3286 cook_list
3287 ;;
3288 cook-all)
3289 check_root
3290 get_options_list="forced missing"
3291 get_tazwok_config
3292 source_lib report
3293 report start
3294 if [ "$missing" ]; then
3295 pkg=$(ls -1 $WOK)
3296 else
3297 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3298 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3299 } | sort -u)"
3300 fi
3301 gen_cook_list
3302 cook_list
3303 ;;
3304 gen-wok-db)
3305 check_root
3306 get_tazwok_config
3307 source_lib report
3308 report start
3309 gen_wok_db
3310 ;;
3311 report)
3312 get_tazwok_config
3313 cd $PACKAGES_REPOSITORY
3314 if [ "$2" ]; then
3315 case $2 in
3316 commit|cooklist|incoming|broken|blocked)
3317 show="$2"
3318 ;;
3319 *)
3320 echo "usage : tazwok report [commit|cooklist|incoming|broken|blocked]" >&2
3321 exit 1
3322 ;;
3323 esac
3324 else
3325 show="commit cooklist incoming broken blocked"
3326 fi
3327 for i in $show; do
3328 if [ -s $i ]; then
3329 echo ""
3330 echo -e "\033[1m$i\033[0m"
3331 echo "================================================================================"
3332 cat $i
3333 echo "================================================================================"
3334 echo ""
3335 fi
3336 done
3337 ;;
3338 check-incoming)
3339 check_root
3340 get_options_list="forced"
3341 get_tazwok_config
3342 source_lib report
3343 report start
3344 [ -f $LOCAL_RESOSITORY/incoming ] && rm [ -f $LOCAL_REPOSITORY/incoming ]
3345 report step "Checking $INCOMING_REPOSITORY"
3346 report open-bloc
3347 [ -f $LOCAL_REPOSITORY/log/incoming.html ] && rm $LOCAL_REPOSITORY/log/incoming.html
3348 report sublog $LOCAL_REPOSITORY/log/incoming.html
3349 echo "incoming" > $LOCAL_REPOSITORY/log/package
3350 check_for_incoming
3351 report end-sublog
3352 report close-bloc
3353 ;;
3354 configure-chroot)
3355 check_root
3356 get_tazwok_config
3357 if [ -f /usr/bin/tazchroot ]; then
3358 cd $LOCAL_REPOSITORY
3359 configure_tazchroot
3360 else
3361 echo "The package tazchroot needs to be installed" >&2
3362 exit 1
3363 fi
3364 ;;
3365 chroot)
3366 check_root
3367 get_tazwok_config
3368 # Merge this and the other chroot function ?.
3369 if [ -f /usr/bin/tazchroot ]; then
3370 cd $LOCAL_REPOSITORY
3371 [ ! -f tazchroot.conf ] && configure_tazchroot
3372 tazchroot
3373 else
3374 echo "The package tazchroot needs to be installed" >&2
3375 exit 1
3376 fi
3377 ;;
3378 cook-toolchain)
3379 check_root
3380 get_tazwok_config
3381 echo -n "" > $PACKAGES_REPOSITORY/broken
3382 if [ -f /usr/bin/tazchroot ]; then
3383 cd $LOCAL_REPOSITORY
3384 [ -f tazchroot.conf ] || configure_tazchroot
3386 # Plan to recook all packages.
3387 if tazchroot cook-toolchain; then
3388 source_lib report
3389 report start
3390 pkg="$(grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt \
3391 $INCOMING_REPOSITORY/packages.txt | sort -u)"
3392 forced=yes
3393 gen_cook_list
3394 fi
3396 # Remove chroot where toolchain has been cooked.
3397 source $LOCAL_REPOSITORY/tazchroot.conf
3398 rm -r $LOCAL_REPOSITORY/chroot
3400 else
3401 echo -e "\nThe package tazchroot needs to be installed.\n" >&2
3402 exit 1
3403 fi
3404 ;;
3405 webserver)
3406 check_root
3407 get_tazwok_config
3408 if [ "$ARG" = on ]; then
3409 if [ "$WEBSERVER" ] && [ -f "$WEBSERVER/repositories.list" ] && \
3410 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3411 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3412 exit 1
3413 fi
3414 if ! [ -f $LOCAL_REPOSITORY/tazchroot.conf ]; then
3415 tazwok configure-chroot ${undigest:+--undigest=$undigest} --SLITAZ_VERSION=$SLITAZ_VERSION --SLITAZ_DIR=$SLITAZ_DIR
3416 fi
3417 for pkg in php lighttpd; do
3418 [ -d $INSTALLED/$pkg ] || missing="$missing $pkg"
3419 done
3420 if [ "$missing" ]; then
3421 echo "You need to install these packages to start webserver: $missing." >&2
3422 exit 1
3423 fi
3424 if [ ! -f "$LOCAL_REPOSITORY/tazwok.conf" ]; then
3425 echo "Copying /etc/slitaz/tazwok.conf to $LOCAL_REPOSITORY/tazwok.conf: webserver is configured repository-by-repository."
3426 cp /etc/slitaz/tazwok.conf $LOCAL_REPOSITORY
3427 fi
3428 if ! [ "$WEBSERVER" ]; then
3429 echo -n "Where to store php pages (default: /var/www/vhosts/bb)? "
3430 read WEBSERVER
3431 [ "$WEBSERVER" ] || WEBSERVER="/var/www/vhosts/bb"
3432 fi
3433 if [ -f "$WEBSERVER/repositories.list" ] && \
3434 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3435 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3436 exit 1
3437 fi
3438 mkdir -p $WEBSERVER
3439 echo "${undigest:-$SLITAZ_VERSION}" >> $WEBSERVER/repositories.list
3440 for file in index.php log.php download.php; do
3441 [ -f "$WEBSERVER/$file" ] || ln -s /usr/share/slitaz/web-bb/$file $WEBSERVER
3442 done
3443 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3444 ln -s $dir $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3445 done
3446 source $LOCAL_REPOSITORY/tazchroot.conf
3447 echo "<?php
3449 // Web interface configuration
3451 \$version=\"${undigest:-$SLITAZ_VERSION}\";
3452 \$chroot=\"$chroot_dir\";
3453 \$lockfile=\"\$chroot/proc/1/status\";
3454 \$db_dir=\"$PACKAGES_REPOSITORY\";
3455 \$log_dir=\"$LOCAL_REPOSITORY/log\";
3456 \$packages=\"$PACKAGES_REPOSITORY\";
3457 \$incoming=\"$INCOMING_REPOSITORY\";
3458 \$wok=\"$WOK\";
3460 ?>" > $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3461 [ -L "$WEBSERVER/web" ] || ln -s /usr/share/slitaz/web $WEBSERVER
3462 echo "WEBSERVER=\"$WEBSERVER\"" >> $LOCAL_REPOSITORY/tazwok.conf
3463 if [ -L "$WEBSERVER/conf.php" ]; then
3464 echo "Do you want to make ${undigest:-$SLITAZ_VERSION} the default page (y/N) ? "
3465 read answer
3466 if [ "$answer" = y ]; then
3467 rm $WEBSERVER/conf.php
3468 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3469 fi
3470 else
3471 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3472 fi
3473 elif [ "$ARG" = off ]; then
3474 if ! [ "$WEBSERVER" ]; then
3475 echo "No webserver running for ${undigest:-$SLITAZ_VERSION}" >&2
3476 exit 1
3477 fi
3478 sed '/^WEBSERVER/d' -i $LOCAL_REPOSITORY/tazwok.conf
3479 sed "/^${undigest:-$SLITAZ_VERSION}$/d" -i $WEBSERVER/repositories.list
3480 rm $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3481 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3482 rm $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3483 done
3484 if ! [ -s "$WEBSERVER/repositories.list" ]; then
3485 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"
3486 rm $WEBSERVER/conf.php
3487 elif [ "$(readlink $WEBSERVER/conf.php)" = "$WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php" ]; then
3488 echo "${undigest:-$SLITAZ_VERSION} was the default version to use; switched to : $(sed 1!d $WEBSERVER/repositories.list)"
3489 rm $WEBSERVER/conf.php
3490 ln -s $WEBSERVER/conf-$(sed 1!d $WEBSERVER/repositories.list).php $WEBSERVER/conf.php
3491 fi
3492 else
3493 echo "Usage: tazwok webserver on/off" >&2
3494 exit 1
3495 fi
3496 ;;
3497 block)
3498 # Add a pkg name to the list of blocked packages.
3499 get_tazwok_config
3500 check_root
3501 check_for_package_on_cmdline
3502 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3503 echo "Can't find $PACKAGE in wok." >&2
3504 echo ""
3505 exit 1
3506 fi
3507 echo ""
3508 if grep -qs "^$PACKAGE$" $blocked; then
3509 echo "$PACKAGE is already in the blocked packages list." >&2
3510 echo ""
3511 exit 1
3512 else
3513 echo -n "Adding $PACKAGE to : $blocked... "
3514 echo "$PACKAGE" >> $blocked
3515 status
3516 if grep -q "^$PACKAGE$" $cooklist; then
3517 echo -n "Removing $PACKAGE from : $cooklist... "
3518 sed -i /"^$PACKAGE$"/d $cooklist
3519 status
3520 fi
3521 fi
3522 echo "" ;;
3523 unblock)
3524 # Remove a pkg name from the list of blocked packages.
3525 get_tazwok_config
3526 check_root
3527 check_for_package_on_cmdline
3528 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3529 echo "Can't find $PACKAGE in wok." >&2
3530 echo ""
3531 exit 1
3532 fi
3533 echo ""
3534 if grep -qs "^$PACKAGE$" $blocked; then
3535 echo -n "Removing $PACKAGE from : $blocked... "
3536 sed -i /"^$PACKAGE$"/d $blocked
3537 sed -i '/^$/d' $blocked
3538 status
3539 else
3540 echo "$PACKAGE is not in the blocked packages list." >&2
3541 echo ""
3542 exit 1
3543 fi
3544 echo "" ;;
3545 usage|*)
3546 # Print usage also for all unknown commands.
3548 usage
3549 ;;
3550 esac
3552 # If a cook command has been used, refresh ID of the repository to avoid
3553 # useless upgrade at next cook command.
3554 case $COMMAND in
3555 cook*)
3556 for repo in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY \
3557 $( [ "$undigest" -a ! "$ref_USE_ONLINE_PKG" ] && echo $ref_PACKAGES_REPOSITORY ); do
3558 [ -f $repo/ID ] || continue
3559 MIRROR_path=$(grep -l "^$repo$" $LOCALSTATE/mirror $LOCALSTATE/undigest/*/mirror)
3560 LOCALSTATE_path=${MIRROR_path%/mirror}
3561 cp -a $repo/ID $LOCALSTATE_path
3562 done
3563 ;;
3564 esac
3566 report stop 2>/dev/null
3567 exit 0