tazwok view tazwok @ rev 483

Merge bugfixes from branch default
author Antoine Bodin <gokhlayeh@slitaz.org>
date Thu Apr 07 19:05:12 2011 +0200 (2011-04-07)
parents 1192edf7f0fb fb70a2fffb05
children bf25a03de4ff
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.3
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 # Check if all packages are up to date into build environnement
89 check_env_status()
90 {
91 { [ "${COMMAND#cook}" = "$COMMAND" ] ||
92 [ "$COMMAND" = cook-toolchain ] ||
93 [ -f /etc/config.site.tmptoolchain ]; } && return
94 MIRROR_path=$(grep -l "^$1$" $LOCALSTATE/mirror $LOCALSTATE/undigest/*/mirror)
96 if [ ! "$MIRROR_path" ]; then
97 echo "You are trying to cook something but you don't use $1 repository, which is \
98 needed for this operation." | fold -s >&2
99 exit 1
100 fi
102 LOCALSTATE_path=${MIRROR_path%/mirror}
104 # Check is possible only if repository use ID.
105 if [ "${MIRROR_path:0:1}" = '/' ]; then
106 [ -f "$MIRROR_path/ID" ] || return
107 else
108 wget -a -s $MIRROR_path/ID 2>/dev/null || return
109 fi
111 [ -f $LOCALSTATE_path/ID ] && ID=$(cat $LOCALSATE_path/ID)
113 if [ "$LOCALSTATE_path" = "$LOCALSTATE" ]; then
114 tazpkg recharge main
115 else
116 tazpkg recharge ${LOCALSTATE_path##*/}
117 fi
119 [ "$(cat $LOCALSTATE_path/ID)" = "$ID" ] || env_status=1
120 }
122 get_tazwok_config()
123 {
124 # Get configuration file.
125 get_config
127 # Define & get options.
128 get_options_list="$get_options_list WOK SLITAZ_DIR SLITAZ_VERSION undigest"
129 get_options
131 LOCAL_REPOSITORY=$SLITAZ_DIR/${undigest:-$SLITAZ_VERSION}
133 if ! [ "$save_dir" ]; then
134 if [ -f $LOCAL_REPOSITORY/tazwok.conf ] || [ -f $LOCAL_REPOSITORY/slitaz.conf ]; then
135 save_dir=$LOCAL_REPOSITORY
136 [ -f $LOCAL_REPOSITORY/slitaz.conf ] && source $LOCAL_REPOSITORY/slitaz.conf
137 cd $save_dir
138 get_tazwok_config
139 unset save_dir
140 return
141 fi
142 fi
144 set_common_path
146 # Check that packages are up to date if user intend to cook.
147 check_env_status ${USE_ONLINE_PKG:-$PACKAGES_REPOSITORY}
148 check_env_status $INCOMING_REPOSITORY
150 # In case undigest is used, we need to upgrade system.
151 if [ "$undigest" ]; then
152 use_undigest_scan_core
153 ref_PACKAGES_REPOSITORY=$SLITAZ_DIR/$SLITAZ_VERSION/packages
154 if [ -f $SLITAZ_DIR/$SLITAZ_VERSION/tazwok.conf ] && \
155 grep -q ^USE_ONLINE_PKG $SLITAZ_DIR/$SLITAZ_VERSION/tazwok.conf; then
156 ref_USE_ONLINE_PKG=$(source $SLITAZ_DIR/$SLITAZ_VERSION/tazwok.conf && \
157 echo $USE_ONLINE_PKG)
158 fi
160 check_env_status ${ref_USE_ONLINE_PKG:-$ref_PACKAGES_REPOSITORY}
161 cd $ref_PACKAGES_REPOSITORY
162 if [ "$ref_USE_ONLINE_PKG" ]; then
163 ref_dep_db=$LOCALSTATE_path/wok-depends.txt
164 ref_wan_db=$LOCALSTATE_path/wok-wanted.txt
165 ref_lib_db=$LOCALSTATE_path/libraries.txt
166 else
167 ref_dep_db=$ref_PACKAGES_REPOSITORY/wok-depends.txt
168 ref_wan_db=$ref_PACKAGES_REPOSITORY/wok-wanted.txt
169 ref_lib_db=$ref_PACKAGES_REPOSITORY/libraries.txt
170 fi
172 for file in $ref_dep_db $ref_wan_db $ref_lib_db; do
173 [ -f "$file" ] && continue
174 missing_file=t
175 echo "$file is missing." >&2
176 done
177 if [ "$missing_file" ]; then
178 echo "
179 Theses files are needed to get datas about packages from the reference repository $SLITAZ_VERSION. \
180 If you don't intend to build this reference repository yourself, you should set USE_ONLINE_PKG variable \
181 into tazwok.conf of this reference repository. How-to:" | fold -s >&2
182 echo "echo 'USE_ONLINE_PKG=\"packages_repository_url\"' >> $SLITAZ_DIR/$SLITAZ_VERSION/tazwok.conf"
183 echo ""
184 exit 1
185 fi
186 fi
188 # If $env_status exists, it means an upgrade may be needed.
189 if [ "$env_status" ]; then
190 if [ -x /usr/bin/clean-chroot ]; then
191 echo y | tazpkg upgrade
192 else
193 echo "\e[0;31mWarning: \e[m"
194 echo "You're environnement may need a package upgrade."
195 echo "Upgrading is highly recommanded to ensure repository consistency."
196 echo "You can (E)xit, (U)pgrade, or (C)ontinue."
197 echo -n "What do you want to do ?"
198 read answer
199 case $answer in
200 [Cc]*) ;;
201 [Uu]*) echo y | tazpkg upgrade ;;
202 *) exit
203 esac
204 fi
205 fi
207 # Check commons directories, create them if user is root.
208 if test $(id -u) = 0 ; then
209 check_dir $WOK || chmod 777 $WOK
210 check_dir $LOCAL_REPOSITORY/clean-wok || chmod 777 $LOCAL_REPOSITORY/clean-wok
211 check_dir $PACKAGES_REPOSITORY
212 check_dir $SOURCES_REPOSITORY
213 check_dir $INCOMING_REPOSITORY
214 check_dir $LOCAL_REPOSITORY/log
215 for file in $dep_db $wan_db $cookorder $commit $cooklist \
216 $broken $blocked $SOURCES_REPOSITORY/sources.list $lib_db
217 do
218 [ -f $file ] || touch $file
219 done
220 fi
222 # Limit memory usage.
223 ulimit -v $(awk '/MemTotal|SwapTotal/ { n+=$2 } END { print int((n*80)/100) }' < /proc/meminfo)
224 }
226 # The path to the most important files/dir used by Tazwok.
227 set_common_path()
228 {
229 PACKAGES_REPOSITORY=$LOCAL_REPOSITORY/packages
230 [ "$WOK" ] || WOK=$LOCAL_REPOSITORY/wok
231 INCOMING_REPOSITORY=$LOCAL_REPOSITORY/packages-incoming
232 SOURCES_REPOSITORY=$LOCAL_REPOSITORY/src
233 RECEIPT="$WOK/$PACKAGE/receipt"
234 LOG="$WOK/$PACKAGE/process.log"
235 dep_db=$INCOMING_REPOSITORY/wok-depends.txt
236 wan_db=$INCOMING_REPOSITORY/wok-wanted.txt
237 lib_db=$INCOMING_REPOSITORY/libraries.txt
238 cookorder=$PACKAGES_REPOSITORY/cookorder.txt
239 commit=$PACKAGES_REPOSITORY/commit
240 cooklist=$PACKAGES_REPOSITORY/cooklist
241 broken=$PACKAGES_REPOSITORY/broken
242 blocked=$PACKAGES_REPOSITORY/blocked
244 # log steps for webserver.
245 log_step="$LOCAL_REPOSITORY/log/step"
246 run_on_exit="$run_on_exit
247 rm -f $LOCAL_REPOSITORY/log/step
248 rm -f $LOCAL_REPOSITORY/log/package"
249 }
251 ########################################################################
252 # TAZWOK CHECK FUNCTIONS
253 ########################
255 # Check for a package name on cmdline.
256 check_for_package_on_cmdline()
257 {
258 if [ ! "$PACKAGE" ]; then
259 echo -e "\nYou must specify a package name on the command line." >&2
260 echo -e "Example : tazwok $COMMAND package\n" >&2
261 exit 1
262 fi
263 }
265 # Check for the receipt of a package used to cook.
266 check_for_receipt()
267 {
268 if [ ! -f "$RECEIPT" ]; then
269 echo -e "\nUnable to find the receipt : $RECEIPT\n" >&2
270 exit 1
271 fi
272 }
274 # Check for a specified file list on cmdline.
275 check_for_list()
276 {
277 if [ ! "$LIST" ]; then
278 echo -e "\nPlease specify the path to the list of packages to cook.\n" >&2
279 exit 1
280 elif ! [ -f "$LIST" ]; then
281 echo -e "\nUnable to find $LIST packages list.\n" >&2
282 exit 1
283 elif ! [ -s "$LIST" ]; then
284 echo -e "\nList is empty.\n" >&2
285 exit 1
286 fi
287 }
289 ########################################################################
290 # TAZWOK CORE FUNCTIONS
291 ########################
293 remove_src()
294 {
295 [ "$WANTED" ] && return
296 look_for_cookopt !remove_src && return
297 if [ ! -d $WOK/$PACKAGE/install ] && [ "$src" ] && [ -d "$src/_pkg" ]; then
298 check_for_var_modification _pkg src || return
299 mv "$src/_pkg" $WOK/$PACKAGE/install
300 fi
302 # Don't remove sources if a package uses src variable in its
303 # genpkg_rules: it maybe needs something inside.
304 for i in $PACKAGE $(look_for_rwanted); do
305 sed -n '/^genpkg_rules\(\)/','/}/'p $WOK/$i/receipt | \
306 fgrep -q '$src' && tazwok_warning "Sources will not be removed \
307 because $i uses \$src in its receipt." && return
308 done
310 report step "Removing sources directory"
311 rm -fr "$src"
312 report end-step
313 }
315 # Check $COOK_OPT; usage : get_cookopt particular_opt
316 # Return error if not found
317 # Return args if the opt is in the format opt=arg1:arg2:etc
318 look_for_cookopt()
319 {
320 for arg in $COOK_OPT; do
321 case $arg in
322 $1=*)
323 arg=${arg#$1=}
324 while [ "$arg" ]; do
325 echo "${arg%%:*}"
326 [ "${arg/:}" = "$arg" ] && return
327 arg=${arg#*:}
328 done
329 ;;
330 $1)
331 return
332 ;;
333 esac
334 done
335 return 1
336 }
338 # Check for the wanted package if specified in WANTED
339 # receipt variable. Set the $src/$_pkg variable to help compile
340 # and generate packages.
341 check_for_wanted()
342 {
343 if [ "$WANTED" ]; then
344 report "Checking for the wanted package"
345 if [ ! -d "$WOK/$WANTED" ]; then
346 report exit "\nWanted package is missing in the work directory.\n"
347 fi
349 # Checking for buildtree of Wanted package
350 if [ ! -d "$WOK/$WANTED/taz" ]; then
351 echo -e "\n\nSource files of wanted package is missing in the work directory."
352 echo -n "Would you like to build the missing package (y/N) ? " ; read anser
353 if [ "$anser" == "y" ]; then
354 tazwok cook $WANTED
355 else
356 report exit "\nWanted package source tree is missing in the work directory.\n"
357 fi
358 fi
359 report end-step
361 # Set wanted src path.
362 set_src_path && set_pkg_path
364 fi
365 }
367 # Check for build dependencies, notify user and install if specified.
368 check_for_build_depends()
369 {
370 [ "$WANTED" ] && return
371 [ "$CATEGORY" = meta ] && ! fgrep -q compile_rules $RECEIPT && return
372 [ ! "$BUILD_DEPENDS" ] && ! fgrep -q compile_rules $RECEIPT && return
373 report step "Looking for build dependencies"
375 # Keep the list of previously installed build_depends then compare
376 # it with new build_depends to know what to install and what to
377 # what to remove.
378 plan_remove=" $MISSING_PACKAGE $remove_later "
379 [ ! "${plan_remove// }" ] && unset plan_remove
380 unset MISSING_PACKAGE remove_later
381 rwanted=$(look_for_rwanted)
383 for pkg in $(scan $PACKAGE --look_for=bdep --with_dev | \
384 grep -v $(for i in $(look_for_rwanted) $PACKAGE; do echo " -e ^$i$"; done))
385 do
387 # Delay the removing of previous cook depends if they are needed
388 # for next cook too.
389 if [ ! -d "$INSTALLED/$pkg" ] ; then
390 MISSING_PACKAGE="$MISSING_PACKAGE $pkg"
391 fi
392 if [ "$plan_remove" != "${plan_remove/ $pkg }" ]; then
393 plan_remove="${plan_remove/ $pkg / }"
394 remove_later="$remove_later $pkg"
395 fi
396 grep -q ^$pkg$ $broken && broken_pkg="$broken_pkg$pkg "
397 done
399 # Don't cook if a depend is broken.
400 if [ "$broken_pkg" ]; then
401 MISSING_PACKAGE=$plan_remove
402 echo "Can't cook $PACKAGE because of broken depend(s) : $broken_pkg" >&2
403 unset plan_remove broken_pkg
405 # Set report step to failed.
406 report_return_code=1
407 report end-step
408 return 1
409 fi
410 if [ "$MISSING_PACKAGE" ]; then
411 install_missing()
412 {
413 echo "Installing missing packages : $MISSING_PACKAGE"
414 for pkg in $MISSING_PACKAGE; do
415 [ -d "$INSTALLED/$pkg" ] || tazpkg get-install $pkg
416 done
417 }
418 if [ "$auto_install" = yes ]; then
419 install_missing
420 else
421 echo "================================================================================"
422 for pkg in $MISSING_PACKAGE
423 do
424 echo "Missing : $pkg"
425 done
426 echo "================================================================================"
427 echo "You can continue, exit or install missing dependencies."
428 echo -n "Install, continue or exit (install/y/N) ? "; read answer
429 case $answer in
430 install)
431 install_missing ;;
432 y|yes)
433 unset MISSING_PACKAGE;;
434 *)
435 report stop
436 exit 0 ;;
437 esac
438 fi
439 fi
440 report end-step
441 remove_build_depends $plan_remove
442 unset plan_remove
443 }
445 remove_build_depends()
446 {
447 [ "$1" ] || return
448 report step "Removing previous build dependencies"
449 echo "Removing these packages : $@"
450 for pkg in $@; do
451 [ -f "$INSTALLED/$pkg/receipt" ] && tazpkg remove $pkg --auto
452 done
453 cd $PWD
454 report end-step
455 }
457 # Check if we can use the new way to handle tarball
458 # or if we keep the previous method by checking for
459 # _pkg=/src= in receipt and reverse-wanted.
460 check_for_var_modification()
461 {
462 for var in $@; do
463 for pkg in $PACKAGE $(look_for_wanted) $(look_for_rwanted); do
464 [ -f $WOK/$pkg/receipt ] || continue
465 fgrep -q "$var=" $WOK/$pkg/receipt && return 1
466 done
467 done
469 # Tweak to make if; then...; fi function working with this one.
470 echo -n ""
471 }
473 set_src_path()
474 {
475 if check_for_var_modification src _pkg; then
476 src=$WOK/${WANTED:-$PACKAGE}/${WANTED:-$PACKAGE}-$VERSION
477 else
478 tazwok_warning "Use original name or tarball root directory because src/_pkg is defined in the receipt (this is no longer needed!)."
479 src=$WOK/${WANTED:-$PACKAGE}/${SOURCE:-${WANTED:-$PACKAGE}}-$VERSION
480 fi
481 stuff=$WOK/$PACKAGE/stuff
482 [ "$WANTED" ] && wanted_stuff=$WOK/$WANTED/stuff
483 }
485 set_pkg_path()
486 {
487 if [ -d $WOK/${WANTED:-$PACKAGE}/install ] ; then
488 _pkg=$WOK/${WANTED:-$PACKAGE}/install
489 else
490 _pkg=$src/_pkg
491 fi
492 }
494 # Output $VERSION-$EXTRAVERSION using packages.txt
495 get_pkg_version()
496 {
497 [ "$PACKAGE" ] || return
498 grep -m1 -A1 -sh ^$PACKAGE$ $1/packages.txt | tail -1 | sed 's/ *//'
499 }
501 remove_previous_package()
502 {
503 [ "$prev_VERSION" ] || return
504 if [ "$VERSION$EXTRAVERSION" != "$prev_VERSION" ]; then
505 rm -f $1/$PACKAGE-$prev_VERSION.tazpkg
506 fi
507 return 0
508 }
510 # Check for src tarball and wget if needed.
511 check_for_tarball()
512 {
513 [ "$WGET_URL" ] || return 0
514 [ "$WANTED" ] || return 0
515 report step "Checking for source tarball: $PACKAGE"
516 local repack_src=$repack_src TARBALL=$TARBALL local nounpack=$nounpack
517 look_for_cookopt !unpack && nounpack=yes
518 if [ "$repack_src" = yes ] && look_for_cookopt !repack_src; then
519 repack_src=no
520 fi
521 if [ "$target" ]; then
522 src="$target"
523 else
524 set_src_path
525 fi
526 tmp_src=$tmp/tarball-$$
527 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ] && \
528 [ ! -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ] ; then
529 cd $SOURCES_REPOSITORY
530 if [ "$SOURCE" ]; then
531 alt_url="http://mirror.slitaz.org/sources/packages/${SOURCE:0:1}/$SOURCE-$VERSION.tar.lzma"
532 else
533 alt_url="http://mirror.slitaz.org/sources/packages/${PACKAGE:0:1}/$PACKAGE-$VERSION.tar.lzma"
534 fi
535 download $WGET_URL $alt_url http://mirror.slitaz.org/sources/packages/${TARBALL:0:1}/$TARBALL
536 unset alt_url
537 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ] && \
538 [ ! -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ] && \
539 [ ! -d $tmp_src ]; then
540 echo -e "\nDownload failed, exiting. Please check WGET_URL variable.\n" >&2
541 report end-step
542 return 1
543 fi
544 fi
545 report end-step
546 if { [ -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ] && [ "$nounpack" ] ; } || \
547 { [ -f "$SOURCES_REPOSITORY/$TARBALL" ] && [ "$repack_src" != yes ] && [ "$nounpack" ] ; }; then
548 [ -d "$tmp_src" ] && rm -r $tmp_src
549 return 0
550 fi
552 report step "Untaring source tarball"
554 # Log process.
555 echo "untaring source tarball" >> $LOG
557 # If $tmp_src exists, there's already a unpacked tarball in it.
558 if ! [ -d $tmp_src ]; then
559 mkdir $tmp_src
560 if [ -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ] && [ "$repack_src" = yes ]; then
561 lzma d $SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma -so | \
562 tar xf - -C $tmp_src
563 repack_src=no
564 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
565 elif [ -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
566 case "$TARBALL" in
567 *zip|*xpi) cd $tmp_src && unzip -o $SOURCES_REPOSITORY/$TARBALL ;;
568 *bz2|*tbz|*gem) tar xjf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
569 *tar) tar xf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
570 *lzma|*lz) unlzma -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
571 *xz) unxz -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
572 *Z|*taz) uncompress -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
573 *gz) tar xzf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
574 *rpm) cd $tmp_src && rpm2cpio $SOURCES_REPOSITORY/$TARBALL | cpio -idm --quiet;;
576 # It's a plain file or something receipt unpack itself.
577 *)
578 mkdir $tmp_src/${SOURCE:-$PACKAGE}-$VERSION
579 cp $SOURCES_REPOSITORY/$TARBALL $tmp_src/${src##*/}
580 ;;
582 esac || { report end-step
583 rm -f $SOURCES_REPOSITORY/$TARBALL
584 rm -r $tmp_src
585 return 1
586 }
587 fi
589 # Check if uncompressed tarball is in a root dir or not.
590 if [ "$(ls -A $tmp_src | wc -l)" -gt 1 ] || [ -f $(echo $tmp_src/*) ]; then
591 if check_for_var_modification src _pkg; then
592 mv $tmp_src $tmp_src-1
593 mkdir $tmp_src
594 mv $tmp_src-1 $tmp_src/${SOURCE:-$PACKAGE}-$VERSION
595 else
596 mv $tmp_src/* $WOK/$PACKAGE
597 repack_src=no
598 rm -r $tmp_src
599 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."
600 fi
601 fi
602 fi
604 if [ "$repack_src" = yes ]; then
605 report step "Repacking sources in .tar.lzma format"
606 [ "$TARBALL" ] && rm -f $SOURCES_REPOSITORY/$TARBALL
607 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
608 cd $tmp_src
609 tar -c * | lzma e $SOURCES_REPOSITORY/$TARBALL -si
610 fi
612 # Remove previous tarball if no other package needs it. We take care to
613 # keep tarball if the same package uses it in the main repository.
614 if [ "$TARBALL" ]; then
615 previous_tarball=$(grep ^$PACKAGE:incoming $SOURCES_REPOSITORY/sources.list | cut -f2)
616 if [ "$previous_tarball" ]; then
617 sed "/^$PACKAGE:incoming/ s/.*/$PACKAGE:incoming\t$TARBALL/" \
618 -i $SOURCES_REPOSITORY/sources.list
619 grep -q $'\t'$previous_tarball$ $SOURCES_REPOSITORY/sources.list || \
620 rm -f $SOURCES_REPOSITORY/$previous_tarball
621 else
622 echo -e "$PACKAGE:incoming\t$TARBALL" >> $SOURCES_REPOSITORY/sources.list
623 fi
624 fi
626 if [ "$nounpack" ]; then
627 [ -d "$tmp_src" ] && rm -r $tmp_src
628 report end-step
629 return
630 fi
631 if [ ! -d "$src" ]|| [ "$target" ]; then
632 # Permissions settings.
633 chown -R root.root "$tmp_src"
634 if [ -d "$src" ]; then
635 mkdir -p $src
636 for f in $tmp_src/*/*; do
637 cp -a $f $src || { report end-step; rm -r $tmp_src; return 1; }
638 done
639 else
640 if ! check_for_var_modification src _pkg && ! [ "$target" ]; then
641 src="${src%/*}/$(ls $tmp_src)"
642 fi
643 mv $(echo $tmp_src/*) "$src" || { report end-step; rm -r $tmp_src; return 1; }
644 fi
645 rm -r $tmp_src
646 else
647 [ -d "$tmp_src" ] && rm -r $tmp_src
648 echo "There's already something at $src. Abort." >&2
649 fi
650 report end-step
651 }
653 # help gen sources.list file from scranch
654 gen_sources_list()
655 {
656 local src_repository=$1
657 [ -f $src_repository/sources.list ] && rm -f $src_repository/sources.list
658 for i in $WOK/*; do
659 unset PACKAGE SOURCE VERSION WGET_URL TARBALL WANTED
660 [ -f $i/receipt ] && source $i/receipt
661 [ "$WGET_URL" ] || continue
662 if grep -q "^$PACKAGE | $VERSION" $PACKAGES_REPOSITORY/packages.desc; then
663 main_version="$VERSION"
664 if [ -f $src_repository/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma ]; then
665 echo -e "$PACKAGE:main\t${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" >> $src_repository/sources.list
666 elif [ -f "$src_repository/$TARBALL" ]; then
667 echo -e "$PACKAGE:main\t$TARBALL" >> $src_repository/sources.list
668 fi
669 else
670 # May not works if package use extraversion.
671 main_version=$(grep -m1 -A1 -sh ^$PACKAGE$ $PACKAGES_REPOSITORY/packages.txt | tail -1 | sed 's/ *//')
672 if [ -f $src_repository/${SOURCE:-$PACKAGE}-$main_version.tar.lzma ]; then
673 echo -e "$PACKAGE:main\t${SOURCE:-$PACKAGE}-$main_version.tar.lzma" >> $src_repository/sources.list
674 else
675 unset main_version
676 fi
677 fi
678 if [ ! "$main_version" ] || [ $(grep -q "^$PACKAGE | $VERSION" $INCOMING_REPOSITORY/packages.desc 2>/dev/null) ]; then
679 if [ -f $src_repository/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma ]; then
680 echo -e "$PACKAGE:incoming\t${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" >> $src_repository/sources.list
681 elif [ -f "$src_repository/$TARBALL" ]; then
682 echo -e "$PACKAGE:incoming\t$TARBALL" >> $src_repository/sources.list
683 fi
684 fi
685 done
686 }
688 # Log and execute compile_rules function if it exists, to configure and
689 # make the package if it exists.
690 check_for_compile_rules()
691 {
692 if grep -q ^compile_rules $RECEIPT; then
693 echo "executing compile_rules" >> $LOG
694 report step "Executing compile_rules"
695 cd $WOK/$PACKAGE
696 rm -f /tmp/config.site
697 ulimit -d unlimited
698 ulimit -m unlimited
700 # Free some RAM by cleaning cache if option is enabled.
701 freeram=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
703 # Disable -pipe in CFLAGS/CXXFLAGS if less than 512Mb of free
704 # RAM are available.
705 if [ "$freeram" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" -o \
706 "$CXXFLAGS" != "${CXXFLAGS/-pipe}" ]; then
707 tazwok_warning "Disabling -pipe compile flag because only ${freeram}b of RAM is available."
708 CFLAGS="${CFLAGS/-pipe}"
709 CXXFLAGS="${CXXFLAGS/-pipe}"
710 fi
711 unset freeram
713 # Set cook environement variables.
714 [ "$src" ] || set_src_path
715 [ "$DESTDIR" ] || DESTDIR="$WOK/$PACKAGE/install"
716 [ "$CONFIG_SITE" ] || CONFIG_SITE=/etc/config.site
717 export CFLAGS=$(echo "$CFLAGS" | tr -s ' ') \
718 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ') \
719 MAKEFLAGS DESTDIR BUILD_HOST CONFIG_SITE default_prefix \
720 default_datarootdir default_datadir default_localedir \
721 default_infodir default_mandir default_build default_host
722 local LC_ALL=POSIX LANG=POSIX
723 compile_rules
724 return_code=$?
726 if [ -f /tmp/config.site ]; then
727 rm /tmp/config.site
728 else
729 tazwok_warning "config.site hasn't been used during \
730 the configuration process."
731 fi
733 # Return the proper status to step.
734 (exit $return_code)
735 report end-step
736 fi
737 }
739 # Check for loop in deps tree. /!\ can be removed.
740 check_for_deps_loop()
741 {
742 local list
743 local pkg
744 local deps
745 pkg=$1
746 shift
747 [ -n "$1" ] || return
748 list=""
750 # Filter out already processed deps.
751 for i in $@; do
752 case " $ALL_DEPS" in
753 *\ $i\ *);;
754 *) list="$list $i";;
755 esac
756 done
757 ALL_DEPS="$ALL_DEPS$list "
758 for i in $list; do
759 [ -f $i/receipt ] || continue
760 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
761 case " $deps " in
762 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
763 *) check_for_deps_loop $pkg $deps;;
764 esac
765 done
766 }
768 # Function used by download().
769 revert_vcs_failure()
770 {
771 cd $SOURCES_REPOSITORY
772 rm -r $tmp_src
773 }
775 download()
776 {
777 if [ "$COMMAND" = get-src ]; then
778 if [ "${DEPENDS/tar}" != "$DEPENDS" ] || [ "${BUILD_DEPENDS/tar}" != "$BUILD_DEPENDS" ]; then
779 [ -f $INSTALLED/tar/receipt ] || tazpkg get-install tar --forced
780 fi
781 fi
782 for file in $@; do
783 echo "Downloading from ${file#*|}..."
784 case "$file" in
785 git\|*)
786 file=${file#git|}
787 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/git/receipt ] && tazpkg get-install git --forced
788 if [ -f $INSTALLED/git/receipt ]; then
789 mkdir $tmp_src
790 cd $tmp_src
791 if [ "$BRANCH" ]; then
792 git clone $file ${src##*/} && cd ${src##*/} && \
793 git checkout $BRANCH && rm -rf .git* && break
794 else
795 git clone $file ${src##*/} && rm -rf ${src##*/}/.git* && break
796 fi
797 revert_vcs_failure
798 else
799 tazwok_warning "Needs git to download the source tarball from $file, please add it as a build-depend."
800 continue
801 fi
802 ;;
803 bazaar\|*)
804 file=${file#bazaar|}
805 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/bazaar/receipt ] && tazpkg get-install bazaar --forced
806 if [ -f $INSTALLED/bazaar/receipt ]; then
807 mkdir $tmp_src
808 cd $tmp_src
809 if [ "$BRANCH" ]; then
810 bzr co $file -r $BRANCH ${src##*/} && rm -rf ${src##*/}/.bzr* && break
811 else
812 bzr co $file ${src##*/} && rm -rf ${src##*/}/.bzr* && break
813 fi
814 revert_vcs_failure
815 else
816 tazwok_warning "Needs bazaar to download the source tarball from $file, please add it as a build-depend."
817 continue
818 fi
819 ;;
820 subversion\|*)
821 file=${file#subversion|}
822 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/subversion/receipt ] && tazpkg get-install subversion --forced
823 if [ -f $INSTALLED/subversion/receipt ]; then
824 mkdir $tmp_src
825 cd $tmp_src
826 if [ "$BRANCH" ]; then
827 echo t | svn co $file -r $BRANCH ${src##*/} && rm -rf ${src##*/}/.svn* && break
828 else
829 echo t | svn co $file ${src##*/} && rm -rf ${src##*/}/.svn* && break
830 fi
831 revert_vcs_failure
832 else
833 tazwok_warning "Needs subversion to download the source tarball from $file, please add it as a build-depend."
834 continue
835 fi
836 ;;
837 mercurial\|*)
838 file=${file#mercurial|}
839 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/mercurial/receipt ] && tazpkg get-install mercurial --forced
840 if [ -f $INSTALLED/mercurial/receipt ]; then
841 mkdir $tmp_src
842 cd $tmp_src
843 if [ "$BRANCH" ]; then
844 hg clone $file --rev $BRANCH ${src##*/} && rm -rf ${src##*/}/.hg* && break
845 else
846 hg clone $file ${src##*/} && rm -rf ${src##*/}/.hg* && break
847 fi
848 revert_vcs_failure
849 else
850 tazwok_warning "Needs mercurial to download the source tarball from $file, please add it as a build-depend."
851 continue
852 fi
853 ;;
854 https*)
855 [ "$COMMAND" = get-src ] && [ ! -f $INSTALLED/wget/receipt ] && tazpkg get-install wget --forced
856 if [ -d $INSTALLED/wget ]; then
857 if [ "${WGET_URL%$TARBALL}" = "$WGET_URL" ] && [ "$file" = "$WGET_URL" ]; then
858 wget -q --no-check-certificate -O $TARBALL $file && break
859 else
860 wget -q --no-check-certificate $file && break
861 fi
862 else
863 tazwok_warning "Needs wget to download the source tarball from $file, please add it as a build-depend."
864 continue
865 fi
866 ;;
867 http*|ftp*)
868 # Handle crappy URL.
869 if [ "$COMMAND" = get-src ]; then
870 if [ "${DEPENDS/wget}" != "$DEPENDS" ] || [ "${BUILD_DEPENDS/wget}" != "$BUILD_DEPENDS" ]; then
871 [ -f $INSALLED/wget/receipt ] || tazpkg get-install wget --forced
872 fi
873 fi
874 if [ "${WGET_URL%$TARBALL}" = "$WGET_URL" ] && [ "$file" = "$WGET_URL" ]; then
875 wget -q -O $TARBALL $file && break
876 else
877 wget -q $file && break
878 fi
879 ;;
880 esac
881 done
882 }
884 # Regenerate every package that wants a PACKAGE compiled.
885 refresh_packages_from_compile()
886 {
887 # make tazwok genpkg happy.
888 mkdir $WOK/$PACKAGE/taz
890 # Cook rwanted in default or specied order.
891 genlist=" $(look_for_rwanted | tr '\n' ' ') "
892 for i in $(look_for_cookopt genpkg | tac); do
893 [ "${genlist/ $i }" = "$genlist" ] && continue
894 genlist=" $i${genlist/ $i / }"
895 done
896 if [ "$genlist" ]; then
897 local PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
898 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
899 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
900 src _pkg DESTDIR CONFIG_SITE RECEIPT LOG stuff wanted_stuff
901 for PACKAGE in $genlist; do
902 set_common_path
903 gen_package
904 done
905 fi
906 }
908 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
909 # so some packages need to copy these files with the receipt and genpkg_rules.
910 # This function is executed by gen_package when 'tazwok genpkg'.
911 copy_generic_files()
912 {
913 # In most cases, locales are in $_pkg/usr/share/locale so we copy files
914 # using generic variables and $LOCALE from Tazwok config file.
915 if [ "$LOCALE" ]; then
916 if [ -d "$_pkg/usr/share/locale" ]; then
917 for i in $LOCALE
918 do
919 if [ -d "$_pkg/usr/share/locale/$i" ]; then
920 mkdir -p $fs/usr/share/locale
921 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
922 fi
923 done
924 fi
925 fi
927 # Pixmaps (PNG or/and XPM only). Some icons/images can be added through
928 # genpkg_rules and generic copy can be disabled with GENERIC_PIXMAPS="no"
929 # in pkg receipt.
930 if [ "$GENERIC_PIXMAPS" != "no" ]; then
931 if [ -d "$_pkg/usr/share/pixmaps" ]; then
932 mkdir -p $fs/usr/share/pixmaps
933 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
934 $fs/usr/share/pixmaps 2>/dev/null
935 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
936 $fs/usr/share/pixmaps 2>/dev/null
937 fi
939 # Custom or homemade PNG pixmap can be in stuff.
940 if [ -f "stuff/$PACKAGE.png" ]; then
941 mkdir -p $fs/usr/share/pixmaps
942 cp -a stuff/$PACKAGE.png $fs/usr/share/pixmaps
943 fi
944 fi
946 # Desktop entry (.desktop).
947 if [ -d "$_pkg/usr/share/applications" ]; then
948 cp -a $_pkg/usr/share/applications $fs/usr/share
949 fi
951 # Homemade desktop file(s) can be in stuff.
952 if [ -d "stuff/applications" ]; then
953 mkdir -p $fs/usr/share
954 cp -a stuff/applications $fs/usr/share
955 fi
956 if [ -f "stuff/$PACKAGE.desktop" ]; then
957 mkdir -p $fs/usr/share/applications
958 cp -a stuff/$PACKAGE.desktop $fs/usr/share/applications
959 fi
960 }
962 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
963 strip_package()
964 {
965 report step "Executing strip on all files"
967 # Binaries.
968 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
969 do
970 if [ -d "$dir" ]; then
971 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
972 fi
973 done
975 # Libraries.
976 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
977 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
978 report end-step
979 }
981 # Remove .pyc and .pyo files from packages.
982 py_compiled_files_remove()
983 {
984 report step "Removing all .pyc and .pyo files from package"
985 find $fs -type f -name "*.pyc" -delete 2>/dev/null
986 find $fs -type f -name "*.pyo" -delete 2>/dev/null
987 report end-step
988 }
990 # Check FSH in a slitaz package (Path: /:/usr)
991 check_fsh()
992 {
993 cd $WOK/$PACKAGE/taz/*/fs
994 if [ -z "$(find * ! -type d)" ] && [ "$CATEGORY" != meta ]; then
995 echo "$PACKAGE fs is empty." >&2
996 cd $WOK/$PACKAGE && rm -rf taz
997 return 1
998 fi
999 [ -n "$FSH" ] || FSH="bin boot dev etc home init lib media mnt proc \
1000 root sbin share sys tmp usr var vz usr/bin usr/games usr/include usr/lib \
1001 usr/local usr/sbin usr/share usr/src"
1002 error=0
1003 for i in `ls -d * usr/* 2>/dev/null`
1004 do
1005 if ! echo $FSH | fgrep -q $i; then
1006 echo "Wrong path: /$i" >&2
1007 error=1
1008 fi
1009 done
1010 if [ "$error" = "1" ]; then
1011 cat << _EOT_
1013 Package will install files in a non standard directory and won't be generated.
1014 You may have a wrong copy path in genpkg_rules or need to add some options to
1015 configure in compile_rules. Some valid options for SliTaz (Linux FSH):
1017 --prefix=/usr
1018 --sysconfdir=/etc
1019 --libexecdir=/usr/lib/(pkgname)
1020 --localstatedir=/var
1021 --mandir=/usr/share/man
1022 --infodir=/usr/share/info
1024 For more information please read SliTaz docs and run: ./configure --help
1025 ================================================================================
1026 $PACKAGE package generation aborted.
1028 _EOT_
1030 # Dont generate a corrupted package.
1031 cd $WOK/$PACKAGE && rm -rf taz
1032 return 1
1033 fi
1034 return 0
1037 gen_cookmd5()
1039 # md5sum of cooking stuff make tazwok able to check for changes
1040 # without hg.
1041 cd $WOK/$PACKAGE
1042 md5sum receipt > md5
1043 [ -f description.txt ] && md5sum description.txt >> md5
1044 if [ -d stuff ]; then
1045 find stuff | while read file; do
1046 md5sum $file >> md5
1047 done
1048 fi
1051 set_pkg_broken()
1053 grep -q ^$PACKAGE$ $broken || echo $PACKAGE >> $broken
1055 # Remove pkg from cooklist to avoid re-cook it if no changes happen
1056 # in the cook stuff.
1057 sed "/^$PACKAGE$/d" -i $cooklist $commit
1059 gen_cookmd5
1061 # Return 1 to make report know that its mother-function failed.
1062 return 1
1065 # Create a package tree and build the gziped cpio archive
1066 # to make a SliTaz (.tazpkg) package.
1067 gen_package()
1069 check_root
1070 check_for_package_on_cmdline
1071 check_for_receipt
1072 source_receipt
1074 # May compute VERSION
1075 if grep -q ^get_version $RECEIPT; then
1076 get_version
1077 fi
1078 check_for_wanted
1079 cd $WOK/$PACKAGE
1081 # Remove old Tazwok package files.
1082 [ -d "taz" ] && rm -rf taz
1084 # Create the package tree and set useful variables.
1085 fs=$WOK/$PACKAGE/taz/$PACKAGE-$VERSION/fs
1086 mkdir -p $fs
1088 # Set $src for standard package and $_pkg variables.
1089 set_src_path
1090 set_pkg_path
1092 # Execute genpkg_rules, check package and copy generic files to build
1093 # the package.
1094 report step "Building $PACKAGE with the receipt"
1095 report open-bloc
1096 if look_for_cookopt !fs; then
1098 elif grep -q ^genpkg_rules $RECEIPT; then
1100 # Log process.
1101 echo "executing genpkg_rules" >> $LOG
1102 report step "Executing genpkg_rules"
1103 ( set -e; genpkg_rules ) || { set_pkg_broken; report close-bloc; return 1; }
1104 check_fsh || { set_pkg_broken; report close-bloc; return 1; }
1105 cd $WOK/$PACKAGE
1106 report end-step
1108 # Skip generic files for packages with a WANTED variable
1109 # (dev and split pkgs).
1110 if [ ! "$WANTED" ]; then
1111 copy_generic_files
1112 fi
1113 look_for_cookopt !strip || strip_package
1114 py_compiled_files_remove
1115 else
1116 echo "No package rules to gen $PACKAGE..." >&2
1117 set_pkg_broken
1118 report close-bloc
1119 return 1
1120 fi
1122 # Copy the receipt and description (if exists) into the binary package tree.
1123 cd $WOK/$PACKAGE
1124 report step "Copying the receipt"
1125 cp receipt taz/$PACKAGE-$VERSION
1126 report end-step
1127 if grep -q ^get_version $RECEIPT; then
1128 report step "Updating version in receipt"
1129 sed -i "s/^VERSION=.*/VERSION=\"$VERSION\"/" \
1130 taz/$PACKAGE-$VERSION/receipt
1131 report end-step
1132 fi
1133 if [ -f "description.txt" ]; then
1134 report step "Copying the description file"
1135 cp description.txt taz/$PACKAGE-$VERSION
1136 report end-step
1137 fi
1139 # Generate md5 of cooking stuff to look for commit later.
1140 gen_cookmd5
1141 echo -e "\n# md5sum of cooking stuff :" >> taz/$PACKAGE-$VERSION/receipt
1142 cat md5 | sed 's/^/# /' >> taz/$PACKAGE-$VERSION/receipt
1144 # Create the files.list by redirecting find output.
1145 report step "Creating the list of files"
1146 cd taz/$PACKAGE-$VERSION
1147 LAST_FILE=""
1148 { find fs -print; echo; } | while read file; do
1149 if [ "$LAST_FILE" ]; then
1150 case "$file" in
1151 $LAST_FILE/*)
1152 case "$(ls -ld "$LAST_FILE")" in
1153 drwxr-xr-x\ *\ root\ *\ root\ *);;
1154 *) echo ${LAST_FILE#fs};;
1155 esac;;
1156 *) echo ${LAST_FILE#fs};;
1157 esac
1158 fi
1159 LAST_FILE="$file"
1160 done > files.list
1162 # Next, check if something has changed in lib files.
1163 # Plan to recook each packages which depends on libs
1164 # which doesn't exists anymore.
1165 for rep in $INCOMING_REPOSITORY $PACKAGES_REPOSITORY; do
1166 prev_VERSION=$(get_pkg_version $rep)
1167 [ "$prev_VERSION" ] && pkg_file=$rep/$PACKAGE-$prev_VERSION.tazpkg && break
1168 done
1169 if [ "$pkg_file" ]; then
1170 report step "Looking if reverse depends needs to be refreshed"
1171 get_pkg_files $pkg_file
1172 cd $WOK/$PACKAGE/taz/$PACKAGE-$VERSION
1174 pkg_to_check=$(diff files.list $pkg_files_dir/files.list | \
1175 grep '^-/.*\.so' | while read lib; do
1176 fgrep " ${lib##*/} " $libs_db | cut -f1
1177 done | sort -u)
1179 if [ "$pkg_to_check" ]; then
1180 for rdep in $(scan $PACKAGE --look_for=rdep | use_wanted); do
1181 echo "$pkg_to_check" | grep -q ^$PACKAGE$ || continue
1182 [ "$rdep" = "${WANTED:-$PACKAGE}" ] && continue
1183 grep -q ^$rdep$ $blocked $cooklist && continue
1184 echo "Plan to recook $rdep"
1185 echo $rdep >> $cooklist
1186 regen_cooklist=yes
1187 done
1188 fi
1190 rm -r $pkg_files_dir
1191 unset pkg_file pkg_file_dir pkg_to_check
1192 report end-step
1193 fi
1195 # Update lib_db
1196 libs=$(for file in $(find * -type f); do
1197 [ "$(dd if=$file bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ] || continue
1198 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $PWD/$file
1199 done | { cut -f 1 -d ' ' | tr -d '\t' | sort -u | \
1200 sed -e 's/^linux-gate.so.*$/SLIB/' -e 's~^/lib/ld-.*$~SLIB~' \
1201 -e '/^statically$/d' | tr '\n' ' '; })
1203 sed "/$PACKAGE\t/d" -i $lib_db
1204 if [ "$libs" ]; then
1205 libs=$(echo " $libs" | sed -r 's/( SLIB)+ / /g')
1206 echo -e "$PACKAGE\t$libs" >> $lib_db
1207 sort -o $lib_db $lib_db
1208 fi
1209 unset libs
1211 if [ ! "$EXTRAVERSION" ]; then
1212 case "$PACKAGE" in
1213 linux*);;
1214 *) EXTRAVERSION="$(grep '/lib/modules/.*-slitaz/' files.list |\
1215 head -1 | sed 's|/lib/modules/\(.*\)-slitaz/.*|_\1|')";;
1216 esac
1217 fi
1218 rm -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg 2> /dev/null
1220 report step "Creating md5sum of files"
1221 while read file; do
1222 [ -L "fs$file" ] && continue
1223 [ -f "fs$file" ] || continue
1224 md5sum "fs$file" | sed 's/ fs/ /'
1225 done < files.list > md5sum
1226 report end-step
1227 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
1228 2> /dev/null | awk '{ sz=$1 } END { print sz }')
1230 # Build cpio archives. Find, cpio and gzip the fs, finish by
1231 # removing the fs tree.
1232 # Don't log this because compression always outputs error messages.
1233 find fs -print | cpio -o -H newc | case "$PACKAGE-$COMPRESSION" in
1234 tazpkg-lzma) gzip > fs.cpio.gz;;
1235 *-lzma) lzma e fs.cpio.lzma -si;;
1236 *) gzip > fs.cpio.gz;;
1237 esac && rm -rf fs
1238 PACKED_SIZE=$(du -chs fs.cpio.* receipt files.list md5sum \
1239 description.txt 2> /dev/null | awk '{ sz=$1 } END { print sz }')
1240 report step "Updating receipt sizes"
1241 sed -i '/^PACKED_SIZE/d' receipt
1242 sed -i '/^UNPACKED_SIZE/d' receipt
1243 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1244 sed -i "s/^VERSION=$/VERSION=\"$VERSION\"/" receipt
1245 report end-step
1246 if [ "$EXTRAVERSION" ]; then
1247 report step "Updating receipt EXTRAVERSION"
1248 sed -i s/^EXTRAVERSION.*$// receipt
1249 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
1250 fi
1251 prev_VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
1252 remove_previous_package $INCOMING_REPOSITORY
1253 report step "Creating full cpio archive"
1254 find . -print | cpio -o -H newc > $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1256 # Restore package tree in case we want to browse it.
1257 report step "Restoring original package tree"
1258 { zcat fs.cpio.gz 2> /dev/null || unlzma -c fs.cpio.lzma; } | cpio --quiet -id
1259 rm fs.cpio.* && cd ..
1261 # Save receipts if save_wok is enabled.
1262 [ "$save_wok" ] && copy_cooking_stuff $WOK $PACKAGE $INCOMING_REPOSITORY/wok
1264 # Recook of reverse-depends if package was broken.
1265 if grep -q "^$PACKAGE$" $broken; then
1266 report step "Planning a re-try cook of reverse depends"
1267 sed "/^$PACKAGE$/d" -i $broken
1268 for rdep in $(look_for_rdep); do
1269 grep -q "^$rdep$" $broken || continue
1270 grep -q "^$rdep$" $cooklist && continue
1271 echo "Adding $rdep to the cooklist"
1272 echo $rdep >> $cooklist
1273 regen_cooklist=t
1274 done
1275 report end-step
1276 fi
1277 sed "/^$PACKAGE$/d" -i $commit $cooklist
1279 # Log process.
1280 echo "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg (done)" >> $LOG
1281 report close-bloc
1282 echo "Package $PACKAGE ($VERSION$EXTRAVERSION) generated."
1283 echo "Size : `du -sh $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
1284 echo ""
1287 ########################################################################
1288 # This section contains functions used by several other functions
1289 # below.
1290 ########################
1292 # Look for receipt/files.list in wok. If they can't be found, get them
1293 # from package. Accept one argument : absolute path to package.
1294 get_pkg_files()
1296 pkg_files_dir=$tmp/$(basename ${1%.tazpkg})
1297 mkdir -p $pkg_files_dir && \
1298 cd $pkg_files_dir && \
1299 cpio --quiet -idm receipt < $1 && \
1300 cpio --quiet -idm files.list < $1
1303 ########################################################################
1304 # This section contains functions to generate packages databases.
1305 ########################
1308 gen_packages_db()
1310 # pkg_repository can be $PACKAGES_REPOSITORY or $INCOMING_REPOSITORY.
1311 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1312 cd $pkg_repository
1313 report step "Generating packages lists: $pkg_repository"
1314 report open-bloc
1315 report step "Removing old files"
1316 for file in files.list.lzma packages.list packages.txt \
1317 packages.desc packages.equiv packages.md5; do
1318 rm -rf $file
1319 done
1320 touch files.list
1322 packages_db_start
1323 unset RECEIPT
1324 report step "Reading data from all packages"
1325 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1326 get_packages_info
1327 done
1328 report end-step
1329 packages_db_end
1330 report close-bloc
1333 update_packages_db()
1335 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1336 cd $pkg_repository
1337 for file in packages.list packages.equiv packages.md5 packages.desc \
1338 packages.txt; do
1339 if [ ! -f "$file" ]; then
1340 gen_packages_db
1341 return
1342 fi
1343 done
1344 if [ -f files.list.lzma ]; then
1345 lzma d files.list.lzma files.list
1346 else
1347 gen_packages_db
1348 return
1349 fi
1350 report step "Updating packages lists: $pkg_repository"
1351 packages_db_start
1353 # Look for removed/update packages.
1354 touch stamp -r packages.list
1355 for PACKAGE in $(grep ^[0-9,a-z,A-Z] packages.txt); do
1356 pkg="$pkg_repository/$(grep -m1 ^$PACKAGE- packages.list).tazpkg"
1357 if ! [ -f "$pkg" ]; then
1358 erase_package_info
1359 else
1360 if [ "$pkg" -nt "stamp" ]; then
1361 updated_pkg="$updated_pkg
1362 $PACKAGE $pkg"
1363 elif [ ! -f $WOK/$PACKAGE/receipt ] && \
1364 [ "$COMMAND" = check-incoming -o "$pkg_repository" = "$INCOMING_REPOSITORY" ]; then
1365 erase_package_info
1366 echo "Removing $PACKAGE from $pkg_repository."
1367 rm $pkg
1368 [ "$save_wok" ] && rm -rf $pkg_repository/wok/$PACKAGE
1369 if [ "$pkg_repository" = "$INCOMING_REPOSITORY" ]; then
1370 rm -rf $WOK/$PACKAGE
1371 sed "/^$PACKAGE\t/d" -i $wan_db $dep_db $cookorder
1372 sed "/^$PACKAGE$/d" -i $cooklist $commit $blocked $broken
1373 rm -f $LOCAL_REPOSITORY/log/$PACKAGE.html
1374 if [ "$(sed 1!d $cookorder)" != "#PlanSort" ]; then
1375 sed 1i"#PlanSort" -i $cookorder
1376 regen_cooklist=yes
1377 fi
1378 else
1379 echo "$PACKAGE" >> removed
1380 sed -n '1,10p' -i removed
1381 fi
1382 fi
1383 fi
1384 done
1385 rm stamp
1386 echo "$updated_pkg" | sed 1d | while read PACKAGE pkg; do
1387 erase_package_info
1388 get_packages_info
1389 done
1390 unset updated_pkg
1392 # Look for new packages.
1393 for pkg in $pkg_repository/*.tazpkg; do
1394 fgrep -q " ${pkg##*/}" packages.md5 || get_packages_info
1395 done
1396 report end-step
1397 packages_db_end
1400 packages_db_start()
1402 if [ -s packages.txt ]; then
1403 sed -e 's/^# Packages :.*/# Packages : unknown/' \
1404 -e "s/# Date :.*/# Date : $(date +%Y-%m-%d\ \%H:%M:%S)/" \
1405 -i packages.txt
1406 else
1407 echo "# SliTaz GNU/Linux - Packages list
1409 # Packages : unknown
1410 # Date : $(date +%Y-%m-%d\ \%H:%M:%S)
1412 " > packages.txt
1413 fi
1415 # Needed in some cases as tazwok defines RECEIPT at configuration time
1416 # in this particular case it can break the script.
1417 unset RECEIPT
1419 # If $packages_repository is the main one, configure few functions
1420 # to act as they should, without having loop on them (speed-up)
1421 if [ "$pkg_repository" = "$PACKAGES_REPOSITORY" ]; then
1422 erase_package_info_extracmd="erase_package_info_main"
1423 get_packages_info_extracmd="get_packages_info_main"
1424 fi
1427 erase_package_info()
1429 cd $pkg_repository
1430 sed "/^$PACKAGE$/,/^$/d" -i packages.txt
1431 sed "/^$PACKAGE /d" -i packages.desc
1432 sed -e "s/=$PACKAGE /= /" -e "s/ $PACKAGE / /" -e "s/ $PACKAGE$//" \
1433 -e "/=$PACKAGE$/d" -e "s/=[0-9,a-z,A-Z]:$PACKAGE /= /" \
1434 -e "s/ [0-9,a-z,A-Z]:$PACKAGE / /" -e "s/ [0-9,a-z,A-Z]:$PACKAGE$/ /" \
1435 -e "/=[0-9,a-z,A-Z]:$PACKAGE$/d" \
1436 -i packages.equiv
1437 sed "/^$PACKAGE:/d" -i files.list
1438 sed "/^$(basename ${pkg%.tazpkg})$/d" -i packages.list
1439 sed "/ $(basename $pkg)$/d" -i packages.md5
1440 $erase_package_info_extracmd
1443 erase_package_info_main()
1445 for i in wanted.txt depends.txt libraries.txt; do
1446 [ -f $i ] || continue
1447 sed "/^$PACKAGE\t/d" -i $i
1448 done
1451 get_packages_info()
1453 # If there's no taz folder in the wok, extract info from the
1454 # package.
1455 get_pkg_files $pkg
1456 source_receipt
1457 echo "Getting data from $PACKAGE"
1459 cat >> $pkg_repository/packages.txt << _EOT_
1460 $PACKAGE
1461 $VERSION$EXTRAVERSION
1462 $SHORT_DESC
1463 _EOT_
1464 if [ "$PACKED_SIZE" ]; then
1465 cat >> $pkg_repository/packages.txt << _EOT_
1466 $PACKED_SIZE ($UNPACKED_SIZE installed)
1468 _EOT_
1469 else
1470 echo "" >> $pkg_repository/packages.txt
1471 fi
1473 # Packages.desc is used by Tazpkgbox <tree>.
1474 echo "$PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> $pkg_repository/packages.desc
1476 # Packages.equiv is used by tazpkg install to check depends.
1477 for i in $PROVIDE; do
1478 DEST=""
1479 echo $i | fgrep -q : && DEST="${i#*:}:"
1480 if grep -qs ^${i%:*}= $pkg_repository/packages.equiv; then
1481 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" $pkg_repository/packages.equiv
1482 else
1483 echo "${i%:*}=$DEST$PACKAGE" >> $pkg_repository/packages.equiv
1484 fi
1485 done
1487 if [ -f files.list ]; then
1488 { echo "$PACKAGE"; cat files.list; } | awk '
1489 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }' >> $pkg_repository/files.list
1490 fi
1492 cd .. && rm -r "$pkg_files_dir"
1494 cd $pkg_repository
1495 echo $(basename ${pkg%.tazpkg}) >> packages.list
1496 md5sum $(basename $pkg) >> packages.md5
1497 $get_packages_info_extracmd
1500 get_packages_info_main()
1502 [ "$WANTED" ] && echo -e "$PACKAGE\t$WANTED" >> wanted.txt
1503 echo -e "$PACKAGE\t "$DEPENDS" \t "$BUILD_DEPENDS" " >> package.txt
1504 grep -m1 ^$PACKAGE$'\t' $lib_db >> libraries.txt
1507 source_receipt()
1509 unset PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
1510 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
1511 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
1512 src _pkg DESTDIR CONFIG_SITE BRANCH TARBALL stuff wanted_stuff
1513 . ${RECEIPT:-$PWD/receipt}
1516 packages_db_end()
1518 cd $pkg_repository
1519 pkgs=$(wc -l packages.list | sed 's/ .*//')
1520 sed "s/# Packages : .*/# Packages : $pkgs/" -i packages.txt
1522 # If lists were updated it's generally needed to sort them well.
1523 if ! sort -c packages.list 2> /dev/null; then
1524 report step "Sorting packages lists"
1525 files_list="packages.list packages.desc packages.equiv"
1526 [ "${pkg_repository##*/}" = packages ] && \
1527 files_list="$files_list wanted.txt depends.txt libraries.txt"
1528 for file in $files_list; do
1529 [ -f $file ] || continue
1530 sort -o $file $file
1531 done
1532 report end-step
1533 fi
1535 md5sum packages.md5 | cut -f1 -d' ' > ID
1536 [ -s ID ] || echo null > ID
1538 # Dont log this because lzma always output errors.
1539 lzma e files.list files.list.lzma
1540 rm -f files.list
1541 [ -f packages.equiv ] || touch packages.equiv
1544 ########################################################################
1545 # This section contains functions to generate wok database.
1546 ########################
1548 gen_wok_db()
1550 report step "Generating wok database"
1551 report open-bloc
1552 report step "Removing old files"
1553 for file in $wan_db $dep_db $cookorder; do
1554 [ -f $file ] && rm $file
1555 done
1556 report step "Generating wok-wanted.txt"
1557 gen_wan_db
1558 report step "Generating wok-depends.txt"
1559 for PACKAGE in $(cut -f1 -d '|' $PACKAGES_REPOSITORY/packages.desc \
1560 $INCOMING_REPOSITORY/packages.desc | sort -u); do
1561 RECEIPT=$WOK/$PACKAGE/receipt
1562 if [ -s $RECEIPT ]; then
1563 source_receipt
1564 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
1565 fi
1566 done
1567 sort_db
1568 report close-bloc
1571 gen_wan_db()
1573 rm -f $wan_db
1574 for RECEIPT in $(fgrep -l WANTED $WOK/*/receipt); do
1575 WANTED=
1576 source $RECEIPT
1577 [ "$WANTED" ] || continue
1578 echo -e $PACKAGE"\t"$WANTED >> $wan_db
1579 done
1582 update_wan_db()
1584 local PACKAGE=$PACKAGE
1585 wanted_list=$(fgrep WANTED=\"$PACKAGE\" $WOK/*/receipt | cut -f1 -d ':')
1586 grep $'\t'$PACKAGE $wan_db | cut -f 1 | while read wan; do
1587 echo "$wanted_list" | fgrep -q /$wan/receipt && continue
1588 sed "/^$wan\t/d" -i $wan_db
1589 done
1590 for RECEIPT in $wanted_list; do
1591 unset WANTED PACKAGE
1592 source $RECEIPT
1593 [ "$WANTED" ] || continue
1594 sed "/^$PACKAGE\t/d" -i $wan_db
1595 echo -e $PACKAGE"\t"$WANTED >> $wan_db
1596 done
1597 unset wanted_list
1600 update_dep_db()
1602 sed "/^$PACKAGE\t/d" -i $dep_db
1603 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
1606 sort_db()
1608 report step "Generating cookorder.txt"
1609 sed 's/ \t / /' $dep_db | while read PACKAGE BUILD_DEPENDS; do
1610 grep -q ^$PACKAGE$'\t' $wan_db && continue
1612 # Replace each BUILD_DEPENDS with a WANTED package by it's
1613 # WANTED package.
1614 echo -e $PACKAGE"\t $(echo $BUILD_DEPENDS | use_wanted | \
1615 sort -u | sed "/^$PACKAGE$/d" | tr '\n' ' ') "
1616 done > $tmp/db
1617 while [ -s "$tmp/db" ]; do
1618 status=start
1619 for pkg in $(cut -f 1 $tmp/db); do
1620 if ! fgrep -q ' '$pkg' ' $tmp/db; then
1621 echo $pkg >> $tmp/cookorder
1622 sed -e "/^$pkg\t/d" -e "s/ $pkg / /g" -i $tmp/db
1623 status=proceed
1624 fi
1625 done
1626 if [ "$status" = start ]; then
1627 cp -f $tmp/db /tmp/remain-depends.txt
1628 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
1629 for remaining in $(cut -f 1 $tmp/db); do
1630 echo "$remaining" >> $blocked
1631 done
1632 break
1633 fi
1634 done
1635 [ -s $tmp/cookorder ] || touch $tmp/cookorder
1637 # The toolchain packages are moved in first position.
1638 grep $(for pkg in `scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
1639 --look_for=all --with_args`; do echo " -e ^$pkg$"; done) \
1640 $tmp/cookorder | tac > $cookorder
1641 for pkg in $(cat $cookorder); do
1642 sed "/^$pkg$/d" -i $tmp/cookorder
1643 done
1645 tac $tmp/cookorder >> $cookorder
1646 report end-step
1649 ########################################################################
1650 # SCAN CORE
1651 ########################
1652 # Includes various scan core-functions. It's not intended to be used
1653 # directly : prefer scan wrappers in next section.
1655 look_for_dep()
1657 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2
1660 look_for_bdep()
1662 look_for_all
1665 look_for_all()
1667 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2,3 | sed 's/ / /'
1670 look_for_rdep()
1672 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1
1675 look_for_rbdep()
1677 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1680 # Return WANTED if it exists.
1681 look_for_wanted()
1683 grep -m1 ^$PACKAGE$'\t' $wan_db | cut -f 2
1686 # Return packages which wants PACKAGE.
1687 look_for_rwanted()
1689 grep $'\t'$PACKAGE$ $wan_db | cut -f 1
1692 look_for_dev()
1694 WANTED=$(look_for_wanted)
1695 if [ "$WANTED" ]; then
1696 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1697 fi
1698 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1701 with_dev()
1703 for PACKAGE in $(cat); do
1704 echo $PACKAGE
1705 look_for_dev
1706 done
1709 with_wanted()
1711 for PACKAGE in $(cat); do
1712 echo $PACKAGE
1713 look_for_wanted
1714 done
1717 use_wanted()
1719 for input in $(cat); do
1720 { grep ^$input$'\t' $wan_db || echo $input
1722 done | sed 's/.*\t//'
1725 check_for_pkg_in_wok()
1727 [ -f $WOK/$PACKAGE/receipt ] && return
1728 echo "Can't find $PACKAGE in wok or mirror" >&2
1729 return 2
1732 # Define how theses functions should act when using --undigest.
1733 use_undigest_scan_core()
1735 look_for_dep()
1737 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1738 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2
1739 else
1740 grep -m1 ^$PACKAGE$'\t' $ref_dep_db | cut -f 2
1741 fi
1744 look_for_all()
1746 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1747 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2,3 | sed 's/ / /'
1748 else
1749 grep -m1 ^$PACKAGE$'\t' $ref_dep_db | cut -f 2,3 | sed 's/ / /'
1750 fi
1753 look_for_rdep()
1755 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1
1756 for rdep in $(fgrep ' '$PACKAGE' ' $ref_dep_db | cut -f 1); do
1757 [ -f "WOK$/$rdep/receipt" ] || echo "$rdep"
1758 done
1761 look_for_rbdep()
1763 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1764 for rdep in $(fgrep ' '$PACKAGE' ' $ref_dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1); do
1765 [ -f "WOK$/$rdep/receipt" ] || echo "$rdep"
1766 done
1769 look_for_wanted()
1771 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1772 grep -m1 ^$PACKAGE$'\t' $wan_db | cut -f 2
1773 else
1774 grep -m1 ^$PACKAGE$'\t' $ref_wan_db | cut -f 2
1775 fi
1778 look_for_rwanted()
1780 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1781 grep $'\t'$PACKAGE$ $wan_db | cut -f 1
1782 else
1783 grep $'\t'$PACKAGE$ $ref_wan_db | cut -f 1
1784 fi
1787 look_for_dev()
1789 WANTED=$(look_for_wanted)
1790 if [ "$WANTED" ]; then
1791 if [ -f "$WOK/$WANTED/receipt" ]; then
1792 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1793 else
1794 grep -q ^$WANTED-dev$'\t' $ref_dep_db && echo $WANTED-dev
1795 fi
1796 fi
1797 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1798 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1799 else
1800 grep -q ^$PACKAGE-dev$'\t' $ref_dep_db && echo $PACKAGE-dev
1801 fi
1804 check_for_pkg_in_wok()
1806 [ -f $WOK/$PACKAGE/receipt ] && return
1807 grep -q ^$PACKAGE'$\t' $ref_dep_db && return 1
1808 echo "Can't find $PACKAGE in wok or mirror" >&2
1809 return 2
1813 ########################################################################
1814 # SCAN
1815 ########################
1816 # Use wok-wanted.txt and wok-depeds.txt to scan depends.
1817 # Option in command line (must be first arg) :
1818 # --look_for=bdep/rbdep - Look for depends or reverse depends.
1819 # --with_dev - Add development packages (*-dev) in the result.
1820 # --with_wanted - Add package+reverse wanted in the result.
1821 # --with_args - Include packages in argument in the result.
1823 scan()
1825 # Get packages in argument.
1826 local PACKAGE=$PACKAGE WANTED=$WANTED pkg_list=
1827 for arg in $@; do
1828 [ "$arg" = "${arg#--}" ] || continue
1829 pkg_list="$pkg_list $arg"
1830 done
1832 # Get options.
1833 [ "$pkg_list" ] || return
1834 local cooklist= look_for= with_dev= with_wanted= with_args= log_command="$0 $@" \
1835 get_options_list="look_for with_dev with_wanted with_args cooklist use_wanted"
1836 get_options
1838 # Get db md5 to be able to check for changes latter.
1839 db_md5=$(md5sum $dep_db $wan_db)
1841 # Cooklist is a special case where we need to modify a little
1842 # scan behavior
1843 if [ "$cooklist" ]; then
1844 gen_wan_db
1845 look_for=all && with_args=yes && with_dev= && with_wanted=
1846 filter=use_wanted
1847 if [ "$COMMAND" = gen-cooklist ]; then
1848 for PACKAGE in $pkg_list; do
1849 grep -q ^$PACKAGE$'\t' $dep_db && continue
1850 [ -d "$WOK/$p" ] || continue
1851 check_for_missing
1852 done
1853 append_to_dep()
1855 if grep -q ^$PACKAGE$'\t' $dep_db; then
1856 echo $PACKAGE >> $tmp/dep
1857 else
1858 check_for_missing && echo $PACKAGE >> $tmp/dep
1859 fi
1861 else
1862 append_to_dep()
1864 check_for_commit && echo $PACKAGE >> $tmp/dep
1866 fi
1867 else
1868 append_to_dep()
1870 echo $PACKAGE >> $tmp/dep
1872 # If requested packages are not in dep_db, partial generation of this db is needed.
1873 for PACKAGE in $pkg_list; do
1874 grep -q ^$PACKAGE$'\t' $dep_db && continue
1875 [ -d "$WOK/$p" ] || continue
1876 plan_check_for_missing=yes
1877 check_for_missing
1878 done
1879 if [ "$plan_check_for_missing" ]; then
1880 append_to_dep()
1882 if grep -q ^$PACKAGE$'\t' $dep_db; then
1883 echo $PACKAGE >> $tmp/dep
1884 else
1885 check_for_missing && echo $PACKAGE >> $tmp/dep
1886 fi
1888 unset plan_check_for_missing
1889 fi
1890 fi
1892 [ "$with_dev" ] && filter=with_dev
1893 [ "$with_wanted" ] && filter=with_wanted
1894 if [ "$filter" ]; then
1895 pkg_list=$(echo $pkg_list | $filter | sort -u)
1896 scan_pkg()
1898 look_for_$look_for | $filter
1900 else
1901 scan_pkg()
1903 look_for_$look_for
1905 fi
1906 touch $tmp/dep
1907 for PACKAGE in $pkg_list; do
1908 [ "$with_args" ] && append_to_dep
1909 scan_pkg
1910 done | tr ' ' '\n' | sort -u > $tmp/list
1911 [ "$look_for" = bdep ] && look_for=dep
1912 while [ -s $tmp/list ]; do
1913 PACKAGE=$(sed 1!d $tmp/list)
1914 sed 1d -i $tmp/list
1915 append_to_dep
1916 for pkg in $(scan_pkg); do
1917 grep -q ^$pkg$ $tmp/list $tmp/dep || echo $pkg >> $tmp/list
1918 done
1919 done
1920 if [ "$cooklist" ]; then
1921 mv $tmp/dep $tmp/cooklist
1922 else
1923 cat $tmp/dep | sort -u
1924 fi
1925 rm -f $tmp/dep $tmp/list
1926 sort -o $dep_db $dep_db
1927 sort -o $wan_db $wan_db
1928 if [ "$db_md5" != "$(md5sum $dep_db $wan_db)" ]; then
1929 grep -q "^#" $cookorder || sed 1i"#PlanSort" -i $cookorder
1930 fi
1933 ########################################################################
1934 # This section contains functions to check the package repository and
1935 # find which packages to cook.
1936 ########################
1938 check_for_missing()
1940 local PACKAGE=$PACKAGE
1941 if ! check_for_pkg_in_wok; then
1942 [ "$?" = 2 ] && return 1
1943 return
1944 fi
1945 RECEIPT=$WOK/$PACKAGE/receipt
1946 source_receipt
1947 PACKAGE=${WANTED:-$PACKAGE}
1948 update_wan_db
1949 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1950 RECEIPT=$WOK/$PACKAGE/receipt
1951 source_receipt
1952 update_dep_db
1953 done
1956 check_for_commit()
1958 if ! check_for_pkg_in_wok; then
1959 [ "$?" = 2 ] && return 1
1960 return
1961 fi
1962 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1963 RECEIPT=$WOK/$PACKAGE/receipt
1964 source_receipt
1966 # We use md5 of cooking stuff in the packaged receipt to check
1967 # commit. We look consecutively in 3 different locations :
1968 # - in the wok/PACKAGE/taz/* folder
1969 # - in the receipt in the package in incoming repository
1970 # - in the receipt in the package in packages repository
1971 # If md5sums match, there's no commit.
1972 check_for_commit_using_md5sum()
1974 if [ ! -f $WOK/$PACKAGE/md5 ]; then
1975 sed -n '/# md5sum of cooking stuff :/,$p' receipt | \
1976 sed -e 1d -e 's/^# //' > $WOK/$PACKAGE/md5
1977 cd $WOK/$PACKAGE
1978 fi
1980 if [ -s md5 ]; then
1981 if md5sum -cs md5; then
1983 # If md5sum check if ok, check for new/missing files in
1984 # cooking stuff.
1985 for file in $([ -f receipt ] && echo receipt; \
1986 [ -f description.txt ] && echo description.txt; \
1987 [ -d stuff ] && find stuff); do
1988 if ! fgrep -q " $file" md5; then
1989 set_commited
1990 fi
1991 done
1992 else
1993 set_commited
1994 fi
1995 else
1996 set_commited
1997 fi
1999 set_commited()
2001 grep -q ^$PACKAGE$ $commit || echo $PACKAGE >> $commit
2002 gen_cookmd5
2003 update_dep_db
2005 taz_dir=$(echo $WOK/$PACKAGE/taz/$PACKAGE-* | fgrep -v '*')
2006 if [ -f $WOK/$PACKAGE/md5 ]; then
2007 cd $WOK/$PACKAGE
2008 check_for_commit_using_md5sum
2009 elif [ "$taz_dir" ]; then
2010 cd $taz_dir
2011 check_for_commit_using_md5sum
2012 else
2013 pkg=$(echo $INCOMING_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
2014 [ "$pkg" ] || pkg=$(echo $PACKAGES_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
2015 if [ "$pkg" ]; then
2016 get_pkg_files $pkg
2017 check_for_commit_using_md5sum
2018 rm -r $pkg_files_dir
2019 else
2020 set_commited
2021 fi
2022 fi
2023 [ "$forced" ] || echo $PACKAGE >> $tmp/checked
2024 done
2025 return
2028 gen_cook_list()
2030 report step "Scanning wok"
2031 if [ "$pkg" ]; then
2032 scan $pkg --cooklist
2033 elif [ "$LIST" ]; then
2034 scan `cat $LIST` --cooklist
2035 else
2036 scan `cat $cooklist` --cooklist
2037 fi
2038 report end-step
2040 [ -s $tmp/checked ] || [ -s $tmp/cooklist ] || return
2042 # Core toolchain should not be cooked unless cook-toolchain is used.
2043 if ! [ -f /etc/config.site.tmptoolchain ] ; then
2044 for PACKAGE in $(scan gcc --look_for=all --with_args --with_wanted); do
2045 grep -q ^$PACKAGE$ $blocked || echo $PACKAGE >> $blocked
2046 done
2047 fi
2049 if [ -s $commit ] && [ "$COMMAND" != gen-cooklist ]; then
2050 for PACKAGE in $(cat $commit); do
2051 WANTED="$(look_for_wanted)"
2052 if [ "$WANTED" ]; then
2053 grep -q ^$WANTED$ $broken $cooklist $blocked $commit && continue
2054 fi
2055 grep -q ^$PACKAGE$ $blocked $cooklist && continue
2056 echo $PACKAGE >> $cooklist
2057 done
2058 fi
2059 sort_cooklist
2062 sort_cooklist()
2064 if [ "$(sed 1!d $cookorder)" = "#PlanSort" ]; then
2065 sed 1d -i $cookorder
2066 sort_db
2067 fi
2068 report step "Generating cooklist"
2069 if [ -f "$tmp/checked" ]; then
2070 rm -f $tmp/cooklist
2071 cat $tmp/checked | while read PACKAGE; do
2072 grep -q ^$PACKAGE$ $cooklist && echo $PACKAGE >> $tmp/cooklist
2073 done
2074 elif ! [ "$COMMAND" = gen-cooklist ]; then
2075 cat $blocked | while read PACKAGE; do
2076 sed "/^$PACKAGE/d" -i $tmp/cooklist
2077 done
2078 fi
2079 report end-step
2080 [ -s $tmp/cooklist ] || return
2082 report step "Sorting cooklist"
2083 for PACKAGE in $(cat $tmp/cooklist); do
2084 WANTED="$(look_for_wanted)"
2085 [ "$WANTED" ] || continue
2086 if grep -q ^$WANTED$ $broken $tmp/cooklist; then
2087 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2088 elif [ ! -d $WOK/$WANTED/install ]; then
2089 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2090 echo $WANTED >> $tmp/cooklist
2091 fi
2092 done
2094 # Use cookorder.txt to sort cooklist.
2095 if [ -s $tmp/cooklist ]; then
2096 cat $cookorder | while read PACKAGE; do
2097 if grep -q ^$PACKAGE$ $tmp/cooklist; then
2098 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2099 echo $PACKAGE >> $tmp/cooklist.tmp
2100 fi
2101 done
2103 # Remaining packages in cooklist are those without compile_rules.
2104 # They can be cooked first in any order.
2105 if [ -f $tmp/cooklist.tmp ]; then
2106 cat $tmp/cooklist.tmp >> $tmp/cooklist
2107 rm $tmp/cooklist.tmp
2108 fi
2110 cat $tmp/cooklist
2111 [ "$LIST" ] || cat $tmp/cooklist > $cooklist
2112 fi
2114 report end-step
2117 look_for_missing_pkg()
2119 for pkg in $(cat $PACKAGES_REPOSITORY/$1); do
2120 grep -q ^$pkg$ $INCOMING_REPOSITORY/packages.txt \
2121 $PACKAGES_REPOSITORY/packages.txt || \
2122 continue
2123 echo $pkg
2124 done
2127 check_for_incoming()
2129 report step "Checking that all packages were cooked OK"
2130 [ -s $INCOMING_REPOSITORY/packages.desc ] || {
2131 echo "No packages in $INCOMING_REPOSITORY."
2132 report end-step; return; }
2133 if [ -s $broken ]; then
2134 missingpkg=$(look_for_missing_pkg broken)
2135 if [ "$missingpkg" ]; then
2136 echo "Don't move incoming packages to main repository because these ones are broken:" >&2
2137 echo "$missingpkg"
2138 report end-step
2139 return 1
2140 fi
2141 fi
2142 if [ -s $cooklist ]; then
2143 missingpkg=$(look_for_missing_pkg cooklist)
2144 if [ "$missingpkg" ]; then
2145 echo "Don't move incoming packages to main repository because these ones need to be cooked:" >&2
2146 echo "$missingpkg"
2147 report end-step
2148 return 1
2149 fi
2150 fi
2151 incoming_pkgs="$(cut -f 1 -d '|' $INCOMING_REPOSITORY/packages.desc)"
2152 if ! [ "$forced" ]; then
2153 cooklist=$PACKAGES_REPOSITORY/cooklist
2154 pkg="$incoming_pkgs"
2155 gen_cook_list
2156 if [ -s $cooklist ]; then
2157 missingpkg=$(look_for_missing_pkg cooklist)
2158 if [ "$missingpkg" ]; then
2159 echo "Don't move incoming packages to main repository because these ones need to be cooked:" >&2
2160 echo "$missingpkg"
2161 report end-step
2162 return 1
2163 fi
2164 fi
2165 fi
2167 report step "Moving incoming packages to main repository"
2168 [ "save_wok" ] && mkdir -p $PACKAGES_REPOSITORY/wok
2169 unset EXTRAVERSION
2170 for PACKAGE in $incoming_pkgs; do
2171 prev_VERSION=$(get_pkg_version $PACKAGES_REPOSITORY)
2172 VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
2173 remove_previous_package $PACKAGES_REPOSITORY
2174 echo "Moving $PACKAGE..."
2175 mv -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION.tazpkg $PACKAGES_REPOSITORY
2176 touch $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
2177 previous_tarball=$(grep -m1 ^$PACKAGE:main $SOURCES_REPOSITORY/sources.list | cut -f2)
2178 sed -e "/^$PACKAGE:main/d" \
2179 -e "s/^$PACKAGE:incoming/$PACKAGE:main/" \
2180 -i $SOURCES_REPOSITORY/sources.list
2181 if [ "$previous_tarball" ]; then
2182 grep -q $'\t'$previous_tarball$ $SOURCES_REPOSITORY/sources.list || \
2183 rm -f $SOURCES_REPOSITORY/$previous_tarball
2184 fi
2185 [ "$save_wok" ] && mv $INCOMING_REPOSITORY/wok/$PACKAGE $PACKAGES_REPOSITORY/wok
2186 done
2188 if [ "$save_wok" = tarball ]; then
2189 rm -f $PACKAGES_REPOSITORY/wok.tar.lzma
2190 cd $PACKAGES_REPOSITORY/wok
2191 report step "Generating safe-wok tarball"
2192 tar -c * | lzma e -si $PACKAGES_REPOSITORY/wok.tar.lzma
2193 report end-step
2194 fi
2196 for file in packages.list packages.equiv packages.md5 packages.desc \
2197 packages.txt; do
2198 echo -n "" > $INCOMING_REPOSITORY/$file
2199 done
2200 rm -r $INCOMING_REPOSITORY/files.list.lzma
2201 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2203 report step "Updating flavors"
2204 if [ -x /usr/bin/tazlito ] || [ -x /usr/bin/clean-chroot ]; then
2205 if ! [ -x /usr/bin/tazlito ]; then
2206 tazpkg get-install tazlito
2207 fi
2209 # Handle cases where tazwok is used into main system;
2210 # Handle cases where SLITAZ_DIR is not /home/slitaz.
2211 [ -L /home/slitaz/flavors ] && rm /home/slitaz/flavors
2212 mkdir -p /home/slitaz
2213 ln -s $LOCAL_REPOSITORY/flavors /home/slitaz/flavors
2215 cd $LOCAL_REPOSITORY/packages
2216 for i in $LOCAL_REPOSITORY/flavors/*; do
2217 [ -d "$i" ] || continue
2218 tazlito pack-flavor ${i##*/}
2219 done
2221 noheader=""
2222 for i in *.flavor; do
2223 tazlito show-flavor $i --brief $noheader
2224 noheader="--noheader"
2225 done > flavors.list
2226 [ -x /usr/bin/clean-chroot ] && clean-chroot
2227 else
2228 echo "Can't create up-to-date flavors because the tazlito package is missing." >&2
2229 fi
2230 report end-step
2233 # Usage: move_cooking_stuff source receipt destination
2234 # Make the argument check before calling it!
2235 copy_cooking_stuff()
2237 rm -rf $3/$2
2238 mkdir -p $3/$2
2239 cp -a $1/$2/receipt $3/$2
2240 [ -f $1/$2/description.txt ] && \
2241 cp -a $1/$2/description.txt $3/$2
2242 if [ -d "$1/$2/stuff" ]; then
2243 cp -a $1/$2/stuff $3/$2
2244 fi
2247 ########################################################################
2248 # TAZWOK MAIN FUNCTIONS
2249 ########################
2251 clean()
2253 cd $WOK/$PACKAGE
2254 ls -A $WOK/$PACKAGE | grep -q -v -e ^receipt$ -e ^description.txt$ \
2255 -e ^stuff$ || return
2257 [ "$COMMAND" = clean-wok ] || report step "Cleaning $PACKAGE"
2258 # Check for clean_wok function.
2259 if grep -q ^clean_wok $RECEIPT; then
2260 clean_wok
2261 fi
2262 # Clean should only have a receipt, stuff and optionals desc/md5.
2263 for f in `ls .`
2264 do
2265 case $f in
2266 receipt|stuff|description.txt|md5)
2267 continue ;;
2268 *)
2269 rm -rf $f ;;
2270 esac
2271 done
2272 [ "$COMMAND" != clean-wok ] && report end-step
2275 # Configure and make a package with the receipt.
2276 compile_package()
2278 check_for_package_on_cmdline
2280 # Include the receipt to get all needed variables and functions
2281 # and cd into the work directory to start the work.
2282 check_for_receipt
2283 source_receipt
2285 # Log the package name and date.
2286 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
2287 echo "package $PACKAGE (compile)" >> $LOG
2289 # Set wanted $src variable to help compiling.
2290 [ ! "$src" ] && set_src_path
2291 check_for_build_depends || return 1
2292 check_for_wanted
2293 unset target
2294 check_for_tarball && check_for_compile_rules
2297 # Cook command also include all features to manage lists which keep
2298 # track of wok/packages state.
2299 cook()
2301 cook_code=
2302 set_common_path
2303 check_for_receipt
2304 source_receipt
2306 # Define log path and start report.
2307 for i in $(look_for_rwanted) $PACKAGE; do
2308 rm -f $LOCAL_REPOSITORY/log/$i.html
2309 done
2310 report sublog $LOCAL_REPOSITORY/log/$PACKAGE.html
2311 echo "$PACKAGE" > $LOCAL_REPOSITORY/log/package
2312 report step "Cooking $PACKAGE"
2313 report open-bloc
2315 clean $PACKAGE
2316 [ -s $tmp/cooklist ] && sed "/^$PACKAGE$/d" -i $tmp/cooklist
2318 if compile_package; then
2319 remove_src
2320 refresh_packages_from_compile
2321 gen_package
2323 # Update packages-incoming repository.
2324 store_pkgname=$PACKAGE
2325 pkg_repository=$INCOMING_REPOSITORY
2326 update_packages_db
2328 PACKAGE=$store_pkgname
2329 unset store_pkgname
2331 # Upgrade to cooked packages if it was previously installed.
2332 report step "Looking for package(s) to upgrade"
2333 for pkg in $(look_for_rwanted) $PACKAGE; do
2334 if [ -f $INSTALLED/$pkg/receipt ]; then
2335 tazpkg get-install $pkg --forced
2336 fi
2337 done
2338 report end-step
2339 else
2340 set_pkg_broken
2341 cook_code=1
2342 fi
2344 # Remove build_depends in cook mode (if in cooklist, it's done when
2345 # checking build_depends of next package and we remove only unneeded
2346 # packages to keep chroot minimal and gain some time).
2347 if [ "$COMMAND" = cook ]; then
2348 remove_build_depends $MISSING_PACKAGE
2349 [ -x /usr/bin/clean-chroot ] && clean-chroot
2350 fi
2352 # Regen the cooklist if it was planned and command is not cook.
2353 [ "$regen_cooklist" ] && unset regen_cooklist &&
2354 [ "$COMMAND" != cook ] && sort_cooklist
2356 # Some hacks to set the bloc & function status as failed if cook has
2357 # failed.
2358 report_return_code=$cook_code
2359 report close-bloc
2360 report end-sublog
2361 rm -f $LOCAL_REPOSITORY/log/package
2362 return $cook_code
2365 cook_list()
2367 if [ -s $tmp/cooklist ]; then
2368 if [ -f /usr/bin/tazchroot ]; then
2369 # Note : options -main variables- are automatically kept by
2370 # the sub-applications tazchroot/tazwok; as well as report data.
2371 cd $LOCAL_REPOSITORY
2372 [ ! -f tazchroot.conf ] && configure_tazchroot
2373 tazchroot tazwok cook-list --SLITAZ_DIR=$SLITAZ_DIR --SLITAZ_VERSION=$SLITAZ_VERSION ${undigest:+ --undigest=$undigest}
2374 return
2375 fi
2376 while [ -s $tmp/cooklist ]; do
2377 PACKAGE=$(sed 1!d $tmp/cooklist)
2378 cook
2379 done
2380 remove_build_depends $MISSING_PACKAGE $remove_later
2381 [ -x /usr/bin/clean-chroot ] && clean-chroot
2382 else
2383 echo "Nothing to cook."
2384 return
2385 fi
2388 configure_tazchroot()
2390 cat > $LOCAL_REPOSITORY/tazchroot.conf << EOF
2391 # Tazchroot configuration file - created by tazwok.
2393 # Local repository definition.
2394 SLITAZ_DIR=$SLITAZ_DIR
2395 SLITAZ_VERSION=$SLITAZ_VERSION
2396 LOCAL_REPOSITORY=$SLITAZ_DIR/${undigest:-$SLITAZ_VERSION}
2397 ${USE_ONLINE_PKG:+USE_ONLINE_PKG=$USE_ONLINE_PKG}
2398 ${undigest:+undigest=$undigest}
2399 ${ref_USE_ONLINE_PKG:+ref_USE_ONLINE_PKG=$ref_USE_ONLINE_PKG}
2401 # Chroot path.
2402 # You can use a chroot into /tmp if it's mounted in RAM
2403 # to speed-up the process, be sure you have a free GB.
2404 # (minimal chroot is like 150~200MB, can be a lot more during cook)
2405 # chroot_dir=/tmp/chroot-${undigest:-$SLITAZ_VERSION}
2406 chroot_dir=\$LOCAL_REPOSITORY/chroot
2408 # Default scripts path (these scripts are added to the
2409 # $chroot_dir/usr/bin and can be called with tazchroot script).
2410 script_dir=/usr/lib/slitaz/chroot-scripts/tazwok
2412 # List of directories to mount.
2413 list_dir="$LOCAL_REPOSITORY
2414 $SLITAZ_LOG$( [ "$undigest" ] && echo -e "\n$SLITAZ_DIR/$SLITAZ_VERSION/packages" )"
2416 create_chroot()
2418 mkdir -p \$chroot_dir
2419 for pkg in \$(tazwok build-depends toolchain --SLITAZ_DIR=\$SLITAZ_DIR --SLITAZ_VERSION=\$SLITAZ_VERSION${undigest:+ --undigest=\$undigest}); do
2420 tazpkg get-install \$pkg --root="\$chroot_dir"
2421 done
2423 # Store list of installed packages needed by cleanchroot.
2424 ls -1 \$chroot_dir/\$INSTALLED > \$chroot_dir/\$LOCALSTATE/chroot-pkgs
2426 sed -e "s~^SLITAZ_DIR=.*~SLITAZ_DIR=\$SLITAZ_DIR~" \\
2427 -e "s/^SLITAZ_VERSION=.*/SLITAZ_VERSION=\$SLITAZ_VERSION/" \\
2428 -i \$chroot_dir/etc/slitaz/slitaz.conf
2429 echo \$SLITAZ_VERSION > \$chroot_dir/etc/slitaz-release
2430 $( [ "$undigest" ] && echo ' echo "undigest='"$undigest"'" >> $chroot_dir/etc/slitaz/tazwok.conf')
2431 sed 's/LC_ALL/LC_ALL=POSIX/' -i \$chroot_dir/etc/profile
2433 # The build bot may run in a sandbox: link sandbox lockfile.
2434 ln -s \$LOCAL_REPOSITORY/sandbox/proc/1 \$chroot_dir/proc/1
2437 mount_chroot()
2439 cp -a /etc/resolv.conf \$chroot_dir/etc/resolv.conf
2440 $( if [ "$USE_ONLINE_PKG" ]; then
2441 echo ' echo "$USE_ONLINE_PKG" > $chroot_dir$LOCALSTATE/mirror'
2442 else
2443 echo ' echo "$LOCAL_REPOSITORY/packages" > $chroot_dir$LOCALSTATE/mirror'
2444 fi
2446 mkdir -p \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming
2447 echo "\$LOCAL_REPOSITORY/packages-incoming" > \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming/mirror
2448 $( if [ "$undigest" ]; then
2449 echo ' mkdir -p $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION'
2450 if [ "$ref_USE_ONLINE_PKG" ]; then
2451 echo ' echo "$ref_USE_ONLINE_PKG" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror'
2452 else
2453 echo ' echo "$ref_LOCAL_REPOSITORY/packages" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror'
2454 fi
2455 fi )
2456 echo -e "\${LOCAL_REPOSITORY##*/}-incoming\nmain" > \$chroot_dir\$LOCALSTATE/priority
2457 mount -o bind /proc \$chroot_dir/proc
2458 mount -o bind /sys \$chroot_dir/sys
2459 mount -o bind /dev/pts \$chroot_dir/dev/pts
2460 mount -o bind /dev/shm \$chroot_dir/dev/shm
2461 for dir in \$list_dir; do
2462 mkdir -p \$dir \$chroot_dir\$dir
2463 mount \$dir \$chroot_dir\$dir
2464 done
2467 umount_chroot()
2469 for dir in \$list_dir; do
2470 umount \$chroot_dir\$dir
2471 done
2472 umount \$chroot_dir/dev/shm
2473 umount \$chroot_dir/dev/pts
2474 umount \$chroot_dir/sys
2475 umount \$chroot_dir/proc
2477 EOF
2480 ########################################################################
2481 ######################### END OF NEW FUNCTIONS #########################
2482 ########################################################################
2484 # List packages providing a virtual package.
2485 whoprovide()
2487 local i;
2488 for i in $(fgrep -l PROVIDE $WOK/*/receipt); do
2489 . $i
2490 case " $PROVIDE " in
2491 *\ $1\ *|*\ $1:*) echo $(basename $(dirname $i));;
2492 esac
2493 done
2496 ########################################################################
2497 # TAZWOK COMMANDS
2498 ########################
2500 case "$COMMAND" in
2501 stats)
2502 # Tazwok general statistics from the wok config file.
2504 get_tazwok_config
2505 echo -e "\n\033[1mTazwok configuration statistics\033[0m
2506 ================================================================================
2507 Wok directory : $WOK
2508 Packages repository : $PACKAGES_REPOSITORY
2509 Incoming repository : $INCOMING_REPOSITORY
2510 Sources repository : $SOURCES_REPOSITORY
2511 Log directory : $LOCAL_REPOSITORY/log
2512 Packages in the wok : `ls -1 $WOK | wc -l`
2513 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2514 Incoming packages : `ls -1 $INCOMING_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2515 ================================================================================\n"
2516 ;;
2517 edit)
2518 get_tazwok_config
2519 check_for_package_on_cmdline
2520 check_for_receipt
2521 $EDITOR $WOK/$PACKAGE/receipt
2522 ;;
2523 build-depends)
2524 # List dependencies to rebuild wok, or only a package.
2525 get_tazwok_config
2526 report(){ : ; }
2527 if [ ! "$PACKAGE" ] || [ "$PACKAGE" = toolchain ]; then
2528 scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
2529 --look_for=dep --with_dev --with_args
2530 else
2531 check_for_package_on_cmdline
2532 scan $PACKAGE --look_for=bdep --with_dev
2533 fi
2534 ;;
2535 gen-cooklist)
2536 check_root
2537 get_options_list="pkg"
2538 get_tazwok_config
2539 report(){ : ; }
2540 if ! [ "$pkg" ]; then
2541 if [ ! "$LIST" ] || [ "$LIST" = toolchain ]; then
2542 pkg="$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA"
2543 else
2544 check_for_list
2545 fi
2546 fi
2547 gen_cook_list
2548 ;;
2549 check-depends)
2550 # Check package depends /!\.
2551 get_tazwok_config
2552 echo ""
2553 echo -e "\033[1mCheck every receipt for DEPENDS - doesn't scan ELF files\033[0m
2554 ================================================================================"
2555 TMPDIR=/tmp/tazwok$$
2556 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
2558 # Build ALL_DEPENDS variable.
2559 scan_dep()
2561 local i
2562 ALL_DEPENDS="$ALL_DEPENDS$PACKAGE "
2563 for i in $DEPENDS $SUGGESTED ; do
2564 case " $ALL_DEPENDS " in
2565 *\ $i\ *) continue;;
2566 esac
2567 [ -d $WOK/$i ] || {
2568 ALL_DEPENDS="$ALL_DEPENDS$i "
2569 continue
2571 DEPENDS=""
2572 SUGGESTED=""
2573 . $WOK/$i/receipt
2574 scan_dep
2575 done
2578 # Check for ELF file.
2579 is_elf()
2581 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
2584 # Print shared library dependencies.
2585 ldd()
2587 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
2590 mkdir $TMPDIR
2591 cd $TMPDIR
2592 for i in $LOCALSTATE/files.list.lzma \
2593 $LOCALSTATE/undigest/*/files.list.lzma ; do
2594 [ -f $i ] && lzma d $i -so >> files.list
2595 done
2596 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
2597 tazpkg extract $pkg > /dev/null 2>&1
2598 . */receipt
2599 ALL_DEPENDS="$DEFAULT_DEPENDS "
2600 scan_dep
2601 find */fs -type f | while read file ; do
2602 is_elf $file || continue
2603 case "$file" in
2604 *.o|*.ko|*.ko.gz) continue;;
2605 esac
2606 ldd $file | while read lib rem; do
2607 case "$lib" in
2608 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
2609 continue;;
2610 esac
2611 for dep in $(fgrep $lib files.list | cut -d: -f1); do
2612 case " $ALL_DEPENDS " in
2613 *\ $dep\ *) continue 2;;
2614 esac
2615 for vdep in $(fgrep $dep $LOCALSTATE/packages.equiv | cut -d= -f1); do
2616 case " $ALL_DEPENDS " in
2617 *\ $vdep\ *) continue 3;;
2618 esac
2619 done
2620 done
2621 [ -n "$dep" ] || dep="UNKNOWN"
2622 echo "$(basename $pkg): ${file#*fs} depends on package $dep for the shared library $lib"
2623 done
2624 done
2625 rm -rf */
2626 done
2627 cd /tmp
2628 rm -rf $TMPDIR
2629 ;;
2630 check)
2631 # Check wok consistency.
2632 get_tazwok_config
2633 echo ""
2634 echo -e "\033[1mWok and packages checking\033[0m
2635 ================================================================================"
2636 cd $WOK
2637 for pkg in $(ls)
2638 do
2639 [ -f $pkg/receipt ] || continue
2640 RECEIPT= $pkg/receipt
2641 source_receipt
2642 [ "$PACKAGE" = "$pkg" ] || echo "Package $PACKAGE should be $pkg" >&2
2643 [ -n "$VERSION" ] || echo "Package $PACKAGE has no VERSION" >&2
2644 [ -n "$PACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded PACKED_SIZE" >&2
2645 [ -n "$UNPACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded UNPACKED_SIZE" >&2
2646 [ -n "$EXTRAVERSION" ] && echo "Package $PACKAGE has hardcoded EXTRAVERSION" >&2
2647 if [ -n "$WANTED" ]; then
2648 if [ ! -f $WANTED/receipt ]; then
2649 echo "Package $PACKAGE wants unknown $WANTED package" >&2
2650 else
2651 BASEVERSION=$(. $WANTED/receipt ; echo $VERSION)
2652 if [ "$VERSION" = "$WANTED" ]; then
2653 # BASEVERSION is computed in receipt
2654 fgrep -q '_pkg=' $pkg/receipt &&
2655 BASEVERSION=$VERSION
2656 fi
2657 if [ "$VERSION" != "$BASEVERSION" ]; then
2658 echo "Package $PACKAGE ($VERSION) wants $WANTED ($BASEVERSION)" >&2
2659 fi
2660 fi
2661 fi
2663 if [ -n "$CATEGORY" ]; then
2664 case " $(echo $CATEGORIES) " in
2665 *\ $CATEGORY\ *);;
2666 *) echo "Package $PACKAGE has an invalid CATEGORY" >&2;;
2667 esac
2668 else
2669 echo"Package $PACKAGE has no CATEGORY" >&2
2670 fi
2671 [ -n "$SHORT_DESC" ] || echo "Package $PACKAGE has no SHORT_DESC" >&2
2672 [ -n "$MAINTAINER" ] || echo "Package $PACKAGE has no MAINTAINER" >&2
2673 case "$WGET_URL" in
2674 ftp*|http*) busybox wget -s $WGET_URL 2> /dev/null ||
2675 echo "Package $PACKAGE has a wrong WGET_URL" >&2;;
2676 '') ;;
2677 *) echo "Package $PACKAGE has an invalid WGET_URL" >&2;;
2678 esac
2679 case "$WEB_SITE" in
2680 ftp*|http*);;
2681 '') echo "Package $PACKAGE has no WEB_SITE" >&2;;
2682 *) echo "Package $PACKAGE has an invalid WEB_SITE" >&2;;
2683 esac
2684 case "$MAINTAINER" in
2685 *\<*|*\>*) echo "Package $PACKAGE has an invalid MAINTAINER: $MAINTAINER" >&2;;
2686 esac
2687 case "$MAINTAINER" in
2688 *@*);;
2689 *) echo "Package $PACKAGE MAINTAINER is not an email address" >&2;;
2690 esac
2691 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2692 for i in $DEPENDS; do
2693 [ -d $i ] && continue
2694 [ -n "$(whoprovide $i)" ] && continue
2695 echo -e "$MSG $i"
2696 MSG=""
2697 done
2698 MSG="Missing build dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2699 for i in $BUILD_DEPENDS; do
2700 [ -d $i ] && continue
2701 [ -n "$(whoprovide $i)" ] && continue
2702 echo -e "$MSG $i"
2703 MSG=""
2704 done
2705 MSG="Dependency loop between $PACKAGE and :\n"
2706 ALL_DEPS=""
2707 check_for_deps_loop $PACKAGE $DEPENDS
2708 [ -d $WOK/$pkg/taz ] && for i in $BUILD_DEPENDS; do
2709 [ $WOK/$pkg/taz -nt $INSTALLED/$i/files.list ] && continue
2710 echo "$pkg should be rebuilt after $i installation"
2711 done
2712 done
2713 ;;
2714 list)
2715 # List packages in wok directory. User can specify a category.
2717 get_tazwok_config
2718 if [ "$2" = "category" ]; then
2719 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
2720 exit 0
2721 fi
2722 # Check for an asked category.
2723 if [ -n "$2" ]; then
2724 ASKED_CATEGORY=$2
2725 echo ""
2726 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
2727 echo "================================================================================"
2728 for pkg in $WOK/*
2729 do
2730 [ ! -f $pkg/receipt ] && continue
2731 . $pkg/receipt
2732 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
2733 echo -n "$PACKAGE"
2734 echo -e "\033[28G $VERSION"
2735 packages=$(($packages+1))
2736 fi
2737 done
2738 echo "================================================================================"
2739 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
2740 else
2741 # By default list all packages and version.
2742 echo ""
2743 echo -e "\033[1mList of packages in the wok\033[0m"
2744 echo "================================================================================"
2745 for pkg in $WOK/*
2746 do
2747 [ ! -f $pkg/receipt ] && continue
2748 . $pkg/receipt
2749 echo -n "$PACKAGE"
2750 echo -en "\033[28G $VERSION"
2751 echo -e "\033[42G $CATEGORY"
2752 packages=$(($packages+1))
2753 done
2754 echo "================================================================================"
2755 echo -e "$packages packages available in the wok.\n"
2756 fi
2757 ;;
2758 info)
2759 # Information about a package.
2761 get_tazwok_config
2762 check_for_package_on_cmdline
2763 check_for_receipt
2764 . $WOK/$PACKAGE/receipt
2765 echo ""
2766 echo -e "\033[1mTazwok package information\033[0m
2767 ================================================================================
2768 Package : $PACKAGE
2769 Version : $VERSION
2770 Category : $CATEGORY
2771 Short desc : $SHORT_DESC
2772 Maintainer : $MAINTAINER"
2773 if [ ! "$WEB_SITE" = "" ]; then
2774 echo "Web site : $WEB_SITE"
2775 fi
2776 if [ ! "$DEPENDS" = "" ]; then
2777 echo "Depends : $DEPENDS"
2778 fi
2779 if [ ! "$WANTED" = "" ]; then
2780 echo "Wanted src : $WANTED"
2781 fi
2782 echo "================================================================================"
2783 echo ""
2784 ;;
2785 check-log)
2786 # We just cat the file log to view process info.
2788 get_tazwok_config
2789 if [ ! -f "$LOG" ]; then
2790 echo -e "\nNo process log found. The package is probably not cooked.\n" >&2
2791 exit 1
2792 else
2793 echo ""
2794 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
2795 echo "================================================================================"
2796 cat $LOG
2797 echo "================================================================================"
2798 echo ""
2799 if [ -s "$WOK/$PACKAGE/warning.txt" ]; then
2800 echo -e "\033[1mCook warning(s) for :\033[0m $PACKAGE"
2801 echo "================================================================================"
2802 cat "$WOK/$PACKAGE/warning.txt"
2803 echo "================================================================================"
2804 echo ""
2805 fi
2806 fi
2807 ;;
2808 search)
2809 # Search for a package by pattern or name.
2811 get_tazwok_config
2812 if [ -z "$2" ]; then
2813 echo -e "\nPlease specify a pattern or a package name to search." >&2
2814 echo -e "Example : 'tazwok search gcc'.\n" >&2
2815 exit 1
2816 fi
2817 echo ""
2818 echo -e "\033[1mSearch result for :\033[0m $2"
2819 echo "================================================================================"
2820 list=`ls -1 $WOK | fgrep $2`
2821 for pkg in $list
2822 do
2823 . $WOK/$pkg/receipt
2824 echo -n "$PACKAGE "
2825 echo -en "\033[24G $VERSION"
2826 echo -e "\033[42G $CATEGORY"
2827 packages=$(($PACKAGEs+1))
2828 done
2829 echo "================================================================================"
2830 echo "$packages packages found for : $2"
2831 echo ""
2832 ;;
2833 compile)
2834 # Configure and make a package with the receipt.
2836 get_tazwok_config
2837 source_lib report
2838 report start
2839 compile_package
2840 ;;
2841 genpkg)
2842 # Generate a package.
2844 get_tazwok_config
2845 source_lib report
2846 report start
2847 gen_package
2848 ;;
2849 cook)
2850 # Compile and generate a package. Just execute tazwok with
2851 # the good commands.
2853 check_root
2854 get_tazwok_config
2855 source_lib report
2856 report start
2857 db_md5=$(md5sum $dep_db $wan_db)
2858 update_wan_db
2859 check_for_commit
2860 sort -o $dep_db $dep_db
2861 sort -o $wan_db $wan_db
2862 if [ "$db_md5" != "$(md5sum $dep_db $wan_db)" ]; then
2863 grep -q "^#" $cookorder || sed 1i"#PlanSort" -i $cookorder
2864 fi
2865 cook
2866 ;;
2867 sort-cooklist)
2868 check_root
2869 get_tazwok_config
2870 check_for_list
2871 report(){ : ; }
2872 # When using sort-cooklist, the script should behave as for gen-cooklist
2873 # The only difference between these two is where the output is sent.
2874 COMMAND=gen-cooklist
2875 gen_cook_list
2876 cp -af $tmp/cooklist $LIST
2877 ;;
2878 cook-list)
2879 # Cook all packages listed in a file or in default cooklist.
2880 check_root
2881 get_options_list="pkg forced"
2882 get_tazwok_config
2883 source_lib report
2884 report start
2885 if ! [ "$pkg" ]; then
2886 [ "$LIST" ] && check_for_list
2887 fi
2888 gen_cook_list
2889 cook_list
2890 ;;
2891 clean)
2892 # Clean up a package work directory + those which want it.
2894 get_tazwok_config
2895 check_for_package_on_cmdline
2896 check_for_receipt
2897 source_lib report
2898 report start
2899 . $RECEIPT
2900 clean
2901 ;;
2902 gen-clean-wok)
2903 # Generate a clean wok from the current wok by copying all receipts
2904 # and stuff directory.
2906 get_tazwok_config
2907 source_lib report
2908 report start
2909 if [ -z "$ARG" ]; then
2910 echo -e "\nPlease specify the destination for the new clean wok.\n" >&2
2911 exit 1
2912 else
2913 dest=$ARG
2914 mkdir -p $dest
2915 fi
2916 report step "Creating clean wok in : $dest"
2917 for pkg in `ls -1 $WOK`
2918 do
2919 copy_cooking_stuff $WOK $pkg $dest
2920 done
2921 [ -d $WOK/.hg ] && cp -a $WOK/.hg $dest
2922 report end-step
2923 echo "Packages cleaned : `ls -1 $dest | wc -l`"
2924 echo ""
2925 ;;
2926 clean-wok)
2927 # Clean all packages in the work directory.
2929 get_tazwok_config
2930 source_lib report
2931 report start
2932 report step "Cleaning wok"
2933 for PACKAGE in `ls -1 $WOK`
2934 do
2935 set_common_path
2936 source_receipt
2937 clean
2938 done
2939 echo "`ls -1 $WOK | wc -l` packages cleaned."
2940 ;;
2941 clean-src)
2942 # Remove tarball unrelated to wok receipts from src repo.
2943 check_root
2944 get_options_list="forced"
2945 get_tazwok_config
2946 cd $SOURCES_REPOSITORY
2947 echo -n "Checking $SOURCES_REPOSITORY..."
2948 for TARBALL in *; do
2949 [ "$TARBALL" = sources.list ] && continue
2950 grep -q $'\t'$TARBALL$ $SOURCES_REPOSITORY/sources.list || \
2951 echo $TARBALL >> $tmp/obsolete
2952 done
2953 status
2954 if ! [ -f $tmp/obsolete ]; then
2955 echo "No sources need to be removed."
2956 exit 1
2957 fi
2958 echo ""
2959 echo -e "\033[1mObsolete/unrelated-to-wok sources :\033[0m"
2960 horizontal_line
2961 cat $tmp/obsolete
2962 horizontal_line
2963 echo "$(wc -l $tmp/obsolete | cut -f1 -d' ') tarballs to remove."
2964 echo ""
2965 echo -n "Please confirm before removing (type uppercase YES): "
2966 read answer
2967 if [ "$answer" = YES ]; then
2968 echo -n "Removing old sources..."
2969 cat $tmp/obsolete | while read i; do
2970 rm -f $SOURCES_REPOSITORY/$i
2971 done
2972 status
2973 fi
2974 ;;
2975 gen-list)
2976 get_tazwok_config
2977 if [ "$2" ]; then
2978 if [ -d "$2" ]; then
2979 pkg_repository=$2
2980 else
2981 echo -e "\nUnable to find directory : $2\n" >&2
2982 exit 1
2983 fi
2984 fi
2986 source_lib report
2987 report start
2988 if [ "$pkg_repository" ]; then
2989 gen_packages_db
2990 else
2991 pkg_repository=$PACKAGES_REPOSITORY && gen_packages_db
2992 pkg_repository=$INCOMING_REPOSITORY && gen_packages_db
2993 fi
2994 ;;
2995 check-list)
2996 # The directory to move into by default is the repository,
2997 # if $2 is not empty cd into $2.
2999 get_tazwok_config
3000 if [ "$2" ]; then
3001 if [ -d "$2" ]; then
3002 pkg_repository=$2
3003 else
3004 echo -e "\nUnable to find directory : $2\n" >&2
3005 exit 1
3006 fi
3007 fi
3009 source_lib report
3010 report start
3011 if [ "$pkg_repository" ]; then
3012 update_packages_db
3013 else
3014 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
3015 pkg_repository=$INCOMING_REPOSITORY && update_packages_db
3016 fi
3017 ;;
3018 new-tree)
3019 # Just create a few directories and generate an empty receipt to prepare
3020 # the creation of a new package.
3022 get_tazwok_config
3023 check_for_package_on_cmdline
3024 clean_wok=$LOCAL_REPOSITORY/clean-wok
3025 if [ -d $clean_wok/$PACKAGE ]; then
3026 echo -e "\n$PACKAGE package tree already exists.\n" >&2
3027 exit 1
3028 fi
3029 echo "Creating : $clean_wok/$PACKAGE"
3030 mkdir $clean_wok/$PACKAGE
3031 cd $clean_wok/$PACKAGE
3032 echo -n "Preparing the receipt..."
3034 # Default receipt begin.
3036 echo "# SliTaz package receipt." > receipt
3037 echo "" >> receipt
3038 echo "PACKAGE=\"$PACKAGE\"" >> receipt
3039 # Finish the empty receipt.
3040 cat >> receipt << "EOF"
3041 VERSION=""
3042 CATEGORY=""
3043 SHORT_DESC=""
3044 MAINTAINER=""
3045 DEPENDS=""
3046 TARBALL="$PACKAGE-$VERSION.tar.gz"
3047 WEB_SITE=""
3048 WGET_URL=""
3050 # Rules to configure and make the package.
3051 compile_rules()
3053 cd $src
3054 ./configure && make && make install
3057 # Rules to gen a SliTaz package suitable for Tazpkg.
3058 genpkg_rules()
3060 mkdir -p $fs/usr
3061 cp -a $_pkg/usr/bin $fs/usr
3064 EOF
3066 # Default receipt end.
3068 status
3069 # Interactive mode, asking and seding.
3070 if [ "$3" = "--interactive" ]; then
3071 echo "Entering interactive mode..."
3072 echo "================================================================================"
3073 echo "Package : $PACKAGE"
3074 # Version.
3075 echo -n "Version : " ; read anser
3076 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
3077 # Category.
3078 echo -n "Category : " ; read anser
3079 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
3080 # Short description.
3081 echo -n "Short desc : " ; read anser
3082 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
3083 # Maintainer.
3084 echo -n "Maintainer : " ; read anser
3085 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
3086 # Web site.
3087 echo -n "Web site : " ; read anser
3088 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
3089 echo ""
3090 # Wget URL.
3091 echo "Wget URL to download source tarball."
3092 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
3093 echo -n "Wget url : " ; read anser
3094 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
3095 # Ask for a stuff dir.
3096 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
3097 if [ "$anser" = "y" ]; then
3098 echo -n "Creating the stuff directory..."
3099 mkdir stuff && status
3100 fi
3101 # Ask for a description file.
3102 echo -n "Are you going to write a description ? (y/N) : " ; read anser
3103 if [ "$anser" = "y" ]; then
3104 echo -n "Creating the description.txt file..."
3105 echo "" > description.txt && status
3106 fi
3107 echo "================================================================================"
3108 echo ""
3109 fi
3110 ;;
3111 remove)
3112 # Remove a package from the wok.
3114 get_tazwok_config
3115 check_for_package_on_cmdline
3116 echo ""
3117 echo -n "Please confirm deletion (y/N) : "; read anser
3118 if [ "$anser" = "y" ]; then
3119 echo -n "Removing $PACKAGE..."
3120 rm -rf $WOK/$PACKAGE && status
3121 echo ""
3122 fi
3123 ;;
3124 update-wok)
3125 # Pull and update a Hg wok.
3126 get_options_list="local"
3127 get_tazwok_config
3128 source_lib report
3129 report start
3130 clean_wok=$LOCAL_REPOSITORY/clean-wok
3131 cd $clean_wok
3132 if ! [ "$local" ]; then
3133 if [ "$WOK_UPDATE_METHOD" = hg ]; then
3134 if ! [ -f "$INSTALLED/mercurial/receipt" ]; then
3136 # Auto-install only if we are in a cook chroot.
3137 if [ -x /usr/bin/clean-chroot ]; then
3138 tazpkg get-install mercurial
3139 else
3140 echo "" >&2
3141 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
3142 echo "">&2
3143 exit 1
3144 fi
3145 fi
3147 report step "Getting wok changes using hg"
3148 if [ -d .hg ]; then
3149 hg pull -u || exit 1
3150 else
3151 hg clone $HG_WOK . || exit 1
3152 fi
3153 report end-step
3154 [ -x /usr/bin/clean-chroot ] && clean-chroot
3155 else
3156 report step "Getting wok changes using tarball"
3157 { mkdir .tmp && cd .tmp
3158 wget "$TARBALL_WOK" &&
3159 case $TARBALL_WOK in
3160 *bz2) tar xjf *.bz2 -C wok; rm *.bz2;;
3161 *lzma) unlzma -c *.lzma | tar xf - -C wok; rm *.lzma ;;
3162 *gz) tar xzf *.gz -C wok; rm*.gz ;;
3163 esac &&
3164 rm -r $(ls -d $clean_wok/*) &&
3165 cp -a wok/* $clean_wok &&
3166 cd .. &&
3167 rm -r .tmp
3168 } || { echo "That's not cool: it fails!" >&2
3169 report end-step
3170 exit 1; }
3171 report end-step
3172 fi
3173 fi
3174 report step "Appending changes to wok"
3176 # Handle removed files/dir.
3177 cd $WOK
3178 for dir in *; do
3179 [ -d "$clean_wok/$dir" ] || rm -rf $dir
3180 done
3181 for file in */receipt */description.txt; do
3182 [ -f "$clean_wok/$file" ] || rm -rf $file
3183 done
3184 for i in $(find */stuff 2>/dev/null); do
3185 [ -e "$clean_wok/$i" ] || rm -rf $i
3186 done
3188 cp -a $clean_wok/* $WOK
3189 report end-step
3190 ;;
3191 maintainers)
3192 get_tazwok_config
3193 echo ""
3194 echo "List of maintainers for: $WOK"
3195 echo "================================================================================"
3196 touch /tmp/slitaz-maintainers
3197 for pkg in $WOK/*
3198 do
3199 . $pkg/receipt
3200 if ! fgrep -q "$MAINTAINER" /tmp/slitaz-maintainers; then
3201 echo "$MAINTAINER" >> /tmp/slitaz-maintainers
3202 echo "$MAINTAINER"
3203 fi
3204 done
3205 echo "================================================================================"
3206 echo "Maintainers: `cat /tmp/slitaz-maintainers | wc -l`"
3207 echo ""
3208 # Remove tmp files
3209 rm -f /tmp/slitaz-maintainers
3210 ;;
3211 maintained-by)
3212 # Search for packages maintained by a contributor.
3213 get_tazwok_config
3214 if [ ! -n "$2" ]; then
3215 echo "Specify a name or email of a maintainer." >&2
3216 exit 1
3217 fi
3218 echo "Maintainer packages"
3219 echo "================================================================================"
3220 for pkg in $WOK/*
3221 do
3222 . $pkg/receipt
3223 if echo "$MAINTAINER" | fgrep -q "$2"; then
3224 echo "$PACKAGE"
3225 packages=$(($PACKAGEs+1))
3226 fi
3227 done
3228 echo "================================================================================"
3229 echo "Packages maintained by $2: $PACKAGEs"
3230 echo ""
3231 ;;
3232 tags)
3233 get_tazwok_config
3234 echo -e "\n\033[1mTags list :\033[0m"
3235 horizontal_line
3236 cd $WOK
3237 for i in */receipt; do
3238 unset TAGS
3239 source $i
3240 for t in $TAGS; do
3241 grep -q ^$t$ $tmp/tags && continue
3242 echo $t | tee -a $tmp/tags
3243 done
3244 done
3245 horizontal_line
3246 echo "$(wc -l $tmp/tags | cut -f1 -d ' ') tags listed."
3247 ;;
3248 check-src)
3249 # Verify if upstream package is still available.
3251 get_tazwok_config
3252 check_for_package_on_cmdline
3253 check_for_receipt
3254 source_receipt
3255 check_src()
3257 for url in $@; do
3258 busybox wget -s $url 2>/dev/null && break
3259 done
3261 if [ "$WGET_URL" ];then
3262 echo -n "$PACKAGE : "
3263 check_src $WGET_URL
3264 status
3265 else
3266 echo "No tarball to check for $PACKAGE"
3267 fi
3268 ;;
3269 gen-src)
3270 get_tazwok_config
3271 if [ "$2" ]; then
3272 if [ -d "$2" ]; then
3273 src_repository=$2
3274 else
3275 echo -e "\nUnable to find directory : $2\n" >&2
3276 exit 1
3277 fi
3278 fi
3279 echo -n "Rebuilding sources.list file"
3280 [ $src_repository ] || src_repository="$SOURCES_REPOSITORY"
3281 gen_sources_list $src_repository
3282 status
3283 ;;
3284 get-src)
3285 check_root
3286 get_options_list="target nounpack"
3287 get_tazwok_config
3288 check_for_package_on_cmdline
3289 check_for_receipt
3290 source_receipt
3291 if [ "$WGET_URL" ];then
3292 source_lib report
3293 report start
3294 check_for_tarball
3295 else
3296 echo "No tarball to download for $PACKAGE"
3297 fi
3298 ;;
3299 check-commit)
3300 check_root
3301 get_options_list="missing forced"
3302 get_tazwok_config
3303 source_lib report
3304 report start
3305 if [ "$forced" ]; then
3306 rm -f $WOK/*/md5
3307 unset forced
3308 fi
3309 if [ "$missing" ]; then
3310 pkg=$(ls -1 $WOK)
3311 else
3312 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3313 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3314 } | sort -u)"
3315 fi
3316 gen_cook_list
3317 ;;
3318 cook-commit)
3319 check_root
3320 get_options_list="missing forced"
3321 get_tazwok_config
3322 source_lib report
3323 report start
3324 if [ "$forced" ]; then
3325 rm -f $WOK/*/md5
3326 unset forced
3327 fi
3328 if [ "$missing" ]; then
3329 pkg=$(ls -1 $WOK)
3330 else
3331 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3332 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3333 } | sort -u)"
3334 fi
3335 gen_cook_list
3336 cook_list
3337 ;;
3338 cook-all)
3339 check_root
3340 get_options_list="forced missing"
3341 get_tazwok_config
3342 source_lib report
3343 report start
3344 if [ "$missing" ]; then
3345 pkg=$(ls -1 $WOK)
3346 else
3347 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3348 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3349 } | sort -u)"
3350 fi
3351 gen_cook_list
3352 cook_list
3353 ;;
3354 gen-wok-db)
3355 check_root
3356 get_tazwok_config
3357 source_lib report
3358 report start
3359 gen_wok_db
3360 ;;
3361 report)
3362 get_tazwok_config
3363 cd $PACKAGES_REPOSITORY
3364 if [ "$2" ]; then
3365 case $2 in
3366 commit|cooklist|incoming|broken|blocked)
3367 show="$2"
3368 ;;
3369 *)
3370 echo "usage : tazwok report [commit|cooklist|incoming|broken|blocked]" >&2
3371 exit 1
3372 ;;
3373 esac
3374 else
3375 show="commit cooklist incoming broken blocked"
3376 fi
3377 for i in $show; do
3378 if [ -s $i ]; then
3379 echo ""
3380 echo -e "\033[1m$i\033[0m"
3381 echo "================================================================================"
3382 cat $i
3383 echo "================================================================================"
3384 echo ""
3385 fi
3386 done
3387 ;;
3388 check-incoming)
3389 check_root
3390 get_options_list="forced"
3391 get_tazwok_config
3392 source_lib report
3393 report start
3394 [ -f $LOCAL_RESOSITORY/incoming ] && rm [ -f $LOCAL_REPOSITORY/incoming ]
3395 report step "Checking $INCOMING_REPOSITORY"
3396 report open-bloc
3397 [ -f $LOCAL_REPOSITORY/log/incoming.html ] && rm $LOCAL_REPOSITORY/log/incoming.html
3398 report sublog $LOCAL_REPOSITORY/log/incoming.html
3399 echo "incoming" > $LOCAL_REPOSITORY/log/package
3400 check_for_incoming
3401 report end-sublog
3402 report close-bloc
3403 ;;
3404 configure-chroot)
3405 check_root
3406 get_tazwok_config
3407 if [ -f /usr/bin/tazchroot ]; then
3408 cd $LOCAL_REPOSITORY
3409 configure_tazchroot
3410 else
3411 echo "The package tazchroot needs to be installed" >&2
3412 exit 1
3413 fi
3414 ;;
3415 chroot)
3416 check_root
3417 get_tazwok_config
3418 # Merge this and the other chroot function ?.
3419 if [ -f /usr/bin/tazchroot ]; then
3420 cd $LOCAL_REPOSITORY
3421 [ ! -f tazchroot.conf ] && configure_tazchroot
3422 tazchroot
3423 else
3424 echo "The package tazchroot needs to be installed" >&2
3425 exit 1
3426 fi
3427 ;;
3428 cook-toolchain)
3429 check_root
3430 get_tazwok_config
3431 echo -n "" > $PACKAGES_REPOSITORY/broken
3432 if [ -f /usr/bin/tazchroot ]; then
3433 cd $LOCAL_REPOSITORY
3434 [ -f tazchroot.conf ] || configure_tazchroot
3436 # Plan to recook all packages.
3437 if tazchroot cook-toolchain; then
3438 source_lib report
3439 report start
3440 pkg="$(grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt \
3441 $INCOMING_REPOSITORY/packages.txt | sort -u)"
3442 forced=yes
3443 gen_cook_list
3444 fi
3446 # Remove chroot where toolchain has been cooked.
3447 source $LOCAL_REPOSITORY/tazchroot.conf
3448 rm -r $LOCAL_REPOSITORY/chroot
3450 else
3451 echo -e "\nThe package tazchroot needs to be installed.\n" >&2
3452 exit 1
3453 fi
3454 ;;
3455 webserver)
3456 check_root
3457 get_tazwok_config
3458 if [ "$ARG" = on ]; then
3459 if [ "$WEBSERVER" ] && [ -f "$WEBSERVER/repositories.list" ] && \
3460 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3461 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3462 exit 1
3463 fi
3464 if ! [ -f $LOCAL_REPOSITORY/tazchroot.conf ]; then
3465 tazwok configure-chroot ${undigest:+--undigest=$undigest} --SLITAZ_VERSION=$SLITAZ_VERSION --SLITAZ_DIR=$SLITAZ_DIR
3466 fi
3467 for pkg in php lighttpd; do
3468 [ -d $INSTALLED/$pkg ] || missing="$missing $pkg"
3469 done
3470 if [ "$missing" ]; then
3471 echo "You need to install these packages to start webserver: $missing." >&2
3472 exit 1
3473 fi
3474 if [ ! -f "$LOCAL_REPOSITORY/tazwok.conf" ]; then
3475 echo "Copying /etc/slitaz/tazwok.conf to $LOCAL_REPOSITORY/tazwok.conf: webserver is configured repository-by-repository."
3476 cp /etc/slitaz/tazwok.conf $LOCAL_REPOSITORY
3477 fi
3478 if ! [ "$WEBSERVER" ]; then
3479 echo -n "Where to store php pages (default: /var/www/vhosts/bb)? "
3480 read WEBSERVER
3481 [ "$WEBSERVER" ] || WEBSERVER="/var/www/vhosts/bb"
3482 fi
3483 if [ -f "$WEBSERVER/repositories.list" ] && \
3484 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3485 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3486 exit 1
3487 fi
3488 mkdir -p $WEBSERVER
3489 echo "${undigest:-$SLITAZ_VERSION}" >> $WEBSERVER/repositories.list
3490 for file in index.php log.php download.php; do
3491 [ -f "$WEBSERVER/$file" ] || ln -s /usr/share/slitaz/web-bb/$file $WEBSERVER
3492 done
3493 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3494 ln -s $dir $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3495 done
3496 source $LOCAL_REPOSITORY/tazchroot.conf
3497 echo "<?php
3499 // Web interface configuration
3501 \$version=\"${undigest:-$SLITAZ_VERSION}\";
3502 \$chroot=\"$chroot_dir\";
3503 \$lockfile=\"\$chroot/proc/1/status\";
3504 \$db_dir=\"$PACKAGES_REPOSITORY\";
3505 \$log_dir=\"$LOCAL_REPOSITORY/log\";
3506 \$packages=\"$PACKAGES_REPOSITORY\";
3507 \$incoming=\"$INCOMING_REPOSITORY\";
3508 \$wok=\"$WOK\";
3510 ?>" > $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3511 [ -L "$WEBSERVER/web" ] || ln -s /usr/share/slitaz/web $WEBSERVER
3512 echo "WEBSERVER=\"$WEBSERVER\"" >> $LOCAL_REPOSITORY/tazwok.conf
3513 if [ -L "$WEBSERVER/conf.php" ]; then
3514 echo "Do you want to make ${undigest:-$SLITAZ_VERSION} the default page (y/N) ? "
3515 read answer
3516 if [ "$answer" = y ]; then
3517 rm $WEBSERVER/conf.php
3518 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3519 fi
3520 else
3521 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3522 fi
3523 elif [ "$ARG" = off ]; then
3524 if ! [ "$WEBSERVER" ]; then
3525 echo "No webserver running for ${undigest:-$SLITAZ_VERSION}" >&2
3526 exit 1
3527 fi
3528 sed '/^WEBSERVER/d' -i $LOCAL_REPOSITORY/tazwok.conf
3529 sed "/^${undigest:-$SLITAZ_VERSION}$/d" -i $WEBSERVER/repositories.list
3530 rm $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3531 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3532 rm $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3533 done
3534 if ! [ -s "$WEBSERVER/repositories.list" ]; then
3535 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"
3536 rm $WEBSERVER/conf.php
3537 elif [ "$(readlink $WEBSERVER/conf.php)" = "$WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php" ]; then
3538 echo "${undigest:-$SLITAZ_VERSION} was the default version to use; switched to : $(sed 1!d $WEBSERVER/repositories.list)"
3539 rm $WEBSERVER/conf.php
3540 ln -s $WEBSERVER/conf-$(sed 1!d $WEBSERVER/repositories.list).php $WEBSERVER/conf.php
3541 fi
3542 else
3543 echo "Usage: tazwok webserver on/off" >&2
3544 exit 1
3545 fi
3546 ;;
3547 block)
3548 # Add a pkg name to the list of blocked packages.
3549 get_tazwok_config
3550 check_root
3551 check_for_package_on_cmdline
3552 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3553 echo "Can't find $PACKAGE in wok." >&2
3554 echo ""
3555 exit 1
3556 fi
3557 echo ""
3558 if grep -qs "^$PACKAGE$" $blocked; then
3559 echo "$PACKAGE is already in the blocked packages list." >&2
3560 echo ""
3561 exit 1
3562 else
3563 echo -n "Adding $PACKAGE to : $blocked... "
3564 echo "$PACKAGE" >> $blocked
3565 status
3566 if grep -q "^$PACKAGE$" $cooklist; then
3567 echo -n "Removing $PACKAGE from : $cooklist... "
3568 sed -i /"^$PACKAGE$"/d $cooklist
3569 status
3570 fi
3571 fi
3572 echo "" ;;
3573 unblock)
3574 # Remove a pkg name from the list of blocked packages.
3575 get_tazwok_config
3576 check_root
3577 check_for_package_on_cmdline
3578 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3579 echo "Can't find $PACKAGE in wok." >&2
3580 echo ""
3581 exit 1
3582 fi
3583 echo ""
3584 if grep -qs "^$PACKAGE$" $blocked; then
3585 echo -n "Removing $PACKAGE from : $blocked... "
3586 sed -i /"^$PACKAGE$"/d $blocked
3587 sed -i '/^$/d' $blocked
3588 status
3589 else
3590 echo "$PACKAGE is not in the blocked packages list." >&2
3591 echo ""
3592 exit 1
3593 fi
3594 echo "" ;;
3595 usage|*)
3596 # Print usage also for all unknown commands.
3598 usage
3599 ;;
3600 esac
3602 # If a cook command has been used, refresh ID of the repository to avoid
3603 # useless upgrade at next cook command.
3604 case $COMMAND in
3605 cook*)
3606 for repo in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY \
3607 $( [ "$undigest" -a ! "$ref_USE_ONLINE_PKG" ] && echo $ref_PACKAGES_REPOSITORY ); do
3608 [ -f $repo/ID ] || continue
3609 MIRROR_path=$(grep -l "^$repo$" $LOCALSTATE/mirror $LOCALSTATE/undigest/*/mirror)
3610 LOCALSTATE_path=${MIRROR_path%/mirror}
3611 cp -a $repo/ID $LOCALSTATE_path
3612 done
3613 ;;
3614 esac
3616 report stop 2>/dev/null
3617 exit 0