tazwok view tazwok @ rev 534

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