tazwok view tazwok @ rev 464

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