tazwok view tazwok @ rev 383

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