tazwok view tazwok @ rev 434

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