tazwok view tazwok @ rev 424

Merge bugfix from default
author Antoine Bodin <gokhlayeh@slitaz.org>
date Sun Mar 06 19:02:57 2011 +0100 (2011-03-06)
parents 6db209f174b3 bf449151a342
children 556a89fc8607
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 excepted 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 datas.
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 avaible options.
70 \033[1mImportant - *: \033[0m Commands which need a rewrite."
71 }
73 # This function display an error message without returning any error code.
74 # It also log 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 use src variable in his
298 # genpkg_rules: it maybe need 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 use \$src in his 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 founded
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 broken depend(s) : $broken_pkg" >&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 theses 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 check 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 are defined into the receipt (this is no more 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 the unpacked tarball into 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 "Put all files into $WOK/$PACKAGE; not sure about how to handle this tarball (no root dir)... Please try to remove src/_pkg definition from receipt if you encounter a problem."
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 use it into 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 are available."
674 CFLAGS="${CFLAGS/-pipe}"
675 CXXFLAGS="${CXXFLAGS/-pipe}"
676 fi
677 unset freeram
679 # Set cook environnement 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 screw 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 #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 build-depend."
763 continue
764 fi
765 ;;
766 subversion\|*)
767 file=${file#subversion|}
768 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/subversion/receipt ] && tazpkg get-install subversion --forced
769 if [ -f $INSTALLED/subversion/receipt ]; then
770 mkdir $tmp_src
771 cd $tmp_src
772 if [ "$BRANCH" ]; then
773 echo t | svn co $file -r $BRANCH ${src##*/} && rm -rf ${src##*/}/.svn* && break
774 else
775 echo t | svn co $file ${src##*/} && rm -rf ${src##*/}/.svn* && break
776 fi
777 revert_vcs_failure
778 else
779 tazwok_warning "Needs subversion to download the source tarball from $file, please add it as build-depend."
780 continue
781 fi
782 ;;
783 mercurial\|*)
784 file=${file#mercurial|}
785 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/mercurial/receipt ] && tazpkg get-install mercurial --forced
786 if [ -f $INSTALLED/mercurial/receipt ]; then
787 mkdir $tmp_src
788 cd $tmp_src
789 if [ "$BRANCH" ]; then
790 hg clone $file --rev $BRANCH ${src##*/} && rm -rf ${src##*/}/.hg* && break
791 else
792 hg clone $file ${src##*/} && rm -rf ${src##*/}/.hg* && break
793 fi
794 revert_vcs_failure
795 else
796 tazwok_warning "Needs mercurial to download the source tarball from $file, please add it as build-depend."
797 continue
798 fi
799 ;;
800 https*)
801 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/wget/receipt ] && tazpkg get-install wget --forced
802 if [ -d $INSTALLED/wget ]; then
803 if [ "${WGET_URL%$TARBALL}" = "$WGET_URL" ] && [ "$file" = "$WGET_URL" ]; then
804 wget -q --no-check-certificate -O $TARBALL $file && break
805 else
806 wget -q --no-check-certificate $file && break
807 fi
808 else
809 tazwok_warning "Needs wget to download the source tarball from $file, please add it as build-depend."
810 continue
811 fi
812 ;;
813 http*|ftp*)
814 # Handle crappy URL.
815 if [ "$COMMAND" = get-src ]; then
816 if [ "${DEPENDS/wget}" != "$DEPENDS" ] || [ "${BUILD_DEPENDS/wget}" != "$BUILD_DEPENDS" ]; then
817 [ -f $INSALLED/wget/receipt ] || tazpkg get-install wget --forced
818 fi
819 fi
820 if [ "${WGET_URL%$TARBALL}" = "$WGET_URL" ] && [ "$file" = "$WGET_URL" ]; then
821 wget -q -O $TARBALL $file && break
822 else
823 wget -q $file && break
824 fi
825 ;;
826 esac
827 done
828 }
830 # Regenerate every package that wants a PACKAGE compiled
831 refresh_packages_from_compile()
832 {
833 # make tazwok genpkg happy
834 mkdir $WOK/$PACKAGE/taz
836 # Cook rwanted in default or specied order
837 genlist=" $(look_for_rwanted | tr '\n' ' ') "
838 for i in $(look_for_cookopt genpkg | tac); do
839 [ "${genlist/ $i }" = "$genlist" ] && continue
840 genlist=" $i${genlist/ $i / }"
841 done
842 if [ "$genlist" ]; then
843 local PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
844 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
845 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
846 src _pkg DESTDIR CONFIG_SITE RECEIPT LOG stuff wanted_stuff
847 for PACKAGE in $genlist; do
848 set_common_path
849 gen_package
850 done
851 fi
852 }
854 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
855 # so some packages need to copy these files with the receipt and genpkg_rules.
856 # This function is executed by gen_package when 'tazwok genpkg'.
857 copy_generic_files()
858 {
859 # In most cases, locales are in $_pkg/usr/share/locale so we copy files
860 # using generic variables and $LOCALE from Tazwok config file.
861 if [ "$LOCALE" ]; then
862 if [ -d "$_pkg/usr/share/locale" ]; then
863 for i in $LOCALE
864 do
865 if [ -d "$_pkg/usr/share/locale/$i" ]; then
866 mkdir -p $fs/usr/share/locale
867 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
868 fi
869 done
870 fi
871 fi
873 # Pixmaps (PNG or/and XPM only). Some icons/images can be added through
874 # genpkg_rules and generic copy can be disabled with GENERIC_PIXMAPS="no"
875 # in pkg receipt.
876 if [ "$GENERIC_PIXMAPS" != "no" ]; then
877 if [ -d "$_pkg/usr/share/pixmaps" ]; then
878 mkdir -p $fs/usr/share/pixmaps
879 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
880 $fs/usr/share/pixmaps 2>/dev/null
881 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
882 $fs/usr/share/pixmaps 2>/dev/null
883 fi
885 # Custom or homemade PNG pixmap can be in stuff.
886 if [ -f "stuff/$PACKAGE.png" ]; then
887 mkdir -p $fs/usr/share/pixmaps
888 cp -a stuff/$PACKAGE.png $fs/usr/share/pixmaps
889 fi
890 fi
892 # Desktop entry (.desktop).
893 if [ -d "$_pkg/usr/share/applications" ]; then
894 cp -a $_pkg/usr/share/applications $fs/usr/share
895 fi
897 # Homemade desktop file(s) can be in stuff.
898 if [ -d "stuff/applications" ]; then
899 mkdir -p $fs/usr/share
900 cp -a stuff/applications $fs/usr/share
901 fi
902 if [ -f "stuff/$PACKAGE.desktop" ]; then
903 mkdir -p $fs/usr/share/applications
904 cp -a stuff/$PACKAGE.desktop $fs/usr/share/applications
905 fi
906 }
908 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
909 strip_package()
910 {
911 report step "Executing strip on all files"
913 # Binaries.
914 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
915 do
916 if [ -d "$dir" ]; then
917 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
918 fi
919 done
921 # Libraries.
922 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
923 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
924 report end-step
925 }
927 # Remove .pyc and .pyo files from packages
928 py_compiled_files_remove()
929 {
930 report step "Removing all .pyc and .pyo files from package ..."
931 find $fs -type f -name "*.pyc" -delete 2>/dev/null
932 find $fs -type f -name "*.pyo" -delete 2>/dev/null
933 report end-step
934 }
936 # Check FSH in a slitaz package (Path: /:/usr)
937 check_fsh()
938 {
939 cd $WOK/$PACKAGE/taz/*/fs
940 if [ -z "$(find * -type f)" ] && [ "$CATEGORY" != meta ]; then
941 echo "$PACKAGE fs is empty." >&2
942 cd $WOK/$PACKAGE && rm -rf taz
943 return 1
944 fi
945 [ -n "$FSH" ] || FSH="bin boot dev etc home init lib media mnt proc \
946 root sbin share sys tmp usr var vz usr/bin usr/games usr/include usr/lib \
947 usr/local usr/sbin usr/share usr/src"
948 for i in `ls -d * usr/* 2>/dev/null`
949 do
950 if ! echo $FSH | fgrep -q $i; then
951 echo "Wrong path: /$i" >&2
952 error=1
953 fi
954 done
955 if [ "$error" = "1" ]; then
956 cat << _EOT_
958 Package will install files in a non standard directory and won't be generated.
959 You may have a wrong copy path in genpkg_rules or need to add some options to
960 configure in compile_rules. Some valid options for SliTaz (Linux FSH):
962 --prefix=/usr
963 --sysconfdir=/etc
964 --libexecdir=/usr/lib/(pkgname)
965 --localstatedir=/var
966 --mandir=/usr/share/man
967 --infodir=/usr/share/info
969 For more information please read SliTaz docs and run: ./configure --help
970 ================================================================================
971 $PACKAGE package generation aborted.
973 _EOT_
975 # Dont generate a corrupted package.
976 cd $WOK/$PACKAGE && rm -rf taz
977 return 1
978 fi
979 return 0
980 }
982 gen_cookmd5()
983 {
984 # md5sum of cooking stuff make tazwok able to check for changes
985 # without hg.
986 cd $WOK/$PACKAGE
987 md5sum receipt > md5
988 [ -f description.txt ] && md5sum description.txt >> md5
989 if [ -d stuff ]; then
990 find stuff | while read file; do
991 md5sum $file >> md5
992 done
993 fi
994 }
996 set_pkg_broken()
997 {
998 grep -q ^$PACKAGE$ $broken || echo $PACKAGE >> $broken
1000 # Remove pkg from cooklist to avoid re-cook it if no changes happens
1001 # in the cook stuff.
1002 sed "/^$PACKAGE$/d" -i $cooklist $commit
1004 gen_cookmd5
1006 # Return 1 to make report know that's mother-function failed.
1007 return 1
1010 # Create a package tree and build the gziped cpio archive
1011 # to make a SliTaz (.tazpkg) package.
1012 gen_package()
1014 check_root
1015 check_for_package_on_cmdline
1016 check_for_receipt
1017 source_receipt
1019 # May compute VERSION
1020 if grep -q ^get_version $RECEIPT; then
1021 get_version
1022 fi
1023 check_for_wanted
1024 cd $WOK/$PACKAGE
1026 # Remove old Tazwok package files.
1027 [ -d "taz" ] && rm -rf taz
1029 # Create the package tree and set useful variables.
1030 fs=$WOK/$PACKAGE/taz/$PACKAGE-$VERSION/fs
1031 mkdir -p $fs
1033 # Set $src for standard package and $_pkg variables.
1034 set_src_path
1035 set_pkg_path
1037 # Execute genpkg_rules, check package and copy generic files to build
1038 # the package.
1039 report step "Building $PACKAGE with the receipt"
1040 report open-bloc
1041 if look_for_cookopt !fs; then
1043 elif grep -q ^genpkg_rules $RECEIPT; then
1045 # Log process.
1046 echo "executing genpkg_rules" >> $LOG
1047 report step "Executing genpkg_rules"
1048 ( set -e; genpkg_rules ) || { set_pkg_broken; report close-bloc; return 1; }
1049 check_fsh || { set_pkg_broken; report close-bloc; return 1; }
1050 cd $WOK/$PACKAGE
1051 report end-step
1053 # Skip generic files for packages with a WANTED variable
1054 # (dev and splited pkgs).
1055 if [ ! "$WANTED" ]; then
1056 copy_generic_files
1057 fi
1058 look_for_cookopt !strip || strip_package
1059 py_compiled_files_remove
1060 else
1061 echo "No package rules to gen $PACKAGE..." >&2
1062 set_pkg_broken
1063 report close-bloc
1064 return 1
1065 fi
1067 # Copy the receipt and description (if exists) into the binary package tree.
1068 cd $WOK/$PACKAGE
1069 report step "Copying the receipt"
1070 cp receipt taz/$PACKAGE-$VERSION
1071 report end-step
1072 if grep -q ^get_version $RECEIPT; then
1073 report step "Updating version in receipt"
1074 sed -i "s/^VERSION=.*/VERSION=\"$VERSION\"/" \
1075 taz/$PACKAGE-$VERSION/receipt
1076 report end-step
1077 fi
1078 if [ -f "description.txt" ]; then
1079 report step "Copying the description file"
1080 cp description.txt taz/$PACKAGE-$VERSION
1081 report end-step
1082 fi
1084 # Generate md5 of cooking stuff to look for commit later.
1085 gen_cookmd5
1086 echo -e "\n# md5sum of cooking stuff :" >> taz/$PACKAGE-$VERSION/receipt
1087 cat md5 | sed 's/^/# /' >> taz/$PACKAGE-$VERSION/receipt
1089 # Create the files.list by redirecting find output.
1090 report step "Creating the list of files"
1091 cd taz/$PACKAGE-$VERSION
1092 LAST_FILE=""
1093 { find fs -print; echo; } | while read file; do
1094 if [ "$LAST_FILE" ]; then
1095 case "$file" in
1096 $LAST_FILE/*)
1097 case "$(ls -ld "$LAST_FILE")" in
1098 drwxr-xr-x\ *\ root\ *\ root\ *);;
1099 *) echo ${LAST_FILE#fs};;
1100 esac;;
1101 *) echo ${LAST_FILE#fs};;
1102 esac
1103 fi
1104 LAST_FILE="$file"
1105 done > files.list
1107 # Next, check if something has changed in lib files.
1108 if fgrep -q '.so' files.list; then
1109 for rep in $INCOMING_REPOSITORY $PACKAGES_REPOSITORY \
1110 $([ "$undigest" ] && echo $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming && \
1111 echo $SLITAZ_DIR/$SLITAZ_VERSION/packages); do
1112 prev_VERSION=$(get_pkg_version $rep)
1113 [ "$prev_VERSION" ] && pkg_file=$rep/$PACKAGE-$prev_VERSION.tazpkg && break
1114 done
1115 if [ "$pkg_file" ]; then
1116 report step "Look for major/minor update in libraries"
1117 get_pkg_files $pkg_file
1118 cd $WOK/$PACKAGE/taz/$PACKAGE-$VERSION
1119 fgrep ".so" files.list | egrep -v "[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*" | \
1120 while read lib; do
1121 fgrep -q "$lib" $pkg_files_dir/files.list && continue
1122 echo "A minor/major update in libraries is detected, planning re-cook of reverse-depends of $PACKAGE."
1123 for rdep in $(scan $PACKAGE --look_for=rdep | use_wanted); do
1124 [ "$rdep" = "${WANTED:-$PACKAGE}" ] && continue
1125 grep -q ^$rdep$ $blocked $cooklist && continue
1126 echo $rdep >> $cooklist
1127 done
1128 regen_cooklist=yes
1129 break
1130 done
1131 rm -r $pkg_files_dir
1132 unset pkg_file
1133 report end-step
1134 fi
1135 fi
1136 if [ ! "$EXTRAVERSION" ]; then
1137 case "$PACKAGE" in
1138 linux*);;
1139 *) EXTRAVERSION="$(grep '/lib/modules/.*-slitaz/' files.list |\
1140 head -1 | sed 's|/lib/modules/\(.*\)-slitaz/.*|_\1|')";;
1141 esac
1142 fi
1143 rm -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg 2> /dev/null
1144 report step "Creating md5sum of files"
1145 while read file; do
1146 [ -L "fs$file" ] && continue
1147 [ -f "fs$file" ] || continue
1148 md5sum "fs$file" | sed 's/ fs/ /'
1149 done < files.list > md5sum
1150 report end-step
1151 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
1152 2> /dev/null | awk '{ sz=$1 } END { print sz }')
1154 # Build cpio archives. Find, cpio and gzip the fs, finish by
1155 # removing the fs tree.
1156 # Don't log this because compression always output error messages.
1157 find fs -print | cpio -o -H newc | case "$PACKAGE-$COMPRESSION" in
1158 tazpkg-lzma) gzip > fs.cpio.gz;;
1159 *-lzma) lzma e fs.cpio.lzma -si;;
1160 *) gzip > fs.cpio.gz;;
1161 esac && rm -rf fs
1162 PACKED_SIZE=$(du -chs fs.cpio.* receipt files.list md5sum \
1163 description.txt 2> /dev/null | awk '{ sz=$1 } END { print sz }')
1164 report step "Updating receipt sizes"
1165 sed -i '/^PACKED_SIZE/d' receipt
1166 sed -i '/^UNPACKED_SIZE/d' receipt
1167 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1168 sed -i "s/^VERSION=$/VERSION=\"$VERSION\"/" receipt
1169 report end-step
1170 if [ "$EXTRAVERSION" ]; then
1171 report step "Updating receipt EXTRAVERSION"
1172 sed -i s/^EXTRAVERSION.*$// receipt
1173 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
1174 fi
1175 prev_VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
1176 remove_previous_package $INCOMING_REPOSITORY
1177 report step "Creating full cpio archive"
1178 find . -print | cpio -o -H newc > $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1180 # Restore package tree in case we want to browse it.
1181 report step "Restoring original package tree"
1182 { zcat fs.cpio.gz 2> /dev/null || unlzma -c fs.cpio.lzma; } | cpio --quiet -id
1183 rm fs.cpio.* && cd ..
1185 # Recook of reverse-depends if package was broken.
1186 if grep -q "^$PACKAGE$" $broken; then
1187 report step "Planning re-try a cook of reverse depends"
1188 sed "/^$PACKAGE$/d" -i $broken
1189 for rdep in $(look_for_rdep); do
1190 grep -q "^$rdep$" $broken || continue
1191 grep -q "^$rdep$" $cooklist && continue
1192 echo "Adding $rdep to the cooklist"
1193 echo $rdep >> $cooklist
1194 regen_cooklist=t
1195 done
1196 report end-step
1197 fi
1198 sed "/^$PACKAGE$/d" -i $commit $cooklist
1200 # Log process.
1201 echo "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg (done)" >> $LOG
1202 report close-bloc
1203 echo "Package $PACKAGE ($VERSION$EXTRAVERSION) generated."
1204 echo "Size : `du -sh $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
1205 echo ""
1208 ########################################################################
1209 # This section contains functions used by several other functions
1210 # bellow.
1211 ########################
1213 # Look for receipt/files.list in wok. If they can't be found, get them
1214 # from package. Accept one argument : absolute path to package.
1215 get_pkg_files()
1217 pkg_files_dir=$tmp/$(basename ${1%.tazpkg})
1218 mkdir -p $pkg_files_dir && \
1219 cd $pkg_files_dir && \
1220 cpio --quiet -idm receipt < $1 && \
1221 cpio --quiet -idm files.list < $1
1224 ########################################################################
1225 # This section contains functions to generate packages databases.
1226 ########################
1229 gen_packages_db()
1231 # pkg_repository can be $PACKAGES_REPOSITORY or $INCOMING_REPOSITORY.
1232 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1233 cd $pkg_repository
1234 report step "Generating packages lists: $pkg_repository"
1235 report open-bloc
1236 report step "Removing old files"
1237 for file in files.list.lzma packages.list packages.txt \
1238 packages.desc packages.equiv packages.md5; do
1239 rm -rf $file
1240 done
1241 touch files.list
1243 packages_db_start
1244 unset RECEIPT
1245 report step "Reading datas from all packages"
1246 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1247 get_packages_info
1248 done
1249 report end-step
1250 packages_db_end
1251 report close-bloc
1254 update_packages_db()
1256 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1257 cd $pkg_repository
1258 for file in packages.list packages.equiv packages.md5 packages.desc \
1259 packages.txt; do
1260 if [ ! -f "$file" ]; then
1261 gen_packages_db
1262 return
1263 fi
1264 done
1265 if [ -f files.list.lzma ]; then
1266 lzma d files.list.lzma files.list
1267 else
1268 gen_packages_db
1269 return
1270 fi
1271 report step "Updating packages lists: $pkg_repository"
1272 packages_db_start
1274 # Look for removed/update packages.
1275 touch stamp -r packages.list
1276 for PACKAGE in $(grep ^[0-9,a-z,A-Z] packages.txt); do
1277 pkg="$pkg_repository/$(grep -m1 ^$PACKAGE- packages.list).tazpkg"
1278 if ! [ -f "$pkg" ]; then
1279 erase_package_info
1280 else
1281 if [ "$pkg" -nt "stamp" ]; then
1282 updated_pkg="$updated_pkg
1283 $PACKAGE $pkg"
1284 elif [ ! -f $WOK/$PACKAGE/receipt ] && \
1285 [ "$COMMAND" = check-incoming -o "$pkg_repository" = "$INCOMING_REPOSITORY" ]; then
1286 erase_package_info
1287 echo "Removing $PACKAGE from $pkg_repository."
1288 rm $pkg
1289 rm -rf $WOK/$PACKAGE
1290 sed "/^$PACKAGE\t/d" -i $wan_db $dep_db $cookorder
1291 sed "/^$PACKAGE$/d" -i $cooklist $commit $blocked $broken
1292 rm -f $LOCAL_REPOSITORY/log/$PACKAGE.html
1293 if [ "$pkg_repository" = "$INCOMING_REPOSITORY" ] && \
1294 [ "$(sed 1!d $cookorder)" != "#PlanSort" ] ; then
1295 sed 1i"#PlanSort" -i $cookorder
1296 regen_cooklist=yes
1297 else
1298 echo "$PACKAGE" >> removed
1299 sed -n '1,10p' -i removed
1300 fi
1301 fi
1302 fi
1303 done
1304 rm stamp
1305 echo "$updated_pkg" | sed 1d | while read PACKAGE pkg; do
1306 erase_package_info
1307 get_packages_info
1308 done
1309 unset updated_pkg
1311 # Look for new packages.
1312 for pkg in $pkg_repository/*.tazpkg; do
1313 fgrep -q " ${pkg##*/}" packages.md5 || get_packages_info
1314 done
1315 report end-step
1316 packages_db_end
1319 packages_db_start()
1321 if [ -s packages.txt ]; then
1322 sed -e 's/^# Packages :.*/# Packages : unknow/' \
1323 -e "s/# Date :.*/# Date : $(date +%Y-%m-%d\ \%H:%M:%S)/" \
1324 -i packages.txt
1325 else
1326 echo "# SliTaz GNU/Linux - Packages list
1328 # Packages : unknow
1329 # Date : $(date +%Y-%m-%d\ \%H:%M:%S)
1331 " > packages.txt
1332 fi
1334 # Needed in some case as tazwok define RECEIPT at configuration time
1335 # in this particular case it can broke the script.
1336 unset RECEIPT
1338 # If $packages_repository is the main one, configure few functions
1339 # to act as they should, without having loop on them (speed-up)
1340 if [ "${pkg_repository##*/}" = packages ]; then
1341 erase_package_info_extracmd="erase_package_info_main"
1342 get_packages_info_extracmd="erase_packages_info_main"
1343 fi
1346 erase_package_info()
1348 cd $pkg_repository
1349 sed "/^$PACKAGE$/,/^$/d" -i packages.txt
1350 sed "/^$PACKAGE /d" -i packages.desc
1351 sed -e "s/=$PACKAGE /= /" -e "s/ $PACKAGE / /" -e "s/ $PACKAGE$//" \
1352 -e "/=$PACKAGE$/d" -e "s/=[0-9,a-z,A-Z]:$PACKAGE /= /" \
1353 -e "s/ [0-9,a-z,A-Z]:$PACKAGE / /" -e "s/ [0-9,a-z,A-Z]:$PACKAGE$/ /" \
1354 -e "/=[0-9,a-z,A-Z]:$PACKAGE$/d" \
1355 -i packages.equiv
1356 sed "/^$PACKAGE:/d" -i files.list
1357 sed "/^$(basename ${pkg%.tazpkg})$/d" -i packages.list
1358 sed "/ $(basename $pkg)$/d" -i packages.md5
1359 $erase_package_info_extracmd
1362 erase_package_info_main()
1364 for i in wanted.txt depends.txt; do
1365 [ -f $i ] || continue
1366 sed "/^$PACKAGE\t/d" -i $i
1367 done
1370 get_packages_info()
1372 # If there's no taz folder in the wok, extract infos from the
1373 # package.
1374 get_pkg_files $pkg
1375 source_receipt
1376 echo "Getting datas from $PACKAGE"
1378 cat >> $pkg_repository/packages.txt << _EOT_
1379 $PACKAGE
1380 $VERSION$EXTRAVERSION
1381 $SHORT_DESC
1382 _EOT_
1383 if [ "$PACKED_SIZE" ]; then
1384 cat >> $pkg_repository/packages.txt << _EOT_
1385 $PACKED_SIZE ($UNPACKED_SIZE installed)
1387 _EOT_
1388 else
1389 echo "" >> $pkg_repository/packages.txt
1390 fi
1392 # Packages.desc is used by Tazpkgbox <tree>.
1393 echo "$PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> $pkg_repository/packages.desc
1395 # Packages.equiv is used by tazpkg install to check depends
1396 for i in $PROVIDE; do
1397 DEST=""
1398 echo $i | fgrep -q : && DEST="${i#*:}:"
1399 if grep -qs ^${i%:*}= $pkg_repository/packages.equiv; then
1400 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" $pkg_repository/packages.equiv
1401 else
1402 echo "${i%:*}=$DEST$PACKAGE" >> $pkg_repository/packages.equiv
1403 fi
1404 done
1406 if [ -f files.list ]; then
1407 { echo "$PACKAGE"; cat files.list; } | awk '
1408 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }' >> $pkg_repository/files.list
1409 fi
1411 cd .. && rm -r "$pkg_files_dir"
1413 cd $pkg_repository
1414 echo $(basename ${pkg%.tazpkg}) >> packages.list
1415 md5sum $(basename $pkg) >> packages.md5
1416 $get_packages_info_extracmd
1419 get_packages_info_main()
1421 [ "$WANTED" ] && echo -e "$PACKAGE\t$WANTED" >> wanted.txt
1422 echo -e "$PACKAGE\t "$DEPENDS" \t "$BUILD_DEPENDS" " >> package.txt
1425 source_receipt()
1427 unset PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
1428 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
1429 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
1430 src _pkg DESTDIR CONFIG_SITE BRANCH TARBALL stuff wanted_stuff
1431 . ${RECEIPT:-$PWD/receipt}
1434 packages_db_end()
1436 cd $pkg_repository
1437 pkgs=$(wc -l packages.list | sed 's/ .*//')
1438 sed "s/# Packages : .*/# Packages : $pkgs/" -i packages.txt
1440 # If lists was updated it's generally needed to sort them well.
1441 if ! sort -c packages.list 2> /dev/null; then
1442 report step "Sorting packages lists"
1443 files_list="packages.list packages.desc packages.equiv"
1444 [ "${pkg_repository##*/}" = packages ] && \
1445 files_list="$files_list wanted.txt depends.txt"
1446 for file in $files_list; do
1447 [ -f $file ] || continue
1448 sort -o $file $file
1449 done
1450 md5sum packages.md5 | cut -f1 -d' ' > ID
1451 report end-step
1452 fi
1454 # Dont log this because lzma always output error.
1455 lzma e files.list files.list.lzma
1456 rm -f files.list
1457 [ -f packages.equiv ] || touch packages.equiv
1460 ########################################################################
1461 # This section contains functions to generate wok database.
1462 ########################
1464 gen_wok_db()
1466 report step "Generating wok database"
1467 report open-bloc
1468 report step "Removing old files"
1469 for file in $wan_db $dep_db $cookorder; do
1470 [ -f $file ] && rm $file
1471 done
1472 report step "Generating wok-wanted.txt"
1473 gen_wan_db
1474 report step "Generating wok-depends.txt"
1475 for PACKAGE in $(cut -f1 -d '|' $PACKAGES_REPOSITORY/packages.desc \
1476 $INCOMING_REPOSITORY/packages.desc | sort -u); do
1477 RECEIPT=$WOK/$PACKAGE/receipt
1478 if [ -s $RECEIPT ]; then
1479 source_receipt
1480 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
1481 fi
1482 done
1483 sort_db
1484 report close-bloc
1487 gen_wan_db()
1489 for RECEIPT in $(fgrep -l WANTED $WOK/*/receipt); do
1490 WANTED=
1491 source $RECEIPT
1492 [ "$WANTED" ] || continue
1493 echo -e $PACKAGE"\t"$WANTED >> $tmp/wan_db
1494 done
1495 if ! [ -f $wan_db ] || [ "$(diff -q $tmp/wan_db $wan_db)" ]; then
1496 mv -f $tmp/wan_db $wan_db
1497 plan_regen_cookorder=yes
1498 else
1499 rm $tmp/wan_db
1500 fi
1503 update_wan_db()
1505 local PACKAGE=$PACKAGE
1506 wanted_list=$(fgrep WANTED=\"$PACKAGE\" $WOK/*/receipt | cut -f1 -d ':')
1507 grep $'\t'$PACKAGE $wan_db | cut -f 1 | while read wan; do
1508 echo "$wanted_list" | fgrep -q /$wan/receipt && continue
1509 sed "/^$wan\t/d" -i $wan_db
1510 plan_regen_cookorder=yes
1511 done
1512 for RECEIPT in $wanted_list; do
1513 WANTED=
1514 source $RECEIPT
1515 [ "$WANTED" ] || continue
1516 wan_info=$(echo -e $PACKAGE"\t"$WANTED)
1517 [ "$wan_info" = "$(grep -m1 ^$PACKAGE$'\t' $wan_db 2>/dev/null)" ] && continue
1518 sed "/^$PACKAGE\t/d" -i $wan_db
1519 echo "$wan_info" >> $wan_db
1520 plan_regen_cookorder=yes
1521 plan_sort_wandb=yes
1522 done
1523 unset wanted_list
1526 update_dep_db()
1528 dep_info=$(echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ')
1529 [ "$dep_info" = "$(grep -m1 ^$PACKAGE$'\t' $dep_db 2>/dev/null)" ] && return
1530 sed "/^$PACKAGE\t/d" -i $dep_db
1531 echo "$dep_info" >> $dep_db
1532 plan_regen_cookorder=yes
1533 plan_sort_depdb=yes
1536 sort_db()
1538 report step "Generating cookorder.txt"
1539 sed 's/ \t / /' $dep_db | while read PACKAGE BUILD_DEPENDS; do
1540 grep -q ^$PACKAGE$'\t' $wan_db && continue
1542 # Replace each BUILD_DEPENDS with a WANTED package by it's
1543 # WANTED package.
1544 echo -e $PACKAGE"\t $(echo $BUILD_DEPENDS | use_wanted | \
1545 sort -u | sed "/^$PACKAGE$/d" | tr '\n' ' ') "
1546 done > $tmp/db
1547 while [ -s "$tmp/db" ]; do
1548 status=start
1549 for pkg in $(cut -f 1 $tmp/db); do
1550 if ! fgrep -q ' '$pkg' ' $tmp/db; then
1551 echo $pkg >> $tmp/cookorder
1552 sed -e "/^$pkg\t/d" -e "s/ $pkg / /g" -i $tmp/db
1553 status=proceed
1554 fi
1555 done
1556 if [ "$status" = start ]; then
1557 cp -f $tmp/db /tmp/remain-depends.txt
1558 echo "Can't go further because there's depency(ies) loop(s). The remaining packages will be commentend in the cookorder and will be unbuild in case of major update until the problem is solved." >&2
1559 for remaining in $(cut -f 1 $tmp/db); do
1560 echo "$remaining" >> $blocked
1561 done
1562 break
1563 fi
1564 done
1565 [ -s $tmp/cookorder ] || touch $tmp/cookorder
1567 # The toolchain packages are moved in first position.
1568 grep $(for pkg in `scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
1569 --look_for=all --with_args`; do echo " -e ^$pkg$"; done) \
1570 $tmp/cookorder | tac > $cookorder
1571 for pkg in $(cat $cookorder); do
1572 sed "/^$pkg$/d" -i $tmp/cookorder
1573 done
1575 tac $tmp/cookorder >> $cookorder
1576 unset plan_regen_cookorder
1577 report end-step
1580 ########################################################################
1581 # SCAN CORE
1582 ########################
1583 # Include various scan core-functions. It's not intended to be used
1584 # directly : prefer scan wrappers in next section.
1586 look_for_dep()
1588 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2
1591 look_for_bdep()
1593 look_for_all
1596 look_for_all()
1598 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2,3 | sed 's/ / /'
1601 look_for_rdep()
1603 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1
1606 look_for_rbdep()
1608 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1611 # Return WANTED if it exists.
1612 look_for_wanted()
1614 grep -m1 ^$PACKAGE$'\t' $wan_db | cut -f 2
1617 # Return packages which wants PACKAGE.
1618 look_for_rwanted()
1620 grep $'\t'$PACKAGE$ $wan_db | cut -f 1
1623 look_for_dev()
1625 WANTED=$(look_for_wanted)
1626 if [ "$WANTED" ]; then
1627 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1628 fi
1629 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1632 with_dev()
1634 for PACKAGE in $(cat); do
1635 echo $PACKAGE
1636 look_for_dev
1637 done
1640 with_wanted()
1642 for PACKAGE in $(cat); do
1643 echo $PACKAGE
1644 look_for_wanted
1645 done
1648 use_wanted()
1650 for input in $(cat); do
1651 { grep ^$input$'\t' $wan_db || echo $input
1653 done | sed 's/.*\t//'
1656 check_for_pkg_in_wok()
1658 [ -f $WOK/$PACKAGE/receipt ] && return
1659 echo "Can't find $PACKAGE in wok or mirror" >&2
1660 return 2
1663 # Define how theses functions should act when using --undigest.
1664 use_undigest_scan_core()
1666 look_for_dep()
1668 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1669 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2
1670 else
1671 grep -m1 ^$PACKAGE$'\t' $ref_dep_db | cut -f 2
1672 fi
1675 look_for_all()
1677 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1678 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2,3 | sed 's/ / /'
1679 else
1680 grep -m1 ^$PACKAGE$'\t' $ref_dep_db | cut -f 2,3 | sed 's/ / /'
1681 fi
1684 look_for_rdep()
1686 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1
1687 for rdep in $(fgrep ' '$PACKAGE' ' $ref_dep_db | cut -f 1); do
1688 [ -f "WOK$/$rdep/receipt" ] || echo "$rdep"
1689 done
1692 look_for_rbdep()
1694 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1695 for rdep in $(fgrep ' '$PACKAGE' ' $ref_dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1); do
1696 [ -f "WOK$/$rdep/receipt" ] || echo "$rdep"
1697 done
1700 look_for_wanted()
1702 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1703 grep -m1 ^$PACKAGE$'\t' $wan_db | cut -f 2
1704 else
1705 grep -m1 ^$PACKAGE$'\t' $ref_wan_db | cut -f 2
1706 fi
1709 look_for_rwanted()
1711 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1712 grep $'\t'$PACKAGE$ $wan_db | cut -f 1
1713 else
1714 grep $'\t'$PACKAGE$ $ref_wan_db | cut -f 1
1715 fi
1718 look_for_dev()
1720 WANTED=$(look_for_wanted)
1721 if [ "$WANTED" ]; then
1722 if [ -f "$WOK/$WANTED/receipt" ]; then
1723 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1724 else
1725 grep -q ^$WANTED-dev$'\t' $ref_dep_db && echo $WANTED-dev
1726 fi
1727 fi
1728 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1729 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1730 else
1731 grep -q ^$PACKAGE-dev$'\t' $ref_dep_db && echo $PACKAGE-dev
1732 fi
1735 check_for_pkg_in_wok()
1737 [ -f $WOK/$PACKAGE/receipt ] && return
1738 grep -q ^$PACKAGE'$\t' $ref_dep_db && return 1
1739 echo "Can't find $PACKAGE in wok or mirror" >&2
1740 return 2
1744 ########################################################################
1745 # SCAN
1746 ########################
1747 # Use wok-wanted.txt and wok-depeds.txt to scan depends.
1748 # Option in command line (must be first arg) :
1749 # --look_for=bdep/rbdep - Look for depends or reverse depends.
1750 # --with_dev - Add development packages (*-dev) in the result.
1751 # --with_wanted - Add package+reverse wanted in the result.
1752 # --with_args - Include packages in argument in the result.
1754 scan()
1756 # Get packages in argument.
1757 local PACKAGE=$PACKAGE WANTED=$WANTED pkg_list=
1758 for arg in $@; do
1759 [ "$arg" = "${arg#--}" ] || continue
1760 pkg_list="$pkg_list $arg"
1761 done
1763 # Get options.
1764 [ "$pkg_list" ] || return
1765 local cooklist= look_for= with_dev= with_wanted= with_args= log_command="$0 $@" \
1766 get_options_list="look_for with_dev with_wanted with_args cooklist use_wanted"
1767 get_options
1769 # Cooklist is a special case where we need to modify a little
1770 # scan behavior
1771 if [ "$cooklist" ]; then
1772 gen_wan_db
1773 look_for=all && with_args=yes && with_dev= && with_wanted=
1774 filter=use_wanted
1775 if [ "$COMMAND" = gen-cooklist ]; then
1776 for PACKAGE in $pkg_list; do
1777 grep -q ^$PACKAGE$'\t' $dep_db && continue
1778 [ -d "$WOK/$p" ] || continue
1779 check_for_missing
1780 done
1781 append_to_dep()
1783 if grep -q ^$PACKAGE$'\t' $dep_db; then
1784 echo $PACKAGE >> $tmp/dep
1785 else
1786 check_for_missing && echo $PACKAGE >> $tmp/dep
1787 fi
1789 else
1790 append_to_dep()
1792 check_for_commit && echo $PACKAGE >> $tmp/dep
1794 fi
1795 else
1796 append_to_dep()
1798 echo $PACKAGE >> $tmp/dep
1800 # If requested packages are not in dep_db, partial generation of this db is needed.
1801 for PACKAGE in $pkg_list; do
1802 grep -q ^$PACKAGE$'\t' $dep_db && continue
1803 [ -d "$WOK/$p" ] || continue
1804 plan_check_for_missing=yes
1805 check_for_missing
1806 done
1807 if [ "$plan_check_for_missing" ]; then
1808 append_to_dep()
1810 if grep -q ^$PACKAGE$'\t' $dep_db; then
1811 echo $PACKAGE >> $tmp/dep
1812 else
1813 check_for_missing && echo $PACKAGE >> $tmp/dep
1814 fi
1816 check_db_status=yes
1817 unset plan_check_for_missing
1818 fi
1819 fi
1821 [ "$with_dev" ] && filter=with_dev
1822 [ "$with_wanted" ] && filter=with_wanted
1823 if [ "$filter" ]; then
1824 pkg_list=$(echo $pkg_list | $filter | sort -u)
1825 scan_pkg()
1827 look_for_$look_for | $filter
1829 else
1830 scan_pkg()
1832 look_for_$look_for
1834 fi
1835 touch $tmp/dep
1836 for PACKAGE in $pkg_list; do
1837 [ "$with_args" ] && append_to_dep
1838 scan_pkg
1839 done | tr ' ' '\n' | sort -u > $tmp/list
1840 [ "$look_for" = bdep ] && look_for=dep
1841 while [ -s $tmp/list ]; do
1842 PACKAGE=$(sed 1!d $tmp/list)
1843 sed 1d -i $tmp/list
1844 append_to_dep
1845 for pkg in $(scan_pkg); do
1846 grep -q ^$pkg$ $tmp/list $tmp/dep || echo $pkg >> $tmp/list
1847 done
1848 done
1849 if [ "$cooklist" ]; then
1850 mv $tmp/dep $tmp/cooklist
1851 else
1852 cat $tmp/dep | sort -u
1853 fi
1854 rm -f $tmp/dep $tmp/list
1855 if [ "$check_db_status" ]; then
1856 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
1857 [ "$plan_sort_wandb" ] && sort -o $wan_db $wan_db && unset plan_sort_wandb
1858 if [ "$plan_regen_cookorder" ] && \
1859 [ "$(sed 1!d $cookorder)" != "#PlanSort" ]; then
1860 grep -q "^#" $cookorder || sed 1i"#PlanSort" -i $cookorder
1861 fi
1862 fi
1865 ########################################################################
1866 # This section contains functions to check package repository and
1867 # find which packages to cook.
1868 ########################
1870 check_for_missing()
1872 local PACKAGE=$PACKAGE
1873 if ! check_for_pkg_in_wok; then
1874 [ "$?" = 2 ] && return 1
1875 return
1876 fi
1877 RECEIPT=$WOK/$PACKAGE/receipt
1878 source_receipt
1879 PACKAGE=${WANTED:-$PACKAGE}
1880 update_wan_db
1881 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1882 RECEIPT=$WOK/$PACKAGE/receipt
1883 source_receipt
1884 update_dep_db
1885 done
1888 check_for_commit()
1890 if ! check_for_pkg_in_wok; then
1891 [ "$?" = 2 ] && return 1
1892 return
1893 fi
1894 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1895 RECEIPT=$WOK/$PACKAGE/receipt
1896 source_receipt
1898 # We use md5 of cooking stuff in the packaged receipt to check
1899 # commit. We look consecutively in 3 different locations :
1900 # - in the wok/PACKAGE/taz/* folder
1901 # - in the receipt in the package in incoming repository
1902 # - in the receipt in the package in packages repository
1903 # If md5sum match, there's no commit.
1904 check_for_commit_using_md5sum()
1906 if [ ! -f $WOK/$PACKAGE/md5 ]; then
1907 sed -n '/# md5sum of cooking stuff :/,$p' receipt | \
1908 sed -e 1d -e 's/^# //' > $WOK/$PACKAGE/md5
1909 cd $WOK/$PACKAGE
1910 fi
1912 if [ -s md5 ]; then
1913 if md5sum -cs md5; then
1915 # If md5sum check if ok, check for new/missing files in
1916 # cooking stuff.
1917 for file in $([ -f receipt ] && echo receipt; \
1918 [ -f description.txt ] && echo description.txt; \
1919 [ -d stuff ] && find stuff); do
1920 if ! fgrep -q " $file" md5; then
1921 set_commited
1922 fi
1923 done
1924 else
1925 set_commited
1926 fi
1927 else
1928 set_commited
1929 fi
1931 set_commited()
1933 grep -q ^$PACKAGE$ $commit || echo $PACKAGE >> $commit
1934 gen_cookmd5
1935 update_dep_db
1937 taz_dir=$(echo $WOK/$PACKAGE/taz/$PACKAGE-* | fgrep -v '*')
1938 if [ -f $WOK/$PACKAGE/md5 ]; then
1939 cd $WOK/$PACKAGE
1940 check_for_commit_using_md5sum
1941 elif [ "$taz_dir" ]; then
1942 cd $taz_dir
1943 check_for_commit_using_md5sum
1944 else
1945 pkg=$(echo $INCOMING_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
1946 [ "$pkg" ] || pkg=$(echo $PACKAGES_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
1947 if [ "$pkg" ]; then
1948 get_pkg_files $pkg
1949 check_for_commit_using_md5sum
1950 rm -r $pkg_files_dir
1951 else
1952 set_commited
1953 fi
1954 fi
1955 [ "$forced" ] || echo $PACKAGE >> $tmp/checked
1956 done
1957 return
1960 gen_cook_list()
1962 report step "Scanning wok"
1963 if [ "$pkg" ]; then
1964 scan $pkg --cooklist
1965 elif [ "$LIST" ]; then
1966 scan `cat $LIST` --cooklist
1967 else
1968 scan `cat $cooklist` --cooklist
1969 fi
1970 report end-step
1972 [ -s $tmp/checked ] || [ -s $tmp/cooklist ] || return
1974 # Core toolchain should not be cooked unless cook-toolchain is used.
1975 if ! [ -f /etc/config.site.tmptoolchain ] ; then
1976 for PACKAGE in $(scan gcc --look_for=all --with_args --with_wanted); do
1977 grep -q ^$PACKAGE$ $blocked || echo $PACKAGE >> $blocked
1978 done
1979 fi
1981 if [ -s $commit ] && [ "$COMMAND" != gen-cooklist ]; then
1982 for PACKAGE in $(cat $commit); do
1983 WANTED="$(look_for_wanted)"
1984 if [ "$WANTED" ]; then
1985 grep -q ^$WANTED$ $broken $cooklist $blocked $commit && continue
1986 fi
1987 grep -q ^$PACKAGE$ $blocked $cooklist && continue
1988 echo $PACKAGE >> $cooklist
1989 done
1990 fi
1991 sort_cooklist
1994 sort_cooklist()
1996 if [ "$(sed 1!d $cookorder)" = "#PlanSort" ]; then
1997 sed 1d -i $cookorder
1998 plan_regen_cookorder=yes
1999 fi
2000 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
2001 [ "$plan_regen_cookorder" ] && sort_db
2002 report step "Generating cooklist"
2003 if [ -f "$tmp/checked" ]; then
2004 rm -f $tmp/cooklist
2005 cat $tmp/checked | while read PACKAGE; do
2006 grep -q ^$PACKAGE$ $cooklist && echo $PACKAGE >> $tmp/cooklist
2007 done
2008 elif ! [ "$COMMAND" = gen-cooklist ]; then
2009 cat $blocked | while read PACKAGE; do
2010 sed "/^$PACKAGE/d" -i $tmp/cooklist
2011 done
2012 fi
2013 report end-step
2014 [ -s $tmp/cooklist ] || return
2016 report step "Sorting cooklist"
2017 for PACKAGE in $(cat $tmp/cooklist); do
2018 WANTED="$(look_for_wanted)"
2019 [ "$WANTED" ] || continue
2020 if grep -q ^$WANTED$ $broken $tmp/cooklist; then
2021 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2022 elif [ ! -d $WOK/$WANTED/install ]; then
2023 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2024 echo $WANTED >> $tmp/cooklist
2025 fi
2026 done
2028 # Use cookorder.txt to sort cooklist.
2029 if [ -s $tmp/cooklist ]; then
2030 cat $cookorder | while read PACKAGE; do
2031 if grep -q ^$PACKAGE$ $tmp/cooklist; then
2032 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2033 echo $PACKAGE >> $tmp/cooklist.tmp
2034 fi
2035 done
2037 # Remaining packages in cooklist are thoses without compile_rules.
2038 # They can be cooked first in any order.
2039 if [ -f $tmp/cooklist.tmp ]; then
2040 cat $tmp/cooklist.tmp >> $tmp/cooklist
2041 rm $tmp/cooklist.tmp
2042 fi
2044 cat $tmp/cooklist
2045 [ "$LIST" ] || cat $tmp/cooklist > $cooklist
2046 fi
2048 report end-step
2051 look_for_missing_pkg()
2053 for pkg in $(cat $PACKAGES_REPOSITORY/$1); do
2054 grep -q ^$pkg$ $INCOMING_REPOSITORY/packages.txt \
2055 $PACKAGES_REPOSITORY/packages.txt || \
2056 continue
2057 echo $pkg
2058 done
2061 check_for_incoming()
2063 report step "Check that all packages were cooked fine"
2064 [ -s $INCOMING_REPOSITORY/packages.desc ] || {
2065 echo "No packages in $INCOMING_REPOSITORY."
2066 report end-step; return; }
2067 if [ -s $broken ]; then
2068 missingpkg=$(look_for_missing_pkg broken)
2069 if [ "$missingpkg" ]; then
2070 echo "Don't move incoming packages to main repository because theses ones are broken:" >&2
2071 echo "$missingpkg"
2072 report end-step
2073 return 1
2074 fi
2075 fi
2076 if [ -s $cooklist ]; then
2077 missingpkg=$(look_for_missing_pkg cooklist)
2078 if [ "$missingpkg" ]; then
2079 echo "Don't move incoming packages to main repository because theses ones needs to be cooked:" >&2
2080 echo "$missingpkg"
2081 report end-step
2082 return 1
2083 fi
2084 fi
2085 incoming_pkgs="$(cut -f 1 -d '|' $INCOMING_REPOSITORY/packages.desc)"
2086 if ! [ "$forced" ]; then
2087 cooklist=$PACKAGES_REPOSITORY/cooklist
2088 pkg="$incoming_pkgs"
2089 gen_cook_list
2090 if [ -s $cooklist ]; then
2091 missingpkg=$(look_for_missing_pkg cooklist)
2092 if [ "$missingpkg" ]; then
2093 echo "Don't move incoming packages to main repository because theses ones needs to be cooked:" >&2
2094 echo "$missingpkg"
2095 report end-step
2096 return 1
2097 fi
2098 fi
2099 fi
2101 report step "Moving incoming packages to main repository"
2102 mkdir -p $PACKAGES_REPOSITORY/wok
2103 unset EXTRAVERSION
2104 for PACKAGE in $incoming_pkgs; do
2105 prev_VERSION=$(get_pkg_version $PACKAGES_REPOSITORY)
2106 VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
2107 remove_previous_package $PACKAGES_REPOSITORY
2108 echo "Moving $PACKAGE..."
2109 mv -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION.tazpkg $PACKAGES_REPOSITORY
2110 touch $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
2111 previous_tarball=$(grep -m1 ^$PACKAGE:main $SOURCES_REPOSITORY/sources.list | cut -f2)
2112 sed -e "/^$PACKAGE:main/d" \
2113 -e "s/^$PACKAGE:incoming/$PACKAGE:main/" \
2114 -i $SOURCES_REPOSITORY/sources.list
2115 if [ "$previous_tarball" ]; then
2116 grep -q $'\t'$previous_tarball$ $SOURCES_REPOSITORY/sources.list || \
2117 rm -f $SOURCES_REPOSITORY/$previous_tarball
2118 fi
2119 rm -rf $PACKAGES_REPOSITORY/wok/$PACKAGE
2120 mkdir -p $PACKAGES_REPOSITORY/wok/$PACKAGE
2121 for i in $WOK/$PACKAGE/receipt $WOK/$PACKAGE/description.txt \
2122 $WOK/$PACKAGE/stuff; do
2123 cp -a $i $PACKAGES_REPOSITORY/wok/$PACKAGE
2124 done
2125 done
2127 if [ "$GEN_SAFE_WOK_TARBALL" ]; then
2128 rm -f $PACKAGES_REPOSITORY/wok.tar.lzma
2129 cd $PACKAGES_REPOSITORY/wok
2130 report step "Generating safe-wok tarball"
2131 tar -c * | lzma e $PACKAGES_REPOSITORY/wok.tar.lzma
2132 report end-step
2133 fi
2135 for file in packages.list packages.equiv packages.md5 packages.desc \
2136 packages.txt; do
2137 echo -n "" > $INCOMING_REPOSITORY/$file
2138 done
2139 rm -r $INCOMING_REPOSITORY/files.list.lzma
2140 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2142 report step "Updating flavors"
2143 if [ -x /usr/bin/tazlito ] || [ -x /usr/bin/clean-chroot ]; then
2144 if ! [ -x /usr/bin/tazlito ]; then
2145 tazpkg get-install tazlito
2146 fi
2148 # Handle cases where tazwok is used into main system;
2149 # Handle cases where SLITAZ_DIR is not /home/slitaz.
2150 [ -L /home/slitaz/flavors ] && rm /home/slitaz/flavors
2151 mkdir -p /home/slitaz
2152 ln -s $LOCAL_REPOSITORY/flavors /home/slitaz/flavors
2154 cd $LOCAL_REPOSITORY/packages
2155 for i in $LOCAL_REPOSITORY/flavors/*; do
2156 [ -d "$i" ] || continue
2157 tazlito pack-flavor ${i##*/}
2158 done
2160 noheader=""
2161 for i in *.flavor; do
2162 tazlito show-flavor $i --brief $noheader
2163 noheader="--noheader"
2164 done > flavors.list
2165 [ -x /usr/bin/clean-chroot ] && clean-chroot
2166 else
2167 echo "Can't create up-to-date flavors because tazlito package is missing." >&2
2168 fi
2169 report end-step
2172 ########################################################################
2173 # TAZWOK MAIN FUNCTIONS
2174 ########################
2176 clean()
2178 cd $WOK/$PACKAGE
2179 ls -A $WOK/$PACKAGE | grep -q -v -e ^receipt$ -e ^description.txt$ \
2180 -e ^stuff$ || return
2182 [ "$COMMAND" = clean-wok ] || report step "Cleaning $PACKAGE"
2183 # Check for clean_wok function.
2184 if grep -q ^clean_wok $RECEIPT; then
2185 clean_wok
2186 fi
2187 # Clean should only have a receipt, stuff and optionals desc/md5.
2188 for f in `ls .`
2189 do
2190 case $f in
2191 receipt|stuff|description.txt|md5)
2192 continue ;;
2193 *)
2194 rm -rf $f ;;
2195 esac
2196 done
2197 [ "$COMMAND" != clean-wok ] && report end-step
2200 # Configure and make a package with the receipt.
2201 compile_package()
2203 check_for_package_on_cmdline
2205 # Include the receipt to get all needed variables and functions
2206 # and cd into the work directory to start the work.
2207 check_for_receipt
2208 source_receipt
2210 # Log the package name and date.
2211 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
2212 echo "package $PACKAGE (compile)" >> $LOG
2214 # Set wanted $src variable to help compiling.
2215 [ ! "$src" ] && set_src_path
2216 check_for_build_depends || return 1
2217 check_for_wanted
2218 unset target
2219 check_for_tarball && check_for_compile_rules
2222 # Cook command also include all features to manage lists which keep
2223 # track of wok/packages state.
2224 cook()
2226 cook_code=
2227 set_common_path
2228 check_for_receipt
2229 source_receipt
2231 # Define log path and start report.
2232 for i in $(look_for_rwanted) $PACKAGE; do
2233 rm -f $LOCAL_REPOSITORY/log/$i.html
2234 done
2235 report sublog $LOCAL_REPOSITORY/log/$PACKAGE.html
2236 echo "$PACKAGE" > $LOCAL_REPOSITORY/log/package
2237 report step "Cooking $PACKAGE"
2238 report open-bloc
2240 clean $PACKAGE
2241 [ -s $tmp/cooklist ] && sed "/^$PACKAGE$/d" -i $tmp/cooklist
2243 if compile_package; then
2244 remove_src
2245 refresh_packages_from_compile
2246 gen_package
2248 # Update packages-incoming repository.
2249 store_pkgname=$PACKAGE
2250 pkg_repository=$INCOMING_REPOSITORY
2251 update_packages_db
2253 PACKAGE=$store_pkgname
2254 unset store_pkgname
2256 # Upgrade to cooked packages if it was previously installed.
2257 report step "Look for package(s) to upgrade"
2258 for pkg in $(look_for_rwanted) $PACKAGE; do
2259 if [ -f $INSTALLED/$pkg/receipt ]; then
2260 tazpkg get-install $pkg --forced
2261 fi
2262 done
2263 report end-step
2264 else
2265 set_pkg_broken
2266 cook_code=1
2267 fi
2269 # Remove build_depends in cook mode (if in cooklist, it's done when
2270 # checking build_depends of next package and we remove only unneeded
2271 # packages to keep chroot minimal and gain some time).
2272 if [ "$COMMAND" = cook ]; then
2273 remove_build_depends $MISSING_PACKAGE
2274 [ -x /usr/bin/clean-chroot ] && clean-chroot
2275 fi
2277 # Regen the cooklist if it was planned and command is not cook.
2278 [ "$regen_cooklist" ] && unset regen_cooklist &&
2279 [ "$COMMAND" != cook ] && sort_cooklist
2281 # Some hacks to set the bloc & function status as failed if cook was
2282 # failed.
2283 report_return_code=$cook_code
2284 report close-bloc
2285 report end-sublog
2286 rm -f $LOCAL_REPOSITORY/log/package
2287 return $cook_code
2290 cook_list()
2292 if [ -s $tmp/cooklist ]; then
2293 if [ -f /usr/bin/tazchroot ]; then
2294 # Note : options -main variables- are automatically keeped by
2295 # the sub-applications tazchroot/tazwok; as well as report data.
2296 cd $LOCAL_REPOSITORY
2297 [ ! -f tazchroot.conf ] && configure_tazchroot
2298 tazchroot tazwok cook-list --SLITAZ_DIR=$SLITAZ_DIR --SLITAZ_VERSION=$SLITAZ_VERSION ${undigest:+ --undigest=$undigest}
2299 return
2300 fi
2301 while [ -s $tmp/cooklist ]; do
2302 PACKAGE=$(sed 1!d $tmp/cooklist)
2303 cook
2304 done
2305 remove_build_depends $MISSING_PACKAGE $remove_later
2306 [ -x /usr/bin/clean-chroot ] && clean-chroot
2307 else
2308 echo "Nothing to cook."
2309 return
2310 fi
2313 configure_tazchroot()
2315 cat > $LOCAL_REPOSITORY/tazchroot.conf << EOF
2316 # Tazchroot configuration file - created by tazwok.
2318 # Local repository definition.
2319 SLITAZ_DIR=$SLITAZ_DIR
2320 SLITAZ_VERSION=$SLITAZ_VERSION
2321 LOCAL_REPOSITORY=$SLITAZ_DIR/${undigest:-$SLITAZ_VERSION}
2322 ${USE_ONLINE_PKG:+USE_ONLINE_PKG=$USE_ONLINE_PKG}
2323 ${undigest:+undigest=$undigest}
2324 ${ref_USE_ONLINE_PKG:+ref_USE_ONLINE_PKG=$ref_USE_ONLINE_PKG}
2326 # Chroot path.
2327 # You can use a chroot into /tmp if it's mounted in RAM
2328 # to speed-up the process, be sure you have a free GB.
2329 # (minimal chroot is like 150~200MB, can be a lot more during cook)
2330 # chroot_dir=/tmp/chroot-${undigest:-$SLITAZ_VERSION}
2331 chroot_dir=\$LOCAL_REPOSITORY/chroot
2333 # Default scripts path (theses scripts are added in the
2334 # $chroot_dir/usr/bin and can be called with tazchroot script)
2335 script_dir=/usr/lib/slitaz/chroot-scripts/tazwok
2337 # List of directories to mount.
2338 list_dir="$LOCAL_REPOSITORY
2339 $SLITAZ_LOG$( [ "$undigest" ] && echo -e "\n$SLITAZ_DIR/$SLITAZ_VERSION/packages" )"
2341 create_chroot()
2343 mkdir -p \$chroot_dir
2344 for pkg in \$(tazwok build-depends toolchain --SLITAZ_DIR=\$SLITAZ_DIR --SLITAZ_VERSION=\$SLITAZ_VERSION${undigest:+ --undigest=\$undigest}); do
2345 tazpkg get-install \$pkg --root="\$chroot_dir"
2346 done
2348 # Store list of installed packages needed by cleanchroot.
2349 ls -1 \$chroot_dir/\$INSTALLED > \$chroot_dir/\$LOCALSTATE/chroot-pkgs
2351 sed -e "s~^SLITAZ_DIR=.*~SLITAZ_DIR=\$SLITAZ_DIR~" \\
2352 -e "s/^SLITAZ_VERSION=.*/SLITAZ_VERSION=\$SLITAZ_VERSION/" \\
2353 -i \$chroot_dir/etc/slitaz/slitaz.conf
2354 echo "\$SLITAZ_VERSION" > /etc/slitaz-release
2355 $( [ "$undigest" ] && echo ' echo "undigest='"$undigest"'" >> $chroot_dir/etc/slitaz/tazwok.conf')
2356 sed 's/LC_ALL/LC_ALL=POSIX/' -i \$chroot_dir/etc/profile
2358 # The build bot may run in a sandbox: link sandbox lockfile
2359 ln -s \$LOCAL_REPOSITORY/sandbox/proc/1 \$chroot_dir/proc/1
2362 mount_chroot()
2364 cp -a /etc/resolv.conf \$chroot_dir/etc/resolv.conf
2365 $( if [ "$USE_ONLINE_PKG" ]; then
2366 echo ' echo "$USE_ONLINE_PKG" > $chroot_dir$LOCALSTATE/mirror'
2367 else
2368 echo ' echo $LOCAL_REPOSITORY/packages" > $chroot_dir$LOCALSTATE/mirror'
2369 fi
2371 mkdir -p \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming
2372 echo "\$LOCAL_REPOSITORY/packages-incoming" > \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming/mirror
2373 $( [ "$undigest" ] || continue
2374 echo ' mkdir -p $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION'
2375 if [ "$ref_USE_ONLINE_PKG" ]; then
2376 echo ' echo "$ref_USE_ONLINE_PKG" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror'
2377 else
2378 echo ' echo "$ref_LOCAL_REPOSITORY/packages" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror'
2379 fi
2381 echo -e "\${LOCAL_REPOSITORY##*/}-incoming\nmain" > \$chroot_dir\$LOCALSTATE/priority
2382 mount -t proc proc \$chroot_dir/proc
2383 mount -t sysfs sysfs \$chroot_dir/sys
2384 mount -t devpts devpts \$chroot_dir/dev/pts
2385 mount -t tmpfs shm \$chroot_dir/dev/shm
2386 for dir in \$list_dir; do
2387 mkdir -p \$dir \$chroot_dir\$dir
2388 mount \$dir \$chroot_dir\$dir
2389 done
2392 umount_chroot()
2394 for dir in \$list_dir; do
2395 umount \$chroot_dir\$dir
2396 done
2397 umount \$chroot_dir/dev/shm
2398 umount \$chroot_dir/dev/pts
2399 umount \$chroot_dir/sys
2400 umount \$chroot_dir/proc
2402 EOF
2405 ########################################################################
2406 ######################### END OF NEW FUNCTIONS #########################
2407 ########################################################################
2409 # List packages providing a virtual package
2410 whoprovide()
2412 local i;
2413 for i in $(fgrep -l PROVIDE $WOK/*/receipt); do
2414 . $i
2415 case " $PROVIDE " in
2416 *\ $1\ *|*\ $1:*) echo $(basename $(dirname $i));;
2417 esac
2418 done
2421 ########################################################################
2422 # TAZWOK COMMANDS
2423 ########################
2425 case "$COMMAND" in
2426 stats)
2427 # Tazwok general statistics from the wok config file.
2429 get_tazwok_config
2430 echo -e "\n\033[1mTazwok configuration statistics\033[0m
2431 ================================================================================
2432 Wok directory : $WOK
2433 Packages repository : $PACKAGES_REPOSITORY
2434 Incoming repository : $INCOMING_REPOSITORY
2435 Sources repository : $SOURCES_REPOSITORY
2436 Log directory : $LOCAL_REPOSITORY/log
2437 Packages in the wok : `ls -1 $WOK | wc -l`
2438 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2439 Incoming packages : `ls -1 $INCOMING_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2440 ================================================================================\n"
2441 ;;
2442 edit)
2443 get_tazwok_config
2444 check_for_package_on_cmdline
2445 check_for_receipt
2446 $EDITOR $WOK/$PACKAGE/receipt
2447 ;;
2448 build-depends)
2449 # List dependencies to rebuild wok, or only a package
2450 get_tazwok_config
2451 report(){ : ; }
2452 if [ ! "$PACKAGE" ] || [ "$PACKAGE" = toolchain ]; then
2453 scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
2454 --look_for=dep --with_dev --with_args
2455 else
2456 check_for_package_on_cmdline
2457 scan $PACKAGE --look_for=bdep --with_dev
2458 fi
2459 ;;
2460 gen-cooklist)
2461 check_root
2462 get_options_list="pkg"
2463 get_tazwok_config
2464 report(){ : ; }
2465 if ! [ "$pkg" ]; then
2466 if [ ! "$LIST" ] || [ "$LIST" = toolchain ]; then
2467 pkg="$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA"
2468 else
2469 check_for_list
2470 fi
2471 fi
2472 gen_cook_list
2473 ;;
2474 check-depends)
2475 # Check package depends /!\
2476 get_tazwok_config
2477 echo ""
2478 echo -e "\033[1mCheck every receipt for DEPENDS - doesn't scan ELF files\033[0m
2479 ================================================================================"
2480 TMPDIR=/tmp/tazwok$$
2481 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
2483 # Build ALL_DEPENDS variable
2484 scan_dep()
2486 local i
2487 ALL_DEPENDS="$ALL_DEPENDS$PACKAGE "
2488 for i in $DEPENDS $SUGGESTED ; do
2489 case " $ALL_DEPENDS " in
2490 *\ $i\ *) continue;;
2491 esac
2492 [ -d $WOK/$i ] || {
2493 ALL_DEPENDS="$ALL_DEPENDS$i "
2494 continue
2496 DEPENDS=""
2497 SUGGESTED=""
2498 . $WOK/$i/receipt
2499 scan_dep
2500 done
2503 # Check for ELF file
2504 is_elf()
2506 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
2509 # Print shared library dependencies
2510 ldd()
2512 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
2515 mkdir $TMPDIR
2516 cd $TMPDIR
2517 for i in $LOCALSTATE/files.list.lzma \
2518 $LOCALSTATE/undigest/*/files.list.lzma ; do
2519 [ -f $i ] && lzma d $i -so >> files.list
2520 done
2521 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
2522 tazpkg extract $pkg > /dev/null 2>&1
2523 . */receipt
2524 ALL_DEPENDS="$DEFAULT_DEPENDS "
2525 scan_dep
2526 find */fs -type f | while read file ; do
2527 is_elf $file || continue
2528 case "$file" in
2529 *.o|*.ko|*.ko.gz) continue;;
2530 esac
2531 ldd $file | while read lib rem; do
2532 case "$lib" in
2533 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
2534 continue;;
2535 esac
2536 for dep in $(fgrep $lib files.list | cut -d: -f1); do
2537 case " $ALL_DEPENDS " in
2538 *\ $dep\ *) continue 2;;
2539 esac
2540 for vdep in $(fgrep $dep $LOCALSTATE/packages.equiv | cut -d= -f1); do
2541 case " $ALL_DEPENDS " in
2542 *\ $vdep\ *) continue 3;;
2543 esac
2544 done
2545 done
2546 [ -n "$dep" ] || dep="UNKNOWN"
2547 echo "$(basename $pkg): ${file#*fs} depends on package $dep for the shared library $lib"
2548 done
2549 done
2550 rm -rf */
2551 done
2552 cd /tmp
2553 rm -rf $TMPDIR
2554 ;;
2555 check)
2556 # Check wok consistency
2557 get_tazwok_config
2558 echo ""
2559 echo -e "\033[1mWok and packages checking\033[0m
2560 ================================================================================"
2561 cd $WOK
2562 for pkg in $(ls)
2563 do
2564 [ -f $pkg/receipt ] || continue
2565 RECEIPT= $pkg/receipt
2566 source_receipt
2567 [ "$PACKAGE" = "$pkg" ] || echo "Package $PACKAGE should be $pkg" >&2
2568 [ -n "$VERSION" ] || echo "Package $PACKAGE has no VERSION" >&2
2569 [ -n "$PACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded PACKED_SIZE" >&2
2570 [ -n "$UNPACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded UNPACKED_SIZE" >&2
2571 [ -n "$EXTRAVERSION" ] && echo "Package $PACKAGE has hardcoded EXTRAVERSION" >&2
2572 if [ -n "$WANTED" ]; then
2573 if [ ! -f $WANTED/receipt ]; then
2574 echo "Package $PACKAGE wants unknown $WANTED package" >&2
2575 else
2576 BASEVERSION=$(. $WANTED/receipt ; echo $VERSION)
2577 if [ "$VERSION" = "$WANTED" ]; then
2578 # BASEVERSION is computed in receipt
2579 fgrep -q '_pkg=' $pkg/receipt &&
2580 BASEVERSION=$VERSION
2581 fi
2582 if [ "$VERSION" != "$BASEVERSION" ]; then
2583 echo "Package $PACKAGE ($VERSION) wants $WANTED ($BASEVERSION)" >&2
2584 fi
2585 fi
2586 fi
2588 if [ -n "$CATEGORY" ]; then
2589 case " $(echo $CATEGORIES) " in
2590 *\ $CATEGORY\ *);;
2591 *) echo "Package $PACKAGE has an invalid CATEGORY" >&2;;
2592 esac
2593 else
2594 echo"Package $PACKAGE has no CATEGORY" >&2
2595 fi
2596 [ -n "$SHORT_DESC" ] || echo "Package $PACKAGE has no SHORT_DESC" >&2
2597 [ -n "$MAINTAINER" ] || echo "Package $PACKAGE has no MAINTAINER" >&2
2598 case "$WGET_URL" in
2599 ftp*|http*) busybox wget -s $WGET_URL 2> /dev/null ||
2600 echo "Package $PACKAGE has a wrong WGET_URL" >&2;;
2601 '') ;;
2602 *) echo "Package $PACKAGE has an invalid WGET_URL" >&2;;
2603 esac
2604 case "$WEB_SITE" in
2605 ftp*|http*);;
2606 '') echo "Package $PACKAGE has no WEB_SITE" >&2;;
2607 *) echo "Package $PACKAGE has an invalid WEB_SITE" >&2;;
2608 esac
2609 case "$MAINTAINER" in
2610 *\<*|*\>*) echo "Package $PACKAGE has an invalid MAINTAINER: $MAINTAINER" >&2;;
2611 esac
2612 case "$MAINTAINER" in
2613 *@*);;
2614 *) echo "Package $PACKAGE MAINTAINER is not an email address" >&2;;
2615 esac
2616 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2617 for i in $DEPENDS; do
2618 [ -d $i ] && continue
2619 [ -n "$(whoprovide $i)" ] && continue
2620 echo -e "$MSG $i"
2621 MSG=""
2622 done
2623 MSG="Missing build dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2624 for i in $BUILD_DEPENDS; do
2625 [ -d $i ] && continue
2626 [ -n "$(whoprovide $i)" ] && continue
2627 echo -e "$MSG $i"
2628 MSG=""
2629 done
2630 MSG="Dependencies loop between $PACKAGE and :\n"
2631 ALL_DEPS=""
2632 check_for_deps_loop $PACKAGE $DEPENDS
2633 [ -d $WOK/$pkg/taz ] && for i in $BUILD_DEPENDS; do
2634 [ $WOK/$pkg/taz -nt $INSTALLED/$i/files.list ] && continue
2635 echo "$pkg should be rebuilt after $i installation"
2636 done
2637 done
2638 ;;
2639 list)
2640 # List packages in wok directory. User can specify a category.
2642 get_tazwok_config
2643 if [ "$2" = "category" ]; then
2644 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
2645 exit 0
2646 fi
2647 # Check for an asked category.
2648 if [ -n "$2" ]; then
2649 ASKED_CATEGORY=$2
2650 echo ""
2651 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
2652 echo "================================================================================"
2653 for pkg in $WOK/*
2654 do
2655 [ ! -f $pkg/receipt ] && continue
2656 . $pkg/receipt
2657 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
2658 echo -n "$PACKAGE"
2659 echo -e "\033[28G $VERSION"
2660 packages=$(($packages+1))
2661 fi
2662 done
2663 echo "================================================================================"
2664 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
2665 else
2666 # By default list all packages and version.
2667 echo ""
2668 echo -e "\033[1mList of packages in the wok\033[0m"
2669 echo "================================================================================"
2670 for pkg in $WOK/*
2671 do
2672 [ ! -f $pkg/receipt ] && continue
2673 . $pkg/receipt
2674 echo -n "$PACKAGE"
2675 echo -en "\033[28G $VERSION"
2676 echo -e "\033[42G $CATEGORY"
2677 packages=$(($packages+1))
2678 done
2679 echo "================================================================================"
2680 echo -e "$packages packages available in the wok.\n"
2681 fi
2682 ;;
2683 info)
2684 # Information about a package.
2686 get_tazwok_config
2687 check_for_package_on_cmdline
2688 check_for_receipt
2689 . $WOK/$PACKAGE/receipt
2690 echo ""
2691 echo -e "\033[1mTazwok package information\033[0m
2692 ================================================================================
2693 Package : $PACKAGE
2694 Version : $VERSION
2695 Category : $CATEGORY
2696 Short desc : $SHORT_DESC
2697 Maintainer : $MAINTAINER"
2698 if [ ! "$WEB_SITE" = "" ]; then
2699 echo "Web site : $WEB_SITE"
2700 fi
2701 if [ ! "$DEPENDS" = "" ]; then
2702 echo "Depends : $DEPENDS"
2703 fi
2704 if [ ! "$WANTED" = "" ]; then
2705 echo "Wanted src : $WANTED"
2706 fi
2707 echo "================================================================================"
2708 echo ""
2709 ;;
2710 check-log)
2711 # We just cat the file log to view process info.
2713 get_tazwok_config
2714 if [ ! -f "$LOG" ]; then
2715 echo -e "\nNo process log found. The package is probably not cooked.\n" >&2
2716 exit 1
2717 else
2718 echo ""
2719 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
2720 echo "================================================================================"
2721 cat $LOG
2722 echo "================================================================================"
2723 echo ""
2724 if [ -s "$WOK/$PACKAGE/warning.txt" ]; then
2725 echo -e "\033[1mCook warning(s) for :\033[0m $PACKAGE"
2726 echo "================================================================================"
2727 cat "$WOK/$PACKAGE/warning.txt"
2728 echo "================================================================================"
2729 echo ""
2730 fi
2731 fi
2732 ;;
2733 search)
2734 # Search for a package by pattern or name.
2736 get_tazwok_config
2737 if [ -z "$2" ]; then
2738 echo -e "\nPlease specify a pattern or a package name to search." >&2
2739 echo -e "Example : 'tazwok search gcc'.\n" >&2
2740 exit 1
2741 fi
2742 echo ""
2743 echo -e "\033[1mSearch result for :\033[0m $2"
2744 echo "================================================================================"
2745 list=`ls -1 $WOK | fgrep $2`
2746 for pkg in $list
2747 do
2748 . $WOK/$pkg/receipt
2749 echo -n "$PACKAGE "
2750 echo -en "\033[24G $VERSION"
2751 echo -e "\033[42G $CATEGORY"
2752 packages=$(($PACKAGEs+1))
2753 done
2754 echo "================================================================================"
2755 echo "$packages packages found for : $2"
2756 echo ""
2757 ;;
2758 compile)
2759 # Configure and make a package with the receipt.
2761 get_tazwok_config
2762 source_lib report
2763 report start
2764 compile_package
2765 ;;
2766 genpkg)
2767 # Generate a package.
2769 get_tazwok_config
2770 source_lib report
2771 report start
2772 gen_package
2773 ;;
2774 cook)
2775 # Compile and generate a package. Just execute tazwok with
2776 # the good commands.
2778 check_root
2779 get_tazwok_config
2780 source_lib report
2781 report start
2782 update_wan_db
2783 check_for_commit
2784 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
2785 [ "$plan_sort_wandb" ] && sort -o $wan_db $wan_db && unset plan_sort_wandb
2786 if [ "$plan_regen_cookorder" ]; then
2787 [ "$(sed 1!d $cookorder)" = "#PlanSort" ] || \
2788 sed 1i"#PlanSort" -i $cookorder
2789 fi
2790 cook
2791 ;;
2792 sort-cooklist)
2793 check_root
2794 get_tazwok_config
2795 check_for_list
2796 report(){ : ; }
2797 # When using sort-cooklist, the script should behave as for gen-cooklist
2798 # The only difference between theses two is where the output is sended.
2799 COMMAND=gen-cooklist
2800 gen_cook_list
2801 cp -af $tmp/cooklist $LIST
2802 ;;
2803 cook-list)
2804 # Cook all packages listed in a file or in default cooklist.
2805 check_root
2806 get_options_list="pkg forced"
2807 get_tazwok_config
2808 source_lib report
2809 report start
2810 if ! [ "$pkg" ]; then
2811 [ "$LIST" ] && check_for_list
2812 fi
2813 gen_cook_list
2814 cook_list
2815 ;;
2816 clean)
2817 # Clean up a package work directory + thoses which want it.
2819 get_tazwok_config
2820 check_for_package_on_cmdline
2821 check_for_receipt
2822 source_lib report
2823 report start
2824 . $RECEIPT
2825 clean
2826 ;;
2827 gen-clean-wok)
2828 # Generate a clean wok from the current wok by copying all receipts
2829 # and stuff directory.
2831 get_tazwok_config
2832 source_lib report
2833 report start
2834 if [ -z "$ARG" ]; then
2835 echo -e "\nPlease specify the destination for the new clean wok.\n" >&2
2836 exit 1
2837 else
2838 dest=$ARG
2839 mkdir -p $dest
2840 fi
2841 report step "Creating clean wok in : $dest"
2842 for pkg in `ls -1 $WOK`
2843 do
2844 mkdir -p $dest/$pkg
2845 cp -a $WOK/$pkg/receipt $dest/$pkg
2846 [ -f $WOK/$pkg/description.txt ] && \
2847 cp -a $WOK/$pkg/description.txt $dest/$pkg
2848 if [ -d "$WOK/$pkg/stuff" ]; then
2849 cp -a $WOK/$pkg/stuff $dest/$pkg
2850 fi
2851 done
2852 [ -d $WOK/.hg ] && cp -a $WOK/.hg $dest
2853 report end-step
2854 echo "Packages cleaned : `ls -1 $dest | wc -l`"
2855 echo ""
2856 ;;
2857 clean-wok)
2858 # Clean all packages in the work directory
2860 get_tazwok_config
2861 source_lib report
2862 report start
2863 report step "Cleaning wok"
2864 for PACKAGE in `ls -1 $WOK`
2865 do
2866 set_common_path
2867 source_receipt
2868 clean
2869 done
2870 echo "`ls -1 $WOK | wc -l` packages cleaned."
2871 ;;
2872 clean-src)
2873 # Remove tarball unrelated to wok receipts from src repo.
2874 check_root
2875 get_options_list="forced"
2876 get_tazwok_config
2877 cd $SOURCES_REPOSITORY
2878 echo -n "Checking $SOURCES_REPOSITORY..."
2879 for TARBALL in *; do
2880 [ "$TARBALL" = sources.list ] && continue
2881 grep -q $'\t'$TARBALL$ $SOURCES_REPOSITORY/sources.list || \
2882 echo $TARBALL >> $tmp/obsolete
2883 done
2884 status
2885 if ! [ -f $tmp/obsolete ]; then
2886 echo "No sources need to be removed."
2887 exit 1
2888 fi
2889 echo ""
2890 echo -e "\033[1mObsolete/unrelated-to-wok sourcess :\033[0m"
2891 horizontal_line
2892 cat $tmp/obsolete
2893 horizontal_line
2894 echo "$(wc -l $tmp/obsolete | cut -f1 -d' ') tarballs to remove."
2895 echo ""
2896 echo -n "Please confirm removing (type uppercase YES): "
2897 read answer
2898 if [ "$answer" = YES ]; then
2899 echo -n "Removing old sources..."
2900 cat $tmp/obsolete | while read i; do
2901 rm -f $SOURCES_REPOSITORY/$i
2902 done
2903 status
2904 fi
2905 ;;
2906 gen-list)
2907 get_tazwok_config
2908 if [ "$2" ]; then
2909 if [ -d "$2" ]; then
2910 pkg_repository=$2
2911 else
2912 echo -e "\nUnable to find directory : $2\n" >&2
2913 exit 1
2914 fi
2915 fi
2917 source_lib report
2918 report start
2919 if [ "$pkg_repository" ]; then
2920 gen_packages_db
2921 else
2922 pkg_repository=$PACKAGES_REPOSITORY && gen_packages_db
2923 pkg_repository=$INCOMING_REPOSITORY && gen_packages_db
2924 fi
2925 ;;
2926 check-list)
2927 # The directory to move into by default is the repository,
2928 # if $2 is not empty cd into $2.
2930 get_tazwok_config
2931 if [ "$2" ]; then
2932 if [ -d "$2" ]; then
2933 pkg_repository=$2
2934 else
2935 echo -e "\nUnable to find directory : $2\n" >&2
2936 exit 1
2937 fi
2938 fi
2940 source_lib report
2941 report start
2942 if [ "$pkg_repository" ]; then
2943 update_packages_db
2944 else
2945 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2946 pkg_repository=$INCOMING_REPOSITORY && update_packages_db
2947 fi
2948 ;;
2949 new-tree)
2950 # Just create a few directories and generate an empty receipt to prepare
2951 # the creation of a new package.
2953 get_tazwok_config
2954 check_for_package_on_cmdline
2955 clean_wok=$LOCAL_REPOSITORY/clean-wok
2956 if [ -d $clean_wok/$PACKAGE ]; then
2957 echo -e "\n$PACKAGE package tree already exists.\n" >&2
2958 exit 1
2959 fi
2960 echo "Creating : $WOK/$PACKAGE"
2961 mkdir $clean_wok/$PACKAGE
2962 cd $clean_wok/$PACKAGE
2963 echo -n "Preparing the receipt..."
2965 # Default receipt begin.
2967 echo "# SliTaz package receipt." > receipt
2968 echo "" >> receipt
2969 echo "PACKAGE=\"$PACKAGE\"" >> receipt
2970 # Finish the empty receipt.
2971 cat >> receipt << "EOF"
2972 VERSION=""
2973 CATEGORY=""
2974 SHORT_DESC=""
2975 MAINTAINER=""
2976 DEPENDS=""
2977 TARBALL="$PACKAGE-$VERSION.tar.gz"
2978 WEB_SITE=""
2979 WGET_URL=""
2981 # Rules to configure and make the package.
2982 compile_rules()
2984 cd $src
2985 ./configure && make && make install
2988 # Rules to gen a SliTaz package suitable for Tazpkg.
2989 genpkg_rules()
2991 mkdir -p $fs/usr
2992 cp -a $_pkg/usr/bin $fs/usr
2995 EOF
2997 # Default receipt end.
2999 status
3000 # Interactive mode, asking and seding.
3001 if [ "$3" = "--interactive" ]; then
3002 echo "Entering into interactive mode..."
3003 echo "================================================================================"
3004 echo "Package : $PACKAGE"
3005 # Version.
3006 echo -n "Version : " ; read anser
3007 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
3008 # Category.
3009 echo -n "Category : " ; read anser
3010 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
3011 # Short description.
3012 echo -n "Short desc : " ; read anser
3013 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
3014 # Maintainer.
3015 echo -n "Maintainer : " ; read anser
3016 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
3017 # Web site.
3018 echo -n "Web site : " ; read anser
3019 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
3020 echo ""
3021 # Wget URL.
3022 echo "Wget URL to download source tarball."
3023 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
3024 echo -n "Wget url : " ; read anser
3025 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
3026 # Ask for a stuff dir.
3027 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
3028 if [ "$anser" = "y" ]; then
3029 echo -n "Creating the stuff directory..."
3030 mkdir stuff && status
3031 fi
3032 # Ask for a description file.
3033 echo -n "Are you going to write a description ? (y/N) : " ; read anser
3034 if [ "$anser" = "y" ]; then
3035 echo -n "Creating the description.txt file..."
3036 echo "" > description.txt && status
3037 fi
3038 echo "================================================================================"
3039 echo ""
3040 fi
3041 ;;
3042 remove)
3043 # Remove a package from the wok.
3045 get_tazwok_config
3046 check_for_package_on_cmdline
3047 echo ""
3048 echo -n "Please confirm deletion (y/N) : "; read anser
3049 if [ "$anser" = "y" ]; then
3050 echo -n "Removing $PACKAGE..."
3051 rm -rf $WOK/$PACKAGE && status
3052 echo ""
3053 fi
3054 ;;
3055 update-wok)
3056 # Pull and update a Hg wok.
3057 get_options_list="local"
3058 get_tazwok_config
3059 source_lib report
3060 report start
3061 clean_wok=$LOCAL_REPOSITORY/clean-wok
3062 cd $clean_wok
3063 if ! [ "$local" ]; then
3064 if [ "$WOK_UPDATE_METHOD" = hg ]; then
3065 if ! [ -f "$INSTALLED/mercurial/receipt" ]; then
3067 # Auto-install only if we are in a cook chroot.
3068 if [ -x /usr/bin/clean-chroot ]; then
3069 tazpkg get-install mercurial
3070 else
3071 echo "" >&2
3072 echo "You need to install mercurial to get wok from hg (recommended). Oherwise, you can switch wok get method to \"tarball\" into $LOCAL_RESOSITORY/tazwok.conf (per-repository configuration, it not always exists) or /etc/slitaz/tazwok.conf (global configuration)." | fold -s >&2
3073 echo "">&2
3074 exit 1
3075 fi
3076 fi
3078 report step "Getting wok changes using hg"
3079 if [ -d .hg ]; then
3080 hg pull -u || exit 1
3081 else
3082 hg clone $HG_WOK . || exit 1
3083 fi
3084 report end-step
3085 [ -x /usr/bin/clean-chroot ] && clean-chroot
3086 else
3087 report step "Getting wok changes using tarball"
3088 { mkdir .tmp && cd .tmp
3089 wget "$TARBALL_WOK" &&
3090 case $TARBALL_WOK in
3091 *bz2) tar xjf *.bz2 -C wok; rm *.bz2;;
3092 *lzma) unlzma -c *.lzma | tar xf - -C wok; rm *.lzma ;;
3093 *gz) tar xzf *.gz -C wok; rm*.gz ;;
3094 esac &&
3095 rm -r $(ls -d $clean_wok/*) &&
3096 cp -a wok/* $clean_wok &&
3097 cd .. &&
3098 rm -r .tmp
3099 } || { echo "That's not cool: it fails!" >&2
3100 report end-step
3101 exit 1; }
3102 report end-step
3103 fi
3104 fi
3105 report step "Appending changes to wok"
3107 # Handle removed files/dir.
3108 cd $WOK
3109 for dir in *; do
3110 [ -d "$clean_wok/$dir" ] || rm -rf $dir
3111 done
3112 for file in */receipt */description.txt; do
3113 [ -f "$clean_wok/$file" ] || rm -rf $file
3114 done
3115 for i in $(find */stuff 2>/dev/null); do
3116 [ -e "$clean_wok/$i" ] || rm -rf $i
3117 done
3119 cp -a $clean_wok/* $WOK
3120 report end-step
3121 ;;
3122 maintainers)
3123 get_tazwok_config
3124 echo ""
3125 echo "List of maintainers for: $WOK"
3126 echo "================================================================================"
3127 touch /tmp/slitaz-maintainers
3128 for pkg in $WOK/*
3129 do
3130 . $pkg/receipt
3131 if ! fgrep -q "$MAINTAINER" /tmp/slitaz-maintainers; then
3132 echo "$MAINTAINER" >> /tmp/slitaz-maintainers
3133 echo "$MAINTAINER"
3134 fi
3135 done
3136 echo "================================================================================"
3137 echo "Maintainers: `cat /tmp/slitaz-maintainers | wc -l`"
3138 echo ""
3139 # Remove tmp files
3140 rm -f /tmp/slitaz-maintainers
3141 ;;
3142 maintained-by)
3143 # Search for packages maintained by a contributor.
3144 get_tazwok_config
3145 if [ ! -n "$2" ]; then
3146 echo "Specify a name or email of a maintainer." >&2
3147 exit 1
3148 fi
3149 echo "Maintainer packages"
3150 echo "================================================================================"
3151 for pkg in $WOK/*
3152 do
3153 . $pkg/receipt
3154 if echo "$MAINTAINER" | fgrep -q "$2"; then
3155 echo "$PACKAGE"
3156 packages=$(($PACKAGEs+1))
3157 fi
3158 done
3159 echo "================================================================================"
3160 echo "Packages maintained by $2: $PACKAGEs"
3161 echo ""
3162 ;;
3163 tags)
3164 get_tazwok_config
3165 echo -e "\n\033[1mTags list :\033[0m"
3166 horizontal_line
3167 cd $WOK
3168 for i in */receipt; do
3169 unset TAGS
3170 source $i
3171 for t in $TAGS; do
3172 grep -q ^$t$ $tmp/tags && continue
3173 echo $t | tee -a $tmp/tags
3174 done
3175 done
3176 horizontal_line
3177 echo "$(wc -l $tmp/tags | cut -f1 -d ' ') tags listed."
3178 ;;
3179 check-src)
3180 # Verify if upstream package is still available
3182 get_tazwok_config
3183 check_for_package_on_cmdline
3184 check_for_receipt
3185 source_receipt
3186 check_src()
3188 for url in $@; do
3189 busybox wget -s $url 2>/dev/null && break
3190 done
3192 if [ "$WGET_URL" ];then
3193 echo -n "$PACKAGE : "
3194 check_src $WGET_URL
3195 status
3196 else
3197 echo "No tarball to check for $PACKAGE"
3198 fi
3199 ;;
3200 get-src)
3201 check_root
3202 get_options_list="target nounpack"
3203 get_tazwok_config
3204 check_for_package_on_cmdline
3205 check_for_receipt
3206 source_receipt
3207 if [ "$WGET_URL" ];then
3208 source_lib report
3209 report start
3210 check_for_tarball
3211 else
3212 echo "No tarball to download for $PACKAGE"
3213 fi
3214 ;;
3215 check-commit)
3216 check_root
3217 get_options_list="missing forced"
3218 get_tazwok_config
3219 source_lib report
3220 report start
3221 if [ "$forced" ]; then
3222 rm -f $WOK/*/md5
3223 unset forced
3224 fi
3225 if [ "$missing" ]; then
3226 pkg=$(ls -1 $WOK)
3227 else
3228 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3229 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3230 } | sort -u)"
3231 fi
3232 gen_cook_list
3233 ;;
3234 cook-commit)
3235 check_root
3236 get_options_list="missing forced"
3237 get_tazwok_config
3238 source_lib report
3239 report start
3240 if [ "$forced" ]; then
3241 rm -f $WOK/*/md5
3242 unset forced
3243 fi
3244 if [ "$missing" ]; then
3245 pkg=$(ls -1 $WOK)
3246 else
3247 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3248 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3249 } | sort -u)"
3250 fi
3251 gen_cook_list
3252 cook_list
3253 ;;
3254 cook-all)
3255 check_root
3256 get_options_list="forced missing"
3257 get_tazwok_config
3258 source_lib report
3259 report start
3260 if [ "$missing" ]; then
3261 pkg=$(ls -1 $WOK)
3262 else
3263 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3264 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3265 } | sort -u)"
3266 fi
3267 gen_cook_list
3268 cook_list
3269 ;;
3270 gen-wok-db)
3271 check_root
3272 get_tazwok_config
3273 source_lib report
3274 report start
3275 gen_wok_db
3276 ;;
3277 report)
3278 get_tazwok_config
3279 cd $PACKAGES_REPOSITORY
3280 if [ "$2" ]; then
3281 case $2 in
3282 commit|cooklist|incoming|broken|blocked)
3283 show="$2"
3284 ;;
3285 *)
3286 echo "usage : tazwok report [commit|cooklist|incoming|broken|blocked]" >&2
3287 exit 1
3288 ;;
3289 esac
3290 else
3291 show="commit cooklist incoming broken blocked"
3292 fi
3293 for i in $show; do
3294 if [ -s $i ]; then
3295 echo ""
3296 echo -e "\033[1m$i\033[0m"
3297 echo "================================================================================"
3298 cat $i
3299 echo "================================================================================"
3300 echo ""
3301 fi
3302 done
3303 ;;
3304 check-incoming)
3305 check_root
3306 get_options_list="forced"
3307 get_tazwok_config
3308 source_lib report
3309 report start
3310 [ -f $LOCAL_RESOSITORY/incoming ] && rm [ -f $LOCAL_REPOSITORY/incoming ]
3311 report step "Checking $INCOMING_REPOSITORY"
3312 report open-bloc
3313 [ -f $LOCAL_REPOSITORY/log/incoming.html ] && rm $LOCAL_REPOSITORY/log/incoming.html
3314 report sublog $LOCAL_REPOSITORY/log/incoming.html
3315 echo "incoming" > $LOCAL_REPOSITORY/log/package
3316 check_for_incoming
3317 report end-sublog
3318 report close-bloc
3319 ;;
3320 configure-chroot)
3321 check_root
3322 get_tazwok_config
3323 if [ -f /usr/bin/tazchroot ]; then
3324 cd $LOCAL_REPOSITORY
3325 configure_tazchroot
3326 else
3327 echo "The packages tazchroot need to be installed" >&2
3328 exit 1
3329 fi
3330 ;;
3331 chroot)
3332 check_root
3333 get_tazwok_config
3334 # Merge this and the other chroot function ?.
3335 if [ -f /usr/bin/tazchroot ]; then
3336 cd $LOCAL_REPOSITORY
3337 [ ! -f tazchroot.conf ] && configure_tazchroot
3338 tazchroot
3339 else
3340 echo "The packages tazchroot need to be installed" >&2
3341 exit 1
3342 fi
3343 ;;
3344 cook-toolchain)
3345 check_root
3346 get_tazwok_config
3347 echo -n "" > $PACKAGES_REPOSITORY/broken
3348 if [ -f /usr/bin/tazchroot ]; then
3349 cd $LOCAL_REPOSITORY
3350 [ -f tazchroot.conf ] || configure_tazchroot
3352 # Plan to recook all packages.
3353 if tazchroot cook-toolchain; then
3354 source_lib report
3355 report start
3356 pkg="$(grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt \
3357 $INCOMING_REPOSITORY/packages.txt | sort -u)"
3358 forced=yes
3359 gen_cook_list
3360 fi
3362 # Remove chroot where toolchain has been cooked.
3363 source $LOCAL_REPOSITORY/tazchroot.conf
3364 rm -r $LOCAL_REPOSITORY/chroot
3366 else
3367 echo -e "\nThe package tazchroot need to be installed.\n" >&2
3368 exit 1
3369 fi
3370 ;;
3371 webserver)
3372 check_root
3373 get_tazwok_config
3374 if [ "$ARG" = on ]; then
3375 if [ "$WEBSERVER" ] && [ -f "$WEBSERVER/repositories.list" ] && \
3376 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3377 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3378 exit 1
3379 fi
3380 if ! [ -f $LOCAL_REPOSITORY/tazchroot.conf ]; then
3381 tazwok configure-chroot ${undigest:+--undigest=$undigest} --SLITAZ_VERSION=$SLITAZ_VERSION --SLITAZ_DIR=$SLITAZ_DIR
3382 fi
3383 for pkg in php lighttpd; do
3384 [ -d $INSTALLED/$pkg ] || missing="$missing $pkg"
3385 done
3386 if [ "$missing" ]; then
3387 echo "You need to install those packages to start webserver: $missing." >&2
3388 exit 1
3389 fi
3390 if [ ! -f "$LOCAL_REPOSITORY/tazwok.conf" ]; then
3391 echo "Copying /etc/slitaz/tazwok.conf to $LOCAL_REPOSITORY/tazwok.conf: webserver is configured repository-by-repository."
3392 cp /etc/slitaz/tazwok.conf $LOCAL_REPOSITORY
3393 fi
3394 if ! [ "$WEBSERVER" ]; then
3395 echo -n "Where to store php pages (default: /var/www/vhosts/bb)? "
3396 read WEBSERVER
3397 [ "$WEBSERVER" ] || WEBSERVER="/var/www/vhosts/bb"
3398 fi
3399 if [ -f "$WEBSERVER/repositories.list" ] && \
3400 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3401 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3402 exit 1
3403 fi
3404 mkdir -p $WEBSERVER
3405 echo "${undigest:-$SLITAZ_VERSION}" >> $WEBSERVER/repositories.list
3406 for file in index.php log.php download.php; do
3407 [ -f "$WEBSERVER/$file" ] || ln -s /usr/share/slitaz/web-bb/$file $WEBSERVER
3408 done
3409 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3410 ln -s $dir $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3411 done
3412 source $LOCAL_REPOSITORY/tazchroot.conf
3413 echo "<?php
3415 // Web interface configuration
3417 \$version=\"${undigest:-$SLITAZ_VERSION}\";
3418 \$chroot=\"$chroot_dir\";
3419 \$lockfile=\"\$chroot/proc/1/status\";
3420 \$db_dir=\"$PACKAGES_REPOSITORY\";
3421 \$log_dir=\"$LOCAL_REPOSITORY/log\";
3422 \$packages=\"$PACKAGES_REPOSITORY\";
3423 \$incoming=\"$INCOMING_REPOSITORY\";
3424 \$wok=\"$WOK\";
3426 ?>" > $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3427 [ -L "$WEBSERVER/web" ] || ln -s /usr/share/slitaz/web $WEBSERVER
3428 echo "WEBSERVER=\"$WEBSERVER\"" >> $LOCAL_REPOSITORY/tazwok.conf
3429 if [ -L "$WEBSERVER/conf.php" ]; then
3430 echo "Do yo want to make ${undigest:-$SLITAZ_VERSION} the default page (y/N) ? "
3431 read answer
3432 if [ "$answer" = y ]; then
3433 rm $WEBSERVER/conf.php
3434 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3435 fi
3436 else
3437 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3438 fi
3439 elif [ "$ARG" = off ]; then
3440 if ! [ "$WEBSERVER" ]; then
3441 echo "No webserver running for ${undigest:-$SLITAZ_VERSION}" >&2
3442 exit 1
3443 fi
3444 sed '/^WEBSERVER/d' -i $LOCAL_REPOSITORY/tazwok.conf
3445 sed "/^${undigest:-$SLITAZ_VERSION}$/d" -i $WEBSERVER/repositories.list
3446 rm $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3447 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3448 rm $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3449 done
3450 if ! [ -s "$WEBSERVER/repositories.list" ]; then
3451 echo "$WEBSERVER/repositories.list is empty; tazwok doesn't remove the server automatically in case you have important stuff in it. If it's not the case, you can remove it using: rm -r $WEBSERVER"
3452 rm $WEBSERVER/conf.php
3453 elif [ "$(readlink $WEBSERVER/conf.php)" = "$WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php" ]; then
3454 echo "${undigest:-$SLITAZ_VERSION} was the default version to use; switched to : $(sed 1!d $WEBSERVER/repositories.list)"
3455 rm $WEBSERVER/conf.php
3456 ln -s $WEBSERVER/conf-$(sed 1!d $WEBSERVER/repositories.list).php $WEBSERVER/conf.php
3457 fi
3458 else
3459 echo "Usage: tazwok webserver on/off" >&2
3460 exit 1
3461 fi
3462 ;;
3463 block)
3464 # Add a pkg name to the list of blocked packages.
3465 get_tazwok_config
3466 check_root
3467 check_for_package_on_cmdline
3468 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3469 echo "Can't find $PACKAGE into wok." >&2
3470 echo ""
3471 exit 1
3472 fi
3473 echo ""
3474 if grep -qs "^$PACKAGE$" $blocked; then
3475 echo "$PACKAGE is already in the blocked packages list." >&2
3476 echo ""
3477 exit 1
3478 else
3479 echo -n "Adding $PACKAGE to : $blocked... "
3480 echo "$PACKAGE" >> $blocked
3481 status
3482 if grep -q "^$PACKAGE$" $cooklist; then
3483 echo -n "Removing $PACKAGE from : $cooklist... "
3484 sed -i /"^$PACKAGE$"/d $cooklist
3485 status
3486 fi
3487 fi
3488 echo "" ;;
3489 unblock)
3490 # Remove a pkg name from 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 into wok." >&2
3496 echo ""
3497 exit 1
3498 fi
3499 echo ""
3500 if grep -qs "^$PACKAGE$" $blocked; then
3501 echo -n "Removing $PACKAGE from : $blocked... "
3502 sed -i /"^$PACKAGE$"/d $blocked
3503 sed -i '/^$/d' $blocked
3504 status
3505 else
3506 echo "$PACKAGE is not in the blocked packages list." >&2
3507 echo ""
3508 exit 1
3509 fi
3510 echo "" ;;
3511 usage|*)
3512 # Print usage also for all unknown commands.
3514 usage
3515 ;;
3516 esac
3518 report stop 2>/dev/null
3519 exit 0