tazwok view tazwok @ rev 397

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