tazwok view tazwok @ rev 532

Merge bug fixes from default branch.
author Christopher Rogers <slaxemulator@gmail.com>
date Mon May 23 20:45:06 2011 +0000 (2011-05-23)
parents 71bd653c6023 fbb7ef572d32
children ba40ec6eac2b
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 # Create a package tree and build the gziped cpio archive
1100 # to make a SliTaz (.tazpkg) package.
1101 gen_package()
1103 check_root
1104 check_for_package_on_cmdline
1105 check_for_receipt
1106 source_receipt
1108 # May compute VERSION
1109 if grep -q ^get_version $RECEIPT; then
1110 get_version
1111 fi
1112 check_for_wanted
1113 cd $WOK/$PACKAGE
1115 # Remove old Tazwok package files.
1116 [ -d "taz" ] && rm -rf taz
1118 # Create the package tree and set useful variables.
1119 fs=$WOK/$PACKAGE/taz/$PACKAGE-$VERSION/fs
1120 mkdir -p $fs
1122 # Set $src for standard package and $_pkg variables.
1123 set_src_path
1124 set_pkg_path
1126 # Execute genpkg_rules, check package and copy generic files to build
1127 # the package.
1128 report step "Building $PACKAGE with the receipt"
1129 report open-bloc
1130 if look_for_cookopt !fs; then
1132 elif grep -q ^genpkg_rules $RECEIPT; then
1134 # Log process.
1135 echo "executing genpkg_rules" >> $LOG
1136 report step "Executing genpkg_rules"
1137 ( set -e; genpkg_rules ) || { set_pkg_broken; report close-bloc; return 1; }
1138 check_fsh || { set_pkg_broken; report close-bloc; return 1; }
1139 cd $WOK/$PACKAGE
1140 report end-step
1142 # Skip generic files for packages with a WANTED variable
1143 # (dev and split pkgs).
1144 if [ ! "$WANTED" ]; then
1145 copy_generic_files
1146 fi
1147 look_for_cookopt !strip || strip_package
1148 perl_compiled_files_remove
1149 else
1150 echo "No package rules to gen $PACKAGE..." >&2
1151 set_pkg_broken
1152 report close-bloc
1153 return 1
1154 fi
1156 # Copy the receipt and description (if exists) into the binary package tree.
1157 cd $WOK/$PACKAGE
1158 report step "Copying the receipt"
1159 cp receipt taz/$PACKAGE-$VERSION
1160 report end-step
1161 if grep -q ^get_version $RECEIPT; then
1162 report step "Updating version in receipt"
1163 sed -i "s/^VERSION=.*/VERSION=\"$VERSION\"/" \
1164 taz/$PACKAGE-$VERSION/receipt
1165 report end-step
1166 fi
1167 if [ -f "description.txt" ]; then
1168 report step "Copying the description file"
1169 cp description.txt taz/$PACKAGE-$VERSION
1170 report end-step
1171 fi
1173 # Generate md5 of cooking stuff to look for commit later.
1174 gen_cookmd5
1175 echo -e "\n# md5sum of cooking stuff :" >> taz/$PACKAGE-$VERSION/receipt
1176 cat md5 | sed 's/^/# /' >> taz/$PACKAGE-$VERSION/receipt
1178 # Create the files.list by redirecting find output.
1179 report step "Creating the list of files"
1180 cd taz/$PACKAGE-$VERSION
1181 LAST_FILE=""
1182 { find fs -print; echo; } | while read file; do
1183 if [ "$LAST_FILE" ]; then
1184 case "$file" in
1185 $LAST_FILE/*)
1186 case "$(ls -ld "$LAST_FILE")" in
1187 drwxr-xr-x\ *\ root\ *\ root\ *);;
1188 *) echo ${LAST_FILE#fs};;
1189 esac;;
1190 *) echo ${LAST_FILE#fs};;
1191 esac
1192 fi
1193 LAST_FILE="$file"
1194 done > files.list
1196 py_compiled_files_remove
1198 # Next, check if something has changed in lib files.
1199 # Plan to recook each packages which depends on libs
1200 # which doesn't exists anymore.
1201 for rep in $INCOMING_REPOSITORY $PACKAGES_REPOSITORY; do
1202 prev_VERSION=$(get_pkg_version $rep)
1203 [ "$prev_VERSION" ] && pkg_file=$rep/$PACKAGE-$prev_VERSION.tazpkg && break
1204 done
1205 if [ "$pkg_file" ]; then
1206 report step "Looking if reverse depends needs to be refreshed"
1207 get_pkg_files $pkg_file
1208 cd $WOK/$PACKAGE/taz/$PACKAGE-$VERSION
1210 pkg_to_check=$(diff files.list $pkg_files_dir/files.list | \
1211 grep '^-/.*\.so' | while read lib; do
1212 fgrep " ${lib##*/} " $libs_db | cut -f1
1213 done | sort -u)
1215 if [ "$pkg_to_check" ]; then
1216 for rdep in $(scan $PACKAGE --look_for=rdep | use_wanted); do
1217 echo "$pkg_to_check" | grep -q ^$PACKAGE$ || continue
1218 [ "$rdep" = "${WANTED:-$PACKAGE}" ] && continue
1219 grep -q ^$rdep$ $blocked $cooklist && continue
1220 echo "Plan to recook $rdep"
1221 echo $rdep >> $cooklist
1222 regen_cooklist=yes
1223 done
1224 fi
1226 rm -r $pkg_files_dir
1227 unset pkg_file pkg_file_dir pkg_to_check
1228 report end-step
1229 fi
1231 # Update lib_db
1232 libs=$(for file in $(find * -type f); do
1233 [ "$(dd if=$file bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ] || continue
1234 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $PWD/$file
1235 done | { cut -f 1 -d ' ' | tr -d '\t' | sort -u | \
1236 sed -e 's/^linux-gate.so.*$/SLIB/' -e 's~^/lib/ld-.*$~SLIB~' \
1237 -e '/^statically$/d' | tr '\n' ' '; })
1239 sed "/$PACKAGE\t/d" -i $lib_db
1240 if [ "$libs" ]; then
1241 libs=$(echo " $libs" | sed -r 's/( SLIB)+ / /g')
1242 echo -e "$PACKAGE\t$libs" >> $lib_db
1243 sort -o $lib_db $lib_db
1244 fi
1245 unset libs
1247 if [ ! "$EXTRAVERSION" ]; then
1248 case "$PACKAGE" in
1249 linux*);;
1250 *) EXTRAVERSION="$(grep '/lib/modules/.*-slitaz/' files.list |\
1251 head -1 | sed 's|/lib/modules/\(.*\)-slitaz/.*|_\1|')";;
1252 esac
1253 fi
1254 rm -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg 2> /dev/null
1256 report step "Creating md5sum of files"
1257 while read file; do
1258 [ -L "fs$file" ] && continue
1259 [ -f "fs$file" ] || continue
1260 md5sum "fs$file" | sed 's/ fs/ /'
1261 done < files.list > md5sum
1262 report end-step
1263 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
1264 2> /dev/null | awk '{ sz=$1 } END { print sz }')
1266 # Build cpio archives. Find, cpio and gzip the fs, finish by
1267 # removing the fs tree.
1268 # Don't log this because compression always outputs error messages.
1269 find fs -print | cpio -o -H newc | case "$PACKAGE-$COMPRESSION" in
1270 tazpkg-lzma) gzip > fs.cpio.gz;;
1271 *-lzma) lzma e fs.cpio.lzma -si;;
1272 *) gzip > fs.cpio.gz;;
1273 esac && rm -rf fs
1274 PACKED_SIZE=$(du -chs fs.cpio.* receipt files.list md5sum \
1275 description.txt 2> /dev/null | awk '{ sz=$1 } END { print sz }')
1276 report step "Updating receipt sizes"
1277 sed -i '/^PACKED_SIZE/d' receipt
1278 sed -i '/^UNPACKED_SIZE/d' receipt
1279 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1280 sed -i "s/^VERSION=$/VERSION=\"$VERSION\"/" receipt
1281 report end-step
1282 if [ "$EXTRAVERSION" ]; then
1283 report step "Updating receipt EXTRAVERSION"
1284 sed -i s/^EXTRAVERSION.*$// receipt
1285 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
1286 fi
1287 prev_VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
1288 remove_previous_package $INCOMING_REPOSITORY
1289 report step "Creating full cpio archive"
1290 find . -print | cpio -o -H newc > $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1292 # Restore package tree in case we want to browse it.
1293 report step "Restoring original package tree"
1294 { zcat fs.cpio.gz 2> /dev/null || unlzma -c fs.cpio.lzma; } | cpio --quiet -id
1295 rm fs.cpio.* && cd ..
1297 # Save receipts if save_wok is enabled.
1298 [ "$save_wok" ] && copy_cooking_stuff $WOK $PACKAGE $INCOMING_REPOSITORY/wok
1300 # Recook of reverse-depends if package was broken.
1301 if grep -q "^$PACKAGE$" $broken; then
1302 report step "Planning a re-try cook of reverse depends"
1303 sed "/^$PACKAGE$/d" -i $broken
1304 for rdep in $(look_for_rdep); do
1305 grep -q "^$rdep$" $broken || continue
1306 grep -q "^$rdep$" $cooklist && continue
1307 echo "Adding $rdep to the cooklist"
1308 echo $rdep >> $cooklist
1309 regen_cooklist=t
1310 done
1311 report end-step
1312 fi
1313 sed "/^$PACKAGE$/d" -i $commit $cooklist
1315 # Log process.
1316 echo "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg (done)" >> $LOG
1317 report close-bloc
1318 echo "Package $PACKAGE ($VERSION$EXTRAVERSION) generated."
1319 echo "Size : `du -sh $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
1320 echo ""
1323 ########################################################################
1324 # This section contains functions used by several other functions
1325 # below.
1326 ########################
1328 # Look for receipt/files.list in wok. If they can't be found, get them
1329 # from package. Accept one argument : absolute path to package.
1330 get_pkg_files()
1332 pkg_files_dir=$tmp/$(basename ${1%.tazpkg})
1333 mkdir -p $pkg_files_dir && \
1334 cd $pkg_files_dir && \
1335 cpio --quiet -idm receipt < $1 && \
1336 cpio --quiet -idm files.list < $1
1339 ########################################################################
1340 # This section contains functions to generate packages databases.
1341 ########################
1344 gen_packages_db()
1346 # pkg_repository can be $PACKAGES_REPOSITORY or $INCOMING_REPOSITORY.
1347 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1348 cd $pkg_repository
1349 report step "Generating packages lists: $pkg_repository"
1350 report open-bloc
1351 report step "Removing old files"
1352 for file in files.list.lzma packages.list packages.txt \
1353 packages.desc packages.equiv packages.md5; do
1354 rm -rf $file
1355 done
1356 touch files.list
1358 packages_db_start
1359 unset RECEIPT
1360 report step "Reading data from all packages"
1361 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1362 get_packages_info
1363 done
1364 report end-step
1365 packages_db_end
1366 report close-bloc
1369 update_packages_db()
1371 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1372 cd $pkg_repository
1373 for file in packages.list packages.equiv packages.md5 packages.desc \
1374 packages.txt; do
1375 if [ ! -f "$file" ]; then
1376 gen_packages_db
1377 return
1378 fi
1379 done
1380 if [ -f files.list.lzma ]; then
1381 lzma d files.list.lzma files.list
1382 else
1383 gen_packages_db
1384 return
1385 fi
1386 report step "Updating packages lists: $pkg_repository"
1387 packages_db_start
1389 # Look for removed/update packages.
1390 touch stamp -r packages.list
1391 for PACKAGE in $(grep ^[0-9,a-z,A-Z] packages.txt); do
1392 pkg="$pkg_repository/$(grep -m1 ^$PACKAGE- packages.list).tazpkg"
1393 if ! [ -f "$pkg" ]; then
1394 erase_package_info
1395 else
1396 if [ "$pkg" -nt "stamp" ]; then
1397 updated_pkg="$updated_pkg
1398 $PACKAGE $pkg"
1399 elif [ ! -f $WOK/$PACKAGE/receipt ] && \
1400 [ "$COMMAND" = check-incoming -o "$pkg_repository" = "$INCOMING_REPOSITORY" ]; then
1401 erase_package_info
1402 echo "Removing $PACKAGE from $pkg_repository."
1403 rm $pkg
1404 [ "$save_wok" ] && rm -rf $pkg_repository/wok/$PACKAGE
1405 if [ "$pkg_repository" = "$INCOMING_REPOSITORY" ]; then
1406 rm -rf $WOK/$PACKAGE
1407 sed "/^$PACKAGE\t/d" -i $wan_db $dep_db $cookorder
1408 sed "/^$PACKAGE$/d" -i $cooklist $commit $blocked $broken
1409 rm -f $LOCAL_REPOSITORY/log/$PACKAGE.html
1410 if [ "$(sed 1!d $cookorder)" != "#PlanSort" ]; then
1411 sed 1i"#PlanSort" -i $cookorder
1412 regen_cooklist=yes
1413 fi
1414 else
1415 echo "$PACKAGE" >> removed
1416 sed -n '1,10p' -i removed
1417 fi
1418 fi
1419 fi
1420 done
1421 rm stamp
1422 echo "$updated_pkg" | sed 1d | while read PACKAGE pkg; do
1423 erase_package_info
1424 get_packages_info
1425 done
1426 unset updated_pkg
1428 # Look for new packages.
1429 for pkg in $pkg_repository/*.tazpkg; do
1430 fgrep -q " ${pkg##*/}" packages.md5 || get_packages_info
1431 done
1432 report end-step
1433 packages_db_end
1436 packages_db_start()
1438 if [ -s packages.txt ]; then
1439 sed -e 's/^# Packages :.*/# Packages : unknown/' \
1440 -e "s/# Date :.*/# Date : $(date +%Y-%m-%d\ \%H:%M:%S)/" \
1441 -i packages.txt
1442 else
1443 echo "# SliTaz GNU/Linux - Packages list
1445 # Packages : unknown
1446 # Date : $(date +%Y-%m-%d\ \%H:%M:%S)
1448 " > packages.txt
1449 fi
1451 # Needed in some cases as tazwok defines RECEIPT at configuration time
1452 # in this particular case it can break the script.
1453 unset RECEIPT
1455 # If $packages_repository is the main one, configure few functions
1456 # to act as they should, without having loop on them (speed-up)
1457 if [ "$pkg_repository" = "$PACKAGES_REPOSITORY" ]; then
1458 erase_package_info_extracmd="erase_package_info_main"
1459 get_packages_info_extracmd="get_packages_info_main"
1460 fi
1463 erase_package_info()
1465 cd $pkg_repository
1466 sed "/^$PACKAGE$/,/^$/d" -i packages.txt
1467 sed "/^$PACKAGE /d" -i packages.desc
1468 sed -e "s/=$PACKAGE /= /" -e "s/ $PACKAGE / /" -e "s/ $PACKAGE$//" \
1469 -e "/=$PACKAGE$/d" -e "s/=[0-9,a-z,A-Z]:$PACKAGE /= /" \
1470 -e "s/ [0-9,a-z,A-Z]:$PACKAGE / /" -e "s/ [0-9,a-z,A-Z]:$PACKAGE$/ /" \
1471 -e "/=[0-9,a-z,A-Z]:$PACKAGE$/d" \
1472 -i packages.equiv
1473 sed "/^$PACKAGE:/d" -i files.list
1474 sed "/^$(basename ${pkg%.tazpkg})$/d" -i packages.list
1475 sed "/ $(basename $pkg)$/d" -i packages.md5
1476 $erase_package_info_extracmd
1479 erase_package_info_main()
1481 for i in wanted.txt depends.txt libraries.txt; do
1482 [ -f $i ] || continue
1483 sed "/^$PACKAGE\t/d" -i $i
1484 done
1487 get_packages_info()
1489 # If there's no taz folder in the wok, extract info from the
1490 # package.
1491 get_pkg_files $pkg
1492 source_receipt
1493 echo "Getting data from $PACKAGE"
1495 cat >> $pkg_repository/packages.txt << _EOT_
1496 $PACKAGE
1497 $VERSION$EXTRAVERSION
1498 $SHORT_DESC
1499 _EOT_
1500 if [ "$PACKED_SIZE" ]; then
1501 cat >> $pkg_repository/packages.txt << _EOT_
1502 $PACKED_SIZE ($UNPACKED_SIZE installed)
1504 _EOT_
1505 else
1506 echo "" >> $pkg_repository/packages.txt
1507 fi
1509 # Packages.desc is used by Tazpkgbox <tree>.
1510 echo "$PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> $pkg_repository/packages.desc
1512 # Packages.equiv is used by tazpkg install to check depends.
1513 for i in $PROVIDE; do
1514 DEST=""
1515 echo $i | fgrep -q : && DEST="${i#*:}:"
1516 if grep -qs ^${i%:*}= $pkg_repository/packages.equiv; then
1517 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" $pkg_repository/packages.equiv
1518 else
1519 echo "${i%:*}=$DEST$PACKAGE" >> $pkg_repository/packages.equiv
1520 fi
1521 done
1523 if [ -f files.list ]; then
1524 { echo "$PACKAGE"; cat files.list; } | awk '
1525 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }' >> $pkg_repository/files.list
1526 fi
1528 cd .. && rm -r "$pkg_files_dir"
1530 cd $pkg_repository
1531 echo $(basename ${pkg%.tazpkg}) >> packages.list
1532 md5sum $(basename $pkg) >> packages.md5
1533 $get_packages_info_extracmd
1536 get_packages_info_main()
1538 [ "$WANTED" ] && echo -e "$PACKAGE\t$WANTED" >> wanted.txt
1539 echo -e "$PACKAGE\t "$DEPENDS" \t "$BUILD_DEPENDS" " >> package.txt
1540 grep -m1 ^$PACKAGE$'\t' $lib_db >> libraries.txt
1543 source_receipt()
1545 unset PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
1546 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
1547 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
1548 src _pkg DESTDIR CONFIG_SITE BRANCH TARBALL stuff wanted_stuff
1549 . ${RECEIPT:-$PWD/receipt}
1552 packages_db_end()
1554 cd $pkg_repository
1555 pkgs=$(wc -l packages.list | sed 's/ .*//')
1556 sed "s/# Packages : .*/# Packages : $pkgs/" -i packages.txt
1558 # If lists were updated it's generally needed to sort them well.
1559 if ! sort -c packages.list 2> /dev/null; then
1560 report step "Sorting packages lists"
1561 files_list="packages.list packages.desc packages.equiv"
1562 [ "${pkg_repository##*/}" = packages ] && \
1563 files_list="$files_list wanted.txt depends.txt libraries.txt"
1564 for file in $files_list; do
1565 [ -f $file ] || continue
1566 sort -o $file $file
1567 done
1568 report end-step
1569 fi
1571 md5sum packages.md5 | cut -f1 -d' ' > ID
1572 [ -s ID ] || echo null > ID
1574 # Dont log this because lzma always output errors.
1575 lzma e files.list files.list.lzma
1576 rm -f files.list
1577 [ -f packages.equiv ] || touch packages.equiv
1580 ########################################################################
1581 # This section contains functions to generate wok database.
1582 ########################
1584 gen_wok_db()
1586 report step "Generating wok database"
1587 report open-bloc
1588 report step "Removing old files"
1589 for file in $wan_db $dep_db $cookorder; do
1590 [ -f $file ] && rm $file
1591 done
1592 report step "Generating wok-wanted.txt"
1593 gen_wan_db
1594 report step "Generating wok-depends.txt"
1595 gen_dep_db
1596 sort_db
1597 report close-bloc
1600 gen_wan_db()
1602 [ -f $wan_db ] && rm -f $wan_db
1603 for RECEIPT in $(fgrep -l WANTED $WOK/*/receipt); do
1604 WANTED=
1605 source $RECEIPT
1606 [ "$WANTED" ] || continue
1607 echo -e $PACKAGE"\t"$WANTED >> $wan_db
1608 done
1611 gen_dep_db()
1613 [ -f $dep_db ] && rm -f $dep_db
1614 for PACKAGE in $(ls $WOK); do
1615 RECEIPT=$WOK/$PACKAGE/receipt
1616 if [ -s $RECEIPT ]; then
1617 source_receipt
1618 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
1619 fi
1620 done
1623 update_wan_db()
1625 local PACKAGE=$PACKAGE
1626 wanted_list=$(fgrep WANTED=\"$PACKAGE\" $WOK/*/receipt | cut -f1 -d ':')
1627 grep $'\t'$PACKAGE $wan_db | cut -f 1 | while read wan; do
1628 echo "$wanted_list" | fgrep -q /$wan/receipt && continue
1629 sed "/^$wan\t/d" -i $wan_db
1630 done
1631 for RECEIPT in $wanted_list; do
1632 unset WANTED PACKAGE
1633 source $RECEIPT
1634 [ "$WANTED" ] || continue
1635 sed "/^$PACKAGE\t/d" -i $wan_db
1636 echo -e $PACKAGE"\t"$WANTED >> $wan_db
1637 done
1638 unset wanted_list
1641 update_dep_db()
1643 sed "/^$PACKAGE\t/d" -i $dep_db
1644 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
1647 sort_db()
1649 report step "Generating cookorder.txt"
1650 sed 's/ \t / /' $dep_db | while read PACKAGE BUILD_DEPENDS; do
1651 grep -q ^$PACKAGE$'\t' $wan_db && continue
1653 # Replace each BUILD_DEPENDS with a WANTED package by it's
1654 # WANTED package.
1655 echo -e $PACKAGE"\t $(echo $BUILD_DEPENDS | use_wanted | \
1656 sort -u | sed "/^$PACKAGE$/d" | tr '\n' ' ') "
1657 done > $tmp/db
1658 while [ -s "$tmp/db" ]; do
1659 status=start
1660 for pkg in $(cut -f 1 $tmp/db); do
1661 if ! fgrep -q ' '$pkg' ' $tmp/db; then
1662 echo $pkg >> $tmp/cookorder
1663 sed -e "/^$pkg\t/d" -e "s/ $pkg / /g" -i $tmp/db
1664 status=proceed
1665 fi
1666 done
1667 if [ "$status" = start ]; then
1668 cp -f $tmp/db /tmp/remain-depends.txt
1669 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
1670 for remaining in $(cut -f 1 $tmp/db); do
1671 if ! grep -q ^$remaining $PACKAGES_REPOSITORY/blocked; then
1672 echo "$remaining" >> $PACKAGES_REPOSITORY/blocked
1673 fi
1674 done
1675 break
1676 fi
1677 done
1678 [ -s $tmp/cookorder ] || touch $tmp/cookorder
1680 # The toolchain packages are moved in first position.
1681 grep $(for pkg in `scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
1682 --look_for=all --with_args`; do echo " -e ^$pkg$"; done) \
1683 $tmp/cookorder | tac > $cookorder
1684 for pkg in $(cat $cookorder); do
1685 sed "/^$pkg$/d" -i $tmp/cookorder
1686 done
1688 tac $tmp/cookorder >> $cookorder
1689 report end-step
1692 ########################################################################
1693 # SCAN CORE
1694 ########################
1695 # Includes various scan core-functions. It's not intended to be used
1696 # directly : prefer scan wrappers in next section.
1698 look_for_dep()
1700 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2
1703 look_for_bdep()
1705 look_for_all
1708 look_for_all()
1710 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2,3 | sed 's/ / /'
1713 look_for_rdep()
1715 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1
1718 look_for_rbdep()
1720 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1723 # Return WANTED if it exists.
1724 look_for_wanted()
1726 grep -m1 ^$PACKAGE$'\t' $wan_db | cut -f 2
1729 # Return packages which wants PACKAGE.
1730 look_for_rwanted()
1732 grep $'\t'$PACKAGE$ $wan_db | cut -f 1
1735 look_for_dev()
1737 WANTED=$(look_for_wanted)
1738 if [ "$WANTED" ]; then
1739 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1740 fi
1741 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1744 with_dev()
1746 for PACKAGE in $(cat); do
1747 echo $PACKAGE
1748 look_for_dev
1749 done
1752 with_wanted()
1754 for PACKAGE in $(cat); do
1755 echo $PACKAGE
1756 look_for_wanted
1757 done
1760 use_wanted()
1762 for input in $(cat); do
1763 { grep ^$input$'\t' $wan_db || echo $input
1765 done | sed 's/.*\t//'
1768 check_for_pkg_in_wok()
1770 [ -f $WOK/$PACKAGE/receipt ] && return
1771 echo "Can't find $PACKAGE in wok or mirror" >&2
1772 return 2
1775 # Define how theses functions should act when using --undigest.
1776 use_undigest_scan_core()
1778 look_for_dep()
1780 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1781 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2
1782 else
1783 grep -m1 ^$PACKAGE$'\t' $ref_dep_db | cut -f 2
1784 fi
1787 look_for_all()
1789 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1790 grep -m1 ^$PACKAGE$'\t' $dep_db | cut -f 2,3 | sed 's/ / /'
1791 else
1792 grep -m1 ^$PACKAGE$'\t' $ref_dep_db | cut -f 2,3 | sed 's/ / /'
1793 fi
1796 look_for_rdep()
1798 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1
1799 for rdep in $(fgrep ' '$PACKAGE' ' $ref_dep_db | cut -f 1); do
1800 [ -f "WOK$/$rdep/receipt" ] || echo "$rdep"
1801 done
1804 look_for_rbdep()
1806 fgrep ' '$PACKAGE' ' $dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1807 for rdep in $(fgrep ' '$PACKAGE' ' $ref_dep_db | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1); do
1808 [ -f "WOK$/$rdep/receipt" ] || echo "$rdep"
1809 done
1812 look_for_wanted()
1814 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1815 grep -m1 ^$PACKAGE$'\t' $wan_db | cut -f 2
1816 else
1817 grep -m1 ^$PACKAGE$'\t' $ref_wan_db | cut -f 2
1818 fi
1821 look_for_rwanted()
1823 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1824 grep $'\t'$PACKAGE$ $wan_db | cut -f 1
1825 else
1826 grep $'\t'$PACKAGE$ $ref_wan_db | cut -f 1
1827 fi
1830 look_for_dev()
1832 WANTED=$(look_for_wanted)
1833 if [ "$WANTED" ]; then
1834 if [ -f "$WOK/$WANTED/receipt" ]; then
1835 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1836 else
1837 grep -q ^$WANTED-dev$'\t' $ref_dep_db && echo $WANTED-dev
1838 fi
1839 fi
1840 if [ -f "$WOK/$PACKAGE/receipt" ]; then
1841 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1842 else
1843 grep -q ^$PACKAGE-dev$'\t' $ref_dep_db && echo $PACKAGE-dev
1844 fi
1847 check_for_pkg_in_wok()
1849 [ -f $WOK/$PACKAGE/receipt ] && return
1850 grep -q ^$PACKAGE'$\t' $ref_dep_db && return 1
1851 echo "Can't find $PACKAGE in wok or mirror" >&2
1852 return 2
1856 ########################################################################
1857 # SCAN
1858 ########################
1859 # Use wok-wanted.txt and wok-depeds.txt to scan depends.
1860 # Option in command line (must be first arg) :
1861 # --look_for=bdep/rbdep - Look for depends or reverse depends.
1862 # --with_dev - Add development packages (*-dev) in the result.
1863 # --with_wanted - Add package+reverse wanted in the result.
1864 # --with_args - Include packages in argument in the result.
1866 scan()
1868 # Get packages in argument.
1869 local PACKAGE=$PACKAGE WANTED=$WANTED pkg_list=
1870 for arg in $@; do
1871 [ "$arg" = "${arg#--}" ] || continue
1872 pkg_list="$pkg_list $arg"
1873 done
1875 # Get options.
1876 [ "$pkg_list" ] || return
1877 local cooklist= look_for= with_dev= with_wanted= with_args= log_command="$0 $@" \
1878 get_options_list="look_for with_dev with_wanted with_args cooklist use_wanted"
1879 get_options
1881 # Get db md5 to be able to check for changes latter.
1882 db_md5=$(md5sum $dep_db $wan_db)
1884 # Cooklist is a special case where we need to modify a little
1885 # scan behavior
1886 if [ "$cooklist" ]; then
1887 gen_wan_db
1888 look_for=all && with_args=yes && with_dev= && with_wanted=
1889 filter=use_wanted
1890 if [ "$COMMAND" = gen-cooklist ]; then
1891 for PACKAGE in $pkg_list; do
1892 grep -q ^$PACKAGE$'\t' $dep_db && continue
1893 [ -d "$WOK/$p" ] || continue
1894 check_for_missing
1895 done
1896 append_to_dep()
1898 if grep -q ^$PACKAGE$'\t' $dep_db; then
1899 echo $PACKAGE >> $tmp/dep
1900 else
1901 check_for_missing && echo $PACKAGE >> $tmp/dep
1902 fi
1904 else
1905 append_to_dep()
1907 check_for_commit && echo $PACKAGE >> $tmp/dep
1909 fi
1910 else
1911 append_to_dep()
1913 echo $PACKAGE >> $tmp/dep
1915 # If requested packages are not in dep_db, partial generation of this db is needed.
1916 for PACKAGE in $pkg_list; do
1917 grep -q ^$PACKAGE$'\t' $dep_db && continue
1918 [ -d "$WOK/$p" ] || continue
1919 plan_check_for_missing=yes
1920 check_for_missing
1921 done
1922 if [ "$plan_check_for_missing" ]; then
1923 append_to_dep()
1925 if grep -q ^$PACKAGE$'\t' $dep_db; then
1926 echo $PACKAGE >> $tmp/dep
1927 else
1928 check_for_missing && echo $PACKAGE >> $tmp/dep
1929 fi
1931 unset plan_check_for_missing
1932 fi
1933 fi
1935 [ "$with_dev" ] && filter=with_dev
1936 [ "$with_wanted" ] && filter=with_wanted
1937 if [ "$filter" ]; then
1938 pkg_list=$(echo $pkg_list | $filter | sort -u)
1939 scan_pkg()
1941 look_for_$look_for | $filter
1943 else
1944 scan_pkg()
1946 look_for_$look_for
1948 fi
1949 touch $tmp/dep
1950 for PACKAGE in $pkg_list; do
1951 [ "$with_args" ] && append_to_dep
1952 scan_pkg
1953 done | tr ' ' '\n' | sort -u > $tmp/list
1954 [ "$look_for" = bdep ] && look_for=dep
1955 while [ -s $tmp/list ]; do
1956 PACKAGE=$(sed 1!d $tmp/list)
1957 sed 1d -i $tmp/list
1958 append_to_dep
1959 for pkg in $(scan_pkg); do
1960 grep -q ^$pkg$ $tmp/list $tmp/dep || echo $pkg >> $tmp/list
1961 done
1962 done
1963 if [ "$cooklist" ]; then
1964 mv $tmp/dep $tmp/cooklist
1965 else
1966 cat $tmp/dep | sort -u
1967 fi
1968 rm -f $tmp/dep $tmp/list
1969 sort -o $dep_db $dep_db
1970 sort -o $wan_db $wan_db
1971 if [ "$db_md5" != "$(md5sum $dep_db $wan_db)" ]; then
1972 grep -q "^#" $cookorder || sed 1i"#PlanSort" -i $cookorder
1973 fi
1976 ########################################################################
1977 # This section contains functions to check the package repository and
1978 # find which packages to cook.
1979 ########################
1981 check_for_missing()
1983 local PACKAGE=$PACKAGE
1984 if ! check_for_pkg_in_wok; then
1985 [ "$?" = 2 ] && return 1
1986 return
1987 fi
1988 RECEIPT=$WOK/$PACKAGE/receipt
1989 source_receipt
1990 PACKAGE=${WANTED:-$PACKAGE}
1991 update_wan_db
1992 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1993 RECEIPT=$WOK/$PACKAGE/receipt
1994 source_receipt
1995 update_dep_db
1996 done
1999 check_for_commit()
2001 if ! check_for_pkg_in_wok; then
2002 [ "$?" = 2 ] && return 1
2003 return
2004 fi
2005 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
2006 RECEIPT=$WOK/$PACKAGE/receipt
2007 source_receipt
2009 # We use md5 of cooking stuff in the packaged receipt to check
2010 # commit. We look consecutively in 3 different locations :
2011 # - in the wok/PACKAGE/taz/* folder
2012 # - in the receipt in the package in incoming repository
2013 # - in the receipt in the package in packages repository
2014 # If md5sums match, there's no commit.
2015 check_for_commit_using_md5sum()
2017 if [ ! -f $WOK/$PACKAGE/md5 ]; then
2018 sed -n '/# md5sum of cooking stuff :/,$p' receipt | \
2019 sed -e 1d -e 's/^# //' > $WOK/$PACKAGE/md5
2020 cd $WOK/$PACKAGE
2021 fi
2023 if [ -s md5 ]; then
2024 if md5sum -cs md5; then
2026 # If md5sum check if ok, check for new/missing files in
2027 # cooking stuff.
2028 for file in $([ -f receipt ] && echo receipt; \
2029 [ -f description.txt ] && echo description.txt; \
2030 [ -d stuff ] && find stuff); do
2031 if ! fgrep -q " $file" md5; then
2032 set_commited
2033 fi
2034 done
2035 else
2036 set_commited
2037 fi
2038 else
2039 set_commited
2040 fi
2042 set_commited()
2044 grep -q ^$PACKAGE$ $commit || echo $PACKAGE >> $commit
2045 gen_cookmd5
2046 update_dep_db
2048 taz_dir=$(echo $WOK/$PACKAGE/taz/$PACKAGE-* | fgrep -v '*')
2049 if [ -f $WOK/$PACKAGE/md5 ]; then
2050 cd $WOK/$PACKAGE
2051 check_for_commit_using_md5sum
2052 elif [ "$taz_dir" ]; then
2053 cd $taz_dir
2054 check_for_commit_using_md5sum
2055 else
2056 pkg=$(echo $INCOMING_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
2057 [ "$pkg" ] || pkg=$(echo $PACKAGES_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
2058 if [ "$pkg" ]; then
2059 get_pkg_files $pkg
2060 check_for_commit_using_md5sum
2061 rm -r $pkg_files_dir
2062 else
2063 set_commited
2064 fi
2065 fi
2066 [ "$forced" ] || echo $PACKAGE >> $tmp/checked
2067 done
2068 return
2071 gen_cook_list()
2073 report step "Scanning wok"
2074 if [ "$pkg" ]; then
2075 scan $pkg --cooklist
2076 elif [ "$LIST" ]; then
2077 scan `cat $LIST` --cooklist
2078 else
2079 scan `cat $cooklist` --cooklist
2080 fi
2081 report end-step
2083 [ -s $tmp/checked ] || [ -s $tmp/cooklist ] || return
2085 # Core toolchain should not be cooked unless cook-toolchain is used.
2086 if ! [ -f /etc/config.site.tmptoolchain ] ; then
2087 for PACKAGE in $(scan gcc --look_for=all --with_args --with_wanted); do
2088 grep -q ^$PACKAGE$ $blocked || echo $PACKAGE >> $blocked
2089 done
2090 fi
2092 if [ -s $commit ] && [ "$COMMAND" != gen-cooklist ]; then
2093 for PACKAGE in $(cat $commit); do
2094 WANTED="$(look_for_wanted)"
2095 if [ "$WANTED" ]; then
2096 grep -q ^$WANTED$ $broken $cooklist $blocked $commit && continue
2097 fi
2098 grep -q ^$PACKAGE$ $blocked $cooklist && continue
2099 echo $PACKAGE >> $cooklist
2100 done
2101 fi
2102 sort_cooklist
2105 sort_cooklist()
2107 if [ "$(sed 1!d $cookorder)" = "#PlanSort" ]; then
2108 sed 1d -i $cookorder
2109 sort_db
2110 fi
2111 report step "Generating cooklist"
2112 if [ -f "$tmp/checked" ]; then
2113 rm -f $tmp/cooklist
2114 cat $tmp/checked | while read PACKAGE; do
2115 grep -q ^$PACKAGE$ $cooklist && echo $PACKAGE >> $tmp/cooklist
2116 done
2117 elif ! [ "$COMMAND" = gen-cooklist ]; then
2118 cat $blocked | while read PACKAGE; do
2119 sed "/^$PACKAGE/d" -i $tmp/cooklist
2120 done
2121 fi
2122 report end-step
2123 [ -s $tmp/cooklist ] || return
2125 report step "Sorting cooklist"
2126 for PACKAGE in $(cat $tmp/cooklist); do
2127 WANTED="$(look_for_wanted)"
2128 [ "$WANTED" ] || continue
2129 if grep -q ^$WANTED$ $broken $tmp/cooklist; then
2130 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2131 elif [ ! -d $WOK/$WANTED/install ]; then
2132 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2133 echo $WANTED >> $tmp/cooklist
2134 fi
2135 done
2137 # Use cookorder.txt to sort cooklist.
2138 if [ -s $tmp/cooklist ]; then
2139 cat $cookorder | while read PACKAGE; do
2140 if grep -q ^$PACKAGE$ $tmp/cooklist; then
2141 sed "/^$PACKAGE$/d" -i $tmp/cooklist
2142 echo $PACKAGE >> $tmp/cooklist.tmp
2143 fi
2144 done
2146 # Remaining packages in cooklist are those without compile_rules.
2147 # They can be cooked first in any order.
2148 if [ -f $tmp/cooklist.tmp ]; then
2149 cat $tmp/cooklist.tmp >> $tmp/cooklist
2150 rm $tmp/cooklist.tmp
2151 fi
2153 cat $tmp/cooklist
2154 [ "$LIST" ] || cat $tmp/cooklist > $cooklist
2155 fi
2157 report end-step
2160 look_for_missing_pkg()
2162 for pkg in $(cat $PACKAGES_REPOSITORY/$1); do
2163 grep -q ^$pkg$ $INCOMING_REPOSITORY/packages.txt \
2164 $PACKAGES_REPOSITORY/packages.txt || \
2165 continue
2166 echo $pkg
2167 done
2170 check_for_incoming()
2172 report step "Checking that all packages were cooked OK"
2173 [ -s $INCOMING_REPOSITORY/packages.desc ] || {
2174 echo "No packages in $INCOMING_REPOSITORY."
2175 report end-step; return; }
2176 if [ -s $broken ]; then
2177 missingpkg=$(look_for_missing_pkg broken)
2178 if [ "$missingpkg" ]; then
2179 echo "Don't move incoming packages to main repository because these ones are broken:" >&2
2180 echo "$missingpkg"
2181 report end-step
2182 return 1
2183 fi
2184 fi
2185 if [ -s $cooklist ]; then
2186 missingpkg=$(look_for_missing_pkg cooklist)
2187 if [ "$missingpkg" ]; then
2188 echo "Don't move incoming packages to main repository because these ones need to be cooked:" >&2
2189 echo "$missingpkg"
2190 report end-step
2191 return 1
2192 fi
2193 fi
2194 incoming_pkgs="$(cut -f 1 -d '|' $INCOMING_REPOSITORY/packages.desc)"
2195 if ! [ "$forced" ]; then
2196 cooklist=$PACKAGES_REPOSITORY/cooklist
2197 pkg="$incoming_pkgs"
2198 gen_cook_list
2199 if [ -s $cooklist ]; then
2200 missingpkg=$(look_for_missing_pkg cooklist)
2201 if [ "$missingpkg" ]; then
2202 echo "Don't move incoming packages to main repository because these ones need to be cooked:" >&2
2203 echo "$missingpkg"
2204 report end-step
2205 return 1
2206 fi
2207 fi
2208 fi
2210 report step "Moving incoming packages to main repository"
2211 [ "save_wok" ] && mkdir -p $PACKAGES_REPOSITORY/wok
2212 unset EXTRAVERSION
2213 for PACKAGE in $incoming_pkgs; do
2214 prev_VERSION=$(get_pkg_version $PACKAGES_REPOSITORY)
2215 VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
2216 remove_previous_package $PACKAGES_REPOSITORY
2217 echo "Moving $PACKAGE..."
2218 mv -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION.tazpkg $PACKAGES_REPOSITORY
2219 touch $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
2220 previous_tarball=$(grep -m1 ^$PACKAGE:main $SOURCES_REPOSITORY/sources.list | cut -f2)
2221 sed -e "/^$PACKAGE:main/d" \
2222 -e "s/^$PACKAGE:incoming/$PACKAGE:main/" \
2223 -i $SOURCES_REPOSITORY/sources.list
2224 if [ "$previous_tarball" ]; then
2225 grep -q $'\t'$previous_tarball$ $SOURCES_REPOSITORY/sources.list || \
2226 rm -f $SOURCES_REPOSITORY/$previous_tarball
2227 fi
2228 [ "$save_wok" ] && mv $INCOMING_REPOSITORY/wok/$PACKAGE $PACKAGES_REPOSITORY/wok
2229 done
2231 if [ "$save_wok" = tarball ]; then
2232 rm -f $PACKAGES_REPOSITORY/wok.tar.lzma
2233 cd $PACKAGES_REPOSITORY/wok
2234 report step "Generating safe-wok tarball"
2235 tar -c * | lzma e -si $PACKAGES_REPOSITORY/wok.tar.lzma
2236 report end-step
2237 fi
2239 for file in packages.list packages.equiv packages.md5 packages.desc \
2240 packages.txt; do
2241 echo -n "" > $INCOMING_REPOSITORY/$file
2242 done
2243 rm -r $INCOMING_REPOSITORY/files.list.lzma
2244 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2246 report step "Updating flavors"
2247 if [ -x /usr/bin/tazlito ] || [ -x /usr/bin/clean-chroot ]; then
2248 if ! [ -x /usr/bin/tazlito ]; then
2249 tazpkg get-install tazlito
2250 fi
2252 # Handle cases where tazwok is used into main system;
2253 # Handle cases where SLITAZ_DIR is not /home/slitaz.
2254 [ -L /home/slitaz/flavors ] && rm /home/slitaz/flavors
2255 mkdir -p /home/slitaz
2256 ln -s $LOCAL_REPOSITORY/flavors /home/slitaz/flavors
2257 cd /home/slitaz/flavors
2258 [ -d .hg ] && hg pull -u
2260 cd $LOCAL_REPOSITORY/packages
2261 for i in $LOCAL_REPOSITORY/flavors/*; do
2262 [ -d "$i" ] || continue
2263 tazlito pack-flavor ${i##*/}
2264 done
2266 noheader=""
2267 for i in *.flavor; do
2268 tazlito show-flavor $i --brief $noheader
2269 noheader="--noheader"
2270 done > flavors.list
2271 [ -x /usr/bin/clean-chroot ] && clean-chroot
2272 else
2273 echo "Can't create up-to-date flavors because the tazlito package is missing." >&2
2274 fi
2275 report end-step
2278 # Usage: move_cooking_stuff source receipt destination
2279 # Make the argument check before calling it!
2280 copy_cooking_stuff()
2282 rm -rf $3/$2
2283 mkdir -p $3/$2
2284 cp -a $1/$2/receipt $3/$2
2285 [ -f $1/$2/description.txt ] && \
2286 cp -a $1/$2/description.txt $3/$2
2287 if [ -d "$1/$2/stuff" ]; then
2288 cp -a $1/$2/stuff $3/$2
2289 fi
2292 ########################################################################
2293 # TAZWOK MAIN FUNCTIONS
2294 ########################
2296 clean()
2298 cd $WOK/$PACKAGE
2299 ls -A $WOK/$PACKAGE | grep -q -v -e ^receipt$ -e ^description.txt$ \
2300 -e ^stuff$ || return
2302 [ "$COMMAND" = clean-wok ] || report step "Cleaning $PACKAGE"
2303 # Check for clean_wok function.
2304 if grep -q ^clean_wok $RECEIPT; then
2305 clean_wok
2306 fi
2307 # Clean should only have a receipt, stuff and optionals desc/md5.
2308 for f in `ls .`
2309 do
2310 case $f in
2311 receipt|stuff|description.txt|md5)
2312 continue ;;
2313 *)
2314 rm -rf $f ;;
2315 esac
2316 done
2317 [ "$COMMAND" != clean-wok ] && report end-step
2320 # Configure and make a package with the receipt.
2321 compile_package()
2323 check_for_package_on_cmdline
2325 # Include the receipt to get all needed variables and functions
2326 # and cd into the work directory to start the work.
2327 check_for_receipt
2328 source_receipt
2330 # Log the package name and date.
2331 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
2332 echo "package $PACKAGE (compile)" >> $LOG
2334 # Set wanted $src variable to help compiling.
2335 [ ! "$src" ] && set_src_path
2336 check_for_build_depends || return 1
2337 check_for_wanted
2338 unset target
2339 check_for_tarball && check_for_compile_rules
2342 # Cook command also include all features to manage lists which keep
2343 # track of wok/packages state.
2344 cook()
2346 cook_code=
2347 set_common_path
2348 check_for_receipt
2349 source_receipt
2351 # Define log path and start report.
2352 for i in $(look_for_rwanted) $PACKAGE; do
2353 rm -f $LOCAL_REPOSITORY/log/$i.html
2354 done
2355 report sublog $LOCAL_REPOSITORY/log/$PACKAGE.html
2356 echo "$PACKAGE" > $LOCAL_REPOSITORY/log/package
2357 report step "Cooking $PACKAGE"
2358 report open-bloc
2360 clean $PACKAGE
2361 [ -s $tmp/cooklist ] && sed "/^$PACKAGE$/d" -i $tmp/cooklist
2363 if compile_package; then
2364 remove_src
2365 refresh_packages_from_compile
2366 gen_package
2368 # Update packages-incoming repository.
2369 store_pkgname=$PACKAGE
2370 pkg_repository=$INCOMING_REPOSITORY
2371 update_packages_db
2373 PACKAGE=$store_pkgname
2374 unset store_pkgname
2376 # Upgrade to cooked packages if it was previously installed.
2377 report step "Looking for package(s) to upgrade"
2378 for pkg in $(look_for_rwanted) $PACKAGE; do
2379 if [ -f $INSTALLED/$pkg/receipt ]; then
2380 tazpkg get-install $pkg --forced
2381 fi
2382 done
2383 report end-step
2384 else
2385 for PACKAGE in $(look_for_wanted) $PACKAGE; do
2386 set_pkg_broken
2387 done
2388 cook_code=1
2389 fi
2391 # Remove build_depends in cook mode (if in cooklist, it's done when
2392 # checking build_depends of next package and we remove only unneeded
2393 # packages to keep chroot minimal and gain some time).
2394 if [ "$COMMAND" = cook ]; then
2395 remove_build_depends $MISSING_PACKAGE
2396 [ -x /usr/bin/clean-chroot ] && clean-chroot
2397 fi
2399 # Regen the cooklist if it was planned and command is not cook.
2400 [ "$regen_cooklist" ] && unset regen_cooklist &&
2401 [ "$COMMAND" != cook ] && sort_cooklist
2403 # Some hacks to set the bloc & function status as failed if cook has
2404 # failed.
2405 report_return_code=$cook_code
2406 report close-bloc
2407 report end-sublog
2408 rm -f $LOCAL_REPOSITORY/log/package
2409 return $cook_code
2412 cook_list()
2414 if [ -s $tmp/cooklist ]; then
2415 if [ -f /usr/bin/tazchroot ]; then
2416 # Note : options -main variables- are automatically kept by
2417 # the sub-applications tazchroot/tazwok; as well as report data.
2418 cd $LOCAL_REPOSITORY
2419 [ ! -f tazchroot.conf ] && configure_tazchroot
2420 tazchroot tazwok cook-list --SLITAZ_DIR=$SLITAZ_DIR --SLITAZ_VERSION=$SLITAZ_VERSION ${undigest:+ --undigest=$undigest}
2421 return
2422 fi
2423 while [ -s $tmp/cooklist ]; do
2424 PACKAGE=$(sed 1!d $tmp/cooklist)
2425 cook
2426 done
2427 remove_build_depends $MISSING_PACKAGE $remove_later
2428 [ -x /usr/bin/clean-chroot ] && clean-chroot
2429 else
2430 echo "Nothing to cook."
2431 return
2432 fi
2435 configure_tazchroot()
2437 cat > $LOCAL_REPOSITORY/tazchroot.conf << EOF
2438 # Tazchroot configuration file - created by tazwok.
2440 # Local repository definition.
2441 SLITAZ_DIR=$SLITAZ_DIR
2442 SLITAZ_VERSION=$SLITAZ_VERSION
2443 LOCAL_REPOSITORY=$SLITAZ_DIR/${undigest:-$SLITAZ_VERSION}
2444 ${USE_ONLINE_PKG:+USE_ONLINE_PKG=$USE_ONLINE_PKG}
2445 ${undigest:+undigest=$undigest}
2446 ${ref_USE_ONLINE_PKG:+ref_USE_ONLINE_PKG=$ref_USE_ONLINE_PKG}
2448 # Chroot path.
2449 # You can use a chroot into /tmp if it's mounted in RAM
2450 # to speed-up the process, be sure you have a free GB.
2451 # (minimal chroot is like 150~200MB, can be a lot more during cook)
2452 # chroot_dir=/tmp/chroot-${undigest:-$SLITAZ_VERSION}
2453 chroot_dir=\$LOCAL_REPOSITORY/chroot
2455 # Default scripts path (these scripts are added to the
2456 # $chroot_dir/usr/bin and can be called with tazchroot script).
2457 script_dir=/usr/lib/slitaz/chroot-scripts/tazwok
2459 # List of directories to mount.
2460 list_dir="$LOCAL_REPOSITORY
2461 $SLITAZ_LOG$( [ "$undigest" ] && echo -e "\n$SLITAZ_DIR/$SLITAZ_VERSION/packages" )"
2463 create_chroot()
2465 mkdir -p \$chroot_dir
2466 for pkg in \$(tazwok build-depends toolchain --SLITAZ_DIR=\$SLITAZ_DIR --SLITAZ_VERSION=\$SLITAZ_VERSION${undigest:+ --undigest=\$undigest}); do
2467 tazpkg get-install \$pkg --root="\$chroot_dir"
2468 done
2470 # Store list of installed packages needed by cleanchroot.
2471 ls -1 \$chroot_dir/\$INSTALLED > \$chroot_dir/\$LOCALSTATE/chroot-pkgs
2473 sed -e "s~^SLITAZ_DIR=.*~SLITAZ_DIR=\$SLITAZ_DIR~" \\
2474 -e "s/^SLITAZ_VERSION=.*/SLITAZ_VERSION=\$SLITAZ_VERSION/" \\
2475 -i \$chroot_dir/etc/slitaz/slitaz.conf
2476 echo \$SLITAZ_VERSION > \$chroot_dir/etc/slitaz-release
2477 $( [ "$undigest" ] && echo ' echo "undigest='"$undigest"'" >> $chroot_dir/etc/slitaz/tazwok.conf')
2478 sed 's/LC_ALL/LC_ALL=POSIX/' -i \$chroot_dir/etc/profile
2480 # The build bot may run in a sandbox: link sandbox lockfile.
2481 [ -d \$LOCAL_REPOSITORY/sandbox ] && ln -s \$LOCAL_REPOSITORY/sandbox/proc/1 \$chroot_dir/proc/1
2484 mount_chroot()
2486 cp -a /etc/resolv.conf \$chroot_dir/etc/resolv.conf
2487 $( if [ "$USE_ONLINE_PKG" ]; then
2488 echo ' echo "$USE_ONLINE_PKG" > $chroot_dir$LOCALSTATE/mirror'
2489 else
2490 echo ' echo "$LOCAL_REPOSITORY/packages" > $chroot_dir$LOCALSTATE/mirror'
2491 fi
2493 mkdir -p \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming
2494 echo "\$LOCAL_REPOSITORY/packages-incoming" > \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming/mirror
2495 $( if [ "$undigest" ]; then
2496 echo ' mkdir -p $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION'
2497 if [ "$ref_USE_ONLINE_PKG" ]; then
2498 echo ' echo "$ref_USE_ONLINE_PKG" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror'
2499 else
2500 echo ' echo "$ref_LOCAL_REPOSITORY/packages" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror'
2501 fi
2502 fi )
2503 echo -e "\${LOCAL_REPOSITORY##*/}-incoming\nmain" > \$chroot_dir\$LOCALSTATE/priority
2504 mount -o bind /proc \$chroot_dir/proc
2505 mount -o bind /sys \$chroot_dir/sys
2506 mount -o bind /dev/pts \$chroot_dir/dev/pts
2507 mount -o bind /dev/shm \$chroot_dir/dev/shm
2508 for dir in \$list_dir; do
2509 mkdir -p \$dir \$chroot_dir\$dir
2510 mount \$dir \$chroot_dir\$dir
2511 done
2514 umount_chroot()
2516 for dir in \$list_dir; do
2517 umount \$chroot_dir\$dir
2518 done
2519 umount \$chroot_dir/dev/shm
2520 umount \$chroot_dir/dev/pts
2521 umount \$chroot_dir/sys
2522 umount \$chroot_dir/proc
2524 EOF
2527 ########################################################################
2528 ######################### END OF NEW FUNCTIONS #########################
2529 ########################################################################
2531 # List packages providing a virtual package.
2532 whoprovide()
2534 local i;
2535 for i in $(fgrep -l PROVIDE $WOK/*/receipt); do
2536 . $i
2537 case " $PROVIDE " in
2538 *\ $1\ *|*\ $1:*) echo $(basename $(dirname $i));;
2539 esac
2540 done
2543 ########################################################################
2544 # TAZWOK COMMANDS
2545 ########################
2547 case "$COMMAND" in
2548 stats)
2549 # Tazwok general statistics from the wok config file.
2551 get_tazwok_config
2552 echo -e "\n\033[1mTazwok configuration statistics\033[0m
2553 ================================================================================
2554 Wok directory : $WOK
2555 Packages repository : $PACKAGES_REPOSITORY
2556 Incoming repository : $INCOMING_REPOSITORY
2557 Sources repository : $SOURCES_REPOSITORY
2558 Log directory : $LOCAL_REPOSITORY/log
2559 Packages in the wok : `ls -1 $WOK | wc -l`
2560 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2561 Incoming packages : `ls -1 $INCOMING_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2562 ================================================================================\n"
2563 ;;
2564 edit)
2565 get_tazwok_config
2566 check_for_package_on_cmdline
2567 check_for_receipt
2568 $EDITOR $WOK/$PACKAGE/receipt
2569 ;;
2570 build-depends)
2571 # List dependencies to rebuild wok, or only a package.
2572 get_tazwok_config
2573 report(){ : ; }
2574 if [ ! "$PACKAGE" ] || [ "$PACKAGE" = toolchain ]; then
2575 scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
2576 --look_for=dep --with_dev --with_args
2577 else
2578 check_for_package_on_cmdline
2579 scan $PACKAGE --look_for=bdep --with_dev
2580 fi
2581 ;;
2582 gen-cooklist)
2583 check_root
2584 get_options_list="pkg"
2585 get_tazwok_config
2586 report(){ : ; }
2587 if ! [ "$pkg" ]; then
2588 if [ ! "$LIST" ] || [ "$LIST" = toolchain ]; then
2589 pkg="$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA"
2590 else
2591 check_for_list
2592 fi
2593 fi
2594 gen_cook_list
2595 ;;
2596 check-depends)
2597 # Check package depends /!\.
2598 get_tazwok_config
2599 echo ""
2600 echo -e "\033[1mCheck every receipt for DEPENDS - doesn't scan ELF files\033[0m
2601 ================================================================================"
2602 TMPDIR=/tmp/tazwok$$
2603 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
2605 # Build ALL_DEPENDS variable.
2606 scan_dep()
2608 local i
2609 ALL_DEPENDS="$ALL_DEPENDS$PACKAGE "
2610 for i in $DEPENDS $SUGGESTED ; do
2611 case " $ALL_DEPENDS " in
2612 *\ $i\ *) continue;;
2613 esac
2614 [ -d $WOK/$i ] || {
2615 ALL_DEPENDS="$ALL_DEPENDS$i "
2616 continue
2618 DEPENDS=""
2619 SUGGESTED=""
2620 . $WOK/$i/receipt
2621 scan_dep
2622 done
2625 # Check for ELF file.
2626 is_elf()
2628 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
2631 # Print shared library dependencies.
2632 ldd()
2634 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
2637 mkdir $TMPDIR
2638 cd $TMPDIR
2639 for i in $LOCALSTATE/files.list.lzma \
2640 $LOCALSTATE/undigest/*/files.list.lzma ; do
2641 [ -f $i ] && lzma d $i -so >> files.list
2642 done
2643 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
2644 tazpkg extract $pkg > /dev/null 2>&1
2645 . */receipt
2646 ALL_DEPENDS="$DEFAULT_DEPENDS "
2647 scan_dep
2648 find */fs -type f | while read file ; do
2649 is_elf $file || continue
2650 case "$file" in
2651 *.o|*.ko|*.ko.gz) continue;;
2652 esac
2653 ldd $file | while read lib rem; do
2654 case "$lib" in
2655 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
2656 continue;;
2657 esac
2658 for dep in $(fgrep $lib files.list | cut -d: -f1); do
2659 case " $ALL_DEPENDS " in
2660 *\ $dep\ *) continue 2;;
2661 esac
2662 for vdep in $(fgrep $dep $LOCALSTATE/packages.equiv | cut -d= -f1); do
2663 case " $ALL_DEPENDS " in
2664 *\ $vdep\ *) continue 3;;
2665 esac
2666 done
2667 done
2668 [ -n "$dep" ] || dep="UNKNOWN"
2669 echo "$(basename $pkg): ${file#*fs} depends on package $dep for the shared library $lib"
2670 done
2671 done
2672 rm -rf */
2673 done
2674 cd /tmp
2675 rm -rf $TMPDIR
2676 ;;
2677 check)
2678 # Check wok consistency.
2679 get_tazwok_config
2680 echo ""
2681 echo -e "\033[1mWok and packages checking\033[0m
2682 ================================================================================"
2683 cd $WOK
2684 for pkg in $(ls)
2685 do
2686 [ -f $pkg/receipt ] || continue
2687 RECEIPT= $pkg/receipt
2688 source_receipt
2689 [ "$PACKAGE" = "$pkg" ] || echo "Package $PACKAGE should be $pkg" >&2
2690 [ -n "$VERSION" ] || echo "Package $PACKAGE has no VERSION" >&2
2691 [ -n "$PACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded PACKED_SIZE" >&2
2692 [ -n "$UNPACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded UNPACKED_SIZE" >&2
2693 [ -n "$EXTRAVERSION" ] && echo "Package $PACKAGE has hardcoded EXTRAVERSION" >&2
2694 if [ -n "$WANTED" ]; then
2695 if [ ! -f $WANTED/receipt ]; then
2696 echo "Package $PACKAGE wants unknown $WANTED package" >&2
2697 else
2698 BASEVERSION=$(. $WANTED/receipt ; echo $VERSION)
2699 if [ "$VERSION" = "$WANTED" ]; then
2700 # BASEVERSION is computed in receipt
2701 fgrep -q '_pkg=' $pkg/receipt &&
2702 BASEVERSION=$VERSION
2703 fi
2704 if [ "$VERSION" != "$BASEVERSION" ]; then
2705 echo "Package $PACKAGE ($VERSION) wants $WANTED ($BASEVERSION)" >&2
2706 fi
2707 fi
2708 fi
2710 if [ -n "$CATEGORY" ]; then
2711 case " $(echo $CATEGORIES) " in
2712 *\ $CATEGORY\ *);;
2713 *) echo "Package $PACKAGE has an invalid CATEGORY" >&2;;
2714 esac
2715 else
2716 echo"Package $PACKAGE has no CATEGORY" >&2
2717 fi
2718 [ -n "$SHORT_DESC" ] || echo "Package $PACKAGE has no SHORT_DESC" >&2
2719 [ -n "$MAINTAINER" ] || echo "Package $PACKAGE has no MAINTAINER" >&2
2720 case "$WGET_URL" in
2721 ftp*|http*) busybox wget -s $WGET_URL 2> /dev/null ||
2722 echo "Package $PACKAGE has a wrong WGET_URL" >&2;;
2723 '') ;;
2724 *) echo "Package $PACKAGE has an invalid WGET_URL" >&2;;
2725 esac
2726 case "$WEB_SITE" in
2727 ftp*|http*);;
2728 '') echo "Package $PACKAGE has no WEB_SITE" >&2;;
2729 *) echo "Package $PACKAGE has an invalid WEB_SITE" >&2;;
2730 esac
2731 case "$MAINTAINER" in
2732 *\<*|*\>*) echo "Package $PACKAGE has an invalid MAINTAINER: $MAINTAINER" >&2;;
2733 esac
2734 case "$MAINTAINER" in
2735 *@*);;
2736 *) echo "Package $PACKAGE MAINTAINER is not an email address" >&2;;
2737 esac
2738 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2739 for i in $DEPENDS; do
2740 [ -d $i ] && continue
2741 [ -n "$(whoprovide $i)" ] && continue
2742 echo -e "$MSG $i"
2743 MSG=""
2744 done
2745 MSG="Missing build dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2746 for i in $BUILD_DEPENDS; do
2747 [ -d $i ] && continue
2748 [ -n "$(whoprovide $i)" ] && continue
2749 echo -e "$MSG $i"
2750 MSG=""
2751 done
2752 MSG="Dependency loop between $PACKAGE and :\n"
2753 ALL_DEPS=""
2754 check_for_deps_loop $PACKAGE $DEPENDS
2755 [ -d $WOK/$pkg/taz ] && for i in $BUILD_DEPENDS; do
2756 [ $WOK/$pkg/taz -nt $INSTALLED/$i/files.list ] && continue
2757 echo "$pkg should be rebuilt after $i installation"
2758 done
2759 done
2760 ;;
2761 list)
2762 # List packages in wok directory. User can specify a category.
2764 get_tazwok_config
2765 if [ "$2" = "category" ]; then
2766 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
2767 exit 0
2768 fi
2769 # Check for an asked category.
2770 if [ -n "$2" ]; then
2771 ASKED_CATEGORY=$2
2772 echo ""
2773 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
2774 horizontal_line
2775 for pkg in $WOK/*
2776 do
2777 [ ! -f $pkg/receipt ] && continue
2778 . $pkg/receipt
2779 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
2780 echo -n "$PACKAGE"
2781 echo -e "\033[28G $VERSION"
2782 packages=$(($packages+1))
2783 fi
2784 done
2785 horizontal_line
2786 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
2787 else
2788 # By default list all packages and version.
2789 echo ""
2790 echo -e "\033[1mList of packages in the wok\033[0m"
2791 horizontal_line
2792 for pkg in $WOK/*
2793 do
2794 [ ! -f $pkg/receipt ] && continue
2795 . $pkg/receipt
2796 echo -n "$PACKAGE"
2797 echo -en "\033[28G $VERSION"
2798 echo -e "\033[42G $CATEGORY"
2799 packages=$(($packages+1))
2800 done
2801 horizontal_line
2802 echo -e "$packages packages available in the wok.\n"
2803 fi
2804 ;;
2805 info)
2806 # Information about a package.
2808 get_tazwok_config
2809 check_for_package_on_cmdline
2810 check_for_receipt
2811 . $WOK/$PACKAGE/receipt
2812 echo ""
2813 echo -e "\033[1mTazwok package information\033[0m
2814 ================================================================================
2815 Package : $PACKAGE
2816 Version : $VERSION
2817 Category : $CATEGORY
2818 Short desc : $SHORT_DESC
2819 Maintainer : $MAINTAINER"
2820 if [ ! "$WEB_SITE" = "" ]; then
2821 echo "Web site : $WEB_SITE"
2822 fi
2823 if [ ! "$DEPENDS" = "" ]; then
2824 echo "Depends : $DEPENDS"
2825 fi
2826 if [ ! "$WANTED" = "" ]; then
2827 echo "Wanted src : $WANTED"
2828 fi
2829 horizontal_line
2830 echo ""
2831 ;;
2832 check-log)
2833 # We just cat the file log to view process info.
2835 get_tazwok_config
2836 if [ ! -f "$LOG" ]; then
2837 echo -e "\nNo process log found. The package is probably not cooked.\n" >&2
2838 exit 1
2839 else
2840 echo ""
2841 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
2842 horizontal_line
2843 cat $LOG
2844 horizontal_line
2845 echo ""
2846 if [ -s "$WOK/$PACKAGE/warning.txt" ]; then
2847 echo -e "\033[1mCook warning(s) for :\033[0m $PACKAGE"
2848 horizontal_line
2849 cat "$WOK/$PACKAGE/warning.txt"
2850 horizontal_line
2851 echo ""
2852 fi
2853 fi
2854 ;;
2855 search)
2856 # Search for a package by pattern or name.
2858 get_tazwok_config
2859 if [ -z "$2" ]; then
2860 echo -e "\nPlease specify a pattern or a package name to search." >&2
2861 echo -e "Example : 'tazwok search gcc'.\n" >&2
2862 exit 1
2863 fi
2864 echo ""
2865 echo -e "\033[1mSearch result for :\033[0m $2"
2866 horizontal_line
2867 list=`ls -1 $WOK | fgrep $2`
2868 for pkg in $list
2869 do
2870 . $WOK/$pkg/receipt
2871 echo -n "$PACKAGE "
2872 echo -en "\033[24G $VERSION"
2873 echo -e "\033[42G $CATEGORY"
2874 packages=$(($PACKAGEs+1))
2875 done
2876 horizontal_line
2877 echo "$packages packages found for : $2"
2878 echo ""
2879 ;;
2880 compile)
2881 # Configure and make a package with the receipt.
2883 get_tazwok_config
2884 source_lib report
2885 report start
2886 compile_package
2887 ;;
2888 genpkg)
2889 # Generate a package.
2891 get_tazwok_config
2892 source_lib report
2893 report start
2894 gen_package
2895 ;;
2896 cook)
2897 # Compile and generate a package. Just execute tazwok with
2898 # the good commands.
2900 check_root
2901 get_tazwok_config
2902 source_lib report
2903 report start
2904 db_md5=$(md5sum $dep_db $wan_db)
2905 update_wan_db
2906 check_for_commit
2907 sort -o $dep_db $dep_db
2908 sort -o $wan_db $wan_db
2909 if [ "$db_md5" != "$(md5sum $dep_db $wan_db)" ]; then
2910 grep -q "^#" $cookorder || sed 1i"#PlanSort" -i $cookorder
2911 fi
2912 cook
2913 ;;
2914 sort-cooklist)
2915 check_root
2916 get_tazwok_config
2917 check_for_list
2918 report(){ : ; }
2919 # When using sort-cooklist, the script should behave as for gen-cooklist
2920 # The only difference between these two is where the output is sent.
2921 COMMAND=gen-cooklist
2922 gen_cook_list
2923 cp -af $tmp/cooklist $LIST
2924 ;;
2925 cook-list)
2926 # Cook all packages listed in a file or in default cooklist.
2927 check_root
2928 get_options_list="pkg forced"
2929 get_tazwok_config
2930 source_lib report
2931 report start
2932 if ! [ "$pkg" ]; then
2933 [ "$LIST" ] && check_for_list
2934 fi
2935 gen_cook_list
2936 cook_list
2937 ;;
2938 clean)
2939 # Clean up a package work directory + those which want it.
2941 get_tazwok_config
2942 check_for_package_on_cmdline
2943 check_for_receipt
2944 source_lib report
2945 report start
2946 . $RECEIPT
2947 clean
2948 ;;
2949 gen-clean-wok)
2950 # Generate a clean wok from the current wok by copying all receipts
2951 # and stuff directory.
2953 get_tazwok_config
2954 source_lib report
2955 report start
2956 if [ -z "$ARG" ]; then
2957 echo -e "\nPlease specify the destination for the new clean wok.\n" >&2
2958 exit 1
2959 else
2960 dest=$ARG
2961 mkdir -p $dest
2962 fi
2963 report step "Creating clean wok in : $dest"
2964 for pkg in `ls -1 $WOK`
2965 do
2966 copy_cooking_stuff $WOK $pkg $dest
2967 done
2968 [ -d $WOK/.hg ] && cp -a $WOK/.hg $dest
2969 report end-step
2970 echo "Packages cleaned : `ls -1 $dest | wc -l`"
2971 echo ""
2972 ;;
2973 clean-wok)
2974 # Clean all packages in the work directory.
2976 get_tazwok_config
2977 source_lib report
2978 report start
2979 report step "Cleaning wok"
2980 for PACKAGE in `ls -1 $WOK`
2981 do
2982 set_common_path
2983 source_receipt
2984 clean
2985 done
2986 echo "`ls -1 $WOK | wc -l` packages cleaned."
2987 ;;
2988 clean-src)
2989 # Remove tarball unrelated to wok receipts from src repo.
2990 check_root
2991 get_options_list="forced"
2992 get_tazwok_config
2993 cd $SOURCES_REPOSITORY
2994 echo -n "Checking $SOURCES_REPOSITORY..."
2995 for TARBALL in *; do
2996 [ "$TARBALL" = sources.list ] && continue
2997 grep -q $'\t'$TARBALL$ $SOURCES_REPOSITORY/sources.list || \
2998 echo $TARBALL >> $tmp/obsolete
2999 done
3000 status
3001 if ! [ -f $tmp/obsolete ]; then
3002 echo "No sources need to be removed."
3003 exit 1
3004 fi
3005 echo ""
3006 echo -e "\033[1mObsolete/unrelated-to-wok sources :\033[0m"
3007 horizontal_line
3008 cat $tmp/obsolete
3009 horizontal_line
3010 echo "$(wc -l $tmp/obsolete | cut -f1 -d' ') tarballs to remove."
3011 echo ""
3012 echo -n "Please confirm before removing (type uppercase YES): "
3013 read answer
3014 if [ "$answer" = YES ]; then
3015 echo -n "Removing old sources..."
3016 cat $tmp/obsolete | while read i; do
3017 rm -f $SOURCES_REPOSITORY/$i
3018 done
3019 status
3020 fi
3021 ;;
3022 gen-list)
3023 get_tazwok_config
3024 if [ "$2" ]; then
3025 if [ -d "$2" ]; then
3026 pkg_repository=$2
3027 else
3028 echo -e "\nUnable to find directory : $2\n" >&2
3029 exit 1
3030 fi
3031 fi
3033 source_lib report
3034 report start
3035 if [ "$pkg_repository" ]; then
3036 gen_packages_db
3037 else
3038 pkg_repository=$PACKAGES_REPOSITORY && gen_packages_db
3039 pkg_repository=$INCOMING_REPOSITORY && gen_packages_db
3040 fi
3041 ;;
3042 check-list)
3043 # The directory to move into by default is the repository,
3044 # if $2 is not empty cd into $2.
3046 get_tazwok_config
3047 if [ "$2" ]; then
3048 if [ -d "$2" ]; then
3049 pkg_repository=$2
3050 else
3051 echo -e "\nUnable to find directory : $2\n" >&2
3052 exit 1
3053 fi
3054 fi
3056 source_lib report
3057 report start
3058 if [ "$pkg_repository" ]; then
3059 update_packages_db
3060 else
3061 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
3062 pkg_repository=$INCOMING_REPOSITORY && update_packages_db
3063 fi
3064 ;;
3065 new-tree)
3066 # Just create a few directories and generate an empty receipt to prepare
3067 # the creation of a new package.
3069 get_tazwok_config
3070 check_for_package_on_cmdline
3071 clean_wok=$LOCAL_REPOSITORY/clean-wok
3072 if [ -d $clean_wok/$PACKAGE ]; then
3073 echo -e "\n$PACKAGE package tree already exists.\n" >&2
3074 exit 1
3075 fi
3076 echo "Creating : $clean_wok/$PACKAGE"
3077 mkdir $clean_wok/$PACKAGE
3078 cd $clean_wok/$PACKAGE
3079 echo -n "Preparing the receipt..."
3081 # Default receipt begin.
3083 echo "# SliTaz package receipt." > receipt
3084 echo "" >> receipt
3085 echo "PACKAGE=\"$PACKAGE\"" >> receipt
3086 # Finish the empty receipt.
3087 cat >> receipt << "EOF"
3088 VERSION=""
3089 CATEGORY=""
3090 SHORT_DESC=""
3091 MAINTAINER=""
3092 DEPENDS=""
3093 TARBALL="$PACKAGE-$VERSION.tar.gz"
3094 WEB_SITE=""
3095 WGET_URL=""
3097 # Rules to configure and make the package.
3098 compile_rules()
3100 cd $src
3101 ./configure $CONFIGURE_ARGS && make && make install
3104 # Rules to gen a SliTaz package suitable for Tazpkg.
3105 genpkg_rules()
3107 mkdir -p $fs/usr
3108 cp -a $_pkg/usr/bin $fs/usr
3111 EOF
3113 # Default receipt end.
3115 status
3116 # Interactive mode, asking and seding.
3117 if [ "$3" = "--interactive" ]; then
3118 echo "Entering interactive mode..."
3119 horizontal_line
3120 echo "Package : $PACKAGE"
3121 # Version.
3122 echo -n "Version : " ; read anser
3123 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
3124 # Category.
3125 echo -n "Category : " ; read anser
3126 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
3127 # Short description.
3128 echo -n "Short desc : " ; read anser
3129 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
3130 # Maintainer.
3131 echo -n "Maintainer : " ; read anser
3132 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
3133 # Web site.
3134 echo -n "Web site : " ; read anser
3135 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
3136 echo ""
3137 # Wget URL.
3138 echo "Wget URL to download source tarball."
3139 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
3140 echo -n "Wget url : " ; read anser
3141 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
3142 # Ask for a stuff dir.
3143 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
3144 if [ "$anser" = "y" ]; then
3145 echo -n "Creating the stuff directory..."
3146 mkdir stuff && status
3147 fi
3148 # Ask for a description file.
3149 echo -n "Are you going to write a description ? (y/N) : " ; read anser
3150 if [ "$anser" = "y" ]; then
3151 echo -n "Creating the description.txt file..."
3152 echo "" > description.txt && status
3153 fi
3154 horizontal_line
3155 echo ""
3156 fi
3157 ;;
3158 remove)
3159 # Remove a package from the wok.
3161 get_tazwok_config
3162 check_for_package_on_cmdline
3163 echo ""
3164 echo -n "Please confirm deletion (y/N) : "; read anser
3165 if [ "$anser" = "y" ]; then
3166 echo -n "Removing $PACKAGE..."
3167 rm -rf $WOK/$PACKAGE && status
3168 echo ""
3169 fi
3170 ;;
3171 update-wok)
3172 # Pull and update a Hg wok.
3173 get_options_list="local"
3174 get_tazwok_config
3175 source_lib report
3176 report start
3177 clean_wok=$LOCAL_REPOSITORY/clean-wok
3178 cd $clean_wok
3179 if ! [ "$local" ]; then
3180 if [ "$WOK_UPDATE_METHOD" = hg ]; then
3181 if ! [ -f "$INSTALLED/mercurial/receipt" ]; then
3183 # Auto-install only if we are in a cook chroot.
3184 if [ -x /usr/bin/clean-chroot ]; then
3185 tazpkg get-install mercurial
3186 else
3187 echo "" >&2
3188 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
3189 echo "">&2
3190 exit 1
3191 fi
3192 fi
3194 report step "Getting wok changes using hg"
3195 if [ -d .hg ]; then
3196 hg pull -u || exit 1
3197 else
3198 hg clone $HG_WOK . || exit 1
3199 fi
3200 report end-step
3201 [ -x /usr/bin/clean-chroot ] && clean-chroot
3202 else
3203 report step "Getting wok changes using tarball"
3204 { mkdir .tmp && cd .tmp
3205 wget "$TARBALL_WOK" &&
3206 case $TARBALL_WOK in
3207 *bz2) tar xjf *.bz2 -C wok; rm *.bz2;;
3208 *lzma) unlzma -c *.lzma | tar xf - -C wok; rm *.lzma ;;
3209 *gz) tar xzf *.gz -C wok; rm*.gz ;;
3210 esac &&
3211 rm -r $(ls -d $clean_wok/*) &&
3212 cp -a wok/* $clean_wok &&
3213 cd .. &&
3214 rm -r .tmp
3215 } || { echo "That's not cool: it fails!" >&2
3216 report end-step
3217 exit 1; }
3218 report end-step
3219 fi
3220 fi
3221 report step "Appending changes to wok"
3223 # Handle removed files/dir.
3224 cd $WOK
3225 for dir in *; do
3226 [ -d "$clean_wok/$dir" ] || rm -rf $dir
3227 done
3228 for file in */receipt */description.txt; do
3229 [ -f "$clean_wok/$file" ] || rm -rf $file
3230 done
3231 for i in $(find */stuff 2>/dev/null); do
3232 [ -e "$clean_wok/$i" ] || rm -rf $i
3233 done
3235 cp -a $clean_wok/* $WOK
3236 report end-step
3237 ;;
3238 maintainers)
3239 get_tazwok_config
3240 echo ""
3241 echo "List of maintainers for: $WOK"
3242 horizontal_line
3243 touch /tmp/slitaz-maintainers
3244 for pkg in $WOK/*
3245 do
3246 . $pkg/receipt
3247 if ! fgrep -q "$MAINTAINER" /tmp/slitaz-maintainers; then
3248 echo "$MAINTAINER" >> /tmp/slitaz-maintainers
3249 echo "$MAINTAINER"
3250 fi
3251 done
3252 horizontal_line
3253 echo "Maintainers: `cat /tmp/slitaz-maintainers | wc -l`"
3254 echo ""
3255 # Remove tmp files
3256 rm -f /tmp/slitaz-maintainers
3257 ;;
3258 maintained-by)
3259 # Search for packages maintained by a contributor.
3260 get_tazwok_config
3261 if [ ! -n "$2" ]; then
3262 echo "Specify a name or email of a maintainer." >&2
3263 exit 1
3264 fi
3265 echo "Maintainer packages"
3266 horizontal_line
3267 for pkg in $WOK/*
3268 do
3269 . $pkg/receipt
3270 if echo "$MAINTAINER" | fgrep -q "$2"; then
3271 echo "$PACKAGE"
3272 packages=$(($PACKAGEs+1))
3273 fi
3274 done
3275 horizontal_line
3276 echo "Packages maintained by $2: $PACKAGEs"
3277 echo ""
3278 ;;
3279 tags)
3280 get_tazwok_config
3281 echo -e "\n\033[1mTags list :\033[0m"
3282 horizontal_line
3283 cd $WOK
3284 for i in */receipt; do
3285 unset TAGS
3286 source $i
3287 for t in $TAGS; do
3288 grep -q ^$t$ $tmp/tags && continue
3289 echo $t | tee -a $tmp/tags
3290 done
3291 done
3292 horizontal_line
3293 echo "$(wc -l $tmp/tags | cut -f1 -d ' ') tags listed."
3294 ;;
3295 check-src)
3296 # Verify if upstream package is still available.
3298 get_tazwok_config
3299 check_for_package_on_cmdline
3300 check_for_receipt
3301 source_receipt
3302 check_src()
3304 for url in $@; do
3305 busybox wget -s $url 2>/dev/null && break
3306 done
3308 if [ "$WGET_URL" ];then
3309 echo -n "$PACKAGE : "
3310 check_src $WGET_URL
3311 status
3312 else
3313 echo "No tarball to check for $PACKAGE"
3314 fi
3315 ;;
3316 gen-src)
3317 get_tazwok_config
3318 if [ "$2" ]; then
3319 if [ -d "$2" ]; then
3320 src_repository=$2
3321 else
3322 echo -e "\nUnable to find directory : $2\n" >&2
3323 exit 1
3324 fi
3325 fi
3326 echo -n "Rebuilding sources.list file"
3327 [ $src_repository ] || src_repository="$SOURCES_REPOSITORY"
3328 gen_sources_list $src_repository
3329 status
3330 ;;
3331 get-src)
3332 check_root
3333 get_options_list="target nounpack"
3334 get_tazwok_config
3335 check_for_package_on_cmdline
3336 check_for_receipt
3337 source_receipt
3338 if [ "$WGET_URL" ];then
3339 source_lib report
3340 report start
3341 check_for_tarball
3342 else
3343 echo "No tarball to download for $PACKAGE"
3344 fi
3345 ;;
3346 check-commit)
3347 check_root
3348 get_options_list="missing forced"
3349 get_tazwok_config
3350 source_lib report
3351 report start
3352 if [ "$forced" ]; then
3353 rm -f $WOK/*/md5
3354 unset forced
3355 fi
3356 if [ "$missing" ]; then
3357 pkg=$(ls -1 $WOK)
3358 else
3359 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3360 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3361 } | sort -u)"
3362 fi
3363 gen_cook_list
3364 ;;
3365 cook-commit)
3366 check_root
3367 get_options_list="missing forced"
3368 get_tazwok_config
3369 source_lib report
3370 report start
3371 if [ "$forced" ]; then
3372 rm -f $WOK/*/md5
3373 unset forced
3374 fi
3375 if [ "$missing" ]; then
3376 pkg=$(ls -1 $WOK)
3377 else
3378 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3379 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3380 } | sort -u)"
3381 fi
3382 gen_cook_list
3383 cook_list
3384 ;;
3385 cook-all)
3386 check_root
3387 get_options_list="forced missing"
3388 get_tazwok_config
3389 source_lib report
3390 report start
3391 if [ "$missing" ]; then
3392 pkg=$(ls -1 $WOK)
3393 else
3394 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
3395 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
3396 } | sort -u)"
3397 fi
3398 gen_cook_list
3399 cook_list
3400 ;;
3401 gen-wok-db)
3402 check_root
3403 get_tazwok_config
3404 source_lib report
3405 report start
3406 gen_wok_db
3407 ;;
3408 report)
3409 get_tazwok_config
3410 cd $PACKAGES_REPOSITORY
3411 if [ "$2" ]; then
3412 case $2 in
3413 commit|cooklist|incoming|broken|blocked)
3414 show="$2"
3415 ;;
3416 *)
3417 echo "usage : tazwok report [commit|cooklist|incoming|broken|blocked]" >&2
3418 exit 1
3419 ;;
3420 esac
3421 else
3422 show="commit cooklist incoming broken blocked"
3423 fi
3424 for i in $show; do
3425 if [ -s $i ]; then
3426 echo ""
3427 echo -e "\033[1m$i\033[0m"
3428 horizontal_line
3429 cat $i
3430 horizontal_line
3431 echo ""
3432 fi
3433 done
3434 ;;
3435 check-incoming)
3436 check_root
3437 get_options_list="forced"
3438 get_tazwok_config
3439 source_lib report
3440 report start
3441 [ -f $LOCAL_RESOSITORY/incoming ] && rm [ -f $LOCAL_REPOSITORY/incoming ]
3442 report step "Checking $INCOMING_REPOSITORY"
3443 report open-bloc
3444 [ -f $LOCAL_REPOSITORY/log/incoming.html ] && rm $LOCAL_REPOSITORY/log/incoming.html
3445 report sublog $LOCAL_REPOSITORY/log/incoming.html
3446 echo "incoming" > $LOCAL_REPOSITORY/log/package
3447 check_for_incoming
3448 report end-sublog
3449 report close-bloc
3450 ;;
3451 configure-chroot)
3452 check_root
3453 get_tazwok_config
3454 if [ -f /usr/bin/tazchroot ]; then
3455 cd $LOCAL_REPOSITORY
3456 configure_tazchroot
3457 else
3458 echo "The package tazchroot needs to be installed" >&2
3459 exit 1
3460 fi
3461 ;;
3462 chroot)
3463 check_root
3464 get_tazwok_config
3465 # Merge this and the other chroot function ?.
3466 if [ -f /usr/bin/tazchroot ]; then
3467 cd $LOCAL_REPOSITORY
3468 [ ! -f tazchroot.conf ] && configure_tazchroot
3469 tazchroot
3470 else
3471 echo "The package tazchroot needs to be installed" >&2
3472 exit 1
3473 fi
3474 ;;
3475 cook-toolchain)
3476 check_root
3477 get_tazwok_config
3478 echo -n "" > $PACKAGES_REPOSITORY/broken
3479 if [ -f /usr/bin/tazchroot ]; then
3480 cd $LOCAL_REPOSITORY
3481 [ -f tazchroot.conf ] || configure_tazchroot
3483 # Plan to recook all packages.
3484 if tazchroot cook-toolchain; then
3485 source_lib report
3486 report start
3487 pkg="$(grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt \
3488 $INCOMING_REPOSITORY/packages.txt | sort -u)"
3489 forced=yes
3490 gen_cook_list
3491 fi
3493 # Remove chroot where toolchain has been cooked.
3494 source $LOCAL_REPOSITORY/tazchroot.conf
3495 rm -r $LOCAL_REPOSITORY/chroot
3497 else
3498 echo -e "\nThe package tazchroot needs to be installed.\n" >&2
3499 exit 1
3500 fi
3501 ;;
3502 webserver)
3503 check_root
3504 get_tazwok_config
3505 if [ "$ARG" = on ]; then
3506 if [ "$WEBSERVER" ] && [ -f "$WEBSERVER/repositories.list" ] && \
3507 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3508 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3509 exit 1
3510 fi
3511 if ! [ -f $LOCAL_REPOSITORY/tazchroot.conf ]; then
3512 tazwok configure-chroot ${undigest:+--undigest=$undigest} --SLITAZ_VERSION=$SLITAZ_VERSION --SLITAZ_DIR=$SLITAZ_DIR
3513 fi
3514 for pkg in php lighttpd; do
3515 [ -d $INSTALLED/$pkg ] || missing="$missing $pkg"
3516 done
3517 if [ "$missing" ]; then
3518 echo "You need to install these packages to start webserver: $missing." >&2
3519 exit 1
3520 fi
3521 if [ ! -f "$LOCAL_REPOSITORY/tazwok.conf" ]; then
3522 echo "Copying /etc/slitaz/tazwok.conf to $LOCAL_REPOSITORY/tazwok.conf: webserver is configured repository-by-repository."
3523 cp /etc/slitaz/tazwok.conf $LOCAL_REPOSITORY
3524 fi
3525 if ! [ "$WEBSERVER" ]; then
3526 echo -n "Where to store php pages (default: /var/www/vhosts/bb)? "
3527 read WEBSERVER
3528 [ "$WEBSERVER" ] || WEBSERVER="/var/www/vhosts/bb"
3529 fi
3530 if [ -f "$WEBSERVER/repositories.list" ] && \
3531 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
3532 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
3533 exit 1
3534 fi
3535 mkdir -p $WEBSERVER
3536 echo "${undigest:-$SLITAZ_VERSION}" >> $WEBSERVER/repositories.list
3537 for file in index.php log.php download.php; do
3538 [ -f "$WEBSERVER/$file" ] || ln -s /usr/share/slitaz/web-bb/$file $WEBSERVER
3539 done
3540 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3541 ln -s $dir $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3542 done
3543 source $LOCAL_REPOSITORY/tazchroot.conf
3544 echo "<?php
3546 // Web interface configuration
3548 \$version=\"${undigest:-$SLITAZ_VERSION}\";
3549 \$chroot=\"$chroot_dir\";
3550 \$lockfile=\"\$chroot/proc/1/status\";
3551 \$db_dir=\"$PACKAGES_REPOSITORY\";
3552 \$log_dir=\"$LOCAL_REPOSITORY/log\";
3553 \$packages=\"$PACKAGES_REPOSITORY\";
3554 \$incoming=\"$INCOMING_REPOSITORY\";
3555 \$wok=\"$WOK\";
3557 ?>" > $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3558 [ -L "$WEBSERVER/web" ] || ln -s /usr/share/slitaz/web $WEBSERVER
3559 echo "WEBSERVER=\"$WEBSERVER\"" >> $LOCAL_REPOSITORY/tazwok.conf
3560 if [ -L "$WEBSERVER/conf.php" ]; then
3561 echo "Do you want to make ${undigest:-$SLITAZ_VERSION} the default page (y/N) ? "
3562 read answer
3563 if [ "$answer" = y ]; then
3564 rm $WEBSERVER/conf.php
3565 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3566 fi
3567 else
3568 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
3569 fi
3570 elif [ "$ARG" = off ]; then
3571 if ! [ "$WEBSERVER" ]; then
3572 echo "No webserver running for ${undigest:-$SLITAZ_VERSION}" >&2
3573 exit 1
3574 fi
3575 sed '/^WEBSERVER/d' -i $LOCAL_REPOSITORY/tazwok.conf
3576 sed "/^${undigest:-$SLITAZ_VERSION}$/d" -i $WEBSERVER/repositories.list
3577 rm $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
3578 for dir in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY; do
3579 rm $WEBSERVER/${undigest:-$SLITAZ_VERSION}-${dir##*/}
3580 done
3581 if ! [ -s "$WEBSERVER/repositories.list" ]; then
3582 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"
3583 rm $WEBSERVER/conf.php
3584 elif [ "$(readlink $WEBSERVER/conf.php)" = "$WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php" ]; then
3585 echo "${undigest:-$SLITAZ_VERSION} was the default version to use; switched to : $(sed 1!d $WEBSERVER/repositories.list)"
3586 rm $WEBSERVER/conf.php
3587 ln -s $WEBSERVER/conf-$(sed 1!d $WEBSERVER/repositories.list).php $WEBSERVER/conf.php
3588 fi
3589 else
3590 echo "Usage: tazwok webserver on/off" >&2
3591 exit 1
3592 fi
3593 ;;
3594 block)
3595 # Add a pkg name to the list of blocked packages.
3596 get_tazwok_config
3597 check_root
3598 check_for_package_on_cmdline
3599 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3600 echo "Can't find $PACKAGE in wok." >&2
3601 echo ""
3602 exit 1
3603 fi
3604 echo ""
3605 if grep -qs "^$PACKAGE$" $blocked; then
3606 echo "$PACKAGE is already in the blocked packages list." >&2
3607 echo ""
3608 exit 1
3609 else
3610 echo -n "Adding $PACKAGE to : $blocked... "
3611 echo "$PACKAGE" >> $blocked
3612 status
3613 if grep -q "^$PACKAGE$" $cooklist; then
3614 echo -n "Removing $PACKAGE from : $cooklist... "
3615 sed -i /"^$PACKAGE$"/d $cooklist
3616 status
3617 fi
3618 fi
3619 echo "" ;;
3620 unblock)
3621 # Remove a pkg name from the list of blocked packages.
3622 get_tazwok_config
3623 check_root
3624 check_for_package_on_cmdline
3625 if ! [ -f $WOK/$PACKAGE/receipt ]; then
3626 echo "Can't find $PACKAGE in wok." >&2
3627 echo ""
3628 exit 1
3629 fi
3630 echo ""
3631 if grep -qs "^$PACKAGE$" $blocked; then
3632 echo -n "Removing $PACKAGE from : $blocked... "
3633 sed -i /"^$PACKAGE$"/d $blocked
3634 sed -i '/^$/d' $blocked
3635 status
3636 else
3637 echo "$PACKAGE is not in the blocked packages list." >&2
3638 echo ""
3639 exit 1
3640 fi
3641 echo "" ;;
3642 usage|*)
3643 # Print usage also for all unknown commands.
3645 usage
3646 ;;
3647 esac
3649 # If a cook command has been used, refresh ID of the repository to avoid
3650 # useless upgrade at next cook command.
3651 case $COMMAND in
3652 cook*)
3653 for repo in $PACKAGES_REPOSITORY $INCOMING_REPOSITORY \
3654 $( [ "$undigest" -a ! "$ref_USE_ONLINE_PKG" ] && echo $ref_PACKAGES_REPOSITORY ); do
3655 [ -f $repo/ID ] || continue
3656 MIRROR_path=$(grep -l "^$repo$" $LOCALSTATE/mirror $LOCALSTATE/undigest/*/mirror)
3657 LOCALSTATE_path=${MIRROR_path%/mirror}
3658 cp -a $repo/ID $LOCALSTATE_path
3659 done
3660 ;;
3661 esac
3663 report stop 2>/dev/null
3664 exit 0