tazwok view tazwok @ rev 368

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