tazwok view tazwok @ rev 259

Fix clean(): don't report fails when it's false, no more detailled output.
author Antoine Bodin <gokhlayeh@slitaz.org>
date Sat Feb 12 22:42:38 2011 +0100 (2011-02-12)
parents edfb3f3deb75
children 533899c4372c
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=3.9.0
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 check Check every receipt for common errors.
37 check-log Check the process log file of a package.
38 check-depends* Check every receipt for DEPENDS - doesn't scan ELF files.
39 check-src Check upstream tarball for package in the wok.
40 search Search for a package in the wok by pattern or name.
41 compile Configure and build a package using the receipt rules.
42 genpkg Generate a suitable package for Tazpkg with the rules.
43 cook Compile and generate a package directly.
44 cook-list Cook all packages specified in the list by order.
45 cook-commit Cook all modified receipts.
46 cook-all Cook all packages excepted toolchain.
47 cook-toolchain Cook the toolchain packages.
48 gen-cooklist Generate a sorted cooklist using packages or list.
49 sort-cooklist Sort the cooklist given in argument.
50 get-src Download the tarball of the package given in argument.
51 clean Clean all generated files in the package tree.
52 new-tree Prepare a new package tree and receipt (--interactive).
53 gen-list (Re-)Generate a packages list for a repository.
54 check-list Update packages lists for a repository.
55 gen-wok-db (Re-)Generate wok lists with depends and wanted datas.
56 gen-clean-wok Generate a clean wok in a dir.
57 clean-wok Clean entirely the wok.
58 remove Remove a package from the wok.
59 webserver Enable/disable webserver on localhost.
60 hgup Pull and update a wok under Hg.
61 maintainers List all maintainers in the wok.
62 maintained-by List packages maintained by a contributor.\n
64 You can use `basename $0` command --help to list avaible options.
65 \033[1mImportant - *: \033[0m Commands which need a rewrite."
66 }
68 # This function display an error message without returning any error code.
69 # It also log the message in source package's warnings.txt; this file can be
70 # used on an eventual package page on website to display cooking warnings.
71 tazwok_warning()
72 {
73 echo -e "tazwok: $1" >&2
74 echo -e "$1" >> $WOK/${WANTED:-$PACKAGE}/warning.txt
75 return
76 }
78 ########################################################################
79 # TAZWOK VARIABLES & INITIAL CONFIGURATION
80 ########################
82 get_tazwok_config()
83 {
84 # Get configuration file.
85 get_config
87 # Define & get options.
88 get_options_list="$get_options_list SLITAZ_DIR SLITAZ_VERSION undigest"
89 get_options
91 if [ "$undigest" ]; then
92 LOCAL_REPOSITORY=$SLITAZ_DIR/$undigest
93 else
94 LOCAL_REPOSITORY=$SLITAZ_DIR/$SLITAZ_VERSION
95 fi
97 if ! [ "$save_dir" ]; then
98 if [ -f $LOCAL_REPOSITORY/tazwok.conf ] || [ -f $LOCAL_REPOSITORY/slitaz.conf ]; then
99 save_dir=$LOCAL_REPOSITORY
100 [ -f $LOCAL_REPOSITORY/slitaz.conf ] && source $LOCAL_REPOSITORY/slitaz.conf
101 cd $save_dir
102 get_tazwok_config
103 unset save_dir
104 return
105 fi
106 fi
108 # The path to the most important files/dir used by Tazwok.
109 PACKAGES_REPOSITORY=$LOCAL_REPOSITORY/packages
110 WOK=$LOCAL_REPOSITORY/wok
111 INCOMING_REPOSITORY=$LOCAL_REPOSITORY/packages-incoming
112 SOURCES_REPOSITORY=$LOCAL_REPOSITORY/src
113 set_common_path
115 # /!\ This part needs some changes.
116 # Basically, get theses files from the net if they are missing.
117 dep_db=$INCOMING_REPOSITORY/wok-depends.txt
118 wan_db=$INCOMING_REPOSITORY/wok-wanted.txt
119 [ -f $dep_db ] || touch $dep_db
120 [ -f $wan_db ] || touch $wan_db
121 [ -f $PACKAGES_REPOSITORY/cookorder.txt ] || touch $PACKAGES_REPOSITORY/cookorder.txt
123 # Check commons directories, create them if user is root.
124 if test $(id -u) = 0 ; then
125 check_dir $WOK || chmod 777 $WOK
126 check_dir $PACKAGES_REPOSITORY
127 check_dir $SOURCES_REPOSITORY
128 check_dir $INCOMING_REPOSITORY
129 check_dir $LOCAL_REPOSITORY/log
130 fi
132 # Some files are needed by tazwok in PACKAGES_REPOSITORY. Create
133 # them if they are missing.
134 for file in broken blocked commit incoming cooklist; do
135 [ ! -f $PACKAGES_REPOSITORY/$file ] && touch $PACKAGES_REPOSITORY/$file
136 done
138 # Limit memory usage.
139 ulimit -v $(awk '/MemTotal/ { print int(($2*80)/100) }' < /proc/meminfo)
140 }
142 # Used in several functions.
143 set_common_path()
144 {
145 # The receipt is used to compile the source code and
146 # generate suitable packages for Tazpkg.
147 RECEIPT="$WOK/$PACKAGE/receipt"
149 # The path to the process log file.
150 LOG="$WOK/$PACKAGE/process.log"
151 }
153 ########################################################################
154 # TAZWOK CHECK FUNCTIONS
155 ########################
157 # Check for a package name on cmdline.
158 check_for_package_on_cmdline()
159 {
160 if [ ! "$PACKAGE" ]; then
161 echo -e "\nYou must specify a package name on the command line." >&2
162 echo -e "Example : tazwok $COMMAND package\n" >&2
163 exit 1
164 fi
165 }
167 # Check for the receipt of a package used to cook.
168 check_for_receipt()
169 {
170 if [ ! -f "$RECEIPT" ]; then
171 echo -e "\nUnable to find the receipt : $RECEIPT\n" >&2
172 exit 1
173 fi
174 }
176 # Check for a specified file list on cmdline.
177 check_for_list()
178 {
179 if [ ! "$LIST" ]; then
180 echo -e "\nPlease specify the path to the list of packages to cook.\n" >&2
181 exit 1
182 fi
184 # Check if the list of packages exists.
185 if [ -f "$LIST" ]; then
186 LIST=`cat $LIST`
187 else
188 echo -e "\nUnable to find $LIST packages list.\n" >&2
189 exit 1
190 fi
192 if [ ! "$LIST" ]; then
193 echo -e "\nList is empty.\n" >&2
194 exit 1
195 fi
196 }
198 check_for_pkg_in_wok()
199 {
200 [ -f $WOK/$PACKAGE/receipt ] && return
201 if [ "$undigest" ]; then
202 [ -f "$SLITAZ_VERSION/wok/$PACKAGE/receipt" ] && return 1
203 grep -q ^$PACKAGE$ $SLITAZ_DIR/$SLITAZ_VERSION/packages/packages.txt && return 1
204 fi
205 echo "Can't find $PACKAGE in wok or mirror" >&2
206 return 2
207 }
209 ########################################################################
210 # TAZWOK CORE FUNCTIONS
211 ########################
213 remove_src()
214 {
215 [ "$WANTED" ] && return
216 look_for_cookopt !remove_src && return
217 if [ ! -d $WOK/$PACKAGE/install ] && [ "$src" ] && [ -d "$src/_pkg" ]; then
218 check_for_var_modification _pkg src || return
219 mv "$src/_pkg" $WOK/$PACKAGE/install
220 fi
222 # Don't remove sources if a package use src variable in his
223 # genpkg_rules: it maybe need something inside.
224 for i in $PACKAGE $(look_for_rwanted); do
225 sed -n '/^genpkg_rules\(\)/','/}/'p $WOK/$i/receipt | \
226 fgrep -q '$src' && tazwok_warning "Sources will not be removed \
227 because $i use \$src in his receipt." && return
228 done
230 report step "Removing sources directory"
231 rm -fr "$src"
232 report end-step
233 }
235 # Check $COOK_OPT; usage : get_cookopt particular_opt
236 # Return error if not founded
237 # Return args if the opt is in the format opt=arg1:arg2:etc
238 look_for_cookopt()
239 {
240 for arg in $COOK_OPT; do
241 case $arg in
242 $1=*)
243 arg=${arg#$1=}
244 while [ "$arg" ]; do
245 echo "${arg%%:*}"
246 [ "${arg/:}" = "$arg" ] && return
247 arg=${arg#*:}
248 done
249 ;;
250 $1)
251 return
252 ;;
253 esac
254 done
255 return 1
256 }
258 # Check for the wanted package if specified in WANTED
259 # receipt variable. Set the $src/$_pkg variable to help compile
260 # and generate packages.
261 check_for_wanted()
262 {
263 if [ "$WANTED" ]; then
264 report "Checking for the wanted package"
265 if [ ! -d "$WOK/$WANTED" ]; then
266 report exit "\nWanted package is missing in the work directory.\n"
267 fi
269 # Checking for buildtree of Wanted package
270 if [ ! -d "$WOK/$WANTED/taz" ]; then
271 echo -e "\n\nSource files of wanted package is missing in the work directory."
272 echo -n "Would you like to build the missing package (y/N) ? " ; read anser
273 if [ "$anser" == "y" ]; then
274 tazwok cook $WANTED
275 else
276 report exit "\nWanted package source tree is missing in the work directory.\n"
277 fi
278 fi
279 report end-step
281 # Set wanted src path.
282 set_src_path && set_pkg_path
284 fi
285 }
287 # Check for build dependencies, notify user and install if specified.
288 check_for_build_depends()
289 {
290 [ "$WANTED" ] && return
291 [ "$CATEGORY" = meta ] && ! fgrep -q compile_rules $RECEIPT && return
292 report step "Looking for build dependencies"
294 # Keep the list of previously installed build_depends then compare
295 # it with new build_depends to know what to install and what to
296 # what to remove.
297 plan_remove=" $MISSING_PACKAGE $remove_later "
298 [ ! "${plan_remove// }" ] && unset plan_remove
299 unset MISSING_PACKAGE remove_later
300 rwanted=$(look_for_rwanted)
302 for pkg in $(scan $PACKAGE --look_for=bdep --with_dev | \
303 fgrep -v $(for i in $(look_for_rwanted) $PACKAGE; do echo " -e $i"; done))
304 do
306 # Delay the removing of previous cook depends if they are needed
307 # for next cook too.
308 if [ ! -d "$INSTALLED/$pkg" ] ; then
309 MISSING_PACKAGE="$MISSING_PACKAGE $pkg"
310 fi
311 if [ "$plan_remove" != "${plan_remove/ $pkg }" ]; then
312 plan_remove="${plan_remove/ $pkg / }"
313 remove_later="$remove_later $pkg"
314 fi
315 if grep -q ^$pkg$ $PACKAGES_REPOSITORY/broken; then
316 broken="$broken$pkg "
317 fi
318 done
320 # Don't cook if a depend is broken.
321 if [ "$broken" ]; then
322 MISSING_PACKAGE=$plan_remove
323 echo "Can't cook $PACKAGE because broken depend(s) : $broken" >&2
324 unset plan_remove broken
326 # Set report step to failed.
327 report_return_code=1
328 report end-step
329 return 1
330 fi
331 if [ "$MISSING_PACKAGE" ]; then
332 install_missing()
333 {
334 echo "Installing missing packages : $MISSING_PACKAGE"
335 for pkg in $MISSING_PACKAGE; do
336 [ -d "$INSTALLED/$pkg" ] || tazpkg get-install $pkg
337 done
338 }
339 if [ "$auto_install" = yes ]; then
340 install_missing
341 else
342 echo "================================================================================"
343 for pkg in $MISSING_PACKAGE
344 do
345 echo "Missing : $pkg"
346 done
347 echo "================================================================================"
348 echo "You can continue, exit or install missing dependencies."
349 echo -n "Install, continue or exit (install/y/N) ? "; read answer
350 case $answer in
351 install)
352 install_missing ;;
353 y|yes)
354 unset MISSING_PACKAGE;;
355 *)
356 report stop
357 exit 0 ;;
358 esac
359 fi
360 fi
361 report end-step
362 remove_build_depends $plan_remove
363 unset plan_remove
364 }
366 remove_build_depends()
367 {
368 [ "$1" ] || return
369 report step "Removing previous build dependencies"
370 echo "Removing theses packages : $@"
371 for pkg in $@; do
372 [ -d "$INSTALLED/$pkg" ] && tazpkg remove $pkg --auto
373 done
374 report end-step
375 }
377 # Check if we can use the new way to handle tarball
378 # or if we keep the previous method by check for
379 # _pkg=/src= in receipt and reverse-wanted.
380 check_for_var_modification()
381 {
382 for var in $@; do
383 for pkg in $PACKAGE $(look_for_wanted) $(look_for_rwanted); do
384 [ -f $WOK/$pkg/receipt ] || continue
385 fgrep -q "$var=" $WOK/$pkg/receipt && return 1
386 done
387 done
389 # Tweak to make if; then...; fi function working with this one.
390 echo -n ""
391 }
393 set_src_path()
394 {
395 if check_for_var_modification src _pkg; then
396 src=$WOK/${WANTED:-$PACKAGE}/${WANTED:-$PACKAGE}-$VERSION
397 else
398 src=$WOK/${WANTED:-$PACKAGE}/${SOURCE:-${WANTED:-$PACKAGE}}-$VERSION
399 fi
400 }
402 set_pkg_path()
403 {
404 if [ -d $WOK/${WANTED:-$PACKAGE}/install ] ; then
405 _pkg=$WOK/${WANTED:-$PACKAGE}/install
406 else
407 _pkg=$src/_pkg
408 fi
409 }
411 # Output $VERSION-$EXTRAVERSION using packages.txt
412 get_pkg_version()
413 {
414 [ "$PACKAGE" ] || return
415 grep -m1 -A1 -sh ^$PACKAGE$ $1/packages.txt | tail -1 | sed 's/ *//'
416 }
418 remove_previous_tarball()
419 {
420 [ "$prev_VERSION" ] || return
421 if [ "$VERSION" != "$prev_VERSION" ]; then
422 rm -f $SOURCES_REPOSITORY/$PACKAGE-$prev_VERSION.tar.lzma
423 fi
424 }
426 remove_previous_package()
427 {
428 [ "$prev_VERSION" ] || return
429 if [ "$VERSION$EXTRAVERSION" != "$prev_VERSION" ]; then
430 rm -f $1/$PACKAGE-$prev_VERSION.tazpkg
431 fi
432 return
433 }
435 # Check for src tarball and wget if needed.
436 check_for_tarball()
437 {
438 [ "$WGET_URL" ] || return 0
439 report step "Checking for source tarball"
441 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ] && \
442 [ ! -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ] ; then
443 cd $SOURCES_REPOSITORY
444 download $WGET_URL
446 # If source tarball is unreachable, try to find it on SliTaz
447 # mirror.
448 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
449 report step "Download failed, try with mirror copy... "
450 if [ "$SOURCE" ]; then
451 download http://mirror.slitaz.org/sources/packages/${SOURCE:0:1}/$SOURCE-$VERSION.tar.lzma
452 else
453 download http://mirror.slitaz.org/sources/packages/${PACKAGE:0:1}/$PACKAGE-$VERSION.tar.lzma
454 fi
455 fi
456 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ] && \
457 [ ! -f "$SOURCES_REPOSITORY/${SOURCE:-PACKAGE}-$VERSION.tar.lzma" ]; then
458 report step "Download failed, try with mirror copy (again)... "
459 file=$(basename $WGET_URL)
460 download http://mirror.slitaz.org/sources/packages/${file:0:1}/$file
461 fi
463 # Exit if download failed to avoid errors.
464 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ] && [ ! -f "$SOURCES_REPOSITORY/${SOURCE:-PACKAGE}-$VERSION.tar.lzma" ; then
465 echo -e "\nDownload failed, exiting. Please check WGET_URL variable.\n" >&2
466 report end-step
467 return 1
468 fi
469 fi
470 report end-step
472 if [ -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ] && [ "$nounpack" ]; then
473 return
474 fi
476 # Untaring source if necessary. We don't need to extract source if
477 # the package is built with a wanted source package.
478 if [ "$WANTED" ]; then
479 return
480 fi
482 report step "Untaring source tarball"
483 if [ "$target" ]; then
484 src="$target"
485 else
486 set_src_path
487 fi
489 # Log process.
490 echo "untaring source tarball" >> $LOG
492 tmp_src=$WOK/$PACKAGE/tmp-src-$$
493 mkdir $tmp_src
494 if [ -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
495 lzma d $SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma -so | \
496 tar xf - -C $tmp_src
497 elif [ -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
498 case "$TARBALL" in
499 *zip|*xpi)
500 cur_dir=$PWD
501 cd $tmp_src
502 unzip -o $SOURCES_REPOSITORY/$TARBALL
503 cd $cur_dir
504 unset cur_dir
505 ;;
506 *bz2|*tbz|*gem) tar xjf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
507 *tar) tar xf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
508 *lzma|*lz) unlzma -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
509 *xz) unxz -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
510 *Z|*taz) uncompress -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
511 *gz) tar xzf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
512 *rpm)
513 cur_dir=$PWD
514 cd $tmp_src
515 rpm2cpio $SOURCES_REPOSITORY/$TARBALL | cpio -idm --quiet
516 cd $cur_dir
517 unset cur_dir
518 ;;
519 # It's a plain file or something receipt unpack itself.
520 *)
521 mkdir $tmp_src/${SOURCE:-$PACKAGE}-$VERSION
522 cp $SOURCES_REPOSITORY/$TARBALL $tmp_src/${SOURCE:-$PACKAGE}-$VERSION
523 ;;
524 esac || return 1
526 # Check if uncompressed tarball is in a root dir or not.
527 if [ "$(ls -A $tmp_src | wc -l)" -gt 1 ]; 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 fi
537 fi
539 if [ "$repack_src" = yes ]; then
540 report step "Repacking sources in .tar.lzma format"
541 cd $tmp_src
542 tar -c * | lzma e $SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma -si
543 rm $SOURCES_REPOSITORY/$TARBALL
544 prev_VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
546 # Remove previous tarball if it's not used either by
547 # incoming and legacy packages.
548 [ "$prev_VERSION" != "$(get_pkg_version $PACKAGES_REPOSITORY)" ] && \
549 remove_previous_tarball
550 report end-step
551 fi
552 fi
553 if [ "$nounpack" ]; then
554 [ -d "$tmp_src" ] && rm -r $tmp_src
555 return
556 fi
557 if [ "$TARBALL" ]; then
558 if [ ! -d "$src" ]; then
559 if [ -d "$tmp_src" ]; then
560 if ! check_for_var_modification src _pkg; then
561 src="${src%/*}/$(ls $tmp_src)"
562 fi
563 mv $(echo $tmp_src/*) "$src"
564 rm -r $tmp_src
566 # Permissions settings.
567 chown -R root.root "$src"
568 fi
569 else
570 echo "There's already something at $src. Abort." >&2
571 fi
572 fi
573 }
575 # Log and execute compile_rules function if it exists, to configure and
576 # make the package if it exists.
577 check_for_compile_rules()
578 {
579 if grep -q ^compile_rules $RECEIPT; then
580 echo "executing compile_rules" >> $LOG
581 report step "Executing compile_rules"
582 cd $WOK/$PACKAGE
583 rm -f /tmp/config.site
585 # Free some RAM by cleaning cache if option is enabled.
586 freeram=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
588 # Disable -pipe in CFLAGS/CXXFLAGS if less than 512Mb of free
589 # RAM are available.
590 if [ "$freeram" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" -o \
591 "$CXXFLAGS" != "${CXXFLAGS/-pipe}" ]; then
592 tazwok_warning "Disabling -pipe compile flag because only ${freeram}b of RAM are available."
593 CFLAGS="${CFLAGS/-pipe}"
594 CXXFLAGS="${CXXFLAGS/-pipe}"
595 fi
596 unset freeram
598 # Set cook environnement variables.
599 [ "$src" ] || set_src_path
600 [ "$DESTDIR" ] || DESTDIR="$WOK/$PACKAGE/install"
601 [ "$CONFIG_SITE" ] || CONFIG_SITE=/etc/config.site
602 export CFLAGS CXXFLAGS MAKEFLAGS DESTDIR BUILD_HOST \
603 CONFIG_SITE default_prefix \
604 default_datarootdir default_datadir default_localedir \
605 default_infodir default_mandir default_build default_host
606 local LC_ALL=POSIX LANG=POSIX
607 compile_rules
609 # Check if config.site has been used.
610 # /!\ disabled since it screw the return_code of the step.
611 #if [ -f /tmp/config.site ]; then
612 # rm /tmp/config.site
613 #else
614 # tazwok_warning "config.site hasn't been used during \
615 #configuration process."
616 #fi
618 report end-step
619 fi
620 }
622 # Check for loop in deps tree. /!\ can be removed
623 check_for_deps_loop()
624 {
625 local list
626 local pkg
627 local deps
628 pkg=$1
629 shift
630 [ -n "$1" ] || return
631 list=""
633 # Filter out already processed deps
634 for i in $@; do
635 case " $ALL_DEPS" in
636 *\ $i\ *);;
637 *) list="$list $i";;
638 esac
639 done
640 ALL_DEPS="$ALL_DEPS$list "
641 for i in $list; do
642 [ -f $i/receipt ] || continue
643 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
644 case " $deps " in
645 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
646 *) check_for_deps_loop $pkg $deps;;
647 esac
648 done
649 }
651 download()
652 {
653 for file in $@; do
654 case "$file" in
655 [Hh][Tt][Tt][Pp][Ss]*)
656 if [ -d $INSTALLED/wget ]; then
657 wget --no-check-certificate -O $(basename $file) $file && break
658 else
659 tazwok_warning "$PACKAGE need wget to download the source tarball from $file, please add it as build-depend."
660 return 1
661 fi
662 esac
663 wget -q $file && break
664 wget -O $(basename $file) $file && break
665 done
666 }
668 # Regenerate every package that wants a PACKAGE compiled
669 refresh_packages_from_compile()
670 {
671 # make tazwok genpkg happy
672 mkdir $WOK/$PACKAGE/taz
674 # Cook rwanted in default or specied order
675 genlist=" $(look_for_rwanted | tr '\n' ' ') "
676 for i in $(look_for_cookopt genpkg | tac); do
677 [ "${genlist/ $i }" = "$genlist" ] && continue
678 genlist=" $i${genlist/ $i / }"
679 done
680 if [ "$genlist" ]; then
681 local PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
682 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
683 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
684 src _pkg DESTDIR CONFIG_SITE RECEIPT LOG
685 for PACKAGE in $genlist; do
686 set_common_path
687 gen_package
688 done
689 fi
690 }
692 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
693 # so some packages need to copy these files with the receipt and genpkg_rules.
694 # This function is executed by gen_package when 'tazwok genpkg'.
695 copy_generic_files()
696 {
697 # In most cases, locales are in $_pkg/usr/share/locale so we copy files
698 # using generic variables and $LOCALE from Tazwok config file.
699 if [ "$LOCALE" ]; then
700 if [ -d "$_pkg/usr/share/locale" ]; then
701 for i in $LOCALE
702 do
703 if [ -d "$_pkg/usr/share/locale/$i" ]; then
704 mkdir -p $fs/usr/share/locale
705 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
706 fi
707 done
708 fi
709 fi
711 # Pixmaps (PNG or/and XPM only). Some icons/images can be added through
712 # genpkg_rules and generic copy can be disabled with GENERIC_PIXMAPS="no"
713 # in pkg receipt.
714 if [ "$GENERIC_PIXMAPS" != "no" ]; then
715 if [ -d "$_pkg/usr/share/pixmaps" ]; then
716 mkdir -p $fs/usr/share/pixmaps
717 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
718 $fs/usr/share/pixmaps 2>/dev/null
719 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
720 $fs/usr/share/pixmaps 2>/dev/null
721 fi
723 # Custom or homemade PNG pixmap can be in stuff.
724 if [ -f "stuff/$PACKAGE.png" ]; then
725 mkdir -p $fs/usr/share/pixmaps
726 cp -a stuff/$PACKAGE.png $fs/usr/share/pixmaps
727 fi
728 fi
730 # Desktop entry (.desktop).
731 if [ -d "$_pkg/usr/share/applications" ]; then
732 cp -a $_pkg/usr/share/applications $fs/usr/share
733 fi
735 # Homemade desktop file(s) can be in stuff.
736 if [ -d "stuff/applications" ]; then
737 mkdir -p $fs/usr/share
738 cp -a stuff/applications $fs/usr/share
739 fi
740 if [ -f "stuff/$PACKAGE.desktop" ]; then
741 mkdir -p $fs/usr/share/applications
742 cp -a stuff/$PACKAGE.desktop $fs/usr/share/applications
743 fi
744 }
746 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
747 strip_package()
748 {
749 report step "Executing strip on all files"
751 # Binaries.
752 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
753 do
754 if [ -d "$dir" ]; then
755 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
756 fi
757 done
759 # Libraries.
760 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
761 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
762 report end-step
763 }
765 # Remove .pyc and .pyo files from packages
766 py_compiled_files_remove()
767 {
768 report step "Removing all .pyc and .pyo files from package ..."
769 find $fs -type f -name "*.pyc" -delete 2>/dev/null
770 find $fs -type f -name "*.pyo" -delete 2>/dev/null
771 report end-step
772 }
774 # Check FSH in a slitaz package (Path: /:/usr)
775 check_fsh()
776 {
777 cd $WOK/$PACKAGE/taz/*/fs
778 [ -n "$FSH" ] || FSH="bin boot dev etc home init lib media mnt proc \
779 root sbin share sys tmp usr var vz usr/bin usr/games usr/include usr/lib \
780 usr/local usr/sbin usr/share usr/src"
781 for i in `ls -d * usr/* 2>/dev/null`
782 do
783 if ! echo $FSH | fgrep -q $i; then
784 echo "Wrong path: /$i" >&2
785 error=1
786 fi
787 done
788 if [ "$error" = "1" ]; then
789 cat << _EOT_
791 Package will install files in a non standard directory and won't be generated.
792 You may have a wrong copy path in genpkg_rules or need to add some options to
793 configure in compile_rules. Some valid options for SliTaz (Linux FSH):
795 --prefix=/usr
796 --sysconfdir=/etc
797 --libexecdir=/usr/lib/(pkgname)
798 --localstatedir=/var
799 --mandir=/usr/share/man
800 --infodir=/usr/share/info
802 For more information please read SliTaz docs and run: ./configure --help
803 ================================================================================
804 $PACKAGE package generation aborted.
806 _EOT_
808 # Dont generate a corrupted package.
809 cd $WOK/$PACKAGE && rm -rf taz
810 report exit
811 fi
812 }
814 gen_cookmd5()
815 {
816 # md5sum of cooking stuff make tazwok able to check for changes
817 # without hg.
818 cd $WOK/$PACKAGE
819 md5sum receipt > md5
820 [ -f description.txt ] && md5sum description.txt >> md5
821 if [ -d stuff ]; then
822 find stuff | while read file; do
823 md5sum $file >> md5
824 done
825 fi
826 }
828 # Create a package tree and build the gziped cpio archive
829 # to make a SliTaz (.tazpkg) package.
830 gen_package()
831 {
832 check_root
833 check_for_package_on_cmdline
834 check_for_receipt
835 EXTRAVERSION=""
836 . $RECEIPT
838 # May compute VERSION
839 if grep -q ^get_version $RECEIPT; then
840 get_version
841 fi
842 check_for_wanted
843 cd $WOK/$PACKAGE
845 # Remove old Tazwok package files.
846 [ -d "taz" ] && rm -rf taz
848 # Create the package tree and set useful variables.
849 mkdir -p taz/$PACKAGE-$VERSION/fs
850 fs=taz/$PACKAGE-$VERSION/fs
852 # Set $src for standard package and $_pkg variables.
853 set_src_path && set_pkg_path
855 # Execute genpkg_rules, check package and copy generic files to build
856 # the package.
857 report step "Building $PACKAGE with the receipt"
858 report open-bloc
859 if grep -q ^genpkg_rules $RECEIPT; then
861 # Log process.
862 echo "executing genpkg_rules" >> $LOG
863 report step "Executing genpkg_rules"
864 genpkg_rules
865 report end-step
866 check_fsh
867 cd $WOK/$PACKAGE
869 # Skip generic files for packages with a WANTED variable
870 # (dev and splited pkgs).
871 if [ ! "$WANTED" ]; then
872 copy_generic_files
873 fi
874 look_for_cookopt !strip || strip_package
875 py_compiled_files_remove
876 else
877 echo "No package rules to gen $PACKAGE..." >&2
878 report exit
879 fi
881 # Copy the receipt and description (if exists) into the binary package tree.
882 cd $WOK/$PACKAGE
883 report step "Copying the receipt"
884 cp receipt taz/$PACKAGE-$VERSION
885 report end-step
886 if grep -q ^get_version $RECEIPT; then
887 report step "Updating version in receipt"
888 sed -i "s/^VERSION=.*/VERSION=\"$VERSION\"/" \
889 taz/$PACKAGE-$VERSION/receipt
890 report end-step
891 fi
892 if [ -f "description.txt" ]; then
893 report step "Copying the description file"
894 cp description.txt taz/$PACKAGE-$VERSION
895 report end-step
896 fi
898 # Generate md5 of cooking stuff to look for commit later.
899 gen_cookmd5
900 echo -e "\n# md5sum of cooking stuff :" >> taz/$PACKAGE-$VERSION/receipt
901 cat md5 | sed 's/^/# /' >> taz/$PACKAGE-$VERSION/receipt
903 # Create the files.list by redirecting find output.
904 report step "Creating the list of files"
905 cd taz/$PACKAGE-$VERSION
906 LAST_FILE=""
907 { find fs -print; echo; } | while read file; do
908 if [ "$LAST_FILE" ]; then
909 case "$file" in
910 $LAST_FILE/*)
911 case "$(ls -ld "$LAST_FILE")" in
912 drwxr-xr-x\ *\ root\ *\ root\ *);;
913 *) echo ${LAST_FILE#fs};;
914 esac;;
915 *) echo ${LAST_FILE#fs};;
916 esac
917 fi
918 LAST_FILE="$file"
919 done > files.list
921 # Next, check if something has changed in lib files.
922 if fgrep -q '.so' files.list; then
923 report step "Look for major/minor update in libraries"
924 for rep in $INCOMING_REPOSITORY $PACKAGES_REPOSITORY \
925 $([ "$undigest" ] && echo SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming && \
926 echo $SLITAZ_DIR/$SLITAZ_VERSION/packages); do
927 prev_VERSION=$(get_pkg_version $rep)
928 [ "$prev_VERSION" ] && pkg_file=$rep/$PACKAGE-$prev_VERSION.tazpkg && break
929 done
930 if [ "$pkg_file" ]; then
931 get_pkg_files $pkg_file
932 cd $WOK/$PACKAGE/taz/$PACKAGE-$VERSION
933 fgrep ".so" files.list | egrep -v "[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*" | \
934 while read lib; do
935 fgrep -q "$lib" $pkg_files_dir/files.list && continue
936 echo "A minor/major update in libraries is detected, planning re-cook of reverse-depends of $PACKAGE."
937 for rdep in $(scan $PACKAGE --look_for=rdep | use_wanted); do
938 [ "$rdep" = "${WANTED:-$PACKAGE}" ] && continue
939 grep -q ^$rdep$ $PACKAGES_REPOSITORY/blocked \
940 $PACKAGES_REPOSITORY/cooklist && continue
941 echo $rdep >> $PACKAGES_REPOSITORY/cooklist
942 done
943 regen_cooklist=yes
944 break
945 done
946 rm -r $pkg_files_dir
947 fi
948 report end-step
949 fi
950 if [ ! "$EXTRAVERSION" ]; then
951 case "$PACKAGE" in
952 linux*);;
953 *) EXTRAVERSION="$(grep '/lib/modules/.*-slitaz/' files.list |\
954 head -1 | sed 's|/lib/modules/\(.*\)-slitaz/.*|_\1|')";;
955 esac
956 fi
957 rm -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg 2> /dev/null
958 report step "Creating md5sum of files"
959 while read file; do
960 [ -L "fs$file" ] && continue
961 [ -f "fs$file" ] || continue
962 md5sum "fs$file" | sed 's/ fs/ /'
963 done < files.list > md5sum
964 report end-step
965 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
966 2> /dev/null | awk '{ sz=$1 } END { print sz }')
968 # Build cpio archives. Find, cpio and gzip the fs, finish by
969 # removing the fs tree.
970 # Don't log this because compression always output error messages.
971 find fs -print | cpio -o -H newc | case "$PACKAGE-$COMPRESSION" in
972 tazpkg-lzma) gzip > fs.cpio.gz;;
973 *-lzma) lzma e fs.cpio.lzma -si;;
974 *) gzip > fs.cpio.gz;;
975 esac && rm -rf fs
976 PACKED_SIZE=$(du -chs fs.cpio.* receipt files.list md5sum \
977 description.txt 2> /dev/null | awk '{ sz=$1 } END { print sz }')
978 report step "Updating receipt sizes"
979 sed -i '/^PACKED_SIZE/d' receipt
980 sed -i '/^UNPACKED_SIZE/d' receipt
981 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
982 sed -i "s/^VERSION=$/VERSION=\"$VERSION\"/" receipt
983 report end-step
984 if [ "$EXTRAVERSION" ]; then
985 report step "Updating receipt EXTRAVERSION"
986 sed -i s/^EXTRAVERSION.*$// receipt
987 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
988 fi
989 prev_VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
990 remove_previous_package $INCOMING_REPOSITORY
991 report step "Creating full cpio archive"
992 find . -print | cpio -o -H newc > $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
994 # Restore package tree in case we want to browse it.
995 report step "Restoring original package tree"
996 { zcat fs.cpio.gz 2> /dev/null || unlzma -c fs.cpio.lzma; } | cpio --quiet -id
997 rm fs.cpio.* && cd ..
999 # Log process.
1000 echo "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg (done)" >> $LOG
1001 report close-bloc
1002 echo "Package $PACKAGE ($VERSION$EXTRAVERSION) generated."
1003 echo "Size : `du -sh $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
1004 echo ""
1006 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/broken
1007 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/commit
1008 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/cooklist
1011 ########################################################################
1012 # This section contains functions used by several other functions
1013 # bellow.
1014 ########################
1016 # Look for receipt/files.list in wok. If they can't be found, get them
1017 # from package. Accept one argument : absolute path to package.
1018 get_pkg_files()
1020 pkg_files_dir=$tmp/$(basename ${1%.tazpkg})
1021 mkdir -p $pkg_files_dir && \
1022 cd $pkg_files_dir && \
1023 cpio --quiet -idm receipt < $1 && \
1024 cpio --quiet -idm files.list < $1
1027 ########################################################################
1028 # This section contains functions to generate packages databases.
1029 ########################
1032 gen_packages_db()
1034 # pkg_repository can be $PACKAGES_REPOSITORY or $INCOMING_REPOSITORY.
1035 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1036 cd $pkg_repository
1037 report step "Generating packages lists: $pkg_repository"
1038 report open-bloc
1039 report step "Removing old files"
1040 for file in files.list.lzma packages.list packages.txt \
1041 packages.desc packages.equiv packages.md5; do
1042 [ -f $file ] && rm $file
1043 done
1044 touch files.list
1046 packages_db_start
1047 unset RECEIPT
1048 report step "Reading datas from all packages"
1049 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1050 get_packages_info
1051 done
1052 report end-step
1053 packages_db_end
1054 report close-bloc
1057 update_packages_db()
1059 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1060 cd $pkg_repository
1061 for file in packages.list packages.equiv packages.md5 packages.desc \
1062 packages.txt; do
1063 if [ ! -f "$file" ]; then
1064 gen_packages_db
1065 return
1066 fi
1067 done
1068 if [ -f files.list.lzma ]; then
1069 lzma d files.list.lzma files.list
1070 else
1071 gen_packages_db
1072 fi
1073 report step "Updating packages lists: $pkg_repository"
1074 packages_db_start
1076 # Look for removed/update packages.
1077 for PACKAGE in $(grep ^[0-9,a-z,A-Z] packages.txt); do
1078 pkg="$pkg_repository/$(grep -m1 ^$PACKAGE- packages.list).tazpkg"
1079 if ! [ -f "$pkg" ]; then
1080 erase_package_info
1081 else
1082 if [ "$pkg" -nt "packages.list" ]; then
1083 updated_pkg="$updated_pkg
1084 $PACKAGE $pkg"
1085 fi
1086 fi
1087 done
1088 echo "$updated_pkg" | sed 1d | while read PACKAGE pkg; do
1089 erase_package_info
1090 get_packages_info
1091 done
1092 unset updated_pkg
1094 # Look for new packages.
1095 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1096 if ! fgrep -q " ${pkg##*/}" $pkg_repository/packages.md5; then
1097 get_packages_info
1098 fi
1099 done
1100 report end-step
1101 packages_db_end
1104 packages_db_start()
1106 if [ ! -s packages.txt ]; then
1107 echo "# SliTaz GNU/Linux - Packages list
1109 # Packages : unknow
1110 # Date : $(date +%Y-%m-%d\ \%H:%M:%S)
1112 " > packages.txt
1113 else
1114 sed -e 's/^# Packages :.*/# Packages : unknow/' \
1115 -e "s/# Date :.*/# Date : $(date +%Y-%m-%d\ \%H:%M:%S)/" \
1116 -i packages.txt
1117 fi
1119 # Needed in some case as tazwok define RECEIPT at configuration time
1120 # in this particular case it can broke the script.
1121 unset RECEIPT
1124 erase_package_info()
1126 cd $pkg_repository
1127 sed "/^$PACKAGE$/,/^$/d" -i packages.txt
1128 sed "/^$PACKAGE /d" -i packages.desc
1129 sed -e "s/=$PACKAGE /= /" -e "s/ $PACKAGE / /" -e "s/ $PACKAGE$//" \
1130 -e "/=$PACKAGE$/d" -e "s/=[0-9,a-z,A-Z]:$PACKAGE /= /" \
1131 -e "s/ [0-9,a-z,A-Z]:$PACKAGE / /" -e "s/ [0-9,a-z,A-Z]:$PACKAGE$/ /" \
1132 -e "/=[0-9,a-z,A-Z]:$PACKAGE$/d" \
1133 -i packages.equiv
1134 sed "/^$PACKAGE:/d" -i files.list
1135 sed "/^$(basename ${pkg%.tazpkg})$/d" -i packages.list
1136 sed "/ $(basename $pkg)$/d" -i packages.md5
1139 get_packages_info()
1141 # If there's no taz folder in the wok, extract infos from the
1142 # package.
1143 get_pkg_files $pkg
1144 source_receipt
1145 echo "Getting datas from $PACKAGE"
1147 cat >> $pkg_repository/packages.txt << _EOT_
1148 $PACKAGE
1149 $VERSION$EXTRAVERSION
1150 $SHORT_DESC
1151 _EOT_
1152 if [ "$PACKED_SIZE" ]; then
1153 cat >> $pkg_repository/packages.txt << _EOT_
1154 $PACKED_SIZE ($UNPACKED_SIZE installed)
1156 _EOT_
1157 else
1158 echo "" >> $pkg_repository/packages.txt
1159 fi
1161 # Packages.desc is used by Tazpkgbox <tree>.
1162 echo "$PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> $pkg_repository/packages.desc
1164 # Packages.equiv is used by tazpkg install to check depends
1165 for i in $PROVIDE; do
1166 DEST=""
1167 echo $i | fgrep -q : && DEST="${i#*:}:"
1168 if grep -qs ^${i%:*}= $pkg_repository/packages.equiv; then
1169 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" $pkg_repository/packages.equiv
1170 else
1171 echo "${i%:*}=$DEST$PACKAGE" >> $pkg_repository/packages.equiv
1172 fi
1173 done
1175 if [ -f files.list ]; then
1176 { echo "$PACKAGE"; cat files.list; } | awk '
1177 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }' >> $pkg_repository/files.list
1178 fi
1180 cd .. && rm -r "$pkg_files_dir"
1182 cd $pkg_repository
1183 echo $(basename ${pkg%.tazpkg}) >> packages.list
1184 [ ! "$package_md5" ] && package_md5=$(md5sum $(basename $pkg))
1185 echo "$package_md5" >> packages.md5
1186 unset package_md5
1189 source_receipt()
1191 unset PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
1192 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
1193 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
1194 src _pkg DESTDIR CONFIG_SITE
1195 . ${RECEIPT:-$PWD/receipt}
1198 packages_db_end()
1200 cd $pkg_repository
1201 pkgs=$(wc -l packages.list | sed 's/ .*//')
1202 sed "s/# Packages : .*/# Packages : $pkgs/" -i packages.txt
1204 # If lists was updated it's generally needed to sort them well.
1205 if ! sort -c packages.list 2> /dev/null; then
1206 report step "Sorting packages lists"
1207 for file in packages.list packages.desc packages.equiv; do
1208 [ -f $file ] || continue
1209 sort -o $file $file
1210 done
1211 report end-step
1212 fi
1214 # Dont log this because lzma always output error.
1215 lzma e files.list files.list.lzma
1216 rm -f files.list
1217 [ -f packages.equiv ] || touch packages.equiv
1220 ########################################################################
1221 # This section contains functions to generate wok database.
1222 ########################
1224 gen_wok_db()
1226 report step "Generating wok database"
1227 report open-bloc
1228 report step "Removing old files"
1229 for file in $wan_db $dep_db $PACKAGES_REPOSITORY/cookorder.txt; do
1230 [ -f $file ] && rm $file
1231 done
1232 report step "Generating wok-wanted.txt"
1233 gen_wan_db
1234 report step "Generating wok-depends.txt"
1235 for PACKAGE in $(cut -f1 -d '|' $PACKAGES_REPOSITORY/packages.desc \
1236 $INCOMING_REPOSITORY/packages.desc | sort -u); do
1237 RECEIPT=$WOK/$PACKAGE/receipt
1238 if [ -s $RECEIPT ]; then
1239 source_receipt
1240 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
1241 fi
1242 done
1243 sort_db
1244 report close-bloc
1247 gen_wan_db()
1249 for RECEIPT in $(fgrep -l WANTED $WOK/*/receipt); do
1250 WANTED=
1251 source $RECEIPT
1252 [ "$WANTED" ] || continue
1253 echo -e $PACKAGE"\t"$WANTED >> $tmp/wan_db
1254 done
1255 if ! [ -f $wan_db ] || [ "$(diff -q $tmp/wan_db $wan_db)" ]; then
1256 mv -f $tmp/wan_db $wan_db
1257 plan_regen_cookorder=yes
1258 else
1259 rm $tmp/wan_db
1260 fi
1263 update_wan_db()
1265 local PACKAGE
1266 for RECEIPT in $(fgrep WANTED $WOK/*/receipt | \
1267 fgrep $PACKAGE | cut -f1 -d ':'); do
1268 WANTED=
1269 source $RECEIPT
1270 [ "$WANTED" ] || continue
1271 wan_info=$(echo -e $PACKAGE"\t"$WANTED)
1272 [ "$wan_info" = "$(grep -m1 ^$PACKAGE$'\t' $wan_db 2>/dev/null)" ] && return
1273 sed "/^$PACKAGE\t/d" -i $wan_db
1274 echo "$wan_info" >> $wan_db
1275 plan_regen_cookorder=yes
1276 plan_sort_wandb=yes
1277 done
1280 update_dep_db()
1282 dep_info=$(echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ')
1283 [ "$dep_info" = "$(grep -m1 ^$PACKAGE$'\t' $dep_db 2>/dev/null)" ] && return
1284 sed "/^$PACKAGE\t/d" -i $dep_db
1285 echo "$dep_info" >> $dep_db
1286 plan_regen_cookorder=yes
1287 plan_sort_depdb=yes
1290 sort_db()
1292 report step "Generating cookorder.txt"
1293 cat $dep_db | sed 's/ \t / /' | while read PACKAGE BUILD_DEPENDS; do
1294 grep -q ^$PACKAGE$'\t' $wan_db && continue
1296 # Replace each BUILD_DEPENDS with a WANTED package by it's
1297 # WANTED package.
1298 replace_by_wanted()
1300 for p in $BUILD_DEPENDS; do
1301 if grep -q ^$p$'\t' $wan_db; then
1302 echo -n $(grep ^$p$'\t' $wan_db | cut -f 2)' '
1303 else
1304 echo -n $p' '
1305 fi
1306 done | tr ' ' '\n' | sort -u | sed "/^$PACKAGE$/d" | tr '\n' ' '
1308 echo -e $PACKAGE"\t $(replace_by_wanted) "
1309 done > $tmp/db
1310 while [ -s "$tmp/db" ]; do
1311 status=start
1312 for pkg in $(cut -f 1 $tmp/db); do
1313 if ! fgrep -q ' '$pkg' ' $tmp/db; then
1314 echo $pkg >> $tmp/cookorder
1315 sed -e "/^$pkg\t/d" -e "s/ $pkg / /g" -i $tmp/db
1316 status=proceed
1317 fi
1318 done
1319 if [ "$status" = start ]; then
1320 cp -f $tmp/db /tmp/remain-depends.txt
1321 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
1322 for blocked in $(cut -f 1 $tmp/db); do
1323 echo "$blocked" >> $PACKAGES_REPOSITORY/blocked
1324 done
1325 break
1326 fi
1327 done
1328 [ -s $tmp/cookorder ] || touch $tmp/cookorder
1330 # The toolchain packages are moved in first position.
1331 grep $(for pkg in `scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
1332 --look_for=all --with_args`; do echo " -e ^$pkg$"; done) \
1333 $tmp/cookorder | tac > $PACKAGES_REPOSITORY/cookorder.txt
1334 for pkg in $(cat $PACKAGES_REPOSITORY/cookorder.txt); do
1335 sed "/^$pkg$/d" -i $tmp/cookorder
1336 done
1338 tac $tmp/cookorder >> $PACKAGES_REPOSITORY/cookorder.txt
1339 unset plan_regen_cookorder
1340 report end-step
1343 ########################################################################
1344 # SCAN CORE
1345 ########################
1346 # Include various scan core-functions. It's not intended to be used
1347 # directly : prefer scan wrappers in next section.
1349 look_for_dep()
1351 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1352 grep ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
1353 | cut -f 2
1354 else
1355 grep ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-depends.txt | \
1356 cut -f 2
1357 fi
1360 look_for_bdep()
1362 look_for_all
1365 look_for_all()
1367 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1368 grep ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
1369 | cut -f 2,3 | sed 's/ / /'
1370 else
1371 grep ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-depends.txt | \
1372 cut -f 2,3 | sed 's/ / /'
1373 fi
1376 look_for_rdep()
1378 fgrep ' '$PACKAGE' ' $INCOMING_REPOSITORY/wok-depends.txt | cut -f 1
1379 if [ "$undigest" ]; then
1380 for rdep in $(fgrep ' '$PACKAGE' ' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt | cut -f 1); do
1381 if [ ! -f "WOK$/$rdep/receipt" ]; then
1382 echo "$rdep"
1383 fi
1384 done
1385 fi
1388 look_for_rbdep()
1390 fgrep ' '$PACKAGE' ' $INCOMING_REPOSITORY/wok-depends.txt | \
1391 cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1392 if [ "$undigest" ]; then
1393 for rdep in $(fgrep ' '$PACKAGE' ' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
1394 | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1); do
1395 if [ ! -f "WOK$/$rdep/receipt" ]; then
1396 echo "$rdep"
1397 fi
1398 done
1399 fi
1402 # Return WANTED if it exists.
1403 look_for_wanted()
1405 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1406 grep ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-wanted.txt | cut -f 2
1407 else
1408 grep ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-wanted.txt | cut -f 2
1409 fi
1412 # Return packages which wants PACKAGE.
1413 look_for_rwanted()
1415 grep $'\t'$PACKAGE$ $INCOMING_REPOSITORY/wok-wanted.txt | cut -f 1
1416 if [ "$undigest" ]; then
1417 for rwanted in $(grep $'\t'$PACKAGE$ $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-wanted.txt | cut -f 1); do
1418 if [ ! -f "$WOK/$rwanted/receipt" ]; then
1419 echo "$rwanted"
1420 fi
1421 done
1422 fi
1425 look_for_dev()
1427 WANTED=$(look_for_wanted)
1428 if [ "$WANTED" ]; then
1429 if [ "$undigest" ] && [ ! -f "$WOK/$WANTED/receipt" ]; then
1430 [ -f "$SLITAZ_DIR/$SLITAZ_VERSION/wok/$WANTED-dev/receipt" ] && echo $WANTED-dev
1431 else
1432 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1433 fi
1434 fi
1435 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1436 [ -f "$SLITAZ_DIR/$SLITAZ_VERSION/wok/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1437 else
1438 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1439 fi
1442 with_dev()
1444 for PACKAGE in $(cat); do
1445 echo $PACKAGE
1446 look_for_dev
1447 done
1450 with_wanted()
1452 for PACKAGE in $(cat); do
1453 echo $PACKAGE
1454 look_for_wanted
1455 done
1458 use_wanted()
1460 for input in $(cat); do
1461 { grep ^$input$'\t' $wan_db || echo $input
1462 } | sed 's/.*\t//'
1463 done
1466 ########################################################################
1467 # SCAN
1468 ########################
1469 # Use wok-wanted.txt and wok-depeds.txt to scan depends.
1470 # Option in command line (must be first arg) :
1471 # --look_for=bdep/rbdep - Look for depends or reverse depends.
1472 # --with_dev - Add development packages (*-dev) in the result.
1473 # --with_wanted - Add package+reverse wanted in the result.
1474 # --with_args - Include packages in argument in the result.
1476 scan()
1478 # Get packages in argument.
1479 local PACKAGE WANTED pkg_list=
1480 for arg in $@; do
1481 [ "$arg" = "${arg#--}" ] || continue
1482 pkg_list="$pkg_list $arg"
1483 done
1485 # Get options.
1486 [ "$pkg_list" ] || return
1487 local cooklist= look_for= with_dev= with_wanted= with_args= log_command="$0 $@" \
1488 get_options_list="look_for with_dev with_wanted with_args cooklist use_wanted"
1489 get_options
1491 # Cooklist is a special case where we need to modify a little
1492 # scan behavior
1493 if [ "$cooklist" ]; then
1494 gen_wan_db
1495 look_for=all && with_args=yes && with_dev= && with_wanted=
1496 filter=use_wanted
1497 if [ "$COMMAND" = gen-cooklist ]; then
1498 for PACKAGE in $pkg_list; do
1499 grep -q ^$PACKAGE$'\t' $dep_db && continue
1500 [ -d "$WOK/$p" ] || continue
1501 check_for_missing
1502 done
1503 append_to_dep()
1505 if ! grep -q ^$PACKAGE$'\t' $dep_db; then
1506 check_for_missing && echo $PACKAGE >> $tmp/dep
1507 else
1508 echo $PACKAGE >> $tmp/dep
1509 fi
1511 else
1512 append_to_dep()
1514 check_for_commit && echo $PACKAGE >> $tmp/dep
1516 fi
1517 else
1518 append_to_dep()
1520 echo $PACKAGE >> $tmp/dep
1522 # If requested packages are not in dep_db, partial generation of this db is needed.
1523 for PACKAGE in $pkg_list; do
1524 grep -q ^$PACKAGE$'\t' $dep_db && continue
1525 [ -d "$WOK/$p" ] || continue
1526 plan_check_for_missing=yes
1527 check_for_missing
1528 done
1529 if [ "$plan_check_for_missing" ]; then
1530 append_to_dep()
1532 if ! grep -q ^$PACKAGE$'\t' $dep_db; then
1533 check_for_missing && echo $PACKAGE >> $tmp/dep
1534 else
1535 echo $PACKAGE >> $tmp/dep
1536 fi
1538 check_db_status=yes
1539 unset plan_check_for_missing
1540 fi
1541 fi
1543 [ "$with_dev" ] && filter=with_dev
1544 [ "$with_wanted" ] && filter=with_wanted
1545 if [ "$filter" ]; then
1546 pkg_list=$(echo $pkg_list | $filter)
1547 scan_pkg()
1549 look_for_$look_for | $filter
1551 else
1552 scan_pkg()
1554 look_for_$look_for
1556 fi
1557 touch $tmp/dep
1558 for PACKAGE in $pkg_list; do
1559 [ "$with_args" ] && append_to_dep
1560 scan_pkg
1561 done | tr ' ' '\n' | sort -u > $tmp/list
1562 [ "$look_for" = bdep ] && look_for=dep
1563 while [ -s $tmp/list ]; do
1564 PACKAGE=$(sed 1!d $tmp/list)
1565 sed 1d -i $tmp/list
1566 append_to_dep
1567 for pkg in $(scan_pkg); do
1568 if ! grep -q ^$pkg$ $tmp/list $tmp/dep; then
1569 echo $pkg >> $tmp/list
1570 fi
1571 done
1572 done
1573 if [ "$cooklist" ]; then
1574 mv $tmp/dep $tmp/cooklist
1575 else
1576 cat $tmp/dep | sort -u
1577 fi
1578 rm -f $tmp/dep $tmp/list
1579 if [ "$check_db_status" ]; then
1580 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
1581 [ "$plan_sort_wandb" ] && sort -o $wan_db $wan_db && unset plan_sort_wandb
1582 if [ "$plan_regen_cookorder" ]; then
1583 grep -q "^#" $PACKAGES_REPOSITORY/cookorder.txt || \
1584 sed 1i"#PlanSort" -i $PACKAGES_REPOSITORY/cookorder.txt
1585 fi
1586 fi
1589 ########################################################################
1590 # This section contains functions to check package repository and
1591 # find which packages to cook.
1592 ########################
1594 check_for_missing()
1596 local PACKAGE
1597 if ! check_for_pkg_in_wok; then
1598 [ "$?" = 2 ] && return 1
1599 return
1600 fi
1601 RECEIPT=$WOK/$PACKAGE/receipt
1602 source_receipt
1603 PACKAGE=${WANTED:-$PACKAGE}
1604 update_wan_db
1605 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1606 RECEIPT=$WOK/$PACKAGE/receipt
1607 source_receipt
1608 update_dep_db
1609 done
1612 check_for_commit()
1614 if ! check_for_pkg_in_wok; then
1615 [ "$?" = 2 ] && return 1
1616 return
1617 fi
1618 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1619 RECEIPT=$WOK/$PACKAGE/receipt
1620 source_receipt
1622 # We use md5 of cooking stuff in the packaged receipt to check
1623 # commit. We look consecutively in 3 different locations :
1624 # - in the wok/PACKAGE/taz/* folder
1625 # - in the receipt in the package in incoming repository
1626 # - in the receipt in the package in packages repository
1627 # If md5sum match, there's no commit.
1628 check_for_commit_using_md5sum()
1630 if [ ! -f $WOK/$PACKAGE/md5 ]; then
1631 sed -n '/# md5sum of cooking stuff :/,$p' receipt | \
1632 sed -e 1d -e 's/^# //' > $WOK/$PACKAGE/md5
1633 cd $WOK/$PACKAGE
1634 fi
1636 if [ -s md5 ]; then
1637 if md5sum -cs md5; then
1639 # If md5sum check if ok, check for new/missing files in
1640 # cooking stuff.
1641 for file in $([ -f receipt ] && echo receipt; \
1642 [ -f description.txt ] && echo description.txt; \
1643 [ -d stuff ] && find stuff); do
1644 if ! fgrep -q " $file" md5; then
1645 set_commited
1646 fi
1647 done
1648 else
1649 set_commited
1650 fi
1651 else
1652 set_commited
1653 fi
1655 set_commited()
1657 ! grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/commit &&
1658 echo $PACKAGE >> $PACKAGES_REPOSITORY/commit
1659 gen_cookmd5
1660 update_dep_db
1662 taz_dir=$(echo $WOK/$PACKAGE/taz/$PACKAGE-* | fgrep -v '*')
1663 if [ -f $WOK/$PACKAGE/md5 ]; then
1664 cd $WOK/$PACKAGE
1665 check_for_commit_using_md5sum
1666 elif [ "$taz_dir" ]; then
1667 cd $taz_dir
1668 check_for_commit_using_md5sum
1669 else
1670 pkg=$(echo $INCOMING_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
1671 [ "$pkg" ] || pkg=$(echo $PACKAGES_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
1672 if [ "$pkg" ]; then
1673 get_pkg_files $pkg
1674 check_for_commit_using_md5sum
1675 rm -r $pkg_files_dir
1676 else
1677 set_commited
1678 fi
1679 fi
1680 [ "$forced" ] || echo $PACKAGE >> $tmp/checked
1681 done
1682 return
1685 gen_cook_list()
1687 report step "Scanning wok"
1688 if [ "$pkg" ]; then
1689 scan $pkg --cooklist
1690 else
1691 scan `cat $cooklist` --cooklist
1692 fi
1693 report end-step
1695 [ -s $tmp/checked ] || [ -s $tmp/cooklist ] || return
1696 if [ "$(sed 1!d $PACKAGES_REPOSITORY/cookorder.txt)" = "#PlanSort" ]; then
1697 sed 1d -i $PACKAGES_REPOSITORY/cookorder.txt
1698 plan_regen_cookorder=yes
1699 fi
1701 # Core toolchain should not be cooked unless cook-toolchain is used.
1702 if ! [ -f /etc/config.site.tmptoolchain ] ; then
1703 for PACKAGE in $(scan gcc --look_for=all --with_args --with_wanted); do
1704 grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/blocked || \
1705 echo $PACKAGE >> $PACKAGES_REPOSITORY/blocked
1706 done
1707 fi
1709 if [ -s $PACKAGES_REPOSITORY/commit ] && [ "$COMMAND" != gen-cooklist ]; then
1710 cd $PACKAGES_REPOSITORY
1711 for PACKAGE in $(cat commit); do
1712 WANTED="$(look_for_wanted)"
1713 if [ "$WANTED" ]; then
1714 grep -q ^$WANTED$ broken cooklist blocked commit && continue
1715 fi
1716 grep -q ^$PACKAGE$ blocked cooklist && continue
1717 echo $PACKAGE >> cooklist
1718 done
1719 fi
1720 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
1721 [ "$plan_regen_cookorder" ] && sort_db
1722 sort_cooklist
1725 sort_cooklist()
1727 report step "Sorting cooklist"
1728 if [ -f "$tmp/checked" ]; then
1729 rm -f $tmp/cooklist
1730 cat $tmp/checked | while read PACKAGE; do
1731 grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/cooklist && \
1732 echo $PACKAGE >> $tmp/cooklist
1733 done
1734 elif ! [ "$COMMAND" = gen-cooklist ]; then
1735 cat $PACKAGES_REPOSITORY/blocked | while read PACKAGE; do
1736 sed "/^$PACKAGE/d" -i $tmp/cooklist
1737 done
1738 fi
1740 for PACKAGE in $(cat $tmp/cooklist); do
1741 WANTED="$(look_for_wanted)"
1742 [ "$WANTED" ] || continue
1743 if grep -q ^$WANTED$ $PACKAGES_REPOSITORY/broken $tmp/cooklist; then
1744 sed "/^$PACKAGE$/d" -i $tmp/cooklist
1745 elif [ ! -d $WOK/$WANTED/install ]; then
1746 sed "/^$PACKAGE$/d" -i $tmp/cooklist
1747 echo $WANTED >> $tmp/cooklist
1748 fi
1749 done
1751 # Use cookorder.txt to sort cooklist.
1752 if [ -s $tmp/cooklist ]; then
1753 cat $PACKAGES_REPOSITORY/cookorder.txt | while read PACKAGE; do
1754 if grep -q ^$PACKAGE$ $tmp/cooklist; then
1755 sed "/^$PACKAGE$/d" -i $tmp/cooklist
1756 echo $PACKAGE >> $tmp/cooklist.tmp
1757 fi
1758 done
1760 # Remaining packages in cooklist are thoses without compile_rules.
1761 # They can be cooked first in any order.
1762 if [ -f $tmp/cooklist.tmp ]; then
1763 cat $tmp/cooklist.tmp >> $tmp/cooklist
1764 rm $tmp/cooklist.tmp
1765 fi
1767 cat $tmp/cooklist
1768 [ "$cooklist" = "$PACKAGES_REPOSITORY/cooklist" ] && \
1769 cat $tmp/cooklist > $cooklist
1770 fi
1772 report end-step
1775 check_for_incoming()
1777 [ -s $INCOMING_REPOSITORY/packages.desc ] || {
1778 echo "No packages in $INCOMING_REPOSITORY."
1779 return; }
1780 if [ -s $PACKAGES_REPOSITORY/broken ]; then
1781 echo "Don't move incoming packages to main repository because theses ones are broken:
1782 $(cat $PACKAGES_REPOSITORY/broken)" >&2
1783 return
1784 fi
1785 if [ -s $PACKAGES_REPOSITORY/cooklist ]; then
1786 echo "Don't move incoming packages to main repository because some of them need to be cooked:
1787 $(cat $PACKAGES_REPOSITORY/cooklist)" >&2
1788 return
1789 fi
1790 pkg="$(cut -f 1 -d '|' $INCOMING_REPOSITORY/packages.desc)"
1791 if ! [ "$forced" ]; then
1792 cooklist=$PACKAGES_REPOSITORY/cooklist
1793 gen_cook_list
1794 if [ -s $PACKAGES_REPOSITORY/cooklist ]; then
1795 echo "Don't move incoming packages to main repository because some of them need to be cooked." >&2
1796 return
1797 fi
1798 fi
1799 report step "Moving incoming packages to main repository"
1800 unset EXTRAVERSION
1801 for PACKAGE in $pkg; do
1802 prev_VERSION=$(get_pkg_version $PACKAGES_REPOSITORY)
1803 VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
1804 remove_previous_package $PACKAGES_REPOSITORY
1805 echo "Moving $PACKAGE..."
1806 mv -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION.tazpkg $PACKAGES_REPOSITORY
1807 touch $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
1808 done
1809 report end-step
1810 for file in packages.list packages.equiv packages.md5 packages.desc \
1811 packages.txt; do
1812 echo -n "" > $INCOMING_REPOSITORY/$file
1813 done
1814 rm -r $INCOMING_REPOSITORY/files.list.lzma
1815 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
1818 ########################################################################
1819 # TAZWOK MAIN FUNCTIONS
1820 ########################
1822 clean()
1824 cd $WOK/$PACKAGE
1825 ls -A $WOK/$PACKAGE | grep -q -v -e ^receipt$ -e ^description.txt$ \
1826 -e ^stuff$ || return
1828 [ "$COMMAND" = clean-wok ] || report step "Cleaning $PACKAGE"
1829 # Check for clean_wok function.
1830 if grep -q ^clean_wok $RECEIPT; then
1831 clean_wok
1832 fi
1833 # Clean should only have a receipt, stuff and optional desc.
1834 for f in `ls .`
1835 do
1836 case $f in
1837 receipt|stuff|description.txt|md5)
1838 continue ;;
1839 *)
1840 rm -rf $f
1841 esac
1842 done
1843 [ ! "$COMMAND" = clean-wok ] && report end-step
1846 # Configure and make a package with the receipt.
1847 compile_package()
1849 check_for_package_on_cmdline
1851 # Include the receipt to get all needed variables and functions
1852 # and cd into the work directory to start the work.
1853 check_for_receipt
1854 source_receipt
1856 # Log the package name and date.
1857 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
1858 echo "package $PACKAGE (compile)" >> $LOG
1860 # Set wanted $src variable to help compiling.
1861 [ ! "$src" ] && set_src_path
1862 check_for_build_depends || return 1
1863 check_for_wanted
1864 unset target
1865 check_for_tarball && check_for_compile_rules
1868 # Cook command also include all features to manage lists which keep
1869 # track of wok/packages state.
1870 cook()
1872 cook_code=
1873 set_common_path
1874 check_for_receipt
1875 source_receipt
1877 # Define log path and start report.
1878 [ -f $LOCAL_REPOSITORY/log/$PACKAGE.html ] && rm $LOCAL_REPOSITORY/log/$PACKAGE.html
1879 report sublog $LOCAL_REPOSITORY/log/$PACKAGE.html
1880 report step "Cooking $PACKAGE"
1881 report open-bloc
1883 clean $PACKAGE
1884 [ -s $tmp/cooklist ] && sed "/^$PACKAGE$/d" -i $tmp/cooklist
1886 if compile_package; then
1887 remove_src
1888 refresh_packages_from_compile
1889 gen_package
1891 # Update packages-incoming repository.
1892 store_pkgname=$PACKAGE
1893 pkg_repository=$INCOMING_REPOSITORY
1894 update_packages_db
1896 PACKAGE=$store_pkgname
1897 unset store_pkgname
1899 # Upgrade to cooked packages if it was previously installed.
1900 report step "Look for package(s) to upgrade"
1901 for pkg in $(look_for_rwanted) $PACKAGE; do
1902 if [ -d $INSTALLED/$pkg ]; then
1903 tazpkg get-install $pkg --forced
1904 fi
1905 done
1906 report end-step
1907 else
1909 # Set package as broken.
1910 if ! grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/broken; then
1911 echo $PACKAGE >> $PACKAGES_REPOSITORY/broken
1912 fi
1913 gen_cookmd5
1914 cook_code=1
1915 fi
1917 # Remove build_depends in cook mode (if in cooklist, it's done when
1918 # checking build_depends of next package and we remove only unneeded
1919 # packages to keep chroot minimal and gain some time).
1920 if [ "$COMMAND" = cook ]; then
1921 remove_build_depends $MISSING_PACKAGE
1922 [ -x /usr/bin/clean-chroot ] && clean-chroot
1923 fi
1925 # Regen the cooklist if it was planned and command is not cook.
1926 [ "$regen_cooklist" ] && unset regen_cooklist && \
1927 [ "$COMMAND" != cook ] && sort_cooklist
1929 # Some hacks to set the bloc & function status as failed if cook was
1930 # failed.
1931 report_return_code=$cook_code
1932 report close-bloc
1933 report end-sublog
1934 return $cook_code
1937 cook_list()
1939 if [ -s $tmp/cooklist ]; then
1940 if [ -f /usr/bin/tazchroot ]; then
1941 # Note : options -main variables- are automatically keeped by
1942 # the sub-applications tazchroot/tazwok; as well as report data.
1943 cd $LOCAL_REPOSITORY
1944 [ ! -f tazchroot.conf ] && configure_tazchroot
1945 tazchroot tazwok cook-list --SLITAZ_DIR=$SLITAZ_DIR --SLITAZ_VERSION=$SLITAZ_VERSION ${undigest:+ --undigest=$undigest}
1946 return
1947 fi
1948 while [ -s $tmp/cooklist ]; do
1949 PACKAGE=$(sed 1!d $tmp/cooklist)
1950 cook
1951 done
1952 remove_build_depends $MISSING_PACKAGE $remove_later
1953 [ -x /usr/bin/clean-chroot ] && clean-chroot
1954 else
1955 echo "Nothing to cook."
1956 return
1957 fi
1960 configure_tazchroot()
1962 cat > $LOCAL_REPOSITORY/tazchroot.conf << EOF
1963 # Tazchroot configuration file - created by tazwok.
1965 # Default chroot path
1966 SLITAZ_DIR=$SLITAZ_DIR
1967 SLITAZ_VERSION=$SLITAZ_VERSION
1968 $( [ "$undigest" ] && echo "undigest=$undigest" )
1969 LOCAL_REPOSITORY=$SLITAZ_DIR/$(if [ "$undigest" ]; then echo '$undigest'; else echo '$SLITAZ_VERSION'; fi)
1970 chroot_dir=\$LOCAL_REPOSITORY/chroot
1972 # Default scripts path (theses scripts are added in the
1973 # $chroot_dir/usr/bin and can be called with tazchroot script)
1974 script_dir=/var/lib/tazchroot
1976 # List of directories to mount.
1977 list_dir="$(for dir in packages wok src packages-incoming log flavors iso; do echo $LOCAL_REPOSITORY/$dir; done)
1978 $SLITAZ_LOG$( [ "$undigest" ] && echo -e "\n$SLITAZ_DIR/$SLITAZ_VERSION/packages" )"
1980 create_chroot()
1982 mkdir -p \$chroot_dir
1983 for pkg in \$(tazwok build-depends toolchain --SLITAZ_DIR=\$SLITAZ_DIR --SLITAZ_VERSION=\$SLITAZ_VERSION${undigest:+ --undigest=\$undigest}); do
1984 tazpkg get-install \$pkg --root="\$chroot_dir"
1985 done
1987 # Store list of installed packages needed by cleanchroot.
1988 ls -1 \$chroot_dir/\$INSTALLED > \$chroot_dir/\$LOCALSTATE/chroot-pkgs
1990 sed -e "s~^SLITAZ_DIR=.*~SLITAZ_DIR=\$SLITAZ_DIR~" \\
1991 -e "s/^SLITAZ_VERSION=.*/SLITAZ_VERSION=\$SLITAZ_VERSION/" \\
1992 -i \$chroot_dir/etc/slitaz/slitaz.conf
1993 $( [ "$undigest" ] && echo ' echo "undigest='"$undigest"'" >> $chroot_dir/etc/slitaz/tazwok.conf')
1994 sed 's/LC_ALL/LC_ALL=POSIX/' -i \$chroot_dir/etc/profile
1997 mount_chroot()
1999 cp -a /etc/resolv.conf \$chroot_dir/etc/resolv.conf
2000 echo "\$LOCAL_REPOSITORY/packages" > \$chroot_dir\$LOCALSTATE/mirror
2001 mkdir -p \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming
2002 echo "\$LOCAL_REPOSITORY/packages-incoming" > \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming/mirror
2003 $( [ "$undigest" ] && echo ' mkdir -p $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION
2004 echo "$SLITAZ_DIR/$SLITAZ_VERSION/packages" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror' )
2005 echo -e "\${LOCAL_REPOSITORY##*/}-incoming\nmain" > \$chroot_dir\$LOCALSTATE/priority
2006 mount -t proc proc \$chroot_dir/proc
2007 mount -t sysfs sysfs \$chroot_dir/sys
2008 mount -t devpts devpts \$chroot_dir/dev/pts
2009 mount -t tmpfs shm \$chroot_dir/dev/shm
2010 for dir in \$list_dir; do
2011 mkdir -p \$dir \$chroot_dir\$dir
2012 mount \$dir \$chroot_dir\$dir
2013 done
2016 umount_chroot()
2018 for dir in \$list_dir; do
2019 umount \$chroot_dir\$dir
2020 done
2021 umount \$chroot_dir/dev/shm
2022 umount \$chroot_dir/dev/pts
2023 umount \$chroot_dir/sys
2024 umount \$chroot_dir/proc
2026 EOF
2029 ########################################################################
2030 ######################### END OF NEW FUNCTIONS #########################
2031 ########################################################################
2033 # List packages providing a virtual package
2034 whoprovide()
2036 local i;
2037 for i in $(fgrep -l PROVIDE $WOK/*/receipt); do
2038 . $i
2039 case " $PROVIDE " in
2040 *\ $1\ *|*\ $1:*) echo $(basename $(dirname $i));;
2041 esac
2042 done
2045 ########################################################################
2046 # TAZWOK COMMANDS
2047 ########################
2049 case "$COMMAND" in
2050 stats)
2051 # Tazwok general statistics from the wok config file.
2053 get_tazwok_config
2054 echo -e "\n\033[1mTazwok configuration statistics\033[0m
2055 ================================================================================
2056 Wok directory : $WOK
2057 Packages repository : $PACKAGES_REPOSITORY
2058 Incoming repository : $INCOMING_REPOSITORY
2059 Sources repository : $SOURCES_REPOSITORY
2060 Log directory : $LOCAL_REPOSITORY/log
2061 Packages in the wok : `ls -1 $WOK | wc -l`
2062 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2063 Incoming packages : `ls -1 $INCOMING_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2064 ================================================================================\n"
2065 ;;
2066 edit)
2067 get_tazwok_config
2068 check_for_package_on_cmdline
2069 check_for_receipt
2070 $EDITOR $WOK/$PACKAGE/receipt
2071 ;;
2072 build-depends)
2073 # List dependencies to rebuild wok, or only a package
2074 get_tazwok_config
2075 report(){ : ; }
2076 if [ ! "$PACKAGE" ] || [ "$PACKAGE" = toolchain ]; then
2077 scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
2078 --look_for=dep --with_dev --with_args
2079 else
2080 check_for_package_on_cmdline
2081 scan $PACKAGE --look_for=bdep --with_dev
2082 fi
2083 ;;
2084 gen-cooklist)
2085 check_root
2086 get_options_list="pkg"
2087 get_tazwok_config
2088 report(){ : ; }
2089 if ! [ "$pkg" ]; then
2090 if [ ! "$LIST" ] || [ "$LIST" = toolchain ]; then
2091 pkg="$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA"
2092 else
2093 cooklist=${LIST:-$PACKAGES_REPOSITORY/cooklist}
2094 fi
2095 fi
2096 gen_cook_list
2097 ;;
2098 check-depends)
2099 # Check package depends /!\
2100 get_tazwok_config
2101 echo ""
2102 echo -e "\033[1mCheck every receipt for DEPENDS - doesn't scan ELF files\033[0m
2103 ================================================================================"
2104 TMPDIR=/tmp/tazwok$$
2105 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
2107 # Build ALL_DEPENDS variable
2108 scan_dep()
2110 local i
2111 ALL_DEPENDS="$ALL_DEPENDS$PACKAGE "
2112 for i in $DEPENDS $SUGGESTED ; do
2113 case " $ALL_DEPENDS " in
2114 *\ $i\ *) continue;;
2115 esac
2116 [ -d $WOK/$i ] || {
2117 ALL_DEPENDS="$ALL_DEPENDS$i "
2118 continue
2120 DEPENDS=""
2121 SUGGESTED=""
2122 . $WOK/$i/receipt
2123 scan_dep
2124 done
2127 # Check for ELF file
2128 is_elf()
2130 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" \
2131 = "ELF" ]
2134 # Print shared library dependencies
2135 ldd()
2137 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
2140 mkdir $TMPDIR
2141 cd $TMPDIR
2142 for i in $LOCALSTATE/files.list.lzma \
2143 $LOCALSTATE/undigest/*/files.list.lzma ; do
2144 [ -f $i ] && lzma d $i -so >> files.list
2145 done
2146 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
2147 tazpkg extract $pkg > /dev/null 2>&1
2148 . */receipt
2149 ALL_DEPENDS="$DEFAULT_DEPENDS "
2150 scan_dep
2151 find */fs -type f | while read file ; do
2152 is_elf $file || continue
2153 case "$file" in
2154 *.o|*.ko|*.ko.gz) continue;;
2155 esac
2156 ldd $file | while read lib rem; do
2157 case "$lib" in
2158 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
2159 continue;;
2160 esac
2161 for dep in $(fgrep $lib files.list | cut -d: -f1); do
2162 case " $ALL_DEPENDS " in
2163 *\ $dep\ *) continue 2;;
2164 esac
2165 for vdep in $(fgrep $dep $LOCALSTATE/packages.equiv | cut -d= -f1); do
2166 case " $ALL_DEPENDS " in
2167 *\ $vdep\ *) continue 3;;
2168 esac
2169 done
2170 done
2171 [ -n "$dep" ] || dep="UNKNOWN"
2172 echo "$(basename $pkg): ${file#*fs} depends on package $dep for the shared library $lib"
2173 done
2174 done
2175 rm -rf */
2176 done
2177 cd /tmp
2178 rm -rf $TMPDIR
2179 ;;
2180 check)
2181 # Check wok consistency
2182 get_tazwok_config
2183 echo ""
2184 echo -e "\033[1mWok and packages checking\033[0m
2185 ================================================================================"
2186 cd $WOK
2187 for pkg in $(ls)
2188 do
2189 [ -f $pkg/receipt ] || continue
2190 RECEIPT= $pkg/receipt
2191 source_receipt
2192 [ "$PACKAGE" = "$pkg" ] || echo "Package $PACKAGE should be $pkg" >&2
2193 [ -n "$VERSION" ] || echo "Package $PACKAGE has no VERSION" >&2
2194 [ -n "$PACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded PACKED_SIZE" >&2
2195 [ -n "$UNPACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded UNPACKED_SIZE" >&2
2196 [ -n "$EXTRAVERSION" ] && echo "Package $PACKAGE has hardcoded EXTRAVERSION" >&2
2197 if [ -n "$WANTED" ]; then
2198 if [ ! -f $WANTED/receipt ]; then
2199 echo "Package $PACKAGE wants unknown $WANTED package" >&2
2200 else
2201 BASEVERSION=$(. $WANTED/receipt ; echo $VERSION)
2202 if [ "$VERSION" = "$WANTED" ]; then
2203 # BASEVERSION is computed in receipt
2204 fgrep -q '_pkg=' $pkg/receipt &&
2205 BASEVERSION=$VERSION
2206 fi
2207 if [ "$VERSION" != "$BASEVERSION" ]; then
2208 echo "Package $PACKAGE ($VERSION) wants $WANTED ($BASEVERSION)" >&2
2209 fi
2210 fi
2211 fi
2213 if [ -n "$CATEGORY" ]; then
2214 case " $(echo $CATEGORIES) " in
2215 *\ $CATEGORY\ *);;
2216 *) echo "Package $PACKAGE has an invalid CATEGORY" >&2;;
2217 esac
2218 else
2219 echo"Package $PACKAGE has no CATEGORY" >&2
2220 fi
2221 [ -n "$SHORT_DESC" ] || echo "Package $PACKAGE has no SHORT_DESC" >&2
2222 [ -n "$MAINTAINER" ] || echo "Package $PACKAGE has no MAINTAINER" >&2
2223 case "$WGET_URL" in
2224 ftp*|http*) busybox wget -s $WGET_URL 2> /dev/null ||
2225 echo "Package $PACKAGE has a wrong WGET_URL" >&2;;
2226 '') ;;
2227 *) echo "Package $PACKAGE has an invalid WGET_URL" >&2;;
2228 esac
2229 case "$WEB_SITE" in
2230 ftp*|http*);;
2231 '') echo "Package $PACKAGE has no WEB_SITE" >&2;;
2232 *) echo "Package $PACKAGE has an invalid WEB_SITE" >&2;;
2233 esac
2234 case "$MAINTAINER" in
2235 *\<*|*\>*) echo "Package $PACKAGE has an invalid MAINTAINER: $MAINTAINER" >&2;;
2236 esac
2237 case "$MAINTAINER" in
2238 *@*);;
2239 *) echo "Package $PACKAGE MAINTAINER is not an email address" >&2;;
2240 esac
2241 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2242 for i in $DEPENDS; do
2243 [ -d $i ] && continue
2244 [ -n "$(whoprovide $i)" ] && continue
2245 echo -e "$MSG $i"
2246 MSG=""
2247 done
2248 MSG="Missing build dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2249 for i in $BUILD_DEPENDS; do
2250 [ -d $i ] && continue
2251 [ -n "$(whoprovide $i)" ] && continue
2252 echo -e "$MSG $i"
2253 MSG=""
2254 done
2255 MSG="Dependencies loop between $PACKAGE and :\n"
2256 ALL_DEPS=""
2257 check_for_deps_loop $PACKAGE $DEPENDS
2258 [ -d $WOK/$pkg/taz ] && for i in $BUILD_DEPENDS; do
2259 [ $WOK/$pkg/taz -nt $INSTALLED/$i/files.list ] && continue
2260 echo "$pkg should be rebuilt after $i installation"
2261 done
2262 done
2263 ;;
2264 list)
2265 # List packages in wok directory. User can specify a category.
2267 get_tazwok_config
2268 if [ "$2" = "category" ]; then
2269 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
2270 exit 0
2271 fi
2272 # Check for an asked category.
2273 if [ -n "$2" ]; then
2274 ASKED_CATEGORY=$2
2275 echo ""
2276 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
2277 echo "================================================================================"
2278 for pkg in $WOK/*
2279 do
2280 [ ! -f $pkg/receipt ] && continue
2281 . $pkg/receipt
2282 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
2283 echo -n "$PACKAGE"
2284 echo -e "\033[28G $VERSION"
2285 packages=$(($packages+1))
2286 fi
2287 done
2288 echo "================================================================================"
2289 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
2290 else
2291 # By default list all packages and version.
2292 echo ""
2293 echo -e "\033[1mList of packages in the wok\033[0m"
2294 echo "================================================================================"
2295 for pkg in $WOK/*
2296 do
2297 [ ! -f $pkg/receipt ] && continue
2298 . $pkg/receipt
2299 echo -n "$PACKAGE"
2300 echo -en "\033[28G $VERSION"
2301 echo -e "\033[42G $CATEGORY"
2302 packages=$(($packages+1))
2303 done
2304 echo "================================================================================"
2305 echo -e "$packages packages available in the wok.\n"
2306 fi
2307 ;;
2308 info)
2309 # Information about a package.
2311 get_tazwok_config
2312 check_for_package_on_cmdline
2313 check_for_receipt
2314 . $WOK/$PACKAGE/receipt
2315 echo ""
2316 echo -e "\033[1mTazwok package information\033[0m
2317 ================================================================================
2318 Package : $PACKAGE
2319 Version : $VERSION
2320 Category : $CATEGORY
2321 Short desc : $SHORT_DESC
2322 Maintainer : $MAINTAINER"
2323 if [ ! "$WEB_SITE" = "" ]; then
2324 echo "Web site : $WEB_SITE"
2325 fi
2326 if [ ! "$DEPENDS" = "" ]; then
2327 echo "Depends : $DEPENDS"
2328 fi
2329 if [ ! "$WANTED" = "" ]; then
2330 echo "Wanted src : $WANTED"
2331 fi
2332 echo "================================================================================"
2333 echo ""
2334 ;;
2335 check-log)
2336 # We just cat the file log to view process info.
2338 get_tazwok_config
2339 if [ ! -f "$LOG" ]; then
2340 echo -e "\nNo process log found. The package is probably not cooked.\n" >&2
2341 exit 1
2342 else
2343 echo ""
2344 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
2345 echo "================================================================================"
2346 cat $LOG
2347 echo "================================================================================"
2348 echo ""
2349 if [ -s "$WOK/$PACKAGE/warning.txt" ]; then
2350 echo -e "\033[1mCook warning(s) for :\033[0m $PACKAGE"
2351 echo "================================================================================"
2352 cat "$WOK/$PACKAGE/warning.txt"
2353 echo "================================================================================"
2354 echo ""
2355 fi
2356 fi
2357 ;;
2358 search)
2359 # Search for a package by pattern or name.
2361 get_tazwok_config
2362 if [ -z "$2" ]; then
2363 echo -e "\nPlease specify a pattern or a package name to search." >&2
2364 echo -e "Example : 'tazwok search gcc'.\n" >&2
2365 exit 1
2366 fi
2367 echo ""
2368 echo -e "\033[1mSearch result for :\033[0m $2"
2369 echo "================================================================================"
2370 list=`ls -1 $WOK | fgrep $2`
2371 for pkg in $list
2372 do
2373 . $WOK/$pkg/receipt
2374 echo -n "$PACKAGE "
2375 echo -en "\033[24G $VERSION"
2376 echo -e "\033[42G $CATEGORY"
2377 packages=$(($PACKAGEs+1))
2378 done
2379 echo "================================================================================"
2380 echo "$packages packages found for : $2"
2381 echo ""
2382 ;;
2383 compile)
2384 # Configure and make a package with the receipt.
2386 get_tazwok_config
2387 source_lib report
2388 report start
2389 compile_package
2390 ;;
2391 genpkg)
2392 # Generate a package.
2394 get_tazwok_config
2395 source_lib report
2396 report start
2397 gen_package
2398 ;;
2399 cook)
2400 # Compile and generate a package. Just execute tazwok with
2401 # the good commands.
2403 check_root
2404 get_tazwok_config
2405 source_lib report
2406 report start
2407 update_wan_db
2408 check_for_commit
2409 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
2410 [ "$plan_sort_wandb" ] && sort -o $wan_db $wan_db && unset plan_sort_wandb
2411 if [ "$plan_regen_cookorder" ]; then
2412 grep -q "^#" $PACKAGES_REPOSITORY/cookorder.txt || \
2413 sed 1i"#PlanSort" -i $PACKAGES_REPOSITORY/cookorder.txt
2414 fi
2415 cook
2416 ;;
2417 sort-cooklist)
2418 if [ ! "$LIST" ]; then
2419 echo "Usage : tazwok sort-cooklist cooklist" >&2\
2420 exit 1
2421 fi
2422 get_tazwok_config
2423 source_lib report
2424 report start
2425 cooklist=$LIST
2426 sort_cooklist
2427 cp -af $tmp/cooklist $cooklist
2428 ;;
2429 cook-list)
2430 # Cook all packages listed in a file or in default cooklist.
2431 check_root
2432 get_options_list="pkg forced"
2433 get_tazwok_config
2434 source_lib report
2435 report start
2436 if ! [ "$pkg" ]; then
2437 cooklist=${LIST:-$PACKAGES_REPOSITORY/cooklist}
2438 fi
2439 gen_cook_list
2440 cook_list
2441 ;;
2442 clean)
2443 # Clean up a package work directory + thoses which want it.
2445 get_tazwok_config
2446 check_for_package_on_cmdline
2447 check_for_receipt
2448 source_lib report
2449 report start
2450 . $RECEIPT
2451 clean
2452 ;;
2453 gen-clean-wok)
2454 # Generate a clean wok from the current wok by copying all receipts
2455 # and stuff directory.
2457 get_tazwok_config
2458 source_lib report
2459 report start
2460 if [ -z "$ARG" ]; then
2461 echo -e "\nPlease specify the destination for the new clean wok.\n" >&2
2462 exit 1
2463 else
2464 dest=$ARG
2465 mkdir -p $dest
2466 fi
2467 report step "Creating clean wok in : $dest"
2468 for pkg in `ls -1 $WOK`
2469 do
2470 mkdir -p $dest/$pkg
2471 cp -a $WOK/$pkg/receipt $dest/$pkg
2472 [ -f $WOK/$pkg/description.txt ] && \
2473 cp -a $WOK/$pkg/description.txt $dest/$pkg
2474 if [ -d "$WOK/$pkg/stuff" ]; then
2475 cp -a $WOK/$pkg/stuff $dest/$pkg
2476 fi
2477 done
2478 [ -d $WOK/.hg ] && cp -a $WOK/.hg $dest
2479 report end-step
2480 echo "Packages cleaned : `ls -1 $dest | wc -l`"
2481 echo ""
2482 ;;
2483 clean-wok)
2484 # Clean all packages in the work directory
2486 get_tazwok_config
2487 source_lib report
2488 report start
2489 report step "Cleaning wok"
2490 for PACKAGE in `ls -1 $WOK`
2491 do
2492 set_common_path
2493 source_receipt
2494 clean
2495 done
2496 echo "`ls -1 $WOK | wc -l` packages cleaned."
2497 ;;
2498 gen-list)
2499 get_tazwok_config
2500 if [ "$2" ]; then
2501 if [ -d "$2" ]; then
2502 pkg_repository=$2
2503 else
2504 echo -e "\nUnable to find directory : $2\n" >&2
2505 exit 1
2506 fi
2507 fi
2509 source_lib report
2510 report start
2511 if [ "$pkg_repository" ]; then
2512 gen_packages_db
2513 else
2514 pkg_repository=$PACKAGES_REPOSITORY && gen_packages_db
2515 pkg_repository=$INCOMING_REPOSITORY && gen_packages_db
2516 fi
2517 ;;
2518 check-list)
2519 # The directory to move into by default is the repository,
2520 # if $2 is not empty cd into $2.
2522 get_tazwok_config
2523 if [ "$2" ]; then
2524 if [ -d "$2" ]; then
2525 pkg_repository=$2
2526 else
2527 echo -e "\nUnable to find directory : $2\n" >&2
2528 exit 1
2529 fi
2530 fi
2532 source_lib report
2533 report start
2534 if [ "$pkg_repository" ]; then
2535 update_packages_db
2536 else
2537 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2538 pkg_repository=$INCOMING_REPOSITORY && update_packages_db
2539 fi
2540 ;;
2541 new-tree)
2542 # Just create a few directories and generate an empty receipt to prepare
2543 # the creation of a new package.
2545 get_tazwok_config
2546 check_for_package_on_cmdline
2547 if [ -d $WOK/$PACKAGE ]; then
2548 echo -e "\n$PACKAGE package tree already exists.\n" >&2
2549 exit 1
2550 fi
2551 echo "Creating : $WOK/$PACKAGE"
2552 mkdir $WOK/$PACKAGE
2553 cd $WOK/$PACKAGE
2554 echo -n "Preparing the receipt..."
2556 # Default receipt begin.
2558 echo "# SliTaz package receipt." > receipt
2559 echo "" >> receipt
2560 echo "PACKAGE=\"$PACKAGE\"" >> receipt
2561 # Finish the empty receipt.
2562 cat >> receipt << "EOF"
2563 VERSION=""
2564 CATEGORY=""
2565 SHORT_DESC=""
2566 MAINTAINER=""
2567 DEPENDS=""
2568 TARBALL="$PACKAGE-$VERSION.tar.gz"
2569 WEB_SITE=""
2570 WGET_URL=""
2572 # Rules to configure and make the package.
2573 compile_rules()
2575 cd $src
2576 ./configure && make && make install
2579 # Rules to gen a SliTaz package suitable for Tazpkg.
2580 genpkg_rules()
2582 mkdir -p $fs/usr
2583 cp -a $_pkg/usr/bin $fs/usr
2586 EOF
2588 # Default receipt end.
2590 status
2591 # Interactive mode, asking and seding.
2592 if [ "$3" = "--interactive" ]; then
2593 echo "Entering into interactive mode..."
2594 echo "================================================================================"
2595 echo "Package : $PACKAGE"
2596 # Version.
2597 echo -n "Version : " ; read anser
2598 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
2599 # Category.
2600 echo -n "Category : " ; read anser
2601 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
2602 # Short description.
2603 echo -n "Short desc : " ; read anser
2604 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
2605 # Maintainer.
2606 echo -n "Maintainer : " ; read anser
2607 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
2608 # Web site.
2609 echo -n "Web site : " ; read anser
2610 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
2611 echo ""
2612 # Wget URL.
2613 echo "Wget URL to download source tarball."
2614 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
2615 echo -n "Wget url : " ; read anser
2616 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
2617 # Ask for a stuff dir.
2618 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
2619 if [ "$anser" = "y" ]; then
2620 echo -n "Creating the stuff directory..."
2621 mkdir stuff && status
2622 fi
2623 # Ask for a description file.
2624 echo -n "Are you going to write a description ? (y/N) : " ; read anser
2625 if [ "$anser" = "y" ]; then
2626 echo -n "Creating the description.txt file..."
2627 echo "" > description.txt && status
2628 fi
2629 echo "================================================================================"
2630 echo ""
2631 fi
2632 ;;
2633 remove)
2634 # Remove a package from the wok.
2636 get_tazwok_config
2637 check_for_package_on_cmdline
2638 echo ""
2639 echo -n "Please confirm deletion (y/N) : "; read anser
2640 if [ "$anser" = "y" ]; then
2641 echo -n "Removing $PACKAGE..."
2642 rm -rf $WOK/$PACKAGE && status
2643 echo ""
2644 fi
2645 ;;
2646 hgup)
2647 # Pull and update a Hg wok.
2648 get_tazwok_config
2649 if ls -l $WOK/.hg/hgrc | fgrep -q "root"; then
2650 check_root
2651 fi
2652 cd $WOK
2653 hg pull && hg update
2654 ;;
2655 maintainers)
2656 get_tazwok_config
2657 echo ""
2658 echo "List of maintainers for: $WOK"
2659 echo "================================================================================"
2660 touch /tmp/slitaz-maintainers
2661 for pkg in $WOK/*
2662 do
2663 . $pkg/receipt
2664 if ! fgrep -q "$MAINTAINER" /tmp/slitaz-maintainers; then
2665 echo "$MAINTAINER" >> /tmp/slitaz-maintainers
2666 echo "$MAINTAINER"
2667 fi
2668 done
2669 echo "================================================================================"
2670 echo "Maintainers: `cat /tmp/slitaz-maintainers | wc -l`"
2671 echo ""
2672 # Remove tmp files
2673 rm -f /tmp/slitaz-maintainers
2674 ;;
2675 maintained-by)
2676 # Search for packages maintained by a contributor.
2677 get_tazwok_config
2678 if [ ! -n "$2" ]; then
2679 echo "Specify a name or email of a maintainer." >&2
2680 exit 1
2681 fi
2682 echo "Maintainer packages"
2683 echo "================================================================================"
2684 for pkg in $WOK/*
2685 do
2686 . $pkg/receipt
2687 if echo "$MAINTAINER" | fgrep -q "$2"; then
2688 echo "$PACKAGE"
2689 packages=$(($PACKAGEs+1))
2690 fi
2691 done
2692 echo "================================================================================"
2693 echo "Packages maintained by $2: $PACKAGEs"
2694 echo ""
2695 ;;
2696 check-src)
2697 # Verify if upstream package is still available
2699 get_tazwok_config
2700 check_for_package_on_cmdline
2701 check_for_receipt
2702 source_receipt
2703 check_src()
2705 for url in $@; do
2706 busybox wget -s $url 2>/dev/null && break
2707 done
2709 if [ "$WGET_URL" ];then
2710 echo -n "$PACKAGE : "
2711 check_src $WGET_URL
2712 status
2713 else
2714 echo "No tarball to check for $PACKAGE"
2715 fi
2716 ;;
2717 get-src)
2718 check_root
2719 get_options_list="target nounpack"
2720 get_tazwok_config
2721 check_for_package_on_cmdline
2722 check_for_receipt
2723 source_receipt
2724 if [ "$WGET_URL" ];then
2725 source_lib report
2726 report start
2727 check_for_tarball
2728 else
2729 echo "No tarball to download for $PACKAGE"
2730 fi
2731 ;;
2732 check-commit)
2733 check_root
2734 get_options_list="missing forced"
2735 get_tazwok_config
2736 source_lib report
2737 report start
2738 if [ "$forced" ]; then
2739 rm -f $WOK/*/md5
2740 unset forced
2741 fi
2742 if [ "$missing" ]; then
2743 pkg=$(ls -1 $WOK)
2744 else
2745 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
2746 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
2747 } | sort -u)"
2748 fi
2749 cooklist=$PACKAGES_REPOSITORY/cooklist
2750 gen_cook_list
2751 ;;
2752 cook-commit)
2753 check_root
2754 get_options_list="missing forced"
2755 get_tazwok_config
2756 source_lib report
2757 report start
2758 if [ "$forced" ]; then
2759 rm -f $WOK/*/md5
2760 unset forced
2761 fi
2762 if [ "$missing" ]; then
2763 pkg=$(ls -1 $WOK)
2764 else
2765 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
2766 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
2767 } | sort -u)"
2768 fi
2769 cooklist=$PACKAGES_REPOSITORY/cooklist
2770 gen_cook_list
2771 cook_list
2772 ;;
2773 cook-all)
2774 check_root
2775 get_options_list="forced missing"
2776 get_tazwok_config
2777 source_lib report
2778 report start
2779 if [ "$missing" ]; then
2780 pkg=$(ls -1 $WOK)
2781 else
2782 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
2783 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
2784 } | sort -u)"
2785 fi
2786 cooklist=$PACKAGES_REPOSITORY/cooklist
2787 gen_cook_list
2788 cook_list
2789 ;;
2790 gen-wok-db)
2791 check_root
2792 get_tazwok_config
2793 source_lib report
2794 report start
2795 gen_wok_db
2796 ;;
2797 report)
2798 check_root
2799 get_tazwok_config
2800 cd $PACKAGES_REPOSITORY
2801 if [ "$2" ]; then
2802 case $2 in
2803 commit|cooklist|incoming|broken|blocked)
2804 show="$2"
2805 ;;
2806 *)
2807 echo "usage : tazwok report [commit|cooklist|incoming|broken|blocked]" >&2
2808 exit 1
2809 ;;
2810 esac
2811 else
2812 show="commit cooklist incoming broken blocked"
2813 fi
2814 for i in $show; do
2815 if [ -s $i ]; then
2816 echo ""
2817 echo -e "\033[1m$i\033[0m"
2818 echo "================================================================================"
2819 cat $i
2820 echo "================================================================================"
2821 echo ""
2822 fi
2823 done
2824 ;;
2825 check-incoming)
2826 check_root
2827 get_options_list="forced"
2828 get_tazwok_config
2829 source_lib report
2830 report start
2831 check_for_incoming
2832 ;;
2833 configure-chroot)
2834 check_root
2835 get_tazwok_config
2836 if [ -f /usr/bin/tazchroot ]; then
2837 cd $LOCAL_REPOSITORY
2838 configure_tazchroot
2839 else
2840 echo "The packages tazchroot need to be installed" >&2
2841 exit 1
2842 fi
2843 ;;
2844 chroot)
2845 check_root
2846 get_tazwok_config
2847 # Merge this and the other chroot function ?.
2848 if [ -f /usr/bin/tazchroot ]; then
2849 cd $LOCAL_REPOSITORY
2850 [ ! -f tazchroot.conf ] && configure_tazchroot
2851 tazchroot
2852 else
2853 echo "The packages tazchroot need to be installed" >&2
2854 exit 1
2855 fi
2856 ;;
2857 cook-toolchain)
2858 check_root
2859 get_tazwok_config
2860 echo -n "" > $PACKAGES_REPOSITORY/broken
2861 if [ -f /usr/bin/tazchroot ]; then
2862 cd $LOCAL_REPOSITORY
2863 [ ! -f tazchroot.conf ] && configure_tazchroot
2864 tazchroot cook-toolchain
2865 # Buggy : chroot can be elsewhere.
2866 rm -r $LOCAL_REPOSITORY/chroot
2867 # /!\ to be writed :
2868 # next rm chroot and plan cook-all by pushing all packages
2869 # in cooklist.
2870 else
2871 echo "The packages tazchroot need to be installed" >&2
2872 exit 1
2873 fi
2874 ;;
2875 webserver)
2876 check_root
2877 get_tazwok_config
2878 if [ "$ARG" = on ]; then
2879 if [ "$WEBSERVER" ] && [ -f "$WEBSERVER/repositories.list" ] && \
2880 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
2881 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
2882 exit 1
2883 fi
2884 if ! [ -f $LOCAL_REPOSITORY/tazchroot.conf ]; then
2885 tazwok configure-chroot ${undigest:+--undigest=$undigest} --SLITAZ_VERSION=$SLITAZ_VERSION --SLITAZ_DIR=$SLITAZ_DIR
2886 fi
2887 for pkg in php lighttpd; do
2888 [ -d $INSTALLED/$pkg ] || missing="$missing $pkg"
2889 done
2890 if [ "$missing" ]; then
2891 echo "You need to install those packages to start webserver: $missing." >&2
2892 exit 1
2893 fi
2894 if [ ! -f "$LOCAL_REPOSITORY/tazwok.conf" ]; then
2895 echo "Copying /etc/slitaz/tazwok.conf to $LOCAL_REPOSITORY/tazwok.conf: webserver is configured repository-by-repository."
2896 cp /etc/slitaz/tazwok.conf $LOCAL_REPOSITORY
2897 fi
2898 if ! [ "$WEBSERVER" ]; then
2899 echo -n "Where to store php pages (default: /var/www/vhosts/bb)? "
2900 read WEBSERVER
2901 [ "$WEBSERVER" ] || WEBSERVER="/var/www/vhosts/bb"
2902 fi
2903 if [ -f "$WEBSERVER/repositories.list" ] && \
2904 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
2905 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
2906 exit 1
2907 fi
2908 mkdir -p $WEBSERVER
2909 echo "${undigest:-$SLITAZ_VERSION}" >> $WEBSERVER/repositories.list
2910 for file in index.php log.php; do
2911 [ -f "$WEBSERVER/$file" ] || ln -s /usr/share/slitaz/web-bb/$file $WEBSERVER
2912 done
2913 source $LOCAL_REPOSITORY/tazchroot.conf
2914 echo "<?php
2916 // Web interface configuration
2918 \$version=\"${undigest:-$SLITAZ_VERSION}\";
2919 \$chroot=\"$chroot_dir\";
2920 \$lockfile=\"\$chroot/proc/1\";
2921 \$db_dir=\"$PACKAGES_REPOSITORY\";
2922 \$log_dir=\"$LOCAL_REPOSITORY/log\";
2923 \$packages=\"$PACKAGES_REPOSITORY\";
2924 \$incoming=\"$INCOMING_REPOSITORY\";
2925 \$wok=\"$WOK\";
2927 ?>" > $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
2928 [ -L "$WEBSERVER/web" ] || ln -s /usr/share/slitaz/web $WEBSERVER
2929 echo "WEBSERVER=\"$WEBSERVER\"" >> $LOCAL_REPOSITORY/tazwok.conf
2930 if [ -L "$WEBSERVER/conf.php" ]; then
2931 echo "Do yo want to make ${undigest:-$SLITAZ_VERSION} the default page (y/N) ? "
2932 read answer
2933 if [ "$answer" = y ]; then
2934 rm $WEBSERVER/conf.php
2935 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
2936 fi
2937 else
2938 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
2939 fi
2940 elif [ "$ARG" = off ]; then
2941 if ! [ "$WEBSERVER" ]; then
2942 echo "No webserver running for ${undigest:-$SLITAZ_VERSION}" >&2
2943 exit 1
2944 fi
2945 sed '/^WEBSERVER/d' -i $LOCAL_REPOSITORY/tazwok.conf
2946 sed "/^${undigest:-$SLITAZ_VERSION}$/d" -i $WEBSERVER/repositories.list
2947 rm $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
2948 if ! [ -s "$WEBSERVER/repositories.list" ]; then
2949 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"
2950 rm $WEBSERVER/conf.php
2951 elif [ "$(readlink $WEBSERVER/conf.php)" = "$WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php" ]; then
2952 echo "${undigest:-$SLITAZ_VERSION} was the default version to use; switched to : $(sed 1!d $WEBSERVER/repositories.list)"
2953 rm $WEBSERVER/conf.php
2954 ln -s $WEBSERVER/conf-$(sed 1!d $WEBSERVER/repositories.list).php $WEBSERVER/conf.php
2955 fi
2956 else
2957 echo "Usage: tazwok webserver on/off" >&2
2958 exit 1
2959 fi
2960 ;;
2961 usage|*)
2962 # Print usage also for all unknown commands.
2964 usage
2965 ;;
2966 esac
2968 report stop 2>/dev/null || exit 0