tazwok view tazwok @ rev 551

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