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