tazwok view tazwok @ rev 267

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