tazwok view tazwok @ rev 540

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