tazwok view tazwok @ rev 550

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