tazwok view tazwok @ rev 307

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