tazwok view tazwok @ rev 412

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