tazwok view tazwok @ rev 407

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