tazwok view tazwok @ rev 547

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