tazwok view tazwok @ rev 526

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