tazwok view tazwok @ rev 472

Merge bugfixes from default
author Antoine Bodin <gokhlayeh@slitaz.org>
date Sat Apr 02 14:47:30 2011 +0200 (2011-04-02)
parents 15c8e63c3091 2b0f1826a119
children 789cd6566f3a
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 except 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 gen-src Rebuild sources.list in $SOURCES_REPOSITORY folder.
53 clean Clean all generated files in the package tree.
54 new-tree Prepare a new package tree and receipt (--interactive).
55 gen-list (Re-)Generate a packages list for a repository.
56 check-list Update packages lists for a repository.
57 gen-wok-db (Re-)Generate wok lists with depends and wanted data.
58 gen-clean-wok Generate a clean wok in a dir.
59 clean-wok Clean entirely the wok.
60 clean-src Remove old/unrelated-to-wok sources.
61 remove Remove a package from the wok.
62 webserver Enable/disable webserver on localhost.
63 update-wok Update the wok.
64 maintainers List all maintainers in the wok.
65 maintained-by List packages maintained by a contributor.
66 tags List all tags used in wok receipts.
67 block Add package from the blocked list to prevent cooking it.
68 unblock Remove package from the blocked list.\n
70 You can use `basename $0` command --help to list available options.
71 \033[1mImportant - *: \033[0m Commands which need a rewrite."
72 }
74 # This function displays an error message without returning any error code.
75 # It also logs the message in source package's warnings.txt; this file can be
76 # used on an eventual package page on website to display cooking warnings.
77 tazwok_warning()
78 {
79 echo -e "tazwok: $1" >&2
80 echo -e "$1" >> $WOK/${WANTED:-$PACKAGE}/warning.txt
81 return
82 }
84 ########################################################################
85 # TAZWOK VARIABLES & INITIAL CONFIGURATION
86 ########################
88 # Check if all packages are up to date into build environnement
89 check_env_status()
90 {
91 { [ "${COMMAND#cook}" = "$COMMAND" ] ||
92 [ "$COMMAND" = cook-toolchain ] ||
93 [ -f /etc/config.site.tmptoolchain ]; } && return
94 MIRROR_path=$(grep -l "^$1$" $LOCALSTATE/mirror $LOCALSTATE/undigest/*/mirror)
96 if [ ! "$MIRROR_path" ]; then
97 echo "You are trying to cook something but you don't use $1 repository, which is \
98 needed for this operation." | fold -s >&2
99 exit 1
100 fi
102 LOCALSTATE_path=${MIRROR_path%/mirror}
104 # Check is possible only if repository use ID.
105 if [ "${MIRROR_path:0:1}" = '/' ]; then
106 [ -f "$MIRROR_path/ID" ] || return
107 else
108 wget -a -s $MIRROR_path/ID 2>/dev/null || return
109 fi
111 [ -f $LOCALSTATE_path/ID ] && ID=$(cat $LOCALSATE_path/ID)
113 if [ "$LOCALSTATE_path" = "$LOCALSTATE" ]; then
114 tazpkg recharge main
115 else
116 tazpkg recharge ${LOCALSTATE_path##*/}
117 fi
119 [ "$(cat $LOCALSTATE_path/ID)" = "$ID" ] || env_status=1
120 }
122 get_tazwok_config()
123 {
124 # Get configuration file.
125 get_config
127 # Define & get options.
128 get_options_list="$get_options_list WOK SLITAZ_DIR SLITAZ_VERSION undigest"
129 get_options
131 LOCAL_REPOSITORY=$SLITAZ_DIR/${undigest:-$SLITAZ_VERSION}
133 if ! [ "$save_dir" ]; then
134 if [ -f $LOCAL_REPOSITORY/tazwok.conf ] || [ -f $LOCAL_REPOSITORY/slitaz.conf ]; then
135 save_dir=$LOCAL_REPOSITORY
136 [ -f $LOCAL_REPOSITORY/slitaz.conf ] && source $LOCAL_REPOSITORY/slitaz.conf
137 cd $save_dir
138 get_tazwok_config
139 unset save_dir
140 return
141 fi
142 fi
144 set_common_path
146 # Check that packages are up to date if user intend to cook.
147 check_env_status ${USE_ONLINE_PKG:-$PACKAGES_REPOSITORY}
148 check_env_status $INCOMING_REPOSITORY
150 # In case undigest is used, we need to upgrade system.
151 if [ "$undigest" ]; then
152 use_undigest_scan_core
153 ref_PACKAGES_REPOSITORY=$SLITAZ_DIR/$SLITAZ_VERSION/packages
154 if [ -f $SLITAZ_DIR/$SLITAZ_VERSION/tazwok.conf ] && \
155 grep -q ^USE_ONLINE_PKG $SLITAZ_DIR/$SLITAZ_VERSION/tazwok.conf; then
156 ref_USE_ONLINE_PKG=$(source $SLITAZ_DIR/$SLITAZ_VERSION/tazwok.conf && \
157 echo $USE_ONLINE_PKG)
158 fi
160 check_env_status ${ref_USE_ONLINE_PKG:-$ref_PACKAGES_REPOSITORY}
161 cd $ref_PACKAGES_REPOSITORY
162 if [ "$ref_USE_ONLINE_PKG" ]; then
163 ref_dep_db=$LOCALSTATE_path/wok-depends.txt
164 ref_wan_db=$LOCALSTATE_path/wok-wanted.txt
165 ref_lib_db=$LOCALSTATE_path/libraries.txt
166 else
167 ref_dep_db=$ref_PACKAGES_REPOSITORY/wok-depends.txt
168 ref_wan_db=$ref_PACKAGES_REPOSITORY/wok-wanted.txt
169 ref_lib_db=$ref_PACKAGES_REPOSITORY/libraries.txt
170 fi
172 for file in $ref_dep_db $ref_wan_db $ref_lib_db; do
173 [ -f "$file" ] && continue
174 missing_file=t
175 echo "$file is missing." >&2
176 done
177 if [ "$missing_file" ]; then
178 echo "
179 Theses files are needed to get datas about packages from the reference repository $SLITAZ_VERSION. \
180 If you don't intend to build this reference repository yourself, you should set USE_ONLINE_PKG variable \
181 into tazwok.conf of this reference repository. How-to:" | fold -s >&2
182 echo "echo 'USE_ONLINE_PKG=\"packages_repository_url\"' >> $SLITAZ_DIR/$SLITAZ_VERSION/tazwok.conf"
183 echo ""
184 exit 1
185 fi
186 fi
188 # If $env_status exists, it means an upgrade may be needed.
189 if [ "$env_status" ]; then
190 if [ -x /usr/bin/clean-chroot ]; then
191 echo y | tazpkg upgrade
192 else
193 echo "\e[0;31mWarning: \e[m"
194 echo "You're environnement may need a package upgrade."
195 echo "Upgrading is highly recommanded to ensure repository consistency."
196 echo "You can (E)xit, (U)pgrade, or (C)ontinue."
197 echo -n "What do you want to do ?"
198 read answer
199 case $answer in
200 [Cc]*) ;;
201 [Uu]*) echo y | tazpkg upgrade ;;
202 *) exit
203 esac
204 fi
205 fi
207 # Check commons directories, create them if user is root.
208 if test $(id -u) = 0 ; then
209 check_dir $WOK || chmod 777 $WOK
210 check_dir $LOCAL_REPOSITORY/clean-wok || chmod 777 $LOCAL_REPOSITORY/clean-wok
211 check_dir $PACKAGES_REPOSITORY
212 check_dir $SOURCES_REPOSITORY
213 check_dir $INCOMING_REPOSITORY
214 check_dir $LOCAL_REPOSITORY/log
215 for file in $dep_db $wan_db $cookorder $commit $cooklist \
216 $broken $blocked $SOURCES_REPOSITORY/sources.list $lib_db
217 do
218 [ -f $file ] || touch $file
219 done
220 fi
222 # Limit memory usage.
223 ulimit -v $(awk '/MemTotal|SwapTotal/ { n+=$2 } END { print int((n*80)/100) }' < /proc/meminfo)
224 }
226 # The path to the most important files/dir used by Tazwok.
227 set_common_path()
228 {
229 PACKAGES_REPOSITORY=$LOCAL_REPOSITORY/packages
230 [ "$WOK" ] || WOK=$LOCAL_REPOSITORY/wok
231 INCOMING_REPOSITORY=$LOCAL_REPOSITORY/packages-incoming
232 SOURCES_REPOSITORY=$LOCAL_REPOSITORY/src
233 RECEIPT="$WOK/$PACKAGE/receipt"
234 LOG="$WOK/$PACKAGE/process.log"
235 dep_db=$INCOMING_REPOSITORY/wok-depends.txt
236 wan_db=$INCOMING_REPOSITORY/wok-wanted.txt
237 lib_db=$INCOMING_REPOSITORY/libraries.txt
238 cookorder=$PACKAGES_REPOSITORY/cookorder.txt
239 commit=$PACKAGES_REPOSITORY/commit
240 cooklist=$PACKAGES_REPOSITORY/cooklist
241 broken=$PACKAGES_REPOSITORY/broken
242 blocked=$PACKAGES_REPOSITORY/blocked
244 # log steps for webserver.
245 log_step="$LOCAL_REPOSITORY/log/step"
246 run_on_exit="$run_on_exit
247 rm -f $LOCAL_REPOSITORY/log/step
248 rm -f $LOCAL_REPOSITORY/log/package"
249 }
251 ########################################################################
252 # TAZWOK CHECK FUNCTIONS
253 ########################
255 # Check for a package name on cmdline.
256 check_for_package_on_cmdline()
257 {
258 if [ ! "$PACKAGE" ]; then
259 echo -e "\nYou must specify a package name on the command line." >&2
260 echo -e "Example : tazwok $COMMAND package\n" >&2
261 exit 1
262 fi
263 }
265 # Check for the receipt of a package used to cook.
266 check_for_receipt()
267 {
268 if [ ! -f "$RECEIPT" ]; then
269 echo -e "\nUnable to find the receipt : $RECEIPT\n" >&2
270 exit 1
271 fi
272 }
274 # Check for a specified file list on cmdline.
275 check_for_list()
276 {
277 if [ ! "$LIST" ]; then
278 echo -e "\nPlease specify the path to the list of packages to cook.\n" >&2
279 exit 1
280 elif ! [ -f "$LIST" ]; then
281 echo -e "\nUnable to find $LIST packages list.\n" >&2
282 exit 1
283 elif ! [ -s "$LIST" ]; then
284 echo -e "\nList is empty.\n" >&2
285 exit 1
286 fi
287 }
289 ########################################################################
290 # TAZWOK CORE FUNCTIONS
291 ########################
293 remove_src()
294 {
295 [ "$WANTED" ] && return
296 look_for_cookopt !remove_src && return
297 if [ ! -d $WOK/$PACKAGE/install ] && [ "$src" ] && [ -d "$src/_pkg" ]; then
298 check_for_var_modification _pkg src || return
299 mv "$src/_pkg" $WOK/$PACKAGE/install
300 fi
302 # Don't remove sources if a package uses src variable in its
303 # genpkg_rules: it maybe needs something inside.
304 for i in $PACKAGE $(look_for_rwanted); do
305 sed -n '/^genpkg_rules\(\)/','/}/'p $WOK/$i/receipt | \
306 fgrep -q '$src' && tazwok_warning "Sources will not be removed \
307 because $i uses \$src in its receipt." && return
308 done
310 report step "Removing sources directory"
311 rm -fr "$src"
312 report end-step
313 }
315 # Check $COOK_OPT; usage : get_cookopt particular_opt
316 # Return error if not found
317 # Return args if the opt is in the format opt=arg1:arg2:etc
318 look_for_cookopt()
319 {
320 for arg in $COOK_OPT; do
321 case $arg in
322 $1=*)
323 arg=${arg#$1=}
324 while [ "$arg" ]; do
325 echo "${arg%%:*}"
326 [ "${arg/:}" = "$arg" ] && return
327 arg=${arg#*:}
328 done
329 ;;
330 $1)
331 return
332 ;;
333 esac
334 done
335 return 1
336 }
338 # Check for the wanted package if specified in WANTED
339 # receipt variable. Set the $src/$_pkg variable to help compile
340 # and generate packages.
341 check_for_wanted()
342 {
343 if [ "$WANTED" ]; then
344 report "Checking for the wanted package"
345 if [ ! -d "$WOK/$WANTED" ]; then
346 report exit "\nWanted package is missing in the work directory.\n"
347 fi
349 # Checking for buildtree of Wanted package
350 if [ ! -d "$WOK/$WANTED/taz" ]; then
351 echo -e "\n\nSource files of wanted package is missing in the work directory."
352 echo -n "Would you like to build the missing package (y/N) ? " ; read anser
353 if [ "$anser" == "y" ]; then
354 tazwok cook $WANTED
355 else
356 report exit "\nWanted package source tree is missing in the work directory.\n"
357 fi
358 fi
359 report end-step
361 # Set wanted src path.
362 set_src_path && set_pkg_path
364 fi
365 }
367 # Check for build dependencies, notify user and install if specified.
368 check_for_build_depends()
369 {
370 [ "$WANTED" ] && return
371 [ "$CATEGORY" = meta ] && ! fgrep -q compile_rules $RECEIPT && return
372 [ ! "$BUILD_DEPENDS" ] && ! fgrep -q compile_rules $RECEIPT && return
373 report step "Looking for build dependencies"
375 # Keep the list of previously installed build_depends then compare
376 # it with new build_depends to know what to install and what to
377 # what to remove.
378 plan_remove=" $MISSING_PACKAGE $remove_later "
379 [ ! "${plan_remove// }" ] && unset plan_remove
380 unset MISSING_PACKAGE remove_later
381 rwanted=$(look_for_rwanted)
383 for pkg in $(scan $PACKAGE --look_for=bdep --with_dev | \
384 grep -v $(for i in $(look_for_rwanted) $PACKAGE; do echo " -e ^$i$"; done))
385 do
387 # Delay the removing of previous cook depends if they are needed
388 # for next cook too.
389 if [ ! -d "$INSTALLED/$pkg" ] ; then
390 MISSING_PACKAGE="$MISSING_PACKAGE $pkg"
391 fi
392 if [ "$plan_remove" != "${plan_remove/ $pkg }" ]; then
393 plan_remove="${plan_remove/ $pkg / }"
394 remove_later="$remove_later $pkg"
395 fi
396 grep -q ^$pkg$ $broken && broken_pkg="$broken_pkg$pkg "
397 done
399 # Don't cook if a depend is broken.
400 if [ "$broken_pkg" ]; then
401 MISSING_PACKAGE=$plan_remove
402 echo "Can't cook $PACKAGE because of broken depend(s) : $broken_pkg" >&2
403 unset plan_remove broken_pkg
405 # Set report step to failed.
406 report_return_code=1
407 report end-step
408 return 1
409 fi
410 if [ "$MISSING_PACKAGE" ]; then
411 install_missing()
412 {
413 echo "Installing missing packages : $MISSING_PACKAGE"
414 for pkg in $MISSING_PACKAGE; do
415 [ -d "$INSTALLED/$pkg" ] || tazpkg get-install $pkg
416 done
417 }
418 if [ "$auto_install" = yes ]; then
419 install_missing
420 else
421 echo "================================================================================"
422 for pkg in $MISSING_PACKAGE
423 do
424 echo "Missing : $pkg"
425 done
426 echo "================================================================================"
427 echo "You can continue, exit or install missing dependencies."
428 echo -n "Install, continue or exit (install/y/N) ? "; read answer
429 case $answer in
430 install)
431 install_missing ;;
432 y|yes)
433 unset MISSING_PACKAGE;;
434 *)
435 report stop
436 exit 0 ;;
437 esac
438 fi
439 fi
440 report end-step
441 remove_build_depends $plan_remove
442 unset plan_remove
443 }
445 remove_build_depends()
446 {
447 [ "$1" ] || return
448 report step "Removing previous build dependencies"
449 echo "Removing these packages : $@"
450 for pkg in $@; do
451 [ -f "$INSTALLED/$pkg/receipt" ] && tazpkg remove $pkg --auto
452 done
453 cd $PWD
454 report end-step
455 }
457 # Check if we can use the new way to handle tarball
458 # or if we keep the previous method by checking for
459 # _pkg=/src= in receipt and reverse-wanted.
460 check_for_var_modification()
461 {
462 for var in $@; do
463 for pkg in $PACKAGE $(look_for_wanted) $(look_for_rwanted); do
464 [ -f $WOK/$pkg/receipt ] || continue
465 fgrep -q "$var=" $WOK/$pkg/receipt && return 1
466 done
467 done
469 # Tweak to make if; then...; fi function working with this one.
470 echo -n ""
471 }
473 set_src_path()
474 {
475 if check_for_var_modification src _pkg; then
476 src=$WOK/${WANTED:-$PACKAGE}/${WANTED:-$PACKAGE}-$VERSION
477 else
478 tazwok_warning "Use original name or tarball root directory because src/_pkg is defined in the receipt (this is no longer needed!)."
479 src=$WOK/${WANTED:-$PACKAGE}/${SOURCE:-${WANTED:-$PACKAGE}}-$VERSION
480 fi
481 stuff=$WOK/$PACKAGE/stuff
482 [ "$WANTED" ] && wanted_stuff=$WOK/$WANTED/stuff
483 }
485 set_pkg_path()
486 {
487 if [ -d $WOK/${WANTED:-$PACKAGE}/install ] ; then
488 _pkg=$WOK/${WANTED:-$PACKAGE}/install
489 else
490 _pkg=$src/_pkg
491 fi
492 }
494 # Output $VERSION-$EXTRAVERSION using packages.txt
495 get_pkg_version()
496 {
497 [ "$PACKAGE" ] || return
498 grep -m1 -A1 -sh ^$PACKAGE$ $1/packages.txt | tail -1 | sed 's/ *//'
499 }
501 remove_previous_package()
502 {
503 [ "$prev_VERSION" ] || return
504 if [ "$VERSION$EXTRAVERSION" != "$prev_VERSION" ]; then
505 rm -f $1/$PACKAGE-$prev_VERSION.tazpkg
506 fi
507 return 0
508 }
510 # Check for src tarball and wget if needed.
511 check_for_tarball()
512 {
513 [ "$WGET_URL" ] || return 0
514 look_for_cookopt !unpack && nounpack=yes
515 report step "Checking for source tarball: $PACKAGE"
516 local repack_src=$repack_src TARBALL=$TARBALL
517 if [ "$repack_src" = yes ] && look_for_cookopt !repack_src; then
518 repack_src=no
519 fi
520 if [ "$target" ]; then
521 src="$target"
522 else
523 set_src_path
524 fi
525 tmp_src=$tmp/tarball-$$
526 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ] && \
527 [ ! -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ] ; then
528 cd $SOURCES_REPOSITORY
529 if [ "$SOURCE" ]; then
530 alt_url="http://mirror.slitaz.org/sources/packages/${SOURCE:0:1}/$SOURCE-$VERSION.tar.lzma"
531 else
532 alt_url="http://mirror.slitaz.org/sources/packages/${PACKAGE:0:1}/$PACKAGE-$VERSION.tar.lzma"
533 fi
534 download $WGET_URL $alt_url http://mirror.slitaz.org/sources/packages/${TARBALL:0:1}/$TARBALL
535 unset alt_url
536 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ] && \
537 [ ! -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ] && \
538 [ ! -d $tmp_src ]; then
539 echo -e "\nDownload failed, exiting. Please check WGET_URL variable.\n" >&2
540 report end-step
541 return 1
542 fi
543 fi
544 report end-step
545 if { [ -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ] && [ "$nounpack" ] ; } || \
546 { [ -f "$SOURCES_REPOSITORY/$TARBALL" ] && [ "$repack_src" != yes ] && [ "$nounpack" ] ; }; then
547 [ -d "$tmp_src" ] && rm -r $tmp_src
548 return 0
549 fi
551 # Untaring source if necessary. We don't need to extract source if
552 # the package is built with a wanted source package.
553 if [ "$WANTED" ]; then
554 [ -d "$tmp_src" ] && rm -r $tmp_src
555 return
556 fi
558 report step "Untaring source tarball"
560 # Log process.
561 echo "untaring source tarball" >> $LOG
563 # If $tmp_src exists, there's already a unpacked tarball in it.
564 if ! [ -d $tmp_src ]; then
565 mkdir $tmp_src
566 if [ -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ] && [ "$repack_src" = yes ]; then
567 lzma d $SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma -so | \
568 tar xf - -C $tmp_src
569 repack_src=no
570 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
571 elif [ -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
572 case "$TARBALL" in
573 *zip|*xpi) cd $tmp_src && unzip -o $SOURCES_REPOSITORY/$TARBALL ;;
574 *bz2|*tbz|*gem) tar xjf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
575 *tar) tar xf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
576 *lzma|*lz) unlzma -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
577 *xz) unxz -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
578 *Z|*taz) uncompress -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
579 *gz) tar xzf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
580 *rpm) cd $tmp_src && rpm2cpio $SOURCES_REPOSITORY/$TARBALL | cpio -idm --quiet;;
582 # It's a plain file or something receipt unpack itself.
583 *)
584 mkdir $tmp_src/${SOURCE:-$PACKAGE}-$VERSION
585 cp $SOURCES_REPOSITORY/$TARBALL $tmp_src/${src##*/}
586 ;;
588 esac || { report end-step
589 rm -f $SOURCES_REPOSITORY/$TARBALL
590 rm -r $tmp_src
591 return 1
592 }
593 fi
595 # Check if uncompressed tarball is in a root dir or not.
596 if [ "$(ls -A $tmp_src | wc -l)" -gt 1 ] || [ -f $(echo $tmp_src/*) ]; then
597 if check_for_var_modification src _pkg; then
598 mv $tmp_src $tmp_src-1
599 mkdir $tmp_src
600 mv $tmp_src-1 $tmp_src/${SOURCE:-$PACKAGE}-$VERSION
601 else
602 mv $tmp_src/* $WOK/$PACKAGE
603 repack_src=no
604 rm -r $tmp_src
605 tazwok_warning "Putting all files in $WOK/$PACKAGE; not sure about how to handle this tarball (no root dir)... Please try to remove src/_pkg definition from the receipt if you encounter any problems."
606 fi
607 fi
608 fi
610 if [ "$repack_src" = yes ]; then
611 report step "Repacking sources in .tar.lzma format"
612 [ "$TARBALL" ] && rm -f $SOURCES_REPOSITORY/$TARBALL
613 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
614 cd $tmp_src
615 tar -c * | lzma e $SOURCES_REPOSITORY/$TARBALL -si
616 fi
618 # Remove previous tarball if no other package needs it. We take care to
619 # keep tarball if the same package uses it in the main repository.
620 if [ "$TARBALL" ]; then
621 previous_tarball=$(grep ^$PACKAGE:incoming $SOURCES_REPOSITORY/sources.list | cut -f2)
622 if [ "$previous_tarball" ]; then
623 sed "/^$PACKAGE:incoming/ s/.*/$PACKAGE:incoming\t$TARBALL/" \
624 -i $SOURCES_REPOSITORY/sources.list
625 grep -q $'\t'$previous_tarball$ $SOURCES_REPOSITORY/sources.list || \
626 rm -f $SOURCES_REPOSITORY/$previous_tarball
627 else
628 echo -e "$PACKAGE:incoming\t$TARBALL" >> $SOURCES_REPOSITORY/sources.list
629 fi
630 fi
632 if [ "$nounpack" ]; then
633 [ -d "$tmp_src" ] && rm -r $tmp_src
634 report end-step
635 return
636 fi
637 if [ ! -d "$src" ]|| [ "$target" ]; then
638 # Permissions settings.
639 chown -R root.root "$tmp_src"
640 if [ -d "$src" ]; then
641 mkdir -p $src
642 for f in $tmp_src/*/*; do
643 cp -a $f $src || { report end-step; rm -r $tmp_src; return 1; }
644 done
645 else
646 if ! check_for_var_modification src _pkg && ! [ "$target" ]; then
647 src="${src%/*}/$(ls $tmp_src)"
648 fi
649 mv $(echo $tmp_src/*) "$src" || { report end-step; rm -r $tmp_src; return 1; }
650 fi
651 rm -r $tmp_src
652 else
653 [ -d "$tmp_src" ] && rm -r $tmp_src
654 echo "There's already something at $src. Abort." >&2
655 fi
656 report end-step
657 }
659 # help gen sources.list file from scranch
660 gen_sources_list()
661 {
662 local src_repository=$1
663 [ -f $src_repository/sources.list ] && rm -f $src_repository/sources.list
664 for i in $WOK/*; do
665 unset PACKAGE SOURCE VERSION WGET_URL TARBALL WANTED
666 [ -f $i/receipt ] && source $i/receipt
667 [ "$WGET_URL" ] || continue
668 if grep -q "^$PACKAGE | $VERSION" $PACKAGES_REPOSITORY/packages.desc; then
669 main_version="$VERSION"
670 if [ -f $src_repository/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma ]; then
671 echo -e "$PACKAGE:main\t${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" >> $src_repository/sources.list
672 elif [ -f "$src_repository/$TARBALL" ]; then
673 echo -e "$PACKAGE:main\t$TARBALL" >> $src_repository/sources.list
674 fi
675 else
676 # May not works if package use extraversion.
677 main_version=$(grep -m1 -A1 -sh ^$PACKAGE$ $PACKAGES_REPOSITORY/packages.txt | tail -1 | sed 's/ *//')
678 if [ -f $src_repository/${SOURCE:-$PACKAGE}-$main_version.tar.lzma ]; then
679 echo -e "$PACKAGE:main\t${SOURCE:-$PACKAGE}-$main_version.tar.lzma" >> $src_repository/sources.list
680 else
681 unset main_version
682 fi
683 fi
684 if [ ! "$main_version" ] || [ $(grep -q "^$PACKAGE | $VERSION" $INCOMING_REPOSITORY/packages.desc 2>/dev/null) ]; then
685 if [ -f $src_repository/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma ]; then
686 echo -e "$PACKAGE:incoming\t${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" >> $src_repository/sources.list
687 elif [ -f "$src_repository/$TARBALL" ]; then
688 echo -e "$PACKAGE:incoming\t$TARBALL" >> $src_repository/sources.list
689 fi
690 fi
691 done
692 }
694 # Log and execute compile_rules function if it exists, to configure and
695 # make the package if it exists.
696 check_for_compile_rules()
697 {
698 if grep -q ^compile_rules $RECEIPT; then
699 echo "executing compile_rules" >> $LOG
700 report step "Executing compile_rules"
701 cd $WOK/$PACKAGE
702 rm -f /tmp/config.site
703 ulimit -d unlimited
704 ulimit -m unlimited
706 # Free some RAM by cleaning cache if option is enabled.
707 freeram=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
709 # Disable -pipe in CFLAGS/CXXFLAGS if less than 512Mb of free
710 # RAM are available.
711 if [ "$freeram" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" -o \
712 "$CXXFLAGS" != "${CXXFLAGS/-pipe}" ]; then
713 tazwok_warning "Disabling -pipe compile flag because only ${freeram}b of RAM is available."
714 CFLAGS="${CFLAGS/-pipe}"
715 CXXFLAGS="${CXXFLAGS/-pipe}"
716 fi
717 unset freeram
719 # Set cook environement variables.
720 [ "$src" ] || set_src_path
721 [ "$DESTDIR" ] || DESTDIR="$WOK/$PACKAGE/install"
722 [ "$CONFIG_SITE" ] || CONFIG_SITE=/etc/config.site
723 export CFLAGS=$(echo "$CFLAGS" | tr -s ' ') \
724 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ') \
725 MAKEFLAGS DESTDIR BUILD_HOST CONFIG_SITE default_prefix \
726 default_datarootdir default_datadir default_localedir \
727 default_infodir default_mandir default_build default_host
728 local LC_ALL=POSIX LANG=POSIX
729 compile_rules
730 return_code=$?
732 if [ -f /tmp/config.site ]; then
733 rm /tmp/config.site
734 else
735 tazwok_warning "config.site hasn't been used during \
736 the configuration process."
737 fi
739 # Return the proper status to step.
740 (exit $return_code)
741 report end-step
742 fi
743 }
745 # Check for loop in deps tree. /!\ can be removed.
746 check_for_deps_loop()
747 {
748 local list
749 local pkg
750 local deps
751 pkg=$1
752 shift
753 [ -n "$1" ] || return
754 list=""
756 # Filter out already processed deps.
757 for i in $@; do
758 case " $ALL_DEPS" in
759 *\ $i\ *);;
760 *) list="$list $i";;
761 esac
762 done
763 ALL_DEPS="$ALL_DEPS$list "
764 for i in $list; do
765 [ -f $i/receipt ] || continue
766 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
767 case " $deps " in
768 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
769 *) check_for_deps_loop $pkg $deps;;
770 esac
771 done
772 }
774 # Function used by download().
775 revert_vcs_failure()
776 {
777 cd $SOURCES_REPOSITORY
778 rm -r $tmp_src
779 }
781 download()
782 {
783 if [ "$COMMAND" = get-src ]; then
784 if [ "${DEPENDS/tar}" != "$DEPENDS" ] || [ "${BUILD_DEPENDS/tar}" != "$BUILD_DEPENDS" ]; then
785 [ -f $INSTALLED/tar/receipt ] || tazpkg get-install tar --forced
786 fi
787 fi
788 for file in $@; do
789 echo "Downloading from ${file#*|}..."
790 case "$file" in
791 git\|*)
792 file=${file#git|}
793 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/git/receipt ] && tazpkg get-install git --forced
794 if [ -f $INSTALLED/git/receipt ]; then
795 mkdir $tmp_src
796 cd $tmp_src
797 if [ "$BRANCH" ]; then
798 git clone $file ${src##*/} && cd ${src##*/} && \
799 git checkout $BRANCH && rm -rf .git* && break
800 else
801 git clone $file ${src##*/} && rm -rf ${src##*/}/.git* && break
802 fi
803 revert_vcs_failure
804 else
805 tazwok_warning "Needs git to download the source tarball from $file, please add it as a build-depend."
806 continue
807 fi
808 ;;
809 bazaar\|*)
810 file=${file#bazaar|}
811 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/bazaar/receipt ] && tazpkg get-install bazaar --forced
812 if [ -f $INSTALLED/bazaar/receipt ]; then
813 mkdir $tmp_src
814 cd $tmp_src
815 if [ "$BRANCH" ]; then
816 bzr co $file -r $BRANCH ${src##*/} && rm -rf ${src##*/}/.bzr* && break
817 else
818 bzr co $file ${src##*/} && rm -rf ${src##*/}/.bzr* && break
819 fi
820 revert_vcs_failure
821 else
822 tazwok_warning "Needs bazaar to download the source tarball from $file, please add it as a build-depend."
823 continue
824 fi
825 ;;
826 subversion\|*)
827 file=${file#subversion|}
828 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/subversion/receipt ] && tazpkg get-install subversion --forced
829 if [ -f $INSTALLED/subversion/receipt ]; then
830 mkdir $tmp_src
831 cd $tmp_src
832 if [ "$BRANCH" ]; then
833 echo t | svn co $file -r $BRANCH ${src##*/} && rm -rf ${src##*/}/.svn* && break
834 else
835 echo t | svn co $file ${src##*/} && rm -rf ${src##*/}/.svn* && break
836 fi
837 revert_vcs_failure
838 else
839 tazwok_warning "Needs subversion to download the source tarball from $file, please add it as a build-depend."
840 continue
841 fi
842 ;;
843 mercurial\|*)
844 file=${file#mercurial|}
845 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/mercurial/receipt ] && tazpkg get-install mercurial --forced
846 if [ -f $INSTALLED/mercurial/receipt ]; then
847 mkdir $tmp_src
848 cd $tmp_src
849 if [ "$BRANCH" ]; then
850 hg clone $file --rev $BRANCH ${src##*/} && rm -rf ${src##*/}/.hg* && break
851 else
852 hg clone $file ${src##*/} && rm -rf ${src##*/}/.hg* && break
853 fi
854 revert_vcs_failure
855 else
856 tazwok_warning "Needs mercurial to download the source tarball from $file, please add it as a build-depend."
857 continue
858 fi
859 ;;
860 https*)
861 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/wget/receipt ] && tazpkg get-install wget --forced
862 if [ -d $INSTALLED/wget ]; then
863 if [ "${WGET_URL%$TARBALL}" = "$WGET_URL" ] && [ "$file" = "$WGET_URL" ]; then
864 wget -q --no-check-certificate -O $TARBALL $file && break
865 else
866 wget -q --no-check-certificate $file && break
867 fi
868 else
869 tazwok_warning "Needs wget to download the source tarball from $file, please add it as a build-depend."
870 continue
871 fi
872 ;;
873 http*|ftp*)
874 # Handle crappy URL.
875 if [ "$COMMAND" = get-src ]; then
876 if [ "${DEPENDS/wget}" != "$DEPENDS" ] || [ "${BUILD_DEPENDS/wget}" != "$BUILD_DEPENDS" ]; then
877 [ -f $INSALLED/wget/receipt ] || tazpkg get-install wget --forced
878 fi
879 fi
880 if [ "${WGET_URL%$TARBALL}" = "$WGET_URL" ] && [ "$file" = "$WGET_URL" ]; then
881 wget -q -O $TARBALL $file && break
882 else
883 wget -q $file && break
884 fi
885 ;;
886 esac
887 done
888 }
890 # Regenerate every package that wants a PACKAGE compiled.
891 refresh_packages_from_compile()
892 {
893 # make tazwok genpkg happy.
894 mkdir $WOK/$PACKAGE/taz
896 # Cook rwanted in default or specied order.
897 genlist=" $(look_for_rwanted | tr '\n' ' ') "
898 for i in $(look_for_cookopt genpkg | tac); do
899 [ "${genlist/ $i }" = "$genlist" ] && continue
900 genlist=" $i${genlist/ $i / }"
901 done
902 if [ "$genlist" ]; then
903 local PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
904 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
905 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
906 src _pkg DESTDIR CONFIG_SITE RECEIPT LOG stuff wanted_stuff
907 for PACKAGE in $genlist; do
908 set_common_path
909 gen_package
910 done
911 fi
912 }
914 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
915 # so some packages need to copy these files with the receipt and genpkg_rules.
916 # This function is executed by gen_package when 'tazwok genpkg'.
917 copy_generic_files()
918 {
919 # In most cases, locales are in $_pkg/usr/share/locale so we copy files
920 # using generic variables and $LOCALE from Tazwok config file.
921 if [ "$LOCALE" ]; then
922 if [ -d "$_pkg/usr/share/locale" ]; then
923 for i in $LOCALE
924 do
925 if [ -d "$_pkg/usr/share/locale/$i" ]; then
926 mkdir -p $fs/usr/share/locale
927 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
928 fi
929 done
930 fi
931 fi
933 # Pixmaps (PNG or/and XPM only). Some icons/images can be added through
934 # genpkg_rules and generic copy can be disabled with GENERIC_PIXMAPS="no"
935 # in pkg receipt.
936 if [ "$GENERIC_PIXMAPS" != "no" ]; then
937 if [ -d "$_pkg/usr/share/pixmaps" ]; then
938 mkdir -p $fs/usr/share/pixmaps
939 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
940 $fs/usr/share/pixmaps 2>/dev/null
941 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
942 $fs/usr/share/pixmaps 2>/dev/null
943 fi
945 # Custom or homemade PNG pixmap can be in stuff.
946 if [ -f "stuff/$PACKAGE.png" ]; then
947 mkdir -p $fs/usr/share/pixmaps
948 cp -a stuff/$PACKAGE.png $fs/usr/share/pixmaps
949 fi
950 fi
952 # Desktop entry (.desktop).
953 if [ -d "$_pkg/usr/share/applications" ]; then
954 cp -a $_pkg/usr/share/applications $fs/usr/share
955 fi
957 # Homemade desktop file(s) can be in stuff.
958 if [ -d "stuff/applications" ]; then
959 mkdir -p $fs/usr/share
960 cp -a stuff/applications $fs/usr/share
961 fi
962 if [ -f "stuff/$PACKAGE.desktop" ]; then
963 mkdir -p $fs/usr/share/applications
964 cp -a stuff/$PACKAGE.desktop $fs/usr/share/applications
965 fi
966 }
968 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
969 strip_package()
970 {
971 report step "Executing strip on all files"
973 # Binaries.
974 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
975 do
976 if [ -d "$dir" ]; then
977 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
978 fi
979 done
981 # Libraries.
982 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
983 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
984 report end-step
985 }
987 # Remove .pyc and .pyo files from packages.
988 py_compiled_files_remove()
989 {
990 report step "Removing all .pyc and .pyo files from package"
991 find $fs -type f -name "*.pyc" -delete 2>/dev/null
992 find $fs -type f -name "*.pyo" -delete 2>/dev/null
993 report end-step
994 }
996 # Check FSH in a slitaz package (Path: /:/usr)
997 check_fsh()
998 {
999 cd $WOK/$PACKAGE/taz/*/fs
1000 if [ -z "$(find * ! -type d)" ] && [ "$CATEGORY" != meta ]; then
1001 echo "$PACKAGE fs is empty." >&2
1002 cd $WOK/$PACKAGE && rm -rf taz
1003 return 1
1004 fi
1005 [ -n "$FSH" ] || FSH="bin boot dev etc home init lib media mnt proc \
1006 root sbin share sys tmp usr var vz usr/bin usr/games usr/include usr/lib \
1007 usr/local usr/sbin usr/share usr/src"
1008 error=0
1009 for i in `ls -d * usr/* 2>/dev/null`
1010 do
1011 if ! echo $FSH | fgrep -q $i; then
1012 echo "Wrong path: /$i" >&2
1013 error=1
1014 fi
1015 done
1016 if [ "$error" = "1" ]; then
1017 cat << _EOT_
1019 Package will install files in a non standard directory and won't be generated.
1020 You may have a wrong copy path in genpkg_rules or need to add some options to
1021 configure in compile_rules. Some valid options for SliTaz (Linux FSH):
1023 --prefix=/usr
1024 --sysconfdir=/etc
1025 --libexecdir=/usr/lib/(pkgname)
1026 --localstatedir=/var
1027 --mandir=/usr/share/man
1028 --infodir=/usr/share/info
1030 For more information please read SliTaz docs and run: ./configure --help
1031 ================================================================================
1032 $PACKAGE package generation aborted.
1034 _EOT_
1036 # Dont generate a corrupted package.
1037 cd $WOK/$PACKAGE && rm -rf taz
1038 return 1
1039 fi
1040 return 0
1043 gen_cookmd5()
1045 # md5sum of cooking stuff make tazwok able to check for changes
1046 # without hg.
1047 cd $WOK/$PACKAGE
1048 md5sum receipt > md5
1049 [ -f description.txt ] && md5sum description.txt >> md5
1050 if [ -d stuff ]; then
1051 find stuff | while read file; do
1052 md5sum $file >> md5
1053 done
1054 fi
1057 set_pkg_broken()
1059 grep -q ^$PACKAGE$ $broken || echo $PACKAGE >> $broken
1061 # Remove pkg from cooklist to avoid re-cook it if no changes happen
1062 # in the cook stuff.
1063 sed "/^$PACKAGE$/d" -i $cooklist $commit
1065 gen_cookmd5
1067 # Return 1 to make report know that its mother-function failed.
1068 return 1
1071 # Create a package tree and build the gziped cpio archive
1072 # to make a SliTaz (.tazpkg) package.
1073 gen_package()
1075 check_root
1076 check_for_package_on_cmdline
1077 check_for_receipt
1078 source_receipt
1080 # May compute VERSION
1081 if grep -q ^get_version $RECEIPT; then
1082 get_version
1083 fi
1084 check_for_wanted
1085 cd $WOK/$PACKAGE
1087 # Remove old Tazwok package files.
1088 [ -d "taz" ] && rm -rf taz
1090 # Create the package tree and set useful variables.
1091 fs=$WOK/$PACKAGE/taz/$PACKAGE-$VERSION/fs
1092 mkdir -p $fs
1094 # Set $src for standard package and $_pkg variables.
1095 set_src_path
1096 set_pkg_path
1098 # Execute genpkg_rules, check package and copy generic files to build
1099 # the package.
1100 report step "Building $PACKAGE with the receipt"
1101 report open-bloc
1102 if look_for_cookopt !fs; then
1104 elif grep -q ^genpkg_rules $RECEIPT; then
1106 # Log process.
1107 echo "executing genpkg_rules" >> $LOG
1108 report step "Executing genpkg_rules"
1109 ( set -e; genpkg_rules ) || { set_pkg_broken; report close-bloc; return 1; }
1110 check_fsh || { set_pkg_broken; report close-bloc; return 1; }
1111 cd $WOK/$PACKAGE
1112 report end-step
1114 # Skip generic files for packages with a WANTED variable
1115 # (dev and split pkgs).
1116 if [ ! "$WANTED" ]; then
1117 copy_generic_files
1118 fi
1119 look_for_cookopt !strip || strip_package
1120 py_compiled_files_remove
1121 else
1122 echo "No package rules to gen $PACKAGE..." >&2
1123 set_pkg_broken
1124 report close-bloc
1125 return 1
1126 fi
1128 # Copy the receipt and description (if exists) into the binary package tree.
1129 cd $WOK/$PACKAGE
1130 report step "Copying the receipt"
1131 cp receipt taz/$PACKAGE-$VERSION
1132 report end-step
1133 if grep -q ^get_version $RECEIPT; then
1134 report step "Updating version in receipt"
1135 sed -i "s/^VERSION=.*/VERSION=\"$VERSION\"/" \
1136 taz/$PACKAGE-$VERSION/receipt
1137 report end-step
1138 fi
1139 if [ -f "description.txt" ]; then
1140 report step "Copying the description file"
1141 cp description.txt taz/$PACKAGE-$VERSION
1142 report end-step
1143 fi
1145 # Generate md5 of cooking stuff to look for commit later.
1146 gen_cookmd5
1147 echo -e "\n# md5sum of cooking stuff :" >> taz/$PACKAGE-$VERSION/receipt
1148 cat md5 | sed 's/^/# /' >> taz/$PACKAGE-$VERSION/receipt
1150 # Create the files.list by redirecting find output.
1151 report step "Creating the list of files"
1152 cd taz/$PACKAGE-$VERSION
1153 LAST_FILE=""
1154 { find fs -print; echo; } | while read file; do
1155 if [ "$LAST_FILE" ]; then
1156 case "$file" in
1157 $LAST_FILE/*)
1158 case "$(ls -ld "$LAST_FILE")" in
1159 drwxr-xr-x\ *\ root\ *\ root\ *);;
1160 *) echo ${LAST_FILE#fs};;
1161 esac;;
1162 *) echo ${LAST_FILE#fs};;
1163 esac
1164 fi
1165 LAST_FILE="$file"
1166 done > files.list
1168 # Next, check if something has changed in lib files.
1169 # Plan to recook each packages which depends on libs
1170 # which doesn't exists anymore.
1171 libs=$(for file in $(find * -type f); do
1172 [ "$(dd if=$file bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ] || continue
1173 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $PWD/$file
1174 done | { cut -f 1 -d ' ' | tr -d '\t' | sort -u | \
1175 sed -e 's/^linux-gate.so.*$/SLIB/' -e 's~^/lib/ld-.*$~SLIB~' \
1176 -e '/^statically$/d' | tr '\n' ' '; })
1177 [ "$libs" ] && libs=$(echo " $libs" | sed -r 's/( SLIB)+ / /g')
1178 old_libs=$(grep -m1 ^$PACKAGE$'\t' $lib_db | cut -f 2)
1179 if [ "$old_libs" ]; then
1180 report step "Looking if reverse depends needs to be refreshed"
1181 for i in $old_libs; do
1182 [ "${libs/ $i }" = "$libs" ] || continue
1183 fgrep " $i " $lib_db | cut -f 1
1184 done | sort -u | while read rdep; do
1185 [ "$rdep" = "${WANTED:-$PACKAGE}" ] && continue
1186 grep -q ^$rdep$ $blocked $cooklist && continue
1187 echo "Plan to recook $rdep"
1188 echo $rdep >> $cooklist
1189 done
1190 sed "/^$PACKAGE\t/d" -i $lib_db
1191 report end-step
1192 fi
1193 if [ "$libs" ]; then
1194 echo -e "$PACKAGE\t$libs" >> $lib_db
1195 sort -o $lib_db $lib_db
1196 fi
1198 if [ ! "$EXTRAVERSION" ]; then
1199 case "$PACKAGE" in
1200 linux*);;
1201 *) EXTRAVERSION="$(grep '/lib/modules/.*-slitaz/' files.list |\
1202 head -1 | sed 's|/lib/modules/\(.*\)-slitaz/.*|_\1|')";;
1203 esac
1204 fi
1205 rm -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg 2> /dev/null
1206 report step "Creating md5sum of files"
1207 while read file; do
1208 [ -L "fs$file" ] && continue
1209 [ -f "fs$file" ] || continue
1210 md5sum "fs$file" | sed 's/ fs/ /'
1211 done < files.list > md5sum
1212 report end-step
1213 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
1214 2> /dev/null | awk '{ sz=$1 } END { print sz }')
1216 # Build cpio archives. Find, cpio and gzip the fs, finish by
1217 # removing the fs tree.
1218 # Don't log this because compression always outputs error messages.
1219 find fs -print | cpio -o -H newc | case "$PACKAGE-$COMPRESSION" in
1220 tazpkg-lzma) gzip > fs.cpio.gz;;
1221 *-lzma) lzma e fs.cpio.lzma -si;;
1222 *) gzip > fs.cpio.gz;;
1223 esac && rm -rf fs
1224 PACKED_SIZE=$(du -chs fs.cpio.* receipt files.list md5sum \
1225 description.txt 2> /dev/null | awk '{ sz=$1 } END { print sz }')
1226 report step "Updating receipt sizes"
1227 sed -i '/^PACKED_SIZE/d' receipt
1228 sed -i '/^UNPACKED_SIZE/d' receipt
1229 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1230 sed -i "s/^VERSION=$/VERSION=\"$VERSION\"/" receipt
1231 report end-step
1232 if [ "$EXTRAVERSION" ]; then
1233 report step "Updating receipt EXTRAVERSION"
1234 sed -i s/^EXTRAVERSION.*$// receipt
1235 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
1236 fi
1237 prev_VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
1238 remove_previous_package $INCOMING_REPOSITORY
1239 report step "Creating full cpio archive"
1240 find . -print | cpio -o -H newc > $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1242 # Restore package tree in case we want to browse it.
1243 report step "Restoring original package tree"
1244 { zcat fs.cpio.gz 2> /dev/null || unlzma -c fs.cpio.lzma; } | cpio --quiet -id
1245 rm fs.cpio.* && cd ..
1247 # Save receipts if save_wok is enabled.
1248 [ "$save_wok" ] && copy_cooking_stuff $WOK $PACKAGE $INCOMING_REPOSITORY/wok
1250 # Recook of reverse-depends if package was broken.
1251 if grep -q "^$PACKAGE$" $broken; then
1252 report step "Planning a re-try cook of reverse depends"
1253 sed "/^$PACKAGE$/d" -i $broken
1254 for rdep in $(look_for_rdep); do
1255 grep -q "^$rdep$" $broken || continue
1256 grep -q "^$rdep$" $cooklist && continue
1257 echo "Adding $rdep to the cooklist"
1258 echo $rdep >> $cooklist
1259 regen_cooklist=t
1260 done
1261 report end-step
1262 fi
1263 sed "/^$PACKAGE$/d" -i $commit $cooklist
1265 # Log process.
1266 echo "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg (done)" >> $LOG
1267 report close-bloc
1268 echo "Package $PACKAGE ($VERSION$EXTRAVERSION) generated."
1269 echo "Size : `du -sh $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
1270 echo ""
1273 ########################################################################
1274 # This section contains functions used by several other functions
1275 # below.
1276 ########################
1278 # Look for receipt/files.list in wok. If they can't be found, get them
1279 # from package. Accept one argument : absolute path to package.
1280 get_pkg_files()
1282 pkg_files_dir=$tmp/$(basename ${1%.tazpkg})
1283 mkdir -p $pkg_files_dir && \
1284 cd $pkg_files_dir && \
1285 cpio --quiet -idm receipt < $1 && \
1286 cpio --quiet -idm files.list < $1
1289 ########################################################################
1290 # This section contains functions to generate packages databases.
1291 ########################
1294 gen_packages_db()
1296 # pkg_repository can be $PACKAGES_REPOSITORY or $INCOMING_REPOSITORY.
1297 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1298 cd $pkg_repository
1299 report step "Generating packages lists: $pkg_repository"
1300 report open-bloc
1301 report step "Removing old files"
1302 for file in files.list.lzma packages.list packages.txt \
1303 packages.desc packages.equiv packages.md5; do
1304 rm -rf $file
1305 done
1306 touch files.list
1308 packages_db_start
1309 unset RECEIPT
1310 report step "Reading data from all packages"
1311 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1312 get_packages_info
1313 done
1314 report end-step
1315 packages_db_end
1316 report close-bloc
1319 update_packages_db()
1321 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1322 cd $pkg_repository
1323 for file in packages.list packages.equiv packages.md5 packages.desc \
1324 packages.txt; do
1325 if [ ! -f "$file" ]; then
1326 gen_packages_db
1327 return
1328 fi
1329 done
1330 if [ -f files.list.lzma ]; then
1331 lzma d files.list.lzma files.list
1332 else
1333 gen_packages_db
1334 return
1335 fi
1336 report step "Updating packages lists: $pkg_repository"
1337 packages_db_start
1339 # Look for removed/update packages.
1340 touch stamp -r packages.list
1341 for PACKAGE in $(grep ^[0-9,a-z,A-Z] packages.txt); do
1342 pkg="$pkg_repository/$(grep -m1 ^$PACKAGE- packages.list).tazpkg"
1343 if ! [ -f "$pkg" ]; then
1344 erase_package_info
1345 else
1346 if [ "$pkg" -nt "stamp" ]; then
1347 updated_pkg="$updated_pkg
1348 $PACKAGE $pkg"
1349 elif [ ! -f $WOK/$PACKAGE/receipt ] && \
1350 [ "$COMMAND" = check-incoming -o "$pkg_repository" = "$INCOMING_REPOSITORY" ]; then
1351 erase_package_info
1352 echo "Removing $PACKAGE from $pkg_repository."
1353 rm $pkg
1354 [ "$save_wok" ] && rm -rf $pkg_repository/wok/$PACKAGE
1355 if [ "$pkg_repository" = "$INCOMING_REPOSITORY" ]; then
1356 rm -rf $WOK/$PACKAGE
1357 sed "/^$PACKAGE\t/d" -i $wan_db $dep_db $cookorder
1358 sed "/^$PACKAGE$/d" -i $cooklist $commit $blocked $broken
1359 rm -f $LOCAL_REPOSITORY/log/$PACKAGE.html
1360 if [ "$(sed 1!d $cookorder)" != "#PlanSort" ]; then
1361 sed 1i"#PlanSort" -i $cookorder
1362 regen_cooklist=yes
1363 fi
1364 else
1365 echo "$PACKAGE" >> removed
1366 sed -n '1,10p' -i removed
1367 fi
1368 fi
1369 fi
1370 done
1371 rm stamp
1372 echo "$updated_pkg" | sed 1d | while read PACKAGE pkg; do
1373 erase_package_info
1374 get_packages_info
1375 done
1376 unset updated_pkg
1378 # Look for new packages.
1379 for pkg in $pkg_repository/*.tazpkg; do
1380 fgrep -q " ${pkg##*/}" packages.md5 || get_packages_info
1381 done
1382 report end-step
1383 packages_db_end
1386 packages_db_start()
1388 if [ -s packages.txt ]; then
1389 sed -e 's/^# Packages :.*/# Packages : unknown/' \
1390 -e "s/# Date :.*/# Date : $(date +%Y-%m-%d\ \%H:%M:%S)/" \
1391 -i packages.txt
1392 else
1393 echo "# SliTaz GNU/Linux - Packages list
1395 # Packages : unknown
1396 # Date : $(date +%Y-%m-%d\ \%H:%M:%S)
1398 " > packages.txt
1399 fi
1401 # Needed in some cases as tazwok defines RECEIPT at configuration time
1402 # in this particular case it can break the script.
1403 unset RECEIPT
1405 # If $packages_repository is the main one, configure few functions
1406 # to act as they should, without having loop on them (speed-up)
1407 if [ "$pkg_repository" = "$PACKAGES_REPOSITORY" ]; then
1408 erase_package_info_extracmd="erase_package_info_main"
1409 get_packages_info_extracmd="get_packages_info_main"
1410 fi
1413 erase_package_info()
1415 cd $pkg_repository
1416 sed "/^$PACKAGE$/,/^$/d" -i packages.txt
1417 sed "/^$PACKAGE /d" -i packages.desc
1418 sed -e "s/=$PACKAGE /= /" -e "s/ $PACKAGE / /" -e "s/ $PACKAGE$//" \
1419 -e "/=$PACKAGE$/d" -e "s/=[0-9,a-z,A-Z]:$PACKAGE /= /" \
1420 -e "s/ [0-9,a-z,A-Z]:$PACKAGE / /" -e "s/ [0-9,a-z,A-Z]:$PACKAGE$/ /" \
1421 -e "/=[0-9,a-z,A-Z]:$PACKAGE$/d" \
1422 -i packages.equiv
1423 sed "/^$PACKAGE:/d" -i files.list
1424 sed "/^$(basename ${pkg%.tazpkg})$/d" -i packages.list
1425 sed "/ $(basename $pkg)$/d" -i packages.md5
1426 $erase_package_info_extracmd
1429 erase_package_info_main()
1431 for i in wanted.txt depends.txt libraries.txt; do
1432 [ -f $i ] || continue
1433 sed "/^$PACKAGE\t/d" -i $i
1434 done
1437 get_packages_info()
1439 # If there's no taz folder in the wok, extract info from the
1440 # package.
1441 get_pkg_files $pkg
1442 source_receipt
1443 echo "Getting data from $PACKAGE"
1445 cat >> $pkg_repository/packages.txt << _EOT_
1446 $PACKAGE
1447 $VERSION$EXTRAVERSION
1448 $SHORT_DESC
1449 _EOT_
1450 if [ "$PACKED_SIZE" ]; then
1451 cat >> $pkg_repository/packages.txt << _EOT_
1452 $PACKED_SIZE ($UNPACKED_SIZE installed)
1454 _EOT_
1455 else
1456 echo "" >> $pkg_repository/packages.txt
1457 fi
1459 # Packages.desc is used by Tazpkgbox <tree>.
1460 echo "$PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> $pkg_repository/packages.desc
1462 # Packages.equiv is used by tazpkg install to check depends.
1463 for i in $PROVIDE; do
1464 DEST=""
1465 echo $i | fgrep -q : && DEST="${i#*:}:"
1466 if grep -qs ^${i%:*}= $pkg_repository/packages.equiv; then
1467 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" $pkg_repository/packages.equiv
1468 else
1469 echo "${i%:*}=$DEST$PACKAGE" >> $pkg_repository/packages.equiv
1470 fi
1471 done
1473 if [ -f files.list ]; then
1474 { echo "$PACKAGE"; cat files.list; } | awk '
1475 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }' >> $pkg_repository/files.list
1476 fi
1478 cd .. && rm -r "$pkg_files_dir"
1480 cd $pkg_repository
1481 echo $(basename ${pkg%.tazpkg}) >> packages.list
1482 md5sum $(basename $pkg) >> packages.md5
1483 $get_packages_info_extracmd
1486 get_packages_info_main()
1488 [ "$WANTED" ] && echo -e "$PACKAGE\t$WANTED" >> wanted.txt
1489 echo -e "$PACKAGE\t "$DEPENDS" \t "$BUILD_DEPENDS" " >> package.txt
1490 grep -m1 ^$PACKAGE$'\t' $lib_db >> libraries.txt
1493 source_receipt()
1495 unset PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
1496 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
1497 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
1498 src _pkg DESTDIR CONFIG_SITE BRANCH TARBALL stuff wanted_stuff
1499 . ${RECEIPT:-$PWD/receipt}
1502 packages_db_end()
1504 cd $pkg_repository
1505 pkgs=$(wc -l packages.list | sed 's/ .*//')
1506 sed "s/# Packages : .*/# Packages : $pkgs/" -i packages.txt
1508 # If lists were updated it's generally needed to sort them well.
1509 if ! sort -c packages.list 2> /dev/null; then
1510 report step "Sorting packages lists"
1511 files_list="packages.list packages.desc packages.equiv"
1512 [ "${pkg_repository##*/}" = packages ] && \
1513 files_list="$files_list wanted.txt depends.txt libraries.txt"
1514 for file in $files_list; do
1515 [ -f $file ] || continue
1516 sort -o $file $file
1517 done
1518 report end-step
1519 fi
1521 md5sum packages.md5 | cut -f1 -d' ' > ID
1522 [ -s ID ] || echo null > ID
1524 # Dont log this because lzma always output errors.
1525 lzma e files.list files.list.lzma
1526 rm -f files.list
1527 [ -f packages.equiv ] || touch packages.equiv
1530 ########################################################################
1531 # This section contains functions to generate wok database.
1532 ########################
1534 gen_wok_db()
1536 report step "Generating wok database"
1537 report open-bloc
1538 report step "Removing old files"
1539 for file in $wan_db $dep_db $cookorder; do
1540 [ -f $file ] && rm $file
1541 done
1542 report step "Generating wok-wanted.txt"
1543 gen_wan_db
1544 report step "Generating wok-depends.txt"
1545 for PACKAGE in $(cut -f1 -d '|' $PACKAGES_REPOSITORY/packages.desc \
1546 $INCOMING_REPOSITORY/packages.desc | sort -u); do
1547 RECEIPT=$WOK/$PACKAGE/receipt
1548 if [ -s $RECEIPT ]; then
1549 source_receipt
1550 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
1551 fi
1552 done
1553 sort_db
1554 report close-bloc
1557 gen_wan_db()
1559 rm -f $wan_db
1560 for RECEIPT in $(fgrep -l WANTED $WOK/*/receipt); do
1561 WANTED=
1562 source $RECEIPT
1563 [ "$WANTED" ] || continue
1564 echo -e $PACKAGE"\t"$WANTED >> $wan_db
1565 done
1568 update_wan_db()
1570 local PACKAGE=$PACKAGE
1571 wanted_list=$(fgrep WANTED=\"$PACKAGE\" $WOK/*/receipt | cut -f1 -d ':')
1572 grep $'\t'$PACKAGE $wan_db | cut -f 1 | while read wan; do
1573 echo "$wanted_list" | fgrep -q /$wan/receipt && continue
1574 sed "/^$wan\t/d" -i $wan_db
1575 done
1576 for RECEIPT in $wanted_list; do
1577 unset WANTED PACKAGE
1578 source $RECEIPT
1579 [ "$WANTED" ] || continue
1580 sed "/^$PACKAGE\t/d" -i $wan_db
1581 echo -e $PACKAGE"\t"$WANTED >> $wan_db
1582 done
1583 unset wanted_list
1586 update_dep_db()
1588 sed "/^$PACKAGE\t/d" -i $dep_db
1589 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
1592 sort_db()
1594 report step "Generating cookorder.txt"
1595 sed 's/ \t / /' $dep_db | while read PACKAGE BUILD_DEPENDS; do
1596 grep -q ^$PACKAGE$'\t' $wan_db && continue
1598 # Replace each BUILD_DEPENDS with a WANTED package by it's
1599 # WANTED package.
1600 echo -e $PACKAGE"\t $(echo $BUILD_DEPENDS | use_wanted | \
1601 sort -u | sed "/^$PACKAGE$/d" | tr '\n' ' ') "
1602 done > $tmp/db
1603 while [ -s "$tmp/db" ]; do
1604 status=start
1605 for pkg in $(cut -f 1 $tmp/db); do
1606 if ! fgrep -q ' '$pkg' ' $tmp/db; then
1607 echo $pkg >> $tmp/cookorder
1608 sed -e "/^$pkg\t/d" -e "s/ $pkg / /g" -i $tmp/db
1609 status=proceed
1610 fi
1611 done
1612 if [ "$status" = start ]; then
1613 cp -f $tmp/db /tmp/remain-depends.txt
1614 echo "Can't go further because of dependency loop(s). The remaining packages will be commented in the cookorder and will be unbuilt in case of major updates until the problem is solved." >&2
1615 for remaining in $(cut -f 1 $tmp/db); do
1616 echo "$remaining" >> $blocked
1617 done
1618 break
1619 fi
1620 done
1621 [ -s $tmp/cookorder ] || touch $tmp/cookorder
1623 # The toolchain packages are moved in first position.
1624 grep $(for pkg in `scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
1625 --look_for=all --with_args`; do echo " -e ^$pkg$"; done) \
1626 $tmp/cookorder | tac > $cookorder
1627 for pkg in $(cat $cookorder); do
1628 sed "/^$pkg$/d" -i $tmp/cookorder
1629 done
1631 tac $tmp/cookorder >> $cookorder
1632 report end-step
1635 ########################################################################
1636 # SCAN CORE
1637 ########################
1638 # Includes various scan core-functions. It's not intended to be used
1639 # directly : prefer scan wrappers in next section.
1641 look_for_dep()
1643 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2
1646 look_for_bdep()
1648 look_for_all
1651 look_for_all()
1653 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2,3 | sed 's/ / /'
1656 look_for_rdep()
1658 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1
1661 look_for_rbdep()
1663 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1666 # Return WANTED if it exists.
1667 look_for_wanted()
1669 grep -m1 ^$PACKAGE$'\t' $wan_db | cut -f 2
1672 # Return packages which wants PACKAGE.
1673 look_for_rwanted()
1675 grep $'\t'$PACKAGE$ $wan_db | cut -f 1
1678 look_for_dev()
1680 WANTED=$(look_for_wanted)
1681 if [ "$WANTED" ]; then
1682 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1683 fi
1684 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1687 with_dev()
1689 for PACKAGE in $(cat); do
1690 echo $PACKAGE
1691 look_for_dev
1692 done
1695 with_wanted()
1697 for PACKAGE in $(cat); do
1698 echo $PACKAGE
1699 look_for_wanted
1700 done
1703 use_wanted()
1705 for input in $(cat); do
1706 { grep ^$input$'\t' $wan_db || echo $input
1708 done | sed 's/.*\t//'
1711 check_for_pkg_in_wok()
1713 [ -f $WOK/$PACKAGE/receipt ] && return
1714 echo "Can't find $PACKAGE in wok or mirror" >&2
1715 return 2
1718 # Define how theses functions should act when using --undigest.
1719 use_undigest_scan_core()
1721 look_for_dep()
1723 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1724 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2
1725 else
1726 grep -m1 ^$PACKAGE$'\t' $ref_dep_db | cut -f 2
1727 fi
1730 look_for_all()
1732 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1733 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2,3 | sed 's/ / /'
1734 else
1735 grep -m1 ^$PACKAGE$'\t' $ref_dep_db | cut -f 2,3 | sed 's/ / /'
1736 fi
1739 look_for_rdep()
1741 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1
1742 for rdep in $(fgrep ' '$PACKAGE' ' $ref_dep_db | cut -f 1); do
1743 [ -f "WOK$/$rdep/receipt" ] || echo "$rdep"
1744 done
1747 look_for_rbdep()
1749 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1750 for rdep in $(fgrep ' '$PACKAGE' ' $ref_dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1); do
1751 [ -f "WOK$/$rdep/receipt" ] || echo "$rdep"
1752 done
1755 look_for_wanted()
1757 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1758 grep -m1 ^$PACKAGE$'\t' $wan_db | cut -f 2
1759 else
1760 grep -m1 ^$PACKAGE$'\t' $ref_wan_db | cut -f 2
1761 fi
1764 look_for_rwanted()
1766 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1767 grep $'\t'$PACKAGE$ $wan_db | cut -f 1
1768 else
1769 grep $'\t'$PACKAGE$ $ref_wan_db | cut -f 1
1770 fi
1773 look_for_dev()
1775 WANTED=$(look_for_wanted)
1776 if [ "$WANTED" ]; then
1777 if [ -f "$WOK/$WANTED/receipt" ]; then
1778 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1779 else
1780 grep -q ^$WANTED-dev$'\t' $ref_dep_db && echo $WANTED-dev
1781 fi
1782 fi
1783 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1784 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1785 else
1786 grep -q ^$PACKAGE-dev$'\t' $ref_dep_db && echo $PACKAGE-dev
1787 fi
1790 check_for_pkg_in_wok()
1792 [ -f $WOK/$PACKAGE/receipt ] && return
1793 grep -q ^$PACKAGE'$\t' $ref_dep_db && return 1
1794 echo "Can't find $PACKAGE in wok or mirror" >&2
1795 return 2
1799 ########################################################################
1800 # SCAN
1801 ########################
1802 # Use wok-wanted.txt and wok-depeds.txt to scan depends.
1803 # Option in command line (must be first arg) :
1804 # --look_for=bdep/rbdep - Look for depends or reverse depends.
1805 # --with_dev - Add development packages (*-dev) in the result.
1806 # --with_wanted - Add package+reverse wanted in the result.
1807 # --with_args - Include packages in argument in the result.
1809 scan()
1811 # Get packages in argument.
1812 local PACKAGE=$PACKAGE WANTED=$WANTED pkg_list=
1813 for arg in $@; do
1814 [ "$arg" = "${arg#--}" ] || continue
1815 pkg_list="$pkg_list $arg"
1816 done
1818 # Get options.
1819 [ "$pkg_list" ] || return
1820 local cooklist= look_for= with_dev= with_wanted= with_args= log_command="$0 $@" \
1821 get_options_list="look_for with_dev with_wanted with_args cooklist use_wanted"
1822 get_options
1824 # Get db md5 to be able to check for changes latter.
1825 db_md5=$(md5sum $dep_db $wan_db)
1827 # Cooklist is a special case where we need to modify a little
1828 # scan behavior
1829 if [ "$cooklist" ]; then
1830 gen_wan_db
1831 look_for=all && with_args=yes && with_dev= && with_wanted=
1832 filter=use_wanted
1833 if [ "$COMMAND" = gen-cooklist ]; then
1834 for PACKAGE in $pkg_list; do
1835 grep -q ^$PACKAGE$'\t' $dep_db && continue
1836 [ -d "$WOK/$p" ] || continue
1837 check_for_missing
1838 done
1839 append_to_dep()
1841 if grep -q ^$PACKAGE$'\t' $dep_db; then
1842 echo $PACKAGE >> $tmp/dep
1843 else
1844 check_for_missing && echo $PACKAGE >> $tmp/dep
1845 fi
1847 else
1848 append_to_dep()
1850 check_for_commit && echo $PACKAGE >> $tmp/dep
1852 fi
1853 else
1854 append_to_dep()
1856 echo $PACKAGE >> $tmp/dep
1858 # If requested packages are not in dep_db, partial generation of this db is needed.
1859 for PACKAGE in $pkg_list; do
1860 grep -q ^$PACKAGE$'\t' $dep_db && continue
1861 [ -d "$WOK/$p" ] || continue
1862 plan_check_for_missing=yes
1863 check_for_missing
1864 done
1865 if [ "$plan_check_for_missing" ]; then
1866 append_to_dep()
1868 if grep -q ^$PACKAGE$'\t' $dep_db; then
1869 echo $PACKAGE >> $tmp/dep
1870 else
1871 check_for_missing && echo $PACKAGE >> $tmp/dep
1872 fi
1874 unset plan_check_for_missing
1875 fi
1876 fi
1878 [ "$with_dev" ] && filter=with_dev
1879 [ "$with_wanted" ] && filter=with_wanted
1880 if [ "$filter" ]; then
1881 pkg_list=$(echo $pkg_list | $filter | sort -u)
1882 scan_pkg()
1884 look_for_$look_for | $filter
1886 else
1887 scan_pkg()
1889 look_for_$look_for
1891 fi
1892 touch $tmp/dep
1893 for PACKAGE in $pkg_list; do
1894 [ "$with_args" ] && append_to_dep
1895 scan_pkg
1896 done | tr ' ' '\n' | sort -u > $tmp/list
1897 [ "$look_for" = bdep ] && look_for=dep
1898 while [ -s $tmp/list ]; do
1899 PACKAGE=$(sed 1!d $tmp/list)
1900 sed 1d -i $tmp/list
1901 append_to_dep
1902 for pkg in $(scan_pkg); do
1903 grep -q ^$pkg$ $tmp/list $tmp/dep || echo $pkg >> $tmp/list
1904 done
1905 done
1906 if [ "$cooklist" ]; then
1907 mv $tmp/dep $tmp/cooklist
1908 else
1909 cat $tmp/dep | sort -u
1910 fi
1911 rm -f $tmp/dep $tmp/list
1912 if [ "$db_md5" != "$(md5sum $dep_db $wan_db)" ]; then
1913 sort -o $dep_db $dep_db
1914 sort -o $wan_db $wan_db
1915 grep -q "^#" $cookorder || sed 1i"#PlanSort" -i $cookorder
1916 fi
1919 ########################################################################
1920 # This section contains functions to check the package repository and
1921 # find which packages to cook.
1922 ########################
1924 check_for_missing()
1926 local PACKAGE=$PACKAGE
1927 if ! check_for_pkg_in_wok; then
1928 [ "$?" = 2 ] && return 1
1929 return
1930 fi
1931 RECEIPT=$WOK/$PACKAGE/receipt
1932 source_receipt
1933 PACKAGE=${WANTED:-$PACKAGE}
1934 update_wan_db
1935 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1936 RECEIPT=$WOK/$PACKAGE/receipt
1937 source_receipt
1938 update_dep_db
1939 done
1942 check_for_commit()
1944 if ! check_for_pkg_in_wok; then
1945 [ "$?" = 2 ] && return 1
1946 return
1947 fi
1948 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1949 RECEIPT=$WOK/$PACKAGE/receipt
1950 source_receipt
1952 # We use md5 of cooking stuff in the packaged receipt to check
1953 # commit. We look consecutively in 3 different locations :
1954 # - in the wok/PACKAGE/taz/* folder
1955 # - in the receipt in the package in incoming repository
1956 # - in the receipt in the package in packages repository
1957 # If md5sums match, there's no commit.
1958 check_for_commit_using_md5sum()
1960 if [ ! -f $WOK/$PACKAGE/md5 ]; then
1961 sed -n '/# md5sum of cooking stuff :/,$p' receipt | \
1962 sed -e 1d -e 's/^# //' > $WOK/$PACKAGE/md5
1963 cd $WOK/$PACKAGE
1964 fi
1966 if [ -s md5 ]; then
1967 if md5sum -cs md5; then
1969 # If md5sum check if ok, check for new/missing files in
1970 # cooking stuff.
1971 for file in $([ -f receipt ] && echo receipt; \
1972 [ -f description.txt ] && echo description.txt; \
1973 [ -d stuff ] && find stuff); do
1974 if ! fgrep -q " $file" md5; then
1975 set_commited
1976 fi
1977 done
1978 else
1979 set_commited
1980 fi
1981 else
1982 set_commited
1983 fi
1985 set_commited()
1987 grep -q ^$PACKAGE$ $commit || echo $PACKAGE >> $commit
1988 gen_cookmd5
1989 update_dep_db
1991 taz_dir=$(echo $WOK/$PACKAGE/taz/$PACKAGE-* | fgrep -v '*')
1992 if [ -f $WOK/$PACKAGE/md5 ]; then
1993 cd $WOK/$PACKAGE
1994 check_for_commit_using_md5sum
1995 elif [ "$taz_dir" ]; then
1996 cd $taz_dir
1997 check_for_commit_using_md5sum
1998 else
1999 pkg=$(echo $INCOMING_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
2000 [ "$pkg" ] || pkg=$(echo $PACKAGES_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
2001 if [ "$pkg" ]; then
2002 get_pkg_files $pkg
2003 check_for_commit_using_md5sum
2004 rm -r $pkg_files_dir
2005 else
2006 set_commited
2007 fi
2008 fi
2009 [ "$forced" ] || echo $PACKAGE >> $tmp/checked
2010 done
2011 return
2014 gen_cook_list()
2016 report step "Scanning wok"
2017 if [ "$pkg" ]; then
2018 scan $pkg --cooklist
2019 elif [ "$LIST" ]; then
2020 scan `cat $LIST` --cooklist
2021 else
2022 scan `cat $cooklist` --cooklist
2023 fi
2024 report end-step
2026 [ -s $tmp/checked ] || [ -s $tmp/cooklist ] || return
2028 # Core toolchain should not be cooked unless cook-toolchain is used.
2029 if ! [ -f /etc/config.site.tmptoolchain ] ; then
2030 for PACKAGE in $(scan gcc --look_for=all --with_args --with_wanted); do
2031 grep -q ^$PACKAGE$ $blocked || echo $PACKAGE >> $blocked
2032 done
2033 fi
2035 if [ -s $commit ] && [ "$COMMAND" != gen-cooklist ]; then
2036 for PACKAGE in $(cat $commit); do
2037 WANTED="$(look_for_wanted)"
2038 if [ "$WANTED" ]; then
2039 grep -q ^$WANTED$ $broken $cooklist $blocked $commit && continue
2040 fi
2041 grep -q ^$PACKAGE$ $blocked $cooklist && continue
2042 echo $PACKAGE >> $cooklist
2043 done
2044 fi
2045 sort_cooklist
2048 sort_cooklist()
2050 if [ "$(sed 1!d $cookorder)" = "#PlanSort" ]; then
2051 sed 1d -i $cookorder
2052 sort_db
2053 fi
2054 report step "Generating cooklist"
2055 if [ -f "$tmp/checked" ]; then
2056 rm -f $tmp/cooklist
2057 cat $tmp/checked | while read PACKAGE; do
2058 grep -q ^$PACKAGE$ $cooklist && echo $PACKAGE >> $tmp/cooklist
2059 done
2060 elif ! [ "$COMMAND" = gen-cooklist ]; then
2061 cat $blocked | while read PACKAGE; do
2062 sed "/^$PACKAGE/d" -i $tmp/cooklist
2063 done
2064 fi
2065 report end-step
2066 [ -s $tmp/cooklist ] || return
2068 report step "Sorting cooklist"
2069 for PACKAGE in $(cat $tmp/cooklist); do
2070 WANTED="$(look_for_wanted)"
2071 [ "$WANTED" ] || continue
2072 if grep -q ^$WANTED$ $broken $tmp/cooklist; then
2073 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2074 elif [ ! -d $WOK/$WANTED/install ]; then
2075 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2076 echo $WANTED >> $tmp/cooklist
2077 fi
2078 done
2080 # Use cookorder.txt to sort cooklist.
2081 if [ -s $tmp/cooklist ]; then
2082 cat $cookorder | while read PACKAGE; do
2083 if grep -q ^$PACKAGE$ $tmp/cooklist; then
2084 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2085 echo $PACKAGE >> $tmp/cooklist.tmp
2086 fi
2087 done
2089 # Remaining packages in cooklist are those without compile_rules.
2090 # They can be cooked first in any order.
2091 if [ -f $tmp/cooklist.tmp ]; then
2092 cat $tmp/cooklist.tmp >> $tmp/cooklist
2093 rm $tmp/cooklist.tmp
2094 fi
2096 cat $tmp/cooklist
2097 [ "$LIST" ] || cat $tmp/cooklist > $cooklist
2098 fi
2100 report end-step
2103 look_for_missing_pkg()
2105 for pkg in $(cat $PACKAGES_REPOSITORY/$1); do
2106 grep -q ^$pkg$ $INCOMING_REPOSITORY/packages.txt \
2107 $PACKAGES_REPOSITORY/packages.txt || \
2108 continue
2109 echo $pkg
2110 done
2113 check_for_incoming()
2115 report step "Checking that all packages were cooked OK"
2116 [ -s $INCOMING_REPOSITORY/packages.desc ] || {
2117 echo "No packages in $INCOMING_REPOSITORY."
2118 report end-step; return; }
2119 if [ -s $broken ]; then
2120 missingpkg=$(look_for_missing_pkg broken)
2121 if [ "$missingpkg" ]; then
2122 echo "Don't move incoming packages to main repository because these ones are broken:" >&2
2123 echo "$missingpkg"
2124 report end-step
2125 return 1
2126 fi
2127 fi
2128 if [ -s $cooklist ]; then
2129 missingpkg=$(look_for_missing_pkg cooklist)
2130 if [ "$missingpkg" ]; then
2131 echo "Don't move incoming packages to main repository because these ones need to be cooked:" >&2
2132 echo "$missingpkg"
2133 report end-step
2134 return 1
2135 fi
2136 fi
2137 incoming_pkgs="$(cut -f 1 -d '|' $INCOMING_REPOSITORY/packages.desc)"
2138 if ! [ "$forced" ]; then
2139 cooklist=$PACKAGES_REPOSITORY/cooklist
2140 pkg="$incoming_pkgs"
2141 gen_cook_list
2142 if [ -s $cooklist ]; then
2143 missingpkg=$(look_for_missing_pkg cooklist)
2144 if [ "$missingpkg" ]; then
2145 echo "Don't move incoming packages to main repository because these ones need to be cooked:" >&2
2146 echo "$missingpkg"
2147 report end-step
2148 return 1
2149 fi
2150 fi
2151 fi
2153 report step "Moving incoming packages to main repository"
2154 [ "save_wok" ] && mkdir -p $PACKAGES_REPOSITORY/wok
2155 unset EXTRAVERSION
2156 for PACKAGE in $incoming_pkgs; do
2157 prev_VERSION=$(get_pkg_version $PACKAGES_REPOSITORY)
2158 VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
2159 remove_previous_package $PACKAGES_REPOSITORY
2160 echo "Moving $PACKAGE..."
2161 mv -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION.tazpkg $PACKAGES_REPOSITORY
2162 touch $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
2163 previous_tarball=$(grep -m1 ^$PACKAGE:main $SOURCES_REPOSITORY/sources.list | cut -f2)
2164 sed -e "/^$PACKAGE:main/d" \
2165 -e "s/^$PACKAGE:incoming/$PACKAGE:main/" \
2166 -i $SOURCES_REPOSITORY/sources.list
2167 if [ "$previous_tarball" ]; then
2168 grep -q $'\t'$previous_tarball$ $SOURCES_REPOSITORY/sources.list || \
2169 rm -f $SOURCES_REPOSITORY/$previous_tarball
2170 fi
2171 [ "$save_wok" ] &&
2172 copy_cooking_stuff $INCOMING_REPOSITORY/wok $PACKAGE $PACKAGES_REPOSITORY/wok &&
2173 rm -r $INCOMING_REPOSITORY/wok/$PACKAGE
2174 done
2176 if [ "$save_wok" = tarball ]; then
2177 rm -f $PACKAGES_REPOSITORY/wok.tar.lzma
2178 cd $PACKAGES_REPOSITORY/wok
2179 report step "Generating safe-wok tarball"
2180 tar -c * | lzma e $PACKAGES_REPOSITORY/wok.tar.lzma
2181 report end-step
2182 fi
2184 for file in packages.list packages.equiv packages.md5 packages.desc \
2185 packages.txt; do
2186 echo -n "" > $INCOMING_REPOSITORY/$file
2187 done
2188 rm -r $INCOMING_REPOSITORY/files.list.lzma
2189 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2191 report step "Updating flavors"
2192 if [ -x /usr/bin/tazlito ] || [ -x /usr/bin/clean-chroot ]; then
2193 if ! [ -x /usr/bin/tazlito ]; then
2194 tazpkg get-install tazlito
2195 fi
2197 # Handle cases where tazwok is used into main system;
2198 # Handle cases where SLITAZ_DIR is not /home/slitaz.
2199 [ -L /home/slitaz/flavors ] && rm /home/slitaz/flavors
2200 mkdir -p /home/slitaz
2201 ln -s $LOCAL_REPOSITORY/flavors /home/slitaz/flavors
2203 cd $LOCAL_REPOSITORY/packages
2204 for i in $LOCAL_REPOSITORY/flavors/*; do
2205 [ -d "$i" ] || continue
2206 tazlito pack-flavor ${i##*/}
2207 done
2209 noheader=""
2210 for i in *.flavor; do
2211 tazlito show-flavor $i --brief $noheader
2212 noheader="--noheader"
2213 done > flavors.list
2214 [ -x /usr/bin/clean-chroot ] && clean-chroot
2215 else
2216 echo "Can't create up-to-date flavors because the tazlito package is missing." >&2
2217 fi
2218 report end-step
2221 # Usage: move_cooking_stuff source receipt destination
2222 # Make the argument check before calling it!
2223 copy_cooking_stuff()
2225 rm -rf $3/$2
2226 mkdir -p $3/$2
2227 cp -a $1/$2/receipt $3/$2
2228 [ -f $1/$2/description.txt ] && \
2229 cp -a $1/$2/description.txt $3/$2
2230 if [ -d "$1/$2/stuff" ]; then
2231 cp -a $1/$2/stuff $3/$2
2232 fi
2235 ########################################################################
2236 # TAZWOK MAIN FUNCTIONS
2237 ########################
2239 clean()
2241 cd $WOK/$PACKAGE
2242 ls -A $WOK/$PACKAGE | grep -q -v -e ^receipt$ -e ^description.txt$ \
2243 -e ^stuff$ || return
2245 [ "$COMMAND" = clean-wok ] || report step "Cleaning $PACKAGE"
2246 # Check for clean_wok function.
2247 if grep -q ^clean_wok $RECEIPT; then
2248 clean_wok
2249 fi
2250 # Clean should only have a receipt, stuff and optionals desc/md5.
2251 for f in `ls .`
2252 do
2253 case $f in
2254 receipt|stuff|description.txt|md5)
2255 continue ;;
2256 *)
2257 rm -rf $f ;;
2258 esac
2259 done
2260 [ "$COMMAND" != clean-wok ] && report end-step
2263 # Configure and make a package with the receipt.
2264 compile_package()
2266 check_for_package_on_cmdline
2268 # Include the receipt to get all needed variables and functions
2269 # and cd into the work directory to start the work.
2270 check_for_receipt
2271 source_receipt
2273 # Log the package name and date.
2274 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
2275 echo "package $PACKAGE (compile)" >> $LOG
2277 # Set wanted $src variable to help compiling.
2278 [ ! "$src" ] && set_src_path
2279 check_for_build_depends || return 1
2280 check_for_wanted
2281 unset target
2282 check_for_tarball && check_for_compile_rules
2285 # Cook command also include all features to manage lists which keep
2286 # track of wok/packages state.
2287 cook()
2289 cook_code=
2290 set_common_path
2291 check_for_receipt
2292 source_receipt
2294 # Define log path and start report.
2295 for i in $(look_for_rwanted) $PACKAGE; do
2296 rm -f $LOCAL_REPOSITORY/log/$i.html
2297 done
2298 report sublog $LOCAL_REPOSITORY/log/$PACKAGE.html
2299 echo "$PACKAGE" > $LOCAL_REPOSITORY/log/package
2300 report step "Cooking $PACKAGE"
2301 report open-bloc
2303 clean $PACKAGE
2304 [ -s $tmp/cooklist ] && sed "/^$PACKAGE$/d" -i $tmp/cooklist
2306 if compile_package; then
2307 remove_src
2308 refresh_packages_from_compile
2309 gen_package
2311 # Update packages-incoming repository.
2312 store_pkgname=$PACKAGE
2313 pkg_repository=$INCOMING_REPOSITORY
2314 update_packages_db
2316 PACKAGE=$store_pkgname
2317 unset store_pkgname
2319 # Upgrade to cooked packages if it was previously installed.
2320 report step "Looking for package(s) to upgrade"
2321 for pkg in $(look_for_rwanted) $PACKAGE; do
2322 if [ -f $INSTALLED/$pkg/receipt ]; then
2323 tazpkg get-install $pkg --forced
2324 fi
2325 done
2326 report end-step
2327 else
2328 set_pkg_broken
2329 cook_code=1
2330 fi
2332 # Remove build_depends in cook mode (if in cooklist, it's done when
2333 # checking build_depends of next package and we remove only unneeded
2334 # packages to keep chroot minimal and gain some time).
2335 if [ "$COMMAND" = cook ]; then
2336 remove_build_depends $MISSING_PACKAGE
2337 [ -x /usr/bin/clean-chroot ] && clean-chroot
2338 fi
2340 # Regen the cooklist if it was planned and command is not cook.
2341 [ "$regen_cooklist" ] && unset regen_cooklist &&
2342 [ "$COMMAND" != cook ] && sort_cooklist
2344 # Some hacks to set the bloc & function status as failed if cook has
2345 # failed.
2346 report_return_code=$cook_code
2347 report close-bloc
2348 report end-sublog
2349 rm -f $LOCAL_REPOSITORY/log/package
2350 return $cook_code
2353 cook_list()
2355 if [ -s $tmp/cooklist ]; then
2356 if [ -f /usr/bin/tazchroot ]; then
2357 # Note : options -main variables- are automatically kept by
2358 # the sub-applications tazchroot/tazwok; as well as report data.
2359 cd $LOCAL_REPOSITORY
2360 [ ! -f tazchroot.conf ] && configure_tazchroot
2361 tazchroot tazwok cook-list --SLITAZ_DIR=$SLITAZ_DIR --SLITAZ_VERSION=$SLITAZ_VERSION ${undigest:+ --undigest=$undigest}
2362 return
2363 fi
2364 while [ -s $tmp/cooklist ]; do
2365 PACKAGE=$(sed 1!d $tmp/cooklist)
2366 cook
2367 done
2368 remove_build_depends $MISSING_PACKAGE $remove_later
2369 [ -x /usr/bin/clean-chroot ] && clean-chroot
2370 else
2371 echo "Nothing to cook."
2372 return
2373 fi
2376 configure_tazchroot()
2378 cat > $LOCAL_REPOSITORY/tazchroot.conf << EOF
2379 # Tazchroot configuration file - created by tazwok.
2381 # Local repository definition.
2382 SLITAZ_DIR=$SLITAZ_DIR
2383 SLITAZ_VERSION=$SLITAZ_VERSION
2384 LOCAL_REPOSITORY=$SLITAZ_DIR/${undigest:-$SLITAZ_VERSION}
2385 ${USE_ONLINE_PKG:+USE_ONLINE_PKG=$USE_ONLINE_PKG}
2386 ${undigest:+undigest=$undigest}
2387 ${ref_USE_ONLINE_PKG:+ref_USE_ONLINE_PKG=$ref_USE_ONLINE_PKG}
2389 # Chroot path.
2390 # You can use a chroot into /tmp if it's mounted in RAM
2391 # to speed-up the process, be sure you have a free GB.
2392 # (minimal chroot is like 150~200MB, can be a lot more during cook)
2393 # chroot_dir=/tmp/chroot-${undigest:-$SLITAZ_VERSION}
2394 chroot_dir=\$LOCAL_REPOSITORY/chroot
2396 # Default scripts path (these scripts are added to the
2397 # $chroot_dir/usr/bin and can be called with tazchroot script).
2398 script_dir=/usr/lib/slitaz/chroot-scripts/tazwok
2400 # List of directories to mount.
2401 list_dir="$LOCAL_REPOSITORY
2402 $SLITAZ_LOG$( [ "$undigest" ] && echo -e "\n$SLITAZ_DIR/$SLITAZ_VERSION/packages" )"
2404 create_chroot()
2406 mkdir -p \$chroot_dir
2407 for pkg in \$(tazwok build-depends toolchain --SLITAZ_DIR=\$SLITAZ_DIR --SLITAZ_VERSION=\$SLITAZ_VERSION${undigest:+ --undigest=\$undigest}); do
2408 tazpkg get-install \$pkg --root="\$chroot_dir"
2409 done
2411 # Store list of installed packages needed by cleanchroot.
2412 ls -1 \$chroot_dir/\$INSTALLED > \$chroot_dir/\$LOCALSTATE/chroot-pkgs
2414 sed -e "s~^SLITAZ_DIR=.*~SLITAZ_DIR=\$SLITAZ_DIR~" \\
2415 -e "s/^SLITAZ_VERSION=.*/SLITAZ_VERSION=\$SLITAZ_VERSION/" \\
2416 -i \$chroot_dir/etc/slitaz/slitaz.conf
2417 echo \$SLITAZ_VERSION > \$chroot_dir/etc/slitaz-release
2418 $( [ "$undigest" ] && echo ' echo "undigest='"$undigest"'" >> $chroot_dir/etc/slitaz/tazwok.conf')
2419 sed 's/LC_ALL/LC_ALL=POSIX/' -i \$chroot_dir/etc/profile
2421 # The build bot may run in a sandbox: link sandbox lockfile.
2422 ln -s \$LOCAL_REPOSITORY/sandbox/proc/1 \$chroot_dir/proc/1
2425 mount_chroot()
2427 cp -a /etc/resolv.conf \$chroot_dir/etc/resolv.conf
2428 $( if [ "$USE_ONLINE_PKG" ]; then
2429 echo ' echo "$USE_ONLINE_PKG" > $chroot_dir$LOCALSTATE/mirror'
2430 else
2431 echo ' echo "$LOCAL_REPOSITORY/packages" > $chroot_dir$LOCALSTATE/mirror'
2432 fi
2434 mkdir -p \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming
2435 echo "\$LOCAL_REPOSITORY/packages-incoming" > \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming/mirror
2436 $( if [ "$undigest" ]; then
2437 echo ' mkdir -p $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION'
2438 if [ "$ref_USE_ONLINE_PKG" ]; then
2439 echo ' echo "$ref_USE_ONLINE_PKG" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror'
2440 else
2441 echo ' echo "$ref_LOCAL_REPOSITORY/packages" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror'
2442 fi
2443 fi )
2444 echo -e "\${LOCAL_REPOSITORY##*/}-incoming\nmain" > \$chroot_dir\$LOCALSTATE/priority
2445 mount -o bind /proc \$chroot_dir/proc
2446 mount -o bind /sys \$chroot_dir/sys
2447 mount -o bind /dev/pts \$chroot_dir/dev/pts
2448 mount -o bind /dev/shm \$chroot_dir/dev/shm
2449 for dir in \$list_dir; do
2450 mkdir -p \$dir \$chroot_dir\$dir
2451 mount \$dir \$chroot_dir\$dir
2452 done
2455 umount_chroot()
2457 for dir in \$list_dir; do
2458 umount \$chroot_dir\$dir
2459 done
2460 umount \$chroot_dir/dev/shm
2461 umount \$chroot_dir/dev/pts
2462 umount \$chroot_dir/sys
2463 umount \$chroot_dir/proc
2465 EOF
2468 ########################################################################
2469 ######################### END OF NEW FUNCTIONS #########################
2470 ########################################################################
2472 # List packages providing a virtual package.
2473 whoprovide()
2475 local i;
2476 for i in $(fgrep -l PROVIDE $WOK/*/receipt); do
2477 . $i
2478 case " $PROVIDE " in
2479 *\ $1\ *|*\ $1:*) echo $(basename $(dirname $i));;
2480 esac
2481 done
2484 ########################################################################
2485 # TAZWOK COMMANDS
2486 ########################
2488 case "$COMMAND" in
2489 stats)
2490 # Tazwok general statistics from the wok config file.
2492 get_tazwok_config
2493 echo -e "\n\033[1mTazwok configuration statistics\033[0m
2494 ================================================================================
2495 Wok directory : $WOK
2496 Packages repository : $PACKAGES_REPOSITORY
2497 Incoming repository : $INCOMING_REPOSITORY
2498 Sources repository : $SOURCES_REPOSITORY
2499 Log directory : $LOCAL_REPOSITORY/log
2500 Packages in the wok : `ls -1 $WOK | wc -l`
2501 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2502 Incoming packages : `ls -1 $INCOMING_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2503 ================================================================================\n"
2504 ;;
2505 edit)
2506 get_tazwok_config
2507 check_for_package_on_cmdline
2508 check_for_receipt
2509 $EDITOR $WOK/$PACKAGE/receipt
2510 ;;
2511 build-depends)
2512 # List dependencies to rebuild wok, or only a package.
2513 get_tazwok_config
2514 report(){ : ; }
2515 if [ ! "$PACKAGE" ] || [ "$PACKAGE" = toolchain ]; then
2516 scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
2517 --look_for=dep --with_dev --with_args
2518 else
2519 check_for_package_on_cmdline
2520 scan $PACKAGE --look_for=bdep --with_dev
2521 fi
2522 ;;
2523 gen-cooklist)
2524 check_root
2525 get_options_list="pkg"
2526 get_tazwok_config
2527 report(){ : ; }
2528 if ! [ "$pkg" ]; then
2529 if [ ! "$LIST" ] || [ "$LIST" = toolchain ]; then
2530 pkg="$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA"
2531 else
2532 check_for_list
2533 fi
2534 fi
2535 gen_cook_list
2536 ;;
2537 check-depends)
2538 # Check package depends /!\.
2539 get_tazwok_config
2540 echo ""
2541 echo -e "\033[1mCheck every receipt for DEPENDS - doesn't scan ELF files\033[0m
2542 ================================================================================"
2543 TMPDIR=/tmp/tazwok$$
2544 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
2546 # Build ALL_DEPENDS variable.
2547 scan_dep()
2549 local i
2550 ALL_DEPENDS="$ALL_DEPENDS$PACKAGE "
2551 for i in $DEPENDS $SUGGESTED ; do
2552 case " $ALL_DEPENDS " in
2553 *\ $i\ *) continue;;
2554 esac
2555 [ -d $WOK/$i ] || {
2556 ALL_DEPENDS="$ALL_DEPENDS$i "
2557 continue
2559 DEPENDS=""
2560 SUGGESTED=""
2561 . $WOK/$i/receipt
2562 scan_dep
2563 done
2566 # Check for ELF file.
2567 is_elf()
2569 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
2572 # Print shared library dependencies.
2573 ldd()
2575 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
2578 mkdir $TMPDIR
2579 cd $TMPDIR
2580 for i in $LOCALSTATE/files.list.lzma \
2581 $LOCALSTATE/undigest/*/files.list.lzma ; do
2582 [ -f $i ] && lzma d $i -so >> files.list
2583 done
2584 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
2585 tazpkg extract $pkg > /dev/null 2>&1
2586 . */receipt
2587 ALL_DEPENDS="$DEFAULT_DEPENDS "
2588 scan_dep
2589 find */fs -type f | while read file ; do
2590 is_elf $file || continue
2591 case "$file" in
2592 *.o|*.ko|*.ko.gz) continue;;
2593 esac
2594 ldd $file | while read lib rem; do
2595 case "$lib" in
2596 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
2597 continue;;
2598 esac
2599 for dep in $(fgrep $lib files.list | cut -d: -f1); do
2600 case " $ALL_DEPENDS " in
2601 *\ $dep\ *) continue 2;;
2602 esac
2603 for vdep in $(fgrep $dep $LOCALSTATE/packages.equiv | cut -d= -f1); do
2604 case " $ALL_DEPENDS " in
2605 *\ $vdep\ *) continue 3;;
2606 esac
2607 done
2608 done
2609 [ -n "$dep" ] || dep="UNKNOWN"
2610 echo "$(basename $pkg): ${file#*fs} depends on package $dep for the shared library $lib"
2611 done
2612 done
2613 rm -rf */
2614 done
2615 cd /tmp
2616 rm -rf $TMPDIR
2617 ;;
2618 check)
2619 # Check wok consistency.
2620 get_tazwok_config
2621 echo ""
2622 echo -e "\033[1mWok and packages checking\033[0m
2623 ================================================================================"
2624 cd $WOK
2625 for pkg in $(ls)
2626 do
2627 [ -f $pkg/receipt ] || continue
2628 RECEIPT= $pkg/receipt
2629 source_receipt
2630 [ "$PACKAGE" = "$pkg" ] || echo "Package $PACKAGE should be $pkg" >&2
2631 [ -n "$VERSION" ] || echo "Package $PACKAGE has no VERSION" >&2
2632 [ -n "$PACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded PACKED_SIZE" >&2
2633 [ -n "$UNPACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded UNPACKED_SIZE" >&2
2634 [ -n "$EXTRAVERSION" ] && echo "Package $PACKAGE has hardcoded EXTRAVERSION" >&2
2635 if [ -n "$WANTED" ]; then
2636 if [ ! -f $WANTED/receipt ]; then
2637 echo "Package $PACKAGE wants unknown $WANTED package" >&2
2638 else
2639 BASEVERSION=$(. $WANTED/receipt ; echo $VERSION)
2640 if [ "$VERSION" = "$WANTED" ]; then
2641 # BASEVERSION is computed in receipt
2642 fgrep -q '_pkg=' $pkg/receipt &&
2643 BASEVERSION=$VERSION
2644 fi
2645 if [ "$VERSION" != "$BASEVERSION" ]; then
2646 echo "Package $PACKAGE ($VERSION) wants $WANTED ($BASEVERSION)" >&2
2647 fi
2648 fi
2649 fi
2651 if [ -n "$CATEGORY" ]; then
2652 case " $(echo $CATEGORIES) " in
2653 *\ $CATEGORY\ *);;
2654 *) echo "Package $PACKAGE has an invalid CATEGORY" >&2;;
2655 esac
2656 else
2657 echo"Package $PACKAGE has no CATEGORY" >&2
2658 fi
2659 [ -n "$SHORT_DESC" ] || echo "Package $PACKAGE has no SHORT_DESC" >&2
2660 [ -n "$MAINTAINER" ] || echo "Package $PACKAGE has no MAINTAINER" >&2
2661 case "$WGET_URL" in
2662 ftp*|http*) busybox wget -s $WGET_URL 2> /dev/null ||
2663 echo "Package $PACKAGE has a wrong WGET_URL" >&2;;
2664 '') ;;
2665 *) echo "Package $PACKAGE has an invalid WGET_URL" >&2;;
2666 esac
2667 case "$WEB_SITE" in
2668 ftp*|http*);;
2669 '') echo "Package $PACKAGE has no WEB_SITE" >&2;;
2670 *) echo "Package $PACKAGE has an invalid WEB_SITE" >&2;;
2671 esac
2672 case "$MAINTAINER" in
2673 *\<*|*\>*) echo "Package $PACKAGE has an invalid MAINTAINER: $MAINTAINER" >&2;;
2674 esac
2675 case "$MAINTAINER" in
2676 *@*);;
2677 *) echo "Package $PACKAGE MAINTAINER is not an email address" >&2;;
2678 esac
2679 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2680 for i in $DEPENDS; do
2681 [ -d $i ] && continue
2682 [ -n "$(whoprovide $i)" ] && continue
2683 echo -e "$MSG $i"
2684 MSG=""
2685 done
2686 MSG="Missing build dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2687 for i in $BUILD_DEPENDS; do
2688 [ -d $i ] && continue
2689 [ -n "$(whoprovide $i)" ] && continue
2690 echo -e "$MSG $i"
2691 MSG=""
2692 done
2693 MSG="Dependency loop between $PACKAGE and :\n"
2694 ALL_DEPS=""
2695 check_for_deps_loop $PACKAGE $DEPENDS
2696 [ -d $WOK/$pkg/taz ] && for i in $BUILD_DEPENDS; do
2697 [ $WOK/$pkg/taz -nt $INSTALLED/$i/files.list ] && continue
2698 echo "$pkg should be rebuilt after $i installation"
2699 done
2700 done
2701 ;;
2702 list)
2703 # List packages in wok directory. User can specify a category.
2705 get_tazwok_config
2706 if [ "$2" = "category" ]; then
2707 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
2708 exit 0
2709 fi
2710 # Check for an asked category.
2711 if [ -n "$2" ]; then
2712 ASKED_CATEGORY=$2
2713 echo ""
2714 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
2715 echo "================================================================================"
2716 for pkg in $WOK/*
2717 do
2718 [ ! -f $pkg/receipt ] && continue
2719 . $pkg/receipt
2720 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
2721 echo -n "$PACKAGE"
2722 echo -e "\033[28G $VERSION"
2723 packages=$(($packages+1))
2724 fi
2725 done
2726 echo "================================================================================"
2727 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
2728 else
2729 # By default list all packages and version.
2730 echo ""
2731 echo -e "\033[1mList of packages in the wok\033[0m"
2732 echo "================================================================================"
2733 for pkg in $WOK/*
2734 do
2735 [ ! -f $pkg/receipt ] && continue
2736 . $pkg/receipt
2737 echo -n "$PACKAGE"
2738 echo -en "\033[28G $VERSION"
2739 echo -e "\033[42G $CATEGORY"
2740 packages=$(($packages+1))
2741 done
2742 echo "================================================================================"
2743 echo -e "$packages packages available in the wok.\n"
2744 fi
2745 ;;
2746 info)
2747 # Information about a package.
2749 get_tazwok_config
2750 check_for_package_on_cmdline
2751 check_for_receipt
2752 . $WOK/$PACKAGE/receipt
2753 echo ""
2754 echo -e "\033[1mTazwok package information\033[0m
2755 ================================================================================
2756 Package : $PACKAGE
2757 Version : $VERSION
2758 Category : $CATEGORY
2759 Short desc : $SHORT_DESC
2760 Maintainer : $MAINTAINER"
2761 if [ ! "$WEB_SITE" = "" ]; then
2762 echo "Web site : $WEB_SITE"
2763 fi
2764 if [ ! "$DEPENDS" = "" ]; then
2765 echo "Depends : $DEPENDS"
2766 fi
2767 if [ ! "$WANTED" = "" ]; then
2768 echo "Wanted src : $WANTED"
2769 fi
2770 echo "================================================================================"
2771 echo ""
2772 ;;
2773 check-log)
2774 # We just cat the file log to view process info.
2776 get_tazwok_config
2777 if [ ! -f "$LOG" ]; then
2778 echo -e "\nNo process log found. The package is probably not cooked.\n" >&2
2779 exit 1
2780 else
2781 echo ""
2782 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
2783 echo "================================================================================"
2784 cat $LOG
2785 echo "================================================================================"
2786 echo ""
2787 if [ -s "$WOK/$PACKAGE/warning.txt" ]; then
2788 echo -e "\033[1mCook warning(s) for :\033[0m $PACKAGE"
2789 echo "================================================================================"
2790 cat "$WOK/$PACKAGE/warning.txt"
2791 echo "================================================================================"
2792 echo ""
2793 fi
2794 fi
2795 ;;
2796 search)
2797 # Search for a package by pattern or name.
2799 get_tazwok_config
2800 if [ -z "$2" ]; then
2801 echo -e "\nPlease specify a pattern or a package name to search." >&2
2802 echo -e "Example : 'tazwok search gcc'.\n" >&2
2803 exit 1
2804 fi
2805 echo ""
2806 echo -e "\033[1mSearch result for :\033[0m $2"
2807 echo "================================================================================"
2808 list=`ls -1 $WOK | fgrep $2`
2809 for pkg in $list
2810 do
2811 . $WOK/$pkg/receipt
2812 echo -n "$PACKAGE "
2813 echo -en "\033[24G $VERSION"
2814 echo -e "\033[42G $CATEGORY"
2815 packages=$(($PACKAGEs+1))
2816 done
2817 echo "================================================================================"
2818 echo "$packages packages found for : $2"
2819 echo ""
2820 ;;
2821 compile)
2822 # Configure and make a package with the receipt.
2824 get_tazwok_config
2825 source_lib report
2826 report start
2827 compile_package
2828 ;;
2829 genpkg)
2830 # Generate a package.
2832 get_tazwok_config
2833 source_lib report
2834 report start
2835 gen_package
2836 ;;
2837 cook)
2838 # Compile and generate a package. Just execute tazwok with
2839 # the good commands.
2841 check_root
2842 get_tazwok_config
2843 source_lib report
2844 report start
2845 db_md5=$(md5sum $dep_db $wan_db)
2846 update_wan_db
2847 check_for_commit
2848 if [ "$db_md5" != "$(md5sum $dep_db $wan_db)" ]; then
2849 sort -o $dep_db $dep_db
2850 sort -o $wan_db $wan_db
2851 grep -q "^#" $cookorder || sed 1i"#PlanSort" -i $cookorder
2852 fi
2853 cook
2854 ;;
2855 sort-cooklist)
2856 check_root
2857 get_tazwok_config
2858 check_for_list
2859 report(){ : ; }
2860 # When using sort-cooklist, the script should behave as for gen-cooklist
2861 # The only difference between these two is where the output is sent.
2862 COMMAND=gen-cooklist
2863 gen_cook_list
2864 cp -af $tmp/cooklist $LIST
2865 ;;
2866 cook-list)
2867 # Cook all packages listed in a file or in default cooklist.
2868 check_root
2869 get_options_list="pkg forced"
2870 get_tazwok_config
2871 source_lib report
2872 report start
2873 if ! [ "$pkg" ]; then
2874 [ "$LIST" ] && check_for_list
2875 fi
2876 gen_cook_list
2877 cook_list
2878 ;;
2879 clean)
2880 # Clean up a package work directory + those which want it.
2882 get_tazwok_config
2883 check_for_package_on_cmdline
2884 check_for_receipt
2885 source_lib report
2886 report start
2887 . $RECEIPT
2888 clean
2889 ;;
2890 gen-clean-wok)
2891 # Generate a clean wok from the current wok by copying all receipts
2892 # and stuff directory.
2894 get_tazwok_config
2895 source_lib report
2896 report start
2897 if [ -z "$ARG" ]; then
2898 echo -e "\nPlease specify the destination for the new clean wok.\n" >&2
2899 exit 1
2900 else
2901 dest=$ARG
2902 mkdir -p $dest
2903 fi
2904 report step "Creating clean wok in : $dest"
2905 for pkg in `ls -1 $WOK`
2906 do
2907 copy_cooking_stuff $WOK $pkg $dest
2908 done
2909 [ -d $WOK/.hg ] && cp -a $WOK/.hg $dest
2910 report end-step
2911 echo "Packages cleaned : `ls -1 $dest | wc -l`"
2912 echo ""
2913 ;;
2914 clean-wok)
2915 # Clean all packages in the work directory.
2917 get_tazwok_config
2918 source_lib report
2919 report start
2920 report step "Cleaning wok"
2921 for PACKAGE in `ls -1 $WOK`
2922 do
2923 set_common_path
2924 source_receipt
2925 clean
2926 done
2927 echo "`ls -1 $WOK | wc -l` packages cleaned."
2928 ;;
2929 clean-src)
2930 # Remove tarball unrelated to wok receipts from src repo.
2931 check_root
2932 get_options_list="forced"
2933 get_tazwok_config
2934 cd $SOURCES_REPOSITORY
2935 echo -n "Checking $SOURCES_REPOSITORY..."
2936 for TARBALL in *; do
2937 [ "$TARBALL" = sources.list ] && continue
2938 grep -q $'\t'$TARBALL$ $SOURCES_REPOSITORY/sources.list || \
2939 echo $TARBALL >> $tmp/obsolete
2940 done
2941 status
2942 if ! [ -f $tmp/obsolete ]; then
2943 echo "No sources need to be removed."
2944 exit 1
2945 fi
2946 echo ""
2947 echo -e "\033[1mObsolete/unrelated-to-wok sources :\033[0m"
2948 horizontal_line
2949 cat $tmp/obsolete
2950 horizontal_line
2951 echo "$(wc -l $tmp/obsolete | cut -f1 -d' ') tarballs to remove."
2952 echo ""
2953 echo -n "Please confirm before removing (type uppercase YES): "
2954 read answer
2955 if [ "$answer" = YES ]; then
2956 echo -n "Removing old sources..."
2957 cat $tmp/obsolete | while read i; do
2958 rm -f $SOURCES_REPOSITORY/$i
2959 done
2960 status
2961 fi
2962 ;;
2963 gen-list)
2964 get_tazwok_config
2965 if [ "$2" ]; then
2966 if [ -d "$2" ]; then
2967 pkg_repository=$2
2968 else
2969 echo -e "\nUnable to find directory : $2\n" >&2
2970 exit 1
2971 fi
2972 fi
2974 source_lib report
2975 report start
2976 if [ "$pkg_repository" ]; then
2977 gen_packages_db
2978 else
2979 pkg_repository=$PACKAGES_REPOSITORY && gen_packages_db
2980 pkg_repository=$INCOMING_REPOSITORY && gen_packages_db
2981 fi
2982 ;;
2983 check-list)
2984 # The directory to move into by default is the repository,
2985 # if $2 is not empty cd into $2.
2987 get_tazwok_config
2988 if [ "$2" ]; then
2989 if [ -d "$2" ]; then
2990 pkg_repository=$2
2991 else
2992 echo -e "\nUnable to find directory : $2\n" >&2
2993 exit 1
2994 fi
2995 fi
2997 source_lib report
2998 report start
2999 if [ "$pkg_repository" ]; then
3000 update_packages_db
3001 else
3002 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
3003 pkg_repository=$INCOMING_REPOSITORY && update_packages_db
3004 fi
3005 ;;
3006 new-tree)
3007 # Just create a few directories and generate an empty receipt to prepare
3008 # the creation of a new package.
3010 get_tazwok_config
3011 check_for_package_on_cmdline
3012 clean_wok=$LOCAL_REPOSITORY/clean-wok
3013 if [ -d $clean_wok/$PACKAGE ]; then
3014 echo -e "\n$PACKAGE package tree already exists.\n" >&2
3015 exit 1
3016 fi
3017 echo "Creating : $clean_wok/$PACKAGE"
3018 mkdir $clean_wok/$PACKAGE
3019 cd $clean_wok/$PACKAGE
3020 echo -n "Preparing the receipt..."
3022 # Default receipt begin.
3024 echo "# SliTaz package receipt." > receipt
3025 echo "" >> receipt
3026 echo "PACKAGE=\"$PACKAGE\"" >> receipt
3027 # Finish the empty receipt.
3028 cat >> receipt << "EOF"
3029 VERSION=""
3030 CATEGORY=""
3031 SHORT_DESC=""
3032 MAINTAINER=""
3033 DEPENDS=""
3034 TARBALL="$PACKAGE-$VERSION.tar.gz"
3035 WEB_SITE=""
3036 WGET_URL=""
3038 # Rules to configure and make the package.
3039 compile_rules()
3041 cd $src
3042 ./configure && make && make install
3045 # Rules to gen a SliTaz package suitable for Tazpkg.
3046 genpkg_rules()
3048 mkdir -p $fs/usr
3049 cp -a $_pkg/usr/bin $fs/usr
3052 EOF
3054 # Default receipt end.
3056 status
3057 # Interactive mode, asking and seding.
3058 if [ "$3" = "--interactive" ]; then
3059 echo "Entering interactive mode..."
3060 echo "================================================================================"
3061 echo "Package : $PACKAGE"
3062 # Version.
3063 echo -n "Version : " ; read anser
3064 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
3065 # Category.
3066 echo -n "Category : " ; read anser
3067 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
3068 # Short description.
3069 echo -n "Short desc : " ; read anser
3070 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
3071 # Maintainer.
3072 echo -n "Maintainer : " ; read anser
3073 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
3074 # Web site.
3075 echo -n "Web site : " ; read anser
3076 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
3077 echo ""
3078 # Wget URL.
3079 echo "Wget URL to download source tarball."
3080 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
3081 echo -n "Wget url : " ; read anser
3082 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
3083 # Ask for a stuff dir.
3084 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
3085 if [ "$anser" = "y" ]; then
3086 echo -n "Creating the stuff directory..."
3087 mkdir stuff && status
3088 fi
3089 # Ask for a description file.
3090 echo -n "Are you going to write a description ? (y/N) : " ; read anser
3091 if [ "$anser" = "y" ]; then
3092 echo -n "Creating the description.txt file..."
3093 echo "" > description.txt && status
3094 fi
3095 echo "================================================================================"
3096 echo ""
3097 fi
3098 ;;
3099 remove)
3100 # Remove a package from the wok.
3102 get_tazwok_config
3103 check_for_package_on_cmdline
3104 echo ""
3105 echo -n "Please confirm deletion (y/N) : "; read anser
3106 if [ "$anser" = "y" ]; then
3107 echo -n "Removing $PACKAGE..."
3108 rm -rf $WOK/$PACKAGE && status
3109 echo ""
3110 fi
3111 ;;
3112 update-wok)
3113 # Pull and update a Hg wok.
3114 get_options_list="local"
3115 get_tazwok_config
3116 source_lib report
3117 report start
3118 clean_wok=$LOCAL_REPOSITORY/clean-wok
3119 cd $clean_wok
3120 if ! [ "$local" ]; then
3121 if [ "$WOK_UPDATE_METHOD" = hg ]; then
3122 if ! [ -f "$INSTALLED/mercurial/receipt" ]; then
3124 # Auto-install only if we are in a cook chroot.
3125 if [ -x /usr/bin/clean-chroot ]; then
3126 tazpkg get-install mercurial
3127 else
3128 echo "" >&2
3129 echo "You need to install mercurial to get wok from hg (recommended). Otherwise, you can switch wok get method to \"tarball\" into $LOCAL_REPOSITORY/tazwok.conf (per-repository configuration, if it doesn't exist) or /etc/slitaz/tazwok.conf (global configuration)." | fold -s >&2
3130 echo "">&2
3131 exit 1
3132 fi
3133 fi
3135 report step "Getting wok changes using hg"
3136 if [ -d .hg ]; then
3137 hg pull -u || exit 1
3138 else
3139 hg clone $HG_WOK . || exit 1
3140 fi
3141 report end-step
3142 [ -x /usr/bin/clean-chroot ] && clean-chroot
3143 else
3144 report step "Getting wok changes using tarball"
3145 { mkdir .tmp && cd .tmp
3146 wget "$TARBALL_WOK" &&
3147 case $TARBALL_WOK in
3148 *bz2) tar xjf *.bz2 -C wok; rm *.bz2;;
3149 *lzma) unlzma -c *.lzma | tar xf - -C wok; rm *.lzma ;;
3150 *gz) tar xzf *.gz -C wok; rm*.gz ;;
3151 esac &&
3152 rm -r $(ls -d $clean_wok/*) &&
3153 cp -a wok/* $clean_wok &&
3154 cd .. &&
3155 rm -r .tmp
3156 } || { echo "That's not cool: it fails!" >&2
3157 report end-step
3158 exit 1; }
3159 report end-step
3160 fi
3161 fi
3162 report step "Appending changes to wok"
3164 # Handle removed files/dir.
3165 cd $WOK
3166 for dir in *; do
3167 [ -d "$clean_wok/$dir" ] || rm -rf $dir
3168 done
3169 for file in */receipt */description.txt; do
3170 [ -f "$clean_wok/$file" ] || rm -rf $file
3171 done
3172 for i in $(find */stuff 2>/dev/null); do
3173 [ -e "$clean_wok/$i" ] || rm -rf $i
3174 done
3176 cp -a $clean_wok/* $WOK
3177 report end-step
3178 ;;
3179 maintainers)
3180 get_tazwok_config
3181 echo ""
3182 echo "List of maintainers for: $WOK"
3183 echo "================================================================================"
3184 touch /tmp/slitaz-maintainers
3185 for pkg in $WOK/*
3186 do
3187 . $pkg/receipt
3188 if ! fgrep -q "$MAINTAINER" /tmp/slitaz-maintainers; then
3189 echo "$MAINTAINER" >> /tmp/slitaz-maintainers
3190 echo "$MAINTAINER"
3191 fi
3192 done
3193 echo "================================================================================"
3194 echo "Maintainers: `cat /tmp/slitaz-maintainers | wc -l`"
3195 echo ""
3196 # Remove tmp files
3197 rm -f /tmp/slitaz-maintainers
3198 ;;
3199 maintained-by)
3200 # Search for packages maintained by a contributor.
3201 get_tazwok_config
3202 if [ ! -n "$2" ]; then
3203 echo "Specify a name or email of a maintainer." >&2
3204 exit 1
3205 fi
3206 echo "Maintainer packages"
3207 echo "================================================================================"
3208 for pkg in $WOK/*
3209 do
3210 . $pkg/receipt
3211 if echo "$MAINTAINER" | fgrep -q "$2"; then
3212 echo "$PACKAGE"
3213 packages=$(($PACKAGEs+1))
3214 fi
3215 done
3216 echo "================================================================================"
3217 echo "Packages maintained by $2: $PACKAGEs"
3218 echo ""
3219 ;;
3220 tags)
3221 get_tazwok_config
3222 echo -e "\n\033[1mTags list :\033[0m"
3223 horizontal_line
3224 cd $WOK
3225 for i in */receipt; do
3226 unset TAGS
3227 source $i
3228 for t in $TAGS; do
3229 grep -q ^$t$ $tmp/tags && continue
3230 echo $t | tee -a $tmp/tags
3231 done
3232 done
3233 horizontal_line
3234 echo "$(wc -l $tmp/tags | cut -f1 -d ' ') tags listed."
3235 ;;
3236 check-src)
3237 # Verify if upstream package is still available.
3239 get_tazwok_config
3240 check_for_package_on_cmdline
3241 check_for_receipt
3242 source_receipt
3243 check_src()
3245 for url in $@; do
3246 busybox wget -s $url 2>/dev/null && break
3247 done
3249 if [ "$WGET_URL" ];then
3250 echo -n "$PACKAGE : "
3251 check_src $WGET_URL
3252 status
3253 else
3254 echo "No tarball to check for $PACKAGE"
3255 fi
3256 ;;
3257 gen-src)
3258 get_tazwok_config
3259 if [ "$2" ]; then
3260 if [ -d "$2" ]; then
3261 src_repository=$2
3262 else
3263 echo -e "\nUnable to find directory : $2\n" >&2
3264 exit 1
3265 fi
3266 fi
3267 echo -n "Rebuilding sources.list file"
3268 [ $src_repository ] || src_repository="$SOURCES_REPOSITORY"
3269 gen_sources_list $src_repository
3270 status
3271 ;;
3272 get-src)
3273 check_root
3274 get_options_list="target nounpack"
3275 get_tazwok_config
3276 check_for_package_on_cmdline
3277 check_for_receipt
3278 source_receipt
3279 if [ "$WGET_URL" ];then
3280 source_lib report
3281 report start
3282 check_for_tarball
3283 else
3284 echo "No tarball to download for $PACKAGE"
3285 fi
3286 ;;
3287 check-commit)
3288 check_root
3289 get_options_list="missing forced"
3290 get_tazwok_config
3291 source_lib report
3292 report start
3293 if [ "$forced" ]; then
3294 rm -f $WOK/*/md5
3295 unset forced
3296 fi
3297 if [ "$missing" ]; then
3298 pkg=$(ls -1 $WOK)
3299 else
3300 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3301 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3302 } | sort -u)"
3303 fi
3304 gen_cook_list
3305 ;;
3306 cook-commit)
3307 check_root
3308 get_options_list="missing forced"
3309 get_tazwok_config
3310 source_lib report
3311 report start
3312 if [ "$forced" ]; then
3313 rm -f $WOK/*/md5
3314 unset forced
3315 fi
3316 if [ "$missing" ]; then
3317 pkg=$(ls -1 $WOK)
3318 else
3319 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3320 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3321 } | sort -u)"
3322 fi
3323 gen_cook_list
3324 cook_list
3325 ;;
3326 cook-all)
3327 check_root
3328 get_options_list="forced missing"
3329 get_tazwok_config
3330 source_lib report
3331 report start
3332 if [ "$missing" ]; then
3333 pkg=$(ls -1 $WOK)
3334 else
3335 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3336 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3337 } | sort -u)"
3338 fi
3339 gen_cook_list
3340 cook_list
3341 ;;
3342 gen-wok-db)
3343 check_root
3344 get_tazwok_config
3345 source_lib report
3346 report start
3347 gen_wok_db
3348 ;;
3349 report)
3350 get_tazwok_config
3351 cd $PACKAGES_REPOSITORY
3352 if [ "$2" ]; then
3353 case $2 in
3354 commit|cooklist|incoming|broken|blocked)
3355 show="$2"
3356 ;;
3357 *)
3358 echo "usage : tazwok report [commit|cooklist|incoming|broken|blocked]" >&2
3359 exit 1
3360 ;;
3361 esac
3362 else
3363 show="commit cooklist incoming broken blocked"
3364 fi
3365 for i in $show; do
3366 if [ -s $i ]; then
3367 echo ""
3368 echo -e "\033[1m$i\033[0m"
3369 echo "================================================================================"
3370 cat $i
3371 echo "================================================================================"
3372 echo ""
3373 fi
3374 done
3375 ;;
3376 check-incoming)
3377 check_root
3378 get_options_list="forced"
3379 get_tazwok_config
3380 source_lib report
3381 report start
3382 [ -f $LOCAL_RESOSITORY/incoming ] && rm [ -f $LOCAL_REPOSITORY/incoming ]
3383 report step "Checking $INCOMING_REPOSITORY"
3384 report open-bloc
3385 [ -f $LOCAL_REPOSITORY/log/incoming.html ] && rm $LOCAL_REPOSITORY/log/incoming.html
3386 report sublog $LOCAL_REPOSITORY/log/incoming.html
3387 echo "incoming" > $LOCAL_REPOSITORY/log/package
3388 check_for_incoming
3389 report end-sublog
3390 report close-bloc
3391 ;;
3392 configure-chroot)
3393 check_root
3394 get_tazwok_config
3395 if [ -f /usr/bin/tazchroot ]; then
3396 cd $LOCAL_REPOSITORY
3397 configure_tazchroot
3398 else
3399 echo "The package tazchroot needs to be installed" >&2
3400 exit 1
3401 fi
3402 ;;
3403 chroot)
3404 check_root
3405 get_tazwok_config
3406 # Merge this and the other chroot function ?.
3407 if [ -f /usr/bin/tazchroot ]; then
3408 cd $LOCAL_REPOSITORY
3409 [ ! -f tazchroot.conf ] && configure_tazchroot
3410 tazchroot
3411 else
3412 echo "The package tazchroot needs to be installed" >&2
3413 exit 1
3414 fi
3415 ;;
3416 cook-toolchain)
3417 check_root
3418 get_tazwok_config
3419 echo -n "" > $PACKAGES_REPOSITORY/broken
3420 if [ -f /usr/bin/tazchroot ]; then
3421 cd $LOCAL_REPOSITORY
3422 [ -f tazchroot.conf ] || configure_tazchroot
3424 # Plan to recook all packages.
3425 if tazchroot cook-toolchain; then
3426 source_lib report
3427 report start
3428 pkg="$(grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt \
3429 $INCOMING_REPOSITORY/packages.txt | sort -u)"
3430 forced=yes
3431 gen_cook_list
3432 fi
3434 # Remove chroot where toolchain has been cooked.
3435 source $LOCAL_REPOSITORY/tazchroot.conf
3436 rm -r $LOCAL_REPOSITORY/chroot
3438 else
3439 echo -e "\nThe package tazchroot needs to be installed.\n" >&2
3440 exit 1
3441 fi
3442 ;;
3443 webserver)
3444 check_root
3445 get_tazwok_config
3446 if [ "$ARG" = on ]; then
3447 if [ "$WEBSERVER" ] && [ -f "$WEBSERVER/repositories.list" ] && \
3448 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3449 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3450 exit 1
3451 fi
3452 if ! [ -f $LOCAL_REPOSITORY/tazchroot.conf ]; then
3453 tazwok configure-chroot ${undigest:+--undigest=$undigest} --SLITAZ_VERSION=$SLITAZ_VERSION --SLITAZ_DIR=$SLITAZ_DIR
3454 fi
3455 for pkg in php lighttpd; do
3456 [ -d $INSTALLED/$pkg ] || missing="$missing $pkg"
3457 done
3458 if [ "$missing" ]; then
3459 echo "You need to install these packages to start webserver: $missing." >&2
3460 exit 1
3461 fi
3462 if [ ! -f "$LOCAL_REPOSITORY/tazwok.conf" ]; then
3463 echo "Copying /etc/slitaz/tazwok.conf to $LOCAL_REPOSITORY/tazwok.conf: webserver is configured repository-by-repository."
3464 cp /etc/slitaz/tazwok.conf $LOCAL_REPOSITORY
3465 fi
3466 if ! [ "$WEBSERVER" ]; then
3467 echo -n "Where to store php pages (default: /var/www/vhosts/bb)? "
3468 read WEBSERVER
3469 [ "$WEBSERVER" ] || WEBSERVER="/var/www/vhosts/bb"
3470 fi
3471 if [ -f "$WEBSERVER/repositories.list" ] && \
3472 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3473 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3474 exit 1
3475 fi
3476 mkdir -p $WEBSERVER
3477 echo "${undigest:-$SLITAZ_VERSION}" >> $WEBSERVER/repositories.list
3478 for file in index.php log.php download.php; do
3479 [ -f "$WEBSERVER/$file" ] || ln -s /usr/share/slitaz/web-bb/$file $WEBSERVER
3480 done
3481 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3482 ln -s $dir $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3483 done
3484 source $LOCAL_REPOSITORY/tazchroot.conf
3485 echo "<?php
3487 // Web interface configuration
3489 \$version=\"${undigest:-$SLITAZ_VERSION}\";
3490 \$chroot=\"$chroot_dir\";
3491 \$lockfile=\"\$chroot/proc/1/status\";
3492 \$db_dir=\"$PACKAGES_REPOSITORY\";
3493 \$log_dir=\"$LOCAL_REPOSITORY/log\";
3494 \$packages=\"$PACKAGES_REPOSITORY\";
3495 \$incoming=\"$INCOMING_REPOSITORY\";
3496 \$wok=\"$WOK\";
3498 ?>" > $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3499 [ -L "$WEBSERVER/web" ] || ln -s /usr/share/slitaz/web $WEBSERVER
3500 echo "WEBSERVER=\"$WEBSERVER\"" >> $LOCAL_REPOSITORY/tazwok.conf
3501 if [ -L "$WEBSERVER/conf.php" ]; then
3502 echo "Do you want to make ${undigest:-$SLITAZ_VERSION} the default page (y/N) ? "
3503 read answer
3504 if [ "$answer" = y ]; then
3505 rm $WEBSERVER/conf.php
3506 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3507 fi
3508 else
3509 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3510 fi
3511 elif [ "$ARG" = off ]; then
3512 if ! [ "$WEBSERVER" ]; then
3513 echo "No webserver running for ${undigest:-$SLITAZ_VERSION}" >&2
3514 exit 1
3515 fi
3516 sed '/^WEBSERVER/d' -i $LOCAL_REPOSITORY/tazwok.conf
3517 sed "/^${undigest:-$SLITAZ_VERSION}$/d" -i $WEBSERVER/repositories.list
3518 rm $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3519 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3520 rm $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3521 done
3522 if ! [ -s "$WEBSERVER/repositories.list" ]; then
3523 echo "$WEBSERVER/repositories.list is empty; tazwok doesn't remove the server automatically in case you have important stuff in it. If that's not the case, you can remove it using: rm -r $WEBSERVER"
3524 rm $WEBSERVER/conf.php
3525 elif [ "$(readlink $WEBSERVER/conf.php)" = "$WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php" ]; then
3526 echo "${undigest:-$SLITAZ_VERSION} was the default version to use; switched to : $(sed 1!d $WEBSERVER/repositories.list)"
3527 rm $WEBSERVER/conf.php
3528 ln -s $WEBSERVER/conf-$(sed 1!d $WEBSERVER/repositories.list).php $WEBSERVER/conf.php
3529 fi
3530 else
3531 echo "Usage: tazwok webserver on/off" >&2
3532 exit 1
3533 fi
3534 ;;
3535 block)
3536 # Add a pkg name to the list of blocked packages.
3537 get_tazwok_config
3538 check_root
3539 check_for_package_on_cmdline
3540 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3541 echo "Can't find $PACKAGE in wok." >&2
3542 echo ""
3543 exit 1
3544 fi
3545 echo ""
3546 if grep -qs "^$PACKAGE$" $blocked; then
3547 echo "$PACKAGE is already in the blocked packages list." >&2
3548 echo ""
3549 exit 1
3550 else
3551 echo -n "Adding $PACKAGE to : $blocked... "
3552 echo "$PACKAGE" >> $blocked
3553 status
3554 if grep -q "^$PACKAGE$" $cooklist; then
3555 echo -n "Removing $PACKAGE from : $cooklist... "
3556 sed -i /"^$PACKAGE$"/d $cooklist
3557 status
3558 fi
3559 fi
3560 echo "" ;;
3561 unblock)
3562 # Remove a pkg name from the list of blocked packages.
3563 get_tazwok_config
3564 check_root
3565 check_for_package_on_cmdline
3566 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3567 echo "Can't find $PACKAGE in wok." >&2
3568 echo ""
3569 exit 1
3570 fi
3571 echo ""
3572 if grep -qs "^$PACKAGE$" $blocked; then
3573 echo -n "Removing $PACKAGE from : $blocked... "
3574 sed -i /"^$PACKAGE$"/d $blocked
3575 sed -i '/^$/d' $blocked
3576 status
3577 else
3578 echo "$PACKAGE is not in the blocked packages list." >&2
3579 echo ""
3580 exit 1
3581 fi
3582 echo "" ;;
3583 usage|*)
3584 # Print usage also for all unknown commands.
3586 usage
3587 ;;
3588 esac
3590 # If a cook command has been used, refresh ID of the repository to avoid
3591 # useless upgrade at next cook command.
3592 case $COMMAND in
3593 cook*)
3594 for repo in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY \
3595 $( [ "$undigest" -a ! "$ref_USE_ONLINE_PKG" ] && echo $ref_PACKAGES_REPOSITORY ); do
3596 [ -f $repo/ID ] || continue
3597 MIRROR_path=$(grep -l "^$repo$" $LOCALSTATE/mirror $LOCALSTATE/undigest/*/mirror)
3598 LOCALSTATE_path=${MIRROR_path%/mirror}
3599 cp -a $repo/ID $LOCALSTATE_path
3600 done
3601 ;;
3602 esac
3604 report stop 2>/dev/null
3605 exit 0