tazwok view tazwok @ rev 461
Merge changes from default
author | Antoine Bodin <gokhlayeh@slitaz.org> |
---|---|
date | Fri Mar 25 18:20:21 2011 +0100 (2011-03-25) |
parents | 4c0c67f36336 e2d5b3583ee8 |
children | ad725c56d2e1 |
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" >&2
403 unset plan_remove broken
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 CXXFLAGS MAKEFLAGS DESTDIR BUILD_HOST \
724 CONFIG_SITE default_prefix \
725 default_datarootdir default_datadir default_localedir \
726 default_infodir default_mandir default_build default_host
727 local LC_ALL=POSIX LANG=POSIX
728 compile_rules
730 # Check if config.site has been used.
731 # /!\ disabled since it screws the return_code of the step.
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
738 report end-step
739 fi
740 }
742 # Check for loop in deps tree. /!\ can be removed.
743 check_for_deps_loop()
744 {
745 local list
746 local pkg
747 local deps
748 pkg=$1
749 shift
750 [ -n "$1" ] || return
751 list=""
753 # Filter out already processed deps.
754 for i in $@; do
755 case " $ALL_DEPS" in
756 *\ $i\ *);;
757 *) list="$list $i";;
758 esac
759 done
760 ALL_DEPS="$ALL_DEPS$list "
761 for i in $list; do
762 [ -f $i/receipt ] || continue
763 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
764 case " $deps " in
765 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
766 *) check_for_deps_loop $pkg $deps;;
767 esac
768 done
769 }
771 # Function used by download().
772 revert_vcs_failure()
773 {
774 cd $SOURCES_REPOSITORY
775 rm -r $tmp_src
776 }
778 download()
779 {
780 if [ "$COMMAND" = get-src ]; then
781 if [ "${DEPENDS/tar}" != "$DEPENDS" ] || [ "${BUILD_DEPENDS/tar}" != "$BUILD_DEPENDS" ]; then
782 [ -f $INSTALLED/tar/receipt ] || tazpkg get-install tar --forced
783 fi
784 fi
785 for file in $@; do
786 echo "Downloading from ${file#*|}..."
787 case "$file" in
788 git\|*)
789 file=${file#git|}
790 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/git/receipt ] && tazpkg get-install git --forced
791 if [ -f $INSTALLED/git/receipt ]; then
792 mkdir $tmp_src
793 cd $tmp_src
794 if [ "$BRANCH" ]; then
795 git clone $file ${src##*/} && cd ${src##*/} && \
796 git checkout $BRANCH && rm -rf .git* && break
797 else
798 git clone $file ${src##*/} && rm -rf ${src##*/}/.git* && break
799 fi
800 revert_vcs_failure
801 else
802 tazwok_warning "Needs git to download the source tarball from $file, please add it as a build-depend."
803 continue
804 fi
805 ;;
806 bazaar\|*)
807 file=${file#bazaar|}
808 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/bazaar/receipt ] && tazpkg get-install bazaar --forced
809 if [ -f $INSTALLED/bazaar/receipt ]; then
810 mkdir $tmp_src
811 cd $tmp_src
812 if [ "$BRANCH" ]; then
813 bzr co $file -r $BRANCH ${src##*/} && rm -rf ${src##*/}/.bzr* && break
814 else
815 bzr co $file ${src##*/} && rm -rf ${src##*/}/.bzr* && break
816 fi
817 revert_vcs_failure
818 else
819 tazwok_warning "Needs bazaar to download the source tarball from $file, please add it as a build-depend."
820 continue
821 fi
822 ;;
823 subversion\|*)
824 file=${file#subversion|}
825 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/subversion/receipt ] && tazpkg get-install subversion --forced
826 if [ -f $INSTALLED/subversion/receipt ]; then
827 mkdir $tmp_src
828 cd $tmp_src
829 if [ "$BRANCH" ]; then
830 echo t | svn co $file -r $BRANCH ${src##*/} && rm -rf ${src##*/}/.svn* && break
831 else
832 echo t | svn co $file ${src##*/} && rm -rf ${src##*/}/.svn* && break
833 fi
834 revert_vcs_failure
835 else
836 tazwok_warning "Needs subversion to download the source tarball from $file, please add it as a build-depend."
837 continue
838 fi
839 ;;
840 mercurial\|*)
841 file=${file#mercurial|}
842 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/mercurial/receipt ] && tazpkg get-install mercurial --forced
843 if [ -f $INSTALLED/mercurial/receipt ]; then
844 mkdir $tmp_src
845 cd $tmp_src
846 if [ "$BRANCH" ]; then
847 hg clone $file --rev $BRANCH ${src##*/} && rm -rf ${src##*/}/.hg* && break
848 else
849 hg clone $file ${src##*/} && rm -rf ${src##*/}/.hg* && break
850 fi
851 revert_vcs_failure
852 else
853 tazwok_warning "Needs mercurial to download the source tarball from $file, please add it as a build-depend."
854 continue
855 fi
856 ;;
857 https*)
858 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/wget/receipt ] && tazpkg get-install wget --forced
859 if [ -d $INSTALLED/wget ]; then
860 if [ "${WGET_URL%$TARBALL}" = "$WGET_URL" ] && [ "$file" = "$WGET_URL" ]; then
861 wget -q --no-check-certificate -O $TARBALL $file && break
862 else
863 wget -q --no-check-certificate $file && break
864 fi
865 else
866 tazwok_warning "Needs wget to download the source tarball from $file, please add it as a build-depend."
867 continue
868 fi
869 ;;
870 http*|ftp*)
871 # Handle crappy URL.
872 if [ "$COMMAND" = get-src ]; then
873 if [ "${DEPENDS/wget}" != "$DEPENDS" ] || [ "${BUILD_DEPENDS/wget}" != "$BUILD_DEPENDS" ]; then
874 [ -f $INSALLED/wget/receipt ] || tazpkg get-install wget --forced
875 fi
876 fi
877 if [ "${WGET_URL%$TARBALL}" = "$WGET_URL" ] && [ "$file" = "$WGET_URL" ]; then
878 wget -q -O $TARBALL $file && break
879 else
880 wget -q $file && break
881 fi
882 ;;
883 esac
884 done
885 }
887 # Regenerate every package that wants a PACKAGE compiled.
888 refresh_packages_from_compile()
889 {
890 # make tazwok genpkg happy.
891 mkdir $WOK/$PACKAGE/taz
893 # Cook rwanted in default or specied order.
894 genlist=" $(look_for_rwanted | tr '\n' ' ') "
895 for i in $(look_for_cookopt genpkg | tac); do
896 [ "${genlist/ $i }" = "$genlist" ] && continue
897 genlist=" $i${genlist/ $i / }"
898 done
899 if [ "$genlist" ]; then
900 local PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
901 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
902 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
903 src _pkg DESTDIR CONFIG_SITE RECEIPT LOG stuff wanted_stuff
904 for PACKAGE in $genlist; do
905 set_common_path
906 gen_package
907 done
908 fi
909 }
911 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
912 # so some packages need to copy these files with the receipt and genpkg_rules.
913 # This function is executed by gen_package when 'tazwok genpkg'.
914 copy_generic_files()
915 {
916 # In most cases, locales are in $_pkg/usr/share/locale so we copy files
917 # using generic variables and $LOCALE from Tazwok config file.
918 if [ "$LOCALE" ]; then
919 if [ -d "$_pkg/usr/share/locale" ]; then
920 for i in $LOCALE
921 do
922 if [ -d "$_pkg/usr/share/locale/$i" ]; then
923 mkdir -p $fs/usr/share/locale
924 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
925 fi
926 done
927 fi
928 fi
930 # Pixmaps (PNG or/and XPM only). Some icons/images can be added through
931 # genpkg_rules and generic copy can be disabled with GENERIC_PIXMAPS="no"
932 # in pkg receipt.
933 if [ "$GENERIC_PIXMAPS" != "no" ]; then
934 if [ -d "$_pkg/usr/share/pixmaps" ]; then
935 mkdir -p $fs/usr/share/pixmaps
936 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
937 $fs/usr/share/pixmaps 2>/dev/null
938 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
939 $fs/usr/share/pixmaps 2>/dev/null
940 fi
942 # Custom or homemade PNG pixmap can be in stuff.
943 if [ -f "stuff/$PACKAGE.png" ]; then
944 mkdir -p $fs/usr/share/pixmaps
945 cp -a stuff/$PACKAGE.png $fs/usr/share/pixmaps
946 fi
947 fi
949 # Desktop entry (.desktop).
950 if [ -d "$_pkg/usr/share/applications" ]; then
951 cp -a $_pkg/usr/share/applications $fs/usr/share
952 fi
954 # Homemade desktop file(s) can be in stuff.
955 if [ -d "stuff/applications" ]; then
956 mkdir -p $fs/usr/share
957 cp -a stuff/applications $fs/usr/share
958 fi
959 if [ -f "stuff/$PACKAGE.desktop" ]; then
960 mkdir -p $fs/usr/share/applications
961 cp -a stuff/$PACKAGE.desktop $fs/usr/share/applications
962 fi
963 }
965 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
966 strip_package()
967 {
968 report step "Executing strip on all files"
970 # Binaries.
971 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
972 do
973 if [ -d "$dir" ]; then
974 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
975 fi
976 done
978 # Libraries.
979 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
980 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
981 report end-step
982 }
984 # Remove .pyc and .pyo files from packages.
985 py_compiled_files_remove()
986 {
987 report step "Removing all .pyc and .pyo files from package"
988 find $fs -type f -name "*.pyc" -delete 2>/dev/null
989 find $fs -type f -name "*.pyo" -delete 2>/dev/null
990 report end-step
991 }
993 # Check FSH in a slitaz package (Path: /:/usr)
994 check_fsh()
995 {
996 cd $WOK/$PACKAGE/taz/*/fs
997 if [ -z "$(find * ! -type d)" ] && [ "$CATEGORY" != meta ]; then
998 echo "$PACKAGE fs is empty." >&2
999 cd $WOK/$PACKAGE && rm -rf taz
1000 return 1
1001 fi
1002 [ -n "$FSH" ] || FSH="bin boot dev etc home init lib media mnt proc \
1003 root sbin share sys tmp usr var vz usr/bin usr/games usr/include usr/lib \
1004 usr/local usr/sbin usr/share usr/src"
1005 error=0
1006 for i in `ls -d * usr/* 2>/dev/null`
1007 do
1008 if ! echo $FSH | fgrep -q $i; then
1009 echo "Wrong path: /$i" >&2
1010 error=1
1011 fi
1012 done
1013 if [ "$error" = "1" ]; then
1014 cat << _EOT_
1016 Package will install files in a non standard directory and won't be generated.
1017 You may have a wrong copy path in genpkg_rules or need to add some options to
1018 configure in compile_rules. Some valid options for SliTaz (Linux FSH):
1020 --prefix=/usr
1021 --sysconfdir=/etc
1022 --libexecdir=/usr/lib/(pkgname)
1023 --localstatedir=/var
1024 --mandir=/usr/share/man
1025 --infodir=/usr/share/info
1027 For more information please read SliTaz docs and run: ./configure --help
1028 ================================================================================
1029 $PACKAGE package generation aborted.
1031 _EOT_
1033 # Dont generate a corrupted package.
1034 cd $WOK/$PACKAGE && rm -rf taz
1035 return 1
1036 fi
1037 return 0
1038 }
1040 gen_cookmd5()
1041 {
1042 # md5sum of cooking stuff make tazwok able to check for changes
1043 # without hg.
1044 cd $WOK/$PACKAGE
1045 md5sum receipt > md5
1046 [ -f description.txt ] && md5sum description.txt >> md5
1047 if [ -d stuff ]; then
1048 find stuff | while read file; do
1049 md5sum $file >> md5
1050 done
1051 fi
1052 }
1054 set_pkg_broken()
1055 {
1056 grep -q ^$PACKAGE$ $broken || echo $PACKAGE >> $broken
1058 # Remove pkg from cooklist to avoid re-cook it if no changes happen
1059 # in the cook stuff.
1060 sed "/^$PACKAGE$/d" -i $cooklist $commit
1062 gen_cookmd5
1064 # Return 1 to make report know that its mother-function failed.
1065 return 1
1066 }
1068 # Create a package tree and build the gziped cpio archive
1069 # to make a SliTaz (.tazpkg) package.
1070 gen_package()
1071 {
1072 check_root
1073 check_for_package_on_cmdline
1074 check_for_receipt
1075 source_receipt
1077 # May compute VERSION
1078 if grep -q ^get_version $RECEIPT; then
1079 get_version
1080 fi
1081 check_for_wanted
1082 cd $WOK/$PACKAGE
1084 # Remove old Tazwok package files.
1085 [ -d "taz" ] && rm -rf taz
1087 # Create the package tree and set useful variables.
1088 fs=$WOK/$PACKAGE/taz/$PACKAGE-$VERSION/fs
1089 mkdir -p $fs
1091 # Set $src for standard package and $_pkg variables.
1092 set_src_path
1093 set_pkg_path
1095 # Execute genpkg_rules, check package and copy generic files to build
1096 # the package.
1097 report step "Building $PACKAGE with the receipt"
1098 report open-bloc
1099 if look_for_cookopt !fs; then
1100 :
1101 elif grep -q ^genpkg_rules $RECEIPT; then
1103 # Log process.
1104 echo "executing genpkg_rules" >> $LOG
1105 report step "Executing genpkg_rules"
1106 ( set -e; genpkg_rules ) || { set_pkg_broken; report close-bloc; return 1; }
1107 check_fsh || { set_pkg_broken; report close-bloc; return 1; }
1108 cd $WOK/$PACKAGE
1109 report end-step
1111 # Skip generic files for packages with a WANTED variable
1112 # (dev and split pkgs).
1113 if [ ! "$WANTED" ]; then
1114 copy_generic_files
1115 fi
1116 look_for_cookopt !strip || strip_package
1117 py_compiled_files_remove
1118 else
1119 echo "No package rules to gen $PACKAGE..." >&2
1120 set_pkg_broken
1121 report close-bloc
1122 return 1
1123 fi
1125 # Copy the receipt and description (if exists) into the binary package tree.
1126 cd $WOK/$PACKAGE
1127 report step "Copying the receipt"
1128 cp receipt taz/$PACKAGE-$VERSION
1129 report end-step
1130 if grep -q ^get_version $RECEIPT; then
1131 report step "Updating version in receipt"
1132 sed -i "s/^VERSION=.*/VERSION=\"$VERSION\"/" \
1133 taz/$PACKAGE-$VERSION/receipt
1134 report end-step
1135 fi
1136 if [ -f "description.txt" ]; then
1137 report step "Copying the description file"
1138 cp description.txt taz/$PACKAGE-$VERSION
1139 report end-step
1140 fi
1142 # Generate md5 of cooking stuff to look for commit later.
1143 gen_cookmd5
1144 echo -e "\n# md5sum of cooking stuff :" >> taz/$PACKAGE-$VERSION/receipt
1145 cat md5 | sed 's/^/# /' >> taz/$PACKAGE-$VERSION/receipt
1147 # Create the files.list by redirecting find output.
1148 report step "Creating the list of files"
1149 cd taz/$PACKAGE-$VERSION
1150 LAST_FILE=""
1151 { find fs -print; echo; } | while read file; do
1152 if [ "$LAST_FILE" ]; then
1153 case "$file" in
1154 $LAST_FILE/*)
1155 case "$(ls -ld "$LAST_FILE")" in
1156 drwxr-xr-x\ *\ root\ *\ root\ *);;
1157 *) echo ${LAST_FILE#fs};;
1158 esac;;
1159 *) echo ${LAST_FILE#fs};;
1160 esac
1161 fi
1162 LAST_FILE="$file"
1163 done > files.list
1165 # Next, check if something has changed in lib files.
1166 # Plan to recook each packages which depends on libs
1167 # which doesn't exists anymore.
1168 libs=$(for file in $(find * -type f); do
1169 [ "$(dd if=$file bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ] || continue
1170 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $PWD/$file
1171 done | { cut -f 1 -d ' ' | tr -d '\t' | sort -u | \
1172 sed -e 's/^linux-gate.so.*$/SLIB/' -e 's~^/lib/ld-.*$~SLIB~' \
1173 -e '/^statically$/d' | tr '\n' ' '; })
1174 [ "$libs" ] && libs=$(echo " $libs" | sed -r 's/( SLIB)+ / /g')
1175 old_libs=$(grep -m1 ^$PACKAGE$'\t' $lib_db | cut -f 2)
1176 if [ "$old_libs" ]; then
1177 report step "Looking if reverse depends needs to be refreshed"
1178 for i in $old_libs; do
1179 [ "${libs/ $i }" = "$libs" ] || continue
1180 fgrep " $i " $lib_db | cut -f 1
1181 done | sort -u | while read rdep; do
1182 [ "$rdep" = "${WANTED:-$PACKAGE}" ] && continue
1183 grep -q ^$rdep$ $blocked $cooklist && continue
1184 echo "Plan to recook $rdep"
1185 echo $rdep >> $cooklist
1186 done
1187 sed "/^$PACKAGE\t/d" -i $lib_db
1188 report end-step
1189 fi
1190 if [ "$libs" ]; then
1191 echo -e "$PACKAGE\t$libs" >> $lib_db
1192 sort -o $lib_db $lib_db
1193 fi
1195 if [ ! "$EXTRAVERSION" ]; then
1196 case "$PACKAGE" in
1197 linux*);;
1198 *) EXTRAVERSION="$(grep '/lib/modules/.*-slitaz/' files.list |\
1199 head -1 | sed 's|/lib/modules/\(.*\)-slitaz/.*|_\1|')";;
1200 esac
1201 fi
1202 rm -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg 2> /dev/null
1203 report step "Creating md5sum of files"
1204 while read file; do
1205 [ -L "fs$file" ] && continue
1206 [ -f "fs$file" ] || continue
1207 md5sum "fs$file" | sed 's/ fs/ /'
1208 done < files.list > md5sum
1209 report end-step
1210 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
1211 2> /dev/null | awk '{ sz=$1 } END { print sz }')
1213 # Build cpio archives. Find, cpio and gzip the fs, finish by
1214 # removing the fs tree.
1215 # Don't log this because compression always outputs error messages.
1216 find fs -print | cpio -o -H newc | case "$PACKAGE-$COMPRESSION" in
1217 tazpkg-lzma) gzip > fs.cpio.gz;;
1218 *-lzma) lzma e fs.cpio.lzma -si;;
1219 *) gzip > fs.cpio.gz;;
1220 esac && rm -rf fs
1221 PACKED_SIZE=$(du -chs fs.cpio.* receipt files.list md5sum \
1222 description.txt 2> /dev/null | awk '{ sz=$1 } END { print sz }')
1223 report step "Updating receipt sizes"
1224 sed -i '/^PACKED_SIZE/d' receipt
1225 sed -i '/^UNPACKED_SIZE/d' receipt
1226 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1227 sed -i "s/^VERSION=$/VERSION=\"$VERSION\"/" receipt
1228 report end-step
1229 if [ "$EXTRAVERSION" ]; then
1230 report step "Updating receipt EXTRAVERSION"
1231 sed -i s/^EXTRAVERSION.*$// receipt
1232 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
1233 fi
1234 prev_VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
1235 remove_previous_package $INCOMING_REPOSITORY
1236 report step "Creating full cpio archive"
1237 find . -print | cpio -o -H newc > $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1239 # Restore package tree in case we want to browse it.
1240 report step "Restoring original package tree"
1241 { zcat fs.cpio.gz 2> /dev/null || unlzma -c fs.cpio.lzma; } | cpio --quiet -id
1242 rm fs.cpio.* && cd ..
1244 # Save receipts if save_wok is enabled.
1245 [ "$save_wok" ] && copy_cooking_stuff $WOK $PACKAGE $INCOMING_REPOSITORY/wok
1247 # Recook of reverse-depends if package was broken.
1248 if grep -q "^$PACKAGE$" $broken; then
1249 report step "Planning a re-try cook of reverse depends"
1250 sed "/^$PACKAGE$/d" -i $broken
1251 for rdep in $(look_for_rdep); do
1252 grep -q "^$rdep$" $broken || continue
1253 grep -q "^$rdep$" $cooklist && continue
1254 echo "Adding $rdep to the cooklist"
1255 echo $rdep >> $cooklist
1256 regen_cooklist=t
1257 done
1258 report end-step
1259 fi
1260 sed "/^$PACKAGE$/d" -i $commit $cooklist
1262 # Log process.
1263 echo "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg (done)" >> $LOG
1264 report close-bloc
1265 echo "Package $PACKAGE ($VERSION$EXTRAVERSION) generated."
1266 echo "Size : `du -sh $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
1267 echo ""
1268 }
1270 ########################################################################
1271 # This section contains functions used by several other functions
1272 # below.
1273 ########################
1275 # Look for receipt/files.list in wok. If they can't be found, get them
1276 # from package. Accept one argument : absolute path to package.
1277 get_pkg_files()
1278 {
1279 pkg_files_dir=$tmp/$(basename ${1%.tazpkg})
1280 mkdir -p $pkg_files_dir && \
1281 cd $pkg_files_dir && \
1282 cpio --quiet -idm receipt < $1 && \
1283 cpio --quiet -idm files.list < $1
1284 }
1286 ########################################################################
1287 # This section contains functions to generate packages databases.
1288 ########################
1291 gen_packages_db()
1292 {
1293 # pkg_repository can be $PACKAGES_REPOSITORY or $INCOMING_REPOSITORY.
1294 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1295 cd $pkg_repository
1296 report step "Generating packages lists: $pkg_repository"
1297 report open-bloc
1298 report step "Removing old files"
1299 for file in files.list.lzma packages.list packages.txt \
1300 packages.desc packages.equiv packages.md5; do
1301 rm -rf $file
1302 done
1303 touch files.list
1305 packages_db_start
1306 unset RECEIPT
1307 report step "Reading data from all packages"
1308 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1309 get_packages_info
1310 done
1311 report end-step
1312 packages_db_end
1313 report close-bloc
1314 }
1316 update_packages_db()
1317 {
1318 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1319 cd $pkg_repository
1320 for file in packages.list packages.equiv packages.md5 packages.desc \
1321 packages.txt; do
1322 if [ ! -f "$file" ]; then
1323 gen_packages_db
1324 return
1325 fi
1326 done
1327 if [ -f files.list.lzma ]; then
1328 lzma d files.list.lzma files.list
1329 else
1330 gen_packages_db
1331 return
1332 fi
1333 report step "Updating packages lists: $pkg_repository"
1334 packages_db_start
1336 # Look for removed/update packages.
1337 touch stamp -r packages.list
1338 for PACKAGE in $(grep ^[0-9,a-z,A-Z] packages.txt); do
1339 pkg="$pkg_repository/$(grep -m1 ^$PACKAGE- packages.list).tazpkg"
1340 if ! [ -f "$pkg" ]; then
1341 erase_package_info
1342 else
1343 if [ "$pkg" -nt "stamp" ]; then
1344 updated_pkg="$updated_pkg
1345 $PACKAGE $pkg"
1346 elif [ ! -f $WOK/$PACKAGE/receipt ] && \
1347 [ "$COMMAND" = check-incoming -o "$pkg_repository" = "$INCOMING_REPOSITORY" ]; then
1348 erase_package_info
1349 echo "Removing $PACKAGE from $pkg_repository."
1350 rm $pkg
1351 [ "$save_wok" ] && rm -rf $pkg_repository/wok/$PACKAGE
1352 if [ "$pkg_repository" = "$INCOMING_REPOSITORY" ]; then
1353 rm -rf $WOK/$PACKAGE
1354 sed "/^$PACKAGE\t/d" -i $wan_db $dep_db $cookorder
1355 sed "/^$PACKAGE$/d" -i $cooklist $commit $blocked $broken
1356 rm -f $LOCAL_REPOSITORY/log/$PACKAGE.html
1357 if [ "$(sed 1!d $cookorder)" != "#PlanSort" ]; then
1358 sed 1i"#PlanSort" -i $cookorder
1359 regen_cooklist=yes
1360 fi
1361 else
1362 echo "$PACKAGE" >> removed
1363 sed -n '1,10p' -i removed
1364 fi
1365 fi
1366 fi
1367 done
1368 rm stamp
1369 echo "$updated_pkg" | sed 1d | while read PACKAGE pkg; do
1370 erase_package_info
1371 get_packages_info
1372 done
1373 unset updated_pkg
1375 # Look for new packages.
1376 for pkg in $pkg_repository/*.tazpkg; do
1377 fgrep -q " ${pkg##*/}" packages.md5 || get_packages_info
1378 done
1379 report end-step
1380 packages_db_end
1381 }
1383 packages_db_start()
1384 {
1385 if [ -s packages.txt ]; then
1386 sed -e 's/^# Packages :.*/# Packages : unknown/' \
1387 -e "s/# Date :.*/# Date : $(date +%Y-%m-%d\ \%H:%M:%S)/" \
1388 -i packages.txt
1389 else
1390 echo "# SliTaz GNU/Linux - Packages list
1391 #
1392 # Packages : unknown
1393 # Date : $(date +%Y-%m-%d\ \%H:%M:%S)
1394 #
1395 " > packages.txt
1396 fi
1398 # Needed in some cases as tazwok defines RECEIPT at configuration time
1399 # in this particular case it can break the script.
1400 unset RECEIPT
1402 # If $packages_repository is the main one, configure few functions
1403 # to act as they should, without having loop on them (speed-up)
1404 if [ "$pkg_repository" = "$PACKAGES_REPOSITORY" ]; then
1405 erase_package_info_extracmd="erase_package_info_main"
1406 get_packages_info_extracmd="get_packages_info_main"
1407 fi
1408 }
1410 erase_package_info()
1411 {
1412 cd $pkg_repository
1413 sed "/^$PACKAGE$/,/^$/d" -i packages.txt
1414 sed "/^$PACKAGE /d" -i packages.desc
1415 sed -e "s/=$PACKAGE /= /" -e "s/ $PACKAGE / /" -e "s/ $PACKAGE$//" \
1416 -e "/=$PACKAGE$/d" -e "s/=[0-9,a-z,A-Z]:$PACKAGE /= /" \
1417 -e "s/ [0-9,a-z,A-Z]:$PACKAGE / /" -e "s/ [0-9,a-z,A-Z]:$PACKAGE$/ /" \
1418 -e "/=[0-9,a-z,A-Z]:$PACKAGE$/d" \
1419 -i packages.equiv
1420 sed "/^$PACKAGE:/d" -i files.list
1421 sed "/^$(basename ${pkg%.tazpkg})$/d" -i packages.list
1422 sed "/ $(basename $pkg)$/d" -i packages.md5
1423 $erase_package_info_extracmd
1424 }
1426 erase_package_info_main()
1427 {
1428 for i in wanted.txt depends.txt libraries.txt; do
1429 [ -f $i ] || continue
1430 sed "/^$PACKAGE\t/d" -i $i
1431 done
1432 }
1434 get_packages_info()
1435 {
1436 # If there's no taz folder in the wok, extract info from the
1437 # package.
1438 get_pkg_files $pkg
1439 source_receipt
1440 echo "Getting data from $PACKAGE"
1442 cat >> $pkg_repository/packages.txt << _EOT_
1443 $PACKAGE
1444 $VERSION$EXTRAVERSION
1445 $SHORT_DESC
1446 _EOT_
1447 if [ "$PACKED_SIZE" ]; then
1448 cat >> $pkg_repository/packages.txt << _EOT_
1449 $PACKED_SIZE ($UNPACKED_SIZE installed)
1451 _EOT_
1452 else
1453 echo "" >> $pkg_repository/packages.txt
1454 fi
1456 # Packages.desc is used by Tazpkgbox <tree>.
1457 echo "$PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> $pkg_repository/packages.desc
1459 # Packages.equiv is used by tazpkg install to check depends.
1460 for i in $PROVIDE; do
1461 DEST=""
1462 echo $i | fgrep -q : && DEST="${i#*:}:"
1463 if grep -qs ^${i%:*}= $pkg_repository/packages.equiv; then
1464 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" $pkg_repository/packages.equiv
1465 else
1466 echo "${i%:*}=$DEST$PACKAGE" >> $pkg_repository/packages.equiv
1467 fi
1468 done
1470 if [ -f files.list ]; then
1471 { echo "$PACKAGE"; cat files.list; } | awk '
1472 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }' >> $pkg_repository/files.list
1473 fi
1475 cd .. && rm -r "$pkg_files_dir"
1477 cd $pkg_repository
1478 echo $(basename ${pkg%.tazpkg}) >> packages.list
1479 md5sum $(basename $pkg) >> packages.md5
1480 $get_packages_info_extracmd
1481 }
1483 get_packages_info_main()
1484 {
1485 [ "$WANTED" ] && echo -e "$PACKAGE\t$WANTED" >> wanted.txt
1486 echo -e "$PACKAGE\t "$DEPENDS" \t "$BUILD_DEPENDS" " >> package.txt
1487 grep -m1 ^$PACKAGE$'\t' $lib_db >> libraries.txt
1488 }
1490 source_receipt()
1491 {
1492 unset PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
1493 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
1494 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
1495 src _pkg DESTDIR CONFIG_SITE BRANCH TARBALL stuff wanted_stuff
1496 . ${RECEIPT:-$PWD/receipt}
1497 }
1499 packages_db_end()
1500 {
1501 cd $pkg_repository
1502 pkgs=$(wc -l packages.list | sed 's/ .*//')
1503 sed "s/# Packages : .*/# Packages : $pkgs/" -i packages.txt
1505 # If lists were updated it's generally needed to sort them well.
1506 if ! sort -c packages.list 2> /dev/null; then
1507 report step "Sorting packages lists"
1508 files_list="packages.list packages.desc packages.equiv"
1509 [ "${pkg_repository##*/}" = packages ] && \
1510 files_list="$files_list wanted.txt depends.txt libraries.txt"
1511 for file in $files_list; do
1512 [ -f $file ] || continue
1513 sort -o $file $file
1514 done
1515 report end-step
1516 fi
1518 md5sum packages.md5 | cut -f1 -d' ' > ID
1519 [ -s ID ] || echo null > ID
1521 # Dont log this because lzma always output errors.
1522 lzma e files.list files.list.lzma
1523 rm -f files.list
1524 [ -f packages.equiv ] || touch packages.equiv
1525 }
1527 ########################################################################
1528 # This section contains functions to generate wok database.
1529 ########################
1531 gen_wok_db()
1532 {
1533 report step "Generating wok database"
1534 report open-bloc
1535 report step "Removing old files"
1536 for file in $wan_db $dep_db $cookorder; do
1537 [ -f $file ] && rm $file
1538 done
1539 report step "Generating wok-wanted.txt"
1540 gen_wan_db
1541 report step "Generating wok-depends.txt"
1542 for PACKAGE in $(cut -f1 -d '|' $PACKAGES_REPOSITORY/packages.desc \
1543 $INCOMING_REPOSITORY/packages.desc | sort -u); do
1544 RECEIPT=$WOK/$PACKAGE/receipt
1545 if [ -s $RECEIPT ]; then
1546 source_receipt
1547 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
1548 fi
1549 done
1550 sort_db
1551 report close-bloc
1552 }
1554 gen_wan_db()
1555 {
1556 for RECEIPT in $(fgrep -l WANTED $WOK/*/receipt); do
1557 WANTED=
1558 source $RECEIPT
1559 [ "$WANTED" ] || continue
1560 echo -e $PACKAGE"\t"$WANTED >> $tmp/wan_db
1561 done
1562 if ! [ -f $wan_db ] || [ "$(diff -q $tmp/wan_db $wan_db)" ]; then
1563 mv -f $tmp/wan_db $wan_db
1564 plan_regen_cookorder=yes
1565 else
1566 rm $tmp/wan_db
1567 fi
1568 }
1570 update_wan_db()
1571 {
1572 local PACKAGE=$PACKAGE
1573 wanted_list=$(fgrep WANTED=\"$PACKAGE\" $WOK/*/receipt | cut -f1 -d ':')
1574 grep $'\t'$PACKAGE $wan_db | cut -f 1 | while read wan; do
1575 echo "$wanted_list" | fgrep -q /$wan/receipt && continue
1576 sed "/^$wan\t/d" -i $wan_db
1577 plan_regen_cookorder=yes
1578 done
1579 for RECEIPT in $wanted_list; do
1580 WANTED=
1581 source $RECEIPT
1582 [ "$WANTED" ] || continue
1583 wan_info=$(echo -e $PACKAGE"\t"$WANTED)
1584 [ "$wan_info" = "$(grep -m1 ^$PACKAGE$'\t' $wan_db 2>/dev/null)" ] && continue
1585 sed "/^$PACKAGE\t/d" -i $wan_db
1586 echo "$wan_info" >> $wan_db
1587 plan_regen_cookorder=yes
1588 plan_sort_wandb=yes
1589 done
1590 unset wanted_list
1591 }
1593 update_dep_db()
1594 {
1595 dep_info=$(echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ')
1596 [ "$dep_info" = "$(grep -m1 ^$PACKAGE$'\t' $dep_db 2>/dev/null)" ] && return
1597 sed "/^$PACKAGE\t/d" -i $dep_db
1598 echo "$dep_info" >> $dep_db
1599 plan_regen_cookorder=yes
1600 plan_sort_depdb=yes
1601 }
1603 sort_db()
1604 {
1605 report step "Generating cookorder.txt"
1606 sed 's/ \t / /' $dep_db | while read PACKAGE BUILD_DEPENDS; do
1607 grep -q ^$PACKAGE$'\t' $wan_db && continue
1609 # Replace each BUILD_DEPENDS with a WANTED package by it's
1610 # WANTED package.
1611 echo -e $PACKAGE"\t $(echo $BUILD_DEPENDS | use_wanted | \
1612 sort -u | sed "/^$PACKAGE$/d" | tr '\n' ' ') "
1613 done > $tmp/db
1614 while [ -s "$tmp/db" ]; do
1615 status=start
1616 for pkg in $(cut -f 1 $tmp/db); do
1617 if ! fgrep -q ' '$pkg' ' $tmp/db; then
1618 echo $pkg >> $tmp/cookorder
1619 sed -e "/^$pkg\t/d" -e "s/ $pkg / /g" -i $tmp/db
1620 status=proceed
1621 fi
1622 done
1623 if [ "$status" = start ]; then
1624 cp -f $tmp/db /tmp/remain-depends.txt
1625 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
1626 for remaining in $(cut -f 1 $tmp/db); do
1627 echo "$remaining" >> $blocked
1628 done
1629 break
1630 fi
1631 done
1632 [ -s $tmp/cookorder ] || touch $tmp/cookorder
1634 # The toolchain packages are moved in first position.
1635 grep $(for pkg in `scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
1636 --look_for=all --with_args`; do echo " -e ^$pkg$"; done) \
1637 $tmp/cookorder | tac > $cookorder
1638 for pkg in $(cat $cookorder); do
1639 sed "/^$pkg$/d" -i $tmp/cookorder
1640 done
1642 tac $tmp/cookorder >> $cookorder
1643 unset plan_regen_cookorder
1644 report end-step
1645 }
1647 ########################################################################
1648 # SCAN CORE
1649 ########################
1650 # Includes various scan core-functions. It's not intended to be used
1651 # directly : prefer scan wrappers in next section.
1653 look_for_dep()
1654 {
1655 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2
1656 }
1658 look_for_bdep()
1659 {
1660 look_for_all
1661 }
1663 look_for_all()
1664 {
1665 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2,3 | sed 's/ / /'
1666 }
1668 look_for_rdep()
1669 {
1670 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1
1671 }
1673 look_for_rbdep()
1674 {
1675 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1676 }
1678 # Return WANTED if it exists.
1679 look_for_wanted()
1680 {
1681 grep -m1 ^$PACKAGE$'\t' $wan_db | cut -f 2
1682 }
1684 # Return packages which wants PACKAGE.
1685 look_for_rwanted()
1686 {
1687 grep $'\t'$PACKAGE$ $wan_db | cut -f 1
1688 }
1690 look_for_dev()
1691 {
1692 WANTED=$(look_for_wanted)
1693 if [ "$WANTED" ]; then
1694 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1695 fi
1696 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1697 }
1699 with_dev()
1700 {
1701 for PACKAGE in $(cat); do
1702 echo $PACKAGE
1703 look_for_dev
1704 done
1705 }
1707 with_wanted()
1708 {
1709 for PACKAGE in $(cat); do
1710 echo $PACKAGE
1711 look_for_wanted
1712 done
1713 }
1715 use_wanted()
1716 {
1717 for input in $(cat); do
1718 { grep ^$input$'\t' $wan_db || echo $input
1719 }
1720 done | sed 's/.*\t//'
1721 }
1723 check_for_pkg_in_wok()
1724 {
1725 [ -f $WOK/$PACKAGE/receipt ] && return
1726 echo "Can't find $PACKAGE in wok or mirror" >&2
1727 return 2
1728 }
1730 # Define how theses functions should act when using --undigest.
1731 use_undigest_scan_core()
1732 {
1733 look_for_dep()
1734 {
1735 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1736 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2
1737 else
1738 grep -m1 ^$PACKAGE$'\t' $ref_dep_db | cut -f 2
1739 fi
1740 }
1742 look_for_all()
1743 {
1744 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1745 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2,3 | sed 's/ / /'
1746 else
1747 grep -m1 ^$PACKAGE$'\t' $ref_dep_db | cut -f 2,3 | sed 's/ / /'
1748 fi
1749 }
1751 look_for_rdep()
1752 {
1753 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1
1754 for rdep in $(fgrep ' '$PACKAGE' ' $ref_dep_db | cut -f 1); do
1755 [ -f "WOK$/$rdep/receipt" ] || echo "$rdep"
1756 done
1757 }
1759 look_for_rbdep()
1760 {
1761 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1762 for rdep in $(fgrep ' '$PACKAGE' ' $ref_dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1); do
1763 [ -f "WOK$/$rdep/receipt" ] || echo "$rdep"
1764 done
1765 }
1767 look_for_wanted()
1768 {
1769 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1770 grep -m1 ^$PACKAGE$'\t' $wan_db | cut -f 2
1771 else
1772 grep -m1 ^$PACKAGE$'\t' $ref_wan_db | cut -f 2
1773 fi
1774 }
1776 look_for_rwanted()
1777 {
1778 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1779 grep $'\t'$PACKAGE$ $wan_db | cut -f 1
1780 else
1781 grep $'\t'$PACKAGE$ $ref_wan_db | cut -f 1
1782 fi
1783 }
1785 look_for_dev()
1786 {
1787 WANTED=$(look_for_wanted)
1788 if [ "$WANTED" ]; then
1789 if [ -f "$WOK/$WANTED/receipt" ]; then
1790 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1791 else
1792 grep -q ^$WANTED-dev$'\t' $ref_dep_db && echo $WANTED-dev
1793 fi
1794 fi
1795 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1796 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1797 else
1798 grep -q ^$PACKAGE-dev$'\t' $ref_dep_db && echo $PACKAGE-dev
1799 fi
1800 }
1802 check_for_pkg_in_wok()
1803 {
1804 [ -f $WOK/$PACKAGE/receipt ] && return
1805 grep -q ^$PACKAGE'$\t' $ref_dep_db && return 1
1806 echo "Can't find $PACKAGE in wok or mirror" >&2
1807 return 2
1808 }
1809 }
1811 ########################################################################
1812 # SCAN
1813 ########################
1814 # Use wok-wanted.txt and wok-depeds.txt to scan depends.
1815 # Option in command line (must be first arg) :
1816 # --look_for=bdep/rbdep - Look for depends or reverse depends.
1817 # --with_dev - Add development packages (*-dev) in the result.
1818 # --with_wanted - Add package+reverse wanted in the result.
1819 # --with_args - Include packages in argument in the result.
1821 scan()
1822 {
1823 # Get packages in argument.
1824 local PACKAGE=$PACKAGE WANTED=$WANTED pkg_list=
1825 for arg in $@; do
1826 [ "$arg" = "${arg#--}" ] || continue
1827 pkg_list="$pkg_list $arg"
1828 done
1830 # Get options.
1831 [ "$pkg_list" ] || return
1832 local cooklist= look_for= with_dev= with_wanted= with_args= log_command="$0 $@" \
1833 get_options_list="look_for with_dev with_wanted with_args cooklist use_wanted"
1834 get_options
1836 # Cooklist is a special case where we need to modify a little
1837 # scan behavior
1838 if [ "$cooklist" ]; then
1839 gen_wan_db
1840 look_for=all && with_args=yes && with_dev= && with_wanted=
1841 filter=use_wanted
1842 if [ "$COMMAND" = gen-cooklist ]; then
1843 for PACKAGE in $pkg_list; do
1844 grep -q ^$PACKAGE$'\t' $dep_db && continue
1845 [ -d "$WOK/$p" ] || continue
1846 check_for_missing
1847 done
1848 append_to_dep()
1849 {
1850 if grep -q ^$PACKAGE$'\t' $dep_db; then
1851 echo $PACKAGE >> $tmp/dep
1852 else
1853 check_for_missing && echo $PACKAGE >> $tmp/dep
1854 fi
1855 }
1856 else
1857 append_to_dep()
1858 {
1859 check_for_commit && echo $PACKAGE >> $tmp/dep
1860 }
1861 fi
1862 else
1863 append_to_dep()
1864 {
1865 echo $PACKAGE >> $tmp/dep
1866 }
1867 # If requested packages are not in dep_db, partial generation of this db is needed.
1868 for PACKAGE in $pkg_list; do
1869 grep -q ^$PACKAGE$'\t' $dep_db && continue
1870 [ -d "$WOK/$p" ] || continue
1871 plan_check_for_missing=yes
1872 check_for_missing
1873 done
1874 if [ "$plan_check_for_missing" ]; then
1875 append_to_dep()
1876 {
1877 if grep -q ^$PACKAGE$'\t' $dep_db; then
1878 echo $PACKAGE >> $tmp/dep
1879 else
1880 check_for_missing && echo $PACKAGE >> $tmp/dep
1881 fi
1882 }
1883 check_db_status=yes
1884 unset plan_check_for_missing
1885 fi
1886 fi
1888 [ "$with_dev" ] && filter=with_dev
1889 [ "$with_wanted" ] && filter=with_wanted
1890 if [ "$filter" ]; then
1891 pkg_list=$(echo $pkg_list | $filter | sort -u)
1892 scan_pkg()
1893 {
1894 look_for_$look_for | $filter
1895 }
1896 else
1897 scan_pkg()
1898 {
1899 look_for_$look_for
1900 }
1901 fi
1902 touch $tmp/dep
1903 for PACKAGE in $pkg_list; do
1904 [ "$with_args" ] && append_to_dep
1905 scan_pkg
1906 done | tr ' ' '\n' | sort -u > $tmp/list
1907 [ "$look_for" = bdep ] && look_for=dep
1908 while [ -s $tmp/list ]; do
1909 PACKAGE=$(sed 1!d $tmp/list)
1910 sed 1d -i $tmp/list
1911 append_to_dep
1912 for pkg in $(scan_pkg); do
1913 grep -q ^$pkg$ $tmp/list $tmp/dep || echo $pkg >> $tmp/list
1914 done
1915 done
1916 if [ "$cooklist" ]; then
1917 mv $tmp/dep $tmp/cooklist
1918 else
1919 cat $tmp/dep | sort -u
1920 fi
1921 rm -f $tmp/dep $tmp/list
1922 if [ "$check_db_status" ]; then
1923 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
1924 [ "$plan_sort_wandb" ] && sort -o $wan_db $wan_db && unset plan_sort_wandb
1925 if [ "$plan_regen_cookorder" ] && \
1926 [ "$(sed 1!d $cookorder)" != "#PlanSort" ]; then
1927 grep -q "^#" $cookorder || sed 1i"#PlanSort" -i $cookorder
1928 fi
1929 fi
1930 }
1932 ########################################################################
1933 # This section contains functions to check the package repository and
1934 # find which packages to cook.
1935 ########################
1937 check_for_missing()
1938 {
1939 local PACKAGE=$PACKAGE
1940 if ! check_for_pkg_in_wok; then
1941 [ "$?" = 2 ] && return 1
1942 return
1943 fi
1944 RECEIPT=$WOK/$PACKAGE/receipt
1945 source_receipt
1946 PACKAGE=${WANTED:-$PACKAGE}
1947 update_wan_db
1948 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1949 RECEIPT=$WOK/$PACKAGE/receipt
1950 source_receipt
1951 update_dep_db
1952 done
1953 }
1955 check_for_commit()
1956 {
1957 if ! check_for_pkg_in_wok; then
1958 [ "$?" = 2 ] && return 1
1959 return
1960 fi
1961 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1962 RECEIPT=$WOK/$PACKAGE/receipt
1963 source_receipt
1965 # We use md5 of cooking stuff in the packaged receipt to check
1966 # commit. We look consecutively in 3 different locations :
1967 # - in the wok/PACKAGE/taz/* folder
1968 # - in the receipt in the package in incoming repository
1969 # - in the receipt in the package in packages repository
1970 # If md5sums match, there's no commit.
1971 check_for_commit_using_md5sum()
1972 {
1973 if [ ! -f $WOK/$PACKAGE/md5 ]; then
1974 sed -n '/# md5sum of cooking stuff :/,$p' receipt | \
1975 sed -e 1d -e 's/^# //' > $WOK/$PACKAGE/md5
1976 cd $WOK/$PACKAGE
1977 fi
1979 if [ -s md5 ]; then
1980 if md5sum -cs md5; then
1982 # If md5sum check if ok, check for new/missing files in
1983 # cooking stuff.
1984 for file in $([ -f receipt ] && echo receipt; \
1985 [ -f description.txt ] && echo description.txt; \
1986 [ -d stuff ] && find stuff); do
1987 if ! fgrep -q " $file" md5; then
1988 set_commited
1989 fi
1990 done
1991 else
1992 set_commited
1993 fi
1994 else
1995 set_commited
1996 fi
1997 }
1998 set_commited()
1999 {
2000 grep -q ^$PACKAGE$ $commit || echo $PACKAGE >> $commit
2001 gen_cookmd5
2002 update_dep_db
2003 }
2004 taz_dir=$(echo $WOK/$PACKAGE/taz/$PACKAGE-* | fgrep -v '*')
2005 if [ -f $WOK/$PACKAGE/md5 ]; then
2006 cd $WOK/$PACKAGE
2007 check_for_commit_using_md5sum
2008 elif [ "$taz_dir" ]; then
2009 cd $taz_dir
2010 check_for_commit_using_md5sum
2011 else
2012 pkg=$(echo $INCOMING_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
2013 [ "$pkg" ] || pkg=$(echo $PACKAGES_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
2014 if [ "$pkg" ]; then
2015 get_pkg_files $pkg
2016 check_for_commit_using_md5sum
2017 rm -r $pkg_files_dir
2018 else
2019 set_commited
2020 fi
2021 fi
2022 [ "$forced" ] || echo $PACKAGE >> $tmp/checked
2023 done
2024 return
2025 }
2027 gen_cook_list()
2028 {
2029 report step "Scanning wok"
2030 if [ "$pkg" ]; then
2031 scan $pkg --cooklist
2032 elif [ "$LIST" ]; then
2033 scan `cat $LIST` --cooklist
2034 else
2035 scan `cat $cooklist` --cooklist
2036 fi
2037 report end-step
2039 [ -s $tmp/checked ] || [ -s $tmp/cooklist ] || return
2041 # Core toolchain should not be cooked unless cook-toolchain is used.
2042 if ! [ -f /etc/config.site.tmptoolchain ] ; then
2043 for PACKAGE in $(scan gcc --look_for=all --with_args --with_wanted); do
2044 grep -q ^$PACKAGE$ $blocked || echo $PACKAGE >> $blocked
2045 done
2046 fi
2048 if [ -s $commit ] && [ "$COMMAND" != gen-cooklist ]; then
2049 for PACKAGE in $(cat $commit); do
2050 WANTED="$(look_for_wanted)"
2051 if [ "$WANTED" ]; then
2052 grep -q ^$WANTED$ $broken $cooklist $blocked $commit && continue
2053 fi
2054 grep -q ^$PACKAGE$ $blocked $cooklist && continue
2055 echo $PACKAGE >> $cooklist
2056 done
2057 fi
2058 sort_cooklist
2059 }
2061 sort_cooklist()
2062 {
2063 if [ "$(sed 1!d $cookorder)" = "#PlanSort" ]; then
2064 sed 1d -i $cookorder
2065 plan_regen_cookorder=yes
2066 fi
2067 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
2068 [ "$plan_regen_cookorder" ] && sort_db
2069 report step "Generating cooklist"
2070 if [ -f "$tmp/checked" ]; then
2071 rm -f $tmp/cooklist
2072 cat $tmp/checked | while read PACKAGE; do
2073 grep -q ^$PACKAGE$ $cooklist && echo $PACKAGE >> $tmp/cooklist
2074 done
2075 elif ! [ "$COMMAND" = gen-cooklist ]; then
2076 cat $blocked | while read PACKAGE; do
2077 sed "/^$PACKAGE/d" -i $tmp/cooklist
2078 done
2079 fi
2080 report end-step
2081 [ -s $tmp/cooklist ] || return
2083 report step "Sorting cooklist"
2084 for PACKAGE in $(cat $tmp/cooklist); do
2085 WANTED="$(look_for_wanted)"
2086 [ "$WANTED" ] || continue
2087 if grep -q ^$WANTED$ $broken $tmp/cooklist; then
2088 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2089 elif [ ! -d $WOK/$WANTED/install ]; then
2090 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2091 echo $WANTED >> $tmp/cooklist
2092 fi
2093 done
2095 # Use cookorder.txt to sort cooklist.
2096 if [ -s $tmp/cooklist ]; then
2097 cat $cookorder | while read PACKAGE; do
2098 if grep -q ^$PACKAGE$ $tmp/cooklist; then
2099 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2100 echo $PACKAGE >> $tmp/cooklist.tmp
2101 fi
2102 done
2104 # Remaining packages in cooklist are those without compile_rules.
2105 # They can be cooked first in any order.
2106 if [ -f $tmp/cooklist.tmp ]; then
2107 cat $tmp/cooklist.tmp >> $tmp/cooklist
2108 rm $tmp/cooklist.tmp
2109 fi
2111 cat $tmp/cooklist
2112 [ "$LIST" ] || cat $tmp/cooklist > $cooklist
2113 fi
2115 report end-step
2116 }
2118 look_for_missing_pkg()
2119 {
2120 for pkg in $(cat $PACKAGES_REPOSITORY/$1); do
2121 grep -q ^$pkg$ $INCOMING_REPOSITORY/packages.txt \
2122 $PACKAGES_REPOSITORY/packages.txt || \
2123 continue
2124 echo $pkg
2125 done
2126 }
2128 check_for_incoming()
2129 {
2130 report step "Checking that all packages were cooked OK"
2131 [ -s $INCOMING_REPOSITORY/packages.desc ] || {
2132 echo "No packages in $INCOMING_REPOSITORY."
2133 report end-step; return; }
2134 if [ -s $broken ]; then
2135 missingpkg=$(look_for_missing_pkg broken)
2136 if [ "$missingpkg" ]; then
2137 echo "Don't move incoming packages to main repository because these ones are broken:" >&2
2138 echo "$missingpkg"
2139 report end-step
2140 return 1
2141 fi
2142 fi
2143 if [ -s $cooklist ]; then
2144 missingpkg=$(look_for_missing_pkg cooklist)
2145 if [ "$missingpkg" ]; then
2146 echo "Don't move incoming packages to main repository because these ones need to be cooked:" >&2
2147 echo "$missingpkg"
2148 report end-step
2149 return 1
2150 fi
2151 fi
2152 incoming_pkgs="$(cut -f 1 -d '|' $INCOMING_REPOSITORY/packages.desc)"
2153 if ! [ "$forced" ]; then
2154 cooklist=$PACKAGES_REPOSITORY/cooklist
2155 pkg="$incoming_pkgs"
2156 gen_cook_list
2157 if [ -s $cooklist ]; then
2158 missingpkg=$(look_for_missing_pkg cooklist)
2159 if [ "$missingpkg" ]; then
2160 echo "Don't move incoming packages to main repository because these ones need to be cooked:" >&2
2161 echo "$missingpkg"
2162 report end-step
2163 return 1
2164 fi
2165 fi
2166 fi
2168 report step "Moving incoming packages to main repository"
2169 [ "save_wok" ] && mkdir -p $PACKAGES_REPOSITORY/wok
2170 unset EXTRAVERSION
2171 for PACKAGE in $incoming_pkgs; do
2172 prev_VERSION=$(get_pkg_version $PACKAGES_REPOSITORY)
2173 VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
2174 remove_previous_package $PACKAGES_REPOSITORY
2175 echo "Moving $PACKAGE..."
2176 mv -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION.tazpkg $PACKAGES_REPOSITORY
2177 touch $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
2178 previous_tarball=$(grep -m1 ^$PACKAGE:main $SOURCES_REPOSITORY/sources.list | cut -f2)
2179 sed -e "/^$PACKAGE:main/d" \
2180 -e "s/^$PACKAGE:incoming/$PACKAGE:main/" \
2181 -i $SOURCES_REPOSITORY/sources.list
2182 if [ "$previous_tarball" ]; then
2183 grep -q $'\t'$previous_tarball$ $SOURCES_REPOSITORY/sources.list || \
2184 rm -f $SOURCES_REPOSITORY/$previous_tarball
2185 fi
2186 [ "$save_wok" ] &&
2187 copy_cooking_stuff $INCOMING_REPOSITORY/wok $PACKAGE $PACKAGES_REPOSITORY/wok
2188 done
2190 if [ "$save_wok" = tarball ]; then
2191 rm -f $PACKAGES_REPOSITORY/wok.tar.lzma
2192 cd $PACKAGES_REPOSITORY/wok
2193 report step "Generating safe-wok tarball"
2194 tar -c * | lzma e $PACKAGES_REPOSITORY/wok.tar.lzma
2195 report end-step
2196 fi
2198 for file in packages.list packages.equiv packages.md5 packages.desc \
2199 packages.txt; do
2200 echo -n "" > $INCOMING_REPOSITORY/$file
2201 done
2202 rm -r $INCOMING_REPOSITORY/files.list.lzma
2203 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2205 report step "Updating flavors"
2206 if [ -x /usr/bin/tazlito ] || [ -x /usr/bin/clean-chroot ]; then
2207 if ! [ -x /usr/bin/tazlito ]; then
2208 tazpkg get-install tazlito
2209 fi
2211 # Handle cases where tazwok is used into main system;
2212 # Handle cases where SLITAZ_DIR is not /home/slitaz.
2213 [ -L /home/slitaz/flavors ] && rm /home/slitaz/flavors
2214 mkdir -p /home/slitaz
2215 ln -s $LOCAL_REPOSITORY/flavors /home/slitaz/flavors
2217 cd $LOCAL_REPOSITORY/packages
2218 for i in $LOCAL_REPOSITORY/flavors/*; do
2219 [ -d "$i" ] || continue
2220 tazlito pack-flavor ${i##*/}
2221 done
2223 noheader=""
2224 for i in *.flavor; do
2225 tazlito show-flavor $i --brief $noheader
2226 noheader="--noheader"
2227 done > flavors.list
2228 [ -x /usr/bin/clean-chroot ] && clean-chroot
2229 else
2230 echo "Can't create up-to-date flavors because the tazlito package is missing." >&2
2231 fi
2232 report end-step
2233 }
2235 # Usage: move_cooking_stuff source receipt destination
2236 # Make the argument check before calling it!
2237 copy_cooking_stuff()
2238 {
2239 rm -rf $3/$2
2240 mkdir -p $3/$2
2241 cp -a $1/$2/receipt $3/$2
2242 [ -f $1/$2/description.txt ] && \
2243 cp -a $1/$2/description.txt $3/$2
2244 if [ -d "$1/$2/stuff" ]; then
2245 cp -a $1/$2/stuff $3/$2
2246 fi
2247 }
2249 ########################################################################
2250 # TAZWOK MAIN FUNCTIONS
2251 ########################
2253 clean()
2254 {
2255 cd $WOK/$PACKAGE
2256 ls -A $WOK/$PACKAGE | grep -q -v -e ^receipt$ -e ^description.txt$ \
2257 -e ^stuff$ || return
2259 [ "$COMMAND" = clean-wok ] || report step "Cleaning $PACKAGE"
2260 # Check for clean_wok function.
2261 if grep -q ^clean_wok $RECEIPT; then
2262 clean_wok
2263 fi
2264 # Clean should only have a receipt, stuff and optionals desc/md5.
2265 for f in `ls .`
2266 do
2267 case $f in
2268 receipt|stuff|description.txt|md5)
2269 continue ;;
2270 *)
2271 rm -rf $f ;;
2272 esac
2273 done
2274 [ "$COMMAND" != clean-wok ] && report end-step
2275 }
2277 # Configure and make a package with the receipt.
2278 compile_package()
2279 {
2280 check_for_package_on_cmdline
2282 # Include the receipt to get all needed variables and functions
2283 # and cd into the work directory to start the work.
2284 check_for_receipt
2285 source_receipt
2287 # Log the package name and date.
2288 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
2289 echo "package $PACKAGE (compile)" >> $LOG
2291 # Set wanted $src variable to help compiling.
2292 [ ! "$src" ] && set_src_path
2293 check_for_build_depends || return 1
2294 check_for_wanted
2295 unset target
2296 check_for_tarball && check_for_compile_rules
2297 }
2299 # Cook command also include all features to manage lists which keep
2300 # track of wok/packages state.
2301 cook()
2302 {
2303 cook_code=
2304 set_common_path
2305 check_for_receipt
2306 source_receipt
2308 # Define log path and start report.
2309 for i in $(look_for_rwanted) $PACKAGE; do
2310 rm -f $LOCAL_REPOSITORY/log/$i.html
2311 done
2312 report sublog $LOCAL_REPOSITORY/log/$PACKAGE.html
2313 echo "$PACKAGE" > $LOCAL_REPOSITORY/log/package
2314 report step "Cooking $PACKAGE"
2315 report open-bloc
2317 clean $PACKAGE
2318 [ -s $tmp/cooklist ] && sed "/^$PACKAGE$/d" -i $tmp/cooklist
2320 if compile_package; then
2321 remove_src
2322 refresh_packages_from_compile
2323 gen_package
2325 # Update packages-incoming repository.
2326 store_pkgname=$PACKAGE
2327 pkg_repository=$INCOMING_REPOSITORY
2328 update_packages_db
2330 PACKAGE=$store_pkgname
2331 unset store_pkgname
2333 # Upgrade to cooked packages if it was previously installed.
2334 report step "Looking for package(s) to upgrade"
2335 for pkg in $(look_for_rwanted) $PACKAGE; do
2336 if [ -f $INSTALLED/$pkg/receipt ]; then
2337 tazpkg get-install $pkg --forced
2338 fi
2339 done
2340 report end-step
2341 else
2342 set_pkg_broken
2343 cook_code=1
2344 fi
2346 # Remove build_depends in cook mode (if in cooklist, it's done when
2347 # checking build_depends of next package and we remove only unneeded
2348 # packages to keep chroot minimal and gain some time).
2349 if [ "$COMMAND" = cook ]; then
2350 remove_build_depends $MISSING_PACKAGE
2351 [ -x /usr/bin/clean-chroot ] && clean-chroot
2352 fi
2354 # Regen the cooklist if it was planned and command is not cook.
2355 [ "$regen_cooklist" ] && unset regen_cooklist &&
2356 [ "$COMMAND" != cook ] && sort_cooklist
2358 # Some hacks to set the bloc & function status as failed if cook has
2359 # failed.
2360 report_return_code=$cook_code
2361 report close-bloc
2362 report end-sublog
2363 rm -f $LOCAL_REPOSITORY/log/package
2364 return $cook_code
2365 }
2367 cook_list()
2368 {
2369 if [ -s $tmp/cooklist ]; then
2370 if [ -f /usr/bin/tazchroot ]; then
2371 # Note : options -main variables- are automatically kept by
2372 # the sub-applications tazchroot/tazwok; as well as report data.
2373 cd $LOCAL_REPOSITORY
2374 [ ! -f tazchroot.conf ] && configure_tazchroot
2375 tazchroot tazwok cook-list --SLITAZ_DIR=$SLITAZ_DIR --SLITAZ_VERSION=$SLITAZ_VERSION ${undigest:+ --undigest=$undigest}
2376 return
2377 fi
2378 while [ -s $tmp/cooklist ]; do
2379 PACKAGE=$(sed 1!d $tmp/cooklist)
2380 cook
2381 done
2382 remove_build_depends $MISSING_PACKAGE $remove_later
2383 [ -x /usr/bin/clean-chroot ] && clean-chroot
2384 else
2385 echo "Nothing to cook."
2386 return
2387 fi
2388 }
2390 configure_tazchroot()
2391 {
2392 cat > $LOCAL_REPOSITORY/tazchroot.conf << EOF
2393 # Tazchroot configuration file - created by tazwok.
2395 # Local repository definition.
2396 SLITAZ_DIR=$SLITAZ_DIR
2397 SLITAZ_VERSION=$SLITAZ_VERSION
2398 LOCAL_REPOSITORY=$SLITAZ_DIR/${undigest:-$SLITAZ_VERSION}
2399 ${USE_ONLINE_PKG:+USE_ONLINE_PKG=$USE_ONLINE_PKG}
2400 ${undigest:+undigest=$undigest}
2401 ${ref_USE_ONLINE_PKG:+ref_USE_ONLINE_PKG=$ref_USE_ONLINE_PKG}
2403 # Chroot path.
2404 # You can use a chroot into /tmp if it's mounted in RAM
2405 # to speed-up the process, be sure you have a free GB.
2406 # (minimal chroot is like 150~200MB, can be a lot more during cook)
2407 # chroot_dir=/tmp/chroot-${undigest:-$SLITAZ_VERSION}
2408 chroot_dir=\$LOCAL_REPOSITORY/chroot
2410 # Default scripts path (these scripts are added to the
2411 # $chroot_dir/usr/bin and can be called with tazchroot script).
2412 script_dir=/usr/lib/slitaz/chroot-scripts/tazwok
2414 # List of directories to mount.
2415 list_dir="$LOCAL_REPOSITORY
2416 $SLITAZ_LOG$( [ "$undigest" ] && echo -e "\n$SLITAZ_DIR/$SLITAZ_VERSION/packages" )"
2418 create_chroot()
2419 {
2420 mkdir -p \$chroot_dir
2421 for pkg in \$(tazwok build-depends toolchain --SLITAZ_DIR=\$SLITAZ_DIR --SLITAZ_VERSION=\$SLITAZ_VERSION${undigest:+ --undigest=\$undigest}); do
2422 tazpkg get-install \$pkg --root="\$chroot_dir"
2423 done
2425 # Store list of installed packages needed by cleanchroot.
2426 ls -1 \$chroot_dir/\$INSTALLED > \$chroot_dir/\$LOCALSTATE/chroot-pkgs
2428 sed -e "s~^SLITAZ_DIR=.*~SLITAZ_DIR=\$SLITAZ_DIR~" \\
2429 -e "s/^SLITAZ_VERSION=.*/SLITAZ_VERSION=\$SLITAZ_VERSION/" \\
2430 -i \$chroot_dir/etc/slitaz/slitaz.conf
2431 echo \$SLITAZ_VERSION > \$chroot_dir/etc/slitaz-release
2432 $( [ "$undigest" ] && echo ' echo "undigest='"$undigest"'" >> $chroot_dir/etc/slitaz/tazwok.conf')
2433 sed 's/LC_ALL/LC_ALL=POSIX/' -i \$chroot_dir/etc/profile
2435 # The build bot may run in a sandbox: link sandbox lockfile.
2436 ln -s \$LOCAL_REPOSITORY/sandbox/proc/1 \$chroot_dir/proc/1
2437 }
2439 mount_chroot()
2440 {
2441 cp -a /etc/resolv.conf \$chroot_dir/etc/resolv.conf
2442 $( if [ "$USE_ONLINE_PKG" ]; then
2443 echo ' echo "$USE_ONLINE_PKG" > $chroot_dir$LOCALSTATE/mirror'
2444 else
2445 echo ' echo "$LOCAL_REPOSITORY/packages" > $chroot_dir$LOCALSTATE/mirror'
2446 fi
2447 )
2448 mkdir -p \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming
2449 echo "\$LOCAL_REPOSITORY/packages-incoming" > \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming/mirror
2450 $( if [ "$undigest" ]; then
2451 echo ' mkdir -p $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION'
2452 if [ "$ref_USE_ONLINE_PKG" ]; then
2453 echo ' echo "$ref_USE_ONLINE_PKG" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror'
2454 else
2455 echo ' echo "$ref_LOCAL_REPOSITORY/packages" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror'
2456 fi
2457 fi )
2458 echo -e "\${LOCAL_REPOSITORY##*/}-incoming\nmain" > \$chroot_dir\$LOCALSTATE/priority
2459 mount -o bind /proc \$chroot_dir/proc
2460 mount -o bind /sys \$chroot_dir/sys
2461 mount -o bind /dev/pts \$chroot_dir/dev/pts
2462 mount -o bind /dev/shm \$chroot_dir/dev/shm
2463 for dir in \$list_dir; do
2464 mkdir -p \$dir \$chroot_dir\$dir
2465 mount \$dir \$chroot_dir\$dir
2466 done
2467 }
2469 umount_chroot()
2470 {
2471 for dir in \$list_dir; do
2472 umount \$chroot_dir\$dir
2473 done
2474 umount \$chroot_dir/dev/shm
2475 umount \$chroot_dir/dev/pts
2476 umount \$chroot_dir/sys
2477 umount \$chroot_dir/proc
2478 }
2479 EOF
2480 }
2482 ########################################################################
2483 ######################### END OF NEW FUNCTIONS #########################
2484 ########################################################################
2486 # List packages providing a virtual package.
2487 whoprovide()
2488 {
2489 local i;
2490 for i in $(fgrep -l PROVIDE $WOK/*/receipt); do
2491 . $i
2492 case " $PROVIDE " in
2493 *\ $1\ *|*\ $1:*) echo $(basename $(dirname $i));;
2494 esac
2495 done
2496 }
2498 ########################################################################
2499 # TAZWOK COMMANDS
2500 ########################
2502 case "$COMMAND" in
2503 stats)
2504 # Tazwok general statistics from the wok config file.
2505 #
2506 get_tazwok_config
2507 echo -e "\n\033[1mTazwok configuration statistics\033[0m
2508 ================================================================================
2509 Wok directory : $WOK
2510 Packages repository : $PACKAGES_REPOSITORY
2511 Incoming repository : $INCOMING_REPOSITORY
2512 Sources repository : $SOURCES_REPOSITORY
2513 Log directory : $LOCAL_REPOSITORY/log
2514 Packages in the wok : `ls -1 $WOK | wc -l`
2515 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2516 Incoming packages : `ls -1 $INCOMING_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2517 ================================================================================\n"
2518 ;;
2519 edit)
2520 get_tazwok_config
2521 check_for_package_on_cmdline
2522 check_for_receipt
2523 $EDITOR $WOK/$PACKAGE/receipt
2524 ;;
2525 build-depends)
2526 # List dependencies to rebuild wok, or only a package.
2527 get_tazwok_config
2528 report(){ : ; }
2529 if [ ! "$PACKAGE" ] || [ "$PACKAGE" = toolchain ]; then
2530 scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
2531 --look_for=dep --with_dev --with_args
2532 else
2533 check_for_package_on_cmdline
2534 scan $PACKAGE --look_for=bdep --with_dev
2535 fi
2536 ;;
2537 gen-cooklist)
2538 check_root
2539 get_options_list="pkg"
2540 get_tazwok_config
2541 report(){ : ; }
2542 if ! [ "$pkg" ]; then
2543 if [ ! "$LIST" ] || [ "$LIST" = toolchain ]; then
2544 pkg="$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA"
2545 else
2546 check_for_list
2547 fi
2548 fi
2549 gen_cook_list
2550 ;;
2551 check-depends)
2552 # Check package depends /!\.
2553 get_tazwok_config
2554 echo ""
2555 echo -e "\033[1mCheck every receipt for DEPENDS - doesn't scan ELF files\033[0m
2556 ================================================================================"
2557 TMPDIR=/tmp/tazwok$$
2558 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
2560 # Build ALL_DEPENDS variable.
2561 scan_dep()
2562 {
2563 local i
2564 ALL_DEPENDS="$ALL_DEPENDS$PACKAGE "
2565 for i in $DEPENDS $SUGGESTED ; do
2566 case " $ALL_DEPENDS " in
2567 *\ $i\ *) continue;;
2568 esac
2569 [ -d $WOK/$i ] || {
2570 ALL_DEPENDS="$ALL_DEPENDS$i "
2571 continue
2572 }
2573 DEPENDS=""
2574 SUGGESTED=""
2575 . $WOK/$i/receipt
2576 scan_dep
2577 done
2578 }
2580 # Check for ELF file.
2581 is_elf()
2582 {
2583 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
2584 }
2586 # Print shared library dependencies.
2587 ldd()
2588 {
2589 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
2590 }
2592 mkdir $TMPDIR
2593 cd $TMPDIR
2594 for i in $LOCALSTATE/files.list.lzma \
2595 $LOCALSTATE/undigest/*/files.list.lzma ; do
2596 [ -f $i ] && lzma d $i -so >> files.list
2597 done
2598 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
2599 tazpkg extract $pkg > /dev/null 2>&1
2600 . */receipt
2601 ALL_DEPENDS="$DEFAULT_DEPENDS "
2602 scan_dep
2603 find */fs -type f | while read file ; do
2604 is_elf $file || continue
2605 case "$file" in
2606 *.o|*.ko|*.ko.gz) continue;;
2607 esac
2608 ldd $file | while read lib rem; do
2609 case "$lib" in
2610 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
2611 continue;;
2612 esac
2613 for dep in $(fgrep $lib files.list | cut -d: -f1); do
2614 case " $ALL_DEPENDS " in
2615 *\ $dep\ *) continue 2;;
2616 esac
2617 for vdep in $(fgrep $dep $LOCALSTATE/packages.equiv | cut -d= -f1); do
2618 case " $ALL_DEPENDS " in
2619 *\ $vdep\ *) continue 3;;
2620 esac
2621 done
2622 done
2623 [ -n "$dep" ] || dep="UNKNOWN"
2624 echo "$(basename $pkg): ${file#*fs} depends on package $dep for the shared library $lib"
2625 done
2626 done
2627 rm -rf */
2628 done
2629 cd /tmp
2630 rm -rf $TMPDIR
2631 ;;
2632 check)
2633 # Check wok consistency.
2634 get_tazwok_config
2635 echo ""
2636 echo -e "\033[1mWok and packages checking\033[0m
2637 ================================================================================"
2638 cd $WOK
2639 for pkg in $(ls)
2640 do
2641 [ -f $pkg/receipt ] || continue
2642 RECEIPT= $pkg/receipt
2643 source_receipt
2644 [ "$PACKAGE" = "$pkg" ] || echo "Package $PACKAGE should be $pkg" >&2
2645 [ -n "$VERSION" ] || echo "Package $PACKAGE has no VERSION" >&2
2646 [ -n "$PACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded PACKED_SIZE" >&2
2647 [ -n "$UNPACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded UNPACKED_SIZE" >&2
2648 [ -n "$EXTRAVERSION" ] && echo "Package $PACKAGE has hardcoded EXTRAVERSION" >&2
2649 if [ -n "$WANTED" ]; then
2650 if [ ! -f $WANTED/receipt ]; then
2651 echo "Package $PACKAGE wants unknown $WANTED package" >&2
2652 else
2653 BASEVERSION=$(. $WANTED/receipt ; echo $VERSION)
2654 if [ "$VERSION" = "$WANTED" ]; then
2655 # BASEVERSION is computed in receipt
2656 fgrep -q '_pkg=' $pkg/receipt &&
2657 BASEVERSION=$VERSION
2658 fi
2659 if [ "$VERSION" != "$BASEVERSION" ]; then
2660 echo "Package $PACKAGE ($VERSION) wants $WANTED ($BASEVERSION)" >&2
2661 fi
2662 fi
2663 fi
2665 if [ -n "$CATEGORY" ]; then
2666 case " $(echo $CATEGORIES) " in
2667 *\ $CATEGORY\ *);;
2668 *) echo "Package $PACKAGE has an invalid CATEGORY" >&2;;
2669 esac
2670 else
2671 echo"Package $PACKAGE has no CATEGORY" >&2
2672 fi
2673 [ -n "$SHORT_DESC" ] || echo "Package $PACKAGE has no SHORT_DESC" >&2
2674 [ -n "$MAINTAINER" ] || echo "Package $PACKAGE has no MAINTAINER" >&2
2675 case "$WGET_URL" in
2676 ftp*|http*) busybox wget -s $WGET_URL 2> /dev/null ||
2677 echo "Package $PACKAGE has a wrong WGET_URL" >&2;;
2678 '') ;;
2679 *) echo "Package $PACKAGE has an invalid WGET_URL" >&2;;
2680 esac
2681 case "$WEB_SITE" in
2682 ftp*|http*);;
2683 '') echo "Package $PACKAGE has no WEB_SITE" >&2;;
2684 *) echo "Package $PACKAGE has an invalid WEB_SITE" >&2;;
2685 esac
2686 case "$MAINTAINER" in
2687 *\<*|*\>*) echo "Package $PACKAGE has an invalid MAINTAINER: $MAINTAINER" >&2;;
2688 esac
2689 case "$MAINTAINER" in
2690 *@*);;
2691 *) echo "Package $PACKAGE MAINTAINER is not an email address" >&2;;
2692 esac
2693 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2694 for i in $DEPENDS; do
2695 [ -d $i ] && continue
2696 [ -n "$(whoprovide $i)" ] && continue
2697 echo -e "$MSG $i"
2698 MSG=""
2699 done
2700 MSG="Missing build dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2701 for i in $BUILD_DEPENDS; do
2702 [ -d $i ] && continue
2703 [ -n "$(whoprovide $i)" ] && continue
2704 echo -e "$MSG $i"
2705 MSG=""
2706 done
2707 MSG="Dependency loop between $PACKAGE and :\n"
2708 ALL_DEPS=""
2709 check_for_deps_loop $PACKAGE $DEPENDS
2710 [ -d $WOK/$pkg/taz ] && for i in $BUILD_DEPENDS; do
2711 [ $WOK/$pkg/taz -nt $INSTALLED/$i/files.list ] && continue
2712 echo "$pkg should be rebuilt after $i installation"
2713 done
2714 done
2715 ;;
2716 list)
2717 # List packages in wok directory. User can specify a category.
2718 #
2719 get_tazwok_config
2720 if [ "$2" = "category" ]; then
2721 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
2722 exit 0
2723 fi
2724 # Check for an asked category.
2725 if [ -n "$2" ]; then
2726 ASKED_CATEGORY=$2
2727 echo ""
2728 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
2729 echo "================================================================================"
2730 for pkg in $WOK/*
2731 do
2732 [ ! -f $pkg/receipt ] && continue
2733 . $pkg/receipt
2734 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
2735 echo -n "$PACKAGE"
2736 echo -e "\033[28G $VERSION"
2737 packages=$(($packages+1))
2738 fi
2739 done
2740 echo "================================================================================"
2741 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
2742 else
2743 # By default list all packages and version.
2744 echo ""
2745 echo -e "\033[1mList of packages in the wok\033[0m"
2746 echo "================================================================================"
2747 for pkg in $WOK/*
2748 do
2749 [ ! -f $pkg/receipt ] && continue
2750 . $pkg/receipt
2751 echo -n "$PACKAGE"
2752 echo -en "\033[28G $VERSION"
2753 echo -e "\033[42G $CATEGORY"
2754 packages=$(($packages+1))
2755 done
2756 echo "================================================================================"
2757 echo -e "$packages packages available in the wok.\n"
2758 fi
2759 ;;
2760 info)
2761 # Information about a package.
2762 #
2763 get_tazwok_config
2764 check_for_package_on_cmdline
2765 check_for_receipt
2766 . $WOK/$PACKAGE/receipt
2767 echo ""
2768 echo -e "\033[1mTazwok package information\033[0m
2769 ================================================================================
2770 Package : $PACKAGE
2771 Version : $VERSION
2772 Category : $CATEGORY
2773 Short desc : $SHORT_DESC
2774 Maintainer : $MAINTAINER"
2775 if [ ! "$WEB_SITE" = "" ]; then
2776 echo "Web site : $WEB_SITE"
2777 fi
2778 if [ ! "$DEPENDS" = "" ]; then
2779 echo "Depends : $DEPENDS"
2780 fi
2781 if [ ! "$WANTED" = "" ]; then
2782 echo "Wanted src : $WANTED"
2783 fi
2784 echo "================================================================================"
2785 echo ""
2786 ;;
2787 check-log)
2788 # We just cat the file log to view process info.
2789 #
2790 get_tazwok_config
2791 if [ ! -f "$LOG" ]; then
2792 echo -e "\nNo process log found. The package is probably not cooked.\n" >&2
2793 exit 1
2794 else
2795 echo ""
2796 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
2797 echo "================================================================================"
2798 cat $LOG
2799 echo "================================================================================"
2800 echo ""
2801 if [ -s "$WOK/$PACKAGE/warning.txt" ]; then
2802 echo -e "\033[1mCook warning(s) for :\033[0m $PACKAGE"
2803 echo "================================================================================"
2804 cat "$WOK/$PACKAGE/warning.txt"
2805 echo "================================================================================"
2806 echo ""
2807 fi
2808 fi
2809 ;;
2810 search)
2811 # Search for a package by pattern or name.
2812 #
2813 get_tazwok_config
2814 if [ -z "$2" ]; then
2815 echo -e "\nPlease specify a pattern or a package name to search." >&2
2816 echo -e "Example : 'tazwok search gcc'.\n" >&2
2817 exit 1
2818 fi
2819 echo ""
2820 echo -e "\033[1mSearch result for :\033[0m $2"
2821 echo "================================================================================"
2822 list=`ls -1 $WOK | fgrep $2`
2823 for pkg in $list
2824 do
2825 . $WOK/$pkg/receipt
2826 echo -n "$PACKAGE "
2827 echo -en "\033[24G $VERSION"
2828 echo -e "\033[42G $CATEGORY"
2829 packages=$(($PACKAGEs+1))
2830 done
2831 echo "================================================================================"
2832 echo "$packages packages found for : $2"
2833 echo ""
2834 ;;
2835 compile)
2836 # Configure and make a package with the receipt.
2837 #
2838 get_tazwok_config
2839 source_lib report
2840 report start
2841 compile_package
2842 ;;
2843 genpkg)
2844 # Generate a package.
2845 #
2846 get_tazwok_config
2847 source_lib report
2848 report start
2849 gen_package
2850 ;;
2851 cook)
2852 # Compile and generate a package. Just execute tazwok with
2853 # the good commands.
2854 #
2855 check_root
2856 get_tazwok_config
2857 source_lib report
2858 report start
2859 update_wan_db
2860 check_for_commit
2861 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
2862 [ "$plan_sort_wandb" ] && sort -o $wan_db $wan_db && unset plan_sort_wandb
2863 if [ "$plan_regen_cookorder" ]; then
2864 [ "$(sed 1!d $cookorder)" = "#PlanSort" ] || \
2865 sed 1i"#PlanSort" -i $cookorder
2866 fi
2867 cook
2868 ;;
2869 sort-cooklist)
2870 check_root
2871 get_tazwok_config
2872 check_for_list
2873 report(){ : ; }
2874 # When using sort-cooklist, the script should behave as for gen-cooklist
2875 # The only difference between these two is where the output is sent.
2876 COMMAND=gen-cooklist
2877 gen_cook_list
2878 cp -af $tmp/cooklist $LIST
2879 ;;
2880 cook-list)
2881 # Cook all packages listed in a file or in default cooklist.
2882 check_root
2883 get_options_list="pkg forced"
2884 get_tazwok_config
2885 source_lib report
2886 report start
2887 if ! [ "$pkg" ]; then
2888 [ "$LIST" ] && check_for_list
2889 fi
2890 gen_cook_list
2891 cook_list
2892 ;;
2893 clean)
2894 # Clean up a package work directory + those which want it.
2895 #
2896 get_tazwok_config
2897 check_for_package_on_cmdline
2898 check_for_receipt
2899 source_lib report
2900 report start
2901 . $RECEIPT
2902 clean
2903 ;;
2904 gen-clean-wok)
2905 # Generate a clean wok from the current wok by copying all receipts
2906 # and stuff directory.
2907 #
2908 get_tazwok_config
2909 source_lib report
2910 report start
2911 if [ -z "$ARG" ]; then
2912 echo -e "\nPlease specify the destination for the new clean wok.\n" >&2
2913 exit 1
2914 else
2915 dest=$ARG
2916 mkdir -p $dest
2917 fi
2918 report step "Creating clean wok in : $dest"
2919 for pkg in `ls -1 $WOK`
2920 do
2921 copy_cooking_stuff $WOK $pkg $dest
2922 done
2923 [ -d $WOK/.hg ] && cp -a $WOK/.hg $dest
2924 report end-step
2925 echo "Packages cleaned : `ls -1 $dest | wc -l`"
2926 echo ""
2927 ;;
2928 clean-wok)
2929 # Clean all packages in the work directory.
2930 #
2931 get_tazwok_config
2932 source_lib report
2933 report start
2934 report step "Cleaning wok"
2935 for PACKAGE in `ls -1 $WOK`
2936 do
2937 set_common_path
2938 source_receipt
2939 clean
2940 done
2941 echo "`ls -1 $WOK | wc -l` packages cleaned."
2942 ;;
2943 clean-src)
2944 # Remove tarball unrelated to wok receipts from src repo.
2945 check_root
2946 get_options_list="forced"
2947 get_tazwok_config
2948 cd $SOURCES_REPOSITORY
2949 echo -n "Checking $SOURCES_REPOSITORY..."
2950 for TARBALL in *; do
2951 [ "$TARBALL" = sources.list ] && continue
2952 grep -q $'\t'$TARBALL$ $SOURCES_REPOSITORY/sources.list || \
2953 echo $TARBALL >> $tmp/obsolete
2954 done
2955 status
2956 if ! [ -f $tmp/obsolete ]; then
2957 echo "No sources need to be removed."
2958 exit 1
2959 fi
2960 echo ""
2961 echo -e "\033[1mObsolete/unrelated-to-wok sources :\033[0m"
2962 horizontal_line
2963 cat $tmp/obsolete
2964 horizontal_line
2965 echo "$(wc -l $tmp/obsolete | cut -f1 -d' ') tarballs to remove."
2966 echo ""
2967 echo -n "Please confirm before removing (type uppercase YES): "
2968 read answer
2969 if [ "$answer" = YES ]; then
2970 echo -n "Removing old sources..."
2971 cat $tmp/obsolete | while read i; do
2972 rm -f $SOURCES_REPOSITORY/$i
2973 done
2974 status
2975 fi
2976 ;;
2977 gen-list)
2978 get_tazwok_config
2979 if [ "$2" ]; then
2980 if [ -d "$2" ]; then
2981 pkg_repository=$2
2982 else
2983 echo -e "\nUnable to find directory : $2\n" >&2
2984 exit 1
2985 fi
2986 fi
2988 source_lib report
2989 report start
2990 if [ "$pkg_repository" ]; then
2991 gen_packages_db
2992 else
2993 pkg_repository=$PACKAGES_REPOSITORY && gen_packages_db
2994 pkg_repository=$INCOMING_REPOSITORY && gen_packages_db
2995 fi
2996 ;;
2997 check-list)
2998 # The directory to move into by default is the repository,
2999 # if $2 is not empty cd into $2.
3000 #
3001 get_tazwok_config
3002 if [ "$2" ]; then
3003 if [ -d "$2" ]; then
3004 pkg_repository=$2
3005 else
3006 echo -e "\nUnable to find directory : $2\n" >&2
3007 exit 1
3008 fi
3009 fi
3011 source_lib report
3012 report start
3013 if [ "$pkg_repository" ]; then
3014 update_packages_db
3015 else
3016 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
3017 pkg_repository=$INCOMING_REPOSITORY && update_packages_db
3018 fi
3019 ;;
3020 new-tree)
3021 # Just create a few directories and generate an empty receipt to prepare
3022 # the creation of a new package.
3023 #
3024 get_tazwok_config
3025 check_for_package_on_cmdline
3026 clean_wok=$LOCAL_REPOSITORY/clean-wok
3027 if [ -d $clean_wok/$PACKAGE ]; then
3028 echo -e "\n$PACKAGE package tree already exists.\n" >&2
3029 exit 1
3030 fi
3031 echo "Creating : $clean_wok/$PACKAGE"
3032 mkdir $clean_wok/$PACKAGE
3033 cd $clean_wok/$PACKAGE
3034 echo -n "Preparing the receipt..."
3035 #
3036 # Default receipt begin.
3037 #
3038 echo "# SliTaz package receipt." > receipt
3039 echo "" >> receipt
3040 echo "PACKAGE=\"$PACKAGE\"" >> receipt
3041 # Finish the empty receipt.
3042 cat >> receipt << "EOF"
3043 VERSION=""
3044 CATEGORY=""
3045 SHORT_DESC=""
3046 MAINTAINER=""
3047 DEPENDS=""
3048 TARBALL="$PACKAGE-$VERSION.tar.gz"
3049 WEB_SITE=""
3050 WGET_URL=""
3052 # Rules to configure and make the package.
3053 compile_rules()
3054 {
3055 cd $src
3056 ./configure && make && make install
3057 }
3059 # Rules to gen a SliTaz package suitable for Tazpkg.
3060 genpkg_rules()
3061 {
3062 mkdir -p $fs/usr
3063 cp -a $_pkg/usr/bin $fs/usr
3064 }
3066 EOF
3067 #
3068 # Default receipt end.
3069 #
3070 status
3071 # Interactive mode, asking and seding.
3072 if [ "$3" = "--interactive" ]; then
3073 echo "Entering interactive mode..."
3074 echo "================================================================================"
3075 echo "Package : $PACKAGE"
3076 # Version.
3077 echo -n "Version : " ; read anser
3078 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
3079 # Category.
3080 echo -n "Category : " ; read anser
3081 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
3082 # Short description.
3083 echo -n "Short desc : " ; read anser
3084 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
3085 # Maintainer.
3086 echo -n "Maintainer : " ; read anser
3087 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
3088 # Web site.
3089 echo -n "Web site : " ; read anser
3090 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
3091 echo ""
3092 # Wget URL.
3093 echo "Wget URL to download source tarball."
3094 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
3095 echo -n "Wget url : " ; read anser
3096 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
3097 # Ask for a stuff dir.
3098 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
3099 if [ "$anser" = "y" ]; then
3100 echo -n "Creating the stuff directory..."
3101 mkdir stuff && status
3102 fi
3103 # Ask for a description file.
3104 echo -n "Are you going to write a description ? (y/N) : " ; read anser
3105 if [ "$anser" = "y" ]; then
3106 echo -n "Creating the description.txt file..."
3107 echo "" > description.txt && status
3108 fi
3109 echo "================================================================================"
3110 echo ""
3111 fi
3112 ;;
3113 remove)
3114 # Remove a package from the wok.
3115 #
3116 get_tazwok_config
3117 check_for_package_on_cmdline
3118 echo ""
3119 echo -n "Please confirm deletion (y/N) : "; read anser
3120 if [ "$anser" = "y" ]; then
3121 echo -n "Removing $PACKAGE..."
3122 rm -rf $WOK/$PACKAGE && status
3123 echo ""
3124 fi
3125 ;;
3126 update-wok)
3127 # Pull and update a Hg wok.
3128 get_options_list="local"
3129 get_tazwok_config
3130 source_lib report
3131 report start
3132 clean_wok=$LOCAL_REPOSITORY/clean-wok
3133 cd $clean_wok
3134 if ! [ "$local" ]; then
3135 if [ "$WOK_UPDATE_METHOD" = hg ]; then
3136 if ! [ -f "$INSTALLED/mercurial/receipt" ]; then
3138 # Auto-install only if we are in a cook chroot.
3139 if [ -x /usr/bin/clean-chroot ]; then
3140 tazpkg get-install mercurial
3141 else
3142 echo "" >&2
3143 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
3144 echo "">&2
3145 exit 1
3146 fi
3147 fi
3149 report step "Getting wok changes using hg"
3150 if [ -d .hg ]; then
3151 hg pull -u || exit 1
3152 else
3153 hg clone $HG_WOK . || exit 1
3154 fi
3155 report end-step
3156 [ -x /usr/bin/clean-chroot ] && clean-chroot
3157 else
3158 report step "Getting wok changes using tarball"
3159 { mkdir .tmp && cd .tmp
3160 wget "$TARBALL_WOK" &&
3161 case $TARBALL_WOK in
3162 *bz2) tar xjf *.bz2 -C wok; rm *.bz2;;
3163 *lzma) unlzma -c *.lzma | tar xf - -C wok; rm *.lzma ;;
3164 *gz) tar xzf *.gz -C wok; rm*.gz ;;
3165 esac &&
3166 rm -r $(ls -d $clean_wok/*) &&
3167 cp -a wok/* $clean_wok &&
3168 cd .. &&
3169 rm -r .tmp
3170 } || { echo "That's not cool: it fails!" >&2
3171 report end-step
3172 exit 1; }
3173 report end-step
3174 fi
3175 fi
3176 report step "Appending changes to wok"
3178 # Handle removed files/dir.
3179 cd $WOK
3180 for dir in *; do
3181 [ -d "$clean_wok/$dir" ] || rm -rf $dir
3182 done
3183 for file in */receipt */description.txt; do
3184 [ -f "$clean_wok/$file" ] || rm -rf $file
3185 done
3186 for i in $(find */stuff 2>/dev/null); do
3187 [ -e "$clean_wok/$i" ] || rm -rf $i
3188 done
3190 cp -a $clean_wok/* $WOK
3191 report end-step
3192 ;;
3193 maintainers)
3194 get_tazwok_config
3195 echo ""
3196 echo "List of maintainers for: $WOK"
3197 echo "================================================================================"
3198 touch /tmp/slitaz-maintainers
3199 for pkg in $WOK/*
3200 do
3201 . $pkg/receipt
3202 if ! fgrep -q "$MAINTAINER" /tmp/slitaz-maintainers; then
3203 echo "$MAINTAINER" >> /tmp/slitaz-maintainers
3204 echo "$MAINTAINER"
3205 fi
3206 done
3207 echo "================================================================================"
3208 echo "Maintainers: `cat /tmp/slitaz-maintainers | wc -l`"
3209 echo ""
3210 # Remove tmp files
3211 rm -f /tmp/slitaz-maintainers
3212 ;;
3213 maintained-by)
3214 # Search for packages maintained by a contributor.
3215 get_tazwok_config
3216 if [ ! -n "$2" ]; then
3217 echo "Specify a name or email of a maintainer." >&2
3218 exit 1
3219 fi
3220 echo "Maintainer packages"
3221 echo "================================================================================"
3222 for pkg in $WOK/*
3223 do
3224 . $pkg/receipt
3225 if echo "$MAINTAINER" | fgrep -q "$2"; then
3226 echo "$PACKAGE"
3227 packages=$(($PACKAGEs+1))
3228 fi
3229 done
3230 echo "================================================================================"
3231 echo "Packages maintained by $2: $PACKAGEs"
3232 echo ""
3233 ;;
3234 tags)
3235 get_tazwok_config
3236 echo -e "\n\033[1mTags list :\033[0m"
3237 horizontal_line
3238 cd $WOK
3239 for i in */receipt; do
3240 unset TAGS
3241 source $i
3242 for t in $TAGS; do
3243 grep -q ^$t$ $tmp/tags && continue
3244 echo $t | tee -a $tmp/tags
3245 done
3246 done
3247 horizontal_line
3248 echo "$(wc -l $tmp/tags | cut -f1 -d ' ') tags listed."
3249 ;;
3250 check-src)
3251 # Verify if upstream package is still available.
3252 #
3253 get_tazwok_config
3254 check_for_package_on_cmdline
3255 check_for_receipt
3256 source_receipt
3257 check_src()
3258 {
3259 for url in $@; do
3260 busybox wget -s $url 2>/dev/null && break
3261 done
3262 }
3263 if [ "$WGET_URL" ];then
3264 echo -n "$PACKAGE : "
3265 check_src $WGET_URL
3266 status
3267 else
3268 echo "No tarball to check for $PACKAGE"
3269 fi
3270 ;;
3271 gen-src)
3272 get_tazwok_config
3273 if [ "$2" ]; then
3274 if [ -d "$2" ]; then
3275 src_repository=$2
3276 else
3277 echo -e "\nUnable to find directory : $2\n" >&2
3278 exit 1
3279 fi
3280 fi
3281 echo -n "Rebuilding sources.list file"
3282 [ $src_repository ] || src_repository="$SOURCES_REPOSITORY"
3283 gen_sources_list $src_repository
3284 status
3285 ;;
3286 get-src)
3287 check_root
3288 get_options_list="target nounpack"
3289 get_tazwok_config
3290 check_for_package_on_cmdline
3291 check_for_receipt
3292 source_receipt
3293 if [ "$WGET_URL" ];then
3294 source_lib report
3295 report start
3296 check_for_tarball
3297 else
3298 echo "No tarball to download for $PACKAGE"
3299 fi
3300 ;;
3301 check-commit)
3302 check_root
3303 get_options_list="missing forced"
3304 get_tazwok_config
3305 source_lib report
3306 report start
3307 if [ "$forced" ]; then
3308 rm -f $WOK/*/md5
3309 unset forced
3310 fi
3311 if [ "$missing" ]; then
3312 pkg=$(ls -1 $WOK)
3313 else
3314 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3315 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3316 } | sort -u)"
3317 fi
3318 gen_cook_list
3319 ;;
3320 cook-commit)
3321 check_root
3322 get_options_list="missing forced"
3323 get_tazwok_config
3324 source_lib report
3325 report start
3326 if [ "$forced" ]; then
3327 rm -f $WOK/*/md5
3328 unset forced
3329 fi
3330 if [ "$missing" ]; then
3331 pkg=$(ls -1 $WOK)
3332 else
3333 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3334 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3335 } | sort -u)"
3336 fi
3337 gen_cook_list
3338 cook_list
3339 ;;
3340 cook-all)
3341 check_root
3342 get_options_list="forced missing"
3343 get_tazwok_config
3344 source_lib report
3345 report start
3346 if [ "$missing" ]; then
3347 pkg=$(ls -1 $WOK)
3348 else
3349 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3350 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3351 } | sort -u)"
3352 fi
3353 gen_cook_list
3354 cook_list
3355 ;;
3356 gen-wok-db)
3357 check_root
3358 get_tazwok_config
3359 source_lib report
3360 report start
3361 gen_wok_db
3362 ;;
3363 report)
3364 get_tazwok_config
3365 cd $PACKAGES_REPOSITORY
3366 if [ "$2" ]; then
3367 case $2 in
3368 commit|cooklist|incoming|broken|blocked)
3369 show="$2"
3370 ;;
3371 *)
3372 echo "usage : tazwok report [commit|cooklist|incoming|broken|blocked]" >&2
3373 exit 1
3374 ;;
3375 esac
3376 else
3377 show="commit cooklist incoming broken blocked"
3378 fi
3379 for i in $show; do
3380 if [ -s $i ]; then
3381 echo ""
3382 echo -e "\033[1m$i\033[0m"
3383 echo "================================================================================"
3384 cat $i
3385 echo "================================================================================"
3386 echo ""
3387 fi
3388 done
3389 ;;
3390 check-incoming)
3391 check_root
3392 get_options_list="forced"
3393 get_tazwok_config
3394 source_lib report
3395 report start
3396 [ -f $LOCAL_RESOSITORY/incoming ] && rm [ -f $LOCAL_REPOSITORY/incoming ]
3397 report step "Checking $INCOMING_REPOSITORY"
3398 report open-bloc
3399 [ -f $LOCAL_REPOSITORY/log/incoming.html ] && rm $LOCAL_REPOSITORY/log/incoming.html
3400 report sublog $LOCAL_REPOSITORY/log/incoming.html
3401 echo "incoming" > $LOCAL_REPOSITORY/log/package
3402 check_for_incoming
3403 report end-sublog
3404 report close-bloc
3405 ;;
3406 configure-chroot)
3407 check_root
3408 get_tazwok_config
3409 if [ -f /usr/bin/tazchroot ]; then
3410 cd $LOCAL_REPOSITORY
3411 configure_tazchroot
3412 else
3413 echo "The package tazchroot needs to be installed" >&2
3414 exit 1
3415 fi
3416 ;;
3417 chroot)
3418 check_root
3419 get_tazwok_config
3420 # Merge this and the other chroot function ?.
3421 if [ -f /usr/bin/tazchroot ]; then
3422 cd $LOCAL_REPOSITORY
3423 [ ! -f tazchroot.conf ] && configure_tazchroot
3424 tazchroot
3425 else
3426 echo "The package tazchroot needs to be installed" >&2
3427 exit 1
3428 fi
3429 ;;
3430 cook-toolchain)
3431 check_root
3432 get_tazwok_config
3433 echo -n "" > $PACKAGES_REPOSITORY/broken
3434 if [ -f /usr/bin/tazchroot ]; then
3435 cd $LOCAL_REPOSITORY
3436 [ -f tazchroot.conf ] || configure_tazchroot
3438 # Plan to recook all packages.
3439 if tazchroot cook-toolchain; then
3440 source_lib report
3441 report start
3442 pkg="$(grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt \
3443 $INCOMING_REPOSITORY/packages.txt | sort -u)"
3444 forced=yes
3445 gen_cook_list
3446 fi
3448 # Remove chroot where toolchain has been cooked.
3449 source $LOCAL_REPOSITORY/tazchroot.conf
3450 rm -r $LOCAL_REPOSITORY/chroot
3452 else
3453 echo -e "\nThe package tazchroot needs to be installed.\n" >&2
3454 exit 1
3455 fi
3456 ;;
3457 webserver)
3458 check_root
3459 get_tazwok_config
3460 if [ "$ARG" = on ]; then
3461 if [ "$WEBSERVER" ] && [ -f "$WEBSERVER/repositories.list" ] && \
3462 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3463 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3464 exit 1
3465 fi
3466 if ! [ -f $LOCAL_REPOSITORY/tazchroot.conf ]; then
3467 tazwok configure-chroot ${undigest:+--undigest=$undigest} --SLITAZ_VERSION=$SLITAZ_VERSION --SLITAZ_DIR=$SLITAZ_DIR
3468 fi
3469 for pkg in php lighttpd; do
3470 [ -d $INSTALLED/$pkg ] || missing="$missing $pkg"
3471 done
3472 if [ "$missing" ]; then
3473 echo "You need to install these packages to start webserver: $missing." >&2
3474 exit 1
3475 fi
3476 if [ ! -f "$LOCAL_REPOSITORY/tazwok.conf" ]; then
3477 echo "Copying /etc/slitaz/tazwok.conf to $LOCAL_REPOSITORY/tazwok.conf: webserver is configured repository-by-repository."
3478 cp /etc/slitaz/tazwok.conf $LOCAL_REPOSITORY
3479 fi
3480 if ! [ "$WEBSERVER" ]; then
3481 echo -n "Where to store php pages (default: /var/www/vhosts/bb)? "
3482 read WEBSERVER
3483 [ "$WEBSERVER" ] || WEBSERVER="/var/www/vhosts/bb"
3484 fi
3485 if [ -f "$WEBSERVER/repositories.list" ] && \
3486 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3487 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3488 exit 1
3489 fi
3490 mkdir -p $WEBSERVER
3491 echo "${undigest:-$SLITAZ_VERSION}" >> $WEBSERVER/repositories.list
3492 for file in index.php log.php download.php; do
3493 [ -f "$WEBSERVER/$file" ] || ln -s /usr/share/slitaz/web-bb/$file $WEBSERVER
3494 done
3495 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3496 ln -s $dir $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3497 done
3498 source $LOCAL_REPOSITORY/tazchroot.conf
3499 echo "<?php
3501 // Web interface configuration
3503 \$version=\"${undigest:-$SLITAZ_VERSION}\";
3504 \$chroot=\"$chroot_dir\";
3505 \$lockfile=\"\$chroot/proc/1/status\";
3506 \$db_dir=\"$PACKAGES_REPOSITORY\";
3507 \$log_dir=\"$LOCAL_REPOSITORY/log\";
3508 \$packages=\"$PACKAGES_REPOSITORY\";
3509 \$incoming=\"$INCOMING_REPOSITORY\";
3510 \$wok=\"$WOK\";
3512 ?>" > $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3513 [ -L "$WEBSERVER/web" ] || ln -s /usr/share/slitaz/web $WEBSERVER
3514 echo "WEBSERVER=\"$WEBSERVER\"" >> $LOCAL_REPOSITORY/tazwok.conf
3515 if [ -L "$WEBSERVER/conf.php" ]; then
3516 echo "Do you want to make ${undigest:-$SLITAZ_VERSION} the default page (y/N) ? "
3517 read answer
3518 if [ "$answer" = y ]; then
3519 rm $WEBSERVER/conf.php
3520 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3521 fi
3522 else
3523 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3524 fi
3525 elif [ "$ARG" = off ]; then
3526 if ! [ "$WEBSERVER" ]; then
3527 echo "No webserver running for ${undigest:-$SLITAZ_VERSION}" >&2
3528 exit 1
3529 fi
3530 sed '/^WEBSERVER/d' -i $LOCAL_REPOSITORY/tazwok.conf
3531 sed "/^${undigest:-$SLITAZ_VERSION}$/d" -i $WEBSERVER/repositories.list
3532 rm $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3533 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3534 rm $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3535 done
3536 if ! [ -s "$WEBSERVER/repositories.list" ]; then
3537 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"
3538 rm $WEBSERVER/conf.php
3539 elif [ "$(readlink $WEBSERVER/conf.php)" = "$WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php" ]; then
3540 echo "${undigest:-$SLITAZ_VERSION} was the default version to use; switched to : $(sed 1!d $WEBSERVER/repositories.list)"
3541 rm $WEBSERVER/conf.php
3542 ln -s $WEBSERVER/conf-$(sed 1!d $WEBSERVER/repositories.list).php $WEBSERVER/conf.php
3543 fi
3544 else
3545 echo "Usage: tazwok webserver on/off" >&2
3546 exit 1
3547 fi
3548 ;;
3549 block)
3550 # Add a pkg name to the list of blocked packages.
3551 get_tazwok_config
3552 check_root
3553 check_for_package_on_cmdline
3554 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3555 echo "Can't find $PACKAGE in wok." >&2
3556 echo ""
3557 exit 1
3558 fi
3559 echo ""
3560 if grep -qs "^$PACKAGE$" $blocked; then
3561 echo "$PACKAGE is already in the blocked packages list." >&2
3562 echo ""
3563 exit 1
3564 else
3565 echo -n "Adding $PACKAGE to : $blocked... "
3566 echo "$PACKAGE" >> $blocked
3567 status
3568 if grep -q "^$PACKAGE$" $cooklist; then
3569 echo -n "Removing $PACKAGE from : $cooklist... "
3570 sed -i /"^$PACKAGE$"/d $cooklist
3571 status
3572 fi
3573 fi
3574 echo "" ;;
3575 unblock)
3576 # Remove a pkg name from the list of blocked packages.
3577 get_tazwok_config
3578 check_root
3579 check_for_package_on_cmdline
3580 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3581 echo "Can't find $PACKAGE in wok." >&2
3582 echo ""
3583 exit 1
3584 fi
3585 echo ""
3586 if grep -qs "^$PACKAGE$" $blocked; then
3587 echo -n "Removing $PACKAGE from : $blocked... "
3588 sed -i /"^$PACKAGE$"/d $blocked
3589 sed -i '/^$/d' $blocked
3590 status
3591 else
3592 echo "$PACKAGE is not in the blocked packages list." >&2
3593 echo ""
3594 exit 1
3595 fi
3596 echo "" ;;
3597 usage|*)
3598 # Print usage also for all unknown commands.
3599 #
3600 usage
3601 ;;
3602 esac
3604 # If a cook command has been used, refresh ID of the repository to avoid
3605 # useless upgrade at next cook command.
3606 case $COMMAND in
3607 cook*)
3608 for repo in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY \
3609 $( [ "$undigest" -a ! "$ref_USE_ONLINE_PKG" ] && echo $ref_PACKAGES_REPOSITORY ); do
3610 [ -f $repo/ID ] || continue
3611 MIRROR_path=$(grep -l "^$repo$" $LOCALSTATE/mirror $LOCALSTATE/undigest/*/mirror)
3612 LOCALSTATE_path=${MIRROR_path%/mirror}
3613 cp -a $repo/ID $LOCALSTATE_path
3614 done
3615 ;;
3616 esac
3618 report stop 2>/dev/null
3619 exit 0