tazwok view tazwok @ rev 419

tazwok: fix source path on mirror.slitaz.org
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Mar 05 21:04:28 2011 +0100 (2011-03-05)
parents 433aa071e16c
children 4032fb1d58d2
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/${TARBALL: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/${TARBALL: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 return
1211 fi
1212 report step "Updating packages lists: $pkg_repository"
1213 packages_db_start
1215 # Look for removed/update packages.
1216 touch stamp -r packages.list
1217 for PACKAGE in $(grep ^[0-9,a-z,A-Z] packages.txt); do
1218 pkg="$pkg_repository/$(grep -m1 ^$PACKAGE- packages.list).tazpkg"
1219 if ! [ -f "$pkg" ]; then
1220 erase_package_info
1221 else
1222 if [ "$pkg" -nt "stamp" ]; then
1223 updated_pkg="$updated_pkg
1224 $PACKAGE $pkg"
1225 elif [ ! -f $WOK/$PACKAGE/receipt ] && \
1226 [ "$COMMAND" = check-incoming -o "$pkg_repository" = "$INCOMING_REPOSITORY" ]; then
1227 erase_package_info
1228 echo "Removing $PACKAGE from $pkg_repository."
1229 rm $pkg
1230 [ -d $WOK/$PACKAGE ] && rm -r $WOK/$PACKAGE
1231 sed "/^$PACKAGE\t/d" -i $wan_db $dep_db
1232 for i in cookorder.txt cooklist commit blocked broken; do
1233 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/$i
1234 done
1235 rm -f $LOCAL_REPOSITORY/log/$PACKAGE.html
1236 if [ "$pkg_repository" = "$INCOMING_REPOSITORY" ] && \
1237 [ "$(sed 1!d $PACKAGES_REPOSITORY/cookorder.txt)" != "#PlanSort" ] ; then
1238 sed 1i"#PlanSort" -i $PACKAGES_REPOSITORY/cookorder.txt
1239 regen_cooklist=yes
1240 else
1241 echo "$PACKAGE" >> $PACKAGES_REPOSITORY/removed
1242 sed -n '1,10p' -i $PACKAGES_REPOSITORY/removed
1243 fi
1244 fi
1245 fi
1246 done
1247 rm stamp
1248 echo "$updated_pkg" | sed 1d | while read PACKAGE pkg; do
1249 erase_package_info
1250 get_packages_info
1251 done
1252 unset updated_pkg
1254 # Look for new packages.
1255 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1256 if ! fgrep -q " ${pkg##*/}" $pkg_repository/packages.md5; then
1257 get_packages_info
1258 fi
1259 done
1260 report end-step
1261 packages_db_end
1264 packages_db_start()
1266 if [ ! -s packages.txt ]; then
1267 echo "# SliTaz GNU/Linux - Packages list
1269 # Packages : unknow
1270 # Date : $(date +%Y-%m-%d\ \%H:%M:%S)
1272 " > packages.txt
1273 else
1274 sed -e 's/^# Packages :.*/# Packages : unknow/' \
1275 -e "s/# Date :.*/# Date : $(date +%Y-%m-%d\ \%H:%M:%S)/" \
1276 -i packages.txt
1277 fi
1279 # Needed in some case as tazwok define RECEIPT at configuration time
1280 # in this particular case it can broke the script.
1281 unset RECEIPT
1284 erase_package_info()
1286 cd $pkg_repository
1287 sed "/^$PACKAGE$/,/^$/d" -i packages.txt
1288 sed "/^$PACKAGE /d" -i packages.desc
1289 sed -e "s/=$PACKAGE /= /" -e "s/ $PACKAGE / /" -e "s/ $PACKAGE$//" \
1290 -e "/=$PACKAGE$/d" -e "s/=[0-9,a-z,A-Z]:$PACKAGE /= /" \
1291 -e "s/ [0-9,a-z,A-Z]:$PACKAGE / /" -e "s/ [0-9,a-z,A-Z]:$PACKAGE$/ /" \
1292 -e "/=[0-9,a-z,A-Z]:$PACKAGE$/d" \
1293 -i packages.equiv
1294 sed "/^$PACKAGE:/d" -i files.list
1295 sed "/^$(basename ${pkg%.tazpkg})$/d" -i packages.list
1296 sed "/ $(basename $pkg)$/d" -i packages.md5
1299 get_packages_info()
1301 # If there's no taz folder in the wok, extract infos from the
1302 # package.
1303 get_pkg_files $pkg
1304 source_receipt
1305 echo "Getting datas from $PACKAGE"
1307 cat >> $pkg_repository/packages.txt << _EOT_
1308 $PACKAGE
1309 $VERSION$EXTRAVERSION
1310 $SHORT_DESC
1311 _EOT_
1312 if [ "$PACKED_SIZE" ]; then
1313 cat >> $pkg_repository/packages.txt << _EOT_
1314 $PACKED_SIZE ($UNPACKED_SIZE installed)
1316 _EOT_
1317 else
1318 echo "" >> $pkg_repository/packages.txt
1319 fi
1321 # Packages.desc is used by Tazpkgbox <tree>.
1322 echo "$PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> $pkg_repository/packages.desc
1324 # Packages.equiv is used by tazpkg install to check depends
1325 for i in $PROVIDE; do
1326 DEST=""
1327 echo $i | fgrep -q : && DEST="${i#*:}:"
1328 if grep -qs ^${i%:*}= $pkg_repository/packages.equiv; then
1329 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" $pkg_repository/packages.equiv
1330 else
1331 echo "${i%:*}=$DEST$PACKAGE" >> $pkg_repository/packages.equiv
1332 fi
1333 done
1335 if [ -f files.list ]; then
1336 { echo "$PACKAGE"; cat files.list; } | awk '
1337 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }' >> $pkg_repository/files.list
1338 fi
1340 cd .. && rm -r "$pkg_files_dir"
1342 cd $pkg_repository
1343 echo $(basename ${pkg%.tazpkg}) >> packages.list
1344 [ ! "$package_md5" ] && package_md5=$(md5sum $(basename $pkg))
1345 echo "$package_md5" >> packages.md5
1346 unset package_md5
1349 source_receipt()
1351 unset PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
1352 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
1353 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
1354 src _pkg DESTDIR CONFIG_SITE BRANCH TARBALL stuff wanted_stuff
1355 . ${RECEIPT:-$PWD/receipt}
1358 packages_db_end()
1360 cd $pkg_repository
1361 pkgs=$(wc -l packages.list | sed 's/ .*//')
1362 sed "s/# Packages : .*/# Packages : $pkgs/" -i packages.txt
1364 # If lists was updated it's generally needed to sort them well.
1365 if ! sort -c packages.list 2> /dev/null; then
1366 report step "Sorting packages lists"
1367 for file in packages.list packages.desc packages.equiv; do
1368 [ -f $file ] || continue
1369 sort -o $file $file
1370 done
1371 report end-step
1372 fi
1374 # Dont log this because lzma always output error.
1375 lzma e files.list files.list.lzma
1376 rm -f files.list
1377 [ -f packages.equiv ] || touch packages.equiv
1380 ########################################################################
1381 # This section contains functions to generate wok database.
1382 ########################
1384 gen_wok_db()
1386 report step "Generating wok database"
1387 report open-bloc
1388 report step "Removing old files"
1389 for file in $wan_db $dep_db $PACKAGES_REPOSITORY/cookorder.txt; do
1390 [ -f $file ] && rm $file
1391 done
1392 report step "Generating wok-wanted.txt"
1393 gen_wan_db
1394 report step "Generating wok-depends.txt"
1395 for PACKAGE in $(cut -f1 -d '|' $PACKAGES_REPOSITORY/packages.desc \
1396 $INCOMING_REPOSITORY/packages.desc | sort -u); do
1397 RECEIPT=$WOK/$PACKAGE/receipt
1398 if [ -s $RECEIPT ]; then
1399 source_receipt
1400 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
1401 fi
1402 done
1403 sort_db
1404 report close-bloc
1407 gen_wan_db()
1409 for RECEIPT in $(fgrep -l WANTED $WOK/*/receipt); do
1410 WANTED=
1411 source $RECEIPT
1412 [ "$WANTED" ] || continue
1413 echo -e $PACKAGE"\t"$WANTED >> $tmp/wan_db
1414 done
1415 if ! [ -f $wan_db ] || [ "$(diff -q $tmp/wan_db $wan_db)" ]; then
1416 mv -f $tmp/wan_db $wan_db
1417 plan_regen_cookorder=yes
1418 else
1419 rm $tmp/wan_db
1420 fi
1423 update_wan_db()
1425 local PACKAGE=$PACKAGE
1426 for RECEIPT in $(fgrep WANTED $WOK/*/receipt | \
1427 fgrep $PACKAGE | cut -f1 -d ':'); do
1428 WANTED=
1429 source $RECEIPT
1430 [ "$WANTED" ] || continue
1431 wan_info=$(echo -e $PACKAGE"\t"$WANTED)
1432 [ "$wan_info" = "$(grep -m1 ^$PACKAGE$'\t' $wan_db 2>/dev/null)" ] && continue
1433 sed "/^$PACKAGE\t/d" -i $wan_db
1434 echo "$wan_info" >> $wan_db
1435 plan_regen_cookorder=yes
1436 plan_sort_wandb=yes
1437 done
1440 update_dep_db()
1442 dep_info=$(echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ')
1443 [ "$dep_info" = "$(grep -m1 ^$PACKAGE$'\t' $dep_db 2>/dev/null)" ] && return
1444 sed "/^$PACKAGE\t/d" -i $dep_db
1445 echo "$dep_info" >> $dep_db
1446 plan_regen_cookorder=yes
1447 plan_sort_depdb=yes
1450 sort_db()
1452 report step "Generating cookorder.txt"
1453 cat $dep_db | sed 's/ \t / /' | while read PACKAGE BUILD_DEPENDS; do
1454 grep -q ^$PACKAGE$'\t' $wan_db && continue
1456 # Replace each BUILD_DEPENDS with a WANTED package by it's
1457 # WANTED package.
1458 replace_by_wanted()
1460 for p in $BUILD_DEPENDS; do
1461 if grep -q ^$p$'\t' $wan_db; then
1462 echo -n $(grep ^$p$'\t' $wan_db | cut -f 2)' '
1463 else
1464 echo -n $p' '
1465 fi
1466 done | tr ' ' '\n' | sort -u | sed "/^$PACKAGE$/d" | tr '\n' ' '
1468 echo -e $PACKAGE"\t $(replace_by_wanted) "
1469 done > $tmp/db
1470 while [ -s "$tmp/db" ]; do
1471 status=start
1472 for pkg in $(cut -f 1 $tmp/db); do
1473 if ! fgrep -q ' '$pkg' ' $tmp/db; then
1474 echo $pkg >> $tmp/cookorder
1475 sed -e "/^$pkg\t/d" -e "s/ $pkg / /g" -i $tmp/db
1476 status=proceed
1477 fi
1478 done
1479 if [ "$status" = start ]; then
1480 cp -f $tmp/db /tmp/remain-depends.txt
1481 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
1482 for blocked in $(cut -f 1 $tmp/db); do
1483 echo "$blocked" >> $PACKAGES_REPOSITORY/blocked
1484 done
1485 break
1486 fi
1487 done
1488 [ -s $tmp/cookorder ] || touch $tmp/cookorder
1490 # The toolchain packages are moved in first position.
1491 grep $(for pkg in `scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
1492 --look_for=all --with_args`; do echo " -e ^$pkg$"; done) \
1493 $tmp/cookorder | tac > $PACKAGES_REPOSITORY/cookorder.txt
1494 for pkg in $(cat $PACKAGES_REPOSITORY/cookorder.txt); do
1495 sed "/^$pkg$/d" -i $tmp/cookorder
1496 done
1498 tac $tmp/cookorder >> $PACKAGES_REPOSITORY/cookorder.txt
1499 unset plan_regen_cookorder
1500 report end-step
1503 ########################################################################
1504 # SCAN CORE
1505 ########################
1506 # Include various scan core-functions. It's not intended to be used
1507 # directly : prefer scan wrappers in next section.
1509 look_for_dep()
1511 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1512 grep -m1 ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
1513 | cut -f 2
1514 else
1515 grep -m1 ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-depends.txt | \
1516 cut -f 2
1517 fi
1520 look_for_bdep()
1522 look_for_all
1525 look_for_all()
1527 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1528 grep -m1 ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
1529 | cut -f 2,3 | sed 's/ / /'
1530 else
1531 grep -m1 ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-depends.txt | \
1532 cut -f 2,3 | sed 's/ / /'
1533 fi
1536 look_for_rdep()
1538 fgrep ' '$PACKAGE' ' $INCOMING_REPOSITORY/wok-depends.txt | cut -f 1
1539 if [ "$undigest" ]; then
1540 for rdep in $(fgrep ' '$PACKAGE' ' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt | cut -f 1); do
1541 if [ ! -f "WOK$/$rdep/receipt" ]; then
1542 echo "$rdep"
1543 fi
1544 done
1545 fi
1548 look_for_rbdep()
1550 fgrep ' '$PACKAGE' ' $INCOMING_REPOSITORY/wok-depends.txt | \
1551 cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1552 if [ "$undigest" ]; then
1553 for rdep in $(fgrep ' '$PACKAGE' ' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
1554 | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1); do
1555 if [ ! -f "WOK$/$rdep/receipt" ]; then
1556 echo "$rdep"
1557 fi
1558 done
1559 fi
1562 # Return WANTED if it exists.
1563 look_for_wanted()
1565 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1566 grep -m1 ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-wanted.txt | cut -f 2
1567 else
1568 grep -m1 ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-wanted.txt | cut -f 2
1569 fi
1572 # Return packages which wants PACKAGE.
1573 look_for_rwanted()
1575 grep $'\t'$PACKAGE$ $INCOMING_REPOSITORY/wok-wanted.txt | cut -f 1
1576 if [ "$undigest" ]; then
1577 for rwanted in $(grep $'\t'$PACKAGE$ $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-wanted.txt | cut -f 1); do
1578 if [ ! -f "$WOK/$rwanted/receipt" ]; then
1579 echo "$rwanted"
1580 fi
1581 done
1582 fi
1585 look_for_dev()
1587 WANTED=$(look_for_wanted)
1588 if [ "$WANTED" ]; then
1589 if [ "$undigest" ] && [ ! -f "$WOK/$WANTED/receipt" ]; then
1590 [ -f "$SLITAZ_DIR/$SLITAZ_VERSION/wok/$WANTED-dev/receipt" ] && echo $WANTED-dev
1591 else
1592 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1593 fi
1594 fi
1595 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1596 [ -f "$SLITAZ_DIR/$SLITAZ_VERSION/wok/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1597 else
1598 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1599 fi
1602 with_dev()
1604 for PACKAGE in $(cat); do
1605 echo $PACKAGE
1606 look_for_dev
1607 done
1610 with_wanted()
1612 for PACKAGE in $(cat); do
1613 echo $PACKAGE
1614 look_for_wanted
1615 done
1618 use_wanted()
1620 for input in $(cat); do
1621 { grep ^$input$'\t' $wan_db || echo $input
1622 } | sed 's/.*\t//'
1623 done
1626 ########################################################################
1627 # SCAN
1628 ########################
1629 # Use wok-wanted.txt and wok-depeds.txt to scan depends.
1630 # Option in command line (must be first arg) :
1631 # --look_for=bdep/rbdep - Look for depends or reverse depends.
1632 # --with_dev - Add development packages (*-dev) in the result.
1633 # --with_wanted - Add package+reverse wanted in the result.
1634 # --with_args - Include packages in argument in the result.
1636 scan()
1638 # Get packages in argument.
1639 local PACKAGE=$PACKAGE WANTED=$WANTED pkg_list=
1640 for arg in $@; do
1641 [ "$arg" = "${arg#--}" ] || continue
1642 pkg_list="$pkg_list $arg"
1643 done
1645 # Get options.
1646 [ "$pkg_list" ] || return
1647 local cooklist= look_for= with_dev= with_wanted= with_args= log_command="$0 $@" \
1648 get_options_list="look_for with_dev with_wanted with_args cooklist use_wanted"
1649 get_options
1651 # Cooklist is a special case where we need to modify a little
1652 # scan behavior
1653 if [ "$cooklist" ]; then
1654 gen_wan_db
1655 look_for=all && with_args=yes && with_dev= && with_wanted=
1656 filter=use_wanted
1657 if [ "$COMMAND" = gen-cooklist ]; then
1658 for PACKAGE in $pkg_list; do
1659 grep -q ^$PACKAGE$'\t' $dep_db && continue
1660 [ -d "$WOK/$p" ] || continue
1661 check_for_missing
1662 done
1663 append_to_dep()
1665 if ! grep -q ^$PACKAGE$'\t' $dep_db; then
1666 check_for_missing && echo $PACKAGE >> $tmp/dep
1667 else
1668 echo $PACKAGE >> $tmp/dep
1669 fi
1671 else
1672 append_to_dep()
1674 check_for_commit && echo $PACKAGE >> $tmp/dep
1676 fi
1677 else
1678 append_to_dep()
1680 echo $PACKAGE >> $tmp/dep
1682 # If requested packages are not in dep_db, partial generation of this db is needed.
1683 for PACKAGE in $pkg_list; do
1684 grep -q ^$PACKAGE$'\t' $dep_db && continue
1685 [ -d "$WOK/$p" ] || continue
1686 plan_check_for_missing=yes
1687 check_for_missing
1688 done
1689 if [ "$plan_check_for_missing" ]; then
1690 append_to_dep()
1692 if ! grep -q ^$PACKAGE$'\t' $dep_db; then
1693 check_for_missing && echo $PACKAGE >> $tmp/dep
1694 else
1695 echo $PACKAGE >> $tmp/dep
1696 fi
1698 check_db_status=yes
1699 unset plan_check_for_missing
1700 fi
1701 fi
1703 [ "$with_dev" ] && filter=with_dev
1704 [ "$with_wanted" ] && filter=with_wanted
1705 if [ "$filter" ]; then
1706 pkg_list=$(echo $pkg_list | $filter | sort -u)
1707 scan_pkg()
1709 look_for_$look_for | $filter
1711 else
1712 scan_pkg()
1714 look_for_$look_for
1716 fi
1717 touch $tmp/dep
1718 for PACKAGE in $pkg_list; do
1719 [ "$with_args" ] && append_to_dep
1720 scan_pkg
1721 done | tr ' ' '\n' | sort -u > $tmp/list
1722 [ "$look_for" = bdep ] && look_for=dep
1723 while [ -s $tmp/list ]; do
1724 PACKAGE=$(sed 1!d $tmp/list)
1725 sed 1d -i $tmp/list
1726 append_to_dep
1727 for pkg in $(scan_pkg); do
1728 if ! grep -q ^$pkg$ $tmp/list $tmp/dep; then
1729 echo $pkg >> $tmp/list
1730 fi
1731 done
1732 done
1733 if [ "$cooklist" ]; then
1734 mv $tmp/dep $tmp/cooklist
1735 else
1736 cat $tmp/dep | sort -u
1737 fi
1738 rm -f $tmp/dep $tmp/list
1739 if [ "$check_db_status" ]; then
1740 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
1741 [ "$plan_sort_wandb" ] && sort -o $wan_db $wan_db && unset plan_sort_wandb
1742 if [ "$plan_regen_cookorder" ] && \
1743 [ "$(sed 1!d $PACKAGES_REPOSITORY/cookorder.txt)" != "#PlanSort" ]; then
1744 grep -q "^#" $PACKAGES_REPOSITORY/cookorder.txt || \
1745 sed 1i"#PlanSort" -i $PACKAGES_REPOSITORY/cookorder.txt
1746 fi
1747 fi
1750 ########################################################################
1751 # This section contains functions to check package repository and
1752 # find which packages to cook.
1753 ########################
1755 check_for_missing()
1757 local PACKAGE=$PACKAGE
1758 if ! check_for_pkg_in_wok; then
1759 [ "$?" = 2 ] && return 1
1760 return
1761 fi
1762 RECEIPT=$WOK/$PACKAGE/receipt
1763 source_receipt
1764 PACKAGE=${WANTED:-$PACKAGE}
1765 update_wan_db
1766 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1767 RECEIPT=$WOK/$PACKAGE/receipt
1768 source_receipt
1769 update_dep_db
1770 done
1773 check_for_commit()
1775 if ! check_for_pkg_in_wok; then
1776 [ "$?" = 2 ] && return 1
1777 return
1778 fi
1779 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1780 RECEIPT=$WOK/$PACKAGE/receipt
1781 source_receipt
1783 # We use md5 of cooking stuff in the packaged receipt to check
1784 # commit. We look consecutively in 3 different locations :
1785 # - in the wok/PACKAGE/taz/* folder
1786 # - in the receipt in the package in incoming repository
1787 # - in the receipt in the package in packages repository
1788 # If md5sum match, there's no commit.
1789 check_for_commit_using_md5sum()
1791 if [ ! -f $WOK/$PACKAGE/md5 ]; then
1792 sed -n '/# md5sum of cooking stuff :/,$p' receipt | \
1793 sed -e 1d -e 's/^# //' > $WOK/$PACKAGE/md5
1794 cd $WOK/$PACKAGE
1795 fi
1797 if [ -s md5 ]; then
1798 if md5sum -cs md5; then
1800 # If md5sum check if ok, check for new/missing files in
1801 # cooking stuff.
1802 for file in $([ -f receipt ] && echo receipt; \
1803 [ -f description.txt ] && echo description.txt; \
1804 [ -d stuff ] && find stuff); do
1805 if ! fgrep -q " $file" md5; then
1806 set_commited
1807 fi
1808 done
1809 else
1810 set_commited
1811 fi
1812 else
1813 set_commited
1814 fi
1816 set_commited()
1818 ! grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/commit &&
1819 echo $PACKAGE >> $PACKAGES_REPOSITORY/commit
1820 gen_cookmd5
1821 update_dep_db
1823 taz_dir=$(echo $WOK/$PACKAGE/taz/$PACKAGE-* | fgrep -v '*')
1824 if [ -f $WOK/$PACKAGE/md5 ]; then
1825 cd $WOK/$PACKAGE
1826 check_for_commit_using_md5sum
1827 elif [ "$taz_dir" ]; then
1828 cd $taz_dir
1829 check_for_commit_using_md5sum
1830 else
1831 pkg=$(echo $INCOMING_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
1832 [ "$pkg" ] || pkg=$(echo $PACKAGES_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
1833 if [ "$pkg" ]; then
1834 get_pkg_files $pkg
1835 check_for_commit_using_md5sum
1836 rm -r $pkg_files_dir
1837 else
1838 set_commited
1839 fi
1840 fi
1841 [ "$forced" ] || echo $PACKAGE >> $tmp/checked
1842 done
1843 return
1846 gen_cook_list()
1848 report step "Scanning wok"
1849 if [ "$pkg" ]; then
1850 scan $pkg --cooklist
1851 else
1852 scan `cat $cooklist` --cooklist
1853 fi
1854 report end-step
1856 [ -s $tmp/checked ] || [ -s $tmp/cooklist ] || return
1858 # Core toolchain should not be cooked unless cook-toolchain is used.
1859 if ! [ -f /etc/config.site.tmptoolchain ] ; then
1860 for PACKAGE in $(scan gcc --look_for=all --with_args --with_wanted); do
1861 grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/blocked || \
1862 echo $PACKAGE >> $PACKAGES_REPOSITORY/blocked
1863 done
1864 fi
1866 if [ -s $PACKAGES_REPOSITORY/commit ] && [ "$COMMAND" != gen-cooklist ]; then
1867 cd $PACKAGES_REPOSITORY
1868 for PACKAGE in $(cat commit); do
1869 WANTED="$(look_for_wanted)"
1870 if [ "$WANTED" ]; then
1871 grep -q ^$WANTED$ broken cooklist blocked commit && continue
1872 fi
1873 grep -q ^$PACKAGE$ blocked cooklist && continue
1874 echo $PACKAGE >> cooklist
1875 done
1876 fi
1877 sort_cooklist
1880 sort_cooklist()
1882 if [ "$(sed 1!d $PACKAGES_REPOSITORY/cookorder.txt)" = "#PlanSort" ]; then
1883 sed 1d -i $PACKAGES_REPOSITORY/cookorder.txt
1884 plan_regen_cookorder=yes
1885 fi
1886 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
1887 [ "$plan_regen_cookorder" ] && sort_db
1888 report step "Generating cooklist"
1889 if [ -f "$tmp/checked" ]; then
1890 rm -f $tmp/cooklist
1891 cat $tmp/checked | while read PACKAGE; do
1892 grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/cooklist && \
1893 echo $PACKAGE >> $tmp/cooklist
1894 done
1895 elif ! [ "$COMMAND" = gen-cooklist ]; then
1896 cat $PACKAGES_REPOSITORY/blocked | while read PACKAGE; do
1897 sed "/^$PACKAGE/d" -i $tmp/cooklist
1898 done
1899 fi
1900 report end-step
1901 [ -s $tmp/cooklist ] || return
1903 report step "Sorting cooklist"
1904 for PACKAGE in $(cat $tmp/cooklist); do
1905 WANTED="$(look_for_wanted)"
1906 [ "$WANTED" ] || continue
1907 if grep -q ^$WANTED$ $PACKAGES_REPOSITORY/broken $tmp/cooklist; then
1908 sed "/^$PACKAGE$/d" -i $tmp/cooklist
1909 elif [ ! -d $WOK/$WANTED/install ]; then
1910 sed "/^$PACKAGE$/d" -i $tmp/cooklist
1911 echo $WANTED >> $tmp/cooklist
1912 fi
1913 done
1915 # Use cookorder.txt to sort cooklist.
1916 if [ -s $tmp/cooklist ]; then
1917 cat $PACKAGES_REPOSITORY/cookorder.txt | while read PACKAGE; do
1918 if grep -q ^$PACKAGE$ $tmp/cooklist; then
1919 sed "/^$PACKAGE$/d" -i $tmp/cooklist
1920 echo $PACKAGE >> $tmp/cooklist.tmp
1921 fi
1922 done
1924 # Remaining packages in cooklist are thoses without compile_rules.
1925 # They can be cooked first in any order.
1926 if [ -f $tmp/cooklist.tmp ]; then
1927 cat $tmp/cooklist.tmp >> $tmp/cooklist
1928 rm $tmp/cooklist.tmp
1929 fi
1931 cat $tmp/cooklist
1932 [ "$cooklist" = "$PACKAGES_REPOSITORY/cooklist" ] && \
1933 cat $tmp/cooklist > $cooklist
1934 fi
1936 report end-step
1939 look_for_missing_pkg()
1941 for pkg in $(cat $PACKAGES_REPOSITORY/$1); do
1942 grep -q ^$pkg$ $INCOMING_REPOSITORY/packages.txt \
1943 $PACKAGES_REPOSITORY/packages.txt || \
1944 continue
1945 echo $pkg
1946 done
1949 check_for_incoming()
1951 report step "Check that all packages were cooked fine"
1952 [ -s $INCOMING_REPOSITORY/packages.desc ] || {
1953 echo "No packages in $INCOMING_REPOSITORY."
1954 report end-step; return; }
1955 if [ -s $PACKAGES_REPOSITORY/broken ]; then
1956 missingpkg=$(look_for_missing_pkg broken)
1957 if [ "$missingpkg" ]; then
1958 echo "Don't move incoming packages to main repository because theses ones are broken:" >&2
1959 echo "$missingpkg"
1960 report end-step
1961 return 1
1962 fi
1963 fi
1964 if [ -s $PACKAGES_REPOSITORY/cooklist ]; then
1965 missingpkg=$(look_for_missing_pkg cooklist)
1966 if [ "$missingpkg" ]; then
1967 echo "Don't move incoming packages to main repository because theses ones needs to be cooked:" >&2
1968 echo "$missingpkg"
1969 report end-step
1970 return 1
1971 fi
1972 fi
1973 incoming_pkgs="$(cut -f 1 -d '|' $INCOMING_REPOSITORY/packages.desc)"
1974 if ! [ "$forced" ]; then
1975 cooklist=$PACKAGES_REPOSITORY/cooklist
1976 pkg="$incoming_pkgs"
1977 gen_cook_list
1978 if [ -s $PACKAGES_REPOSITORY/cooklist ]; then
1979 missingpkg=$(look_for_missing_pkg cooklist)
1980 if [ "$missingpkg" ]; then
1981 echo "Don't move incoming packages to main repository because theses ones needs to be cooked:" >&2
1982 echo "$missingpkg"
1983 report end-step
1984 return 1
1985 fi
1986 fi
1987 fi
1989 report step "Moving incoming packages to main repository"
1990 unset EXTRAVERSION
1991 for PACKAGE in $incoming_pkgs; do
1992 prev_VERSION=$(get_pkg_version $PACKAGES_REPOSITORY)
1993 VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
1994 remove_previous_package $PACKAGES_REPOSITORY
1995 echo "Moving $PACKAGE..."
1996 mv -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION.tazpkg $PACKAGES_REPOSITORY
1997 touch $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
1998 previous_tarball=$(grep ^$PACKAGE:main $SOURCES_REPOSITORY/sources.list | cut -f2)
1999 sed -e "/^$PACKAGE:main/d" \
2000 -e "s/^$PACKAGE:incoming/$PACKAGE:main/" \
2001 -i $SOURCES_REPOSITORY/sources.list
2002 if [ "$previous_tarball" ]; then
2003 grep -q $'\t'$previous_tarball$ $SOURCES_REPOSITORY/sources.list || \
2004 rm -f $SOURCES_REPOSITORY/$previous_tarball
2005 fi
2006 done
2007 for file in packages.list packages.equiv packages.md5 packages.desc \
2008 packages.txt; do
2009 echo -n "" > $INCOMING_REPOSITORY/$file
2010 done
2011 rm -r $INCOMING_REPOSITORY/files.list.lzma
2012 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2014 report step "Updating flavors"
2015 if [ -x /usr/bin/tazlito ] || [ -x /usr/bin/clean-chroot ]; then
2016 if ! [ -x /usr/bin/tazlito ]; then
2017 tazpkg get-install tazlito
2018 fi
2020 # Handle cases where tazwok is used into main system;
2021 # Handle cases where SLITAZ_DIR is not /home/slitaz.
2022 [ -L /home/slitaz/flavors ] && rm /home/slitaz/flavors
2023 mkdir -p /home/slitaz
2024 ln -s $LOCAL_REPOSITORY/flavors /home/slitaz/flavors
2026 cd $LOCAL_REPOSITORY/packages
2027 for i in $LOCAL_REPOSITORY/flavors/*; do
2028 [ -d "$i" ] || continue
2029 tazlito pack-flavor ${i##*/}
2030 done
2032 noheader=""
2033 for i in *.flavor; do
2034 tazlito show-flavor $i --brief $noheader
2035 noheader="--noheader"
2036 done > flavors.list
2037 [ -x /usr/bin/clean-chroot ] && clean-chroot
2038 else
2039 echo "Can't create up-to-date flavors because tazlito package is missing." >&2
2040 fi
2041 report end-step
2044 ########################################################################
2045 # TAZWOK MAIN FUNCTIONS
2046 ########################
2048 clean()
2050 cd $WOK/$PACKAGE
2051 ls -A $WOK/$PACKAGE | grep -q -v -e ^receipt$ -e ^description.txt$ \
2052 -e ^stuff$ || return
2054 [ "$COMMAND" = clean-wok ] || report step "Cleaning $PACKAGE"
2055 # Check for clean_wok function.
2056 if grep -q ^clean_wok $RECEIPT; then
2057 clean_wok
2058 fi
2059 # Clean should only have a receipt, stuff and optional desc.
2060 for f in `ls .`
2061 do
2062 case $f in
2063 receipt|stuff|description.txt|md5)
2064 continue ;;
2065 *)
2066 rm -rf $f ;;
2067 esac
2068 done
2069 [ "$COMMAND" != clean-wok ] && report end-step
2072 # Configure and make a package with the receipt.
2073 compile_package()
2075 check_for_package_on_cmdline
2077 # Include the receipt to get all needed variables and functions
2078 # and cd into the work directory to start the work.
2079 check_for_receipt
2080 source_receipt
2082 # Log the package name and date.
2083 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
2084 echo "package $PACKAGE (compile)" >> $LOG
2086 # Set wanted $src variable to help compiling.
2087 [ ! "$src" ] && set_src_path
2088 check_for_build_depends || return 1
2089 check_for_wanted
2090 unset target
2091 check_for_tarball && check_for_compile_rules
2094 # Cook command also include all features to manage lists which keep
2095 # track of wok/packages state.
2096 cook()
2098 cook_code=
2099 set_common_path
2100 check_for_receipt
2101 source_receipt
2103 # Define log path and start report.
2104 [ -f $LOCAL_REPOSITORY/log/$PACKAGE.html ] && rm $LOCAL_REPOSITORY/log/$PACKAGE.html
2105 report sublog $LOCAL_REPOSITORY/log/$PACKAGE.html
2106 echo "$PACKAGE" > $LOCAL_REPOSITORY/log/package
2107 report step "Cooking $PACKAGE"
2108 report open-bloc
2110 clean $PACKAGE
2111 [ -s $tmp/cooklist ] && sed "/^$PACKAGE$/d" -i $tmp/cooklist
2113 if compile_package; then
2114 remove_src
2115 refresh_packages_from_compile
2116 gen_package
2118 # Update packages-incoming repository.
2119 store_pkgname=$PACKAGE
2120 pkg_repository=$INCOMING_REPOSITORY
2121 update_packages_db
2123 PACKAGE=$store_pkgname
2124 unset store_pkgname
2126 # Upgrade to cooked packages if it was previously installed.
2127 report step "Look for package(s) to upgrade"
2128 for pkg in $(look_for_rwanted) $PACKAGE; do
2129 if [ -d $INSTALLED/$pkg ]; then
2130 tazpkg get-install $pkg --forced
2131 fi
2132 done
2133 report end-step
2134 else
2135 set_pkg_broken
2136 cook_code=1
2137 fi
2139 # Remove build_depends in cook mode (if in cooklist, it's done when
2140 # checking build_depends of next package and we remove only unneeded
2141 # packages to keep chroot minimal and gain some time).
2142 if [ "$COMMAND" = cook ]; then
2143 remove_build_depends $MISSING_PACKAGE
2144 [ -x /usr/bin/clean-chroot ] && clean-chroot
2145 fi
2147 # Regen the cooklist if it was planned and command is not cook.
2148 [ "$regen_cooklist" ] && unset regen_cooklist && \
2149 [ "$COMMAND" != cook ] && sort_cooklist
2151 # Some hacks to set the bloc & function status as failed if cook was
2152 # failed.
2153 report_return_code=$cook_code
2154 report close-bloc
2155 report end-sublog
2156 rm -f $LOCAL_REPOSITORY/log/package
2157 return $cook_code
2160 cook_list()
2162 if [ -s $tmp/cooklist ]; then
2163 if [ -f /usr/bin/tazchroot ]; then
2164 # Note : options -main variables- are automatically keeped by
2165 # the sub-applications tazchroot/tazwok; as well as report data.
2166 cd $LOCAL_REPOSITORY
2167 [ ! -f tazchroot.conf ] && configure_tazchroot
2168 tazchroot tazwok cook-list --SLITAZ_DIR=$SLITAZ_DIR --SLITAZ_VERSION=$SLITAZ_VERSION ${undigest:+ --undigest=$undigest}
2169 return
2170 fi
2171 while [ -s $tmp/cooklist ]; do
2172 PACKAGE=$(sed 1!d $tmp/cooklist)
2173 cook
2174 done
2175 remove_build_depends $MISSING_PACKAGE $remove_later
2176 [ -x /usr/bin/clean-chroot ] && clean-chroot
2177 else
2178 echo "Nothing to cook."
2179 return
2180 fi
2183 configure_tazchroot()
2185 cat > $LOCAL_REPOSITORY/tazchroot.conf << EOF
2186 # Tazchroot configuration file - created by tazwok.
2188 # Default chroot path
2189 SLITAZ_DIR=$SLITAZ_DIR
2190 SLITAZ_VERSION=$SLITAZ_VERSION
2191 $( [ "$undigest" ] && echo "undigest=$undigest" )
2192 LOCAL_REPOSITORY=$SLITAZ_DIR/$(if [ "$undigest" ]; then echo '$undigest'; else echo '$SLITAZ_VERSION'; fi)
2193 chroot_dir=\$LOCAL_REPOSITORY/chroot
2195 # Default scripts path (theses scripts are added in the
2196 # $chroot_dir/usr/bin and can be called with tazchroot script)
2197 script_dir=/usr/lib/slitaz/chroot-scripts/tazwok
2199 # List of directories to mount.
2200 list_dir="$(for dir in packages wok src packages-incoming log flavors iso clean-wok; do echo $LOCAL_REPOSITORY/$dir; done)
2201 $SLITAZ_LOG$( [ "$undigest" ] && echo -e "\n$SLITAZ_DIR/$SLITAZ_VERSION/packages" )"
2203 create_chroot()
2205 mkdir -p \$chroot_dir
2206 for pkg in \$(tazwok build-depends toolchain --SLITAZ_DIR=\$SLITAZ_DIR --SLITAZ_VERSION=\$SLITAZ_VERSION${undigest:+ --undigest=\$undigest}); do
2207 tazpkg get-install \$pkg --root="\$chroot_dir"
2208 done
2210 # Store list of installed packages needed by cleanchroot.
2211 ls -1 \$chroot_dir/\$INSTALLED > \$chroot_dir/\$LOCALSTATE/chroot-pkgs
2213 sed -e "s~^SLITAZ_DIR=.*~SLITAZ_DIR=\$SLITAZ_DIR~" \\
2214 -e "s/^SLITAZ_VERSION=.*/SLITAZ_VERSION=\$SLITAZ_VERSION/" \\
2215 -i \$chroot_dir/etc/slitaz/slitaz.conf
2216 $( [ "$undigest" ] && echo ' echo "undigest='"$undigest"'" >> $chroot_dir/etc/slitaz/tazwok.conf')
2217 sed 's/LC_ALL/LC_ALL=POSIX/' -i \$chroot_dir/etc/profile
2218 # The build bot may run in a sandbox: link sandbox lockfile
2219 ln -s \$LOCAL_REPOSITORY/sandbox/proc/1 \$chroot_dir/proc/1
2222 mount_chroot()
2224 cp -a /etc/resolv.conf \$chroot_dir/etc/resolv.conf
2225 echo "\$LOCAL_REPOSITORY/packages" > \$chroot_dir\$LOCALSTATE/mirror
2226 mkdir -p \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming
2227 echo "\$LOCAL_REPOSITORY/packages-incoming" > \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming/mirror
2228 $( [ "$undigest" ] && echo ' mkdir -p $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION
2229 echo "$SLITAZ_DIR/$SLITAZ_VERSION/packages" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror' )
2230 echo -e "\${LOCAL_REPOSITORY##*/}-incoming\nmain" > \$chroot_dir\$LOCALSTATE/priority
2231 mount -t proc proc \$chroot_dir/proc
2232 mount -t sysfs sysfs \$chroot_dir/sys
2233 mount -t devpts devpts \$chroot_dir/dev/pts
2234 mount -t tmpfs shm \$chroot_dir/dev/shm
2235 for dir in \$list_dir; do
2236 mkdir -p \$dir \$chroot_dir\$dir
2237 mount \$dir \$chroot_dir\$dir
2238 done
2241 umount_chroot()
2243 for dir in \$list_dir; do
2244 umount \$chroot_dir\$dir
2245 done
2246 umount \$chroot_dir/dev/shm
2247 umount \$chroot_dir/dev/pts
2248 umount \$chroot_dir/sys
2249 umount \$chroot_dir/proc
2251 EOF
2254 ########################################################################
2255 ######################### END OF NEW FUNCTIONS #########################
2256 ########################################################################
2258 # List packages providing a virtual package
2259 whoprovide()
2261 local i;
2262 for i in $(fgrep -l PROVIDE $WOK/*/receipt); do
2263 . $i
2264 case " $PROVIDE " in
2265 *\ $1\ *|*\ $1:*) echo $(basename $(dirname $i));;
2266 esac
2267 done
2270 ########################################################################
2271 # TAZWOK COMMANDS
2272 ########################
2274 case "$COMMAND" in
2275 stats)
2276 # Tazwok general statistics from the wok config file.
2278 get_tazwok_config
2279 echo -e "\n\033[1mTazwok configuration statistics\033[0m
2280 ================================================================================
2281 Wok directory : $WOK
2282 Packages repository : $PACKAGES_REPOSITORY
2283 Incoming repository : $INCOMING_REPOSITORY
2284 Sources repository : $SOURCES_REPOSITORY
2285 Log directory : $LOCAL_REPOSITORY/log
2286 Packages in the wok : `ls -1 $WOK | wc -l`
2287 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2288 Incoming packages : `ls -1 $INCOMING_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2289 ================================================================================\n"
2290 ;;
2291 edit)
2292 get_tazwok_config
2293 check_for_package_on_cmdline
2294 check_for_receipt
2295 $EDITOR $WOK/$PACKAGE/receipt
2296 ;;
2297 build-depends)
2298 # List dependencies to rebuild wok, or only a package
2299 get_tazwok_config
2300 report(){ : ; }
2301 if [ ! "$PACKAGE" ] || [ "$PACKAGE" = toolchain ]; then
2302 scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
2303 --look_for=dep --with_dev --with_args
2304 else
2305 check_for_package_on_cmdline
2306 scan $PACKAGE --look_for=bdep --with_dev
2307 fi
2308 ;;
2309 gen-cooklist)
2310 check_root
2311 get_options_list="pkg"
2312 get_tazwok_config
2313 report(){ : ; }
2314 if ! [ "$pkg" ]; then
2315 if [ ! "$LIST" ] || [ "$LIST" = toolchain ]; then
2316 pkg="$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA"
2317 else
2318 cooklist=${LIST:-$PACKAGES_REPOSITORY/cooklist}
2319 fi
2320 fi
2321 gen_cook_list
2322 ;;
2323 check-depends)
2324 # Check package depends /!\
2325 get_tazwok_config
2326 echo ""
2327 echo -e "\033[1mCheck every receipt for DEPENDS - doesn't scan ELF files\033[0m
2328 ================================================================================"
2329 TMPDIR=/tmp/tazwok$$
2330 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
2332 # Build ALL_DEPENDS variable
2333 scan_dep()
2335 local i
2336 ALL_DEPENDS="$ALL_DEPENDS$PACKAGE "
2337 for i in $DEPENDS $SUGGESTED ; do
2338 case " $ALL_DEPENDS " in
2339 *\ $i\ *) continue;;
2340 esac
2341 [ -d $WOK/$i ] || {
2342 ALL_DEPENDS="$ALL_DEPENDS$i "
2343 continue
2345 DEPENDS=""
2346 SUGGESTED=""
2347 . $WOK/$i/receipt
2348 scan_dep
2349 done
2352 # Check for ELF file
2353 is_elf()
2355 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
2358 # Print shared library dependencies
2359 ldd()
2361 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
2364 mkdir $TMPDIR
2365 cd $TMPDIR
2366 for i in $LOCALSTATE/files.list.lzma \
2367 $LOCALSTATE/undigest/*/files.list.lzma ; do
2368 [ -f $i ] && lzma d $i -so >> files.list
2369 done
2370 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
2371 tazpkg extract $pkg > /dev/null 2>&1
2372 . */receipt
2373 ALL_DEPENDS="$DEFAULT_DEPENDS "
2374 scan_dep
2375 find */fs -type f | while read file ; do
2376 is_elf $file || continue
2377 case "$file" in
2378 *.o|*.ko|*.ko.gz) continue;;
2379 esac
2380 ldd $file | while read lib rem; do
2381 case "$lib" in
2382 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
2383 continue;;
2384 esac
2385 for dep in $(fgrep $lib files.list | cut -d: -f1); do
2386 case " $ALL_DEPENDS " in
2387 *\ $dep\ *) continue 2;;
2388 esac
2389 for vdep in $(fgrep $dep $LOCALSTATE/packages.equiv | cut -d= -f1); do
2390 case " $ALL_DEPENDS " in
2391 *\ $vdep\ *) continue 3;;
2392 esac
2393 done
2394 done
2395 [ -n "$dep" ] || dep="UNKNOWN"
2396 echo "$(basename $pkg): ${file#*fs} depends on package $dep for the shared library $lib"
2397 done
2398 done
2399 rm -rf */
2400 done
2401 cd /tmp
2402 rm -rf $TMPDIR
2403 ;;
2404 check)
2405 # Check wok consistency
2406 get_tazwok_config
2407 echo ""
2408 echo -e "\033[1mWok and packages checking\033[0m
2409 ================================================================================"
2410 cd $WOK
2411 for pkg in $(ls)
2412 do
2413 [ -f $pkg/receipt ] || continue
2414 RECEIPT= $pkg/receipt
2415 source_receipt
2416 [ "$PACKAGE" = "$pkg" ] || echo "Package $PACKAGE should be $pkg" >&2
2417 [ -n "$VERSION" ] || echo "Package $PACKAGE has no VERSION" >&2
2418 [ -n "$PACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded PACKED_SIZE" >&2
2419 [ -n "$UNPACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded UNPACKED_SIZE" >&2
2420 [ -n "$EXTRAVERSION" ] && echo "Package $PACKAGE has hardcoded EXTRAVERSION" >&2
2421 if [ -n "$WANTED" ]; then
2422 if [ ! -f $WANTED/receipt ]; then
2423 echo "Package $PACKAGE wants unknown $WANTED package" >&2
2424 else
2425 BASEVERSION=$(. $WANTED/receipt ; echo $VERSION)
2426 if [ "$VERSION" = "$WANTED" ]; then
2427 # BASEVERSION is computed in receipt
2428 fgrep -q '_pkg=' $pkg/receipt &&
2429 BASEVERSION=$VERSION
2430 fi
2431 if [ "$VERSION" != "$BASEVERSION" ]; then
2432 echo "Package $PACKAGE ($VERSION) wants $WANTED ($BASEVERSION)" >&2
2433 fi
2434 fi
2435 fi
2437 if [ -n "$CATEGORY" ]; then
2438 case " $(echo $CATEGORIES) " in
2439 *\ $CATEGORY\ *);;
2440 *) echo "Package $PACKAGE has an invalid CATEGORY" >&2;;
2441 esac
2442 else
2443 echo"Package $PACKAGE has no CATEGORY" >&2
2444 fi
2445 [ -n "$SHORT_DESC" ] || echo "Package $PACKAGE has no SHORT_DESC" >&2
2446 [ -n "$MAINTAINER" ] || echo "Package $PACKAGE has no MAINTAINER" >&2
2447 case "$WGET_URL" in
2448 ftp*|http*) busybox wget -s $WGET_URL 2> /dev/null ||
2449 echo "Package $PACKAGE has a wrong WGET_URL" >&2;;
2450 '') ;;
2451 *) echo "Package $PACKAGE has an invalid WGET_URL" >&2;;
2452 esac
2453 case "$WEB_SITE" in
2454 ftp*|http*);;
2455 '') echo "Package $PACKAGE has no WEB_SITE" >&2;;
2456 *) echo "Package $PACKAGE has an invalid WEB_SITE" >&2;;
2457 esac
2458 case "$MAINTAINER" in
2459 *\<*|*\>*) echo "Package $PACKAGE has an invalid MAINTAINER: $MAINTAINER" >&2;;
2460 esac
2461 case "$MAINTAINER" in
2462 *@*);;
2463 *) echo "Package $PACKAGE MAINTAINER is not an email address" >&2;;
2464 esac
2465 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2466 for i in $DEPENDS; do
2467 [ -d $i ] && continue
2468 [ -n "$(whoprovide $i)" ] && continue
2469 echo -e "$MSG $i"
2470 MSG=""
2471 done
2472 MSG="Missing build dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2473 for i in $BUILD_DEPENDS; do
2474 [ -d $i ] && continue
2475 [ -n "$(whoprovide $i)" ] && continue
2476 echo -e "$MSG $i"
2477 MSG=""
2478 done
2479 MSG="Dependencies loop between $PACKAGE and :\n"
2480 ALL_DEPS=""
2481 check_for_deps_loop $PACKAGE $DEPENDS
2482 [ -d $WOK/$pkg/taz ] && for i in $BUILD_DEPENDS; do
2483 [ $WOK/$pkg/taz -nt $INSTALLED/$i/files.list ] && continue
2484 echo "$pkg should be rebuilt after $i installation"
2485 done
2486 done
2487 ;;
2488 list)
2489 # List packages in wok directory. User can specify a category.
2491 get_tazwok_config
2492 if [ "$2" = "category" ]; then
2493 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
2494 exit 0
2495 fi
2496 # Check for an asked category.
2497 if [ -n "$2" ]; then
2498 ASKED_CATEGORY=$2
2499 echo ""
2500 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
2501 echo "================================================================================"
2502 for pkg in $WOK/*
2503 do
2504 [ ! -f $pkg/receipt ] && continue
2505 . $pkg/receipt
2506 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
2507 echo -n "$PACKAGE"
2508 echo -e "\033[28G $VERSION"
2509 packages=$(($packages+1))
2510 fi
2511 done
2512 echo "================================================================================"
2513 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
2514 else
2515 # By default list all packages and version.
2516 echo ""
2517 echo -e "\033[1mList of packages in the wok\033[0m"
2518 echo "================================================================================"
2519 for pkg in $WOK/*
2520 do
2521 [ ! -f $pkg/receipt ] && continue
2522 . $pkg/receipt
2523 echo -n "$PACKAGE"
2524 echo -en "\033[28G $VERSION"
2525 echo -e "\033[42G $CATEGORY"
2526 packages=$(($packages+1))
2527 done
2528 echo "================================================================================"
2529 echo -e "$packages packages available in the wok.\n"
2530 fi
2531 ;;
2532 info)
2533 # Information about a package.
2535 get_tazwok_config
2536 check_for_package_on_cmdline
2537 check_for_receipt
2538 . $WOK/$PACKAGE/receipt
2539 echo ""
2540 echo -e "\033[1mTazwok package information\033[0m
2541 ================================================================================
2542 Package : $PACKAGE
2543 Version : $VERSION
2544 Category : $CATEGORY
2545 Short desc : $SHORT_DESC
2546 Maintainer : $MAINTAINER"
2547 if [ ! "$WEB_SITE" = "" ]; then
2548 echo "Web site : $WEB_SITE"
2549 fi
2550 if [ ! "$DEPENDS" = "" ]; then
2551 echo "Depends : $DEPENDS"
2552 fi
2553 if [ ! "$WANTED" = "" ]; then
2554 echo "Wanted src : $WANTED"
2555 fi
2556 echo "================================================================================"
2557 echo ""
2558 ;;
2559 check-log)
2560 # We just cat the file log to view process info.
2562 get_tazwok_config
2563 if [ ! -f "$LOG" ]; then
2564 echo -e "\nNo process log found. The package is probably not cooked.\n" >&2
2565 exit 1
2566 else
2567 echo ""
2568 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
2569 echo "================================================================================"
2570 cat $LOG
2571 echo "================================================================================"
2572 echo ""
2573 if [ -s "$WOK/$PACKAGE/warning.txt" ]; then
2574 echo -e "\033[1mCook warning(s) for :\033[0m $PACKAGE"
2575 echo "================================================================================"
2576 cat "$WOK/$PACKAGE/warning.txt"
2577 echo "================================================================================"
2578 echo ""
2579 fi
2580 fi
2581 ;;
2582 search)
2583 # Search for a package by pattern or name.
2585 get_tazwok_config
2586 if [ -z "$2" ]; then
2587 echo -e "\nPlease specify a pattern or a package name to search." >&2
2588 echo -e "Example : 'tazwok search gcc'.\n" >&2
2589 exit 1
2590 fi
2591 echo ""
2592 echo -e "\033[1mSearch result for :\033[0m $2"
2593 echo "================================================================================"
2594 list=`ls -1 $WOK | fgrep $2`
2595 for pkg in $list
2596 do
2597 . $WOK/$pkg/receipt
2598 echo -n "$PACKAGE "
2599 echo -en "\033[24G $VERSION"
2600 echo -e "\033[42G $CATEGORY"
2601 packages=$(($PACKAGEs+1))
2602 done
2603 echo "================================================================================"
2604 echo "$packages packages found for : $2"
2605 echo ""
2606 ;;
2607 compile)
2608 # Configure and make a package with the receipt.
2610 get_tazwok_config
2611 source_lib report
2612 report start
2613 compile_package
2614 ;;
2615 genpkg)
2616 # Generate a package.
2618 get_tazwok_config
2619 source_lib report
2620 report start
2621 gen_package
2622 ;;
2623 cook)
2624 # Compile and generate a package. Just execute tazwok with
2625 # the good commands.
2627 check_root
2628 get_tazwok_config
2629 source_lib report
2630 report start
2631 update_wan_db
2632 check_for_commit
2633 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
2634 [ "$plan_sort_wandb" ] && sort -o $wan_db $wan_db && unset plan_sort_wandb
2635 if [ "$plan_regen_cookorder" ]; then
2636 [ "$(sed 1!d $PACKAGES_REPOSITORY/cookorder.txt)" = "#PlanSort" ] || \
2637 sed 1i"#PlanSort" -i $PACKAGES_REPOSITORY/cookorder.txt
2638 fi
2639 cook
2640 ;;
2641 sort-cooklist)
2642 if [ ! -f "$LIST" ]; then
2643 echo "Usage : tazwok sort-cooklist cooklist" >&2
2644 exit 1
2645 fi
2646 check_root
2647 get_tazwok_config
2648 report(){ : ; }
2649 # When using sort-cooklist, the script should behave as for gen-cooklist
2650 # The only difference between theses two is where the output is sended.
2651 COMMAND=gen-cooklist
2652 cooklist=$LIST
2653 gen_cook_list
2654 cp -af $tmp/cooklist $cooklist
2655 ;;
2656 cook-list)
2657 # Cook all packages listed in a file or in default cooklist.
2658 check_root
2659 get_options_list="pkg forced"
2660 get_tazwok_config
2661 source_lib report
2662 report start
2663 if ! [ "$pkg" ]; then
2664 cooklist=${LIST:-$PACKAGES_REPOSITORY/cooklist}
2665 fi
2666 gen_cook_list
2667 cook_list
2668 ;;
2669 clean)
2670 # Clean up a package work directory + thoses which want it.
2672 get_tazwok_config
2673 check_for_package_on_cmdline
2674 check_for_receipt
2675 source_lib report
2676 report start
2677 . $RECEIPT
2678 clean
2679 ;;
2680 gen-clean-wok)
2681 # Generate a clean wok from the current wok by copying all receipts
2682 # and stuff directory.
2684 get_tazwok_config
2685 source_lib report
2686 report start
2687 if [ -z "$ARG" ]; then
2688 echo -e "\nPlease specify the destination for the new clean wok.\n" >&2
2689 exit 1
2690 else
2691 dest=$ARG
2692 mkdir -p $dest
2693 fi
2694 report step "Creating clean wok in : $dest"
2695 for pkg in `ls -1 $WOK`
2696 do
2697 mkdir -p $dest/$pkg
2698 cp -a $WOK/$pkg/receipt $dest/$pkg
2699 [ -f $WOK/$pkg/description.txt ] && \
2700 cp -a $WOK/$pkg/description.txt $dest/$pkg
2701 if [ -d "$WOK/$pkg/stuff" ]; then
2702 cp -a $WOK/$pkg/stuff $dest/$pkg
2703 fi
2704 done
2705 [ -d $WOK/.hg ] && cp -a $WOK/.hg $dest
2706 report end-step
2707 echo "Packages cleaned : `ls -1 $dest | wc -l`"
2708 echo ""
2709 ;;
2710 clean-wok)
2711 # Clean all packages in the work directory
2713 get_tazwok_config
2714 source_lib report
2715 report start
2716 report step "Cleaning wok"
2717 for PACKAGE in `ls -1 $WOK`
2718 do
2719 set_common_path
2720 source_receipt
2721 clean
2722 done
2723 echo "`ls -1 $WOK | wc -l` packages cleaned."
2724 ;;
2725 clean-src)
2726 # Remove tarball unrelated to wok receipts from src repo.
2727 check_root
2728 get_options_list="forced"
2729 get_tazwok_config
2730 cd $SOURCES_REPOSITORY
2731 echo -n "Checking $SOURCES_REPOSITORY..."
2732 for TARBALL in *; do
2733 [ "$TARBALL" = sources.list ] && continue
2734 grep -q $'\t'$TARBALL$ $SOURCES_REPOSITORY/sources.list || \
2735 echo $TARBALL >> $tmp/obsolete
2736 done
2737 status
2738 if ! [ -f $tmp/obsolete ]; then
2739 echo "No sources need to be removed."
2740 exit 1
2741 fi
2742 echo ""
2743 echo -e "\033[1mObsolete/unrelated-to-wok sourcess :\033[0m"
2744 horizontal_line
2745 cat $tmp/obsolete
2746 horizontal_line
2747 echo "$(wc -l $tmp/obsolete | cut -f1 -d' ') tarballs to remove."
2748 echo ""
2749 echo -n "Please confirm removing (type uppercase YES): "
2750 read answer
2751 if [ "$answer" = YES ]; then
2752 echo -n "Removing old sources..."
2753 cat $tmp/obsolete | while read i; do
2754 rm -f $SOURCES_REPOSITORY/$i
2755 done
2756 status
2757 fi
2758 ;;
2759 gen-list)
2760 get_tazwok_config
2761 if [ "$2" ]; then
2762 if [ -d "$2" ]; then
2763 pkg_repository=$2
2764 else
2765 echo -e "\nUnable to find directory : $2\n" >&2
2766 exit 1
2767 fi
2768 fi
2770 source_lib report
2771 report start
2772 if [ "$pkg_repository" ]; then
2773 gen_packages_db
2774 else
2775 pkg_repository=$PACKAGES_REPOSITORY && gen_packages_db
2776 pkg_repository=$INCOMING_REPOSITORY && gen_packages_db
2777 fi
2778 ;;
2779 check-list)
2780 # The directory to move into by default is the repository,
2781 # if $2 is not empty cd into $2.
2783 get_tazwok_config
2784 if [ "$2" ]; then
2785 if [ -d "$2" ]; then
2786 pkg_repository=$2
2787 else
2788 echo -e "\nUnable to find directory : $2\n" >&2
2789 exit 1
2790 fi
2791 fi
2793 source_lib report
2794 report start
2795 if [ "$pkg_repository" ]; then
2796 update_packages_db
2797 else
2798 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2799 pkg_repository=$INCOMING_REPOSITORY && update_packages_db
2800 fi
2801 ;;
2802 new-tree)
2803 # Just create a few directories and generate an empty receipt to prepare
2804 # the creation of a new package.
2806 get_tazwok_config
2807 check_for_package_on_cmdline
2808 clean_wok=$LOCAL_REPOSITORY/clean-wok
2809 if [ -d $clean_wok/$PACKAGE ]; then
2810 echo -e "\n$PACKAGE package tree already exists.\n" >&2
2811 exit 1
2812 fi
2813 echo "Creating : $WOK/$PACKAGE"
2814 mkdir $clean_wok/$PACKAGE
2815 cd $clean_wok/$PACKAGE
2816 echo -n "Preparing the receipt..."
2818 # Default receipt begin.
2820 echo "# SliTaz package receipt." > receipt
2821 echo "" >> receipt
2822 echo "PACKAGE=\"$PACKAGE\"" >> receipt
2823 # Finish the empty receipt.
2824 cat >> receipt << "EOF"
2825 VERSION=""
2826 CATEGORY=""
2827 SHORT_DESC=""
2828 MAINTAINER=""
2829 DEPENDS=""
2830 TARBALL="$PACKAGE-$VERSION.tar.gz"
2831 WEB_SITE=""
2832 WGET_URL=""
2834 # Rules to configure and make the package.
2835 compile_rules()
2837 cd $src
2838 ./configure && make && make install
2841 # Rules to gen a SliTaz package suitable for Tazpkg.
2842 genpkg_rules()
2844 mkdir -p $fs/usr
2845 cp -a $_pkg/usr/bin $fs/usr
2848 EOF
2850 # Default receipt end.
2852 status
2853 # Interactive mode, asking and seding.
2854 if [ "$3" = "--interactive" ]; then
2855 echo "Entering into interactive mode..."
2856 echo "================================================================================"
2857 echo "Package : $PACKAGE"
2858 # Version.
2859 echo -n "Version : " ; read anser
2860 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
2861 # Category.
2862 echo -n "Category : " ; read anser
2863 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
2864 # Short description.
2865 echo -n "Short desc : " ; read anser
2866 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
2867 # Maintainer.
2868 echo -n "Maintainer : " ; read anser
2869 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
2870 # Web site.
2871 echo -n "Web site : " ; read anser
2872 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
2873 echo ""
2874 # Wget URL.
2875 echo "Wget URL to download source tarball."
2876 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
2877 echo -n "Wget url : " ; read anser
2878 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
2879 # Ask for a stuff dir.
2880 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
2881 if [ "$anser" = "y" ]; then
2882 echo -n "Creating the stuff directory..."
2883 mkdir stuff && status
2884 fi
2885 # Ask for a description file.
2886 echo -n "Are you going to write a description ? (y/N) : " ; read anser
2887 if [ "$anser" = "y" ]; then
2888 echo -n "Creating the description.txt file..."
2889 echo "" > description.txt && status
2890 fi
2891 echo "================================================================================"
2892 echo ""
2893 fi
2894 ;;
2895 remove)
2896 # Remove a package from the wok.
2898 get_tazwok_config
2899 check_for_package_on_cmdline
2900 echo ""
2901 echo -n "Please confirm deletion (y/N) : "; read anser
2902 if [ "$anser" = "y" ]; then
2903 echo -n "Removing $PACKAGE..."
2904 rm -rf $WOK/$PACKAGE && status
2905 echo ""
2906 fi
2907 ;;
2908 update-wok)
2909 # Pull and update a Hg wok.
2910 get_options_list="local"
2911 get_tazwok_config
2912 source_lib report
2913 report start
2914 clean_wok=$LOCAL_REPOSITORY/clean-wok
2915 cd $clean_wok
2916 if ! [ "$local" ]; then
2917 if [ "$WOK_UPDATE_METHOD" = hg ]; then
2918 if ! [ -f "$INSTALLED/mercurial/receipt" ]; then
2920 # Auto-install only if we are in a cook chroot.
2921 if [ -x /usr/bin/clean-chroot ]; then
2922 tazpkg get-install mercurial
2923 else
2924 echo "" >&2
2925 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
2926 echo "">&2
2927 exit 1
2928 fi
2929 fi
2931 report step "Getting wok changes using hg"
2932 if [ -d .hg ]; then
2933 hg pull -u || exit 1
2934 else
2935 hg clone $HG_WOK . || exit 1
2936 fi
2937 report end-step
2938 [ -x /usr/bin/clean-chroot ] && clean-chroot
2939 else
2940 report step "Getting wok changes using tarball"
2941 { mkdir .tmp && cd .tmp
2942 wget "$TARBALL_WOK" &&
2943 case $TARBALL_WOK in
2944 *bz2) tar xjf *.bz2 -C wok; rm *.bz2;;
2945 *lzma) unlzma -c *.lzma | tar xf - -C wok; rm *.lzma ;;
2946 *gz) tar xzf *.gz -C wok; rm*.gz ;;
2947 esac &&
2948 rm -r $(ls -d $clean_wok/*) &&
2949 cp -a wok/* $clean_wok &&
2950 cd .. &&
2951 rm -r .tmp
2952 } || { echo "That's not cool: it fails!" >&2
2953 report end-step
2954 exit 1; }
2955 report end-step
2956 fi
2957 fi
2958 report step "Appending changes to wok"
2960 # Handle removed files/dir.
2961 cd $WOK
2962 for dir in *; do
2963 [ -d "$clean_wok/$dir" ] || rm -rf $dir
2964 done
2965 for file in */receipt */description.txt; do
2966 [ -f "$clean_wok/$file" ] || rm -rf $file
2967 done
2968 for i in $(find */stuff 2>/dev/null); do
2969 [ -e "$clean_wok/$i" ] || rm -rf $i
2970 done
2972 cp -a $clean_wok/* $WOK
2973 report end-step
2974 ;;
2975 maintainers)
2976 get_tazwok_config
2977 echo ""
2978 echo "List of maintainers for: $WOK"
2979 echo "================================================================================"
2980 touch /tmp/slitaz-maintainers
2981 for pkg in $WOK/*
2982 do
2983 . $pkg/receipt
2984 if ! fgrep -q "$MAINTAINER" /tmp/slitaz-maintainers; then
2985 echo "$MAINTAINER" >> /tmp/slitaz-maintainers
2986 echo "$MAINTAINER"
2987 fi
2988 done
2989 echo "================================================================================"
2990 echo "Maintainers: `cat /tmp/slitaz-maintainers | wc -l`"
2991 echo ""
2992 # Remove tmp files
2993 rm -f /tmp/slitaz-maintainers
2994 ;;
2995 maintained-by)
2996 # Search for packages maintained by a contributor.
2997 get_tazwok_config
2998 if [ ! -n "$2" ]; then
2999 echo "Specify a name or email of a maintainer." >&2
3000 exit 1
3001 fi
3002 echo "Maintainer packages"
3003 echo "================================================================================"
3004 for pkg in $WOK/*
3005 do
3006 . $pkg/receipt
3007 if echo "$MAINTAINER" | fgrep -q "$2"; then
3008 echo "$PACKAGE"
3009 packages=$(($PACKAGEs+1))
3010 fi
3011 done
3012 echo "================================================================================"
3013 echo "Packages maintained by $2: $PACKAGEs"
3014 echo ""
3015 ;;
3016 tags)
3017 get_tazwok_config
3018 echo -e "\n\033[1mTags list :\033[0m"
3019 horizontal_line
3020 cd $WOK
3021 for i in */receipt; do
3022 unset TAGS
3023 source $i
3024 for t in $TAGS; do
3025 grep -q ^$t$ $tmp/tags && continue
3026 echo $t | tee -a $tmp/tags
3027 done
3028 done
3029 horizontal_line
3030 echo "$(wc -l $tmp/tags | cut -f1 -d ' ') tags listed."
3031 ;;
3032 check-src)
3033 # Verify if upstream package is still available
3035 get_tazwok_config
3036 check_for_package_on_cmdline
3037 check_for_receipt
3038 source_receipt
3039 check_src()
3041 for url in $@; do
3042 busybox wget -s $url 2>/dev/null && break
3043 done
3045 if [ "$WGET_URL" ];then
3046 echo -n "$PACKAGE : "
3047 check_src $WGET_URL
3048 status
3049 else
3050 echo "No tarball to check for $PACKAGE"
3051 fi
3052 ;;
3053 get-src)
3054 check_root
3055 get_options_list="target nounpack"
3056 get_tazwok_config
3057 check_for_package_on_cmdline
3058 check_for_receipt
3059 source_receipt
3060 if [ "$WGET_URL" ];then
3061 source_lib report
3062 report start
3063 check_for_tarball
3064 else
3065 echo "No tarball to download for $PACKAGE"
3066 fi
3067 ;;
3068 check-commit)
3069 check_root
3070 get_options_list="missing forced"
3071 get_tazwok_config
3072 source_lib report
3073 report start
3074 if [ "$forced" ]; then
3075 rm -f $WOK/*/md5
3076 unset forced
3077 fi
3078 if [ "$missing" ]; then
3079 pkg=$(ls -1 $WOK)
3080 else
3081 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3082 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3083 } | sort -u)"
3084 fi
3085 cooklist=$PACKAGES_REPOSITORY/cooklist
3086 gen_cook_list
3087 ;;
3088 cook-commit)
3089 check_root
3090 get_options_list="missing forced"
3091 get_tazwok_config
3092 source_lib report
3093 report start
3094 if [ "$forced" ]; then
3095 rm -f $WOK/*/md5
3096 unset forced
3097 fi
3098 if [ "$missing" ]; then
3099 pkg=$(ls -1 $WOK)
3100 else
3101 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3102 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3103 } | sort -u)"
3104 fi
3105 cooklist=$PACKAGES_REPOSITORY/cooklist
3106 gen_cook_list
3107 cook_list
3108 ;;
3109 cook-all)
3110 check_root
3111 get_options_list="forced missing"
3112 get_tazwok_config
3113 source_lib report
3114 report start
3115 if [ "$missing" ]; then
3116 pkg=$(ls -1 $WOK)
3117 else
3118 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3119 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3120 } | sort -u)"
3121 fi
3122 cooklist=$PACKAGES_REPOSITORY/cooklist
3123 gen_cook_list
3124 cook_list
3125 ;;
3126 gen-wok-db)
3127 check_root
3128 get_tazwok_config
3129 source_lib report
3130 report start
3131 gen_wok_db
3132 ;;
3133 report)
3134 get_tazwok_config
3135 cd $PACKAGES_REPOSITORY
3136 if [ "$2" ]; then
3137 case $2 in
3138 commit|cooklist|incoming|broken|blocked)
3139 show="$2"
3140 ;;
3141 *)
3142 echo "usage : tazwok report [commit|cooklist|incoming|broken|blocked]" >&2
3143 exit 1
3144 ;;
3145 esac
3146 else
3147 show="commit cooklist incoming broken blocked"
3148 fi
3149 for i in $show; do
3150 if [ -s $i ]; then
3151 echo ""
3152 echo -e "\033[1m$i\033[0m"
3153 echo "================================================================================"
3154 cat $i
3155 echo "================================================================================"
3156 echo ""
3157 fi
3158 done
3159 ;;
3160 check-incoming)
3161 check_root
3162 get_options_list="forced"
3163 get_tazwok_config
3164 source_lib report
3165 report start
3166 [ -f $LOCAL_RESOSITORY/incoming ] && rm [ -f $LOCAL_REPOSITORY/incoming ]
3167 report step "Checking $INCOMING_REPOSITORY"
3168 report open-bloc
3169 [ -f $LOCAL_REPOSITORY/log/incoming.html ] && rm $LOCAL_REPOSITORY/log/incoming.html
3170 report sublog $LOCAL_REPOSITORY/log/incoming.html
3171 echo "incoming" > $LOCAL_REPOSITORY/log/package
3172 check_for_incoming
3173 report end-sublog
3174 report close-bloc
3175 ;;
3176 configure-chroot)
3177 check_root
3178 get_tazwok_config
3179 if [ -f /usr/bin/tazchroot ]; then
3180 cd $LOCAL_REPOSITORY
3181 configure_tazchroot
3182 else
3183 echo "The packages tazchroot need to be installed" >&2
3184 exit 1
3185 fi
3186 ;;
3187 chroot)
3188 check_root
3189 get_tazwok_config
3190 # Merge this and the other chroot function ?.
3191 if [ -f /usr/bin/tazchroot ]; then
3192 cd $LOCAL_REPOSITORY
3193 [ ! -f tazchroot.conf ] && configure_tazchroot
3194 tazchroot
3195 else
3196 echo "The packages tazchroot need to be installed" >&2
3197 exit 1
3198 fi
3199 ;;
3200 cook-toolchain)
3201 check_root
3202 get_tazwok_config
3203 echo -n "" > $PACKAGES_REPOSITORY/broken
3204 if [ -f /usr/bin/tazchroot ]; then
3205 cd $LOCAL_REPOSITORY
3206 [ ! -f tazchroot.conf ] && configure_tazchroot
3207 tazchroot cook-toolchain
3208 # Buggy : chroot can be elsewhere.
3209 rm -r $LOCAL_REPOSITORY/chroot
3210 # /!\ to be writed :
3211 # next rm chroot and plan cook-all by pushing all packages
3212 # in cooklist.
3213 else
3214 echo "The packages tazchroot need to be installed" >&2
3215 exit 1
3216 fi
3217 ;;
3218 webserver)
3219 check_root
3220 get_tazwok_config
3221 if [ "$ARG" = on ]; then
3222 if [ "$WEBSERVER" ] && [ -f "$WEBSERVER/repositories.list" ] && \
3223 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3224 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3225 exit 1
3226 fi
3227 if ! [ -f $LOCAL_REPOSITORY/tazchroot.conf ]; then
3228 tazwok configure-chroot ${undigest:+--undigest=$undigest} --SLITAZ_VERSION=$SLITAZ_VERSION --SLITAZ_DIR=$SLITAZ_DIR
3229 fi
3230 for pkg in php lighttpd; do
3231 [ -d $INSTALLED/$pkg ] || missing="$missing $pkg"
3232 done
3233 if [ "$missing" ]; then
3234 echo "You need to install those packages to start webserver: $missing." >&2
3235 exit 1
3236 fi
3237 if [ ! -f "$LOCAL_REPOSITORY/tazwok.conf" ]; then
3238 echo "Copying /etc/slitaz/tazwok.conf to $LOCAL_REPOSITORY/tazwok.conf: webserver is configured repository-by-repository."
3239 cp /etc/slitaz/tazwok.conf $LOCAL_REPOSITORY
3240 fi
3241 if ! [ "$WEBSERVER" ]; then
3242 echo -n "Where to store php pages (default: /var/www/vhosts/bb)? "
3243 read WEBSERVER
3244 [ "$WEBSERVER" ] || WEBSERVER="/var/www/vhosts/bb"
3245 fi
3246 if [ -f "$WEBSERVER/repositories.list" ] && \
3247 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3248 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3249 exit 1
3250 fi
3251 mkdir -p $WEBSERVER
3252 echo "${undigest:-$SLITAZ_VERSION}" >> $WEBSERVER/repositories.list
3253 for file in index.php log.php download.php; do
3254 [ -f "$WEBSERVER/$file" ] || ln -s /usr/share/slitaz/web-bb/$file $WEBSERVER
3255 done
3256 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3257 ln -s $dir $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3258 done
3259 source $LOCAL_REPOSITORY/tazchroot.conf
3260 echo "<?php
3262 // Web interface configuration
3264 \$version=\"${undigest:-$SLITAZ_VERSION}\";
3265 \$chroot=\"$chroot_dir\";
3266 \$lockfile=\"\$chroot/proc/1/status\";
3267 \$db_dir=\"$PACKAGES_REPOSITORY\";
3268 \$log_dir=\"$LOCAL_REPOSITORY/log\";
3269 \$packages=\"$PACKAGES_REPOSITORY\";
3270 \$incoming=\"$INCOMING_REPOSITORY\";
3271 \$wok=\"$WOK\";
3273 ?>" > $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3274 [ -L "$WEBSERVER/web" ] || ln -s /usr/share/slitaz/web $WEBSERVER
3275 echo "WEBSERVER=\"$WEBSERVER\"" >> $LOCAL_REPOSITORY/tazwok.conf
3276 if [ -L "$WEBSERVER/conf.php" ]; then
3277 echo "Do yo want to make ${undigest:-$SLITAZ_VERSION} the default page (y/N) ? "
3278 read answer
3279 if [ "$answer" = y ]; then
3280 rm $WEBSERVER/conf.php
3281 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3282 fi
3283 else
3284 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3285 fi
3286 elif [ "$ARG" = off ]; then
3287 if ! [ "$WEBSERVER" ]; then
3288 echo "No webserver running for ${undigest:-$SLITAZ_VERSION}" >&2
3289 exit 1
3290 fi
3291 sed '/^WEBSERVER/d' -i $LOCAL_REPOSITORY/tazwok.conf
3292 sed "/^${undigest:-$SLITAZ_VERSION}$/d" -i $WEBSERVER/repositories.list
3293 rm $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3294 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3295 rm $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3296 done
3297 if ! [ -s "$WEBSERVER/repositories.list" ]; then
3298 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"
3299 rm $WEBSERVER/conf.php
3300 elif [ "$(readlink $WEBSERVER/conf.php)" = "$WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php" ]; then
3301 echo "${undigest:-$SLITAZ_VERSION} was the default version to use; switched to : $(sed 1!d $WEBSERVER/repositories.list)"
3302 rm $WEBSERVER/conf.php
3303 ln -s $WEBSERVER/conf-$(sed 1!d $WEBSERVER/repositories.list).php $WEBSERVER/conf.php
3304 fi
3305 else
3306 echo "Usage: tazwok webserver on/off" >&2
3307 exit 1
3308 fi
3309 ;;
3310 block)
3311 # Add a pkg name to the list of blocked packages.
3312 get_tazwok_config
3313 check_root
3314 check_for_package_on_cmdline
3315 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3316 echo "Can't find $PACKAGE into wok." >&2
3317 echo ""
3318 exit 1
3319 fi
3320 echo ""
3321 if grep -qs "^$PACKAGE$" $PACKAGES_REPOSITORY/blocked; then
3322 echo "$PACKAGE is already in the blocked packages list." >&2
3323 echo ""
3324 exit 1
3325 else
3326 echo -n "Adding $PACKAGE to : $PACKAGES_REPOSITORY/blocked... "
3327 echo "$PACKAGE" >> $PACKAGES_REPOSITORY/blocked
3328 status
3329 if grep -q "^$PACKAGE$" $PACKAGES_REPOSITORY/cooklist; then
3330 echo -n "Removing $PACKAGE from : $PACKAGES_REPOSITORY/cooklist... "
3331 sed -i /"^$PACKAGE$"/d $PACKAGES_REPOSITORY/cooklist
3332 status
3333 fi
3334 fi
3335 echo "" ;;
3336 unblock)
3337 # Remove a pkg name from the list of blocked packages.
3338 get_tazwok_config
3339 check_root
3340 check_for_package_on_cmdline
3341 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3342 echo "Can't find $PACKAGE into wok." >&2
3343 echo ""
3344 exit 1
3345 fi
3346 echo ""
3347 if grep -qs "^$PACKAGE$" $PACKAGES_REPOSITORY/blocked; then
3348 echo -n "Removing $PACKAGE from : $PACKAGES_REPOSITORY/blocked... "
3349 sed -i /"^$PACKAGE$"/d $PACKAGES_REPOSITORY/blocked
3350 sed -i '/^$/d' $PACKAGES_REPOSITORY/blocked
3351 status
3352 else
3353 echo "$PACKAGE is not in the blocked packages list." >&2
3354 echo ""
3355 exit 1
3356 fi
3357 echo "" ;;
3358 usage|*)
3359 # Print usage also for all unknown commands.
3361 usage
3362 ;;
3363 esac
3365 report stop 2>/dev/null
3366 exit 0