tazwok view tazwok @ rev 252

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