tazwok view tazwok @ rev 465

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