tazwok view tazwok @ rev 449

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