tazwok view tazwok @ rev 385

tazwok: remove 64M memory limit
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Mar 01 12:05:13 2011 +0100 (2011-03-01)
parents 57321b17f1b9
children c977b7cf78f3
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
599 ulimit -d unlimited
600 ulimit -m unlimited
602 # Free some RAM by cleaning cache if option is enabled.
603 freeram=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
605 # Disable -pipe in CFLAGS/CXXFLAGS if less than 512Mb of free
606 # RAM are available.
607 if [ "$freeram" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" -o \
608 "$CXXFLAGS" != "${CXXFLAGS/-pipe}" ]; then
609 tazwok_warning "Disabling -pipe compile flag because only ${freeram}b of RAM are available."
610 CFLAGS="${CFLAGS/-pipe}"
611 CXXFLAGS="${CXXFLAGS/-pipe}"
612 fi
613 unset freeram
615 # Set cook environnement variables.
616 [ "$src" ] || set_src_path
617 [ "$DESTDIR" ] || DESTDIR="$WOK/$PACKAGE/install"
618 [ "$CONFIG_SITE" ] || CONFIG_SITE=/etc/config.site
619 export CFLAGS CXXFLAGS MAKEFLAGS DESTDIR BUILD_HOST \
620 CONFIG_SITE default_prefix \
621 default_datarootdir default_datadir default_localedir \
622 default_infodir default_mandir default_build default_host
623 local LC_ALL=POSIX LANG=POSIX
624 compile_rules
626 # Check if config.site has been used.
627 # /!\ disabled since it screw the return_code of the step.
628 #if [ -f /tmp/config.site ]; then
629 # rm /tmp/config.site
630 #else
631 # tazwok_warning "config.site hasn't been used during \
632 #configuration process."
633 #fi
634 report end-step
635 fi
636 }
638 # Check for loop in deps tree. /!\ can be removed
639 check_for_deps_loop()
640 {
641 local list
642 local pkg
643 local deps
644 pkg=$1
645 shift
646 [ -n "$1" ] || return
647 list=""
649 # Filter out already processed deps
650 for i in $@; do
651 case " $ALL_DEPS" in
652 *\ $i\ *);;
653 *) list="$list $i";;
654 esac
655 done
656 ALL_DEPS="$ALL_DEPS$list "
657 for i in $list; do
658 [ -f $i/receipt ] || continue
659 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
660 case " $deps " in
661 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
662 *) check_for_deps_loop $pkg $deps;;
663 esac
664 done
665 }
667 # Function used by download().
668 revert_vcs_failure()
669 {
670 cd $SOURCES_REPOSITORY
671 rm -r $tmp_src
672 }
674 download()
675 {
676 if [ "$COMMAND" = get-src ]; then
677 if [ "${DEPENDS/tar}" != "$DEPENDS" ] || [ "${BUILD_DEPENDS/tar}" != "$BUILD_DEPENDS" ]; then
678 [ -f $INSTALLED/tar/receipt ] || tazpkg get-install tar --forced
679 fi
680 fi
681 for file in $@; do
682 echo "Downloading from ${file#*|}..."
683 case "$file" in
684 git\|*)
685 file=${file#git|}
686 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/git/receipt ] && tazpkg get-install git --forced
687 if [ -f $INSTALLED/git/receipt ]; then
688 mkdir $tmp_src
689 cd $tmp_src
690 if [ "$BRANCH" ]; then
691 git clone $file ${src##*/} && cd ${src##*/} && \
692 git checkout $BRANCH && rm -rf .git* && break
693 else
694 git clone $file ${src##*/} && rm -rf ${src##*/}/.git* && break
695 fi
696 revert_vcs_failure
697 else
698 tazwok_warning "Needs git to download the source tarball from $file, please add it as build-depend."
699 continue
700 fi
701 ;;
702 subversion\|*)
703 file=${file#subversion|}
704 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/subversion/receipt ] && tazpkg get-install subversion --forced
705 if [ -f $INSTALLED/subversion/receipt ]; then
706 mkdir $tmp_src
707 cd $tmp_src
708 if [ "$BRANCH" ]; then
709 echo t | svn co $file -r $BRANCH ${src##*/} && rm -rf ${src##*/}/.svn* && break
710 else
711 echo t | svn co $file ${src##*/} && rm -rf ${src##*/}/.svn* && break
712 fi
713 revert_vcs_failure
714 else
715 tazwok_warning "Needs subversion to download the source tarball from $file, please add it as build-depend."
716 continue
717 fi
718 ;;
719 mercurial\|*)
720 file=${file#mercurial|}
721 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/mercurial/receipt ] && tazpkg get-install mercurial --forced
722 if [ -f $INSTALLED/mercurial/receipt ]; then
723 mkdir $tmp_src
724 cd $tmp_src
725 if [ "$BRANCH" ]; then
726 hg clone $file --rev $BRANCH ${src##*/} && rm -rf ${src##*/}/.hg* && break
727 else
728 hg clone $file ${src##*/} && rm -rf ${src##*/}/.hg* && break
729 fi
730 revert_vcs_failure
731 else
732 tazwok_warning "Needs mercurial to download the source tarball from $file, please add it as build-depend."
733 continue
734 fi
735 ;;
736 https*)
737 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/wget/receipt ] && tazpkg get-install wget --forced
738 if [ -d $INSTALLED/wget ]; then
739 if [ "${WGET_URL%$TARBALL}" = "$WGET_URL" ] && [ "$file" = "$WGET_URL" ]; then
740 wget -q --no-check-certificate -O $TARBALL $file && break
741 else
742 wget -q --no-check-certificate $file && break
743 fi
744 else
745 tazwok_warning "Needs wget to download the source tarball from $file, please add it as build-depend."
746 continue
747 fi
748 ;;
749 http*|ftp*)
750 # Handle crappy URL.
751 if [ "$COMMAND" = get-src ]; then
752 if [ "${DEPENDS/wget}" != "$DEPENDS" ] || [ "${BUILD_DEPENDS/wget}" != "$BUILD_DEPENDS" ]; then
753 [ -f $INSALLED/wget/receipt ] || tazpkg get-install wget --forced
754 fi
755 fi
756 if [ "${WGET_URL%$TARBALL}" = "$WGET_URL" ] && [ "$file" = "$WGET_URL" ]; then
757 wget -q -O $TARBALL $file && break
758 else
759 wget -q $file && break
760 fi
761 ;;
762 esac
763 done
764 }
766 # Regenerate every package that wants a PACKAGE compiled
767 refresh_packages_from_compile()
768 {
769 # make tazwok genpkg happy
770 mkdir $WOK/$PACKAGE/taz
772 # Cook rwanted in default or specied order
773 genlist=" $(look_for_rwanted | tr '\n' ' ') "
774 for i in $(look_for_cookopt genpkg | tac); do
775 [ "${genlist/ $i }" = "$genlist" ] && continue
776 genlist=" $i${genlist/ $i / }"
777 done
778 if [ "$genlist" ]; then
779 local PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
780 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
781 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
782 src _pkg DESTDIR CONFIG_SITE RECEIPT LOG stuff wanted_stuff
783 for PACKAGE in $genlist; do
784 set_common_path
785 gen_package
786 done
787 fi
788 }
790 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
791 # so some packages need to copy these files with the receipt and genpkg_rules.
792 # This function is executed by gen_package when 'tazwok genpkg'.
793 copy_generic_files()
794 {
795 # In most cases, locales are in $_pkg/usr/share/locale so we copy files
796 # using generic variables and $LOCALE from Tazwok config file.
797 if [ "$LOCALE" ]; then
798 if [ -d "$_pkg/usr/share/locale" ]; then
799 for i in $LOCALE
800 do
801 if [ -d "$_pkg/usr/share/locale/$i" ]; then
802 mkdir -p $fs/usr/share/locale
803 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
804 fi
805 done
806 fi
807 fi
809 # Pixmaps (PNG or/and XPM only). Some icons/images can be added through
810 # genpkg_rules and generic copy can be disabled with GENERIC_PIXMAPS="no"
811 # in pkg receipt.
812 if [ "$GENERIC_PIXMAPS" != "no" ]; then
813 if [ -d "$_pkg/usr/share/pixmaps" ]; then
814 mkdir -p $fs/usr/share/pixmaps
815 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
816 $fs/usr/share/pixmaps 2>/dev/null
817 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
818 $fs/usr/share/pixmaps 2>/dev/null
819 fi
821 # Custom or homemade PNG pixmap can be in stuff.
822 if [ -f "stuff/$PACKAGE.png" ]; then
823 mkdir -p $fs/usr/share/pixmaps
824 cp -a stuff/$PACKAGE.png $fs/usr/share/pixmaps
825 fi
826 fi
828 # Desktop entry (.desktop).
829 if [ -d "$_pkg/usr/share/applications" ]; then
830 cp -a $_pkg/usr/share/applications $fs/usr/share
831 fi
833 # Homemade desktop file(s) can be in stuff.
834 if [ -d "stuff/applications" ]; then
835 mkdir -p $fs/usr/share
836 cp -a stuff/applications $fs/usr/share
837 fi
838 if [ -f "stuff/$PACKAGE.desktop" ]; then
839 mkdir -p $fs/usr/share/applications
840 cp -a stuff/$PACKAGE.desktop $fs/usr/share/applications
841 fi
842 }
844 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
845 strip_package()
846 {
847 report step "Executing strip on all files"
849 # Binaries.
850 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
851 do
852 if [ -d "$dir" ]; then
853 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
854 fi
855 done
857 # Libraries.
858 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
859 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
860 report end-step
861 }
863 # Remove .pyc and .pyo files from packages
864 py_compiled_files_remove()
865 {
866 report step "Removing all .pyc and .pyo files from package ..."
867 find $fs -type f -name "*.pyc" -delete 2>/dev/null
868 find $fs -type f -name "*.pyo" -delete 2>/dev/null
869 report end-step
870 }
872 # Check FSH in a slitaz package (Path: /:/usr)
873 check_fsh()
874 {
875 cd $WOK/$PACKAGE/taz/*/fs
876 if ! [ "$(find * -type f)" ]; then
877 echo "$PACKAGE fs is empty." >&2
878 cd $WOK/$PACKAGE && rm -rf taz
879 return 1
880 fi
881 [ -n "$FSH" ] || FSH="bin boot dev etc home init lib media mnt proc \
882 root sbin share sys tmp usr var vz usr/bin usr/games usr/include usr/lib \
883 usr/local usr/sbin usr/share usr/src"
884 for i in `ls -d * usr/* 2>/dev/null`
885 do
886 if ! echo $FSH | fgrep -q $i; then
887 echo "Wrong path: /$i" >&2
888 error=1
889 fi
890 done
891 if [ "$error" = "1" ]; then
892 cat << _EOT_
894 Package will install files in a non standard directory and won't be generated.
895 You may have a wrong copy path in genpkg_rules or need to add some options to
896 configure in compile_rules. Some valid options for SliTaz (Linux FSH):
898 --prefix=/usr
899 --sysconfdir=/etc
900 --libexecdir=/usr/lib/(pkgname)
901 --localstatedir=/var
902 --mandir=/usr/share/man
903 --infodir=/usr/share/info
905 For more information please read SliTaz docs and run: ./configure --help
906 ================================================================================
907 $PACKAGE package generation aborted.
909 _EOT_
911 # Dont generate a corrupted package.
912 cd $WOK/$PACKAGE && rm -rf taz
913 return 1
914 fi
915 return 0
916 }
918 gen_cookmd5()
919 {
920 # md5sum of cooking stuff make tazwok able to check for changes
921 # without hg.
922 cd $WOK/$PACKAGE
923 md5sum receipt > md5
924 [ -f description.txt ] && md5sum description.txt >> md5
925 if [ -d stuff ]; then
926 find stuff | while read file; do
927 md5sum $file >> md5
928 done
929 fi
930 }
932 set_pkg_broken()
933 {
934 if ! grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/broken; then
935 echo $PACKAGE >> $PACKAGES_REPOSITORY/broken
936 fi
938 # Remove pkg from cooklist to avoid re-cook it if no changes happens
939 # in the cook stuff.
940 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/cooklist
941 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/commit
943 gen_cookmd5
945 # Return 1 to make report know that's mother-function failed.
946 return 1
947 }
949 # Create a package tree and build the gziped cpio archive
950 # to make a SliTaz (.tazpkg) package.
951 gen_package()
952 {
953 check_root
954 check_for_package_on_cmdline
955 check_for_receipt
956 source_receipt
958 # May compute VERSION
959 if grep -q ^get_version $RECEIPT; then
960 get_version
961 fi
962 check_for_wanted
963 cd $WOK/$PACKAGE
965 # Remove old Tazwok package files.
966 [ -d "taz" ] && rm -rf taz
968 # Create the package tree and set useful variables.
969 fs=$WOK/$PACKAGE/taz/$PACKAGE-$VERSION/fs
970 mkdir -p $fs
972 # Set $src for standard package and $_pkg variables.
973 set_src_path
974 set_pkg_path
976 # Execute genpkg_rules, check package and copy generic files to build
977 # the package.
978 report step "Building $PACKAGE with the receipt"
979 report open-bloc
980 if look_for_cookopt !fs; then
981 :
982 elif grep -q ^genpkg_rules $RECEIPT; then
984 # Log process.
985 echo "executing genpkg_rules" >> $LOG
986 report step "Executing genpkg_rules"
987 ( set -e; genpkg_rules ) || { set_pkg_broken; report close-bloc; return 1; }
988 check_fsh || { set_pkg_broken; report close-bloc; return 1; }
989 cd $WOK/$PACKAGE
990 report end-step
992 # Skip generic files for packages with a WANTED variable
993 # (dev and splited pkgs).
994 if [ ! "$WANTED" ]; then
995 copy_generic_files
996 fi
997 look_for_cookopt !strip || strip_package
998 py_compiled_files_remove
999 else
1000 echo "No package rules to gen $PACKAGE..." >&2
1001 set_pkg_broken
1002 report close-bloc
1003 return 1
1004 fi
1006 # Copy the receipt and description (if exists) into the binary package tree.
1007 cd $WOK/$PACKAGE
1008 report step "Copying the receipt"
1009 cp receipt taz/$PACKAGE-$VERSION
1010 report end-step
1011 if grep -q ^get_version $RECEIPT; then
1012 report step "Updating version in receipt"
1013 sed -i "s/^VERSION=.*/VERSION=\"$VERSION\"/" \
1014 taz/$PACKAGE-$VERSION/receipt
1015 report end-step
1016 fi
1017 if [ -f "description.txt" ]; then
1018 report step "Copying the description file"
1019 cp description.txt taz/$PACKAGE-$VERSION
1020 report end-step
1021 fi
1023 # Generate md5 of cooking stuff to look for commit later.
1024 gen_cookmd5
1025 echo -e "\n# md5sum of cooking stuff :" >> taz/$PACKAGE-$VERSION/receipt
1026 cat md5 | sed 's/^/# /' >> taz/$PACKAGE-$VERSION/receipt
1028 # Create the files.list by redirecting find output.
1029 report step "Creating the list of files"
1030 cd taz/$PACKAGE-$VERSION
1031 LAST_FILE=""
1032 { find fs -print; echo; } | while read file; do
1033 if [ "$LAST_FILE" ]; then
1034 case "$file" in
1035 $LAST_FILE/*)
1036 case "$(ls -ld "$LAST_FILE")" in
1037 drwxr-xr-x\ *\ root\ *\ root\ *);;
1038 *) echo ${LAST_FILE#fs};;
1039 esac;;
1040 *) echo ${LAST_FILE#fs};;
1041 esac
1042 fi
1043 LAST_FILE="$file"
1044 done > files.list
1046 # Next, check if something has changed in lib files.
1047 if fgrep -q '.so' files.list; then
1048 for rep in $INCOMING_REPOSITORY $PACKAGES_REPOSITORY \
1049 $([ "$undigest" ] && echo $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming && \
1050 echo $SLITAZ_DIR/$SLITAZ_VERSION/packages); do
1051 prev_VERSION=$(get_pkg_version $rep)
1052 [ "$prev_VERSION" ] && pkg_file=$rep/$PACKAGE-$prev_VERSION.tazpkg && break
1053 done
1054 if [ "$pkg_file" ]; then
1055 report step "Look for major/minor update in libraries"
1056 get_pkg_files $pkg_file
1057 cd $WOK/$PACKAGE/taz/$PACKAGE-$VERSION
1058 fgrep ".so" files.list | egrep -v "[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*" | \
1059 while read lib; do
1060 fgrep -q "$lib" $pkg_files_dir/files.list && continue
1061 echo "A minor/major update in libraries is detected, planning re-cook of reverse-depends of $PACKAGE."
1062 for rdep in $(scan $PACKAGE --look_for=rdep | use_wanted); do
1063 [ "$rdep" = "${WANTED:-$PACKAGE}" ] && continue
1064 grep -q ^$rdep$ $PACKAGES_REPOSITORY/blocked \
1065 $PACKAGES_REPOSITORY/cooklist && continue
1066 echo $rdep >> $PACKAGES_REPOSITORY/cooklist
1067 done
1068 regen_cooklist=yes
1069 break
1070 done
1071 rm -r $pkg_files_dir
1072 unset pkg_file
1073 report end-step
1074 fi
1075 fi
1076 if [ ! "$EXTRAVERSION" ]; then
1077 case "$PACKAGE" in
1078 linux*);;
1079 *) EXTRAVERSION="$(grep '/lib/modules/.*-slitaz/' files.list |\
1080 head -1 | sed 's|/lib/modules/\(.*\)-slitaz/.*|_\1|')";;
1081 esac
1082 fi
1083 rm -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg 2> /dev/null
1084 report step "Creating md5sum of files"
1085 while read file; do
1086 [ -L "fs$file" ] && continue
1087 [ -f "fs$file" ] || continue
1088 md5sum "fs$file" | sed 's/ fs/ /'
1089 done < files.list > md5sum
1090 report end-step
1091 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
1092 2> /dev/null | awk '{ sz=$1 } END { print sz }')
1094 # Build cpio archives. Find, cpio and gzip the fs, finish by
1095 # removing the fs tree.
1096 # Don't log this because compression always output error messages.
1097 find fs -print | cpio -o -H newc | case "$PACKAGE-$COMPRESSION" in
1098 tazpkg-lzma) gzip > fs.cpio.gz;;
1099 *-lzma) lzma e fs.cpio.lzma -si;;
1100 *) gzip > fs.cpio.gz;;
1101 esac && rm -rf fs
1102 PACKED_SIZE=$(du -chs fs.cpio.* receipt files.list md5sum \
1103 description.txt 2> /dev/null | awk '{ sz=$1 } END { print sz }')
1104 report step "Updating receipt sizes"
1105 sed -i '/^PACKED_SIZE/d' receipt
1106 sed -i '/^UNPACKED_SIZE/d' receipt
1107 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1108 sed -i "s/^VERSION=$/VERSION=\"$VERSION\"/" receipt
1109 report end-step
1110 if [ "$EXTRAVERSION" ]; then
1111 report step "Updating receipt EXTRAVERSION"
1112 sed -i s/^EXTRAVERSION.*$// receipt
1113 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
1114 fi
1115 prev_VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
1116 remove_previous_package $INCOMING_REPOSITORY
1117 report step "Creating full cpio archive"
1118 find . -print | cpio -o -H newc > $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1120 # Restore package tree in case we want to browse it.
1121 report step "Restoring original package tree"
1122 { zcat fs.cpio.gz 2> /dev/null || unlzma -c fs.cpio.lzma; } | cpio --quiet -id
1123 rm fs.cpio.* && cd ..
1125 # Recook of reverse-depends if package was broken.
1126 if grep -q "^$PACKAGE$" $PACKAGES_REPOSITORY/broken; then
1127 report step "Planning re-try a cook of reverse depends"
1128 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/broken
1129 for rdep in $(look_for_rdep); do
1130 grep -q "^$rdep$" $PACKAGES_REPOSITORY/broken || continue
1131 grep -q "^$rdep$" $PACKAGES_REPOSITORY/cooklist && continue
1132 echo "Adding $rdep to the cooklist"
1133 echo $rdep >> $PACKAGES_REPOSITORY/cooklist
1134 regen_cooklist=t
1135 done
1136 report end-step
1137 fi
1138 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/commit
1139 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/cooklist
1141 # Log process.
1142 echo "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg (done)" >> $LOG
1143 report close-bloc
1144 echo "Package $PACKAGE ($VERSION$EXTRAVERSION) generated."
1145 echo "Size : `du -sh $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
1146 echo ""
1149 ########################################################################
1150 # This section contains functions used by several other functions
1151 # bellow.
1152 ########################
1154 # Look for receipt/files.list in wok. If they can't be found, get them
1155 # from package. Accept one argument : absolute path to package.
1156 get_pkg_files()
1158 pkg_files_dir=$tmp/$(basename ${1%.tazpkg})
1159 mkdir -p $pkg_files_dir && \
1160 cd $pkg_files_dir && \
1161 cpio --quiet -idm receipt < $1 && \
1162 cpio --quiet -idm files.list < $1
1165 ########################################################################
1166 # This section contains functions to generate packages databases.
1167 ########################
1170 gen_packages_db()
1172 # pkg_repository can be $PACKAGES_REPOSITORY or $INCOMING_REPOSITORY.
1173 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1174 cd $pkg_repository
1175 report step "Generating packages lists: $pkg_repository"
1176 report open-bloc
1177 report step "Removing old files"
1178 for file in files.list.lzma packages.list packages.txt \
1179 packages.desc packages.equiv packages.md5; do
1180 [ -f $file ] && rm $file
1181 done
1182 touch files.list
1184 packages_db_start
1185 unset RECEIPT
1186 report step "Reading datas from all packages"
1187 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1188 get_packages_info
1189 done
1190 report end-step
1191 packages_db_end
1192 report close-bloc
1195 update_packages_db()
1197 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1198 cd $pkg_repository
1199 for file in packages.list packages.equiv packages.md5 packages.desc \
1200 packages.txt; do
1201 if [ ! -f "$file" ]; then
1202 gen_packages_db
1203 return
1204 fi
1205 done
1206 if [ -f files.list.lzma ]; then
1207 lzma d files.list.lzma files.list
1208 else
1209 gen_packages_db
1210 fi
1211 report step "Updating packages lists: $pkg_repository"
1212 packages_db_start
1214 # Look for removed/update packages.
1215 for PACKAGE in $(grep ^[0-9,a-z,A-Z] packages.txt); do
1216 pkg="$pkg_repository/$(grep -m1 ^$PACKAGE- packages.list).tazpkg"
1217 if ! [ -f "$pkg" ]; then
1218 erase_package_info
1219 else
1220 if [ "$pkg" -nt "packages.list" ]; then
1221 updated_pkg="$updated_pkg
1222 $PACKAGE $pkg"
1223 elif [ ! -f $WOK/$PACKAGE/receipt ] && \
1224 [ "$COMMAND" = check-incoming -o "$pkg_repository" = "$INCOMING_REPOSITORY" ]; then
1225 erase_package_info
1226 echo "Removing $PACKAGE from $pkg_repository."
1227 rm $pkg
1228 [ -d $WOK/$PACKAGE ] && rm -r $WOK/$PACKAGE
1229 sed "/^$PACKAGE\t/d" -i $wan_db $dep_db
1230 for i in cookorder.txt cooklist commit blocked broken; do
1231 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/$i
1232 done
1233 rm -f $LOCAL_REPOSITORY/log/$PACKAGE.html
1234 if [ "$pkg_repository" = "$INCOMING_REPOSITORY" ] && \
1235 [ "$(sed 1!d $PACKAGES_REPOSITORY/cookorder.txt)" != "#PlanSort" ] ; then
1236 sed 1i"#PlanSort" -i $PACKAGES_REPOSITORY/cookorder.txt
1237 regen_cooklist=yes
1238 else
1239 echo "$PACKAGE" >> $PACKAGES_REPOSITORY/removed
1240 sed -n '1,10p' -i $PACKAGES_REPOSITORY/removed
1241 fi
1242 fi
1243 fi
1244 done
1245 echo "$updated_pkg" | sed 1d | while read PACKAGE pkg; do
1246 erase_package_info
1247 get_packages_info
1248 done
1249 unset updated_pkg
1251 # Look for new packages.
1252 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1253 if ! fgrep -q " ${pkg##*/}" $pkg_repository/packages.md5; then
1254 get_packages_info
1255 fi
1256 done
1257 report end-step
1258 packages_db_end
1261 packages_db_start()
1263 if [ ! -s packages.txt ]; then
1264 echo "# SliTaz GNU/Linux - Packages list
1266 # Packages : unknow
1267 # Date : $(date +%Y-%m-%d\ \%H:%M:%S)
1269 " > packages.txt
1270 else
1271 sed -e 's/^# Packages :.*/# Packages : unknow/' \
1272 -e "s/# Date :.*/# Date : $(date +%Y-%m-%d\ \%H:%M:%S)/" \
1273 -i packages.txt
1274 fi
1276 # Needed in some case as tazwok define RECEIPT at configuration time
1277 # in this particular case it can broke the script.
1278 unset RECEIPT
1281 erase_package_info()
1283 cd $pkg_repository
1284 sed "/^$PACKAGE$/,/^$/d" -i packages.txt
1285 sed "/^$PACKAGE /d" -i packages.desc
1286 sed -e "s/=$PACKAGE /= /" -e "s/ $PACKAGE / /" -e "s/ $PACKAGE$//" \
1287 -e "/=$PACKAGE$/d" -e "s/=[0-9,a-z,A-Z]:$PACKAGE /= /" \
1288 -e "s/ [0-9,a-z,A-Z]:$PACKAGE / /" -e "s/ [0-9,a-z,A-Z]:$PACKAGE$/ /" \
1289 -e "/=[0-9,a-z,A-Z]:$PACKAGE$/d" \
1290 -i packages.equiv
1291 sed "/^$PACKAGE:/d" -i files.list
1292 sed "/^$(basename ${pkg%.tazpkg})$/d" -i packages.list
1293 sed "/ $(basename $pkg)$/d" -i packages.md5
1296 get_packages_info()
1298 # If there's no taz folder in the wok, extract infos from the
1299 # package.
1300 get_pkg_files $pkg
1301 source_receipt
1302 echo "Getting datas from $PACKAGE"
1304 cat >> $pkg_repository/packages.txt << _EOT_
1305 $PACKAGE
1306 $VERSION$EXTRAVERSION
1307 $SHORT_DESC
1308 _EOT_
1309 if [ "$PACKED_SIZE" ]; then
1310 cat >> $pkg_repository/packages.txt << _EOT_
1311 $PACKED_SIZE ($UNPACKED_SIZE installed)
1313 _EOT_
1314 else
1315 echo "" >> $pkg_repository/packages.txt
1316 fi
1318 # Packages.desc is used by Tazpkgbox <tree>.
1319 echo "$PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> $pkg_repository/packages.desc
1321 # Packages.equiv is used by tazpkg install to check depends
1322 for i in $PROVIDE; do
1323 DEST=""
1324 echo $i | fgrep -q : && DEST="${i#*:}:"
1325 if grep -qs ^${i%:*}= $pkg_repository/packages.equiv; then
1326 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" $pkg_repository/packages.equiv
1327 else
1328 echo "${i%:*}=$DEST$PACKAGE" >> $pkg_repository/packages.equiv
1329 fi
1330 done
1332 if [ -f files.list ]; then
1333 { echo "$PACKAGE"; cat files.list; } | awk '
1334 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }' >> $pkg_repository/files.list
1335 fi
1337 cd .. && rm -r "$pkg_files_dir"
1339 cd $pkg_repository
1340 echo $(basename ${pkg%.tazpkg}) >> packages.list
1341 [ ! "$package_md5" ] && package_md5=$(md5sum $(basename $pkg))
1342 echo "$package_md5" >> packages.md5
1343 unset package_md5
1346 source_receipt()
1348 unset PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
1349 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
1350 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
1351 src _pkg DESTDIR CONFIG_SITE BRANCH TARBALL stuff wanted_stuff
1352 . ${RECEIPT:-$PWD/receipt}
1355 packages_db_end()
1357 cd $pkg_repository
1358 pkgs=$(wc -l packages.list | sed 's/ .*//')
1359 sed "s/# Packages : .*/# Packages : $pkgs/" -i packages.txt
1361 # If lists was updated it's generally needed to sort them well.
1362 if ! sort -c packages.list 2> /dev/null; then
1363 report step "Sorting packages lists"
1364 for file in packages.list packages.desc packages.equiv; do
1365 [ -f $file ] || continue
1366 sort -o $file $file
1367 done
1368 report end-step
1369 fi
1371 # Dont log this because lzma always output error.
1372 lzma e files.list files.list.lzma
1373 rm -f files.list
1374 [ -f packages.equiv ] || touch packages.equiv
1377 ########################################################################
1378 # This section contains functions to generate wok database.
1379 ########################
1381 gen_wok_db()
1383 report step "Generating wok database"
1384 report open-bloc
1385 report step "Removing old files"
1386 for file in $wan_db $dep_db $PACKAGES_REPOSITORY/cookorder.txt; do
1387 [ -f $file ] && rm $file
1388 done
1389 report step "Generating wok-wanted.txt"
1390 gen_wan_db
1391 report step "Generating wok-depends.txt"
1392 for PACKAGE in $(cut -f1 -d '|' $PACKAGES_REPOSITORY/packages.desc \
1393 $INCOMING_REPOSITORY/packages.desc | sort -u); do
1394 RECEIPT=$WOK/$PACKAGE/receipt
1395 if [ -s $RECEIPT ]; then
1396 source_receipt
1397 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
1398 fi
1399 done
1400 sort_db
1401 report close-bloc
1404 gen_wan_db()
1406 for RECEIPT in $(fgrep -l WANTED $WOK/*/receipt); do
1407 WANTED=
1408 source $RECEIPT
1409 [ "$WANTED" ] || continue
1410 echo -e $PACKAGE"\t"$WANTED >> $tmp/wan_db
1411 done
1412 if ! [ -f $wan_db ] || [ "$(diff -q $tmp/wan_db $wan_db)" ]; then
1413 mv -f $tmp/wan_db $wan_db
1414 plan_regen_cookorder=yes
1415 else
1416 rm $tmp/wan_db
1417 fi
1420 update_wan_db()
1422 local PACKAGE=$PACKAGE
1423 for RECEIPT in $(fgrep WANTED $WOK/*/receipt | \
1424 fgrep $PACKAGE | cut -f1 -d ':'); do
1425 WANTED=
1426 source $RECEIPT
1427 [ "$WANTED" ] || continue
1428 wan_info=$(echo -e $PACKAGE"\t"$WANTED)
1429 [ "$wan_info" = "$(grep -m1 ^$PACKAGE$'\t' $wan_db 2>/dev/null)" ] && return
1430 sed "/^$PACKAGE\t/d" -i $wan_db
1431 echo "$wan_info" >> $wan_db
1432 plan_regen_cookorder=yes
1433 plan_sort_wandb=yes
1434 done
1437 update_dep_db()
1439 dep_info=$(echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ')
1440 [ "$dep_info" = "$(grep -m1 ^$PACKAGE$'\t' $dep_db 2>/dev/null)" ] && return
1441 sed "/^$PACKAGE\t/d" -i $dep_db
1442 echo "$dep_info" >> $dep_db
1443 plan_regen_cookorder=yes
1444 plan_sort_depdb=yes
1447 sort_db()
1449 report step "Generating cookorder.txt"
1450 cat $dep_db | sed 's/ \t / /' | while read PACKAGE BUILD_DEPENDS; do
1451 grep -q ^$PACKAGE$'\t' $wan_db && continue
1453 # Replace each BUILD_DEPENDS with a WANTED package by it's
1454 # WANTED package.
1455 replace_by_wanted()
1457 for p in $BUILD_DEPENDS; do
1458 if grep -q ^$p$'\t' $wan_db; then
1459 echo -n $(grep ^$p$'\t' $wan_db | cut -f 2)' '
1460 else
1461 echo -n $p' '
1462 fi
1463 done | tr ' ' '\n' | sort -u | sed "/^$PACKAGE$/d" | tr '\n' ' '
1465 echo -e $PACKAGE"\t $(replace_by_wanted) "
1466 done > $tmp/db
1467 while [ -s "$tmp/db" ]; do
1468 status=start
1469 for pkg in $(cut -f 1 $tmp/db); do
1470 if ! fgrep -q ' '$pkg' ' $tmp/db; then
1471 echo $pkg >> $tmp/cookorder
1472 sed -e "/^$pkg\t/d" -e "s/ $pkg / /g" -i $tmp/db
1473 status=proceed
1474 fi
1475 done
1476 if [ "$status" = start ]; then
1477 cp -f $tmp/db /tmp/remain-depends.txt
1478 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
1479 for blocked in $(cut -f 1 $tmp/db); do
1480 echo "$blocked" >> $PACKAGES_REPOSITORY/blocked
1481 done
1482 break
1483 fi
1484 done
1485 [ -s $tmp/cookorder ] || touch $tmp/cookorder
1487 # The toolchain packages are moved in first position.
1488 grep $(for pkg in `scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
1489 --look_for=all --with_args`; do echo " -e ^$pkg$"; done) \
1490 $tmp/cookorder | tac > $PACKAGES_REPOSITORY/cookorder.txt
1491 for pkg in $(cat $PACKAGES_REPOSITORY/cookorder.txt); do
1492 sed "/^$pkg$/d" -i $tmp/cookorder
1493 done
1495 tac $tmp/cookorder >> $PACKAGES_REPOSITORY/cookorder.txt
1496 unset plan_regen_cookorder
1497 report end-step
1500 ########################################################################
1501 # SCAN CORE
1502 ########################
1503 # Include various scan core-functions. It's not intended to be used
1504 # directly : prefer scan wrappers in next section.
1506 look_for_dep()
1508 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1509 grep -m1 ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
1510 | cut -f 2
1511 else
1512 grep -m1 ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-depends.txt | \
1513 cut -f 2
1514 fi
1517 look_for_bdep()
1519 look_for_all
1522 look_for_all()
1524 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1525 grep -m1 ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
1526 | cut -f 2,3 | sed 's/ / /'
1527 else
1528 grep -m1 ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-depends.txt | \
1529 cut -f 2,3 | sed 's/ / /'
1530 fi
1533 look_for_rdep()
1535 fgrep ' '$PACKAGE' ' $INCOMING_REPOSITORY/wok-depends.txt | cut -f 1
1536 if [ "$undigest" ]; then
1537 for rdep in $(fgrep ' '$PACKAGE' ' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt | cut -f 1); do
1538 if [ ! -f "WOK$/$rdep/receipt" ]; then
1539 echo "$rdep"
1540 fi
1541 done
1542 fi
1545 look_for_rbdep()
1547 fgrep ' '$PACKAGE' ' $INCOMING_REPOSITORY/wok-depends.txt | \
1548 cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1549 if [ "$undigest" ]; then
1550 for rdep in $(fgrep ' '$PACKAGE' ' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
1551 | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1); do
1552 if [ ! -f "WOK$/$rdep/receipt" ]; then
1553 echo "$rdep"
1554 fi
1555 done
1556 fi
1559 # Return WANTED if it exists.
1560 look_for_wanted()
1562 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1563 grep -m1 ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-wanted.txt | cut -f 2
1564 else
1565 grep -m1 ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-wanted.txt | cut -f 2
1566 fi
1569 # Return packages which wants PACKAGE.
1570 look_for_rwanted()
1572 grep $'\t'$PACKAGE$ $INCOMING_REPOSITORY/wok-wanted.txt | cut -f 1
1573 if [ "$undigest" ]; then
1574 for rwanted in $(grep $'\t'$PACKAGE$ $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-wanted.txt | cut -f 1); do
1575 if [ ! -f "$WOK/$rwanted/receipt" ]; then
1576 echo "$rwanted"
1577 fi
1578 done
1579 fi
1582 look_for_dev()
1584 WANTED=$(look_for_wanted)
1585 if [ "$WANTED" ]; then
1586 if [ "$undigest" ] && [ ! -f "$WOK/$WANTED/receipt" ]; then
1587 [ -f "$SLITAZ_DIR/$SLITAZ_VERSION/wok/$WANTED-dev/receipt" ] && echo $WANTED-dev
1588 else
1589 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1590 fi
1591 fi
1592 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1593 [ -f "$SLITAZ_DIR/$SLITAZ_VERSION/wok/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1594 else
1595 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1596 fi
1599 with_dev()
1601 for PACKAGE in $(cat); do
1602 echo $PACKAGE
1603 look_for_dev
1604 done
1607 with_wanted()
1609 for PACKAGE in $(cat); do
1610 echo $PACKAGE
1611 look_for_wanted
1612 done
1615 use_wanted()
1617 for input in $(cat); do
1618 { grep ^$input$'\t' $wan_db || echo $input
1619 } | sed 's/.*\t//'
1620 done
1623 ########################################################################
1624 # SCAN
1625 ########################
1626 # Use wok-wanted.txt and wok-depeds.txt to scan depends.
1627 # Option in command line (must be first arg) :
1628 # --look_for=bdep/rbdep - Look for depends or reverse depends.
1629 # --with_dev - Add development packages (*-dev) in the result.
1630 # --with_wanted - Add package+reverse wanted in the result.
1631 # --with_args - Include packages in argument in the result.
1633 scan()
1635 # Get packages in argument.
1636 local PACKAGE=$PACKAGE WANTED=$WANTED pkg_list=
1637 for arg in $@; do
1638 [ "$arg" = "${arg#--}" ] || continue
1639 pkg_list="$pkg_list $arg"
1640 done
1642 # Get options.
1643 [ "$pkg_list" ] || return
1644 local cooklist= look_for= with_dev= with_wanted= with_args= log_command="$0 $@" \
1645 get_options_list="look_for with_dev with_wanted with_args cooklist use_wanted"
1646 get_options
1648 # Cooklist is a special case where we need to modify a little
1649 # scan behavior
1650 if [ "$cooklist" ]; then
1651 gen_wan_db
1652 look_for=all && with_args=yes && with_dev= && with_wanted=
1653 filter=use_wanted
1654 if [ "$COMMAND" = gen-cooklist ]; then
1655 for PACKAGE in $pkg_list; do
1656 grep -q ^$PACKAGE$'\t' $dep_db && continue
1657 [ -d "$WOK/$p" ] || continue
1658 check_for_missing
1659 done
1660 append_to_dep()
1662 if ! grep -q ^$PACKAGE$'\t' $dep_db; then
1663 check_for_missing && echo $PACKAGE >> $tmp/dep
1664 else
1665 echo $PACKAGE >> $tmp/dep
1666 fi
1668 else
1669 append_to_dep()
1671 check_for_commit && echo $PACKAGE >> $tmp/dep
1673 fi
1674 else
1675 append_to_dep()
1677 echo $PACKAGE >> $tmp/dep
1679 # If requested packages are not in dep_db, partial generation of this db is needed.
1680 for PACKAGE in $pkg_list; do
1681 grep -q ^$PACKAGE$'\t' $dep_db && continue
1682 [ -d "$WOK/$p" ] || continue
1683 plan_check_for_missing=yes
1684 check_for_missing
1685 done
1686 if [ "$plan_check_for_missing" ]; then
1687 append_to_dep()
1689 if ! grep -q ^$PACKAGE$'\t' $dep_db; then
1690 check_for_missing && echo $PACKAGE >> $tmp/dep
1691 else
1692 echo $PACKAGE >> $tmp/dep
1693 fi
1695 check_db_status=yes
1696 unset plan_check_for_missing
1697 fi
1698 fi
1700 [ "$with_dev" ] && filter=with_dev
1701 [ "$with_wanted" ] && filter=with_wanted
1702 if [ "$filter" ]; then
1703 pkg_list=$(echo $pkg_list | $filter | sort -u)
1704 scan_pkg()
1706 look_for_$look_for | $filter
1708 else
1709 scan_pkg()
1711 look_for_$look_for
1713 fi
1714 touch $tmp/dep
1715 for PACKAGE in $pkg_list; do
1716 [ "$with_args" ] && append_to_dep
1717 scan_pkg
1718 done | tr ' ' '\n' | sort -u > $tmp/list
1719 [ "$look_for" = bdep ] && look_for=dep
1720 while [ -s $tmp/list ]; do
1721 PACKAGE=$(sed 1!d $tmp/list)
1722 sed 1d -i $tmp/list
1723 append_to_dep
1724 for pkg in $(scan_pkg); do
1725 if ! grep -q ^$pkg$ $tmp/list $tmp/dep; then
1726 echo $pkg >> $tmp/list
1727 fi
1728 done
1729 done
1730 if [ "$cooklist" ]; then
1731 mv $tmp/dep $tmp/cooklist
1732 else
1733 cat $tmp/dep | sort -u
1734 fi
1735 rm -f $tmp/dep $tmp/list
1736 if [ "$check_db_status" ]; then
1737 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
1738 [ "$plan_sort_wandb" ] && sort -o $wan_db $wan_db && unset plan_sort_wandb
1739 if [ "$plan_regen_cookorder" ] && \
1740 [ "$(sed 1!d $PACKAGES_REPOSITORY/cookorder.txt)" != "#PlanSort" ]; then
1741 grep -q "^#" $PACKAGES_REPOSITORY/cookorder.txt || \
1742 sed 1i"#PlanSort" -i $PACKAGES_REPOSITORY/cookorder.txt
1743 fi
1744 fi
1747 ########################################################################
1748 # This section contains functions to check package repository and
1749 # find which packages to cook.
1750 ########################
1752 check_for_missing()
1754 local PACKAGE=$PACKAGE
1755 if ! check_for_pkg_in_wok; then
1756 [ "$?" = 2 ] && return 1
1757 return
1758 fi
1759 RECEIPT=$WOK/$PACKAGE/receipt
1760 source_receipt
1761 PACKAGE=${WANTED:-$PACKAGE}
1762 update_wan_db
1763 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1764 RECEIPT=$WOK/$PACKAGE/receipt
1765 source_receipt
1766 update_dep_db
1767 done
1770 check_for_commit()
1772 if ! check_for_pkg_in_wok; then
1773 [ "$?" = 2 ] && return 1
1774 return
1775 fi
1776 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1777 RECEIPT=$WOK/$PACKAGE/receipt
1778 source_receipt
1780 # We use md5 of cooking stuff in the packaged receipt to check
1781 # commit. We look consecutively in 3 different locations :
1782 # - in the wok/PACKAGE/taz/* folder
1783 # - in the receipt in the package in incoming repository
1784 # - in the receipt in the package in packages repository
1785 # If md5sum match, there's no commit.
1786 check_for_commit_using_md5sum()
1788 if [ ! -f $WOK/$PACKAGE/md5 ]; then
1789 sed -n '/# md5sum of cooking stuff :/,$p' receipt | \
1790 sed -e 1d -e 's/^# //' > $WOK/$PACKAGE/md5
1791 cd $WOK/$PACKAGE
1792 fi
1794 if [ -s md5 ]; then
1795 if md5sum -cs md5; then
1797 # If md5sum check if ok, check for new/missing files in
1798 # cooking stuff.
1799 for file in $([ -f receipt ] && echo receipt; \
1800 [ -f description.txt ] && echo description.txt; \
1801 [ -d stuff ] && find stuff); do
1802 if ! fgrep -q " $file" md5; then
1803 set_commited
1804 fi
1805 done
1806 else
1807 set_commited
1808 fi
1809 else
1810 set_commited
1811 fi
1813 set_commited()
1815 ! grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/commit &&
1816 echo $PACKAGE >> $PACKAGES_REPOSITORY/commit
1817 gen_cookmd5
1818 update_dep_db
1820 taz_dir=$(echo $WOK/$PACKAGE/taz/$PACKAGE-* | fgrep -v '*')
1821 if [ -f $WOK/$PACKAGE/md5 ]; then
1822 cd $WOK/$PACKAGE
1823 check_for_commit_using_md5sum
1824 elif [ "$taz_dir" ]; then
1825 cd $taz_dir
1826 check_for_commit_using_md5sum
1827 else
1828 pkg=$(echo $INCOMING_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
1829 [ "$pkg" ] || pkg=$(echo $PACKAGES_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
1830 if [ "$pkg" ]; then
1831 get_pkg_files $pkg
1832 check_for_commit_using_md5sum
1833 rm -r $pkg_files_dir
1834 else
1835 set_commited
1836 fi
1837 fi
1838 [ "$forced" ] || echo $PACKAGE >> $tmp/checked
1839 done
1840 return
1843 gen_cook_list()
1845 report step "Scanning wok"
1846 if [ "$pkg" ]; then
1847 scan $pkg --cooklist
1848 else
1849 scan `cat $cooklist` --cooklist
1850 fi
1851 report end-step
1853 [ -s $tmp/checked ] || [ -s $tmp/cooklist ] || return
1855 # Core toolchain should not be cooked unless cook-toolchain is used.
1856 if ! [ -f /etc/config.site.tmptoolchain ] ; then
1857 for PACKAGE in $(scan gcc --look_for=all --with_args --with_wanted); do
1858 grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/blocked || \
1859 echo $PACKAGE >> $PACKAGES_REPOSITORY/blocked
1860 done
1861 fi
1863 if [ -s $PACKAGES_REPOSITORY/commit ] && [ "$COMMAND" != gen-cooklist ]; then
1864 cd $PACKAGES_REPOSITORY
1865 for PACKAGE in $(cat commit); do
1866 WANTED="$(look_for_wanted)"
1867 if [ "$WANTED" ]; then
1868 grep -q ^$WANTED$ broken cooklist blocked commit && continue
1869 fi
1870 grep -q ^$PACKAGE$ blocked cooklist && continue
1871 echo $PACKAGE >> cooklist
1872 done
1873 fi
1874 sort_cooklist
1877 sort_cooklist()
1879 if [ "$(sed 1!d $PACKAGES_REPOSITORY/cookorder.txt)" = "#PlanSort" ]; then
1880 sed 1d -i $PACKAGES_REPOSITORY/cookorder.txt
1881 plan_regen_cookorder=yes
1882 fi
1883 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
1884 [ "$plan_regen_cookorder" ] && sort_db
1885 report step "Generating cooklist"
1886 if [ -f "$tmp/checked" ]; then
1887 rm -f $tmp/cooklist
1888 cat $tmp/checked | while read PACKAGE; do
1889 grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/cooklist && \
1890 echo $PACKAGE >> $tmp/cooklist
1891 done
1892 elif ! [ "$COMMAND" = gen-cooklist ]; then
1893 cat $PACKAGES_REPOSITORY/blocked | while read PACKAGE; do
1894 sed "/^$PACKAGE/d" -i $tmp/cooklist
1895 done
1896 fi
1897 report end-step
1898 [ -s $tmp/cooklist ] || return
1900 report step "Sorting cooklist"
1901 for PACKAGE in $(cat $tmp/cooklist); do
1902 WANTED="$(look_for_wanted)"
1903 [ "$WANTED" ] || continue
1904 if grep -q ^$WANTED$ $PACKAGES_REPOSITORY/broken $tmp/cooklist; then
1905 sed "/^$PACKAGE$/d" -i $tmp/cooklist
1906 elif [ ! -d $WOK/$WANTED/install ]; then
1907 sed "/^$PACKAGE$/d" -i $tmp/cooklist
1908 echo $WANTED >> $tmp/cooklist
1909 fi
1910 done
1912 # Use cookorder.txt to sort cooklist.
1913 if [ -s $tmp/cooklist ]; then
1914 cat $PACKAGES_REPOSITORY/cookorder.txt | while read PACKAGE; do
1915 if grep -q ^$PACKAGE$ $tmp/cooklist; then
1916 sed "/^$PACKAGE$/d" -i $tmp/cooklist
1917 echo $PACKAGE >> $tmp/cooklist.tmp
1918 fi
1919 done
1921 # Remaining packages in cooklist are thoses without compile_rules.
1922 # They can be cooked first in any order.
1923 if [ -f $tmp/cooklist.tmp ]; then
1924 cat $tmp/cooklist.tmp >> $tmp/cooklist
1925 rm $tmp/cooklist.tmp
1926 fi
1928 cat $tmp/cooklist
1929 [ "$cooklist" = "$PACKAGES_REPOSITORY/cooklist" ] && \
1930 cat $tmp/cooklist > $cooklist
1931 fi
1933 report end-step
1936 look_for_missing_pkg()
1938 for pkg in $(cat $PACKAGES_REPOSITORY/$1); do
1939 grep -q ^$pkg$ $INCOMING_REPOSITORY/packages.txt \
1940 $PACKAGES_REPOSITORY/packages.txt || \
1941 continue
1942 echo $pkg
1943 done
1946 check_for_incoming()
1948 report step "Check that all packages were cooked fine"
1949 [ -s $INCOMING_REPOSITORY/packages.desc ] || {
1950 echo "No packages in $INCOMING_REPOSITORY."
1951 report end-step; return; }
1952 if [ -s $PACKAGES_REPOSITORY/broken ]; then
1953 missingpkg=$(look_for_missing_pkg broken)
1954 if [ "$missingpkg" ]; then
1955 echo "Don't move incoming packages to main repository because theses ones are broken:" >&2
1956 echo "$missingpkg"
1957 report end-step
1958 return 1
1959 fi
1960 fi
1961 if [ -s $PACKAGES_REPOSITORY/cooklist ]; then
1962 missingpkg=$(look_for_missing_pkg cooklist)
1963 if [ "$missingpkg" ]; then
1964 echo "Don't move incoming packages to main repository because theses ones needs to be cooked:" >&2
1965 echo "$missingpkg"
1966 report end-step
1967 return 1
1968 fi
1969 fi
1970 incoming_pkgs="$(cut -f 1 -d '|' $INCOMING_REPOSITORY/packages.desc)"
1971 if ! [ "$forced" ]; then
1972 cooklist=$PACKAGES_REPOSITORY/cooklist
1973 pkg="$incoming_pkgs"
1974 gen_cook_list
1975 if [ -s $PACKAGES_REPOSITORY/cooklist ]; then
1976 missingpkg=$(look_for_missing_pkg cooklist)
1977 if [ "$missingpkg" ]; then
1978 echo "Don't move incoming packages to main repository because theses ones needs to be cooked:" >&2
1979 echo "$missingpkg"
1980 report end-step
1981 return 1
1982 fi
1983 fi
1984 fi
1986 report step "Moving incoming packages to main repository"
1987 unset EXTRAVERSION
1988 for PACKAGE in $incoming_pkgs; do
1989 prev_VERSION=$(get_pkg_version $PACKAGES_REPOSITORY)
1990 VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
1991 remove_previous_package $PACKAGES_REPOSITORY
1992 echo "Moving $PACKAGE..."
1993 mv -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION.tazpkg $PACKAGES_REPOSITORY
1994 touch $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
1995 previous_tarball=$(grep ^$PACKAGE:main $SOURCES_REPOSITORY/sources.list | cut -f2)
1996 sed -e "/^$PACKAGE:main/d" \
1997 -e "s/^$PACKAGE:incoming/$PACKAGE:main/" \
1998 -i $SOURCES_REPOSITORY/sources.list
1999 if [ "$previous_tarball" ]; then
2000 grep -q $'\t'$previous_tarball$ $SOURCES_REPOSITORY/sources.list || \
2001 rm -f $SOURCES_REPOSITORY/$previous_tarball
2002 fi
2003 done
2004 for file in packages.list packages.equiv packages.md5 packages.desc \
2005 packages.txt; do
2006 echo -n "" > $INCOMING_REPOSITORY/$file
2007 done
2008 rm -r $INCOMING_REPOSITORY/files.list.lzma
2009 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2011 report step "Updating flavors"
2012 if [ -x /usr/bin/tazlito ] || [ -x /usr/bin/clean-chroot ]; then
2013 if ! [ -x /usr/bin/tazlito ]; then
2014 tazpkg get-install tazlito
2015 fi
2017 # Handle cases where tazwok is used into main system;
2018 # Handle cases where SLITAZ_DIR is not /home/slitaz.
2019 [ -L /home/slitaz/flavors ] && rm /home/slitaz/flavors
2020 mkdir -p /home/slitaz
2021 ln -s $LOCAL_REPOSITORY/flavors /home/slitaz/flavors
2023 cd $LOCAL_REPOSITORY/packages
2024 for i in $LOCAL_REPOSITORY/flavors/*; do
2025 [ -d "$i" ] || continue
2026 tazlito pack-flavor ${i##*/}
2027 done
2029 noheader=""
2030 for i in *.flavor; do
2031 tazlito show-flavor $i --brief $noheader
2032 noheader="--noheader"
2033 done > flavors.list
2034 [ -x /usr/bin/clean-chroot ] && clean-chroot
2035 else
2036 echo "Can't create up-to-date flavors because tazlito package is missing." >&2
2037 fi
2038 report end-step
2041 ########################################################################
2042 # TAZWOK MAIN FUNCTIONS
2043 ########################
2045 clean()
2047 cd $WOK/$PACKAGE
2048 ls -A $WOK/$PACKAGE | grep -q -v -e ^receipt$ -e ^description.txt$ \
2049 -e ^stuff$ || return
2051 [ "$COMMAND" = clean-wok ] || report step "Cleaning $PACKAGE"
2052 # Check for clean_wok function.
2053 if grep -q ^clean_wok $RECEIPT; then
2054 clean_wok
2055 fi
2056 # Clean should only have a receipt, stuff and optional desc.
2057 for f in `ls .`
2058 do
2059 case $f in
2060 receipt|stuff|description.txt|md5)
2061 continue ;;
2062 *)
2063 rm -rf $f ;;
2064 esac
2065 done
2066 [ "$COMMAND" != clean-wok ] && report end-step
2069 # Configure and make a package with the receipt.
2070 compile_package()
2072 check_for_package_on_cmdline
2074 # Include the receipt to get all needed variables and functions
2075 # and cd into the work directory to start the work.
2076 check_for_receipt
2077 source_receipt
2079 # Log the package name and date.
2080 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
2081 echo "package $PACKAGE (compile)" >> $LOG
2083 # Set wanted $src variable to help compiling.
2084 [ ! "$src" ] && set_src_path
2085 check_for_build_depends || return 1
2086 check_for_wanted
2087 unset target
2088 check_for_tarball && check_for_compile_rules
2091 # Cook command also include all features to manage lists which keep
2092 # track of wok/packages state.
2093 cook()
2095 cook_code=
2096 set_common_path
2097 check_for_receipt
2098 source_receipt
2100 # Define log path and start report.
2101 [ -f $LOCAL_REPOSITORY/log/$PACKAGE.html ] && rm $LOCAL_REPOSITORY/log/$PACKAGE.html
2102 report sublog $LOCAL_REPOSITORY/log/$PACKAGE.html
2103 echo "$PACKAGE" > $LOCAL_REPOSITORY/log/package
2104 report step "Cooking $PACKAGE"
2105 report open-bloc
2107 clean $PACKAGE
2108 [ -s $tmp/cooklist ] && sed "/^$PACKAGE$/d" -i $tmp/cooklist
2110 if compile_package; then
2111 remove_src
2112 refresh_packages_from_compile
2113 gen_package
2115 # Update packages-incoming repository.
2116 store_pkgname=$PACKAGE
2117 pkg_repository=$INCOMING_REPOSITORY
2118 update_packages_db
2120 PACKAGE=$store_pkgname
2121 unset store_pkgname
2123 # Upgrade to cooked packages if it was previously installed.
2124 report step "Look for package(s) to upgrade"
2125 for pkg in $(look_for_rwanted) $PACKAGE; do
2126 if [ -d $INSTALLED/$pkg ]; then
2127 tazpkg get-install $pkg --forced
2128 fi
2129 done
2130 report end-step
2131 else
2132 set_pkg_broken
2133 cook_code=1
2134 fi
2136 # Remove build_depends in cook mode (if in cooklist, it's done when
2137 # checking build_depends of next package and we remove only unneeded
2138 # packages to keep chroot minimal and gain some time).
2139 if [ "$COMMAND" = cook ]; then
2140 remove_build_depends $MISSING_PACKAGE
2141 [ -x /usr/bin/clean-chroot ] && clean-chroot
2142 fi
2144 # Regen the cooklist if it was planned and command is not cook.
2145 [ "$regen_cooklist" ] && unset regen_cooklist && \
2146 [ "$COMMAND" != cook ] && sort_cooklist
2148 # Some hacks to set the bloc & function status as failed if cook was
2149 # failed.
2150 report_return_code=$cook_code
2151 report close-bloc
2152 report end-sublog
2153 rm -f $LOCAL_REPOSITORY/log/package
2154 return $cook_code
2157 cook_list()
2159 if [ -s $tmp/cooklist ]; then
2160 if [ -f /usr/bin/tazchroot ]; then
2161 # Note : options -main variables- are automatically keeped by
2162 # the sub-applications tazchroot/tazwok; as well as report data.
2163 cd $LOCAL_REPOSITORY
2164 [ ! -f tazchroot.conf ] && configure_tazchroot
2165 tazchroot tazwok cook-list --SLITAZ_DIR=$SLITAZ_DIR --SLITAZ_VERSION=$SLITAZ_VERSION ${undigest:+ --undigest=$undigest}
2166 return
2167 fi
2168 while [ -s $tmp/cooklist ]; do
2169 PACKAGE=$(sed 1!d $tmp/cooklist)
2170 cook
2171 done
2172 remove_build_depends $MISSING_PACKAGE $remove_later
2173 [ -x /usr/bin/clean-chroot ] && clean-chroot
2174 else
2175 echo "Nothing to cook."
2176 return
2177 fi
2180 configure_tazchroot()
2182 cat > $LOCAL_REPOSITORY/tazchroot.conf << EOF
2183 # Tazchroot configuration file - created by tazwok.
2185 # Default chroot path
2186 SLITAZ_DIR=$SLITAZ_DIR
2187 SLITAZ_VERSION=$SLITAZ_VERSION
2188 $( [ "$undigest" ] && echo "undigest=$undigest" )
2189 LOCAL_REPOSITORY=$SLITAZ_DIR/$(if [ "$undigest" ]; then echo '$undigest'; else echo '$SLITAZ_VERSION'; fi)
2190 chroot_dir=\$LOCAL_REPOSITORY/chroot
2192 # Default scripts path (theses scripts are added in the
2193 # $chroot_dir/usr/bin and can be called with tazchroot script)
2194 script_dir=/usr/lib/slitaz/chroot-scripts/tazwok
2196 # List of directories to mount.
2197 list_dir="$(for dir in packages wok src packages-incoming log flavors iso clean-wok; do echo $LOCAL_REPOSITORY/$dir; done)
2198 $SLITAZ_LOG$( [ "$undigest" ] && echo -e "\n$SLITAZ_DIR/$SLITAZ_VERSION/packages" )"
2200 create_chroot()
2202 mkdir -p \$chroot_dir
2203 for pkg in \$(tazwok build-depends toolchain --SLITAZ_DIR=\$SLITAZ_DIR --SLITAZ_VERSION=\$SLITAZ_VERSION${undigest:+ --undigest=\$undigest}); do
2204 tazpkg get-install \$pkg --root="\$chroot_dir"
2205 done
2207 # Store list of installed packages needed by cleanchroot.
2208 ls -1 \$chroot_dir/\$INSTALLED > \$chroot_dir/\$LOCALSTATE/chroot-pkgs
2210 sed -e "s~^SLITAZ_DIR=.*~SLITAZ_DIR=\$SLITAZ_DIR~" \\
2211 -e "s/^SLITAZ_VERSION=.*/SLITAZ_VERSION=\$SLITAZ_VERSION/" \\
2212 -i \$chroot_dir/etc/slitaz/slitaz.conf
2213 $( [ "$undigest" ] && echo ' echo "undigest='"$undigest"'" >> $chroot_dir/etc/slitaz/tazwok.conf')
2214 sed 's/LC_ALL/LC_ALL=POSIX/' -i \$chroot_dir/etc/profile
2215 # The build bot may run in a sandbox: link sandbox lockfile
2216 ln -s \$LOCAL_REPOSITORY/sandbox/proc/1 \$chroot_dir/proc/1
2219 mount_chroot()
2221 cp -a /etc/resolv.conf \$chroot_dir/etc/resolv.conf
2222 echo "\$LOCAL_REPOSITORY/packages" > \$chroot_dir\$LOCALSTATE/mirror
2223 mkdir -p \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming
2224 echo "\$LOCAL_REPOSITORY/packages-incoming" > \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming/mirror
2225 $( [ "$undigest" ] && echo ' mkdir -p $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION
2226 echo "$SLITAZ_DIR/$SLITAZ_VERSION/packages" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror' )
2227 echo -e "\${LOCAL_REPOSITORY##*/}-incoming\nmain" > \$chroot_dir\$LOCALSTATE/priority
2228 mount -t proc proc \$chroot_dir/proc
2229 mount -t sysfs sysfs \$chroot_dir/sys
2230 mount -t devpts devpts \$chroot_dir/dev/pts
2231 mount -t tmpfs shm \$chroot_dir/dev/shm
2232 for dir in \$list_dir; do
2233 mkdir -p \$dir \$chroot_dir\$dir
2234 mount \$dir \$chroot_dir\$dir
2235 done
2238 umount_chroot()
2240 for dir in \$list_dir; do
2241 umount \$chroot_dir\$dir
2242 done
2243 umount \$chroot_dir/dev/shm
2244 umount \$chroot_dir/dev/pts
2245 umount \$chroot_dir/sys
2246 umount \$chroot_dir/proc
2248 EOF
2251 ########################################################################
2252 ######################### END OF NEW FUNCTIONS #########################
2253 ########################################################################
2255 # List packages providing a virtual package
2256 whoprovide()
2258 local i;
2259 for i in $(fgrep -l PROVIDE $WOK/*/receipt); do
2260 . $i
2261 case " $PROVIDE " in
2262 *\ $1\ *|*\ $1:*) echo $(basename $(dirname $i));;
2263 esac
2264 done
2267 ########################################################################
2268 # TAZWOK COMMANDS
2269 ########################
2271 case "$COMMAND" in
2272 stats)
2273 # Tazwok general statistics from the wok config file.
2275 get_tazwok_config
2276 echo -e "\n\033[1mTazwok configuration statistics\033[0m
2277 ================================================================================
2278 Wok directory : $WOK
2279 Packages repository : $PACKAGES_REPOSITORY
2280 Incoming repository : $INCOMING_REPOSITORY
2281 Sources repository : $SOURCES_REPOSITORY
2282 Log directory : $LOCAL_REPOSITORY/log
2283 Packages in the wok : `ls -1 $WOK | wc -l`
2284 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2285 Incoming packages : `ls -1 $INCOMING_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2286 ================================================================================\n"
2287 ;;
2288 edit)
2289 get_tazwok_config
2290 check_for_package_on_cmdline
2291 check_for_receipt
2292 $EDITOR $WOK/$PACKAGE/receipt
2293 ;;
2294 build-depends)
2295 # List dependencies to rebuild wok, or only a package
2296 get_tazwok_config
2297 report(){ : ; }
2298 if [ ! "$PACKAGE" ] || [ "$PACKAGE" = toolchain ]; then
2299 scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
2300 --look_for=dep --with_dev --with_args
2301 else
2302 check_for_package_on_cmdline
2303 scan $PACKAGE --look_for=bdep --with_dev
2304 fi
2305 ;;
2306 gen-cooklist)
2307 check_root
2308 get_options_list="pkg"
2309 get_tazwok_config
2310 report(){ : ; }
2311 if ! [ "$pkg" ]; then
2312 if [ ! "$LIST" ] || [ "$LIST" = toolchain ]; then
2313 pkg="$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA"
2314 else
2315 cooklist=${LIST:-$PACKAGES_REPOSITORY/cooklist}
2316 fi
2317 fi
2318 gen_cook_list
2319 ;;
2320 check-depends)
2321 # Check package depends /!\
2322 get_tazwok_config
2323 echo ""
2324 echo -e "\033[1mCheck every receipt for DEPENDS - doesn't scan ELF files\033[0m
2325 ================================================================================"
2326 TMPDIR=/tmp/tazwok$$
2327 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
2329 # Build ALL_DEPENDS variable
2330 scan_dep()
2332 local i
2333 ALL_DEPENDS="$ALL_DEPENDS$PACKAGE "
2334 for i in $DEPENDS $SUGGESTED ; do
2335 case " $ALL_DEPENDS " in
2336 *\ $i\ *) continue;;
2337 esac
2338 [ -d $WOK/$i ] || {
2339 ALL_DEPENDS="$ALL_DEPENDS$i "
2340 continue
2342 DEPENDS=""
2343 SUGGESTED=""
2344 . $WOK/$i/receipt
2345 scan_dep
2346 done
2349 # Check for ELF file
2350 is_elf()
2352 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
2355 # Print shared library dependencies
2356 ldd()
2358 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
2361 mkdir $TMPDIR
2362 cd $TMPDIR
2363 for i in $LOCALSTATE/files.list.lzma \
2364 $LOCALSTATE/undigest/*/files.list.lzma ; do
2365 [ -f $i ] && lzma d $i -so >> files.list
2366 done
2367 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
2368 tazpkg extract $pkg > /dev/null 2>&1
2369 . */receipt
2370 ALL_DEPENDS="$DEFAULT_DEPENDS "
2371 scan_dep
2372 find */fs -type f | while read file ; do
2373 is_elf $file || continue
2374 case "$file" in
2375 *.o|*.ko|*.ko.gz) continue;;
2376 esac
2377 ldd $file | while read lib rem; do
2378 case "$lib" in
2379 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
2380 continue;;
2381 esac
2382 for dep in $(fgrep $lib files.list | cut -d: -f1); do
2383 case " $ALL_DEPENDS " in
2384 *\ $dep\ *) continue 2;;
2385 esac
2386 for vdep in $(fgrep $dep $LOCALSTATE/packages.equiv | cut -d= -f1); do
2387 case " $ALL_DEPENDS " in
2388 *\ $vdep\ *) continue 3;;
2389 esac
2390 done
2391 done
2392 [ -n "$dep" ] || dep="UNKNOWN"
2393 echo "$(basename $pkg): ${file#*fs} depends on package $dep for the shared library $lib"
2394 done
2395 done
2396 rm -rf */
2397 done
2398 cd /tmp
2399 rm -rf $TMPDIR
2400 ;;
2401 check)
2402 # Check wok consistency
2403 get_tazwok_config
2404 echo ""
2405 echo -e "\033[1mWok and packages checking\033[0m
2406 ================================================================================"
2407 cd $WOK
2408 for pkg in $(ls)
2409 do
2410 [ -f $pkg/receipt ] || continue
2411 RECEIPT= $pkg/receipt
2412 source_receipt
2413 [ "$PACKAGE" = "$pkg" ] || echo "Package $PACKAGE should be $pkg" >&2
2414 [ -n "$VERSION" ] || echo "Package $PACKAGE has no VERSION" >&2
2415 [ -n "$PACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded PACKED_SIZE" >&2
2416 [ -n "$UNPACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded UNPACKED_SIZE" >&2
2417 [ -n "$EXTRAVERSION" ] && echo "Package $PACKAGE has hardcoded EXTRAVERSION" >&2
2418 if [ -n "$WANTED" ]; then
2419 if [ ! -f $WANTED/receipt ]; then
2420 echo "Package $PACKAGE wants unknown $WANTED package" >&2
2421 else
2422 BASEVERSION=$(. $WANTED/receipt ; echo $VERSION)
2423 if [ "$VERSION" = "$WANTED" ]; then
2424 # BASEVERSION is computed in receipt
2425 fgrep -q '_pkg=' $pkg/receipt &&
2426 BASEVERSION=$VERSION
2427 fi
2428 if [ "$VERSION" != "$BASEVERSION" ]; then
2429 echo "Package $PACKAGE ($VERSION) wants $WANTED ($BASEVERSION)" >&2
2430 fi
2431 fi
2432 fi
2434 if [ -n "$CATEGORY" ]; then
2435 case " $(echo $CATEGORIES) " in
2436 *\ $CATEGORY\ *);;
2437 *) echo "Package $PACKAGE has an invalid CATEGORY" >&2;;
2438 esac
2439 else
2440 echo"Package $PACKAGE has no CATEGORY" >&2
2441 fi
2442 [ -n "$SHORT_DESC" ] || echo "Package $PACKAGE has no SHORT_DESC" >&2
2443 [ -n "$MAINTAINER" ] || echo "Package $PACKAGE has no MAINTAINER" >&2
2444 case "$WGET_URL" in
2445 ftp*|http*) busybox wget -s $WGET_URL 2> /dev/null ||
2446 echo "Package $PACKAGE has a wrong WGET_URL" >&2;;
2447 '') ;;
2448 *) echo "Package $PACKAGE has an invalid WGET_URL" >&2;;
2449 esac
2450 case "$WEB_SITE" in
2451 ftp*|http*);;
2452 '') echo "Package $PACKAGE has no WEB_SITE" >&2;;
2453 *) echo "Package $PACKAGE has an invalid WEB_SITE" >&2;;
2454 esac
2455 case "$MAINTAINER" in
2456 *\<*|*\>*) echo "Package $PACKAGE has an invalid MAINTAINER: $MAINTAINER" >&2;;
2457 esac
2458 case "$MAINTAINER" in
2459 *@*);;
2460 *) echo "Package $PACKAGE MAINTAINER is not an email address" >&2;;
2461 esac
2462 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2463 for i in $DEPENDS; do
2464 [ -d $i ] && continue
2465 [ -n "$(whoprovide $i)" ] && continue
2466 echo -e "$MSG $i"
2467 MSG=""
2468 done
2469 MSG="Missing build dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2470 for i in $BUILD_DEPENDS; do
2471 [ -d $i ] && continue
2472 [ -n "$(whoprovide $i)" ] && continue
2473 echo -e "$MSG $i"
2474 MSG=""
2475 done
2476 MSG="Dependencies loop between $PACKAGE and :\n"
2477 ALL_DEPS=""
2478 check_for_deps_loop $PACKAGE $DEPENDS
2479 [ -d $WOK/$pkg/taz ] && for i in $BUILD_DEPENDS; do
2480 [ $WOK/$pkg/taz -nt $INSTALLED/$i/files.list ] && continue
2481 echo "$pkg should be rebuilt after $i installation"
2482 done
2483 done
2484 ;;
2485 list)
2486 # List packages in wok directory. User can specify a category.
2488 get_tazwok_config
2489 if [ "$2" = "category" ]; then
2490 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
2491 exit 0
2492 fi
2493 # Check for an asked category.
2494 if [ -n "$2" ]; then
2495 ASKED_CATEGORY=$2
2496 echo ""
2497 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
2498 echo "================================================================================"
2499 for pkg in $WOK/*
2500 do
2501 [ ! -f $pkg/receipt ] && continue
2502 . $pkg/receipt
2503 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
2504 echo -n "$PACKAGE"
2505 echo -e "\033[28G $VERSION"
2506 packages=$(($packages+1))
2507 fi
2508 done
2509 echo "================================================================================"
2510 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
2511 else
2512 # By default list all packages and version.
2513 echo ""
2514 echo -e "\033[1mList of packages in the wok\033[0m"
2515 echo "================================================================================"
2516 for pkg in $WOK/*
2517 do
2518 [ ! -f $pkg/receipt ] && continue
2519 . $pkg/receipt
2520 echo -n "$PACKAGE"
2521 echo -en "\033[28G $VERSION"
2522 echo -e "\033[42G $CATEGORY"
2523 packages=$(($packages+1))
2524 done
2525 echo "================================================================================"
2526 echo -e "$packages packages available in the wok.\n"
2527 fi
2528 ;;
2529 info)
2530 # Information about a package.
2532 get_tazwok_config
2533 check_for_package_on_cmdline
2534 check_for_receipt
2535 . $WOK/$PACKAGE/receipt
2536 echo ""
2537 echo -e "\033[1mTazwok package information\033[0m
2538 ================================================================================
2539 Package : $PACKAGE
2540 Version : $VERSION
2541 Category : $CATEGORY
2542 Short desc : $SHORT_DESC
2543 Maintainer : $MAINTAINER"
2544 if [ ! "$WEB_SITE" = "" ]; then
2545 echo "Web site : $WEB_SITE"
2546 fi
2547 if [ ! "$DEPENDS" = "" ]; then
2548 echo "Depends : $DEPENDS"
2549 fi
2550 if [ ! "$WANTED" = "" ]; then
2551 echo "Wanted src : $WANTED"
2552 fi
2553 echo "================================================================================"
2554 echo ""
2555 ;;
2556 check-log)
2557 # We just cat the file log to view process info.
2559 get_tazwok_config
2560 if [ ! -f "$LOG" ]; then
2561 echo -e "\nNo process log found. The package is probably not cooked.\n" >&2
2562 exit 1
2563 else
2564 echo ""
2565 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
2566 echo "================================================================================"
2567 cat $LOG
2568 echo "================================================================================"
2569 echo ""
2570 if [ -s "$WOK/$PACKAGE/warning.txt" ]; then
2571 echo -e "\033[1mCook warning(s) for :\033[0m $PACKAGE"
2572 echo "================================================================================"
2573 cat "$WOK/$PACKAGE/warning.txt"
2574 echo "================================================================================"
2575 echo ""
2576 fi
2577 fi
2578 ;;
2579 search)
2580 # Search for a package by pattern or name.
2582 get_tazwok_config
2583 if [ -z "$2" ]; then
2584 echo -e "\nPlease specify a pattern or a package name to search." >&2
2585 echo -e "Example : 'tazwok search gcc'.\n" >&2
2586 exit 1
2587 fi
2588 echo ""
2589 echo -e "\033[1mSearch result for :\033[0m $2"
2590 echo "================================================================================"
2591 list=`ls -1 $WOK | fgrep $2`
2592 for pkg in $list
2593 do
2594 . $WOK/$pkg/receipt
2595 echo -n "$PACKAGE "
2596 echo -en "\033[24G $VERSION"
2597 echo -e "\033[42G $CATEGORY"
2598 packages=$(($PACKAGEs+1))
2599 done
2600 echo "================================================================================"
2601 echo "$packages packages found for : $2"
2602 echo ""
2603 ;;
2604 compile)
2605 # Configure and make a package with the receipt.
2607 get_tazwok_config
2608 source_lib report
2609 report start
2610 compile_package
2611 ;;
2612 genpkg)
2613 # Generate a package.
2615 get_tazwok_config
2616 source_lib report
2617 report start
2618 gen_package
2619 ;;
2620 cook)
2621 # Compile and generate a package. Just execute tazwok with
2622 # the good commands.
2624 check_root
2625 get_tazwok_config
2626 source_lib report
2627 report start
2628 update_wan_db
2629 check_for_commit
2630 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
2631 [ "$plan_sort_wandb" ] && sort -o $wan_db $wan_db && unset plan_sort_wandb
2632 if [ "$plan_regen_cookorder" ]; then
2633 [ "$(sed 1!d $PACKAGES_REPOSITORY/cookorder.txt)" = "#PlanSort" ] || \
2634 sed 1i"#PlanSort" -i $PACKAGES_REPOSITORY/cookorder.txt
2635 fi
2636 cook
2637 ;;
2638 sort-cooklist)
2639 if [ ! -f "$LIST" ]; then
2640 echo "Usage : tazwok sort-cooklist cooklist" >&2
2641 exit 1
2642 fi
2643 check_root
2644 get_tazwok_config
2645 report(){ : ; }
2646 # When using sort-cooklist, the script should behave as for gen-cooklist
2647 # The only difference between theses two is where the output is sended.
2648 COMMAND=gen-cooklist
2649 cooklist=$LIST
2650 gen_cook_list
2651 cp -af $tmp/cooklist $cooklist
2652 ;;
2653 cook-list)
2654 # Cook all packages listed in a file or in default cooklist.
2655 check_root
2656 get_options_list="pkg forced"
2657 get_tazwok_config
2658 source_lib report
2659 report start
2660 if ! [ "$pkg" ]; then
2661 cooklist=${LIST:-$PACKAGES_REPOSITORY/cooklist}
2662 fi
2663 gen_cook_list
2664 cook_list
2665 ;;
2666 clean)
2667 # Clean up a package work directory + thoses which want it.
2669 get_tazwok_config
2670 check_for_package_on_cmdline
2671 check_for_receipt
2672 source_lib report
2673 report start
2674 . $RECEIPT
2675 clean
2676 ;;
2677 gen-clean-wok)
2678 # Generate a clean wok from the current wok by copying all receipts
2679 # and stuff directory.
2681 get_tazwok_config
2682 source_lib report
2683 report start
2684 if [ -z "$ARG" ]; then
2685 echo -e "\nPlease specify the destination for the new clean wok.\n" >&2
2686 exit 1
2687 else
2688 dest=$ARG
2689 mkdir -p $dest
2690 fi
2691 report step "Creating clean wok in : $dest"
2692 for pkg in `ls -1 $WOK`
2693 do
2694 mkdir -p $dest/$pkg
2695 cp -a $WOK/$pkg/receipt $dest/$pkg
2696 [ -f $WOK/$pkg/description.txt ] && \
2697 cp -a $WOK/$pkg/description.txt $dest/$pkg
2698 if [ -d "$WOK/$pkg/stuff" ]; then
2699 cp -a $WOK/$pkg/stuff $dest/$pkg
2700 fi
2701 done
2702 [ -d $WOK/.hg ] && cp -a $WOK/.hg $dest
2703 report end-step
2704 echo "Packages cleaned : `ls -1 $dest | wc -l`"
2705 echo ""
2706 ;;
2707 clean-wok)
2708 # Clean all packages in the work directory
2710 get_tazwok_config
2711 source_lib report
2712 report start
2713 report step "Cleaning wok"
2714 for PACKAGE in `ls -1 $WOK`
2715 do
2716 set_common_path
2717 source_receipt
2718 clean
2719 done
2720 echo "`ls -1 $WOK | wc -l` packages cleaned."
2721 ;;
2722 clean-src)
2723 # Remove tarball unrelated to wok receipts from src repo.
2724 check_root
2725 get_options_list="forced"
2726 get_tazwok_config
2727 cd $SOURCES_REPOSITORY
2728 echo -n "Checking $SOURCES_REPOSITORY..."
2729 for TARBALL in *; do
2730 [ "$TARBALL" = sources.list ] && continue
2731 grep -q $'\t'$TARBALL$ $SOURCES_REPOSITORY/sources.list || \
2732 echo $TARBALL >> $tmp/obsolete
2733 done
2734 status
2735 if ! [ -f $tmp/obsolete ]; then
2736 echo "No sources need to be removed."
2737 exit 1
2738 fi
2739 echo ""
2740 echo -e "\033[1mObsolete/unrelated-to-wok sourcess :\033[0m"
2741 horizontal_line
2742 cat $tmp/obsolete
2743 horizontal_line
2744 echo "$(wc -l $tmp/obsolete | cut -f1 -d' ') tarballs to remove."
2745 echo ""
2746 echo -n "Please confirm removing (type uppercase YES): "
2747 read answer
2748 if [ "$answer" = YES ]; then
2749 echo -n "Removing old sources..."
2750 cat $tmp/obsolete | while read i; do
2751 rm -f $SOURCES_REPOSITORY/$i
2752 done
2753 status
2754 fi
2755 ;;
2756 gen-list)
2757 get_tazwok_config
2758 if [ "$2" ]; then
2759 if [ -d "$2" ]; then
2760 pkg_repository=$2
2761 else
2762 echo -e "\nUnable to find directory : $2\n" >&2
2763 exit 1
2764 fi
2765 fi
2767 source_lib report
2768 report start
2769 if [ "$pkg_repository" ]; then
2770 gen_packages_db
2771 else
2772 pkg_repository=$PACKAGES_REPOSITORY && gen_packages_db
2773 pkg_repository=$INCOMING_REPOSITORY && gen_packages_db
2774 fi
2775 ;;
2776 check-list)
2777 # The directory to move into by default is the repository,
2778 # if $2 is not empty cd into $2.
2780 get_tazwok_config
2781 if [ "$2" ]; then
2782 if [ -d "$2" ]; then
2783 pkg_repository=$2
2784 else
2785 echo -e "\nUnable to find directory : $2\n" >&2
2786 exit 1
2787 fi
2788 fi
2790 source_lib report
2791 report start
2792 if [ "$pkg_repository" ]; then
2793 update_packages_db
2794 else
2795 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2796 pkg_repository=$INCOMING_REPOSITORY && update_packages_db
2797 fi
2798 ;;
2799 new-tree)
2800 # Just create a few directories and generate an empty receipt to prepare
2801 # the creation of a new package.
2803 get_tazwok_config
2804 check_for_package_on_cmdline
2805 clean_wok=$LOCAL_REPOSITORY/clean-wok
2806 if [ -d $clean_wok/$PACKAGE ]; then
2807 echo -e "\n$PACKAGE package tree already exists.\n" >&2
2808 exit 1
2809 fi
2810 echo "Creating : $WOK/$PACKAGE"
2811 mkdir $clean_wok/$PACKAGE
2812 cd $clean_wok/$PACKAGE
2813 echo -n "Preparing the receipt..."
2815 # Default receipt begin.
2817 echo "# SliTaz package receipt." > receipt
2818 echo "" >> receipt
2819 echo "PACKAGE=\"$PACKAGE\"" >> receipt
2820 # Finish the empty receipt.
2821 cat >> receipt << "EOF"
2822 VERSION=""
2823 CATEGORY=""
2824 SHORT_DESC=""
2825 MAINTAINER=""
2826 DEPENDS=""
2827 TARBALL="$PACKAGE-$VERSION.tar.gz"
2828 WEB_SITE=""
2829 WGET_URL=""
2831 # Rules to configure and make the package.
2832 compile_rules()
2834 cd $src
2835 ./configure && make && make install
2838 # Rules to gen a SliTaz package suitable for Tazpkg.
2839 genpkg_rules()
2841 mkdir -p $fs/usr
2842 cp -a $_pkg/usr/bin $fs/usr
2845 EOF
2847 # Default receipt end.
2849 status
2850 # Interactive mode, asking and seding.
2851 if [ "$3" = "--interactive" ]; then
2852 echo "Entering into interactive mode..."
2853 echo "================================================================================"
2854 echo "Package : $PACKAGE"
2855 # Version.
2856 echo -n "Version : " ; read anser
2857 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
2858 # Category.
2859 echo -n "Category : " ; read anser
2860 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
2861 # Short description.
2862 echo -n "Short desc : " ; read anser
2863 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
2864 # Maintainer.
2865 echo -n "Maintainer : " ; read anser
2866 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
2867 # Web site.
2868 echo -n "Web site : " ; read anser
2869 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
2870 echo ""
2871 # Wget URL.
2872 echo "Wget URL to download source tarball."
2873 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
2874 echo -n "Wget url : " ; read anser
2875 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
2876 # Ask for a stuff dir.
2877 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
2878 if [ "$anser" = "y" ]; then
2879 echo -n "Creating the stuff directory..."
2880 mkdir stuff && status
2881 fi
2882 # Ask for a description file.
2883 echo -n "Are you going to write a description ? (y/N) : " ; read anser
2884 if [ "$anser" = "y" ]; then
2885 echo -n "Creating the description.txt file..."
2886 echo "" > description.txt && status
2887 fi
2888 echo "================================================================================"
2889 echo ""
2890 fi
2891 ;;
2892 remove)
2893 # Remove a package from the wok.
2895 get_tazwok_config
2896 check_for_package_on_cmdline
2897 echo ""
2898 echo -n "Please confirm deletion (y/N) : "; read anser
2899 if [ "$anser" = "y" ]; then
2900 echo -n "Removing $PACKAGE..."
2901 rm -rf $WOK/$PACKAGE && status
2902 echo ""
2903 fi
2904 ;;
2905 update-wok)
2906 # Pull and update a Hg wok.
2907 get_options_list="local"
2908 get_tazwok_config
2909 source_lib report
2910 report start
2911 clean_wok=$LOCAL_REPOSITORY/clean-wok
2912 cd $clean_wok
2913 if ! [ "$local" ]; then
2914 if [ "$WOK_UPDATE_METHOD" = hg ]; then
2915 if ! [ -f "$INSTALLED/mercurial/receipt" ]; then
2917 # Auto-install only if we are in a cook chroot.
2918 if [ -x /usr/bin/clean-chroot ]; then
2919 echo "" >&2
2920 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
2921 echo "">&2
2922 exit 1
2923 else
2924 tazpkg get-install mercurial
2925 fi
2926 fi
2928 report step "Getting wok changes using hg"
2929 if [ -d .hg ]; then
2930 hg pull -u || exit 1
2931 else
2932 hg clone $HG_WOK . || exit 1
2933 fi
2934 report end-step
2935 [ -x /usr/bin/clean-chroot ] && clean-chroot
2936 else
2937 report step "Getting wok changes using tarball"
2938 { mkdir .tmp && cd .tmp
2939 wget "$TARBALL_WOK" &&
2940 case $TARBALL_WOK in
2941 *bz2) tar xjf *.bz2 -C wok; rm *.bz2;;
2942 *lzma) unlzma -c *.lzma | tar xf - -C wok; rm *.lzma ;;
2943 *gz) tar xzf *.gz -C wok; rm*.gz ;;
2944 esac &&
2945 rm -r $(ls -d $clean_wok/*) &&
2946 cp -a wok/* $clean_wok &&
2947 cd .. &&
2948 rm -r .tmp
2949 } || { echo "That's not cool: it fails!" >&2
2950 report end-step
2951 exit 1; }
2952 report end-step
2953 fi
2954 fi
2955 report step "Appending changes to wok"
2957 # Handle removed files/dir.
2958 cd $WOK
2959 for dir in *; do
2960 [ -d "$clean_wok/$dir" ] || rm -rf $dir
2961 done
2962 for file in */receipt */description.txt; do
2963 [ -f "$clean_wok/$file" ] || rm -rf $file
2964 done
2965 for i in $(find */stuff 2>/dev/null); do
2966 [ -e "$clean_wok/$i" ] || rm -rf $i
2967 done
2969 cp -a $clean_wok/* $WOK
2970 report end-step
2971 ;;
2972 maintainers)
2973 get_tazwok_config
2974 echo ""
2975 echo "List of maintainers for: $WOK"
2976 echo "================================================================================"
2977 touch /tmp/slitaz-maintainers
2978 for pkg in $WOK/*
2979 do
2980 . $pkg/receipt
2981 if ! fgrep -q "$MAINTAINER" /tmp/slitaz-maintainers; then
2982 echo "$MAINTAINER" >> /tmp/slitaz-maintainers
2983 echo "$MAINTAINER"
2984 fi
2985 done
2986 echo "================================================================================"
2987 echo "Maintainers: `cat /tmp/slitaz-maintainers | wc -l`"
2988 echo ""
2989 # Remove tmp files
2990 rm -f /tmp/slitaz-maintainers
2991 ;;
2992 maintained-by)
2993 # Search for packages maintained by a contributor.
2994 get_tazwok_config
2995 if [ ! -n "$2" ]; then
2996 echo "Specify a name or email of a maintainer." >&2
2997 exit 1
2998 fi
2999 echo "Maintainer packages"
3000 echo "================================================================================"
3001 for pkg in $WOK/*
3002 do
3003 . $pkg/receipt
3004 if echo "$MAINTAINER" | fgrep -q "$2"; then
3005 echo "$PACKAGE"
3006 packages=$(($PACKAGEs+1))
3007 fi
3008 done
3009 echo "================================================================================"
3010 echo "Packages maintained by $2: $PACKAGEs"
3011 echo ""
3012 ;;
3013 tags)
3014 get_tazwok_config
3015 echo -e "\n\033[1mTags list :\033[0m"
3016 horizontal_line
3017 cd $WOK
3018 for i in */receipt; do
3019 unset TAGS
3020 source $i
3021 for t in $TAGS; do
3022 grep -q ^$t$ $tmp/tags && continue
3023 echo $t | tee -a $tmp/tags
3024 done
3025 done
3026 horizontal_line
3027 echo "$(wc -l $tmp/tags | cut -f1 -d ' ') tags listed."
3028 ;;
3029 check-src)
3030 # Verify if upstream package is still available
3032 get_tazwok_config
3033 check_for_package_on_cmdline
3034 check_for_receipt
3035 source_receipt
3036 check_src()
3038 for url in $@; do
3039 busybox wget -s $url 2>/dev/null && break
3040 done
3042 if [ "$WGET_URL" ];then
3043 echo -n "$PACKAGE : "
3044 check_src $WGET_URL
3045 status
3046 else
3047 echo "No tarball to check for $PACKAGE"
3048 fi
3049 ;;
3050 get-src)
3051 check_root
3052 get_options_list="target nounpack"
3053 get_tazwok_config
3054 check_for_package_on_cmdline
3055 check_for_receipt
3056 source_receipt
3057 if [ "$WGET_URL" ];then
3058 source_lib report
3059 report start
3060 check_for_tarball
3061 else
3062 echo "No tarball to download for $PACKAGE"
3063 fi
3064 ;;
3065 check-commit)
3066 check_root
3067 get_options_list="missing forced"
3068 get_tazwok_config
3069 source_lib report
3070 report start
3071 if [ "$forced" ]; then
3072 rm -f $WOK/*/md5
3073 unset forced
3074 fi
3075 if [ "$missing" ]; then
3076 pkg=$(ls -1 $WOK)
3077 else
3078 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3079 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3080 } | sort -u)"
3081 fi
3082 cooklist=$PACKAGES_REPOSITORY/cooklist
3083 gen_cook_list
3084 ;;
3085 cook-commit)
3086 check_root
3087 get_options_list="missing forced"
3088 get_tazwok_config
3089 source_lib report
3090 report start
3091 if [ "$forced" ]; then
3092 rm -f $WOK/*/md5
3093 unset forced
3094 fi
3095 if [ "$missing" ]; then
3096 pkg=$(ls -1 $WOK)
3097 else
3098 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3099 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3100 } | sort -u)"
3101 fi
3102 cooklist=$PACKAGES_REPOSITORY/cooklist
3103 gen_cook_list
3104 cook_list
3105 ;;
3106 cook-all)
3107 check_root
3108 get_options_list="forced missing"
3109 get_tazwok_config
3110 source_lib report
3111 report start
3112 if [ "$missing" ]; then
3113 pkg=$(ls -1 $WOK)
3114 else
3115 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3116 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3117 } | sort -u)"
3118 fi
3119 cooklist=$PACKAGES_REPOSITORY/cooklist
3120 gen_cook_list
3121 cook_list
3122 ;;
3123 gen-wok-db)
3124 check_root
3125 get_tazwok_config
3126 source_lib report
3127 report start
3128 gen_wok_db
3129 ;;
3130 report)
3131 get_tazwok_config
3132 cd $PACKAGES_REPOSITORY
3133 if [ "$2" ]; then
3134 case $2 in
3135 commit|cooklist|incoming|broken|blocked)
3136 show="$2"
3137 ;;
3138 *)
3139 echo "usage : tazwok report [commit|cooklist|incoming|broken|blocked]" >&2
3140 exit 1
3141 ;;
3142 esac
3143 else
3144 show="commit cooklist incoming broken blocked"
3145 fi
3146 for i in $show; do
3147 if [ -s $i ]; then
3148 echo ""
3149 echo -e "\033[1m$i\033[0m"
3150 echo "================================================================================"
3151 cat $i
3152 echo "================================================================================"
3153 echo ""
3154 fi
3155 done
3156 ;;
3157 check-incoming)
3158 check_root
3159 get_options_list="forced"
3160 get_tazwok_config
3161 source_lib report
3162 report start
3163 [ -f $LOCAL_RESOSITORY/incoming ] && rm [ -f $LOCAL_REPOSITORY/incoming ]
3164 report step "Checking $INCOMING_REPOSITORY"
3165 report open-bloc
3166 [ -f $LOCAL_REPOSITORY/log/incoming.html ] && rm $LOCAL_REPOSITORY/log/incoming.html
3167 report sublog $LOCAL_REPOSITORY/log/incoming.html
3168 echo "incoming" > $LOCAL_REPOSITORY/log/package
3169 check_for_incoming
3170 report end-sublog
3171 report close-bloc
3172 ;;
3173 configure-chroot)
3174 check_root
3175 get_tazwok_config
3176 if [ -f /usr/bin/tazchroot ]; then
3177 cd $LOCAL_REPOSITORY
3178 configure_tazchroot
3179 else
3180 echo "The packages tazchroot need to be installed" >&2
3181 exit 1
3182 fi
3183 ;;
3184 chroot)
3185 check_root
3186 get_tazwok_config
3187 # Merge this and the other chroot function ?.
3188 if [ -f /usr/bin/tazchroot ]; then
3189 cd $LOCAL_REPOSITORY
3190 [ ! -f tazchroot.conf ] && configure_tazchroot
3191 tazchroot
3192 else
3193 echo "The packages tazchroot need to be installed" >&2
3194 exit 1
3195 fi
3196 ;;
3197 cook-toolchain)
3198 check_root
3199 get_tazwok_config
3200 echo -n "" > $PACKAGES_REPOSITORY/broken
3201 if [ -f /usr/bin/tazchroot ]; then
3202 cd $LOCAL_REPOSITORY
3203 [ ! -f tazchroot.conf ] && configure_tazchroot
3204 tazchroot cook-toolchain
3205 # Buggy : chroot can be elsewhere.
3206 rm -r $LOCAL_REPOSITORY/chroot
3207 # /!\ to be writed :
3208 # next rm chroot and plan cook-all by pushing all packages
3209 # in cooklist.
3210 else
3211 echo "The packages tazchroot need to be installed" >&2
3212 exit 1
3213 fi
3214 ;;
3215 webserver)
3216 check_root
3217 get_tazwok_config
3218 if [ "$ARG" = on ]; then
3219 if [ "$WEBSERVER" ] && [ -f "$WEBSERVER/repositories.list" ] && \
3220 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3221 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3222 exit 1
3223 fi
3224 if ! [ -f $LOCAL_REPOSITORY/tazchroot.conf ]; then
3225 tazwok configure-chroot ${undigest:+--undigest=$undigest} --SLITAZ_VERSION=$SLITAZ_VERSION --SLITAZ_DIR=$SLITAZ_DIR
3226 fi
3227 for pkg in php lighttpd; do
3228 [ -d $INSTALLED/$pkg ] || missing="$missing $pkg"
3229 done
3230 if [ "$missing" ]; then
3231 echo "You need to install those packages to start webserver: $missing." >&2
3232 exit 1
3233 fi
3234 if [ ! -f "$LOCAL_REPOSITORY/tazwok.conf" ]; then
3235 echo "Copying /etc/slitaz/tazwok.conf to $LOCAL_REPOSITORY/tazwok.conf: webserver is configured repository-by-repository."
3236 cp /etc/slitaz/tazwok.conf $LOCAL_REPOSITORY
3237 fi
3238 if ! [ "$WEBSERVER" ]; then
3239 echo -n "Where to store php pages (default: /var/www/vhosts/bb)? "
3240 read WEBSERVER
3241 [ "$WEBSERVER" ] || WEBSERVER="/var/www/vhosts/bb"
3242 fi
3243 if [ -f "$WEBSERVER/repositories.list" ] && \
3244 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3245 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3246 exit 1
3247 fi
3248 mkdir -p $WEBSERVER
3249 echo "${undigest:-$SLITAZ_VERSION}" >> $WEBSERVER/repositories.list
3250 for file in index.php log.php download.php; do
3251 [ -f "$WEBSERVER/$file" ] || ln -s /usr/share/slitaz/web-bb/$file $WEBSERVER
3252 done
3253 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3254 ln -s $dir $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3255 done
3256 source $LOCAL_REPOSITORY/tazchroot.conf
3257 echo "<?php
3259 // Web interface configuration
3261 \$version=\"${undigest:-$SLITAZ_VERSION}\";
3262 \$chroot=\"$chroot_dir\";
3263 \$lockfile=\"\$chroot/proc/1/status\";
3264 \$db_dir=\"$PACKAGES_REPOSITORY\";
3265 \$log_dir=\"$LOCAL_REPOSITORY/log\";
3266 \$packages=\"$PACKAGES_REPOSITORY\";
3267 \$incoming=\"$INCOMING_REPOSITORY\";
3268 \$wok=\"$WOK\";
3270 ?>" > $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3271 [ -L "$WEBSERVER/web" ] || ln -s /usr/share/slitaz/web $WEBSERVER
3272 echo "WEBSERVER=\"$WEBSERVER\"" >> $LOCAL_REPOSITORY/tazwok.conf
3273 if [ -L "$WEBSERVER/conf.php" ]; then
3274 echo "Do yo want to make ${undigest:-$SLITAZ_VERSION} the default page (y/N) ? "
3275 read answer
3276 if [ "$answer" = y ]; then
3277 rm $WEBSERVER/conf.php
3278 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3279 fi
3280 else
3281 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3282 fi
3283 elif [ "$ARG" = off ]; then
3284 if ! [ "$WEBSERVER" ]; then
3285 echo "No webserver running for ${undigest:-$SLITAZ_VERSION}" >&2
3286 exit 1
3287 fi
3288 sed '/^WEBSERVER/d' -i $LOCAL_REPOSITORY/tazwok.conf
3289 sed "/^${undigest:-$SLITAZ_VERSION}$/d" -i $WEBSERVER/repositories.list
3290 rm $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3291 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3292 rm $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3293 done
3294 if ! [ -s "$WEBSERVER/repositories.list" ]; then
3295 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"
3296 rm $WEBSERVER/conf.php
3297 elif [ "$(readlink $WEBSERVER/conf.php)" = "$WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php" ]; then
3298 echo "${undigest:-$SLITAZ_VERSION} was the default version to use; switched to : $(sed 1!d $WEBSERVER/repositories.list)"
3299 rm $WEBSERVER/conf.php
3300 ln -s $WEBSERVER/conf-$(sed 1!d $WEBSERVER/repositories.list).php $WEBSERVER/conf.php
3301 fi
3302 else
3303 echo "Usage: tazwok webserver on/off" >&2
3304 exit 1
3305 fi
3306 ;;
3307 block)
3308 # Add a pkg name to the list of blocked packages.
3309 get_tazwok_config
3310 check_root
3311 check_for_package_on_cmdline
3312 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3313 echo "Can't find $PACKAGE into wok." >&2
3314 echo ""
3315 exit 1
3316 fi
3317 echo ""
3318 if grep -qs "^$PACKAGE$" $PACKAGES_REPOSITORY/blocked; then
3319 echo "$PACKAGE is already in the blocked packages list." >&2
3320 echo ""
3321 exit 1
3322 else
3323 echo -n "Adding $PACKAGE to : $PACKAGES_REPOSITORY/blocked... "
3324 echo "$PACKAGE" >> $PACKAGES_REPOSITORY/blocked
3325 status
3326 if grep -q "^$PACKAGE$" $PACKAGES_REPOSITORY/cooklist; then
3327 echo -n "Removing $PACKAGE from : $PACKAGES_REPOSITORY/cooklist... "
3328 sed -i /"^$PACKAGE$"/d $PACKAGES_REPOSITORY/cooklist
3329 status
3330 fi
3331 fi
3332 echo "" ;;
3333 unblock)
3334 # Remove a pkg name from the list of blocked packages.
3335 get_tazwok_config
3336 check_root
3337 check_for_package_on_cmdline
3338 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3339 echo "Can't find $PACKAGE into wok." >&2
3340 echo ""
3341 exit 1
3342 fi
3343 echo ""
3344 if grep -qs "^$PACKAGE$" $PACKAGES_REPOSITORY/blocked; then
3345 echo -n "Removing $PACKAGE from : $PACKAGES_REPOSITORY/blocked... "
3346 sed -i /"^$PACKAGE$"/d $PACKAGES_REPOSITORY/blocked
3347 sed -i '/^$/d' $PACKAGES_REPOSITORY/blocked
3348 status
3349 else
3350 echo "$PACKAGE is not in the blocked packages list." >&2
3351 echo ""
3352 exit 1
3353 fi
3354 echo "" ;;
3355 usage|*)
3356 # Print usage also for all unknown commands.
3358 usage
3359 ;;
3360 esac
3362 report stop 2>/dev/null
3363 exit 0