tazwok view tazwok @ rev 238

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