tazwok view tazwok @ rev 537

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