tazwok view tazwok @ rev 246

Moving another report end-step to good location
author Antoine Bodin <gokhlayeh@slitaz.org>
date Sat Feb 12 02:33:51 2011 +0100 (2011-02-12)
parents 321c5e6f8d27
children 9cc115298e1a
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 if [ "$WGET_URL" ]; then
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/$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" ]; 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
471 fi
473 if [ -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ] && [ "$nounpack" ]; then
474 return
475 fi
477 # Untaring source if necessary. We don't need to extract source if
478 # the package is built with a wanted source package.
479 if [ "$WANTED" ]; then
480 return
481 fi
483 report step "Untaring source tarball"
484 if [ "$target" ]; then
485 src="$target"
486 else
487 set_src_path
488 fi
490 # Log process.
491 echo "untaring source tarball" >> $LOG
493 tmp_src=$WOK/$PACKAGE/tmp-src-$$
494 mkdir $tmp_src
495 if [ -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
496 lzma d $SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma -so | \
497 tar xf - -C $tmp_src
498 elif [ -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
499 case "$TARBALL" in
500 *zip|*xpi) { cd $tmp_src; unzip -o $SOURCES_REPOSITORY/$TARBALL; };;
501 *bz2) tar xjf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
502 *tar) tar xf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
503 *lzma) unlzma -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
504 *xz) unxz -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
505 *Z) uncompress -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
506 *) tar xzf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
507 esac || return 1
509 # Check if uncompressed tarball is in a root dir or not.
510 if [ "$(ls -A $tmp_src | wc -l)" -gt 1 ]; then
511 if check_for_var_modification src _pkg; then
512 mv $tmp_src $tmp_src-1
513 mkdir $tmp_src
514 mv $tmp_src-1 $tmp_src/${SOURCE:-$PACKAGE}-$VERSION
515 else
516 mv $tmp_src/* $WOK/$PACKAGE
517 repack_src=no
518 rm -r $tmp_src
519 fi
520 fi
522 if [ "$repack_src" = yes ]; then
523 report step "Repacking sources in .tar.lzma format"
524 cd $tmp_src
525 tar -c * | lzma e $SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma -si
526 rm $SOURCES_REPOSITORY/$TARBALL
527 prev_VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
529 # Remove previous tarball if it's not used either by
530 # incoming and legacy packages.
531 [ "$prev_VERSION" != "$(get_pkg_version $PACKAGES_REPOSITORY)" ] && \
532 remove_previous_tarball
533 report end-step
534 fi
535 fi
536 if [ "$nounpack" ]; then
537 [ -d "$tmp_src" ] && rm -r $tmp_src
538 return
539 fi
540 if [ "$TARBALL" ]; then
541 if [ ! -d "$src" ]; then
542 if [ -d "$tmp_src" ]; then
543 if ! check_for_var_modification src _pkg; then
544 src="${src%/*}/$(ls $tmp_src)"
545 fi
546 mv $(echo $tmp_src/*) "$src"
547 rm -r $tmp_src
549 # Permissions settings.
550 chown -R root.root "$src"
551 fi
552 else
553 echo "There's already something at $src. Abort." >&2
554 fi
555 fi
556 }
558 # Log and execute compile_rules function if it exists, to configure and
559 # make the package if it exists.
560 check_for_compile_rules()
561 {
562 if grep -q ^compile_rules $RECEIPT; then
563 echo "executing compile_rules" >> $LOG
564 report step "Executing compile_rules"
565 cd $WOK/$PACKAGE
566 rm -f /tmp/config.site
568 # Free some RAM by cleaning cache if option is enabled.
569 freeram=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
571 # Disable -pipe in CFLAGS/CXXFLAGS if less than 512Mb of free
572 # RAM are available.
573 if [ "$freeram" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" -o \
574 "$CXXFLAGS" != "${CXXFLAGS/-pipe}" ]; then
575 tazwok_warning "Disabling -pipe compile flag because only ${freeram}b of RAM are available."
576 CFLAGS="${CFLAGS/-pipe}"
577 CXXFLAGS="${CXXFLAGS/-pipe}"
578 fi
579 unset freeram
581 # Set cook environnement variables.
582 [ "$src" ] || set_src_path
583 [ "$DESTDIR" ] || DESTDIR="$WOK/$PACKAGE/install"
584 [ "$CONFIG_SITE" ] || CONFIG_SITE=/etc/config.site
585 export CFLAGS CXXFLAGS MAKEFLAGS DESTDIR BUILD_HOST \
586 CONFIG_SITE default_prefix \
587 default_datarootdir default_datadir default_localedir \
588 default_infodir default_mandir default_build default_host
589 local LC_ALL=POSIX LANG=POSIX
590 compile_rules
592 # Check if config.site has been used.
593 # /!\ disabled since it screw the return_code of the step.
594 #if [ -f /tmp/config.site ]; then
595 # rm /tmp/config.site
596 #else
597 # tazwok_warning "config.site hasn't been used during \
598 #configuration process."
599 #fi
601 report end-step
602 fi
603 }
605 # Check for loop in deps tree. /!\ can be removed
606 check_for_deps_loop()
607 {
608 local list
609 local pkg
610 local deps
611 pkg=$1
612 shift
613 [ -n "$1" ] || return
614 list=""
616 # Filter out already processed deps
617 for i in $@; do
618 case " $ALL_DEPS" in
619 *\ $i\ *);;
620 *) list="$list $i";;
621 esac
622 done
623 ALL_DEPS="$ALL_DEPS$list "
624 for i in $list; do
625 [ -f $i/receipt ] || continue
626 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
627 case " $deps " in
628 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
629 *) check_for_deps_loop $pkg $deps;;
630 esac
631 done
632 }
634 download()
635 {
636 for file in $@; do
637 wget -q $file && break
638 done
639 }
641 # Regenerate every package that wants a PACKAGE compiled
642 refresh_packages_from_compile()
643 {
644 # make tazwok genpkg happy
645 mkdir $WOK/$PACKAGE/taz
647 # Cook rwanted in default or specied order
648 genlist=" $(look_for_rwanted | tr '\n' ' ') "
649 for i in $(look_for_cookopt genpkg | tac); do
650 [ "${genlist/ $i }" = "$genlist" ] && continue
651 genlist=" $i${genlist/ $i / }"
652 done
653 if [ "$genlist" ]; then
654 local PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
655 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
656 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
657 src _pkg DESTDIR CONFIG_SITE RECEIPT LOG
658 for PACKAGE in $genlist; do
659 set_common_path
660 gen_package
661 done
662 fi
663 }
665 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
666 # so some packages need to copy these files with the receipt and genpkg_rules.
667 # This function is executed by gen_package when 'tazwok genpkg'.
668 copy_generic_files()
669 {
670 # In most cases, locales are in $_pkg/usr/share/locale so we copy files
671 # using generic variables and $LOCALE from Tazwok config file.
672 if [ "$LOCALE" ]; then
673 if [ -d "$_pkg/usr/share/locale" ]; then
674 for i in $LOCALE
675 do
676 if [ -d "$_pkg/usr/share/locale/$i" ]; then
677 mkdir -p $fs/usr/share/locale
678 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
679 fi
680 done
681 fi
682 fi
684 # Pixmaps (PNG or/and XPM only). Some icons/images can be added through
685 # genpkg_rules and generic copy can be disabled with GENERIC_PIXMAPS="no"
686 # in pkg receipt.
687 if [ "$GENERIC_PIXMAPS" != "no" ]; then
688 if [ -d "$_pkg/usr/share/pixmaps" ]; then
689 mkdir -p $fs/usr/share/pixmaps
690 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
691 $fs/usr/share/pixmaps 2>/dev/null
692 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
693 $fs/usr/share/pixmaps 2>/dev/null
694 fi
696 # Custom or homemade PNG pixmap can be in stuff.
697 if [ -f "stuff/$PACKAGE.png" ]; then
698 mkdir -p $fs/usr/share/pixmaps
699 cp -a stuff/$PACKAGE.png $fs/usr/share/pixmaps
700 fi
701 fi
703 # Desktop entry (.desktop).
704 if [ -d "$_pkg/usr/share/applications" ]; then
705 cp -a $_pkg/usr/share/applications $fs/usr/share
706 fi
708 # Homemade desktop file(s) can be in stuff.
709 if [ -d "stuff/applications" ]; then
710 mkdir -p $fs/usr/share
711 cp -a stuff/applications $fs/usr/share
712 fi
713 if [ -f "stuff/$PACKAGE.desktop" ]; then
714 mkdir -p $fs/usr/share/applications
715 cp -a stuff/$PACKAGE.desktop $fs/usr/share/applications
716 fi
717 }
719 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
720 strip_package()
721 {
722 report step "Executing strip on all files"
724 # Binaries.
725 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
726 do
727 if [ -d "$dir" ]; then
728 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
729 fi
730 done
732 # Libraries.
733 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
734 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
735 report end-step
736 }
738 # Remove .pyc and .pyo files from packages
739 py_compiled_files_remove()
740 {
741 report step "Removing all .pyc and .pyo files from package ..."
742 find $fs -type f -name "*.pyc" -delete 2>/dev/null
743 find $fs -type f -name "*.pyo" -delete 2>/dev/null
744 report end-step
745 }
747 # Check FSH in a slitaz package (Path: /:/usr)
748 check_fsh()
749 {
750 cd $WOK/$PACKAGE/taz/*/fs
751 [ -n "$FSH" ] || FSH="bin boot dev etc home init lib media mnt proc \
752 root sbin share sys tmp usr var vz usr/bin usr/games usr/include usr/lib \
753 usr/local usr/sbin usr/share usr/src"
754 for i in `ls -d * usr/* 2>/dev/null`
755 do
756 if ! echo $FSH | fgrep -q $i; then
757 echo "Wrong path: /$i" >&2
758 error=1
759 fi
760 done
761 if [ "$error" = "1" ]; then
762 cat << _EOT_
764 Package will install files in a non standard directory and won't be generated.
765 You may have a wrong copy path in genpkg_rules or need to add some options to
766 configure in compile_rules. Some valid options for SliTaz (Linux FSH):
768 --prefix=/usr
769 --sysconfdir=/etc
770 --libexecdir=/usr/lib/(pkgname)
771 --localstatedir=/var
772 --mandir=/usr/share/man
773 --infodir=/usr/share/info
775 For more information please read SliTaz docs and run: ./configure --help
776 ================================================================================
777 $PACKAGE package generation aborted.
779 _EOT_
781 # Dont generate a corrupted package.
782 cd $WOK/$PACKAGE && rm -rf taz
783 report exit
784 fi
785 }
787 gen_cookmd5()
788 {
789 # md5sum of cooking stuff make tazwok able to check for changes
790 # without hg.
791 cd $WOK/$PACKAGE
792 md5sum receipt > md5
793 [ -f description.txt ] && md5sum description.txt >> md5
794 if [ -d stuff ]; then
795 find stuff | while read file; do
796 md5sum $file >> md5
797 done
798 fi
799 }
801 # Create a package tree and build the gziped cpio archive
802 # to make a SliTaz (.tazpkg) package.
803 gen_package()
804 {
805 check_root
806 check_for_package_on_cmdline
807 check_for_receipt
808 EXTRAVERSION=""
809 . $RECEIPT
811 # May compute VERSION
812 if grep -q ^get_version $RECEIPT; then
813 get_version
814 fi
815 check_for_wanted
816 cd $WOK/$PACKAGE
818 # Remove old Tazwok package files.
819 [ -d "taz" ] && rm -rf taz
821 # Create the package tree and set useful variables.
822 mkdir -p taz/$PACKAGE-$VERSION/fs
823 fs=taz/$PACKAGE-$VERSION/fs
825 # Set $src for standard package and $_pkg variables.
826 set_src_path && set_pkg_path
828 # Execute genpkg_rules, check package and copy generic files to build
829 # the package.
830 report step "Building $PACKAGE with the receipt"
831 report open-bloc
832 if grep -q ^genpkg_rules $RECEIPT; then
834 # Log process.
835 echo "executing genpkg_rules" >> $LOG
836 report step "Executing genpkg_rules"
837 genpkg_rules
838 report end-step
839 check_fsh
840 cd $WOK/$PACKAGE
842 # Skip generic files for packages with a WANTED variable
843 # (dev and splited pkgs).
844 if [ ! "$WANTED" ]; then
845 copy_generic_files
846 fi
847 look_for_cookopt !strip || strip_package
848 py_compiled_files_remove
849 else
850 echo "No package rules to gen $PACKAGE..." >&2
851 report exit
852 fi
854 # Copy the receipt and description (if exists) into the binary package tree.
855 cd $WOK/$PACKAGE
856 report step "Copying the receipt"
857 cp receipt taz/$PACKAGE-$VERSION
858 report end-step
859 if grep -q ^get_version $RECEIPT; then
860 report step "Updating version in receipt"
861 sed -i "s/^VERSION=.*/VERSION=\"$VERSION\"/" \
862 taz/$PACKAGE-$VERSION/receipt
863 report end-step
864 fi
865 if [ -f "description.txt" ]; then
866 report step "Copying the description file"
867 cp description.txt taz/$PACKAGE-$VERSION
868 report end-step
869 fi
871 # Generate md5 of cooking stuff to look for commit later.
872 gen_cookmd5
873 echo -e "\n# md5sum of cooking stuff :" >> taz/$PACKAGE-$VERSION/receipt
874 cat md5 | sed 's/^/# /' >> taz/$PACKAGE-$VERSION/receipt
876 # Create the files.list by redirecting find output.
877 report step "Creating the list of files"
878 cd taz/$PACKAGE-$VERSION
879 LAST_FILE=""
880 { find fs -print; echo; } | while read file; do
881 if [ "$LAST_FILE" ]; then
882 case "$file" in
883 $LAST_FILE/*)
884 case "$(ls -ld "$LAST_FILE")" in
885 drwxr-xr-x\ *\ root\ *\ root\ *);;
886 *) echo ${LAST_FILE#fs};;
887 esac;;
888 *) echo ${LAST_FILE#fs};;
889 esac
890 fi
891 LAST_FILE="$file"
892 done > files.list
894 # Next, check if something has changed in lib files.
895 if fgrep -q '.so' files.list; then
896 report step "Look for major/minor update in libraries"
897 for rep in $INCOMING_REPOSITORY $PACKAGES_REPOSITORY \
898 $([ "$undigest" ] && echo SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming && \
899 echo $SLITAZ_DIR/$SLITAZ_VERSION/packages); do
900 prev_VERSION=$(get_pkg_version $rep)
901 [ "$prev_VERSION" ] && pkg_file=$rep/$PACKAGE-$prev_VERSION.tazpkg && break
902 done
903 if [ "$pkg_file" ]; then
904 get_pkg_files $pkg_file
905 cd $WOK/$PACKAGE/taz/$PACKAGE-$VERSION
906 fgrep ".so" files.list | egrep -v "[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*" | \
907 while read lib; do
908 fgrep -q "$lib" $pkg_files_dir/files.list && continue
909 echo "A minor/major update in libraries is detected, planning re-cook of reverse-depends of $PACKAGE."
910 for rdep in $(scan $PACKAGE --look_for=rdep | use_wanted); do
911 [ "$rdep" = "${WANTED:-$PACKAGE}" ] && continue
912 grep -q ^$rdep$ $PACKAGES_REPOSITORY/blocked \
913 $PACKAGES_REPOSITORY/cooklist && continue
914 echo $rdep >> $PACKAGES_REPOSITORY/cooklist
915 done
916 regen_cooklist=yes
917 break
918 done
919 rm -r $pkg_files_dir
920 fi
921 report end-step
922 fi
923 if [ ! "$EXTRAVERSION" ]; then
924 case "$PACKAGE" in
925 linux*);;
926 *) EXTRAVERSION="$(grep '/lib/modules/.*-slitaz/' files.list |\
927 head -1 | sed 's|/lib/modules/\(.*\)-slitaz/.*|_\1|')";;
928 esac
929 fi
930 rm -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg 2> /dev/null
931 report step "Creating md5sum of files"
932 while read file; do
933 [ -L "fs$file" ] && continue
934 [ -f "fs$file" ] || continue
935 md5sum "fs$file" | sed 's/ fs/ /'
936 done < files.list > md5sum
937 report end-step
938 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
939 2> /dev/null | awk '{ sz=$1 } END { print sz }')
941 # Build cpio archives. Find, cpio and gzip the fs, finish by
942 # removing the fs tree.
943 # Don't log this because compression always output error messages.
944 find fs -print | cpio -o -H newc | case "$PACKAGE-$COMPRESSION" in
945 tazpkg-lzma) gzip > fs.cpio.gz;;
946 *-lzma) lzma e fs.cpio.lzma -si;;
947 *) gzip > fs.cpio.gz;;
948 esac && rm -rf fs
949 PACKED_SIZE=$(du -chs fs.cpio.* receipt files.list md5sum \
950 description.txt 2> /dev/null | awk '{ sz=$1 } END { print sz }')
951 report step "Updating receipt sizes"
952 sed -i '/^PACKED_SIZE/d' receipt
953 sed -i '/^UNPACKED_SIZE/d' receipt
954 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
955 sed -i "s/^VERSION=$/VERSION=\"$VERSION\"/" receipt
956 report end-step
957 if [ "$EXTRAVERSION" ]; then
958 report step "Updating receipt EXTRAVERSION"
959 sed -i s/^EXTRAVERSION.*$// receipt
960 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
961 fi
962 prev_VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
963 remove_previous_package $INCOMING_REPOSITORY
964 report step "Creating full cpio archive"
965 find . -print | cpio -o -H newc > $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
967 # Restore package tree in case we want to browse it.
968 report step "Restoring original package tree"
969 { zcat fs.cpio.gz 2> /dev/null || unlzma -c fs.cpio.lzma; } | cpio --quiet -id
970 rm fs.cpio.* && cd ..
972 # Log process.
973 echo "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg (done)" >> $LOG
974 report close-bloc
975 echo "Package $PACKAGE ($VERSION$EXTRAVERSION) generated."
976 echo "Size : `du -sh $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
977 echo ""
979 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/broken
980 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/commit
981 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/cooklist
982 }
984 ########################################################################
985 # This section contains functions used by several other functions
986 # bellow.
987 ########################
989 # Look for receipt/files.list in wok. If they can't be found, get them
990 # from package. Accept one argument : absolute path to package.
991 get_pkg_files()
992 {
993 pkg_files_dir=$tmp/$(basename ${1%.tazpkg})
994 mkdir -p $pkg_files_dir && \
995 cd $pkg_files_dir && \
996 cpio --quiet -idm receipt < $1 && \
997 cpio --quiet -idm files.list < $1
998 }
1000 ########################################################################
1001 # This section contains functions to generate packages databases.
1002 ########################
1005 gen_packages_db()
1007 # pkg_repository can be $PACKAGES_REPOSITORY or $INCOMING_REPOSITORY.
1008 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1009 cd $pkg_repository
1010 report step "Generating packages lists: $pkg_repository"
1011 report open-bloc
1012 report step "Removing old files"
1013 for file in files.list.lzma packages.list packages.txt \
1014 packages.desc packages.equiv packages.md5; do
1015 [ -f $file ] && rm $file
1016 done
1017 touch files.list
1019 packages_db_start
1020 unset RECEIPT
1021 report step "Reading datas from all packages"
1022 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1023 get_packages_info
1024 done
1025 report end-step
1026 packages_db_end
1027 report close-bloc
1030 update_packages_db()
1032 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1033 cd $pkg_repository
1034 for file in packages.list packages.equiv packages.md5 packages.desc \
1035 packages.txt; do
1036 if [ ! -f "$file" ]; then
1037 gen_packages_db
1038 return
1039 fi
1040 done
1041 if [ -f files.list.lzma ]; then
1042 lzma d files.list.lzma files.list
1043 else
1044 gen_packages_db
1045 fi
1046 report step "Updating packages lists: $pkg_repository"
1047 packages_db_start
1049 # Look for removed/update packages.
1050 for PACKAGE in $(grep ^[0-9,a-z,A-Z] packages.txt); do
1051 pkg="$pkg_repository/$(grep -m1 ^$PACKAGE- packages.list).tazpkg"
1052 if ! [ -f "$pkg" ]; then
1053 erase_package_info
1054 else
1055 if [ "$pkg" -nt "packages.list" ]; then
1056 updated_pkg="$updated_pkg
1057 $PACKAGE $pkg"
1058 fi
1059 fi
1060 done
1061 echo "$updated_pkg" | sed 1d | while read PACKAGE pkg; do
1062 erase_package_info
1063 get_packages_info
1064 done
1065 unset updated_pkg
1067 # Look for new packages.
1068 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1069 if ! fgrep -q " ${pkg##*/}" $pkg_repository/packages.md5; then
1070 get_packages_info
1071 fi
1072 done
1073 report end-step
1074 packages_db_end
1077 packages_db_start()
1079 if [ ! -s packages.txt ]; then
1080 echo "# SliTaz GNU/Linux - Packages list
1082 # Packages : unknow
1083 # Date : $(date +%Y-%m-%d\ \%H:%M:%S)
1085 " > packages.txt
1086 else
1087 sed -e 's/^# Packages :.*/# Packages : unknow/' \
1088 -e "s/# Date :.*/# Date : $(date +%Y-%m-%d\ \%H:%M:%S)/" \
1089 -i packages.txt
1090 fi
1092 # Needed in some case as tazwok define RECEIPT at configuration time
1093 # in this particular case it can broke the script.
1094 unset RECEIPT
1097 erase_package_info()
1099 cd $pkg_repository
1100 sed "/^$PACKAGE$/,/^$/d" -i packages.txt
1101 sed "/^$PACKAGE /d" -i packages.desc
1102 sed -e "s/=$PACKAGE /= /" -e "s/ $PACKAGE / /" -e "s/ $PACKAGE$//" \
1103 -e "/=$PACKAGE$/d" -e "s/=[0-9,a-z,A-Z]:$PACKAGE /= /" \
1104 -e "s/ [0-9,a-z,A-Z]:$PACKAGE / /" -e "s/ [0-9,a-z,A-Z]:$PACKAGE$/ /" \
1105 -e "/=[0-9,a-z,A-Z]:$PACKAGE$/d" \
1106 -i packages.equiv
1107 sed "/^$PACKAGE:/d" -i files.list
1108 sed "/^$(basename ${pkg%.tazpkg})$/d" -i packages.list
1109 sed "/ $(basename $pkg)$/d" -i packages.md5
1112 get_packages_info()
1114 # If there's no taz folder in the wok, extract infos from the
1115 # package.
1116 get_pkg_files $pkg
1117 source_receipt
1118 echo "Getting datas from $PACKAGE"
1120 cat >> $pkg_repository/packages.txt << _EOT_
1121 $PACKAGE
1122 $VERSION$EXTRAVERSION
1123 $SHORT_DESC
1124 _EOT_
1125 if [ "$PACKED_SIZE" ]; then
1126 cat >> $pkg_repository/packages.txt << _EOT_
1127 $PACKED_SIZE ($UNPACKED_SIZE installed)
1129 _EOT_
1130 else
1131 echo "" >> $pkg_repository/packages.txt
1132 fi
1134 # Packages.desc is used by Tazpkgbox <tree>.
1135 echo "$PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> $pkg_repository/packages.desc
1137 # Packages.equiv is used by tazpkg install to check depends
1138 for i in $PROVIDE; do
1139 DEST=""
1140 echo $i | fgrep -q : && DEST="${i#*:}:"
1141 if grep -qs ^${i%:*}= $pkg_repository/packages.equiv; then
1142 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" $pkg_repository/packages.equiv
1143 else
1144 echo "${i%:*}=$DEST$PACKAGE" >> $pkg_repository/packages.equiv
1145 fi
1146 done
1148 if [ -f files.list ]; then
1149 { echo "$PACKAGE"; cat files.list; } | awk '
1150 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }' >> $pkg_repository/files.list
1151 fi
1153 cd .. && rm -r "$pkg_files_dir"
1155 cd $pkg_repository
1156 echo $(basename ${pkg%.tazpkg}) >> packages.list
1157 [ ! "$package_md5" ] && package_md5=$(md5sum $(basename $pkg))
1158 echo "$package_md5" >> packages.md5
1159 unset package_md5
1162 source_receipt()
1164 unset PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
1165 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
1166 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
1167 src _pkg DESTDIR CONFIG_SITE
1168 . ${RECEIPT:-$PWD/receipt}
1171 packages_db_end()
1173 cd $pkg_repository
1174 pkgs=$(wc -l packages.list | sed 's/ .*//')
1175 sed "s/# Packages : .*/# Packages : $pkgs/" -i packages.txt
1177 # If lists was updated it's generally needed to sort them well.
1178 if ! sort -c packages.list 2> /dev/null; then
1179 report step "Sorting packages lists"
1180 for file in packages.list packages.desc packages.equiv; do
1181 [ -f $file ] || continue
1182 sort -o $file $file
1183 done
1184 report end-step
1185 fi
1187 # Dont log this because lzma always output error.
1188 lzma e files.list files.list.lzma
1189 rm -f files.list
1190 [ -f packages.equiv ] || touch packages.equiv
1193 ########################################################################
1194 # This section contains functions to generate wok database.
1195 ########################
1197 gen_wok_db()
1199 report step "Generating wok database"
1200 report open-bloc
1201 report step "Removing old files"
1202 for file in $wan_db $dep_db $PACKAGES_REPOSITORY/cookorder.txt; do
1203 [ -f $file ] && rm $file
1204 done
1205 report step "Generating wok-wanted.txt"
1206 gen_wan_db
1207 report step "Generating wok-depends.txt"
1208 for PACKAGE in $(cut -f1 -d '|' $PACKAGES_REPOSITORY/packages.desc \
1209 $INCOMING_REPOSITORY/packages.desc | sort -u); do
1210 RECEIPT=$WOK/$PACKAGE/receipt
1211 if [ -s $RECEIPT ]; then
1212 source_receipt
1213 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
1214 fi
1215 done
1216 sort_db
1217 report close-bloc
1220 gen_wan_db()
1222 for RECEIPT in $(fgrep -l WANTED $WOK/*/receipt); do
1223 WANTED=
1224 source $RECEIPT
1225 [ "$WANTED" ] || continue
1226 echo -e $PACKAGE"\t"$WANTED >> $tmp/wan_db
1227 done
1228 if ! [ -f $wan_db ] || [ "$(diff -q $tmp/wan_db $wan_db)" ]; then
1229 mv -f $tmp/wan_db $wan_db
1230 plan_regen_cookorder=yes
1231 else
1232 rm $tmp/wan_db
1233 fi
1236 update_wan_db()
1238 local PACKAGE
1239 for RECEIPT in $(fgrep WANTED $WOK/*/receipt | \
1240 fgrep $PACKAGE | cut -f1 -d ':'); do
1241 WANTED=
1242 source $RECEIPT
1243 [ "$WANTED" ] || continue
1244 wan_info=$(echo -e $PACKAGE"\t"$WANTED)
1245 [ "$wan_info" = "$(grep -m1 ^$PACKAGE$'\t' $wan_db 2>/dev/null)" ] && return
1246 sed "/^$PACKAGE\t/d" -i $wan_db
1247 echo "$wan_info" >> $wan_db
1248 plan_regen_cookorder=yes
1249 plan_sort_wandb=yes
1250 done
1253 update_dep_db()
1255 dep_info=$(echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ')
1256 [ "$dep_info" = "$(grep -m1 ^$PACKAGE$'\t' $dep_db 2>/dev/null)" ] && return
1257 sed "/^$PACKAGE\t/d" -i $dep_db
1258 echo "$dep_info" >> $dep_db
1259 plan_regen_cookorder=yes
1260 plan_sort_depdb=yes
1263 sort_db()
1265 report step "Generating cookorder.txt"
1266 cat $dep_db | sed 's/ \t / /' | while read PACKAGE BUILD_DEPENDS; do
1267 grep -q ^$PACKAGE$'\t' $wan_db && continue
1269 # Replace each BUILD_DEPENDS with a WANTED package by it's
1270 # WANTED package.
1271 replace_by_wanted()
1273 for p in $BUILD_DEPENDS; do
1274 if grep -q ^$p$'\t' $wan_db; then
1275 echo -n $(grep ^$p$'\t' $wan_db | cut -f 2)' '
1276 else
1277 echo -n $p' '
1278 fi
1279 done | tr ' ' '\n' | sort -u | sed "/^$PACKAGE$/d" | tr '\n' ' '
1281 echo -e $PACKAGE"\t $(replace_by_wanted) "
1282 done > $tmp/db
1283 while [ -s "$tmp/db" ]; do
1284 status=start
1285 for pkg in $(cut -f 1 $tmp/db); do
1286 if ! fgrep -q ' '$pkg' ' $tmp/db; then
1287 echo $pkg >> $tmp/cookorder
1288 sed -e "/^$pkg\t/d" -e "s/ $pkg / /g" -i $tmp/db
1289 status=proceed
1290 fi
1291 done
1292 if [ "$status" = start ]; then
1293 cp -f $tmp/db /tmp/remain-depends.txt
1294 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
1295 for blocked in $(cut -f 1 $tmp/db); do
1296 echo "$blocked" >> $PACKAGES_REPOSITORY/blocked
1297 done
1298 break
1299 fi
1300 done
1301 [ -s $tmp/cookorder ] || touch $tmp/cookorder
1303 # The toolchain packages are moved in first position.
1304 grep $(for pkg in `scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
1305 --look_for=all --with_args`; do echo " -e ^$pkg$"; done) \
1306 $tmp/cookorder | tac > $PACKAGES_REPOSITORY/cookorder.txt
1307 for pkg in $(cat $PACKAGES_REPOSITORY/cookorder.txt); do
1308 sed "/^$pkg$/d" -i $tmp/cookorder
1309 done
1311 tac $tmp/cookorder >> $PACKAGES_REPOSITORY/cookorder.txt
1312 unset plan_regen_cookorder
1313 report end-step
1316 ########################################################################
1317 # SCAN CORE
1318 ########################
1319 # Include various scan core-functions. It's not intended to be used
1320 # directly : prefer scan wrappers in next section.
1322 look_for_dep()
1324 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1325 grep ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
1326 | cut -f 2
1327 else
1328 grep ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-depends.txt | \
1329 cut -f 2
1330 fi
1333 look_for_bdep()
1335 look_for_all
1338 look_for_all()
1340 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1341 grep ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
1342 | cut -f 2,3 | sed 's/ / /'
1343 else
1344 grep ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-depends.txt | \
1345 cut -f 2,3 | sed 's/ / /'
1346 fi
1349 look_for_rdep()
1351 fgrep ' '$PACKAGE' ' $INCOMING_REPOSITORY/wok-depends.txt | cut -f 1
1352 if [ "$undigest" ]; then
1353 for rdep in $(fgrep ' '$PACKAGE' ' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt | cut -f 1); do
1354 if [ ! -f "WOK$/$rdep/receipt" ]; then
1355 echo "$rdep"
1356 fi
1357 done
1358 fi
1361 look_for_rbdep()
1363 fgrep ' '$PACKAGE' ' $INCOMING_REPOSITORY/wok-depends.txt | \
1364 cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1365 if [ "$undigest" ]; then
1366 for rdep in $(fgrep ' '$PACKAGE' ' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
1367 | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1); do
1368 if [ ! -f "WOK$/$rdep/receipt" ]; then
1369 echo "$rdep"
1370 fi
1371 done
1372 fi
1375 # Return WANTED if it exists.
1376 look_for_wanted()
1378 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1379 grep ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-wanted.txt | cut -f 2
1380 else
1381 grep ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-wanted.txt | cut -f 2
1382 fi
1385 # Return packages which wants PACKAGE.
1386 look_for_rwanted()
1388 grep $'\t'$PACKAGE$ $INCOMING_REPOSITORY/wok-wanted.txt | cut -f 1
1389 if [ "$undigest" ]; then
1390 for rwanted in $(grep $'\t'$PACKAGE$ $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-wanted.txt | cut -f 1); do
1391 if [ ! -f "$WOK/$rwanted/receipt" ]; then
1392 echo "$rwanted"
1393 fi
1394 done
1395 fi
1398 look_for_dev()
1400 WANTED=$(look_for_wanted)
1401 if [ "$WANTED" ]; then
1402 if [ "$undigest" ] && [ ! -f "$WOK/$WANTED/receipt" ]; then
1403 [ -f "$SLITAZ_DIR/$SLITAZ_VERSION/wok/$WANTED-dev/receipt" ] && echo $WANTED-dev
1404 else
1405 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1406 fi
1407 fi
1408 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1409 [ -f "$SLITAZ_DIR/$SLITAZ_VERSION/wok/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1410 else
1411 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1412 fi
1415 with_dev()
1417 for PACKAGE in $(cat); do
1418 echo $PACKAGE
1419 look_for_dev
1420 done
1423 with_wanted()
1425 for PACKAGE in $(cat); do
1426 echo $PACKAGE
1427 look_for_wanted
1428 done
1431 use_wanted()
1433 for input in $(cat); do
1434 { grep ^$input$'\t' $wan_db || echo $input
1435 } | sed 's/.*\t//'
1436 done
1439 ########################################################################
1440 # SCAN
1441 ########################
1442 # Use wok-wanted.txt and wok-depeds.txt to scan depends.
1443 # Option in command line (must be first arg) :
1444 # --look_for=bdep/rbdep - Look for depends or reverse depends.
1445 # --with_dev - Add development packages (*-dev) in the result.
1446 # --with_wanted - Add package+reverse wanted in the result.
1447 # --with_args - Include packages in argument in the result.
1449 scan()
1451 # Get packages in argument.
1452 local PACKAGE WANTED pkg_list=
1453 for arg in $@; do
1454 [ "$arg" = "${arg#--}" ] || continue
1455 pkg_list="$pkg_list $arg"
1456 done
1458 # Get options.
1459 [ "$pkg_list" ] || return
1460 local cooklist= look_for= with_dev= with_wanted= with_args= log_command="$0 $@" \
1461 get_options_list="look_for with_dev with_wanted with_args cooklist use_wanted"
1462 get_options
1464 # Cooklist is a special case where we need to modify a little
1465 # scan behavior
1466 if [ "$cooklist" ]; then
1467 gen_wan_db
1468 look_for=all && with_args=yes && with_dev= && with_wanted=
1469 filter=use_wanted
1470 if [ "$COMMAND" = gen-cooklist ]; then
1471 for PACKAGE in $pkg_list; do
1472 grep -q ^$PACKAGE$'\t' $dep_db && continue
1473 [ -d "$WOK/$p" ] || continue
1474 check_for_missing
1475 done
1476 append_to_dep()
1478 if ! grep -q ^$PACKAGE$'\t' $dep_db; then
1479 check_for_missing && echo $PACKAGE >> $tmp/dep
1480 else
1481 echo $PACKAGE >> $tmp/dep
1482 fi
1484 else
1485 append_to_dep()
1487 check_for_commit && echo $PACKAGE >> $tmp/dep
1489 fi
1490 else
1491 append_to_dep()
1493 echo $PACKAGE >> $tmp/dep
1495 # If requested packages are not in dep_db, partial generation of this db is needed.
1496 for PACKAGE in $pkg_list; do
1497 grep -q ^$PACKAGE$'\t' $dep_db && continue
1498 [ -d "$WOK/$p" ] || continue
1499 plan_check_for_missing=yes
1500 check_for_missing
1501 done
1502 if [ "$plan_check_for_missing" ]; then
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 check_db_status=yes
1512 unset plan_check_for_missing
1513 fi
1514 fi
1516 [ "$with_dev" ] && filter=with_dev
1517 [ "$with_wanted" ] && filter=with_wanted
1518 if [ "$filter" ]; then
1519 pkg_list=$(echo $pkg_list | $filter)
1520 scan_pkg()
1522 look_for_$look_for | $filter
1524 else
1525 scan_pkg()
1527 look_for_$look_for
1529 fi
1530 touch $tmp/dep
1531 for PACKAGE in $pkg_list; do
1532 [ "$with_args" ] && append_to_dep
1533 scan_pkg
1534 done | tr ' ' '\n' | sort -u > $tmp/list
1535 [ "$look_for" = bdep ] && look_for=dep
1536 while [ -s $tmp/list ]; do
1537 PACKAGE=$(sed 1!d $tmp/list)
1538 sed 1d -i $tmp/list
1539 append_to_dep
1540 for pkg in $(scan_pkg); do
1541 if ! grep -q ^$pkg$ $tmp/list $tmp/dep; then
1542 echo $pkg >> $tmp/list
1543 fi
1544 done
1545 done
1546 if [ "$cooklist" ]; then
1547 mv $tmp/dep $tmp/cooklist
1548 else
1549 cat $tmp/dep | sort -u
1550 fi
1551 rm -f $tmp/dep $tmp/list
1552 if [ "$check_db_status" ]; then
1553 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
1554 [ "$plan_sort_wandb" ] && sort -o $wan_db $wan_db && unset plan_sort_wandb
1555 if [ "$plan_regen_cookorder" ]; then
1556 grep -q "^#" $PACKAGES_REPOSITORY/cookorder.txt || \
1557 sed 1i"#PlanSort" -i $PACKAGES_REPOSITORY/cookorder.txt
1558 fi
1559 fi
1562 ########################################################################
1563 # This section contains functions to check package repository and
1564 # find which packages to cook.
1565 ########################
1567 check_for_missing()
1569 local PACKAGE
1570 if ! check_for_pkg_in_wok; then
1571 [ "$?" = 2 ] && return 1
1572 return
1573 fi
1574 RECEIPT=$WOK/$PACKAGE/receipt
1575 source_receipt
1576 PACKAGE=${WANTED:-$PACKAGE}
1577 update_wan_db
1578 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1579 RECEIPT=$WOK/$PACKAGE/receipt
1580 source_receipt
1581 update_dep_db
1582 done
1585 check_for_commit()
1587 if ! check_for_pkg_in_wok; then
1588 [ "$?" = 2 ] && return 1
1589 return
1590 fi
1591 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1592 RECEIPT=$WOK/$PACKAGE/receipt
1593 source_receipt
1595 # We use md5 of cooking stuff in the packaged receipt to check
1596 # commit. We look consecutively in 3 different locations :
1597 # - in the wok/PACKAGE/taz/* folder
1598 # - in the receipt in the package in incoming repository
1599 # - in the receipt in the package in packages repository
1600 # If md5sum match, there's no commit.
1601 check_for_commit_using_md5sum()
1603 if [ ! -f $WOK/$PACKAGE/md5 ]; then
1604 sed -n '/# md5sum of cooking stuff :/,$p' receipt | \
1605 sed -e 1d -e 's/^# //' > $WOK/$PACKAGE/md5
1606 cd $WOK/$PACKAGE
1607 fi
1609 if [ -s md5 ]; then
1610 if md5sum -cs md5; then
1612 # If md5sum check if ok, check for new/missing files in
1613 # cooking stuff.
1614 for file in $([ -f receipt ] && echo receipt; \
1615 [ -f description.txt ] && echo description.txt; \
1616 [ -d stuff ] && find stuff); do
1617 if ! fgrep -q " $file" md5; then
1618 set_commited
1619 fi
1620 done
1621 else
1622 set_commited
1623 fi
1624 else
1625 set_commited
1626 fi
1628 set_commited()
1630 ! grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/commit &&
1631 echo $PACKAGE >> $PACKAGES_REPOSITORY/commit
1632 gen_cookmd5
1633 update_dep_db
1635 taz_dir=$(echo $WOK/$PACKAGE/taz/$PACKAGE-* | fgrep -v '*')
1636 if [ -f $WOK/$PACKAGE/md5 ]; then
1637 cd $WOK/$PACKAGE
1638 check_for_commit_using_md5sum
1639 elif [ "$taz_dir" ]; then
1640 cd $taz_dir
1641 check_for_commit_using_md5sum
1642 else
1643 pkg=$(echo $INCOMING_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
1644 [ "$pkg" ] || pkg=$(echo $PACKAGES_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
1645 if [ "$pkg" ]; then
1646 get_pkg_files $pkg
1647 check_for_commit_using_md5sum
1648 rm -r $pkg_files_dir
1649 else
1650 set_commited
1651 fi
1652 fi
1653 [ "$forced" ] || echo $PACKAGE >> $tmp/checked
1654 done
1655 return
1658 gen_cook_list()
1660 report step "Scanning wok"
1661 if [ "$pkg" ]; then
1662 scan $pkg --cooklist
1663 else
1664 scan `cat $cooklist` --cooklist
1665 fi
1666 report end-step
1668 [ -s $tmp/checked ] || [ -s $tmp/cooklist ] || return
1669 if [ "$(sed 1!d $PACKAGES_REPOSITORY/cookorder.txt)" = "#PlanSort" ]; then
1670 sed 1d -i $PACKAGES_REPOSITORY/cookorder.txt
1671 plan_regen_cookorder=yes
1672 fi
1674 # Core toolchain should not be cooked unless cook-toolchain is used.
1675 if ! [ -f /etc/config.site.tmptoolchain ] ; then
1676 for PACKAGE in $(scan gcc --look_for=all --with_args --with_wanted); do
1677 grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/blocked || \
1678 echo $PACKAGE >> $PACKAGES_REPOSITORY/blocked
1679 done
1680 fi
1682 if [ -s $PACKAGES_REPOSITORY/commit ] && [ "$COMMAND" != gen-cooklist ]; then
1683 cd $PACKAGES_REPOSITORY
1684 for PACKAGE in $(cat commit); do
1685 WANTED="$(look_for_wanted)"
1686 if [ "$WANTED" ]; then
1687 grep -q ^$WANTED$ broken cooklist blocked commit && continue
1688 fi
1689 grep -q ^$PACKAGE$ blocked cooklist && continue
1690 echo $PACKAGE >> cooklist
1691 done
1692 fi
1693 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
1694 [ "$plan_regen_cookorder" ] && sort_db
1695 sort_cooklist
1698 sort_cooklist()
1700 report step "Sorting cooklist"
1701 if [ -f "$tmp/checked" ]; then
1702 rm -f $tmp/cooklist
1703 cat $tmp/checked | while read PACKAGE; do
1704 grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/cooklist && \
1705 echo $PACKAGE >> $tmp/cooklist
1706 done
1707 elif ! [ "$COMMAND" = gen-cooklist ]; then
1708 cat $PACKAGES_REPOSITORY/blocked | while read PACKAGE; do
1709 sed "/^$PACKAGE/d" -i $tmp/cooklist
1710 done
1711 fi
1713 for PACKAGE in $(cat $tmp/cooklist); do
1714 WANTED="$(look_for_wanted)"
1715 [ "$WANTED" ] || continue
1716 if grep -q ^$WANTED$ $PACKAGES_REPOSITORY/broken $tmp/cooklist; then
1717 sed "/^$PACKAGE$/d" -i $tmp/cooklist
1718 elif [ ! -d $WOK/$WANTED/install ]; then
1719 sed "/^$PACKAGE$/d" -i $tmp/cooklist
1720 echo $WANTED >> $tmp/cooklist
1721 fi
1722 done
1724 # Use cookorder.txt to sort cooklist.
1725 if [ -s $tmp/cooklist ]; then
1726 cat $PACKAGES_REPOSITORY/cookorder.txt | while read PACKAGE; do
1727 if grep -q ^$PACKAGE$ $tmp/cooklist; then
1728 sed "/^$PACKAGE$/d" -i $tmp/cooklist
1729 echo $PACKAGE >> $tmp/cooklist.tmp
1730 fi
1731 done
1733 # Remaining packages in cooklist are thoses without compile_rules.
1734 # They can be cooked first in any order.
1735 if [ -f $tmp/cooklist.tmp ]; then
1736 cat $tmp/cooklist.tmp >> $tmp/cooklist
1737 rm $tmp/cooklist.tmp
1738 fi
1740 cat $tmp/cooklist
1741 [ "$cooklist" = "$PACKAGES_REPOSITORY/cooklist" ] && \
1742 cat $tmp/cooklist > $cooklist
1743 fi
1745 report end-step
1748 check_for_incoming()
1750 [ -s $INCOMING_REPOSITORY/packages.desc ] || {
1751 echo "No packages in $INCOMING_REPOSITORY."
1752 return; }
1753 if [ -s $PACKAGES_REPOSITORY/broken ]; then
1754 echo "Don't move incoming packages to main repository because theses ones are broken:
1755 $(cat $PACKAGES_REPOSITORY/broken)" >&2
1756 return
1757 fi
1758 if [ -s $PACKAGES_REPOSITORY/cooklist ]; then
1759 echo "Don't move incoming packages to main repository because some of them need to be cooked:
1760 $(cat $PACKAGES_REPOSITORY/cooklist)" >&2
1761 return
1762 fi
1763 pkg="$(cut -f 1 -d '|' $INCOMING_REPOSITORY/packages.desc)"
1764 if ! [ "$forced" ]; then
1765 cooklist=$PACKAGES_REPOSITORY/cooklist
1766 gen_cook_list
1767 if [ -s $PACKAGES_REPOSITORY/cooklist ]; then
1768 echo "Don't move incoming packages to main repository because some of them need to be cooked." >&2
1769 return
1770 fi
1771 fi
1772 report step "Moving incoming packages to main repository"
1773 unset EXTRAVERSION
1774 for PACKAGE in $pkg; do
1775 prev_VERSION=$(get_pkg_version $PACKAGES_REPOSITORY)
1776 VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
1777 remove_previous_package $PACKAGES_REPOSITORY
1778 remove_previous_tarball
1779 echo "Moving $PACKAGE..."
1780 mv -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION.tazpkg $PACKAGES_REPOSITORY
1781 touch $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
1782 done
1783 report end-step
1784 for file in packages.list packages.equiv packages.md5 packages.desc \
1785 packages.txt; do
1786 echo -n "" > $INCOMING_REPOSITORY/$file
1787 done
1788 rm -r $INCOMING_REPOSITORY/files.list.lzma
1789 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
1792 ########################################################################
1793 # TAZWOK MAIN FUNCTIONS
1794 ########################
1796 clean()
1798 cd $WOK/$PACKAGE
1799 ls -A $WOK/$PACKAGE | grep -q -v -e ^receipt$ -e ^description.txt$ \
1800 -e ^stuff$ || return
1802 report step "Cleaning $PACKAGE"
1803 # Check for clean_wok function.
1804 if grep -q ^clean_wok $RECEIPT; then
1805 clean_wok
1806 fi
1807 # Clean should only have a receipt, stuff and optional desc.
1808 for f in `ls .`
1809 do
1810 case $f in
1811 receipt|stuff|description.txt)
1812 continue ;;
1813 *)
1814 echo "Removing: $f"
1815 rm -rf $f
1816 esac
1817 done
1818 report end-step
1821 # Configure and make a package with the receipt.
1822 compile_package()
1824 check_for_package_on_cmdline
1826 # Include the receipt to get all needed variables and functions
1827 # and cd into the work directory to start the work.
1828 check_for_receipt
1829 source_receipt
1831 # Log the package name and date.
1832 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
1833 echo "package $PACKAGE (compile)" >> $LOG
1835 # Set wanted $src variable to help compiling.
1836 [ ! "$src" ] && set_src_path
1837 check_for_build_depends || return 1
1838 check_for_wanted
1839 unset target
1840 check_for_tarball && check_for_compile_rules
1843 # Cook command also include all features to manage lists which keep
1844 # track of wok/packages state.
1845 cook()
1847 cook_code=
1848 set_common_path
1849 check_for_receipt
1850 source_receipt
1852 # Define log path and start report.
1853 [ -f $LOCAL_REPOSITORY/log/$PACKAGE.html ] && rm $LOCAL_REPOSITORY/log/$PACKAGE.html
1854 report sublog $LOCAL_REPOSITORY/log/$PACKAGE.html
1855 report step "Cooking $PACKAGE"
1856 report open-bloc
1858 clean $PACKAGE
1859 [ -s $tmp/cooklist ] && sed "/^$PACKAGE$/d" -i $tmp/cooklist
1861 if compile_package; then
1862 remove_src
1863 refresh_packages_from_compile
1864 gen_package
1866 # Update packages-incoming repository.
1867 store_pkgname=$PACKAGE
1868 pkg_repository=$INCOMING_REPOSITORY
1869 update_packages_db
1871 PACKAGE=$store_pkgname
1872 unset store_pkgname
1874 # Upgrade to cooked packages if it was previously installed.
1875 report step "Look for package(s) to upgrade"
1876 for pkg in $(look_for_rwanted) $PACKAGE; do
1877 if [ -d $INSTALLED/$pkg ]; then
1878 tazpkg get-install $pkg --forced
1879 fi
1880 done
1881 report end-step
1882 else
1884 # Set package as broken.
1885 if ! grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/broken; then
1886 echo $PACKAGE >> $PACKAGES_REPOSITORY/broken
1887 fi
1888 gen_cookmd5
1889 cook_code=1
1890 fi
1892 # Remove build_depends in cook mode (if in cooklist, it's done when
1893 # checking build_depends of next package and we remove only unneeded
1894 # packages to keep chroot minimal and gain some time).
1895 if [ "$COMMAND" = cook ]; then
1896 remove_build_depends $MISSING_PACKAGE
1897 [ -x /usr/bin/clean-chroot ] && clean-chroot
1898 fi
1900 # Regen the cooklist if it was planned and command is not cook.
1901 [ "$regen_cooklist" ] && unset regen_cooklist && \
1902 [ "$COMMAND" != cook ] && sort_cooklist
1904 # Some hacks to set the bloc & function status as failed if cook was
1905 # failed.
1906 report_return_code=$cook_code
1907 report close-bloc
1908 report end-sublog
1909 return $cook_code
1912 cook_list()
1914 if [ -s $tmp/cooklist ]; then
1915 if [ -f /usr/bin/tazchroot ]; then
1916 # Note : options -main variables- are automatically keeped by
1917 # the sub-applications tazchroot/tazwok; as well as report data.
1918 cd $LOCAL_REPOSITORY
1919 [ ! -f tazchroot.conf ] && configure_tazchroot
1920 tazchroot tazwok cook-list --SLITAZ_DIR=$SLITAZ_DIR --SLITAZ_VERSION=$SLITAZ_VERSION ${undigest:+ --undigest=$undigest}
1921 return
1922 fi
1923 while [ -s $tmp/cooklist ]; do
1924 PACKAGE=$(sed 1!d $tmp/cooklist)
1925 cook
1926 done
1927 remove_build_depends $MISSING_PACKAGE $remove_later
1928 [ -x /usr/bin/clean-chroot ] && clean-chroot
1929 else
1930 echo "Nothing to cook."
1931 return
1932 fi
1935 configure_tazchroot()
1937 cat > $LOCAL_REPOSITORY/tazchroot.conf << EOF
1938 # Tazchroot configuration file - created by tazwok.
1940 # Default chroot path
1941 SLITAZ_DIR=$SLITAZ_DIR
1942 SLITAZ_VERSION=$SLITAZ_VERSION
1943 $( [ "$undigest" ] && echo "undigest=$undigest" )
1944 LOCAL_REPOSITORY=$SLITAZ_DIR/$(if [ "$undigest" ]; then echo '$undigest'; else echo '$SLITAZ_VERSION'; fi)
1945 chroot_dir=\$LOCAL_REPOSITORY/chroot
1947 # Default scripts path (theses scripts are added in the
1948 # $chroot_dir/usr/bin and can be called with tazchroot script)
1949 script_dir=/var/lib/tazchroot
1951 # List of directories to mount.
1952 list_dir="$(for dir in packages wok src packages-incoming log flavors iso; do echo $LOCAL_REPOSITORY/$dir; done)
1953 $SLITAZ_LOG$( [ "$undigest" ] && echo -e "\n$SLITAZ_DIR/$SLITAZ_VERSION/packages" )"
1955 create_chroot()
1957 mkdir -p \$chroot_dir
1958 for pkg in \$(tazwok build-depends toolchain --SLITAZ_DIR=\$SLITAZ_DIR --SLITAZ_VERSION=\$SLITAZ_VERSION${undigest:+ --undigest=\$undigest}); do
1959 tazpkg get-install \$pkg --root="\$chroot_dir"
1960 done
1962 # Store list of installed packages needed by cleanchroot.
1963 ls -1 \$chroot_dir/\$INSTALLED > \$chroot_dir/\$LOCALSTATE/chroot-pkgs
1965 sed -e "s~^SLITAZ_DIR=.*~SLITAZ_DIR=\$SLITAZ_DIR~" \\
1966 -e "s/^SLITAZ_VERSION=.*/SLITAZ_VERSION=\$SLITAZ_VERSION/" \\
1967 -i \$chroot_dir/etc/slitaz/slitaz.conf
1968 $( [ "$undigest" ] && echo ' echo "undigest='"$undigest"'" >> $chroot_dir/etc/slitaz/tazwok.conf')
1969 sed 's/LC_ALL/LC_ALL=POSIX/' -i \$chroot_dir/etc/profile
1972 mount_chroot()
1974 cp -a /etc/resolv.conf \$chroot_dir/etc/resolv.conf
1975 echo "\$LOCAL_REPOSITORY/packages" > \$chroot_dir\$LOCALSTATE/mirror
1976 mkdir -p \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming
1977 echo "\$LOCAL_REPOSITORY/packages-incoming" > \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming/mirror
1978 $( [ "$undigest" ] && echo ' mkdir -p $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION
1979 echo "$SLITAZ_DIR/$SLITAZ_VERSION/packages" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror' )
1980 echo -e "\${LOCAL_REPOSITORY##*/}-incoming\nmain" > \$chroot_dir\$LOCALSTATE/priority
1981 mount -t proc proc \$chroot_dir/proc
1982 mount -t sysfs sysfs \$chroot_dir/sys
1983 mount -t devpts devpts \$chroot_dir/dev/pts
1984 mount -t tmpfs shm \$chroot_dir/dev/shm
1985 for dir in \$list_dir; do
1986 mkdir -p \$dir \$chroot_dir\$dir
1987 mount \$dir \$chroot_dir\$dir
1988 done
1991 umount_chroot()
1993 for dir in \$list_dir; do
1994 umount \$chroot_dir\$dir
1995 done
1996 umount \$chroot_dir/dev/shm
1997 umount \$chroot_dir/dev/pts
1998 umount \$chroot_dir/sys
1999 umount \$chroot_dir/proc
2001 EOF
2004 ########################################################################
2005 ######################### END OF NEW FUNCTIONS #########################
2006 ########################################################################
2008 # List packages providing a virtual package
2009 whoprovide()
2011 local i;
2012 for i in $(fgrep -l PROVIDE $WOK/*/receipt); do
2013 . $i
2014 case " $PROVIDE " in
2015 *\ $1\ *|*\ $1:*) echo $(basename $(dirname $i));;
2016 esac
2017 done
2020 ########################################################################
2021 # TAZWOK COMMANDS
2022 ########################
2024 case "$COMMAND" in
2025 stats)
2026 # Tazwok general statistics from the wok config file.
2028 get_tazwok_config
2029 echo -e "\n\033[1mTazwok configuration statistics\033[0m
2030 ================================================================================
2031 Wok directory : $WOK
2032 Packages repository : $PACKAGES_REPOSITORY
2033 Incoming repository : $INCOMING_REPOSITORY
2034 Sources repository : $SOURCES_REPOSITORY
2035 Log directory : $LOCAL_REPOSITORY/log
2036 Packages in the wok : `ls -1 $WOK | wc -l`
2037 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2038 Incoming packages : `ls -1 $INCOMING_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2039 ================================================================================\n"
2040 ;;
2041 edit)
2042 get_tazwok_config
2043 check_for_package_on_cmdline
2044 check_for_receipt
2045 $EDITOR $WOK/$PACKAGE/receipt
2046 ;;
2047 build-depends)
2048 # List dependencies to rebuild wok, or only a package
2049 get_tazwok_config
2050 report(){ : ; }
2051 if [ ! "$PACKAGE" ] || [ "$PACKAGE" = toolchain ]; then
2052 scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
2053 --look_for=dep --with_dev --with_args
2054 else
2055 check_for_package_on_cmdline
2056 scan $PACKAGE --look_for=bdep --with_dev
2057 fi
2058 ;;
2059 gen-cooklist)
2060 check_root
2061 get_options_list="pkg"
2062 get_tazwok_config
2063 report(){ : ; }
2064 if ! [ "$pkg" ]; then
2065 if [ ! "$LIST" ] || [ "$LIST" = toolchain ]; then
2066 pkg="$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA"
2067 else
2068 cooklist=${LIST:-$PACKAGES_REPOSITORY/cooklist}
2069 fi
2070 fi
2071 gen_cook_list
2072 ;;
2073 check-depends)
2074 # Check package depends /!\
2075 get_tazwok_config
2076 echo ""
2077 echo -e "\033[1mCheck every receipt for DEPENDS - doesn't scan ELF files\033[0m
2078 ================================================================================"
2079 TMPDIR=/tmp/tazwok$$
2080 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
2082 # Build ALL_DEPENDS variable
2083 scan_dep()
2085 local i
2086 ALL_DEPENDS="$ALL_DEPENDS$PACKAGE "
2087 for i in $DEPENDS $SUGGESTED ; do
2088 case " $ALL_DEPENDS " in
2089 *\ $i\ *) continue;;
2090 esac
2091 [ -d $WOK/$i ] || {
2092 ALL_DEPENDS="$ALL_DEPENDS$i "
2093 continue
2095 DEPENDS=""
2096 SUGGESTED=""
2097 . $WOK/$i/receipt
2098 scan_dep
2099 done
2102 # Check for ELF file
2103 is_elf()
2105 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" \
2106 = "ELF" ]
2109 # Print shared library dependencies
2110 ldd()
2112 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
2115 mkdir $TMPDIR
2116 cd $TMPDIR
2117 for i in $LOCALSTATE/files.list.lzma \
2118 $LOCALSTATE/undigest/*/files.list.lzma ; do
2119 [ -f $i ] && lzma d $i -so >> files.list
2120 done
2121 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
2122 tazpkg extract $pkg > /dev/null 2>&1
2123 . */receipt
2124 ALL_DEPENDS="$DEFAULT_DEPENDS "
2125 scan_dep
2126 find */fs -type f | while read file ; do
2127 is_elf $file || continue
2128 case "$file" in
2129 *.o|*.ko|*.ko.gz) continue;;
2130 esac
2131 ldd $file | while read lib rem; do
2132 case "$lib" in
2133 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
2134 continue;;
2135 esac
2136 for dep in $(fgrep $lib files.list | cut -d: -f1); do
2137 case " $ALL_DEPENDS " in
2138 *\ $dep\ *) continue 2;;
2139 esac
2140 for vdep in $(fgrep $dep $LOCALSTATE/packages.equiv | cut -d= -f1); do
2141 case " $ALL_DEPENDS " in
2142 *\ $vdep\ *) continue 3;;
2143 esac
2144 done
2145 done
2146 [ -n "$dep" ] || dep="UNKNOWN"
2147 echo "$(basename $pkg): ${file#*fs} depends on package $dep for the shared library $lib"
2148 done
2149 done
2150 rm -rf */
2151 done
2152 cd /tmp
2153 rm -rf $TMPDIR
2154 ;;
2155 check)
2156 # Check wok consistency
2157 get_tazwok_config
2158 echo ""
2159 echo -e "\033[1mWok and packages checking\033[0m
2160 ================================================================================"
2161 cd $WOK
2162 for pkg in $(ls)
2163 do
2164 [ -f $pkg/receipt ] || continue
2165 RECEIPT= $pkg/receipt
2166 source_receipt
2167 [ "$PACKAGE" = "$pkg" ] || echo "Package $PACKAGE should be $pkg" >&2
2168 [ -n "$VERSION" ] || echo "Package $PACKAGE has no VERSION" >&2
2169 [ -n "$PACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded PACKED_SIZE" >&2
2170 [ -n "$UNPACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded UNPACKED_SIZE" >&2
2171 [ -n "$EXTRAVERSION" ] && echo "Package $PACKAGE has hardcoded EXTRAVERSION" >&2
2172 if [ -n "$WANTED" ]; then
2173 if [ ! -f $WANTED/receipt ]; then
2174 echo "Package $PACKAGE wants unknown $WANTED package" >&2
2175 else
2176 BASEVERSION=$(. $WANTED/receipt ; echo $VERSION)
2177 if [ "$VERSION" = "$WANTED" ]; then
2178 # BASEVERSION is computed in receipt
2179 fgrep -q '_pkg=' $pkg/receipt &&
2180 BASEVERSION=$VERSION
2181 fi
2182 if [ "$VERSION" != "$BASEVERSION" ]; then
2183 echo "Package $PACKAGE ($VERSION) wants $WANTED ($BASEVERSION)" >&2
2184 fi
2185 fi
2186 fi
2188 if [ -n "$CATEGORY" ]; then
2189 case " $(echo $CATEGORIES) " in
2190 *\ $CATEGORY\ *);;
2191 *) echo "Package $PACKAGE has an invalid CATEGORY" >&2;;
2192 esac
2193 else
2194 echo"Package $PACKAGE has no CATEGORY" >&2
2195 fi
2196 [ -n "$SHORT_DESC" ] || echo "Package $PACKAGE has no SHORT_DESC" >&2
2197 [ -n "$MAINTAINER" ] || echo "Package $PACKAGE has no MAINTAINER" >&2
2198 case "$WGET_URL" in
2199 ftp*|http*) busybox wget -s $WGET_URL 2> /dev/null ||
2200 echo "Package $PACKAGE has a wrong WGET_URL" >&2;;
2201 '') ;;
2202 *) echo "Package $PACKAGE has an invalid WGET_URL" >&2;;
2203 esac
2204 case "$WEB_SITE" in
2205 ftp*|http*);;
2206 '') echo "Package $PACKAGE has no WEB_SITE" >&2;;
2207 *) echo "Package $PACKAGE has an invalid WEB_SITE" >&2;;
2208 esac
2209 case "$MAINTAINER" in
2210 *\<*|*\>*) echo "Package $PACKAGE has an invalid MAINTAINER: $MAINTAINER" >&2;;
2211 esac
2212 case "$MAINTAINER" in
2213 *@*);;
2214 *) echo "Package $PACKAGE MAINTAINER is not an email address" >&2;;
2215 esac
2216 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2217 for i in $DEPENDS; do
2218 [ -d $i ] && continue
2219 [ -n "$(whoprovide $i)" ] && continue
2220 echo -e "$MSG $i"
2221 MSG=""
2222 done
2223 MSG="Missing build dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2224 for i in $BUILD_DEPENDS; do
2225 [ -d $i ] && continue
2226 [ -n "$(whoprovide $i)" ] && continue
2227 echo -e "$MSG $i"
2228 MSG=""
2229 done
2230 MSG="Dependencies loop between $PACKAGE and :\n"
2231 ALL_DEPS=""
2232 check_for_deps_loop $PACKAGE $DEPENDS
2233 [ -d $WOK/$pkg/taz ] && for i in $BUILD_DEPENDS; do
2234 [ $WOK/$pkg/taz -nt $INSTALLED/$i/files.list ] && continue
2235 echo "$pkg should be rebuilt after $i installation"
2236 done
2237 done
2238 ;;
2239 list)
2240 # List packages in wok directory. User can specify a category.
2242 get_tazwok_config
2243 if [ "$2" = "category" ]; then
2244 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
2245 exit 0
2246 fi
2247 # Check for an asked category.
2248 if [ -n "$2" ]; then
2249 ASKED_CATEGORY=$2
2250 echo ""
2251 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
2252 echo "================================================================================"
2253 for pkg in $WOK/*
2254 do
2255 [ ! -f $pkg/receipt ] && continue
2256 . $pkg/receipt
2257 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
2258 echo -n "$PACKAGE"
2259 echo -e "\033[28G $VERSION"
2260 packages=$(($packages+1))
2261 fi
2262 done
2263 echo "================================================================================"
2264 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
2265 else
2266 # By default list all packages and version.
2267 echo ""
2268 echo -e "\033[1mList of packages in the wok\033[0m"
2269 echo "================================================================================"
2270 for pkg in $WOK/*
2271 do
2272 [ ! -f $pkg/receipt ] && continue
2273 . $pkg/receipt
2274 echo -n "$PACKAGE"
2275 echo -en "\033[28G $VERSION"
2276 echo -e "\033[42G $CATEGORY"
2277 packages=$(($packages+1))
2278 done
2279 echo "================================================================================"
2280 echo -e "$packages packages available in the wok.\n"
2281 fi
2282 ;;
2283 info)
2284 # Information about a package.
2286 get_tazwok_config
2287 check_for_package_on_cmdline
2288 check_for_receipt
2289 . $WOK/$PACKAGE/receipt
2290 echo ""
2291 echo -e "\033[1mTazwok package information\033[0m
2292 ================================================================================
2293 Package : $PACKAGE
2294 Version : $VERSION
2295 Category : $CATEGORY
2296 Short desc : $SHORT_DESC
2297 Maintainer : $MAINTAINER"
2298 if [ ! "$WEB_SITE" = "" ]; then
2299 echo "Web site : $WEB_SITE"
2300 fi
2301 if [ ! "$DEPENDS" = "" ]; then
2302 echo "Depends : $DEPENDS"
2303 fi
2304 if [ ! "$WANTED" = "" ]; then
2305 echo "Wanted src : $WANTED"
2306 fi
2307 echo "================================================================================"
2308 echo ""
2309 ;;
2310 check-log)
2311 # We just cat the file log to view process info.
2313 get_tazwok_config
2314 if [ ! -f "$LOG" ]; then
2315 echo -e "\nNo process log found. The package is probably not cooked.\n" >&2
2316 exit 1
2317 else
2318 echo ""
2319 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
2320 echo "================================================================================"
2321 cat $LOG
2322 echo "================================================================================"
2323 echo ""
2324 if [ -s "$WOK/$PACKAGE/warning.txt" ]; then
2325 echo -e "\033[1mCook warning(s) for :\033[0m $PACKAGE"
2326 echo "================================================================================"
2327 cat "$WOK/$PACKAGE/warning.txt"
2328 echo "================================================================================"
2329 echo ""
2330 fi
2331 fi
2332 ;;
2333 search)
2334 # Search for a package by pattern or name.
2336 get_tazwok_config
2337 if [ -z "$2" ]; then
2338 echo -e "\nPlease specify a pattern or a package name to search." >&2
2339 echo -e "Example : 'tazwok search gcc'.\n" >&2
2340 exit 1
2341 fi
2342 echo ""
2343 echo -e "\033[1mSearch result for :\033[0m $2"
2344 echo "================================================================================"
2345 list=`ls -1 $WOK | fgrep $2`
2346 for pkg in $list
2347 do
2348 . $WOK/$pkg/receipt
2349 echo -n "$PACKAGE "
2350 echo -en "\033[24G $VERSION"
2351 echo -e "\033[42G $CATEGORY"
2352 packages=$(($PACKAGEs+1))
2353 done
2354 echo "================================================================================"
2355 echo "$packages packages found for : $2"
2356 echo ""
2357 ;;
2358 compile)
2359 # Configure and make a package with the receipt.
2361 get_tazwok_config
2362 source_lib report
2363 report start
2364 compile_package
2365 ;;
2366 genpkg)
2367 # Generate a package.
2369 get_tazwok_config
2370 source_lib report
2371 report start
2372 gen_package
2373 ;;
2374 cook)
2375 # Compile and generate a package. Just execute tazwok with
2376 # the good commands.
2378 check_root
2379 get_tazwok_config
2380 source_lib report
2381 report start
2382 update_wan_db
2383 check_for_commit
2384 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
2385 [ "$plan_sort_wandb" ] && sort -o $wan_db $wan_db && unset plan_sort_wandb
2386 if [ "$plan_regen_cookorder" ]; then
2387 grep -q "^#" $PACKAGES_REPOSITORY/cookorder.txt || \
2388 sed 1i"#PlanSort" -i $PACKAGES_REPOSITORY/cookorder.txt
2389 fi
2390 cook
2391 ;;
2392 sort-cooklist)
2393 if [ ! "$LIST" ]; then
2394 echo "Usage : tazwok sort-cooklist cooklist" >&2\
2395 exit 1
2396 fi
2397 get_tazwok_config
2398 source_lib report
2399 report start
2400 cooklist=$LIST
2401 sort_cooklist
2402 cp -af $tmp/cooklist $cooklist
2403 ;;
2404 cook-list)
2405 # Cook all packages listed in a file or in default cooklist.
2406 check_root
2407 get_options_list="pkg forced"
2408 get_tazwok_config
2409 source_lib report
2410 report start
2411 if ! [ "$pkg" ]; then
2412 cooklist=${LIST:-$PACKAGES_REPOSITORY/cooklist}
2413 fi
2414 gen_cook_list
2415 cook_list
2416 ;;
2417 clean)
2418 # Clean up a package work directory + thoses which want it.
2420 get_tazwok_config
2421 check_for_package_on_cmdline
2422 check_for_receipt
2423 source_lib report
2424 report start
2425 . $RECEIPT
2426 clean
2427 ;;
2428 gen-clean-wok)
2429 # Generate a clean wok from the current wok by copying all receipts
2430 # and stuff directory.
2432 get_tazwok_config
2433 source_lib report
2434 report start
2435 if [ -z "$ARG" ]; then
2436 echo -e "\nPlease specify the destination for the new clean wok.\n" >&2
2437 exit 1
2438 else
2439 dest=$ARG
2440 mkdir -p $dest
2441 fi
2442 report step "Creating clean wok in : $dest"
2443 for pkg in `ls -1 $WOK`
2444 do
2445 mkdir -p $dest/$pkg
2446 cp -a $WOK/$pkg/receipt $dest/$pkg
2447 [ -f $WOK/$pkg/description.txt ] && \
2448 cp -a $WOK/$pkg/description.txt $dest/$pkg
2449 if [ -d "$WOK/$pkg/stuff" ]; then
2450 cp -a $WOK/$pkg/stuff $dest/$pkg
2451 fi
2452 done
2453 [ -d $WOK/.hg ] && cp -a $WOK/.hg $dest
2454 report end-step
2455 echo "Packages cleaned : `ls -1 $dest | wc -l`"
2456 echo ""
2457 ;;
2458 clean-wok)
2459 # Clean all packages in the work directory
2461 get_tazwok_config
2462 source_lib report
2463 report start
2464 report step "Cleaning wok"
2465 report open-bloc
2466 for PACKAGE in `ls -1 $WOK`
2467 do
2468 set_common_path
2469 source_receipt
2470 clean
2471 done
2472 report close-bloc
2473 echo "`ls -1 $WOK | wc -l` packages cleaned."
2474 ;;
2475 gen-list)
2476 get_tazwok_config
2477 if [ "$2" ]; then
2478 if [ -d "$2" ]; then
2479 pkg_repository=$2
2480 else
2481 echo -e "\nUnable to find directory : $2\n" >&2
2482 exit 1
2483 fi
2484 fi
2486 source_lib report
2487 report start
2488 if [ "$pkg_repository" ]; then
2489 gen_packages_db
2490 else
2491 pkg_repository=$PACKAGES_REPOSITORY && gen_packages_db
2492 pkg_repository=$INCOMING_REPOSITORY && gen_packages_db
2493 fi
2494 ;;
2495 check-list)
2496 # The directory to move into by default is the repository,
2497 # if $2 is not empty cd into $2.
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 update_packages_db
2513 else
2514 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2515 pkg_repository=$INCOMING_REPOSITORY && update_packages_db
2516 fi
2517 ;;
2518 new-tree)
2519 # Just create a few directories and generate an empty receipt to prepare
2520 # the creation of a new package.
2522 get_tazwok_config
2523 check_for_package_on_cmdline
2524 if [ -d $WOK/$PACKAGE ]; then
2525 echo -e "\n$PACKAGE package tree already exists.\n" >&2
2526 exit 1
2527 fi
2528 echo "Creating : $WOK/$PACKAGE"
2529 mkdir $WOK/$PACKAGE
2530 cd $WOK/$PACKAGE
2531 echo -n "Preparing the receipt..."
2533 # Default receipt begin.
2535 echo "# SliTaz package receipt." > receipt
2536 echo "" >> receipt
2537 echo "PACKAGE=\"$PACKAGE\"" >> receipt
2538 # Finish the empty receipt.
2539 cat >> receipt << "EOF"
2540 VERSION=""
2541 CATEGORY=""
2542 SHORT_DESC=""
2543 MAINTAINER=""
2544 DEPENDS=""
2545 TARBALL="$PACKAGE-$VERSION.tar.gz"
2546 WEB_SITE=""
2547 WGET_URL=""
2549 # Rules to configure and make the package.
2550 compile_rules()
2552 cd $src
2553 ./configure && make && make install
2556 # Rules to gen a SliTaz package suitable for Tazpkg.
2557 genpkg_rules()
2559 mkdir -p $fs/usr
2560 cp -a $_pkg/usr/bin $fs/usr
2563 EOF
2565 # Default receipt end.
2567 status
2568 # Interactive mode, asking and seding.
2569 if [ "$3" = "--interactive" ]; then
2570 echo "Entering into interactive mode..."
2571 echo "================================================================================"
2572 echo "Package : $PACKAGE"
2573 # Version.
2574 echo -n "Version : " ; read anser
2575 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
2576 # Category.
2577 echo -n "Category : " ; read anser
2578 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
2579 # Short description.
2580 echo -n "Short desc : " ; read anser
2581 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
2582 # Maintainer.
2583 echo -n "Maintainer : " ; read anser
2584 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
2585 # Web site.
2586 echo -n "Web site : " ; read anser
2587 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
2588 echo ""
2589 # Wget URL.
2590 echo "Wget URL to download source tarball."
2591 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
2592 echo -n "Wget url : " ; read anser
2593 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
2594 # Ask for a stuff dir.
2595 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
2596 if [ "$anser" = "y" ]; then
2597 echo -n "Creating the stuff directory..."
2598 mkdir stuff && status
2599 fi
2600 # Ask for a description file.
2601 echo -n "Are you going to write a description ? (y/N) : " ; read anser
2602 if [ "$anser" = "y" ]; then
2603 echo -n "Creating the description.txt file..."
2604 echo "" > description.txt && status
2605 fi
2606 echo "================================================================================"
2607 echo ""
2608 fi
2609 ;;
2610 remove)
2611 # Remove a package from the wok.
2613 get_tazwok_config
2614 check_for_package_on_cmdline
2615 echo ""
2616 echo -n "Please confirm deletion (y/N) : "; read anser
2617 if [ "$anser" = "y" ]; then
2618 echo -n "Removing $PACKAGE..."
2619 rm -rf $WOK/$PACKAGE && status
2620 echo ""
2621 fi
2622 ;;
2623 hgup)
2624 # Pull and update a Hg wok.
2625 get_tazwok_config
2626 if ls -l $WOK/.hg/hgrc | fgrep -q "root"; then
2627 check_root
2628 fi
2629 cd $WOK
2630 hg pull && hg update
2631 ;;
2632 maintainers)
2633 get_tazwok_config
2634 echo ""
2635 echo "List of maintainers for: $WOK"
2636 echo "================================================================================"
2637 touch /tmp/slitaz-maintainers
2638 for pkg in $WOK/*
2639 do
2640 . $pkg/receipt
2641 if ! fgrep -q "$MAINTAINER" /tmp/slitaz-maintainers; then
2642 echo "$MAINTAINER" >> /tmp/slitaz-maintainers
2643 echo "$MAINTAINER"
2644 fi
2645 done
2646 echo "================================================================================"
2647 echo "Maintainers: `cat /tmp/slitaz-maintainers | wc -l`"
2648 echo ""
2649 # Remove tmp files
2650 rm -f /tmp/slitaz-maintainers
2651 ;;
2652 maintained-by)
2653 # Search for packages maintained by a contributor.
2654 get_tazwok_config
2655 if [ ! -n "$2" ]; then
2656 echo "Specify a name or email of a maintainer." >&2
2657 exit 1
2658 fi
2659 echo "Maintainer packages"
2660 echo "================================================================================"
2661 for pkg in $WOK/*
2662 do
2663 . $pkg/receipt
2664 if echo "$MAINTAINER" | fgrep -q "$2"; then
2665 echo "$PACKAGE"
2666 packages=$(($PACKAGEs+1))
2667 fi
2668 done
2669 echo "================================================================================"
2670 echo "Packages maintained by $2: $PACKAGEs"
2671 echo ""
2672 ;;
2673 check-src)
2674 # Verify if upstream package is still available
2676 get_tazwok_config
2677 check_for_package_on_cmdline
2678 check_for_receipt
2679 source_receipt
2680 check_src()
2682 for url in $@; do
2683 busybox wget -s $url 2>/dev/null && break
2684 done
2686 if [ "$WGET_URL" ];then
2687 echo -n "$PACKAGE : "
2688 check_src $WGET_URL
2689 status
2690 else
2691 echo "No tarball to check for $PACKAGE"
2692 fi
2693 ;;
2694 get-src)
2695 check_root
2696 get_options_list="target nounpack"
2697 get_tazwok_config
2698 check_for_package_on_cmdline
2699 check_for_receipt
2700 source_receipt
2701 if [ "$WGET_URL" ];then
2702 source_lib report
2703 report start
2704 check_for_tarball
2705 else
2706 echo "No tarball to download for $PACKAGE"
2707 fi
2708 ;;
2709 check-commit)
2710 check_root
2711 get_options_list="missing forced"
2712 get_tazwok_config
2713 source_lib report
2714 report start
2715 if [ "$forced" ]; then
2716 rm -f $WOK/*/md5
2717 unset forced
2718 fi
2719 if [ "$missing" ]; then
2720 pkg=$(ls -1 $WOK)
2721 else
2722 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
2723 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
2724 } | sort -u)"
2725 fi
2726 cooklist=$PACKAGES_REPOSITORY/cooklist
2727 gen_cook_list
2728 ;;
2729 cook-commit)
2730 check_root
2731 get_options_list="missing forced"
2732 get_tazwok_config
2733 source_lib report
2734 report start
2735 if [ "$forced" ]; then
2736 rm -f $WOK/*/md5
2737 unset forced
2738 fi
2739 if [ "$missing" ]; then
2740 pkg=$(ls -1 $WOK)
2741 else
2742 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
2743 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
2744 } | sort -u)"
2745 fi
2746 cooklist=$PACKAGES_REPOSITORY/cooklist
2747 gen_cook_list
2748 cook_list
2749 ;;
2750 cook-all)
2751 check_root
2752 get_options_list="forced missing"
2753 get_tazwok_config
2754 source_lib report
2755 report start
2756 if [ "$missing" ]; then
2757 pkg=$(ls -1 $WOK)
2758 else
2759 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
2760 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
2761 } | sort -u)"
2762 fi
2763 cooklist=$PACKAGES_REPOSITORY/cooklist
2764 gen_cook_list
2765 cook_list
2766 ;;
2767 gen-wok-db)
2768 check_root
2769 get_tazwok_config
2770 source_lib report
2771 report start
2772 gen_wok_db
2773 ;;
2774 report)
2775 check_root
2776 get_tazwok_config
2777 cd $PACKAGES_REPOSITORY
2778 if [ "$2" ]; then
2779 case $2 in
2780 commit|cooklist|incoming|broken|blocked)
2781 show="$2"
2782 ;;
2783 *)
2784 echo "usage : tazwok report [commit|cooklist|incoming|broken|blocked]" >&2
2785 exit 1
2786 ;;
2787 esac
2788 else
2789 show="commit cooklist incoming broken blocked"
2790 fi
2791 for i in $show; do
2792 if [ -s $i ]; then
2793 echo ""
2794 echo -e "\033[1m$i\033[0m"
2795 echo "================================================================================"
2796 cat $i
2797 echo "================================================================================"
2798 echo ""
2799 fi
2800 done
2801 ;;
2802 check-incoming)
2803 check_root
2804 get_options_list="forced"
2805 get_tazwok_config
2806 source_lib report
2807 report start
2808 check_for_incoming
2809 ;;
2810 configure-chroot)
2811 check_root
2812 get_tazwok_config
2813 if [ -f /usr/bin/tazchroot ]; then
2814 cd $LOCAL_REPOSITORY
2815 configure_tazchroot
2816 else
2817 echo "The packages tazchroot need to be installed" >&2
2818 exit 1
2819 fi
2820 ;;
2821 chroot)
2822 check_root
2823 get_tazwok_config
2824 # Merge this and the other chroot function ?.
2825 if [ -f /usr/bin/tazchroot ]; then
2826 cd $LOCAL_REPOSITORY
2827 [ ! -f tazchroot.conf ] && configure_tazchroot
2828 tazchroot
2829 else
2830 echo "The packages tazchroot need to be installed" >&2
2831 exit 1
2832 fi
2833 ;;
2834 cook-toolchain)
2835 check_root
2836 get_tazwok_config
2837 echo -n "" > $PACKAGES_REPOSITORY/broken
2838 if [ -f /usr/bin/tazchroot ]; then
2839 cd $LOCAL_REPOSITORY
2840 [ ! -f tazchroot.conf ] && configure_tazchroot
2841 tazchroot cook-toolchain
2842 # Buggy : chroot can be elsewhere.
2843 rm -r $LOCAL_REPOSITORY/chroot
2844 # /!\ to be writed :
2845 # next rm chroot and plan cook-all by pushing all packages
2846 # in cooklist.
2847 else
2848 echo "The packages tazchroot need to be installed" >&2
2849 exit 1
2850 fi
2851 ;;
2852 webserver)
2853 check_root
2854 get_tazwok_config
2855 if [ "$ARG" = on ]; then
2856 if [ "$WEBSERVER" ] && [ -f "$WEBSERVER/repositories.list" ] && \
2857 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
2858 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
2859 exit 1
2860 fi
2861 if ! [ -f $LOCAL_REPOSITORY/tazchroot.conf ]; then
2862 tazwok configure-chroot ${undigest:+--undigest=$undigest} --SLITAZ_VERSION=$SLITAZ_VERSION --SLITAZ_DIR=$SLITAZ_DIR
2863 fi
2864 for pkg in php lighttpd; do
2865 [ -d $INSTALLED/$pkg ] || missing="$missing $pkg"
2866 done
2867 if [ "$missing" ]; then
2868 echo "You need to install those packages to start webserver: $missing." >&2
2869 exit 1
2870 fi
2871 if [ ! -f "$LOCAL_REPOSITORY/tazwok.conf" ]; then
2872 echo "Copying /etc/slitaz/tazwok.conf to $LOCAL_REPOSITORY/tazwok.conf: webserver is configured repository-by-repository."
2873 cp /etc/slitaz/tazwok.conf $LOCAL_REPOSITORY
2874 fi
2875 if ! [ "$WEBSERVER" ]; then
2876 echo -n "Where to store php pages (default: /var/www/vhosts/bb)? "
2877 read WEBSERVER
2878 [ "$WEBSERVER" ] || WEBSERVER="/var/www/vhosts/bb"
2879 fi
2880 if [ -f "$WEBSERVER/repositories.list" ] && \
2881 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
2882 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
2883 exit 1
2884 fi
2885 mkdir -p $WEBSERVER
2886 echo "${undigest:-$SLITAZ_VERSION}" >> $WEBSERVER/repositories.list
2887 for file in index.php log.php; do
2888 [ -f "$WEBSERVER/$file" ] || ln -s /usr/share/slitaz/web-bb/$file $WEBSERVER
2889 done
2890 source $LOCAL_REPOSITORY/tazchroot.conf
2891 echo "<?php
2893 // Web interface configuration
2895 \$version=\"${undigest:-$SLITAZ_VERSION}\";
2896 \$chroot=\"$chroot_dir\";
2897 \$lockfile=\"\$chroot/proc/1\";
2898 \$db_dir=\"$PACKAGES_REPOSITORY\";
2899 \$log_dir=\"$LOCAL_REPOSITORY/log\";
2900 \$packages=\"$PACKAGES_REPOSITORY\";
2901 \$incoming=\"$INCOMING_REPOSITORY\";
2903 ?>" > $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
2904 [ -L "$WEBSERVER/web" ] || ln -s /usr/share/slitaz/web $WEBSERVER
2905 echo "WEBSERVER=\"$WEBSERVER\"" >> $LOCAL_REPOSITORY/tazwok.conf
2906 if [ -L "$WEBSERVER/conf.php" ]; then
2907 echo "Do yo want to make ${undigest:-$SLITAZ_VERSION} the default page (y/N) ? "
2908 read answer
2909 if [ "$answer" = y ]; then
2910 rm $WEBSERVER/conf.php
2911 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
2912 fi
2913 else
2914 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
2915 fi
2916 elif [ "$ARG" = off ]; then
2917 if ! [ "$WEBSERVER" ]; then
2918 echo "No webserver running for ${undigest:-$SLITAZ_VERSION}" >&2
2919 exit 1
2920 fi
2921 sed '/^WEBSERVER/d' -i $LOCAL_REPOSITORY/tazwok.conf
2922 sed "/^${undigest:-$SLITAZ_VERSION}$/d" -i $WEBSERVER/repositories.list
2923 rm $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
2924 if ! [ -s "$WEBSERVER/repositories.list" ]; then
2925 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"
2926 rm $WEBSERVER/conf.php
2927 elif [ "$(readlink $WEBSERVER/conf.php)" = "$WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php" ]; then
2928 echo "${undigest:-$SLITAZ_VERSION} was the default version to use; switched to : $(sed 1!d $WEBSERVER/repositories.list)"
2929 rm $WEBSERVER/conf.php
2930 ln -s $WEBSERVER/conf-$(sed 1!d $WEBSERVER/repositories.list).php $WEBSERVER/conf.php
2931 fi
2932 else
2933 echo "Usage: tazwok webserver on/off" >&2
2934 exit 1
2935 fi
2936 ;;
2937 usage|*)
2938 # Print usage also for all unknown commands.
2940 usage
2941 ;;
2942 esac
2944 report stop 2>/dev/null || exit 0