tazwok view tazwok @ rev 543

Change VERSION to 4.2.17
author Antoine Bodin <gokhlayeh@slitaz.org>
date Sat Nov 26 16:56:28 2011 +0100 (2011-11-26)
parents 44e24b12e9dd
children fcc1dc4dd1af 8822f9e826ae
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.17
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 [ "$prev_VERSION" ] || return
442 if [ "$VERSION$EXTRAVERSION" != "$prev_VERSION" ]; then
443 rm -f $1/$PACKAGE-$prev_VERSION.tazpkg
444 fi
445 return 0
446 }
448 # Check for src tarball and wget if needed.
449 check_for_tarball()
450 {
451 [ "$WGET_URL" ] || return 0
452 [ "$WANTED" ] && return 0
453 report step "Checking for source tarball: $PACKAGE"
454 local repack_src=$repack_src TARBALL=$TARBALL nounpack=$nounpack
455 look_for_cookopt !unpack && nounpack=yes
456 if [ "$repack_src" = yes ] && look_for_cookopt !repack_src; then
457 repack_src=no
458 fi
459 if [ "$target" ]; then
460 src="$target"
461 else
462 set_src_path
463 fi
464 tmp_src=$LOCAL_REPOSITORY/tmp/tarball-$$
465 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ] && \
466 [ ! -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}.tar.lzma" ] ; then
467 cd $SOURCES_REPOSITORY
468 if [ "$SOURCE" ]; then
469 alt_url="http://mirror.slitaz.org/sources/packages/${SOURCE:0:1}/$SOURCE-${KBASEVER:-$VERSION}.tar.lzma"
470 else
471 alt_url="http://mirror.slitaz.org/sources/packages/${PACKAGE:0:1}/$PACKAGE-${KBASEVER:-$VERSION}.tar.lzma"
472 fi
473 download $WGET_URL $alt_url http://mirror.slitaz.org/sources/packages/${TARBALL:0:1}/$TARBALL
474 unset alt_url
475 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ] && \
476 [ ! -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}.tar.lzma" ] && \
477 [ ! -d $tmp_src ]; then
478 echo -e "\nDownload failed, exiting. Please check WGET_URL variable.\n" >&2
479 report end-step
480 return 1
481 fi
482 fi
483 report end-step
484 if { [ -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}.tar.lzma" ] && [ "$nounpack" ] ; } || \
485 { [ -f "$SOURCES_REPOSITORY/$TARBALL" ] && [ "$repack_src" != yes ] && [ "$nounpack" ] ; }; then
486 [ -d "$tmp_src" ] && rm -r "$tmp_src"
487 return 0
488 fi
490 report step "Untaring source tarball"
492 # Log process.
493 echo "untaring source tarball" >> $LOG
495 # If $tmp_src exists, there's already a unpacked tarball in it.
496 if ! [ -d "$tmp_src" ]; then
497 mkdir "$tmp_src"
498 if [ -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}.tar.lzma" ] && [ "$repack_src" = yes ]; then
499 lzma d $SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}.tar.lzma -so | \
500 tar xf - -C "$tmp_src"
501 repack_src=no
502 TARBALL=${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}.tar.lzma
503 elif [ -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
504 case "$TARBALL" in
505 *zip|*xpi) cd $tmp_src && unzip -o $SOURCES_REPOSITORY/$TARBALL ;;
506 *bz2|*tbz|*gem) tar xjf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
507 *tar) tar xf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
508 *lzma|*lz) unlzma -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
509 *xz) unxz -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
510 *Z|*taz) uncompress -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
511 *gz) tar xzf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
512 *rpm) cd $tmp_src && rpm2cpio $SOURCES_REPOSITORY/$TARBALL | cpio -idm --quiet;;
513 *.run) cd $tmp_src && sh $SOURCES_REPOSITORY/$TARBALL $RUN_OPTS;;
515 # It's a plain file or something receipt unpack itself.
516 *)
517 mkdir $tmp_src/${SOURCE:-$PACKAGE}-$VERSION
518 cp $SOURCES_REPOSITORY/$TARBALL $tmp_src/${src##*/}
519 ;;
521 esac || { report end-step
522 rm -f $SOURCES_REPOSITORY/$TARBALL
523 rm -r $tmp_src
524 return 1
525 }
526 fi
528 # Check if uncompressed tarball is in a root dir or not.
529 if [ "$(ls -A $tmp_src | wc -l)" -gt 1 ] || [ -f "$(echo $tmp_src/*)" ]; then
530 if check_for_var_modification src _pkg; then
531 mv "$tmp_src" "$tmp_src-1"
532 mkdir "$tmp_src"
533 mv "$tmp_src-1" "$tmp_src/${SOURCE:-$PACKAGE}-$VERSION"
534 else
535 mv "$tmp_src"/* "$WOK/$PACKAGE"
536 repack_src=no
537 rm -r "$tmp_src"
538 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."
539 fi
540 fi
541 fi
543 if [ "$repack_src" = yes ]; then
544 report step "Repacking sources in .tar.lzma format"
545 [ "$TARBALL" ] && rm -f $SOURCES_REPOSITORY/$TARBALL
546 TARBALL=${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}.tar.lzma
547 cd "$tmp_src"
548 tar -c * | lzma e $SOURCES_REPOSITORY/$TARBALL -si
549 fi
551 # Remove previous tarball if no other package needs it. We take care to
552 # keep tarball if the same package uses it in the main repository.
553 if [ "$TARBALL" ]; then
554 previous_tarball=$(grep ^$PACKAGE:incoming $SOURCES_REPOSITORY/sources.list | cut -f2)
555 if [ "$previous_tarball" ]; then
556 sed "/^$PACKAGE:incoming/ s/.*/$PACKAGE:incoming\t$TARBALL/" \
557 -i $SOURCES_REPOSITORY/sources.list
558 grep -q $'\t'$previous_tarball$ $SOURCES_REPOSITORY/sources.list || \
559 rm -f $SOURCES_REPOSITORY/$previous_tarball
560 else
561 echo -e "$PACKAGE:incoming\t$TARBALL" >> $SOURCES_REPOSITORY/sources.list
562 fi
563 fi
565 if [ "$nounpack" ]; then
566 [ -d "$tmp_src" ] && rm -r "$tmp_src"
567 report end-step
568 return
569 fi
570 if [ ! -d "$src" ]|| [ "$target" ]; then
571 # Permissions settings.
572 chown -R root.root "$tmp_src"
573 if [ -d "$src" ]; then
574 mkdir -p "$src"
575 for f in "$tmp_src"/*/*; do
576 cp -a "$f" "$src" || { report end-step; rm -r "$tmp_src"; return 1; }
577 done
578 else
579 if ! check_for_var_modification src _pkg && ! [ "$target" ]; then
580 src="${src%/*}/$(ls $tmp_src)"
581 fi
582 mv "$(echo $tmp_src/*)" "$src" || { report end-step; rm -r "$tmp_src"; return 1; }
583 fi
584 rm -r "$tmp_src"
585 else
586 [ -d "$tmp_src" ] && rm -r "$tmp_src"
587 echo "There's already something at $src. Abort." >&2
588 fi
589 report end-step
590 }
592 # help gen sources.list file from scranch
593 gen_sources_list()
594 {
595 local src_repository=$1
596 [ -f $src_repository/sources.list ] && rm -f $src_repository/sources.list
597 for i in $WOK/*; do
598 unset PACKAGE SOURCE VERSION WGET_URL TARBALL WANTED
599 [ -f $i/receipt ] && source $i/receipt
600 [ "$WGET_URL" ] || continue
601 if grep -q "^$PACKAGE | $VERSION" $PACKAGES_REPOSITORY/packages.desc; then
602 main_version="$VERSION"
603 if [ -f $src_repository/${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}.tar.lzma ]; then
604 echo -e "$PACKAGE:main\t${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}.tar.lzma" >> $src_repository/sources.list
605 elif [ -f "$src_repository/$TARBALL" ]; then
606 echo -e "$PACKAGE:main\t$TARBALL" >> $src_repository/sources.list
607 fi
608 else
609 # May not works if package use extraversion.
610 main_version=$(grep -m1 -A1 -sh ^$PACKAGE$ $PACKAGES_REPOSITORY/packages.txt | tail -1 | sed 's/ *//')
611 if [ -f $src_repository/${SOURCE:-$PACKAGE}-$main_version.tar.lzma ]; then
612 echo -e "$PACKAGE:main\t${SOURCE:-$PACKAGE}-$main_version.tar.lzma" >> $src_repository/sources.list
613 else
614 unset main_version
615 fi
616 fi
617 if [ ! "$main_version" ] || [ $(grep -q "^$PACKAGE | $VERSION" $INCOMING_REPOSITORY/packages.desc 2>/dev/null) ]; then
618 if [ -f $src_repository/${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}.tar.lzma ]; then
619 echo -e "$PACKAGE:incoming\t${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}.tar.lzma" >> $src_repository/sources.list
620 elif [ -f "$src_repository/$TARBALL" ]; then
621 echo -e "$PACKAGE:incoming\t$TARBALL" >> $src_repository/sources.list
622 fi
623 fi
624 done
625 }
627 # Log and execute compile_rules function if it exists, to configure and
628 # make the package if it exists.
629 check_for_compile_rules()
630 {
631 if grep -q ^compile_rules $RECEIPT; then
632 echo "executing compile_rules" >> $LOG
633 report step "Executing compile_rules"
634 cd $WOK/$PACKAGE
635 rm -f /tmp/config.site
636 ulimit -d unlimited
637 ulimit -m unlimited
639 # Free some RAM by cleaning cache if option is enabled.
640 freeram=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
642 # Disable -pipe in CFLAGS/CXXFLAGS if less than 512Mb of free
643 # RAM are available.
644 if [ "$freeram" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" -o \
645 "$CXXFLAGS" != "${CXXFLAGS/-pipe}" ]; then
646 tazwok_warning "Disabling -pipe compile flag because only ${freeram}b of RAM is available."
647 CFLAGS="${CFLAGS/-pipe}"
648 CXXFLAGS="${CXXFLAGS/-pipe}"
649 fi
650 unset freeram
652 # Set cook environement variables.
653 [ "$src" ] || set_src_path
654 [ "$DESTDIR" ] || DESTDIR="$WOK/$PACKAGE/install"
655 [ "$CONFIG_SITE" ] || CONFIG_SITE=/etc/config.site
656 export CFLAGS=$(echo "$CFLAGS" | tr -s ' ') \
657 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ') \
658 MAKEFLAGS DESTDIR CONFIG_SITE default_prefix \
659 default_datarootdir default_datadir default_localedir \
660 default_infodir default_mandir default_build default_host \
661 BUILD_SYSTEM HOST_SYSTEM
662 local LC_ALL=POSIX LANG=POSIX
663 compile_rules
665 # Check if config.site has been used.
666 # /!\ disabled since it screws the return_code of the step.
667 #if [ -f /tmp/config.site ]; then
668 # rm /tmp/config.site
669 #else
670 # tazwok_warning "config.site hasn't been used during \
671 #the configuration process."
672 #fi
673 report end-step
674 fi
675 }
677 # Check for loop in deps tree. /!\ can be removed.
678 check_for_deps_loop()
679 {
680 local list
681 local pkg
682 local deps
683 pkg=$1
684 shift
685 [ -n "$1" ] || return
686 list=""
688 # Filter out already processed deps.
689 for i in $@; do
690 case " $ALL_DEPS" in
691 *\ $i\ *);;
692 *) list="$list $i";;
693 esac
694 done
695 ALL_DEPS="$ALL_DEPS$list "
696 for i in $list; do
697 [ -f $i/receipt ] || continue
698 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
699 case " $deps " in
700 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
701 *) check_for_deps_loop $pkg $deps;;
702 esac
703 done
704 }
706 # Function used by download().
707 revert_vcs_failure()
708 {
709 cd $SOURCES_REPOSITORY
710 rm -r $tmp_src
711 }
713 download()
714 {
715 if [ "$COMMAND" = get-src ]; then
716 if [ "${DEPENDS/tar}" != "$DEPENDS" ] || [ "${BUILD_DEPENDS/tar}" != "$BUILD_DEPENDS" ]; then
717 [ -f $INSTALLED/tar/receipt ] || tazpkg get-install tar --forced
718 fi
719 fi
720 for file in $@; do
721 echo "Downloading from ${file#*|}..."
722 case "$file" in
723 git\|*)
724 file=${file#git|}
725 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/git/receipt ] && tazpkg get-install git --forced
726 if [ -f $INSTALLED/git/receipt ]; then
727 mkdir $tmp_src
728 cd $tmp_src
729 if [ "$BRANCH" ]; then
730 git clone $file ${src##*/} && cd ${src##*/} && \
731 git checkout $BRANCH && rm -rf .git* && break
732 else
733 git clone $file ${src##*/} && rm -rf ${src##*/}/.git* && break
734 fi
735 revert_vcs_failure
736 else
737 tazwok_warning "Needs git to download the source tarball from $file, please add it as a build-depend."
738 continue
739 fi
740 ;;
741 bazaar\|*)
742 file=${file#bazaar|}
743 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/bazaar/receipt ] && tazpkg get-install bazaar --forced
744 if [ -f $INSTALLED/bazaar/receipt ]; then
745 mkdir $tmp_src
746 cd $tmp_src
747 if [ "$BRANCH" ]; then
748 bzr co $file -r $BRANCH ${src##*/} && rm -rf ${src##*/}/.bzr* && break
749 else
750 bzr co $file ${src##*/} && rm -rf ${src##*/}/.bzr* && break
751 fi
752 revert_vcs_failure
753 else
754 tazwok_warning "Needs bazaar to download the source tarball from $file, please add it as a build-depend."
755 continue
756 fi
757 ;;
758 svn*|subversion*)
759 if $(echo "$WGET_URL" | fgrep -q svn); then
760 file=${WGET_URL#svn|}
761 else
762 file=${WGET_URL#subversion|}
763 fi
764 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/subversion/receipt ] && tazpkg get-install subversion --forced
765 if [ -f $INSTALLED/subversion/receipt ]; then
766 mkdir $tmp_src
767 cd $tmp_src
768 if [ "$BRANCH" ]; then
769 echo t | svn co $file -r $BRANCH ${src##*/} && rm -rf ${src##*/}/.svn* && break
770 else
771 echo t | svn co $file ${src##*/} && rm -rf ${src##*/}/.svn* && break
772 fi
773 revert_vcs_failure
774 else
775 tazwok_warning "Needs subversion to download the source tarball from $file, please add it as a build-depend."
776 continue
777 fi
778 ;;
779 hg*|mercurial*)
780 if $(echo "$WGET_URL" | fgrep -q hg); then
781 file=${WGET_URL#hg|}
782 else
783 file=${WGET_URL#mercurial|}
784 fi
785 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/mercurial/receipt ] && tazpkg get-install mercurial --forced
786 if [ -f $INSTALLED/mercurial/receipt ]; then
787 mkdir $tmp_src
788 cd $tmp_src
789 if [ "$BRANCH" ]; then
790 hg clone $file --rev $BRANCH ${src##*/} && rm -rf ${src##*/}/.hg* && break
791 else
792 hg clone $file ${src##*/} && rm -rf ${src##*/}/.hg* && break
793 fi
794 revert_vcs_failure
795 else
796 tazwok_warning "Needs mercurial to download the source tarball from $file, please add it as a build-depend."
797 continue
798 fi
799 ;;
800 cvs*)
801 file=${WGET_URL#cvs|}
802 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/cvs/receipt ] && tazpkg get-install cvs --forced
803 if [ -f $INSTALLED/cvs/receipt ]; then
804 mkdir $tmp_src
805 cd $tmp_src
806 mod=${src##*/}
807 [ "$CVS_MODULE" ] && mod=$CVS_MODULE
808 cvs -z3 -d:$file co $mod && rm -rf $mod/CVS && break
809 else
810 tazwok_warning "Needs cvs to download the source tarball from $file, please add it as a build-depend."
811 continue
812 fi
813 ;;
814 https*)
815 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/wget/receipt ] && tazpkg get-install wget --forced
816 if [ -d $INSTALLED/wget ]; then
817 if [ "${WGET_URL%$TARBALL}" = "$WGET_URL" ] && [ "$file" = "$WGET_URL" ]; then
818 wget -q --no-check-certificate -O $TARBALL $file && break
819 else
820 wget -q --no-check-certificate $file && break
821 fi
822 else
823 tazwok_warning "Needs wget to download the source tarball from $file, please add it as a build-depend."
824 continue
825 fi
826 ;;
827 http*|ftp*)
828 # Handle crappy URL.
829 if [ "$COMMAND" = get-src ]; then
830 if [ "${DEPENDS/wget}" != "$DEPENDS" ] || [ "${BUILD_DEPENDS/wget}" != "$BUILD_DEPENDS" ]; then
831 [ -f $INSALLED/wget/receipt ] || tazpkg get-install wget --forced
832 fi
833 fi
834 if [ "${WGET_URL%$TARBALL}" = "$WGET_URL" ] && [ "$file" = "$WGET_URL" ]; then
835 wget -q -O $TARBALL $file && break
836 else
837 wget -q $file && break
838 fi
839 ;;
840 esac
841 done
842 }
844 # Regenerate every package that wants a PACKAGE compiled.
845 refresh_packages_from_compile()
846 {
847 # make tazwok genpkg happy.
848 mkdir $WOK/$PACKAGE/taz
850 # Cook rwanted in default or specied order.
851 genlist=" $(look_for_rwanted | tr '\n' ' ') "
852 for i in $(look_for_cookopt genpkg | tac); do
853 [ "${genlist/ $i }" = "$genlist" ] && continue
854 genlist=" $i${genlist/ $i / }"
855 done
856 if [ "$genlist" ]; then
857 local PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
858 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
859 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
860 src _pkg DESTDIR CONFIG_SITE RECEIPT LOG stuff wanted_stuff
861 for PACKAGE in $genlist; do
862 set_common_path
863 gen_package
864 done
865 fi
866 }
868 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
869 # so some packages need to copy these files with the receipt and genpkg_rules.
870 # This function is executed by gen_package when 'tazwok genpkg'.
871 copy_generic_files()
872 {
873 # In most cases, locales are in $_pkg/usr/share/locale so we copy files
874 # using generic variables and $LOCALE from Tazwok config file.
875 if [ "$LOCALE" ]; then
876 if [ -d "$_pkg/usr/share/locale" ]; then
877 for i in $LOCALE
878 do
879 if [ -d "$_pkg/usr/share/locale/$i" ]; then
880 mkdir -p $fs/usr/share/locale
881 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
882 fi
883 done
884 fi
885 fi
887 # Pixmaps (PNG or/and XPM only). Some icons/images can be added through
888 # genpkg_rules and generic copy can be disabled with GENERIC_PIXMAPS="no"
889 # in pkg receipt.
890 if [ "$GENERIC_PIXMAPS" != "no" ]; then
891 if [ -d "$_pkg/usr/share/pixmaps" ]; then
892 mkdir -p $fs/usr/share/pixmaps
893 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
894 $fs/usr/share/pixmaps 2>/dev/null
895 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
896 $fs/usr/share/pixmaps 2>/dev/null
897 fi
899 # Custom or homemade PNG pixmap can be in stuff.
900 if [ -f "stuff/$PACKAGE.png" ]; then
901 mkdir -p $fs/usr/share/pixmaps
902 cp -a stuff/$PACKAGE.png $fs/usr/share/pixmaps
903 fi
904 fi
906 # Desktop entry (.desktop).
907 if [ -d "$_pkg/usr/share/applications" ]; then
908 cp -a $_pkg/usr/share/applications $fs/usr/share
909 fi
911 # Homemade desktop file(s) can be in stuff.
912 if [ -d "stuff/applications" ]; then
913 mkdir -p $fs/usr/share
914 cp -a stuff/applications $fs/usr/share
915 fi
916 if [ -f "stuff/$PACKAGE.desktop" ]; then
917 mkdir -p $fs/usr/share/applications
918 cp -a stuff/$PACKAGE.desktop $fs/usr/share/applications
919 fi
920 }
922 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
923 strip_package()
924 {
925 report step "Executing strip on all files"
927 # Binaries.
928 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
929 do
930 if [ -d "$dir" ]; then
931 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
932 fi
933 done
935 # Libraries.
936 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
937 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
938 report end-step
939 }
941 # Remove .pyc and .pyo files from packages.
942 py_compiled_files_remove()
943 {
944 report step "Removing all .pyc and .pyo files from package"
945 find $fs -type f -name "*.pyc" -delete 2>/dev/null
946 find $fs -type f -name "*.pyo" -delete 2>/dev/null
947 report end-step
948 }
950 # Removing all perllocal.pod and .packlist files from package
951 perl_compiled_files_remove()
952 {
953 report step "Removing all perllocal.pod and .packlist files from package"
954 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
955 find $fs -type f -name ".packlist" -delete 2>/dev/null
956 report end-step
957 }
959 # Check FSH in a slitaz package (Path: /:/usr)
960 check_fsh()
961 {
962 cd $WOK/$PACKAGE/taz/*/fs
963 if [ -z "$(find * ! -type d)" ] && [ "$CATEGORY" != meta ]; then
964 echo "$PACKAGE fs is empty." >&2
965 cd $WOK/$PACKAGE && rm -rf taz
966 return 1
967 fi
968 [ -n "$FSH" ] || FSH="bin boot dev etc home init lib media mnt proc \
969 root sbin share sys tmp usr var vz usr/bin usr/games usr/include usr/lib \
970 usr/local usr/sbin usr/share usr/src"
971 error=0
972 for i in `ls -d * usr/* 2>/dev/null`
973 do
974 if ! echo $FSH | fgrep -q $i; then
975 echo "Wrong path: /$i" >&2
976 error=1
977 fi
978 done
979 if [ "$error" = "1" ]; then
980 cat << _EOT_
982 Package will install files in a non standard directory and won't be generated.
983 You may have a wrong copy path in genpkg_rules or need to add some options to
984 configure in compile_rules. Some valid options for SliTaz (Linux FSH):
986 --prefix=/usr
987 --sysconfdir=/etc
988 --libexecdir=/usr/lib/(pkgname)
989 --localstatedir=/var
990 --mandir=/usr/share/man
991 --infodir=/usr/share/info
993 For more information please read SliTaz docs and run: ./configure --help
994 ================================================================================
995 $PACKAGE package generation aborted.
997 _EOT_
999 # Dont generate a corrupted package.
1000 cd $WOK/$PACKAGE && rm -rf taz
1001 return 1
1002 fi
1003 return 0
1006 gen_cookmd5()
1008 # md5sum of cooking stuff make tazwok able to check for changes
1009 # without hg.
1010 cd $WOK/$PACKAGE
1011 md5sum receipt > md5
1012 [ -f description.txt ] && md5sum description.txt >> md5
1013 if [ -d stuff ]; then
1014 find stuff | while read file; do
1015 md5sum $file >> md5
1016 done
1017 fi
1020 set_pkg_broken()
1022 if ! grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/broken; then
1023 echo $PACKAGE >> $PACKAGES_REPOSITORY/broken
1024 fi
1026 # Remove pkg from cooklist to avoid re-cook it if no changes happen
1027 # in the cook stuff.
1028 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/cooklist
1029 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/commit
1031 gen_cookmd5
1033 # Return 1 to make report know that its mother-function failed.
1034 return 1
1037 # Create a package tree and build the gziped cpio archive
1038 # to make a SliTaz (.tazpkg) package.
1039 gen_package()
1041 check_root
1042 check_for_package_on_cmdline
1043 check_for_receipt
1044 source_receipt
1046 # May compute VERSION
1047 if grep -q ^get_version $RECEIPT; then
1048 get_version
1049 fi
1050 check_for_wanted
1051 cd $WOK/$PACKAGE
1053 # Remove old Tazwok package files.
1054 [ -d "taz" ] && rm -rf taz
1056 # Create the package tree and set useful variables.
1057 fs=$WOK/$PACKAGE/taz/$PACKAGE-$VERSION/fs
1058 mkdir -p $fs
1060 # Set $src for standard package and $_pkg variables.
1061 set_src_path
1062 set_pkg_path
1064 # Execute genpkg_rules, check package and copy generic files to build
1065 # the package.
1066 report step "Building $PACKAGE with the receipt"
1067 report open-bloc
1068 if look_for_cookopt !fs; then
1070 elif grep -q ^genpkg_rules $RECEIPT; then
1072 # Log process.
1073 echo "executing genpkg_rules" >> $LOG
1074 report step "Executing genpkg_rules"
1075 ( set -e; genpkg_rules ) || { set_pkg_broken; report close-bloc; return 1; }
1076 check_fsh || { set_pkg_broken; report close-bloc; return 1; }
1077 cd $WOK/$PACKAGE
1078 report end-step
1080 # Skip generic files for packages with a WANTED variable
1081 # (dev and split pkgs).
1082 if [ ! "$WANTED" ]; then
1083 copy_generic_files
1084 fi
1085 look_for_cookopt !strip || strip_package
1086 perl_compiled_files_remove
1087 else
1088 echo "No package rules to gen $PACKAGE..." >&2
1089 set_pkg_broken
1090 report close-bloc
1091 return 1
1092 fi
1094 # Copy the receipt and description (if exists) into the binary package tree.
1095 cd $WOK/$PACKAGE
1096 report step "Copying the receipt"
1097 cp receipt taz/$PACKAGE-$VERSION
1098 report end-step
1099 if grep -q ^get_version $RECEIPT; then
1100 report step "Updating version in receipt"
1101 sed -i "s/^VERSION=.*/VERSION=\"$VERSION\"/" \
1102 taz/$PACKAGE-$VERSION/receipt
1103 report end-step
1104 fi
1105 if [ -f "description.txt" ]; then
1106 report step "Copying the description file"
1107 cp description.txt taz/$PACKAGE-$VERSION
1108 report end-step
1109 fi
1111 # Generate md5 of cooking stuff to look for commit later.
1112 gen_cookmd5
1113 echo -e "\n# md5sum of cooking stuff :" >> taz/$PACKAGE-$VERSION/receipt
1114 cat md5 | sed 's/^/# /' >> taz/$PACKAGE-$VERSION/receipt
1116 # Create the files.list by redirecting find output.
1117 report step "Creating the list of files"
1118 cd taz/$PACKAGE-$VERSION
1119 LAST_FILE=""
1120 { find fs -print; echo; } | while read file; do
1121 if [ "$LAST_FILE" ]; then
1122 case "$file" in
1123 $LAST_FILE/*)
1124 case "$(ls -ld "$LAST_FILE")" in
1125 drwxr-xr-x\ *\ root\ *\ root\ *);;
1126 *) echo ${LAST_FILE#fs};;
1127 esac;;
1128 *) echo ${LAST_FILE#fs};;
1129 esac
1130 fi
1131 LAST_FILE="$file"
1132 done > files.list
1134 py_compiled_files_remove
1136 # Next, check if something has changed in lib files.
1137 if fgrep -q '.so' files.list; then
1138 for rep in $INCOMING_REPOSITORY $PACKAGES_REPOSITORY \
1139 $([ "$undigest" ] && echo $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming && \
1140 echo $SLITAZ_DIR/$SLITAZ_VERSION/packages); do
1141 prev_VERSION=$(get_pkg_version $rep)
1142 [ "$prev_VERSION" ] && pkg_file=$rep/$PACKAGE-$prev_VERSION.tazpkg && break
1143 done
1144 if [ "$pkg_file" ]; then
1145 report step "Looking for major/minor updates in libraries"
1146 get_pkg_files $pkg_file
1147 cd $WOK/$PACKAGE/taz/$PACKAGE-$VERSION
1148 fgrep ".so" files.list | egrep -v "[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*" | \
1149 while read lib; do
1150 fgrep -q "$lib" $pkg_files_dir/files.list && continue
1151 echo "A minor/major update in libraries is detected, planning re-cook of reverse-depends of $PACKAGE."
1152 for rdep in $(scan $PACKAGE --look_for=rdep | use_wanted); do
1153 [ "$rdep" = "${WANTED:-$PACKAGE}" ] && continue
1154 grep -q ^$rdep$ $PACKAGES_REPOSITORY/blocked \
1155 $PACKAGES_REPOSITORY/cooklist && continue
1156 echo $rdep >> $PACKAGES_REPOSITORY/cooklist
1157 done
1158 regen_cooklist=yes
1159 break
1160 done
1161 rm -r $pkg_files_dir
1162 unset pkg_file
1163 report end-step
1164 fi
1165 fi
1166 if [ ! "$EXTRAVERSION" ]; then
1167 case "$PACKAGE" in
1168 linux*);;
1169 *) EXTRAVERSION="$(grep '/lib/modules/.*-slitaz/' files.list |\
1170 head -1 | sed 's|/lib/modules/\(.*\)-slitaz/.*|_\1|')";;
1171 esac
1172 fi
1173 rm -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg 2> /dev/null
1174 report step "Creating md5sum of files"
1175 while read file; do
1176 [ -L "fs$file" ] && continue
1177 [ -f "fs$file" ] || continue
1178 md5sum "fs$file" | sed 's/ fs/ /'
1179 done < files.list > md5sum
1180 report end-step
1181 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
1182 2> /dev/null | awk '{ sz=$1 } END { print sz }')
1184 # Build cpio archives. Find, cpio and gzip the fs, finish by
1185 # removing the fs tree.
1186 # Don't log this because compression always outputs error messages.
1187 find fs -print | cpio -o -H newc | case "$PACKAGE-$COMPRESSION" in
1188 tazpkg-lzma) gzip > fs.cpio.gz;;
1189 *-lzma) lzma e fs.cpio.lzma -si;;
1190 *) gzip > fs.cpio.gz;;
1191 esac && rm -rf fs
1192 PACKED_SIZE=$(du -chs fs.cpio.* receipt files.list md5sum \
1193 description.txt 2> /dev/null | awk '{ sz=$1 } END { print sz }')
1194 report step "Updating receipt sizes"
1195 sed -i '/^PACKED_SIZE/d' receipt
1196 sed -i '/^UNPACKED_SIZE/d' receipt
1197 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1198 sed -i "s/^VERSION=$/VERSION=\"$VERSION\"/" receipt
1199 report end-step
1200 if [ "$EXTRAVERSION" ]; then
1201 report step "Updating receipt EXTRAVERSION"
1202 sed -i s/^EXTRAVERSION.*$// receipt
1203 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
1204 fi
1205 prev_VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
1206 remove_previous_package $INCOMING_REPOSITORY
1207 report step "Creating full cpio archive"
1208 find . -print | cpio -o -H newc > $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1210 # Restore package tree in case we want to browse it.
1211 report step "Restoring original package tree"
1212 { zcat fs.cpio.gz 2> /dev/null || unlzma -c fs.cpio.lzma; } | cpio --quiet -id
1213 rm fs.cpio.* && cd ..
1215 # Recook of reverse-depends if package was broken.
1216 if grep -q "^$PACKAGE$" $PACKAGES_REPOSITORY/broken; then
1217 report step "Planning a re-try cook of reverse depends"
1218 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/broken
1219 for rdep in $(look_for_rdep); do
1220 grep -q "^$rdep$" $PACKAGES_REPOSITORY/broken || continue
1221 grep -q "^$rdep$" $PACKAGES_REPOSITORY/cooklist && continue
1222 echo "Adding $rdep to the cooklist"
1223 echo $rdep >> $PACKAGES_REPOSITORY/cooklist
1224 regen_cooklist=t
1225 done
1226 report end-step
1227 fi
1228 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/commit
1229 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/cooklist
1231 # Log process.
1232 echo "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg (done)" >> $LOG
1233 report close-bloc
1234 echo "Package $PACKAGE ($VERSION$EXTRAVERSION) generated."
1235 echo "Size : `du -sh $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
1236 echo ""
1239 ########################################################################
1240 # This section contains functions used by several other functions
1241 # below.
1242 ########################
1244 # Look for receipt/files.list in wok. If they can't be found, get them
1245 # from package. Accept one argument : absolute path to package.
1246 get_pkg_files()
1248 pkg_files_dir=$tmp/$(basename ${1%.tazpkg})
1249 mkdir -p $pkg_files_dir && \
1250 cd $pkg_files_dir && \
1251 cpio --quiet -idm receipt < $1 && \
1252 cpio --quiet -idm files.list < $1
1255 ########################################################################
1256 # This section contains functions to generate packages databases.
1257 ########################
1260 gen_packages_db()
1262 # pkg_repository can be $PACKAGES_REPOSITORY or $INCOMING_REPOSITORY.
1263 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1264 cd $pkg_repository
1265 report step "Generating packages lists: $pkg_repository"
1266 report open-bloc
1267 report step "Removing old files"
1268 for file in files.list.lzma packages.list packages.txt \
1269 packages.desc packages.equiv packages.md5; do
1270 [ -f $file ] && rm $file
1271 done
1272 touch files.list
1274 packages_db_start
1275 unset RECEIPT
1276 report step "Reading data from all packages"
1277 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1278 get_packages_info
1279 done
1280 report end-step
1281 packages_db_end
1282 report close-bloc
1285 update_packages_db()
1287 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1288 cd $pkg_repository
1289 for file in packages.list packages.equiv packages.md5 packages.desc \
1290 packages.txt; do
1291 if [ ! -f "$file" ]; then
1292 gen_packages_db
1293 return
1294 fi
1295 done
1296 if [ -f files.list.lzma ]; then
1297 lzma d files.list.lzma files.list
1298 else
1299 gen_packages_db
1300 return
1301 fi
1302 report step "Updating packages lists: $pkg_repository"
1303 packages_db_start
1305 # Look for removed/update packages.
1306 touch stamp -r packages.list
1307 for PACKAGE in $(grep ^[0-9,a-z,A-Z] packages.txt); do
1308 pkg="$pkg_repository/$(grep -m1 ^$PACKAGE- packages.list).tazpkg"
1309 if ! [ -f "$pkg" ]; then
1310 erase_package_info
1311 else
1312 if [ "$pkg" -nt "stamp" ]; then
1313 updated_pkg="$updated_pkg
1314 $PACKAGE $pkg"
1315 elif [ ! -f $WOK/$PACKAGE/receipt ] && \
1316 [ "$COMMAND" = check-incoming -o "$pkg_repository" = "$INCOMING_REPOSITORY" ]; then
1317 erase_package_info
1318 echo "Removing $PACKAGE from $pkg_repository."
1319 rm $pkg
1320 [ -d $WOK/$PACKAGE ] && rm -r $WOK/$PACKAGE
1321 sed "/^$PACKAGE\t/d" -i $wan_db $dep_db
1322 for i in cookorder.txt cooklist commit blocked broken; do
1323 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/$i
1324 done
1325 rm -f $LOCAL_REPOSITORY/log/$PACKAGE.html
1326 if [ "$pkg_repository" = "$INCOMING_REPOSITORY" ] && \
1327 [ "$(sed 1!d $PACKAGES_REPOSITORY/cookorder.txt)" != "#PlanSort" ] ; then
1328 sed 1i"#PlanSort" -i $PACKAGES_REPOSITORY/cookorder.txt
1329 regen_cooklist=yes
1330 else
1331 echo "$PACKAGE" >> $PACKAGES_REPOSITORY/removed
1332 sed -n '1,10p' -i $PACKAGES_REPOSITORY/removed
1333 fi
1334 fi
1335 fi
1336 done
1337 rm stamp
1338 echo "$updated_pkg" | sed 1d | while read PACKAGE pkg; do
1339 erase_package_info
1340 get_packages_info
1341 done
1342 unset updated_pkg
1344 # Look for new packages.
1345 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1346 if ! fgrep -q " ${pkg##*/}" $pkg_repository/packages.md5; then
1347 get_packages_info
1348 fi
1349 done
1350 report end-step
1351 packages_db_end
1354 packages_db_start()
1356 if [ ! -s packages.txt ]; then
1357 echo "# SliTaz GNU/Linux - Packages list
1359 # Packages : unknown
1360 # Date : $(date +%Y-%m-%d\ \%H:%M:%S)
1362 " > packages.txt
1363 else
1364 sed -e 's/^# Packages :.*/# Packages : unknown/' \
1365 -e "s/# Date :.*/# Date : $(date +%Y-%m-%d\ \%H:%M:%S)/" \
1366 -i packages.txt
1367 fi
1369 # Needed in some cases as tazwok defines RECEIPT at configuration time
1370 # in this particular case it can break the script.
1371 unset RECEIPT
1374 erase_package_info()
1376 cd $pkg_repository
1377 sed "/^$PACKAGE$/,/^$/d" -i packages.txt
1378 sed "/^$PACKAGE /d" -i packages.desc
1379 sed -e "s/=$PACKAGE /= /" -e "s/ $PACKAGE / /" -e "s/ $PACKAGE$//" \
1380 -e "/=$PACKAGE$/d" -e "s/=[0-9,a-z,A-Z]:$PACKAGE /= /" \
1381 -e "s/ [0-9,a-z,A-Z]:$PACKAGE / /" -e "s/ [0-9,a-z,A-Z]:$PACKAGE$/ /" \
1382 -e "/=[0-9,a-z,A-Z]:$PACKAGE$/d" \
1383 -i packages.equiv
1384 sed "/^$PACKAGE:/d" -i files.list
1385 sed "/^$(basename ${pkg%.tazpkg})$/d" -i packages.list
1386 sed "/ $(basename $pkg)$/d" -i packages.md5
1389 get_packages_info()
1391 # If there's no taz folder in the wok, extract info from the
1392 # package.
1393 get_pkg_files $pkg
1394 source_receipt
1395 echo "Getting data from $PACKAGE"
1397 cat >> $pkg_repository/packages.txt << _EOT_
1398 $PACKAGE
1399 $VERSION$EXTRAVERSION
1400 $SHORT_DESC
1401 _EOT_
1402 if [ "$PACKED_SIZE" ]; then
1403 cat >> $pkg_repository/packages.txt << _EOT_
1404 $PACKED_SIZE ($UNPACKED_SIZE installed)
1406 _EOT_
1407 else
1408 echo "" >> $pkg_repository/packages.txt
1409 fi
1411 # Packages.desc is used by Tazpkgbox <tree>.
1412 echo "$PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> $pkg_repository/packages.desc
1414 # Packages.equiv is used by tazpkg install to check depends.
1415 for i in $PROVIDE; do
1416 DEST=""
1417 echo $i | fgrep -q : && DEST="${i#*:}:"
1418 if grep -qs ^${i%:*}= $pkg_repository/packages.equiv; then
1419 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" $pkg_repository/packages.equiv
1420 else
1421 echo "${i%:*}=$DEST$PACKAGE" >> $pkg_repository/packages.equiv
1422 fi
1423 done
1425 if [ -f files.list ]; then
1426 { echo "$PACKAGE"; cat files.list; } | awk '
1427 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }' >> $pkg_repository/files.list
1428 fi
1430 cd .. && rm -r "$pkg_files_dir"
1432 cd $pkg_repository
1433 echo $(basename ${pkg%.tazpkg}) >> packages.list
1434 [ ! "$package_md5" ] && package_md5=$(md5sum $(basename $pkg))
1435 echo "$package_md5" >> packages.md5
1436 unset package_md5
1439 source_receipt()
1441 unset PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
1442 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
1443 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
1444 src _pkg DESTDIR CONFIG_SITE BRANCH TARBALL KBASEVER \
1445 stuff wanted_stuff
1446 . ${RECEIPT:-$PWD/receipt}
1449 packages_db_end()
1451 cd $pkg_repository
1452 pkgs=$(wc -l packages.list | sed 's/ .*//')
1453 sed "s/# Packages : .*/# Packages : $pkgs/" -i packages.txt
1455 # If lists were updated it's generally needed to sort them well.
1456 if ! sort -c packages.list 2> /dev/null; then
1457 report step "Sorting packages lists"
1458 for file in packages.list packages.desc packages.equiv; do
1459 [ -f $file ] || continue
1460 sort -o $file $file
1461 done
1462 report end-step
1463 fi
1465 # Dont log this because lzma always output errors.
1466 lzma e files.list files.list.lzma
1467 rm -f files.list
1468 [ -f packages.equiv ] || touch packages.equiv
1471 ########################################################################
1472 # This section contains functions to generate wok database.
1473 ########################
1475 gen_wok_db()
1477 report step "Generating wok database"
1478 report open-bloc
1479 report step "Removing old files"
1480 for file in $wan_db $dep_db $PACKAGES_REPOSITORY/cookorder.txt; do
1481 [ -f $file ] && rm $file
1482 done
1483 report step "Generating wok-wanted.txt"
1484 gen_wan_db
1485 report step "Generating wok-depends.txt"
1486 gen_dep_db
1487 sort_db
1488 report close-bloc
1491 gen_wan_db()
1493 [ -f $wan_db ] && rm -f $wan_db
1494 for RECEIPT in $(fgrep -l WANTED $WOK/*/receipt); do
1495 WANTED=
1496 source $RECEIPT
1497 [ "$WANTED" ] || continue
1498 echo -e $PACKAGE"\t"$WANTED >> $wan_db
1499 done
1502 gen_dep_db()
1504 [ -f $dep_db ] && rm -f $dep_db
1505 for PACKAGE in $(ls $WOK); do
1506 RECEIPT=$WOK/$PACKAGE/receipt
1507 if [ -s $RECEIPT ]; then
1508 source_receipt
1509 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
1510 fi
1511 done
1514 update_wan_db()
1516 local PACKAGE=$PACKAGE
1517 wanted_list=$(fgrep WANTED=\"$PACKAGE\" $WOK/*/receipt | cut -f1 -d ':')
1518 grep $'\t'$PACKAGE $wan_db | cut -f 1 | while read wan; do
1519 echo "$wanted_list" | fgrep -q /$wan/receipt && continue
1520 sed "/^$wan\t/d" -i $wan_db
1521 done
1522 for RECEIPT in $wanted_list; do
1523 unset WANTED PACKAGE
1524 source $RECEIPT
1525 [ "$WANTED" ] || continue
1526 sed "/^$PACKAGE\t/d" -i $wan_db
1527 echo -e $PACKAGE"\t"$WANTED >> $wan_db
1528 done
1529 unset wanted_list
1532 update_dep_db()
1534 sed "/^$PACKAGE\t/d" -i $dep_db
1535 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
1538 sort_db()
1540 report step "Generating cookorder.txt"
1541 cat $dep_db | sed 's/ \t / /' | while read PACKAGE BUILD_DEPENDS; do
1542 grep -q ^$PACKAGE$'\t' $wan_db && continue
1544 # Replace each BUILD_DEPENDS with a WANTED package by it's
1545 # WANTED package.
1546 replace_by_wanted()
1548 for p in $BUILD_DEPENDS; do
1549 if grep -q ^$p$'\t' $wan_db; then
1550 echo -n $(grep ^$p$'\t' $wan_db | cut -f 2)' '
1551 else
1552 echo -n $p' '
1553 fi
1554 done | tr ' ' '\n' | sort -u | sed "/^$PACKAGE$/d" | tr '\n' ' '
1556 echo -e $PACKAGE"\t $(replace_by_wanted) "
1557 done > $tmp/db
1558 while [ -s "$tmp/db" ]; do
1559 status=start
1560 for pkg in $(cut -f 1 $tmp/db); do
1561 if ! fgrep -q ' '$pkg' ' $tmp/db; then
1562 echo $pkg >> $tmp/cookorder
1563 sed -e "/^$pkg\t/d" -e "s/ $pkg / /g" -i $tmp/db
1564 status=proceed
1565 fi
1566 done
1567 if [ "$status" = start ]; then
1568 cp -f $tmp/db /tmp/remain-depends.txt
1569 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
1570 for remaining in $(cut -f 1 $tmp/db); do
1571 if ! grep -q ^$remaining $PACKAGES_REPOSITORY/blocked; then
1572 echo "$remaining" >> $PACKAGES_REPOSITORY/blocked
1573 fi
1574 done
1575 break
1576 fi
1577 done
1578 [ -s $tmp/cookorder ] || touch $tmp/cookorder
1580 # The toolchain packages are moved in first position.
1581 grep $(for pkg in `scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
1582 --look_for=all --with_args`; do echo " -e ^$pkg$"; done) \
1583 $tmp/cookorder | tac > $PACKAGES_REPOSITORY/cookorder.txt
1584 for pkg in $(cat $PACKAGES_REPOSITORY/cookorder.txt); do
1585 sed "/^$pkg$/d" -i $tmp/cookorder
1586 done
1588 tac $tmp/cookorder >> $PACKAGES_REPOSITORY/cookorder.txt
1589 report end-step
1592 ########################################################################
1593 # SCAN CORE
1594 ########################
1595 # Includes various scan core-functions. It's not intended to be used
1596 # directly : prefer scan wrappers in next section.
1598 look_for_dep()
1600 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1601 grep -m1 ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
1602 | cut -f 2
1603 else
1604 grep -m1 ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-depends.txt | \
1605 cut -f 2
1606 fi
1609 look_for_bdep()
1611 look_for_all
1614 look_for_all()
1616 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1617 grep -m1 ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
1618 | cut -f 2,3 | sed 's/ / /'
1619 else
1620 grep -m1 ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-depends.txt | \
1621 cut -f 2,3 | sed 's/ / /'
1622 fi
1625 look_for_rdep()
1627 fgrep ' '$PACKAGE' ' $INCOMING_REPOSITORY/wok-depends.txt | cut -f 1
1628 if [ "$undigest" ]; then
1629 for rdep in $(fgrep ' '$PACKAGE' ' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt | cut -f 1); do
1630 if [ ! -f "WOK$/$rdep/receipt" ]; then
1631 echo "$rdep"
1632 fi
1633 done
1634 fi
1637 look_for_rbdep()
1639 fgrep ' '$PACKAGE' ' $INCOMING_REPOSITORY/wok-depends.txt | \
1640 cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1641 if [ "$undigest" ]; then
1642 for rdep in $(fgrep ' '$PACKAGE' ' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
1643 | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1); do
1644 if [ ! -f "WOK$/$rdep/receipt" ]; then
1645 echo "$rdep"
1646 fi
1647 done
1648 fi
1651 # Return WANTED if it exists.
1652 look_for_wanted()
1654 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1655 grep -m1 ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-wanted.txt | cut -f 2
1656 else
1657 grep -m1 ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-wanted.txt | cut -f 2
1658 fi
1661 # Return packages which wants PACKAGE.
1662 look_for_rwanted()
1664 grep $'\t'$PACKAGE$ $INCOMING_REPOSITORY/wok-wanted.txt | cut -f 1
1665 if [ "$undigest" ]; then
1666 for rwanted in $(grep $'\t'$PACKAGE$ $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-wanted.txt | cut -f 1); do
1667 if [ ! -f "$WOK/$rwanted/receipt" ]; then
1668 echo "$rwanted"
1669 fi
1670 done
1671 fi
1674 look_for_dev()
1676 WANTED=$(look_for_wanted)
1677 if [ "$WANTED" ]; then
1678 if [ "$undigest" ] && [ ! -f "$WOK/$WANTED/receipt" ]; then
1679 [ -f "$SLITAZ_DIR/$SLITAZ_VERSION/wok/$WANTED-dev/receipt" ] && echo $WANTED-dev
1680 else
1681 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1682 fi
1683 fi
1684 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1685 [ -f "$SLITAZ_DIR/$SLITAZ_VERSION/wok/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1686 else
1687 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1688 fi
1691 with_dev()
1693 for PACKAGE in $(cat); do
1694 echo $PACKAGE
1695 look_for_dev
1696 done
1699 with_wanted()
1701 for PACKAGE in $(cat); do
1702 echo $PACKAGE
1703 look_for_wanted
1704 done
1707 use_wanted()
1709 for input in $(cat); do
1710 { grep ^$input$'\t' $wan_db || echo $input
1711 } | sed 's/.*\t//'
1712 done
1715 ########################################################################
1716 # SCAN
1717 ########################
1718 # Use wok-wanted.txt and wok-depeds.txt to scan depends.
1719 # Option in command line (must be first arg) :
1720 # --look_for=bdep/rbdep - Look for depends or reverse depends.
1721 # --with_dev - Add development packages (*-dev) in the result.
1722 # --with_wanted - Add package+reverse wanted in the result.
1723 # --with_args - Include packages in argument in the result.
1725 scan()
1727 # Get packages in argument.
1728 local PACKAGE=$PACKAGE WANTED=$WANTED pkg_list=
1729 for arg in $@; do
1730 [ "$arg" = "${arg#--}" ] || continue
1731 pkg_list="$pkg_list $arg"
1732 done
1734 # Get options.
1735 [ "$pkg_list" ] || return
1736 local cooklist= look_for= with_dev= with_wanted= with_args= log_command="$0 $@" \
1737 get_options_list="look_for with_dev with_wanted with_args cooklist use_wanted"
1738 get_options
1740 # Get db md5 to be able to check for changes latter.
1741 db_md5=$(md5sum $dep_db $wan_db)
1743 # Cooklist is a special case where we need to modify a little
1744 # scan behavior
1745 if [ "$cooklist" ]; then
1746 gen_wan_db
1747 look_for=all && with_args=yes && with_dev= && with_wanted=
1748 filter=use_wanted
1749 if [ "$COMMAND" = gen-cooklist ]; then
1750 for PACKAGE in $pkg_list; do
1751 grep -q ^$PACKAGE$'\t' $dep_db && continue
1752 [ -d "$WOK/$p" ] || continue
1753 check_for_missing
1754 done
1755 append_to_dep()
1757 if ! grep -q ^$PACKAGE$'\t' $dep_db; then
1758 check_for_missing && echo $PACKAGE >> $tmp/dep
1759 else
1760 echo $PACKAGE >> $tmp/dep
1761 fi
1763 else
1764 append_to_dep()
1766 check_for_commit && echo $PACKAGE >> $tmp/dep
1768 fi
1769 else
1770 append_to_dep()
1772 echo $PACKAGE >> $tmp/dep
1774 # If requested packages are not in dep_db, partial generation of this db is needed.
1775 for PACKAGE in $pkg_list; do
1776 grep -q ^$PACKAGE$'\t' $dep_db && continue
1777 [ -d "$WOK/$p" ] || continue
1778 plan_check_for_missing=yes
1779 check_for_missing
1780 done
1781 if [ "$plan_check_for_missing" ]; then
1782 append_to_dep()
1784 if ! grep -q ^$PACKAGE$'\t' $dep_db; then
1785 check_for_missing && echo $PACKAGE >> $tmp/dep
1786 else
1787 echo $PACKAGE >> $tmp/dep
1788 fi
1790 unset plan_check_for_missing
1791 fi
1792 fi
1794 [ "$with_dev" ] && filter=with_dev
1795 [ "$with_wanted" ] && filter=with_wanted
1796 if [ "$filter" ]; then
1797 pkg_list=$(echo $pkg_list | $filter | sort -u)
1798 scan_pkg()
1800 look_for_$look_for | $filter
1802 else
1803 scan_pkg()
1805 look_for_$look_for
1807 fi
1808 touch $tmp/dep
1809 for PACKAGE in $pkg_list; do
1810 [ "$with_args" ] && append_to_dep
1811 scan_pkg
1812 done | tr ' ' '\n' | sort -u > $tmp/list
1813 [ "$look_for" = bdep ] && look_for=dep
1814 while [ -s $tmp/list ]; do
1815 PACKAGE=$(sed 1!d $tmp/list)
1816 sed 1d -i $tmp/list
1817 append_to_dep
1818 for pkg in $(scan_pkg); do
1819 if ! grep -q ^$pkg$ $tmp/list $tmp/dep; then
1820 echo $pkg >> $tmp/list
1821 fi
1822 done
1823 done
1824 if [ "$cooklist" ]; then
1825 mv $tmp/dep $tmp/cooklist
1826 else
1827 cat $tmp/dep | sort -u
1828 fi
1829 rm -f $tmp/dep $tmp/list
1830 sort -o $dep_db $dep_db
1831 sort -o $wan_db $wan_db
1832 if [ "$db_md5" != "$(md5sum $dep_db $wan_db)" ]; then
1833 grep -q "^#" $PACKAGES_REPOSITORY/cookorder.txt ||
1834 sed 1i"#PlanSort" -i $PACKAGES_REPOSITORY/cookorder.txt
1835 fi
1838 ########################################################################
1839 # This section contains functions to check the package repository and
1840 # find which packages to cook.
1841 ########################
1843 check_for_missing()
1845 local PACKAGE=$PACKAGE
1846 if ! check_for_pkg_in_wok; then
1847 [ "$?" = 2 ] && return 1
1848 return
1849 fi
1850 RECEIPT=$WOK/$PACKAGE/receipt
1851 source_receipt
1852 PACKAGE=${WANTED:-$PACKAGE}
1853 update_wan_db
1854 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1855 RECEIPT=$WOK/$PACKAGE/receipt
1856 source_receipt
1857 update_dep_db
1858 done
1861 check_for_commit()
1863 if ! check_for_pkg_in_wok; then
1864 [ "$?" = 2 ] && return 1
1865 return
1866 fi
1867 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1868 RECEIPT=$WOK/$PACKAGE/receipt
1869 source_receipt
1871 # We use md5 of cooking stuff in the packaged receipt to check
1872 # commit. We look consecutively in 3 different locations :
1873 # - in the wok/PACKAGE/taz/* folder
1874 # - in the receipt in the package in incoming repository
1875 # - in the receipt in the package in packages repository
1876 # If md5sums match, there's no commit.
1877 check_for_commit_using_md5sum()
1879 if [ ! -f $WOK/$PACKAGE/md5 ]; then
1880 sed -n '/# md5sum of cooking stuff :/,$p' receipt | \
1881 sed -e 1d -e 's/^# //' > $WOK/$PACKAGE/md5
1882 cd $WOK/$PACKAGE
1883 fi
1885 if [ -s md5 ]; then
1886 if md5sum -cs md5; then
1888 # If md5sum check if ok, check for new/missing files in
1889 # cooking stuff.
1890 for file in $([ -f receipt ] && echo receipt; \
1891 [ -f description.txt ] && echo description.txt; \
1892 [ -d stuff ] && find stuff); do
1893 if ! fgrep -q " $file" md5; then
1894 set_commited
1895 fi
1896 done
1897 else
1898 set_commited
1899 fi
1900 else
1901 set_commited
1902 fi
1904 set_commited()
1906 ! grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/commit &&
1907 echo $PACKAGE >> $PACKAGES_REPOSITORY/commit
1908 gen_cookmd5
1909 update_dep_db
1911 taz_dir=$(echo $WOK/$PACKAGE/taz/$PACKAGE-* | fgrep -v '*')
1912 if [ -f $WOK/$PACKAGE/md5 ]; then
1913 cd $WOK/$PACKAGE
1914 check_for_commit_using_md5sum
1915 elif [ "$taz_dir" ]; then
1916 cd $taz_dir
1917 check_for_commit_using_md5sum
1918 else
1919 pkg=$(echo $INCOMING_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
1920 [ "$pkg" ] || pkg=$(echo $PACKAGES_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
1921 if [ "$pkg" ]; then
1922 get_pkg_files $pkg
1923 check_for_commit_using_md5sum
1924 rm -r $pkg_files_dir
1925 else
1926 set_commited
1927 fi
1928 fi
1929 [ "$forced" ] || echo $PACKAGE >> $tmp/checked
1930 done
1931 return
1934 gen_cook_list()
1936 report step "Scanning wok"
1937 if [ "$pkg" ]; then
1938 scan $pkg --cooklist
1939 else
1940 scan `cat $cooklist` --cooklist
1941 fi
1942 report end-step
1944 [ -s $tmp/checked ] || [ -s $tmp/cooklist ] || return
1946 # Core toolchain should not be cooked unless cook-toolchain is used.
1947 if ! [ -f /etc/config.site.tmptoolchain ] ; then
1948 for PACKAGE in $(scan gcc --look_for=all --with_args --with_wanted); do
1949 grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/blocked || \
1950 echo $PACKAGE >> $PACKAGES_REPOSITORY/blocked
1951 done
1952 fi
1954 if [ -s $PACKAGES_REPOSITORY/commit ] && [ "$COMMAND" != gen-cooklist ]; then
1955 cd $PACKAGES_REPOSITORY
1956 for PACKAGE in $(cat commit); do
1957 WANTED="$(look_for_wanted)"
1958 if [ "$WANTED" ]; then
1959 grep -q ^$WANTED$ broken cooklist blocked commit && continue
1960 fi
1961 grep -q ^$PACKAGE$ blocked cooklist && continue
1962 echo $PACKAGE >> cooklist
1963 done
1964 fi
1965 sort_cooklist
1968 sort_cooklist()
1970 if [ "$(sed 1!d $PACKAGES_REPOSITORY/cookorder.txt)" = "#PlanSort" ]; then
1971 sed 1d -i $PACKAGES_REPOSITORY/cookorder.txt
1972 sort_db
1973 fi
1974 report step "Generating cooklist"
1975 if [ -f "$tmp/checked" ]; then
1976 rm -f $tmp/cooklist
1977 cat $tmp/checked | while read PACKAGE; do
1978 grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/cooklist && \
1979 echo $PACKAGE >> $tmp/cooklist
1980 done
1981 elif ! [ "$COMMAND" = gen-cooklist ]; then
1982 cat $PACKAGES_REPOSITORY/blocked | while read PACKAGE; do
1983 sed "/^$PACKAGE/d" -i $tmp/cooklist
1984 done
1985 fi
1986 report end-step
1987 [ -s $tmp/cooklist ] || return
1989 report step "Sorting cooklist"
1990 for PACKAGE in $(cat $tmp/cooklist); do
1991 WANTED="$(look_for_wanted)"
1992 [ "$WANTED" ] || continue
1993 if grep -q ^$WANTED$ $PACKAGES_REPOSITORY/broken $tmp/cooklist; then
1994 sed "/^$PACKAGE$/d" -i $tmp/cooklist
1995 elif [ ! -d $WOK/$WANTED/install ]; then
1996 sed "/^$PACKAGE$/d" -i $tmp/cooklist
1997 echo $WANTED >> $tmp/cooklist
1998 fi
1999 done
2001 # Use cookorder.txt to sort cooklist.
2002 if [ -s $tmp/cooklist ]; then
2003 cat $PACKAGES_REPOSITORY/cookorder.txt | while read PACKAGE; do
2004 if grep -q ^$PACKAGE$ $tmp/cooklist; then
2005 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2006 echo $PACKAGE >> $tmp/cooklist.tmp
2007 fi
2008 done
2010 # Remaining packages in cooklist are those without compile_rules.
2011 # They can be cooked first in any order.
2012 if [ -f $tmp/cooklist.tmp ]; then
2013 cat $tmp/cooklist.tmp >> $tmp/cooklist
2014 rm $tmp/cooklist.tmp
2015 fi
2017 cat $tmp/cooklist
2018 [ "$cooklist" = "$PACKAGES_REPOSITORY/cooklist" ] && \
2019 cat $tmp/cooklist > $cooklist
2020 fi
2022 report end-step
2025 look_for_missing_pkg()
2027 for pkg in $(cat $PACKAGES_REPOSITORY/$1); do
2028 grep -q ^$pkg$ $INCOMING_REPOSITORY/packages.txt \
2029 $PACKAGES_REPOSITORY/packages.txt || \
2030 continue
2031 echo $pkg
2032 done
2035 check_for_incoming()
2037 report step "Checking that all packages were cooked OK"
2038 [ -s $INCOMING_REPOSITORY/packages.desc ] || {
2039 echo "No packages in $INCOMING_REPOSITORY."
2040 report end-step; return; }
2041 if [ -s $PACKAGES_REPOSITORY/broken ]; then
2042 missingpkg=$(look_for_missing_pkg broken)
2043 if [ "$missingpkg" ]; then
2044 echo "Don't move incoming packages to main repository because these ones are broken:" >&2
2045 echo "$missingpkg"
2046 report end-step
2047 return 1
2048 fi
2049 fi
2050 if [ -s $PACKAGES_REPOSITORY/cooklist ]; then
2051 missingpkg=$(look_for_missing_pkg cooklist)
2052 if [ "$missingpkg" ]; then
2053 echo "Don't move incoming packages to main repository because these ones need to be cooked:" >&2
2054 echo "$missingpkg"
2055 report end-step
2056 return 1
2057 fi
2058 fi
2059 incoming_pkgs="$(cut -f 1 -d '|' $INCOMING_REPOSITORY/packages.desc)"
2060 if ! [ "$forced" ]; then
2061 cooklist=$PACKAGES_REPOSITORY/cooklist
2062 pkg="$incoming_pkgs"
2063 gen_cook_list
2064 if [ -s $PACKAGES_REPOSITORY/cooklist ]; then
2065 missingpkg=$(look_for_missing_pkg cooklist)
2066 if [ "$missingpkg" ]; then
2067 echo "Don't move incoming packages to main repository because these ones need to be cooked:" >&2
2068 echo "$missingpkg"
2069 report end-step
2070 return 1
2071 fi
2072 fi
2073 fi
2075 report step "Moving incoming packages to main repository"
2076 unset EXTRAVERSION
2077 for PACKAGE in $incoming_pkgs; do
2078 prev_VERSION=$(get_pkg_version $PACKAGES_REPOSITORY)
2079 VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
2080 remove_previous_package $PACKAGES_REPOSITORY
2081 echo "Moving $PACKAGE..."
2082 mv -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION.tazpkg $PACKAGES_REPOSITORY
2083 touch $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
2084 previous_tarball=$(grep ^$PACKAGE:main $SOURCES_REPOSITORY/sources.list | cut -f2)
2085 sed -e "/^$PACKAGE:main/d" \
2086 -e "s/^$PACKAGE:incoming/$PACKAGE:main/" \
2087 -i $SOURCES_REPOSITORY/sources.list
2088 if [ "$previous_tarball" ]; then
2089 grep -q $'\t'$previous_tarball$ $SOURCES_REPOSITORY/sources.list || \
2090 rm -f $SOURCES_REPOSITORY/$previous_tarball
2091 fi
2092 done
2093 for file in packages.list packages.equiv packages.md5 packages.desc \
2094 packages.txt; do
2095 echo -n "" > $INCOMING_REPOSITORY/$file
2096 done
2097 rm -r $INCOMING_REPOSITORY/files.list.lzma
2098 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2100 report step "Updating flavors"
2101 if [ -x /usr/bin/tazlito ] || [ -x /usr/bin/clean-chroot ]; then
2102 if ! [ -x /usr/bin/tazlito ]; then
2103 tazpkg get-install tazlito
2104 fi
2106 # Handle cases where tazwok is used into main system;
2107 # Handle cases where SLITAZ_DIR is not /home/slitaz.
2108 [ -L /home/slitaz/flavors ] && rm /home/slitaz/flavors
2109 mkdir -p /home/slitaz
2110 ln -s $LOCAL_REPOSITORY/flavors /home/slitaz/flavors
2111 cd /home/slitaz/flavors
2112 [ -d .hg ] && hg pull -u
2114 cd $LOCAL_REPOSITORY/packages
2115 for i in $LOCAL_REPOSITORY/flavors/*; do
2116 [ -d "$i" ] || continue
2117 tazlito pack-flavor ${i##*/}
2118 done
2120 noheader=""
2121 for i in *.flavor; do
2122 tazlito show-flavor $i --brief $noheader
2123 noheader="--noheader"
2124 done > flavors.list
2125 [ -x /usr/bin/clean-chroot ] && clean-chroot
2126 else
2127 echo "Can't create up-to-date flavors because the tazlito package is missing." >&2
2128 fi
2129 report end-step
2132 ########################################################################
2133 # TAZWOK MAIN FUNCTIONS
2134 ########################
2136 clean()
2138 cd $WOK/$PACKAGE
2139 ls -A $WOK/$PACKAGE | grep -q -v -e ^receipt$ -e ^description.txt$ \
2140 -e ^stuff$ || return
2142 [ "$COMMAND" = clean-wok ] || report step "Cleaning $PACKAGE"
2143 # Check for clean_wok function.
2144 if grep -q ^clean_wok $RECEIPT; then
2145 clean_wok
2146 fi
2147 # Clean should only have a receipt, stuff and optional desc.
2148 for f in `ls .`
2149 do
2150 case $f in
2151 receipt|stuff|description.txt|md5)
2152 continue ;;
2153 *)
2154 rm -rf $f ;;
2155 esac
2156 done
2157 [ "$COMMAND" != clean-wok ] && report end-step
2160 # Configure and make a package with the receipt.
2161 compile_package()
2163 check_for_package_on_cmdline
2165 # Include the receipt to get all needed variables and functions
2166 # and cd into the work directory to start the work.
2167 check_for_receipt
2168 source_receipt
2170 # Log the package name and date.
2171 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
2172 echo "package $PACKAGE (compile)" >> $LOG
2174 # Set wanted $src variable to help compiling.
2175 [ ! "$src" ] && set_src_path
2176 check_for_build_depends || return 1
2177 check_for_wanted
2178 unset target
2179 check_for_tarball && check_for_compile_rules
2182 # Cook command also include all features to manage lists which keep
2183 # track of wok/packages state.
2184 cook()
2186 cook_code=
2187 set_common_path
2188 check_for_receipt
2189 source_receipt
2191 # Define log path and start report.
2192 [ -f $LOCAL_REPOSITORY/log/$PACKAGE.html ] && rm $LOCAL_REPOSITORY/log/$PACKAGE.html
2193 report sublog $LOCAL_REPOSITORY/log/$PACKAGE.html
2194 echo "$PACKAGE" > $LOCAL_REPOSITORY/log/package
2195 report step "Cooking $PACKAGE"
2196 report open-bloc
2198 clean $PACKAGE
2199 [ -s $tmp/cooklist ] && sed "/^$PACKAGE$/d" -i $tmp/cooklist
2201 if compile_package; then
2202 remove_src
2203 refresh_packages_from_compile
2204 gen_package
2206 # Update packages-incoming repository.
2207 store_pkgname=$PACKAGE
2208 pkg_repository=$INCOMING_REPOSITORY
2209 update_packages_db
2211 PACKAGE=$store_pkgname
2212 unset store_pkgname
2214 # Upgrade to cooked packages if it was previously installed.
2215 report step "Looking for package(s) to upgrade"
2216 for pkg in $(look_for_rwanted) $PACKAGE; do
2217 if [ -d $INSTALLED/$pkg ]; then
2218 tazpkg get-install $pkg --forced
2219 fi
2220 done
2221 report end-step
2222 else
2223 for PACKAGE in $(look_for_wanted) $PACKAGE; do
2224 set_pkg_broken
2225 done
2226 cook_code=1
2227 fi
2229 # Remove build_depends in cook mode (if in cooklist, it's done when
2230 # checking build_depends of next package and we remove only unneeded
2231 # packages to keep chroot minimal and gain some time).
2232 if [ "$COMMAND" = cook ]; then
2233 remove_build_depends $MISSING_PACKAGE
2234 [ -x /usr/bin/clean-chroot ] && clean-chroot
2235 fi
2237 # Regen the cooklist if it was planned and command is not cook.
2238 [ "$regen_cooklist" ] && unset regen_cooklist && \
2239 [ "$COMMAND" != cook ] && sort_cooklist
2241 # Some hacks to set the bloc & function status as failed if cook has
2242 # failed.
2243 report_return_code=$cook_code
2244 report close-bloc
2245 report end-sublog
2246 rm -f $LOCAL_REPOSITORY/log/package
2247 return $cook_code
2250 cook_list()
2252 if [ -s $tmp/cooklist ]; then
2253 if [ -f /usr/bin/tazchroot ]; then
2254 # Note : options -main variables- are automatically kept by
2255 # the sub-applications tazchroot/tazwok; as well as report data.
2256 cd $LOCAL_REPOSITORY
2257 [ ! -f tazchroot.conf ] && configure_tazchroot
2258 tazchroot tazwok cook-list --SLITAZ_DIR=$SLITAZ_DIR --SLITAZ_VERSION=$SLITAZ_VERSION ${undigest:+ --undigest=$undigest}
2259 return
2260 fi
2261 while [ -s $tmp/cooklist ]; do
2262 PACKAGE=$(sed 1!d $tmp/cooklist)
2263 cook
2264 done
2265 remove_build_depends $MISSING_PACKAGE $remove_later
2266 [ -x /usr/bin/clean-chroot ] && clean-chroot
2267 else
2268 echo "Nothing to cook."
2269 return
2270 fi
2273 configure_tazchroot()
2275 cat > $LOCAL_REPOSITORY/tazchroot.conf << EOF
2276 # Tazchroot configuration file - created by tazwok.
2278 # Default chroot path.
2279 SLITAZ_DIR=$SLITAZ_DIR
2280 SLITAZ_VERSION=$SLITAZ_VERSION
2281 $( [ "$undigest" ] && echo "undigest=$undigest" )
2282 LOCAL_REPOSITORY=$SLITAZ_DIR/$(if [ "$undigest" ]; then echo '$undigest'; else echo '$SLITAZ_VERSION'; fi)
2283 chroot_dir=\$LOCAL_REPOSITORY/chroot
2285 # Default scripts path (these scripts are added to the
2286 # $chroot_dir/usr/bin and can be called with tazchroot script).
2287 script_dir=/usr/lib/slitaz/chroot-scripts/tazwok
2289 # List of directories to mount.
2290 list_dir="$(for dir in packages wok src packages-incoming log flavors iso clean-wok; do echo $LOCAL_REPOSITORY/$dir; done)
2291 $SLITAZ_LOG$( [ "$undigest" ] && echo -e "\n$SLITAZ_DIR/$SLITAZ_VERSION/packages" )"
2293 create_chroot()
2295 mkdir -p \$chroot_dir
2296 for pkg in \$(tazwok build-depends toolchain --SLITAZ_DIR=\$SLITAZ_DIR --SLITAZ_VERSION=\$SLITAZ_VERSION${undigest:+ --undigest=\$undigest}); do
2297 tazpkg get-install \$pkg --root="\$chroot_dir"
2298 done
2300 # Store list of installed packages needed by cleanchroot.
2301 ls -1 \$chroot_dir/\$INSTALLED > \$chroot_dir/\$LOCALSTATE/chroot-pkgs
2303 sed -e "s~^SLITAZ_DIR=.*~SLITAZ_DIR=\$SLITAZ_DIR~" \\
2304 -e "s/^SLITAZ_VERSION=.*/SLITAZ_VERSION=\$SLITAZ_VERSION/" \\
2305 -i \$chroot_dir/etc/slitaz/slitaz.conf
2306 echo \$SLITAZ_VERSION > \$chroot_dir/etc/slitaz-release
2307 $( [ "$undigest" ] && echo ' echo "undigest='"$undigest"'" >> $chroot_dir/etc/slitaz/tazwok.conf')
2308 sed 's/LC_ALL/LC_ALL=POSIX/' -i \$chroot_dir/etc/profile
2309 # The build bot may run in a sandbox: link sandbox lockfile.
2310 [ -d \$LOCAL_REPOSITORY/sandbox ] && ln -s \$LOCAL_REPOSITORY/sandbox/proc/1 \$chroot_dir/proc/1
2313 mount_chroot()
2315 cp -a /etc/resolv.conf \$chroot_dir/etc/resolv.conf
2316 echo "\$LOCAL_REPOSITORY/packages" > \$chroot_dir\$LOCALSTATE/mirror
2317 mkdir -p \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming
2318 echo "\$LOCAL_REPOSITORY/packages-incoming" > \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming/mirror
2319 $( [ "$undigest" ] && echo ' mkdir -p $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION
2320 echo "$SLITAZ_DIR/$SLITAZ_VERSION/packages" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror' )
2321 echo -e "\${LOCAL_REPOSITORY##*/}-incoming\nmain" > \$chroot_dir\$LOCALSTATE/priority
2322 mount -o bind /proc \$chroot_dir/proc
2323 mount -o bind /sys \$chroot_dir/sys
2324 mount -o bind /dev/pts \$chroot_dir/dev/pts
2325 mount -o bind /dev/shm \$chroot_dir/dev/shm
2326 for dir in \$list_dir; do
2327 mkdir -p \$dir \$chroot_dir\$dir
2328 mount \$dir \$chroot_dir\$dir
2329 done
2332 umount_chroot()
2334 for dir in \$list_dir; do
2335 umount \$chroot_dir\$dir
2336 done
2337 umount \$chroot_dir/dev/shm
2338 umount \$chroot_dir/dev/pts
2339 umount \$chroot_dir/sys
2340 umount \$chroot_dir/proc
2342 EOF
2345 ########################################################################
2346 ######################### END OF NEW FUNCTIONS #########################
2347 ########################################################################
2349 # List packages providing a virtual package.
2350 whoprovide()
2352 local i;
2353 for i in $(fgrep -l PROVIDE $WOK/*/receipt); do
2354 . $i
2355 case " $PROVIDE " in
2356 *\ $1\ *|*\ $1:*) echo $(basename $(dirname $i));;
2357 esac
2358 done
2361 ########################################################################
2362 # TAZWOK COMMANDS
2363 ########################
2365 case "$COMMAND" in
2366 stats)
2367 # Tazwok general statistics from the wok config file.
2369 get_tazwok_config
2370 echo -e "\n\033[1mTazwok configuration statistics\033[0m
2371 ================================================================================
2372 Wok directory : $WOK
2373 Packages repository : $PACKAGES_REPOSITORY
2374 Incoming repository : $INCOMING_REPOSITORY
2375 Sources repository : $SOURCES_REPOSITORY
2376 Log directory : $LOCAL_REPOSITORY/log
2377 Packages in the wok : `ls -1 $WOK | wc -l`
2378 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2379 Incoming packages : `ls -1 $INCOMING_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2380 ================================================================================\n"
2381 ;;
2382 edit)
2383 get_tazwok_config
2384 check_for_package_on_cmdline
2385 check_for_receipt
2386 $EDITOR $WOK/$PACKAGE/receipt
2387 ;;
2388 build-depends)
2389 # List dependencies to rebuild wok, or only a package.
2390 get_tazwok_config
2391 report(){ : ; }
2392 if [ ! "$PACKAGE" ] || [ "$PACKAGE" = toolchain ]; then
2393 scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
2394 --look_for=dep --with_dev --with_args
2395 else
2396 check_for_package_on_cmdline
2397 scan $PACKAGE --look_for=bdep --with_dev
2398 fi
2399 ;;
2400 gen-cooklist)
2401 check_root
2402 get_options_list="pkg"
2403 get_tazwok_config
2404 report(){ : ; }
2405 if ! [ "$pkg" ]; then
2406 if [ ! "$LIST" ] || [ "$LIST" = toolchain ]; then
2407 pkg="$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA"
2408 else
2409 cooklist=${LIST:-$PACKAGES_REPOSITORY/cooklist}
2410 fi
2411 fi
2412 gen_cook_list
2413 ;;
2414 check-depends)
2415 # Check package depends /!\.
2416 get_tazwok_config
2417 echo ""
2418 echo -e "\033[1mCheck every receipt for DEPENDS - doesn't scan ELF files\033[0m
2419 ================================================================================"
2420 TMPDIR=/tmp/tazwok$$
2421 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
2423 # Build ALL_DEPENDS variable.
2424 scan_dep()
2426 local i
2427 ALL_DEPENDS="$ALL_DEPENDS$PACKAGE "
2428 for i in $DEPENDS $SUGGESTED ; do
2429 case " $ALL_DEPENDS " in
2430 *\ $i\ *) continue;;
2431 esac
2432 [ -d $WOK/$i ] || {
2433 ALL_DEPENDS="$ALL_DEPENDS$i "
2434 continue
2436 DEPENDS=""
2437 SUGGESTED=""
2438 . $WOK/$i/receipt
2439 scan_dep
2440 done
2443 # Check for ELF file.
2444 is_elf()
2446 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
2449 # Print shared library dependencies.
2450 ldd()
2452 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
2455 mkdir $TMPDIR
2456 cd $TMPDIR
2457 for i in $LOCALSTATE/files.list.lzma \
2458 $LOCALSTATE/undigest/*/files.list.lzma ; do
2459 [ -f $i ] && lzma d $i -so >> files.list
2460 done
2461 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
2462 tazpkg extract $pkg > /dev/null 2>&1
2463 . */receipt
2464 ALL_DEPENDS="$DEFAULT_DEPENDS "
2465 scan_dep
2466 find */fs -type f | while read file ; do
2467 is_elf $file || continue
2468 case "$file" in
2469 *.o|*.ko|*.ko.gz) continue;;
2470 esac
2471 ldd $file | while read lib rem; do
2472 case "$lib" in
2473 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
2474 continue;;
2475 esac
2476 for dep in $(fgrep $lib files.list | cut -d: -f1); do
2477 case " $ALL_DEPENDS " in
2478 *\ $dep\ *) continue 2;;
2479 esac
2480 for vdep in $(fgrep $dep $LOCALSTATE/packages.equiv | cut -d= -f1); do
2481 case " $ALL_DEPENDS " in
2482 *\ $vdep\ *) continue 3;;
2483 esac
2484 done
2485 done
2486 [ -n "$dep" ] || dep="UNKNOWN"
2487 echo "$(basename $pkg): ${file#*fs} depends on package $dep for the shared library $lib"
2488 done
2489 done
2490 rm -rf */
2491 done
2492 cd /tmp
2493 rm -rf $TMPDIR
2494 ;;
2495 check)
2496 # Check wok consistency.
2497 get_tazwok_config
2498 echo ""
2499 echo -e "\033[1mWok and packages checking\033[0m
2500 ================================================================================"
2501 cd $WOK
2502 for pkg in $(ls)
2503 do
2504 [ -f $pkg/receipt ] || continue
2505 RECEIPT= $pkg/receipt
2506 source_receipt
2507 [ "$PACKAGE" = "$pkg" ] || echo "Package $PACKAGE should be $pkg" >&2
2508 [ -n "$VERSION" ] || echo "Package $PACKAGE has no VERSION" >&2
2509 [ -n "$PACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded PACKED_SIZE" >&2
2510 [ -n "$UNPACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded UNPACKED_SIZE" >&2
2511 [ -n "$EXTRAVERSION" ] && echo "Package $PACKAGE has hardcoded EXTRAVERSION" >&2
2512 if [ -n "$WANTED" ]; then
2513 if [ ! -f $WANTED/receipt ]; then
2514 echo "Package $PACKAGE wants unknown $WANTED package" >&2
2515 else
2516 BASEVERSION=$(. $WANTED/receipt ; echo $VERSION)
2517 if [ "$VERSION" = "$WANTED" ]; then
2518 # BASEVERSION is computed in receipt
2519 fgrep -q '_pkg=' $pkg/receipt &&
2520 BASEVERSION=$VERSION
2521 fi
2522 if [ "$VERSION" != "$BASEVERSION" ]; then
2523 echo "Package $PACKAGE ($VERSION) wants $WANTED ($BASEVERSION)" >&2
2524 fi
2525 fi
2526 fi
2528 if [ -n "$CATEGORY" ]; then
2529 case " $(echo $CATEGORIES) " in
2530 *\ $CATEGORY\ *);;
2531 *) echo "Package $PACKAGE has an invalid CATEGORY" >&2;;
2532 esac
2533 else
2534 echo"Package $PACKAGE has no CATEGORY" >&2
2535 fi
2536 [ -n "$SHORT_DESC" ] || echo "Package $PACKAGE has no SHORT_DESC" >&2
2537 [ -n "$MAINTAINER" ] || echo "Package $PACKAGE has no MAINTAINER" >&2
2538 case "$WGET_URL" in
2539 ftp*|http*) busybox wget -s $WGET_URL 2> /dev/null ||
2540 echo "Package $PACKAGE has a wrong WGET_URL" >&2;;
2541 '') ;;
2542 *) echo "Package $PACKAGE has an invalid WGET_URL" >&2;;
2543 esac
2544 case "$WEB_SITE" in
2545 ftp*|http*);;
2546 '') echo "Package $PACKAGE has no WEB_SITE" >&2;;
2547 *) echo "Package $PACKAGE has an invalid WEB_SITE" >&2;;
2548 esac
2549 case "$MAINTAINER" in
2550 *\<*|*\>*) echo "Package $PACKAGE has an invalid MAINTAINER: $MAINTAINER" >&2;;
2551 esac
2552 case "$MAINTAINER" in
2553 *@*);;
2554 *) echo "Package $PACKAGE MAINTAINER is not an email address" >&2;;
2555 esac
2556 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2557 for i in $DEPENDS; do
2558 [ -d $i ] && continue
2559 [ -n "$(whoprovide $i)" ] && continue
2560 echo -e "$MSG $i"
2561 MSG=""
2562 done
2563 MSG="Missing build dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2564 for i in $BUILD_DEPENDS; do
2565 [ -d $i ] && continue
2566 [ -n "$(whoprovide $i)" ] && continue
2567 echo -e "$MSG $i"
2568 MSG=""
2569 done
2570 MSG="Dependency loop between $PACKAGE and :\n"
2571 ALL_DEPS=""
2572 check_for_deps_loop $PACKAGE $DEPENDS
2573 [ -d $WOK/$pkg/taz ] && for i in $BUILD_DEPENDS; do
2574 [ $WOK/$pkg/taz -nt $INSTALLED/$i/files.list ] && continue
2575 echo "$pkg should be rebuilt after $i installation"
2576 done
2577 done
2578 ;;
2579 list)
2580 # List packages in wok directory. User can specify a category.
2582 get_tazwok_config
2583 if [ "$2" = "category" ]; then
2584 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
2585 exit 0
2586 fi
2587 # Check for an asked category.
2588 if [ -n "$2" ]; then
2589 ASKED_CATEGORY=$2
2590 echo ""
2591 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
2592 horizontal_line
2593 for pkg in $WOK/*
2594 do
2595 [ ! -f $pkg/receipt ] && continue
2596 . $pkg/receipt
2597 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
2598 echo -n "$PACKAGE"
2599 echo -e "\033[28G $VERSION"
2600 packages=$(($packages+1))
2601 fi
2602 done
2603 horizontal_line
2604 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
2605 else
2606 # By default list all packages and version.
2607 echo ""
2608 echo -e "\033[1mList of packages in the wok\033[0m"
2609 horizontal_line
2610 for pkg in $WOK/*
2611 do
2612 [ ! -f $pkg/receipt ] && continue
2613 . $pkg/receipt
2614 echo -n "$PACKAGE"
2615 echo -en "\033[28G $VERSION"
2616 echo -e "\033[42G $CATEGORY"
2617 packages=$(($packages+1))
2618 done
2619 horizontal_line
2620 echo -e "$packages packages available in the wok.\n"
2621 fi
2622 ;;
2623 info)
2624 # Information about a package.
2626 get_tazwok_config
2627 check_for_package_on_cmdline
2628 check_for_receipt
2629 . $WOK/$PACKAGE/receipt
2630 echo ""
2631 echo -e "\033[1mTazwok package information\033[0m
2632 ================================================================================
2633 Package : $PACKAGE
2634 Version : $VERSION
2635 Category : $CATEGORY
2636 Short desc : $SHORT_DESC
2637 Maintainer : $MAINTAINER"
2638 if [ ! "$WEB_SITE" = "" ]; then
2639 echo "Web site : $WEB_SITE"
2640 fi
2641 if [ ! "$DEPENDS" = "" ]; then
2642 echo "Depends : $DEPENDS"
2643 fi
2644 if [ ! "$WANTED" = "" ]; then
2645 echo "Wanted src : $WANTED"
2646 fi
2647 horizontal_line
2648 echo ""
2649 ;;
2650 check-log)
2651 # We just cat the file log to view process info.
2653 get_tazwok_config
2654 if [ ! -f "$LOG" ]; then
2655 echo -e "\nNo process log found. The package is probably not cooked.\n" >&2
2656 exit 1
2657 else
2658 echo ""
2659 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
2660 horizontal_line
2661 cat $LOG
2662 horizontal_line
2663 echo ""
2664 if [ -s "$WOK/$PACKAGE/warning.txt" ]; then
2665 echo -e "\033[1mCook warning(s) for :\033[0m $PACKAGE"
2666 horizontal_line
2667 cat "$WOK/$PACKAGE/warning.txt"
2668 horizontal_line
2669 echo ""
2670 fi
2671 fi
2672 ;;
2673 search)
2674 # Search for a package by pattern or name.
2676 get_tazwok_config
2677 if [ -z "$2" ]; then
2678 echo -e "\nPlease specify a pattern or a package name to search." >&2
2679 echo -e "Example : 'tazwok search gcc'.\n" >&2
2680 exit 1
2681 fi
2682 echo ""
2683 echo -e "\033[1mSearch result for :\033[0m $2"
2684 horizontal_line
2685 list=`ls -1 $WOK | fgrep $2`
2686 for pkg in $list
2687 do
2688 . $WOK/$pkg/receipt
2689 echo -n "$PACKAGE "
2690 echo -en "\033[24G $VERSION"
2691 echo -e "\033[42G $CATEGORY"
2692 packages=$(($PACKAGEs+1))
2693 done
2694 horizontal_line
2695 echo "$packages packages found for : $2"
2696 echo ""
2697 ;;
2698 compile)
2699 # Configure and make a package with the receipt.
2701 get_tazwok_config
2702 source_lib report
2703 report start
2704 compile_package
2705 ;;
2706 genpkg)
2707 # Generate a package.
2709 get_tazwok_config
2710 source_lib report
2711 report start
2712 gen_package
2713 ;;
2714 cook)
2715 # Compile and generate a package. Just execute tazwok with
2716 # the good commands.
2718 check_root
2719 get_tazwok_config
2720 source_lib report
2721 report start
2722 db_md5=$(md5sum $dep_db $wan_db)
2723 update_wan_db
2724 check_for_commit
2725 sort -o $dep_db $dep_db
2726 sort -o $wan_db $wan_db
2727 if [ "$db_md5" != "$(md5sum $dep_db $wan_db)" ]; then
2728 grep -q "^#" $PACKAGES_REPOSITORY/cookorder.txt ||
2729 sed 1i"#PlanSort" -i $PACKAGES_REPOSITORY/cookorder.txt
2730 fi
2731 cook
2732 ;;
2733 sort-cooklist)
2734 if [ ! -f "$LIST" ]; then
2735 echo "Usage : tazwok sort-cooklist cooklist" >&2
2736 exit 1
2737 fi
2738 check_root
2739 get_tazwok_config
2740 report(){ : ; }
2741 # When using sort-cooklist, the script should behave as for gen-cooklist
2742 # The only difference between these two is where the output is sent.
2743 COMMAND=gen-cooklist
2744 cooklist=$LIST
2745 gen_cook_list
2746 cp -af $tmp/cooklist $cooklist
2747 ;;
2748 cook-list)
2749 # Cook all packages listed in a file or in default cooklist.
2750 check_root
2751 get_options_list="pkg forced"
2752 get_tazwok_config
2753 source_lib report
2754 report start
2755 if ! [ "$pkg" ]; then
2756 cooklist=${LIST:-$PACKAGES_REPOSITORY/cooklist}
2757 fi
2758 gen_cook_list
2759 cook_list
2760 ;;
2761 clean)
2762 # Clean up a package work directory + those which want it.
2764 get_tazwok_config
2765 check_for_package_on_cmdline
2766 check_for_receipt
2767 source_lib report
2768 report start
2769 . $RECEIPT
2770 clean
2771 ;;
2772 gen-clean-wok)
2773 # Generate a clean wok from the current wok by copying all receipts
2774 # and stuff directory.
2776 get_tazwok_config
2777 source_lib report
2778 report start
2779 if [ -z "$ARG" ]; then
2780 echo -e "\nPlease specify the destination for the new clean wok.\n" >&2
2781 exit 1
2782 else
2783 dest=$ARG
2784 mkdir -p $dest
2785 fi
2786 report step "Creating clean wok in : $dest"
2787 for pkg in `ls -1 $WOK`
2788 do
2789 mkdir -p $dest/$pkg
2790 cp -a $WOK/$pkg/receipt $dest/$pkg
2791 [ -f $WOK/$pkg/description.txt ] && \
2792 cp -a $WOK/$pkg/description.txt $dest/$pkg
2793 if [ -d "$WOK/$pkg/stuff" ]; then
2794 cp -a $WOK/$pkg/stuff $dest/$pkg
2795 fi
2796 done
2797 [ -d $WOK/.hg ] && cp -a $WOK/.hg $dest
2798 report end-step
2799 echo "Packages cleaned : `ls -1 $dest | wc -l`"
2800 echo ""
2801 ;;
2802 clean-wok)
2803 # Clean all packages in the work directory.
2805 get_tazwok_config
2806 source_lib report
2807 report start
2808 report step "Cleaning wok"
2809 for PACKAGE in `ls -1 $WOK`
2810 do
2811 set_common_path
2812 source_receipt
2813 clean
2814 done
2815 echo "`ls -1 $WOK | wc -l` packages cleaned."
2816 ;;
2817 clean-src)
2818 # Remove tarball unrelated to wok receipts from src repo.
2819 check_root
2820 get_options_list="forced"
2821 get_tazwok_config
2822 cd $SOURCES_REPOSITORY
2823 echo -n "Checking $SOURCES_REPOSITORY..."
2824 for TARBALL in *; do
2825 [ "$TARBALL" = sources.list ] && continue
2826 grep -q $'\t'$TARBALL$ $SOURCES_REPOSITORY/sources.list || \
2827 echo $TARBALL >> $tmp/obsolete
2828 done
2829 status
2830 if ! [ -f $tmp/obsolete ]; then
2831 echo "No sources need to be removed."
2832 exit 1
2833 fi
2834 echo ""
2835 echo -e "\033[1mObsolete/unrelated-to-wok sources :\033[0m"
2836 horizontal_line
2837 cat $tmp/obsolete
2838 horizontal_line
2839 echo "$(wc -l $tmp/obsolete | cut -f1 -d' ') tarballs to remove."
2840 echo ""
2841 echo -n "Please confirm before removing (type uppercase YES): "
2842 read answer
2843 if [ "$answer" = YES ]; then
2844 echo -n "Removing old sources..."
2845 cat $tmp/obsolete | while read i; do
2846 rm -f $SOURCES_REPOSITORY/$i
2847 done
2848 status
2849 fi
2850 ;;
2851 gen-list)
2852 get_tazwok_config
2853 if [ "$2" ]; then
2854 if [ -d "$2" ]; then
2855 pkg_repository=$2
2856 else
2857 echo -e "\nUnable to find directory : $2\n" >&2
2858 exit 1
2859 fi
2860 fi
2862 source_lib report
2863 report start
2864 if [ "$pkg_repository" ]; then
2865 gen_packages_db
2866 else
2867 pkg_repository=$PACKAGES_REPOSITORY && gen_packages_db
2868 pkg_repository=$INCOMING_REPOSITORY && gen_packages_db
2869 fi
2870 ;;
2871 check-list)
2872 # The directory to move into by default is the repository,
2873 # if $2 is not empty cd into $2.
2875 get_tazwok_config
2876 if [ "$2" ]; then
2877 if [ -d "$2" ]; then
2878 pkg_repository=$2
2879 else
2880 echo -e "\nUnable to find directory : $2\n" >&2
2881 exit 1
2882 fi
2883 fi
2885 source_lib report
2886 report start
2887 if [ "$pkg_repository" ]; then
2888 update_packages_db
2889 else
2890 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2891 pkg_repository=$INCOMING_REPOSITORY && update_packages_db
2892 fi
2893 ;;
2894 new-tree)
2895 # Just create a few directories and generate an empty receipt to prepare
2896 # the creation of a new package.
2898 get_tazwok_config
2899 check_for_package_on_cmdline
2900 clean_wok=$LOCAL_REPOSITORY/clean-wok
2901 if [ -d $clean_wok/$PACKAGE ]; then
2902 echo -e "\n$PACKAGE package tree already exists.\n" >&2
2903 exit 1
2904 fi
2905 echo "Creating : $clean_wok/$PACKAGE"
2906 mkdir $clean_wok/$PACKAGE
2907 cd $clean_wok/$PACKAGE
2908 echo -n "Preparing the receipt..."
2910 # Default receipt begin.
2912 echo "# SliTaz package receipt." > receipt
2913 echo "" >> receipt
2914 echo "PACKAGE=\"$PACKAGE\"" >> receipt
2915 # Finish the empty receipt.
2916 cat >> receipt << "EOF"
2917 VERSION=""
2918 CATEGORY=""
2919 SHORT_DESC=""
2920 MAINTAINER=""
2921 DEPENDS=""
2922 TARBALL="$PACKAGE-$VERSION.tar.gz"
2923 WEB_SITE=""
2924 WGET_URL=""
2926 # Rules to configure and make the package.
2927 compile_rules()
2929 cd $src
2930 ./configure $CONFIGURE_ARGS && make && make install
2933 # Rules to gen a SliTaz package suitable for Tazpkg.
2934 genpkg_rules()
2936 mkdir -p $fs/usr
2937 cp -a $_pkg/usr/bin $fs/usr
2940 EOF
2942 # Default receipt end.
2944 status
2945 # Interactive mode, asking and seding.
2946 if [ "$3" = "--interactive" ]; then
2947 echo "Entering interactive mode..."
2948 horizontal_line
2949 echo "Package : $PACKAGE"
2950 # Version.
2951 echo -n "Version : " ; read anser
2952 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
2953 # Category.
2954 echo -n "Category : " ; read anser
2955 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
2956 # Short description.
2957 echo -n "Short desc : " ; read anser
2958 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
2959 # Maintainer.
2960 echo -n "Maintainer : " ; read anser
2961 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
2962 # Web site.
2963 echo -n "Web site : " ; read anser
2964 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
2965 echo ""
2966 # Wget URL.
2967 echo "Wget URL to download source tarball."
2968 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
2969 echo -n "Wget url : " ; read anser
2970 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
2971 # Ask for a stuff dir.
2972 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
2973 if [ "$anser" = "y" ]; then
2974 echo -n "Creating the stuff directory..."
2975 mkdir stuff && status
2976 fi
2977 # Ask for a description file.
2978 echo -n "Are you going to write a description ? (y/N) : " ; read anser
2979 if [ "$anser" = "y" ]; then
2980 echo -n "Creating the description.txt file..."
2981 echo "" > description.txt && status
2982 fi
2983 horizontal_line
2984 echo ""
2985 fi
2986 ;;
2987 remove)
2988 # Remove a package from the wok.
2990 get_tazwok_config
2991 check_for_package_on_cmdline
2992 echo ""
2993 echo -n "Please confirm deletion (y/N) : "; read anser
2994 if [ "$anser" = "y" ]; then
2995 echo -n "Removing $PACKAGE..."
2996 rm -rf $WOK/$PACKAGE && status
2997 echo ""
2998 fi
2999 ;;
3000 update-wok)
3001 # Pull and update a Hg wok.
3002 get_options_list="local"
3003 get_tazwok_config
3004 source_lib report
3005 report start
3006 clean_wok=$LOCAL_REPOSITORY/clean-wok
3007 cd $clean_wok
3008 if ! [ "$local" ]; then
3009 if [ "$WOK_UPDATE_METHOD" = hg ]; then
3010 if ! [ -f "$INSTALLED/mercurial/receipt" ]; then
3012 # Auto-install only if we are in a cook chroot.
3013 if [ -x /usr/bin/clean-chroot ]; then
3014 tazpkg get-install mercurial
3015 else
3016 echo "" >&2
3017 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
3018 echo "">&2
3019 exit 1
3020 fi
3021 fi
3023 report step "Getting wok changes using hg"
3024 if [ -d .hg ]; then
3025 hg pull -u || exit 1
3026 else
3027 hg clone $HG_WOK . || exit 1
3028 fi
3029 report end-step
3030 [ -x /usr/bin/clean-chroot ] && clean-chroot
3031 else
3032 report step "Getting wok changes using tarball"
3033 { mkdir .tmp && cd .tmp
3034 wget "$TARBALL_WOK" &&
3035 case $TARBALL_WOK in
3036 *bz2) tar xjf *.bz2 -C wok; rm *.bz2;;
3037 *lzma) unlzma -c *.lzma | tar xf - -C wok; rm *.lzma ;;
3038 *gz) tar xzf *.gz -C wok; rm*.gz ;;
3039 esac &&
3040 rm -r $(ls -d $clean_wok/*) &&
3041 cp -a wok/* $clean_wok &&
3042 cd .. &&
3043 rm -r .tmp
3044 } || { echo "That's not cool: it fails!" >&2
3045 report end-step
3046 exit 1; }
3047 report end-step
3048 fi
3049 fi
3050 report step "Appending changes to wok"
3052 # Handle removed files/dir.
3053 cd $WOK
3054 for dir in *; do
3055 [ -d "$clean_wok/$dir" ] || rm -rf $dir
3056 done
3057 for file in */receipt */description.txt; do
3058 [ -f "$clean_wok/$file" ] || rm -rf $file
3059 done
3060 for i in $(find */stuff 2>/dev/null); do
3061 [ -e "$clean_wok/$i" ] || rm -rf $i
3062 done
3064 cp -a $clean_wok/* $WOK
3065 report end-step
3066 ;;
3067 maintainers)
3068 get_tazwok_config
3069 echo ""
3070 echo "List of maintainers for: $WOK"
3071 horizontal_line
3072 touch /tmp/slitaz-maintainers
3073 for pkg in $WOK/*
3074 do
3075 . $pkg/receipt
3076 if ! fgrep -q "$MAINTAINER" /tmp/slitaz-maintainers; then
3077 echo "$MAINTAINER" >> /tmp/slitaz-maintainers
3078 echo "$MAINTAINER"
3079 fi
3080 done
3081 horizontal_line
3082 echo "Maintainers: `cat /tmp/slitaz-maintainers | wc -l`"
3083 echo ""
3084 # Remove tmp files
3085 rm -f /tmp/slitaz-maintainers
3086 ;;
3087 maintained-by)
3088 # Search for packages maintained by a contributor.
3089 get_tazwok_config
3090 if [ ! -n "$2" ]; then
3091 echo "Specify a name or email of a maintainer." >&2
3092 exit 1
3093 fi
3094 echo "Maintainer packages"
3095 horizontal_line
3096 for pkg in $WOK/*
3097 do
3098 . $pkg/receipt
3099 if echo "$MAINTAINER" | fgrep -q "$2"; then
3100 echo "$PACKAGE"
3101 packages=$(($PACKAGEs+1))
3102 fi
3103 done
3104 horizontal_line
3105 echo "Packages maintained by $2: $PACKAGEs"
3106 echo ""
3107 ;;
3108 tags)
3109 get_tazwok_config
3110 echo -e "\n\033[1mTags list :\033[0m"
3111 horizontal_line
3112 cd $WOK
3113 for i in */receipt; do
3114 unset TAGS
3115 source $i
3116 for t in $TAGS; do
3117 grep -q ^$t$ $tmp/tags && continue
3118 echo $t | tee -a $tmp/tags
3119 done
3120 done
3121 horizontal_line
3122 echo "$(wc -l $tmp/tags | cut -f1 -d ' ') tags listed."
3123 ;;
3124 check-src)
3125 # Verify if upstream package is still available.
3127 get_tazwok_config
3128 check_for_package_on_cmdline
3129 check_for_receipt
3130 source_receipt
3131 check_src()
3133 for url in $@; do
3134 busybox wget -s $url 2>/dev/null && break
3135 done
3137 if [ "$WGET_URL" ];then
3138 echo -n "$PACKAGE : "
3139 check_src $WGET_URL
3140 status
3141 else
3142 echo "No tarball to check for $PACKAGE"
3143 fi
3144 ;;
3145 gen-src)
3146 get_tazwok_config
3147 if [ "$2" ]; then
3148 if [ -d "$2" ]; then
3149 src_repository=$2
3150 else
3151 echo -e "\nUnable to find directory : $2\n" >&2
3152 exit 1
3153 fi
3154 fi
3155 echo -n "Rebuilding sources.list file"
3156 [ $src_repository ] || src_repository="$SOURCES_REPOSITORY"
3157 gen_sources_list $src_repository
3158 status
3159 ;;
3160 get-src)
3161 check_root
3162 get_options_list="target nounpack"
3163 get_tazwok_config
3164 check_for_package_on_cmdline
3165 check_for_receipt
3166 source_receipt
3167 if [ "$WGET_URL" ];then
3168 source_lib report
3169 report start
3170 check_for_tarball
3171 else
3172 echo "No tarball to download for $PACKAGE"
3173 fi
3174 ;;
3175 check-commit)
3176 check_root
3177 get_options_list="missing forced"
3178 get_tazwok_config
3179 source_lib report
3180 report start
3181 if [ "$forced" ]; then
3182 rm -f $WOK/*/md5
3183 unset forced
3184 fi
3185 if [ "$missing" ]; then
3186 pkg=$(ls -1 $WOK)
3187 else
3188 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3189 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3190 } | sort -u)"
3191 fi
3192 cooklist=$PACKAGES_REPOSITORY/cooklist
3193 gen_cook_list
3194 ;;
3195 cook-commit)
3196 check_root
3197 get_options_list="missing forced"
3198 get_tazwok_config
3199 source_lib report
3200 report start
3201 if [ "$forced" ]; then
3202 rm -f $WOK/*/md5
3203 unset forced
3204 fi
3205 if [ "$missing" ]; then
3206 pkg=$(ls -1 $WOK)
3207 else
3208 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3209 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3210 } | sort -u)"
3211 fi
3212 cooklist=$PACKAGES_REPOSITORY/cooklist
3213 gen_cook_list
3214 cook_list
3215 ;;
3216 cook-all)
3217 check_root
3218 get_options_list="forced missing"
3219 get_tazwok_config
3220 source_lib report
3221 report start
3222 if [ "$missing" ]; then
3223 pkg=$(ls -1 $WOK)
3224 else
3225 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3226 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3227 } | sort -u)"
3228 fi
3229 cooklist=$PACKAGES_REPOSITORY/cooklist
3230 gen_cook_list
3231 cook_list
3232 ;;
3233 gen-wok-db)
3234 check_root
3235 get_tazwok_config
3236 source_lib report
3237 report start
3238 gen_wok_db
3239 ;;
3240 report)
3241 get_tazwok_config
3242 cd $PACKAGES_REPOSITORY
3243 if [ "$2" ]; then
3244 case $2 in
3245 commit|cooklist|incoming|broken|blocked)
3246 show="$2"
3247 ;;
3248 *)
3249 echo "usage : tazwok report [commit|cooklist|incoming|broken|blocked]" >&2
3250 exit 1
3251 ;;
3252 esac
3253 else
3254 show="commit cooklist incoming broken blocked"
3255 fi
3256 for i in $show; do
3257 if [ -s $i ]; then
3258 echo ""
3259 echo -e "\033[1m$i\033[0m"
3260 horizontal_line
3261 cat $i
3262 horizontal_line
3263 echo ""
3264 fi
3265 done
3266 ;;
3267 check-incoming)
3268 check_root
3269 get_options_list="forced"
3270 get_tazwok_config
3271 source_lib report
3272 report start
3273 [ -f $LOCAL_RESOSITORY/incoming ] && rm [ -f $LOCAL_REPOSITORY/incoming ]
3274 report step "Checking $INCOMING_REPOSITORY"
3275 report open-bloc
3276 [ -f $LOCAL_REPOSITORY/log/incoming.html ] && rm $LOCAL_REPOSITORY/log/incoming.html
3277 report sublog $LOCAL_REPOSITORY/log/incoming.html
3278 echo "incoming" > $LOCAL_REPOSITORY/log/package
3279 check_for_incoming
3280 report end-sublog
3281 report close-bloc
3282 ;;
3283 configure-chroot)
3284 check_root
3285 get_tazwok_config
3286 if [ -f /usr/bin/tazchroot ]; then
3287 cd $LOCAL_REPOSITORY
3288 configure_tazchroot
3289 else
3290 echo "The package tazchroot needs to be installed" >&2
3291 exit 1
3292 fi
3293 ;;
3294 chroot)
3295 check_root
3296 get_tazwok_config
3297 # Merge this and the other chroot function ?.
3298 if [ -f /usr/bin/tazchroot ]; then
3299 cd $LOCAL_REPOSITORY
3300 [ ! -f tazchroot.conf ] && configure_tazchroot
3301 tazchroot
3302 else
3303 echo "The package tazchroot needs to be installed" >&2
3304 exit 1
3305 fi
3306 ;;
3307 cook-toolchain)
3308 check_root
3309 get_tazwok_config
3310 echo -n "" > $PACKAGES_REPOSITORY/broken
3311 if [ -f /usr/bin/tazchroot ]; then
3312 cd $LOCAL_REPOSITORY
3313 [ ! -f tazchroot.conf ] && configure_tazchroot
3314 tazchroot cook-toolchain
3315 # Buggy : chroot can be elsewhere.
3316 rm -r $LOCAL_REPOSITORY/chroot
3317 # /!\ to be written :
3318 # next rm chroot and plan cook-all by pushing all packages
3319 # in cooklist.
3320 else
3321 echo "The package tazchroot needs to be installed" >&2
3322 exit 1
3323 fi
3324 ;;
3325 webserver)
3326 check_root
3327 get_tazwok_config
3328 if [ "$ARG" = on ]; then
3329 if [ "$WEBSERVER" ] && [ -f "$WEBSERVER/repositories.list" ] && \
3330 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3331 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3332 exit 1
3333 fi
3334 if ! [ -f $LOCAL_REPOSITORY/tazchroot.conf ]; then
3335 tazwok configure-chroot ${undigest:+--undigest=$undigest} --SLITAZ_VERSION=$SLITAZ_VERSION --SLITAZ_DIR=$SLITAZ_DIR
3336 fi
3337 for pkg in php lighttpd; do
3338 [ -d $INSTALLED/$pkg ] || missing="$missing $pkg"
3339 done
3340 if [ "$missing" ]; then
3341 echo "You need to install these packages to start webserver: $missing." >&2
3342 exit 1
3343 fi
3344 if [ ! -f "$LOCAL_REPOSITORY/tazwok.conf" ]; then
3345 echo "Copying /etc/slitaz/tazwok.conf to $LOCAL_REPOSITORY/tazwok.conf: webserver is configured repository-by-repository."
3346 cp /etc/slitaz/tazwok.conf $LOCAL_REPOSITORY
3347 fi
3348 if ! [ "$WEBSERVER" ]; then
3349 echo -n "Where to store php pages (default: /var/www/vhosts/bb)? "
3350 read WEBSERVER
3351 [ "$WEBSERVER" ] || WEBSERVER="/var/www/vhosts/bb"
3352 fi
3353 if [ -f "$WEBSERVER/repositories.list" ] && \
3354 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3355 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3356 exit 1
3357 fi
3358 mkdir -p $WEBSERVER
3359 echo "${undigest:-$SLITAZ_VERSION}" >> $WEBSERVER/repositories.list
3360 for file in index.php log.php download.php; do
3361 [ -f "$WEBSERVER/$file" ] || ln -s /usr/share/slitaz/web-bb/$file $WEBSERVER
3362 done
3363 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3364 ln -s $dir $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3365 done
3366 source $LOCAL_REPOSITORY/tazchroot.conf
3367 echo "<?php
3369 // Web interface configuration
3371 \$version=\"${undigest:-$SLITAZ_VERSION}\";
3372 \$chroot=\"$chroot_dir\";
3373 \$lockfile=\"\$chroot/proc/1/status\";
3374 \$db_dir=\"$PACKAGES_REPOSITORY\";
3375 \$log_dir=\"$LOCAL_REPOSITORY/log\";
3376 \$packages=\"$PACKAGES_REPOSITORY\";
3377 \$incoming=\"$INCOMING_REPOSITORY\";
3378 \$wok=\"$WOK\";
3380 ?>" > $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3381 [ -L "$WEBSERVER/web" ] || ln -s /usr/share/slitaz/web $WEBSERVER
3382 echo "WEBSERVER=\"$WEBSERVER\"" >> $LOCAL_REPOSITORY/tazwok.conf
3383 if [ -L "$WEBSERVER/conf.php" ]; then
3384 echo "Do you want to make ${undigest:-$SLITAZ_VERSION} the default page (y/N) ? "
3385 read answer
3386 if [ "$answer" = y ]; then
3387 rm $WEBSERVER/conf.php
3388 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3389 fi
3390 else
3391 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3392 fi
3393 elif [ "$ARG" = off ]; then
3394 if ! [ "$WEBSERVER" ]; then
3395 echo "No webserver running for ${undigest:-$SLITAZ_VERSION}" >&2
3396 exit 1
3397 fi
3398 sed '/^WEBSERVER/d' -i $LOCAL_REPOSITORY/tazwok.conf
3399 sed "/^${undigest:-$SLITAZ_VERSION}$/d" -i $WEBSERVER/repositories.list
3400 rm $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3401 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3402 rm $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3403 done
3404 if ! [ -s "$WEBSERVER/repositories.list" ]; then
3405 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"
3406 rm $WEBSERVER/conf.php
3407 elif [ "$(readlink $WEBSERVER/conf.php)" = "$WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php" ]; then
3408 echo "${undigest:-$SLITAZ_VERSION} was the default version to use; switched to : $(sed 1!d $WEBSERVER/repositories.list)"
3409 rm $WEBSERVER/conf.php
3410 ln -s $WEBSERVER/conf-$(sed 1!d $WEBSERVER/repositories.list).php $WEBSERVER/conf.php
3411 fi
3412 else
3413 echo "Usage: tazwok webserver on/off" >&2
3414 exit 1
3415 fi
3416 ;;
3417 block)
3418 # Add a pkg name to the list of blocked packages.
3419 get_tazwok_config
3420 check_root
3421 check_for_package_on_cmdline
3422 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3423 echo "Can't find $PACKAGE in wok." >&2
3424 echo ""
3425 exit 1
3426 fi
3427 echo ""
3428 if grep -qs "^$PACKAGE$" $PACKAGES_REPOSITORY/blocked; then
3429 echo "$PACKAGE is already in the blocked packages list." >&2
3430 echo ""
3431 exit 1
3432 else
3433 echo -n "Adding $PACKAGE to : $PACKAGES_REPOSITORY/blocked... "
3434 echo "$PACKAGE" >> $PACKAGES_REPOSITORY/blocked
3435 status
3436 if grep -q "^$PACKAGE$" $PACKAGES_REPOSITORY/cooklist; then
3437 echo -n "Removing $PACKAGE from : $PACKAGES_REPOSITORY/cooklist... "
3438 sed -i /"^$PACKAGE$"/d $PACKAGES_REPOSITORY/cooklist
3439 status
3440 fi
3441 fi
3442 echo "" ;;
3443 unblock)
3444 # Remove a pkg name from the list of blocked packages.
3445 get_tazwok_config
3446 check_root
3447 check_for_package_on_cmdline
3448 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3449 echo "Can't find $PACKAGE in wok." >&2
3450 echo ""
3451 exit 1
3452 fi
3453 echo ""
3454 if grep -qs "^$PACKAGE$" $PACKAGES_REPOSITORY/blocked; then
3455 echo -n "Removing $PACKAGE from : $PACKAGES_REPOSITORY/blocked... "
3456 sed -i /"^$PACKAGE$"/d $PACKAGES_REPOSITORY/blocked
3457 sed -i '/^$/d' $PACKAGES_REPOSITORY/blocked
3458 status
3459 else
3460 echo "$PACKAGE is not in the blocked packages list." >&2
3461 echo ""
3462 exit 1
3463 fi
3464 echo "" ;;
3465 usage|*)
3466 # Print usage also for all unknown commands.
3468 usage
3469 ;;
3470 esac
3472 report stop 2>/dev/null
3473 exit 0