tazwok view tazwok @ rev 548

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