tazwok view tazwok @ rev 255

Forgotten code: support https (from changesets 179 & 182 of tazwok)
author Antoine Bodin <gokhlayeh@slitaz.org>
date Sat Feb 12 14:44:06 2011 +0100 (2011-02-12)
parents f91a9bc05a97
children edfb3f3deb75
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=3.9.0
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 check Check every receipt for common errors.
37 check-log Check the process log file of a package.
38 check-depends* Check every receipt for DEPENDS - doesn't scan ELF files.
39 check-src Check upstream tarball for package in the wok.
40 search Search for a package in the wok by pattern or name.
41 compile Configure and build a package using the receipt rules.
42 genpkg Generate a suitable package for Tazpkg with the rules.
43 cook Compile and generate a package directly.
44 cook-list Cook all packages specified in the list by order.
45 cook-commit Cook all modified receipts.
46 cook-all Cook all packages excepted toolchain.
47 cook-toolchain Cook the toolchain packages.
48 gen-cooklist Generate a sorted cooklist using packages or list.
49 sort-cooklist Sort the cooklist given in argument.
50 get-src Download the tarball of the package given in argument.
51 clean Clean all generated files in the package tree.
52 new-tree Prepare a new package tree and receipt (--interactive).
53 gen-list (Re-)Generate a packages list for a repository.
54 check-list Update packages lists for a repository.
55 gen-wok-db (Re-)Generate wok lists with depends and wanted datas.
56 gen-clean-wok Generate a clean wok in a dir.
57 clean-wok Clean entirely the wok.
58 remove Remove a package from the wok.
59 webserver Enable/disable webserver on localhost.
60 hgup Pull and update a wok under Hg.
61 maintainers List all maintainers in the wok.
62 maintained-by List packages maintained by a contributor.\n
64 You can use `basename $0` command --help to list avaible options.
65 \033[1mImportant - *: \033[0m Commands which need a rewrite."
66 }
68 # This function display an error message without returning any error code.
69 # It also log the message in source package's warnings.txt; this file can be
70 # used on an eventual package page on website to display cooking warnings.
71 tazwok_warning()
72 {
73 echo -e "tazwok: $1" >&2
74 echo -e "$1" >> $WOK/${WANTED:-$PACKAGE}/warning.txt
75 return
76 }
78 ########################################################################
79 # TAZWOK VARIABLES & INITIAL CONFIGURATION
80 ########################
82 get_tazwok_config()
83 {
84 # Get configuration file.
85 get_config
87 # Define & get options.
88 get_options_list="$get_options_list SLITAZ_DIR SLITAZ_VERSION undigest"
89 get_options
91 if [ "$undigest" ]; then
92 LOCAL_REPOSITORY=$SLITAZ_DIR/$undigest
93 else
94 LOCAL_REPOSITORY=$SLITAZ_DIR/$SLITAZ_VERSION
95 fi
97 if ! [ "$save_dir" ]; then
98 if [ -f $LOCAL_REPOSITORY/tazwok.conf ] || [ -f $LOCAL_REPOSITORY/slitaz.conf ]; then
99 save_dir=$LOCAL_REPOSITORY
100 [ -f $LOCAL_REPOSITORY/slitaz.conf ] && source $LOCAL_REPOSITORY/slitaz.conf
101 cd $save_dir
102 get_tazwok_config
103 unset save_dir
104 return
105 fi
106 fi
108 # The path to the most important files/dir used by Tazwok.
109 PACKAGES_REPOSITORY=$LOCAL_REPOSITORY/packages
110 WOK=$LOCAL_REPOSITORY/wok
111 INCOMING_REPOSITORY=$LOCAL_REPOSITORY/packages-incoming
112 SOURCES_REPOSITORY=$LOCAL_REPOSITORY/src
113 set_common_path
115 # /!\ This part needs some changes.
116 # Basically, get theses files from the net if they are missing.
117 dep_db=$INCOMING_REPOSITORY/wok-depends.txt
118 wan_db=$INCOMING_REPOSITORY/wok-wanted.txt
119 [ -f $dep_db ] || touch $dep_db
120 [ -f $wan_db ] || touch $wan_db
121 [ -f $PACKAGES_REPOSITORY/cookorder.txt ] || touch $PACKAGES_REPOSITORY/cookorder.txt
123 # Check commons directories, create them if user is root.
124 if test $(id -u) = 0 ; then
125 check_dir $WOK || chmod 777 $WOK
126 check_dir $PACKAGES_REPOSITORY
127 check_dir $SOURCES_REPOSITORY
128 check_dir $INCOMING_REPOSITORY
129 check_dir $LOCAL_REPOSITORY/log
130 fi
132 # Some files are needed by tazwok in PACKAGES_REPOSITORY. Create
133 # them if they are missing.
134 for file in broken blocked commit incoming cooklist; do
135 [ ! -f $PACKAGES_REPOSITORY/$file ] && touch $PACKAGES_REPOSITORY/$file
136 done
138 # Limit memory usage.
139 ulimit -v $(awk '/MemTotal/ { print int(($2*80)/100) }' < /proc/meminfo)
140 }
142 # Used in several functions.
143 set_common_path()
144 {
145 # The receipt is used to compile the source code and
146 # generate suitable packages for Tazpkg.
147 RECEIPT="$WOK/$PACKAGE/receipt"
149 # The path to the process log file.
150 LOG="$WOK/$PACKAGE/process.log"
151 }
153 ########################################################################
154 # TAZWOK CHECK FUNCTIONS
155 ########################
157 # Check for a package name on cmdline.
158 check_for_package_on_cmdline()
159 {
160 if [ ! "$PACKAGE" ]; then
161 echo -e "\nYou must specify a package name on the command line." >&2
162 echo -e "Example : tazwok $COMMAND package\n" >&2
163 exit 1
164 fi
165 }
167 # Check for the receipt of a package used to cook.
168 check_for_receipt()
169 {
170 if [ ! -f "$RECEIPT" ]; then
171 echo -e "\nUnable to find the receipt : $RECEIPT\n" >&2
172 exit 1
173 fi
174 }
176 # Check for a specified file list on cmdline.
177 check_for_list()
178 {
179 if [ ! "$LIST" ]; then
180 echo -e "\nPlease specify the path to the list of packages to cook.\n" >&2
181 exit 1
182 fi
184 # Check if the list of packages exists.
185 if [ -f "$LIST" ]; then
186 LIST=`cat $LIST`
187 else
188 echo -e "\nUnable to find $LIST packages list.\n" >&2
189 exit 1
190 fi
192 if [ ! "$LIST" ]; then
193 echo -e "\nList is empty.\n" >&2
194 exit 1
195 fi
196 }
198 check_for_pkg_in_wok()
199 {
200 [ -f $WOK/$PACKAGE/receipt ] && return
201 if [ "$undigest" ]; then
202 [ -f "$SLITAZ_VERSION/wok/$PACKAGE/receipt" ] && return 1
203 grep -q ^$PACKAGE$ $SLITAZ_DIR/$SLITAZ_VERSION/packages/packages.txt && return 1
204 fi
205 echo "Can't find $PACKAGE in wok or mirror" >&2
206 return 2
207 }
209 ########################################################################
210 # TAZWOK CORE FUNCTIONS
211 ########################
213 remove_src()
214 {
215 [ "$WANTED" ] && return
216 look_for_cookopt !remove_src && return
217 if [ ! -d $WOK/$PACKAGE/install ] && [ "$src" ] && [ -d "$src/_pkg" ]; then
218 check_for_var_modification _pkg src || return
219 mv "$src/_pkg" $WOK/$PACKAGE/install
220 fi
222 # Don't remove sources if a package use src variable in his
223 # genpkg_rules: it maybe need something inside.
224 for i in $PACKAGE $(look_for_rwanted); do
225 sed -n '/^genpkg_rules\(\)/','/}/'p $WOK/$i/receipt | \
226 fgrep -q '$src' && tazwok_warning "Sources will not be removed \
227 because $i use \$src in his receipt." && return
228 done
230 report step "Removing sources directory"
231 rm -fr "$src"
232 report end-step
233 }
235 # Check $COOK_OPT; usage : get_cookopt particular_opt
236 # Return error if not founded
237 # Return args if the opt is in the format opt=arg1:arg2:etc
238 look_for_cookopt()
239 {
240 for arg in $COOK_OPT; do
241 case $arg in
242 $1=*)
243 arg=${arg#$1=}
244 while [ "$arg" ]; do
245 echo "${arg%%:*}"
246 [ "${arg/:}" = "$arg" ] && return
247 arg=${arg#*:}
248 done
249 ;;
250 $1)
251 return
252 ;;
253 esac
254 done
255 return 1
256 }
258 # Check for the wanted package if specified in WANTED
259 # receipt variable. Set the $src/$_pkg variable to help compile
260 # and generate packages.
261 check_for_wanted()
262 {
263 if [ "$WANTED" ]; then
264 report "Checking for the wanted package"
265 if [ ! -d "$WOK/$WANTED" ]; then
266 report exit "\nWanted package is missing in the work directory.\n"
267 fi
269 # Checking for buildtree of Wanted package
270 if [ ! -d "$WOK/$WANTED/taz" ]; then
271 echo -e "\n\nSource files of wanted package is missing in the work directory."
272 echo -n "Would you like to build the missing package (y/N) ? " ; read anser
273 if [ "$anser" == "y" ]; then
274 tazwok cook $WANTED
275 else
276 report exit "\nWanted package source tree is missing in the work directory.\n"
277 fi
278 fi
279 report end-step
281 # Set wanted src path.
282 set_src_path && set_pkg_path
284 fi
285 }
287 # Check for build dependencies, notify user and install if specified.
288 check_for_build_depends()
289 {
290 [ "$WANTED" ] && return
291 [ "$CATEGORY" = meta ] && ! fgrep -q compile_rules $RECEIPT && return
292 report step "Looking for build dependencies"
294 # Keep the list of previously installed build_depends then compare
295 # it with new build_depends to know what to install and what to
296 # what to remove.
297 plan_remove=" $MISSING_PACKAGE $remove_later "
298 [ ! "${plan_remove// }" ] && unset plan_remove
299 unset MISSING_PACKAGE remove_later
300 rwanted=$(look_for_rwanted)
302 for pkg in $(scan $PACKAGE --look_for=bdep --with_dev | \
303 fgrep -v $(for i in $(look_for_rwanted) $PACKAGE; do echo " -e $i"; done))
304 do
306 # Delay the removing of previous cook depends if they are needed
307 # for next cook too.
308 if [ ! -d "$INSTALLED/$pkg" ] ; then
309 MISSING_PACKAGE="$MISSING_PACKAGE $pkg"
310 fi
311 if [ "$plan_remove" != "${plan_remove/ $pkg }" ]; then
312 plan_remove="${plan_remove/ $pkg / }"
313 remove_later="$remove_later $pkg"
314 fi
315 if grep -q ^$pkg$ $PACKAGES_REPOSITORY/broken; then
316 broken="$broken$pkg "
317 fi
318 done
320 # Don't cook if a depend is broken.
321 if [ "$broken" ]; then
322 MISSING_PACKAGE=$plan_remove
323 echo "Can't cook $PACKAGE because broken depend(s) : $broken" >&2
324 unset plan_remove broken
326 # Set report step to failed.
327 report_return_code=1
328 report end-step
329 return 1
330 fi
331 if [ "$MISSING_PACKAGE" ]; then
332 install_missing()
333 {
334 echo "Installing missing packages : $MISSING_PACKAGE"
335 for pkg in $MISSING_PACKAGE; do
336 [ -d "$INSTALLED/$pkg" ] || tazpkg get-install $pkg
337 done
338 }
339 if [ "$auto_install" = yes ]; then
340 install_missing
341 else
342 echo "================================================================================"
343 for pkg in $MISSING_PACKAGE
344 do
345 echo "Missing : $pkg"
346 done
347 echo "================================================================================"
348 echo "You can continue, exit or install missing dependencies."
349 echo -n "Install, continue or exit (install/y/N) ? "; read answer
350 case $answer in
351 install)
352 install_missing ;;
353 y|yes)
354 unset MISSING_PACKAGE;;
355 *)
356 report stop
357 exit 0 ;;
358 esac
359 fi
360 fi
361 report end-step
362 remove_build_depends $plan_remove
363 unset plan_remove
364 }
366 remove_build_depends()
367 {
368 [ "$1" ] || return
369 report step "Removing previous build dependencies"
370 echo "Removing theses packages : $@"
371 for pkg in $@; do
372 [ -d "$INSTALLED/$pkg" ] && tazpkg remove $pkg --auto
373 done
374 report end-step
375 }
377 # Check if we can use the new way to handle tarball
378 # or if we keep the previous method by check for
379 # _pkg=/src= in receipt and reverse-wanted.
380 check_for_var_modification()
381 {
382 for var in $@; do
383 for pkg in $PACKAGE $(look_for_wanted) $(look_for_rwanted); do
384 [ -f $WOK/$pkg/receipt ] || continue
385 fgrep -q "$var=" $WOK/$pkg/receipt && return 1
386 done
387 done
389 # Tweak to make if; then...; fi function working with this one.
390 echo -n ""
391 }
393 set_src_path()
394 {
395 if check_for_var_modification src _pkg; then
396 src=$WOK/${WANTED:-$PACKAGE}/${WANTED:-$PACKAGE}-$VERSION
397 else
398 src=$WOK/${WANTED:-$PACKAGE}/${SOURCE:-${WANTED:-$PACKAGE}}-$VERSION
399 fi
400 }
402 set_pkg_path()
403 {
404 if [ -d $WOK/${WANTED:-$PACKAGE}/install ] ; then
405 _pkg=$WOK/${WANTED:-$PACKAGE}/install
406 else
407 _pkg=$src/_pkg
408 fi
409 }
411 # Output $VERSION-$EXTRAVERSION using packages.txt
412 get_pkg_version()
413 {
414 [ "$PACKAGE" ] || return
415 grep -m1 -A1 -sh ^$PACKAGE$ $1/packages.txt | tail -1 | sed 's/ *//'
416 }
418 remove_previous_tarball()
419 {
420 [ "$prev_VERSION" ] || return
421 if [ "$VERSION" != "$prev_VERSION" ]; then
422 rm -f $SOURCES_REPOSITORY/$PACKAGE-$prev_VERSION.tar.lzma
423 fi
424 }
426 remove_previous_package()
427 {
428 [ "$prev_VERSION" ] || return
429 if [ "$VERSION$EXTRAVERSION" != "$prev_VERSION" ]; then
430 rm -f $1/$PACKAGE-$prev_VERSION.tazpkg
431 fi
432 return
433 }
435 # Check for src tarball and wget if needed.
436 check_for_tarball()
437 {
438 [ "$WGET_URL" ] || return
439 report step "Checking for source tarball"
441 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ] && \
442 [ ! -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ] ; then
443 cd $SOURCES_REPOSITORY
444 download $WGET_URL
446 # If source tarball is unreachable, try to find it on SliTaz
447 # mirror.
448 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
449 report step "Download failed, try with mirror copy... "
450 if [ "$SOURCE" ]; then
451 download http://mirror.slitaz.org/sources/packages/${SOURCE:0:1}/$SOURCE-$VERSION.tar.lzma
452 else
453 download http://mirror.slitaz.org/sources/packages/${PACKAGE:0:1}/$PACKAGE-$VERSION.tar.lzma
454 fi
455 fi
456 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ] && \
457 [ ! -f "$SOURCES_REPOSITORY/${SOURCE:-PACKAGE}-$VERSION.tar.lzma" ]; then
458 report step "Download failed, try with mirror copy (again)... "
459 file=$(basename $WGET_URL)
460 download http://mirror.slitaz.org/sources/packages/${file:0:1}/$file
461 fi
463 # Exit if download failed to avoid errors.
464 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ] && [ ! -f "$SOURCES_REPOSITORY/${SOURCE:-PACKAGE}-$VERSION.tar.lzma" ; then
465 echo -e "\nDownload failed, exiting. Please check WGET_URL variable.\n" >&2
466 report end-step
467 return 1
468 fi
469 fi
470 report end-step
472 if [ -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ] && [ "$nounpack" ]; then
473 return
474 fi
476 # Untaring source if necessary. We don't need to extract source if
477 # the package is built with a wanted source package.
478 if [ "$WANTED" ]; then
479 return
480 fi
482 report step "Untaring source tarball"
483 if [ "$target" ]; then
484 src="$target"
485 else
486 set_src_path
487 fi
489 # Log process.
490 echo "untaring source tarball" >> $LOG
492 tmp_src=$WOK/$PACKAGE/tmp-src-$$
493 mkdir $tmp_src
494 if [ -f "$SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
495 lzma d $SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma -so | \
496 tar xf - -C $tmp_src
497 elif [ -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
498 case "$TARBALL" in
499 *zip|*xpi) { cd $tmp_src; unzip -o $SOURCES_REPOSITORY/$TARBALL; };;
500 *bz2) tar xjf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
501 *tar) tar xf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
502 *lzma) unlzma -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
503 *xz) unxz -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
504 *Z) uncompress -c $SOURCES_REPOSITORY/$TARBALL | tar xf - -C $tmp_src;;
505 *jar) mkdir $src && cp -f $SOURCES_REPOSITORY/$TARBALL $tmp_src ;;
506 *) tar xzf $SOURCES_REPOSITORY/$TARBALL -C $tmp_src;;
507 esac || return 1
509 # Check if uncompressed tarball is in a root dir or not.
510 if [ "$(ls -A $tmp_src | wc -l)" -gt 1 ]; then
511 if check_for_var_modification src _pkg; then
512 mv $tmp_src $tmp_src-1
513 mkdir $tmp_src
514 mv $tmp_src-1 $tmp_src/${SOURCE:-$PACKAGE}-$VERSION
515 else
516 mv $tmp_src/* $WOK/$PACKAGE
517 repack_src=no
518 rm -r $tmp_src
519 fi
520 fi
522 if [ "$repack_src" = yes ]; then
523 report step "Repacking sources in .tar.lzma format"
524 cd $tmp_src
525 tar -c * | lzma e $SOURCES_REPOSITORY/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma -si
526 rm $SOURCES_REPOSITORY/$TARBALL
527 prev_VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
529 # Remove previous tarball if it's not used either by
530 # incoming and legacy packages.
531 [ "$prev_VERSION" != "$(get_pkg_version $PACKAGES_REPOSITORY)" ] && \
532 remove_previous_tarball
533 report end-step
534 fi
535 fi
536 if [ "$nounpack" ]; then
537 [ -d "$tmp_src" ] && rm -r $tmp_src
538 return
539 fi
540 if [ "$TARBALL" ]; then
541 if [ ! -d "$src" ]; then
542 if [ -d "$tmp_src" ]; then
543 if ! check_for_var_modification src _pkg; then
544 src="${src%/*}/$(ls $tmp_src)"
545 fi
546 mv $(echo $tmp_src/*) "$src"
547 rm -r $tmp_src
549 # Permissions settings.
550 chown -R root.root "$src"
551 fi
552 else
553 echo "There's already something at $src. Abort." >&2
554 fi
555 fi
556 }
558 # Log and execute compile_rules function if it exists, to configure and
559 # make the package if it exists.
560 check_for_compile_rules()
561 {
562 if grep -q ^compile_rules $RECEIPT; then
563 echo "executing compile_rules" >> $LOG
564 report step "Executing compile_rules"
565 cd $WOK/$PACKAGE
566 rm -f /tmp/config.site
568 # Free some RAM by cleaning cache if option is enabled.
569 freeram=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
571 # Disable -pipe in CFLAGS/CXXFLAGS if less than 512Mb of free
572 # RAM are available.
573 if [ "$freeram" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" -o \
574 "$CXXFLAGS" != "${CXXFLAGS/-pipe}" ]; then
575 tazwok_warning "Disabling -pipe compile flag because only ${freeram}b of RAM are available."
576 CFLAGS="${CFLAGS/-pipe}"
577 CXXFLAGS="${CXXFLAGS/-pipe}"
578 fi
579 unset freeram
581 # Set cook environnement variables.
582 [ "$src" ] || set_src_path
583 [ "$DESTDIR" ] || DESTDIR="$WOK/$PACKAGE/install"
584 [ "$CONFIG_SITE" ] || CONFIG_SITE=/etc/config.site
585 export CFLAGS CXXFLAGS MAKEFLAGS DESTDIR BUILD_HOST \
586 CONFIG_SITE default_prefix \
587 default_datarootdir default_datadir default_localedir \
588 default_infodir default_mandir default_build default_host
589 local LC_ALL=POSIX LANG=POSIX
590 compile_rules
592 # Check if config.site has been used.
593 # /!\ disabled since it screw the return_code of the step.
594 #if [ -f /tmp/config.site ]; then
595 # rm /tmp/config.site
596 #else
597 # tazwok_warning "config.site hasn't been used during \
598 #configuration process."
599 #fi
601 report end-step
602 fi
603 }
605 # Check for loop in deps tree. /!\ can be removed
606 check_for_deps_loop()
607 {
608 local list
609 local pkg
610 local deps
611 pkg=$1
612 shift
613 [ -n "$1" ] || return
614 list=""
616 # Filter out already processed deps
617 for i in $@; do
618 case " $ALL_DEPS" in
619 *\ $i\ *);;
620 *) list="$list $i";;
621 esac
622 done
623 ALL_DEPS="$ALL_DEPS$list "
624 for i in $list; do
625 [ -f $i/receipt ] || continue
626 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
627 case " $deps " in
628 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
629 *) check_for_deps_loop $pkg $deps;;
630 esac
631 done
632 }
634 download()
635 {
636 for file in $@; do
637 case "$file" in
638 [Hh][Tt][Tt][Pp][Ss]*)
639 if [ -d $INSTALLED/wget ]; then
640 wget --no-check-certificate -O $(basename $file) $file && break
641 else
642 tazwok_warning "$PACKAGE need wget to download the source tarball from $file, please add it as build-depend."
643 return 1
644 fi
645 esac
646 wget -q $file && break
647 wget -O $(basename $file) $file && break
648 done
649 }
651 # Regenerate every package that wants a PACKAGE compiled
652 refresh_packages_from_compile()
653 {
654 # make tazwok genpkg happy
655 mkdir $WOK/$PACKAGE/taz
657 # Cook rwanted in default or specied order
658 genlist=" $(look_for_rwanted | tr '\n' ' ') "
659 for i in $(look_for_cookopt genpkg | tac); do
660 [ "${genlist/ $i }" = "$genlist" ] && continue
661 genlist=" $i${genlist/ $i / }"
662 done
663 if [ "$genlist" ]; then
664 local PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
665 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
666 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
667 src _pkg DESTDIR CONFIG_SITE RECEIPT LOG
668 for PACKAGE in $genlist; do
669 set_common_path
670 gen_package
671 done
672 fi
673 }
675 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
676 # so some packages need to copy these files with the receipt and genpkg_rules.
677 # This function is executed by gen_package when 'tazwok genpkg'.
678 copy_generic_files()
679 {
680 # In most cases, locales are in $_pkg/usr/share/locale so we copy files
681 # using generic variables and $LOCALE from Tazwok config file.
682 if [ "$LOCALE" ]; then
683 if [ -d "$_pkg/usr/share/locale" ]; then
684 for i in $LOCALE
685 do
686 if [ -d "$_pkg/usr/share/locale/$i" ]; then
687 mkdir -p $fs/usr/share/locale
688 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
689 fi
690 done
691 fi
692 fi
694 # Pixmaps (PNG or/and XPM only). Some icons/images can be added through
695 # genpkg_rules and generic copy can be disabled with GENERIC_PIXMAPS="no"
696 # in pkg receipt.
697 if [ "$GENERIC_PIXMAPS" != "no" ]; then
698 if [ -d "$_pkg/usr/share/pixmaps" ]; then
699 mkdir -p $fs/usr/share/pixmaps
700 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
701 $fs/usr/share/pixmaps 2>/dev/null
702 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
703 $fs/usr/share/pixmaps 2>/dev/null
704 fi
706 # Custom or homemade PNG pixmap can be in stuff.
707 if [ -f "stuff/$PACKAGE.png" ]; then
708 mkdir -p $fs/usr/share/pixmaps
709 cp -a stuff/$PACKAGE.png $fs/usr/share/pixmaps
710 fi
711 fi
713 # Desktop entry (.desktop).
714 if [ -d "$_pkg/usr/share/applications" ]; then
715 cp -a $_pkg/usr/share/applications $fs/usr/share
716 fi
718 # Homemade desktop file(s) can be in stuff.
719 if [ -d "stuff/applications" ]; then
720 mkdir -p $fs/usr/share
721 cp -a stuff/applications $fs/usr/share
722 fi
723 if [ -f "stuff/$PACKAGE.desktop" ]; then
724 mkdir -p $fs/usr/share/applications
725 cp -a stuff/$PACKAGE.desktop $fs/usr/share/applications
726 fi
727 }
729 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
730 strip_package()
731 {
732 report step "Executing strip on all files"
734 # Binaries.
735 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
736 do
737 if [ -d "$dir" ]; then
738 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
739 fi
740 done
742 # Libraries.
743 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
744 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
745 report end-step
746 }
748 # Remove .pyc and .pyo files from packages
749 py_compiled_files_remove()
750 {
751 report step "Removing all .pyc and .pyo files from package ..."
752 find $fs -type f -name "*.pyc" -delete 2>/dev/null
753 find $fs -type f -name "*.pyo" -delete 2>/dev/null
754 report end-step
755 }
757 # Check FSH in a slitaz package (Path: /:/usr)
758 check_fsh()
759 {
760 cd $WOK/$PACKAGE/taz/*/fs
761 [ -n "$FSH" ] || FSH="bin boot dev etc home init lib media mnt proc \
762 root sbin share sys tmp usr var vz usr/bin usr/games usr/include usr/lib \
763 usr/local usr/sbin usr/share usr/src"
764 for i in `ls -d * usr/* 2>/dev/null`
765 do
766 if ! echo $FSH | fgrep -q $i; then
767 echo "Wrong path: /$i" >&2
768 error=1
769 fi
770 done
771 if [ "$error" = "1" ]; then
772 cat << _EOT_
774 Package will install files in a non standard directory and won't be generated.
775 You may have a wrong copy path in genpkg_rules or need to add some options to
776 configure in compile_rules. Some valid options for SliTaz (Linux FSH):
778 --prefix=/usr
779 --sysconfdir=/etc
780 --libexecdir=/usr/lib/(pkgname)
781 --localstatedir=/var
782 --mandir=/usr/share/man
783 --infodir=/usr/share/info
785 For more information please read SliTaz docs and run: ./configure --help
786 ================================================================================
787 $PACKAGE package generation aborted.
789 _EOT_
791 # Dont generate a corrupted package.
792 cd $WOK/$PACKAGE && rm -rf taz
793 report exit
794 fi
795 }
797 gen_cookmd5()
798 {
799 # md5sum of cooking stuff make tazwok able to check for changes
800 # without hg.
801 cd $WOK/$PACKAGE
802 md5sum receipt > md5
803 [ -f description.txt ] && md5sum description.txt >> md5
804 if [ -d stuff ]; then
805 find stuff | while read file; do
806 md5sum $file >> md5
807 done
808 fi
809 }
811 # Create a package tree and build the gziped cpio archive
812 # to make a SliTaz (.tazpkg) package.
813 gen_package()
814 {
815 check_root
816 check_for_package_on_cmdline
817 check_for_receipt
818 EXTRAVERSION=""
819 . $RECEIPT
821 # May compute VERSION
822 if grep -q ^get_version $RECEIPT; then
823 get_version
824 fi
825 check_for_wanted
826 cd $WOK/$PACKAGE
828 # Remove old Tazwok package files.
829 [ -d "taz" ] && rm -rf taz
831 # Create the package tree and set useful variables.
832 mkdir -p taz/$PACKAGE-$VERSION/fs
833 fs=taz/$PACKAGE-$VERSION/fs
835 # Set $src for standard package and $_pkg variables.
836 set_src_path && set_pkg_path
838 # Execute genpkg_rules, check package and copy generic files to build
839 # the package.
840 report step "Building $PACKAGE with the receipt"
841 report open-bloc
842 if grep -q ^genpkg_rules $RECEIPT; then
844 # Log process.
845 echo "executing genpkg_rules" >> $LOG
846 report step "Executing genpkg_rules"
847 genpkg_rules
848 report end-step
849 check_fsh
850 cd $WOK/$PACKAGE
852 # Skip generic files for packages with a WANTED variable
853 # (dev and splited pkgs).
854 if [ ! "$WANTED" ]; then
855 copy_generic_files
856 fi
857 look_for_cookopt !strip || strip_package
858 py_compiled_files_remove
859 else
860 echo "No package rules to gen $PACKAGE..." >&2
861 report exit
862 fi
864 # Copy the receipt and description (if exists) into the binary package tree.
865 cd $WOK/$PACKAGE
866 report step "Copying the receipt"
867 cp receipt taz/$PACKAGE-$VERSION
868 report end-step
869 if grep -q ^get_version $RECEIPT; then
870 report step "Updating version in receipt"
871 sed -i "s/^VERSION=.*/VERSION=\"$VERSION\"/" \
872 taz/$PACKAGE-$VERSION/receipt
873 report end-step
874 fi
875 if [ -f "description.txt" ]; then
876 report step "Copying the description file"
877 cp description.txt taz/$PACKAGE-$VERSION
878 report end-step
879 fi
881 # Generate md5 of cooking stuff to look for commit later.
882 gen_cookmd5
883 echo -e "\n# md5sum of cooking stuff :" >> taz/$PACKAGE-$VERSION/receipt
884 cat md5 | sed 's/^/# /' >> taz/$PACKAGE-$VERSION/receipt
886 # Create the files.list by redirecting find output.
887 report step "Creating the list of files"
888 cd taz/$PACKAGE-$VERSION
889 LAST_FILE=""
890 { find fs -print; echo; } | while read file; do
891 if [ "$LAST_FILE" ]; then
892 case "$file" in
893 $LAST_FILE/*)
894 case "$(ls -ld "$LAST_FILE")" in
895 drwxr-xr-x\ *\ root\ *\ root\ *);;
896 *) echo ${LAST_FILE#fs};;
897 esac;;
898 *) echo ${LAST_FILE#fs};;
899 esac
900 fi
901 LAST_FILE="$file"
902 done > files.list
904 # Next, check if something has changed in lib files.
905 if fgrep -q '.so' files.list; then
906 report step "Look for major/minor update in libraries"
907 for rep in $INCOMING_REPOSITORY $PACKAGES_REPOSITORY \
908 $([ "$undigest" ] && echo SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming && \
909 echo $SLITAZ_DIR/$SLITAZ_VERSION/packages); do
910 prev_VERSION=$(get_pkg_version $rep)
911 [ "$prev_VERSION" ] && pkg_file=$rep/$PACKAGE-$prev_VERSION.tazpkg && break
912 done
913 if [ "$pkg_file" ]; then
914 get_pkg_files $pkg_file
915 cd $WOK/$PACKAGE/taz/$PACKAGE-$VERSION
916 fgrep ".so" files.list | egrep -v "[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*" | \
917 while read lib; do
918 fgrep -q "$lib" $pkg_files_dir/files.list && continue
919 echo "A minor/major update in libraries is detected, planning re-cook of reverse-depends of $PACKAGE."
920 for rdep in $(scan $PACKAGE --look_for=rdep | use_wanted); do
921 [ "$rdep" = "${WANTED:-$PACKAGE}" ] && continue
922 grep -q ^$rdep$ $PACKAGES_REPOSITORY/blocked \
923 $PACKAGES_REPOSITORY/cooklist && continue
924 echo $rdep >> $PACKAGES_REPOSITORY/cooklist
925 done
926 regen_cooklist=yes
927 break
928 done
929 rm -r $pkg_files_dir
930 fi
931 report end-step
932 fi
933 if [ ! "$EXTRAVERSION" ]; then
934 case "$PACKAGE" in
935 linux*);;
936 *) EXTRAVERSION="$(grep '/lib/modules/.*-slitaz/' files.list |\
937 head -1 | sed 's|/lib/modules/\(.*\)-slitaz/.*|_\1|')";;
938 esac
939 fi
940 rm -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg 2> /dev/null
941 report step "Creating md5sum of files"
942 while read file; do
943 [ -L "fs$file" ] && continue
944 [ -f "fs$file" ] || continue
945 md5sum "fs$file" | sed 's/ fs/ /'
946 done < files.list > md5sum
947 report end-step
948 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
949 2> /dev/null | awk '{ sz=$1 } END { print sz }')
951 # Build cpio archives. Find, cpio and gzip the fs, finish by
952 # removing the fs tree.
953 # Don't log this because compression always output error messages.
954 find fs -print | cpio -o -H newc | case "$PACKAGE-$COMPRESSION" in
955 tazpkg-lzma) gzip > fs.cpio.gz;;
956 *-lzma) lzma e fs.cpio.lzma -si;;
957 *) gzip > fs.cpio.gz;;
958 esac && rm -rf fs
959 PACKED_SIZE=$(du -chs fs.cpio.* receipt files.list md5sum \
960 description.txt 2> /dev/null | awk '{ sz=$1 } END { print sz }')
961 report step "Updating receipt sizes"
962 sed -i '/^PACKED_SIZE/d' receipt
963 sed -i '/^UNPACKED_SIZE/d' receipt
964 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
965 sed -i "s/^VERSION=$/VERSION=\"$VERSION\"/" receipt
966 report end-step
967 if [ "$EXTRAVERSION" ]; then
968 report step "Updating receipt EXTRAVERSION"
969 sed -i s/^EXTRAVERSION.*$// receipt
970 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
971 fi
972 prev_VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
973 remove_previous_package $INCOMING_REPOSITORY
974 report step "Creating full cpio archive"
975 find . -print | cpio -o -H newc > $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
977 # Restore package tree in case we want to browse it.
978 report step "Restoring original package tree"
979 { zcat fs.cpio.gz 2> /dev/null || unlzma -c fs.cpio.lzma; } | cpio --quiet -id
980 rm fs.cpio.* && cd ..
982 # Log process.
983 echo "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg (done)" >> $LOG
984 report close-bloc
985 echo "Package $PACKAGE ($VERSION$EXTRAVERSION) generated."
986 echo "Size : `du -sh $INCOMING_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
987 echo ""
989 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/broken
990 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/commit
991 sed "/^$PACKAGE$/d" -i $PACKAGES_REPOSITORY/cooklist
992 }
994 ########################################################################
995 # This section contains functions used by several other functions
996 # bellow.
997 ########################
999 # Look for receipt/files.list in wok. If they can't be found, get them
1000 # from package. Accept one argument : absolute path to package.
1001 get_pkg_files()
1003 pkg_files_dir=$tmp/$(basename ${1%.tazpkg})
1004 mkdir -p $pkg_files_dir && \
1005 cd $pkg_files_dir && \
1006 cpio --quiet -idm receipt < $1 && \
1007 cpio --quiet -idm files.list < $1
1010 ########################################################################
1011 # This section contains functions to generate packages databases.
1012 ########################
1015 gen_packages_db()
1017 # pkg_repository can be $PACKAGES_REPOSITORY or $INCOMING_REPOSITORY.
1018 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1019 cd $pkg_repository
1020 report step "Generating packages lists: $pkg_repository"
1021 report open-bloc
1022 report step "Removing old files"
1023 for file in files.list.lzma packages.list packages.txt \
1024 packages.desc packages.equiv packages.md5; do
1025 [ -f $file ] && rm $file
1026 done
1027 touch files.list
1029 packages_db_start
1030 unset RECEIPT
1031 report step "Reading datas from all packages"
1032 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1033 get_packages_info
1034 done
1035 report end-step
1036 packages_db_end
1037 report close-bloc
1040 update_packages_db()
1042 [ "$pkg_repository" ] || pkg_repository=$PACKAGES_REPOSITORY
1043 cd $pkg_repository
1044 for file in packages.list packages.equiv packages.md5 packages.desc \
1045 packages.txt; do
1046 if [ ! -f "$file" ]; then
1047 gen_packages_db
1048 return
1049 fi
1050 done
1051 if [ -f files.list.lzma ]; then
1052 lzma d files.list.lzma files.list
1053 else
1054 gen_packages_db
1055 fi
1056 report step "Updating packages lists: $pkg_repository"
1057 packages_db_start
1059 # Look for removed/update packages.
1060 for PACKAGE in $(grep ^[0-9,a-z,A-Z] packages.txt); do
1061 pkg="$pkg_repository/$(grep -m1 ^$PACKAGE- packages.list).tazpkg"
1062 if ! [ -f "$pkg" ]; then
1063 erase_package_info
1064 else
1065 if [ "$pkg" -nt "packages.list" ]; then
1066 updated_pkg="$updated_pkg
1067 $PACKAGE $pkg"
1068 fi
1069 fi
1070 done
1071 echo "$updated_pkg" | sed 1d | while read PACKAGE pkg; do
1072 erase_package_info
1073 get_packages_info
1074 done
1075 unset updated_pkg
1077 # Look for new packages.
1078 for pkg in $(echo $pkg_repository/*.tazpkg | fgrep -v '*'); do
1079 if ! fgrep -q " ${pkg##*/}" $pkg_repository/packages.md5; then
1080 get_packages_info
1081 fi
1082 done
1083 report end-step
1084 packages_db_end
1087 packages_db_start()
1089 if [ ! -s packages.txt ]; then
1090 echo "# SliTaz GNU/Linux - Packages list
1092 # Packages : unknow
1093 # Date : $(date +%Y-%m-%d\ \%H:%M:%S)
1095 " > packages.txt
1096 else
1097 sed -e 's/^# Packages :.*/# Packages : unknow/' \
1098 -e "s/# Date :.*/# Date : $(date +%Y-%m-%d\ \%H:%M:%S)/" \
1099 -i packages.txt
1100 fi
1102 # Needed in some case as tazwok define RECEIPT at configuration time
1103 # in this particular case it can broke the script.
1104 unset RECEIPT
1107 erase_package_info()
1109 cd $pkg_repository
1110 sed "/^$PACKAGE$/,/^$/d" -i packages.txt
1111 sed "/^$PACKAGE /d" -i packages.desc
1112 sed -e "s/=$PACKAGE /= /" -e "s/ $PACKAGE / /" -e "s/ $PACKAGE$//" \
1113 -e "/=$PACKAGE$/d" -e "s/=[0-9,a-z,A-Z]:$PACKAGE /= /" \
1114 -e "s/ [0-9,a-z,A-Z]:$PACKAGE / /" -e "s/ [0-9,a-z,A-Z]:$PACKAGE$/ /" \
1115 -e "/=[0-9,a-z,A-Z]:$PACKAGE$/d" \
1116 -i packages.equiv
1117 sed "/^$PACKAGE:/d" -i files.list
1118 sed "/^$(basename ${pkg%.tazpkg})$/d" -i packages.list
1119 sed "/ $(basename $pkg)$/d" -i packages.md5
1122 get_packages_info()
1124 # If there's no taz folder in the wok, extract infos from the
1125 # package.
1126 get_pkg_files $pkg
1127 source_receipt
1128 echo "Getting datas from $PACKAGE"
1130 cat >> $pkg_repository/packages.txt << _EOT_
1131 $PACKAGE
1132 $VERSION$EXTRAVERSION
1133 $SHORT_DESC
1134 _EOT_
1135 if [ "$PACKED_SIZE" ]; then
1136 cat >> $pkg_repository/packages.txt << _EOT_
1137 $PACKED_SIZE ($UNPACKED_SIZE installed)
1139 _EOT_
1140 else
1141 echo "" >> $pkg_repository/packages.txt
1142 fi
1144 # Packages.desc is used by Tazpkgbox <tree>.
1145 echo "$PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> $pkg_repository/packages.desc
1147 # Packages.equiv is used by tazpkg install to check depends
1148 for i in $PROVIDE; do
1149 DEST=""
1150 echo $i | fgrep -q : && DEST="${i#*:}:"
1151 if grep -qs ^${i%:*}= $pkg_repository/packages.equiv; then
1152 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" $pkg_repository/packages.equiv
1153 else
1154 echo "${i%:*}=$DEST$PACKAGE" >> $pkg_repository/packages.equiv
1155 fi
1156 done
1158 if [ -f files.list ]; then
1159 { echo "$PACKAGE"; cat files.list; } | awk '
1160 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }' >> $pkg_repository/files.list
1161 fi
1163 cd .. && rm -r "$pkg_files_dir"
1165 cd $pkg_repository
1166 echo $(basename ${pkg%.tazpkg}) >> packages.list
1167 [ ! "$package_md5" ] && package_md5=$(md5sum $(basename $pkg))
1168 echo "$package_md5" >> packages.md5
1169 unset package_md5
1172 source_receipt()
1174 unset PACKAGE SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
1175 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED \
1176 PACKED_SIZE UNPACKED_SIZE COOK_OPT PROVIDE CONFIG_FILES TAGS \
1177 src _pkg DESTDIR CONFIG_SITE
1178 . ${RECEIPT:-$PWD/receipt}
1181 packages_db_end()
1183 cd $pkg_repository
1184 pkgs=$(wc -l packages.list | sed 's/ .*//')
1185 sed "s/# Packages : .*/# Packages : $pkgs/" -i packages.txt
1187 # If lists was updated it's generally needed to sort them well.
1188 if ! sort -c packages.list 2> /dev/null; then
1189 report step "Sorting packages lists"
1190 for file in packages.list packages.desc packages.equiv; do
1191 [ -f $file ] || continue
1192 sort -o $file $file
1193 done
1194 report end-step
1195 fi
1197 # Dont log this because lzma always output error.
1198 lzma e files.list files.list.lzma
1199 rm -f files.list
1200 [ -f packages.equiv ] || touch packages.equiv
1203 ########################################################################
1204 # This section contains functions to generate wok database.
1205 ########################
1207 gen_wok_db()
1209 report step "Generating wok database"
1210 report open-bloc
1211 report step "Removing old files"
1212 for file in $wan_db $dep_db $PACKAGES_REPOSITORY/cookorder.txt; do
1213 [ -f $file ] && rm $file
1214 done
1215 report step "Generating wok-wanted.txt"
1216 gen_wan_db
1217 report step "Generating wok-depends.txt"
1218 for PACKAGE in $(cut -f1 -d '|' $PACKAGES_REPOSITORY/packages.desc \
1219 $INCOMING_REPOSITORY/packages.desc | sort -u); do
1220 RECEIPT=$WOK/$PACKAGE/receipt
1221 if [ -s $RECEIPT ]; then
1222 source_receipt
1223 echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
1224 fi
1225 done
1226 sort_db
1227 report close-bloc
1230 gen_wan_db()
1232 for RECEIPT in $(fgrep -l WANTED $WOK/*/receipt); do
1233 WANTED=
1234 source $RECEIPT
1235 [ "$WANTED" ] || continue
1236 echo -e $PACKAGE"\t"$WANTED >> $tmp/wan_db
1237 done
1238 if ! [ -f $wan_db ] || [ "$(diff -q $tmp/wan_db $wan_db)" ]; then
1239 mv -f $tmp/wan_db $wan_db
1240 plan_regen_cookorder=yes
1241 else
1242 rm $tmp/wan_db
1243 fi
1246 update_wan_db()
1248 local PACKAGE
1249 for RECEIPT in $(fgrep WANTED $WOK/*/receipt | \
1250 fgrep $PACKAGE | cut -f1 -d ':'); do
1251 WANTED=
1252 source $RECEIPT
1253 [ "$WANTED" ] || continue
1254 wan_info=$(echo -e $PACKAGE"\t"$WANTED)
1255 [ "$wan_info" = "$(grep -m1 ^$PACKAGE$'\t' $wan_db 2>/dev/null)" ] && return
1256 sed "/^$PACKAGE\t/d" -i $wan_db
1257 echo "$wan_info" >> $wan_db
1258 plan_regen_cookorder=yes
1259 plan_sort_wandb=yes
1260 done
1263 update_dep_db()
1265 dep_info=$(echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ')
1266 [ "$dep_info" = "$(grep -m1 ^$PACKAGE$'\t' $dep_db 2>/dev/null)" ] && return
1267 sed "/^$PACKAGE\t/d" -i $dep_db
1268 echo "$dep_info" >> $dep_db
1269 plan_regen_cookorder=yes
1270 plan_sort_depdb=yes
1273 sort_db()
1275 report step "Generating cookorder.txt"
1276 cat $dep_db | sed 's/ \t / /' | while read PACKAGE BUILD_DEPENDS; do
1277 grep -q ^$PACKAGE$'\t' $wan_db && continue
1279 # Replace each BUILD_DEPENDS with a WANTED package by it's
1280 # WANTED package.
1281 replace_by_wanted()
1283 for p in $BUILD_DEPENDS; do
1284 if grep -q ^$p$'\t' $wan_db; then
1285 echo -n $(grep ^$p$'\t' $wan_db | cut -f 2)' '
1286 else
1287 echo -n $p' '
1288 fi
1289 done | tr ' ' '\n' | sort -u | sed "/^$PACKAGE$/d" | tr '\n' ' '
1291 echo -e $PACKAGE"\t $(replace_by_wanted) "
1292 done > $tmp/db
1293 while [ -s "$tmp/db" ]; do
1294 status=start
1295 for pkg in $(cut -f 1 $tmp/db); do
1296 if ! fgrep -q ' '$pkg' ' $tmp/db; then
1297 echo $pkg >> $tmp/cookorder
1298 sed -e "/^$pkg\t/d" -e "s/ $pkg / /g" -i $tmp/db
1299 status=proceed
1300 fi
1301 done
1302 if [ "$status" = start ]; then
1303 cp -f $tmp/db /tmp/remain-depends.txt
1304 echo "Can't go further because there's depency(ies) loop(s). The remaining packages will be commentend in the cookorder and will be unbuild in case of major update until the problem is solved." >&2
1305 for blocked in $(cut -f 1 $tmp/db); do
1306 echo "$blocked" >> $PACKAGES_REPOSITORY/blocked
1307 done
1308 break
1309 fi
1310 done
1311 [ -s $tmp/cookorder ] || touch $tmp/cookorder
1313 # The toolchain packages are moved in first position.
1314 grep $(for pkg in `scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
1315 --look_for=all --with_args`; do echo " -e ^$pkg$"; done) \
1316 $tmp/cookorder | tac > $PACKAGES_REPOSITORY/cookorder.txt
1317 for pkg in $(cat $PACKAGES_REPOSITORY/cookorder.txt); do
1318 sed "/^$pkg$/d" -i $tmp/cookorder
1319 done
1321 tac $tmp/cookorder >> $PACKAGES_REPOSITORY/cookorder.txt
1322 unset plan_regen_cookorder
1323 report end-step
1326 ########################################################################
1327 # SCAN CORE
1328 ########################
1329 # Include various scan core-functions. It's not intended to be used
1330 # directly : prefer scan wrappers in next section.
1332 look_for_dep()
1334 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1335 grep ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
1336 | cut -f 2
1337 else
1338 grep ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-depends.txt | \
1339 cut -f 2
1340 fi
1343 look_for_bdep()
1345 look_for_all
1348 look_for_all()
1350 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1351 grep ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
1352 | cut -f 2,3 | sed 's/ / /'
1353 else
1354 grep ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-depends.txt | \
1355 cut -f 2,3 | sed 's/ / /'
1356 fi
1359 look_for_rdep()
1361 fgrep ' '$PACKAGE' ' $INCOMING_REPOSITORY/wok-depends.txt | cut -f 1
1362 if [ "$undigest" ]; then
1363 for rdep in $(fgrep ' '$PACKAGE' ' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt | cut -f 1); do
1364 if [ ! -f "WOK$/$rdep/receipt" ]; then
1365 echo "$rdep"
1366 fi
1367 done
1368 fi
1371 look_for_rbdep()
1373 fgrep ' '$PACKAGE' ' $INCOMING_REPOSITORY/wok-depends.txt | \
1374 cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
1375 if [ "$undigest" ]; then
1376 for rdep in $(fgrep ' '$PACKAGE' ' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
1377 | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1); do
1378 if [ ! -f "WOK$/$rdep/receipt" ]; then
1379 echo "$rdep"
1380 fi
1381 done
1382 fi
1385 # Return WANTED if it exists.
1386 look_for_wanted()
1388 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1389 grep ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-wanted.txt | cut -f 2
1390 else
1391 grep ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-wanted.txt | cut -f 2
1392 fi
1395 # Return packages which wants PACKAGE.
1396 look_for_rwanted()
1398 grep $'\t'$PACKAGE$ $INCOMING_REPOSITORY/wok-wanted.txt | cut -f 1
1399 if [ "$undigest" ]; then
1400 for rwanted in $(grep $'\t'$PACKAGE$ $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-wanted.txt | cut -f 1); do
1401 if [ ! -f "$WOK/$rwanted/receipt" ]; then
1402 echo "$rwanted"
1403 fi
1404 done
1405 fi
1408 look_for_dev()
1410 WANTED=$(look_for_wanted)
1411 if [ "$WANTED" ]; then
1412 if [ "$undigest" ] && [ ! -f "$WOK/$WANTED/receipt" ]; then
1413 [ -f "$SLITAZ_DIR/$SLITAZ_VERSION/wok/$WANTED-dev/receipt" ] && echo $WANTED-dev
1414 else
1415 [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
1416 fi
1417 fi
1418 if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
1419 [ -f "$SLITAZ_DIR/$SLITAZ_VERSION/wok/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1420 else
1421 [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
1422 fi
1425 with_dev()
1427 for PACKAGE in $(cat); do
1428 echo $PACKAGE
1429 look_for_dev
1430 done
1433 with_wanted()
1435 for PACKAGE in $(cat); do
1436 echo $PACKAGE
1437 look_for_wanted
1438 done
1441 use_wanted()
1443 for input in $(cat); do
1444 { grep ^$input$'\t' $wan_db || echo $input
1445 } | sed 's/.*\t//'
1446 done
1449 ########################################################################
1450 # SCAN
1451 ########################
1452 # Use wok-wanted.txt and wok-depeds.txt to scan depends.
1453 # Option in command line (must be first arg) :
1454 # --look_for=bdep/rbdep - Look for depends or reverse depends.
1455 # --with_dev - Add development packages (*-dev) in the result.
1456 # --with_wanted - Add package+reverse wanted in the result.
1457 # --with_args - Include packages in argument in the result.
1459 scan()
1461 # Get packages in argument.
1462 local PACKAGE WANTED pkg_list=
1463 for arg in $@; do
1464 [ "$arg" = "${arg#--}" ] || continue
1465 pkg_list="$pkg_list $arg"
1466 done
1468 # Get options.
1469 [ "$pkg_list" ] || return
1470 local cooklist= look_for= with_dev= with_wanted= with_args= log_command="$0 $@" \
1471 get_options_list="look_for with_dev with_wanted with_args cooklist use_wanted"
1472 get_options
1474 # Cooklist is a special case where we need to modify a little
1475 # scan behavior
1476 if [ "$cooklist" ]; then
1477 gen_wan_db
1478 look_for=all && with_args=yes && with_dev= && with_wanted=
1479 filter=use_wanted
1480 if [ "$COMMAND" = gen-cooklist ]; then
1481 for PACKAGE in $pkg_list; do
1482 grep -q ^$PACKAGE$'\t' $dep_db && continue
1483 [ -d "$WOK/$p" ] || continue
1484 check_for_missing
1485 done
1486 append_to_dep()
1488 if ! grep -q ^$PACKAGE$'\t' $dep_db; then
1489 check_for_missing && echo $PACKAGE >> $tmp/dep
1490 else
1491 echo $PACKAGE >> $tmp/dep
1492 fi
1494 else
1495 append_to_dep()
1497 check_for_commit && echo $PACKAGE >> $tmp/dep
1499 fi
1500 else
1501 append_to_dep()
1503 echo $PACKAGE >> $tmp/dep
1505 # If requested packages are not in dep_db, partial generation of this db is needed.
1506 for PACKAGE in $pkg_list; do
1507 grep -q ^$PACKAGE$'\t' $dep_db && continue
1508 [ -d "$WOK/$p" ] || continue
1509 plan_check_for_missing=yes
1510 check_for_missing
1511 done
1512 if [ "$plan_check_for_missing" ]; then
1513 append_to_dep()
1515 if ! grep -q ^$PACKAGE$'\t' $dep_db; then
1516 check_for_missing && echo $PACKAGE >> $tmp/dep
1517 else
1518 echo $PACKAGE >> $tmp/dep
1519 fi
1521 check_db_status=yes
1522 unset plan_check_for_missing
1523 fi
1524 fi
1526 [ "$with_dev" ] && filter=with_dev
1527 [ "$with_wanted" ] && filter=with_wanted
1528 if [ "$filter" ]; then
1529 pkg_list=$(echo $pkg_list | $filter)
1530 scan_pkg()
1532 look_for_$look_for | $filter
1534 else
1535 scan_pkg()
1537 look_for_$look_for
1539 fi
1540 touch $tmp/dep
1541 for PACKAGE in $pkg_list; do
1542 [ "$with_args" ] && append_to_dep
1543 scan_pkg
1544 done | tr ' ' '\n' | sort -u > $tmp/list
1545 [ "$look_for" = bdep ] && look_for=dep
1546 while [ -s $tmp/list ]; do
1547 PACKAGE=$(sed 1!d $tmp/list)
1548 sed 1d -i $tmp/list
1549 append_to_dep
1550 for pkg in $(scan_pkg); do
1551 if ! grep -q ^$pkg$ $tmp/list $tmp/dep; then
1552 echo $pkg >> $tmp/list
1553 fi
1554 done
1555 done
1556 if [ "$cooklist" ]; then
1557 mv $tmp/dep $tmp/cooklist
1558 else
1559 cat $tmp/dep | sort -u
1560 fi
1561 rm -f $tmp/dep $tmp/list
1562 if [ "$check_db_status" ]; then
1563 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
1564 [ "$plan_sort_wandb" ] && sort -o $wan_db $wan_db && unset plan_sort_wandb
1565 if [ "$plan_regen_cookorder" ]; then
1566 grep -q "^#" $PACKAGES_REPOSITORY/cookorder.txt || \
1567 sed 1i"#PlanSort" -i $PACKAGES_REPOSITORY/cookorder.txt
1568 fi
1569 fi
1572 ########################################################################
1573 # This section contains functions to check package repository and
1574 # find which packages to cook.
1575 ########################
1577 check_for_missing()
1579 local PACKAGE
1580 if ! check_for_pkg_in_wok; then
1581 [ "$?" = 2 ] && return 1
1582 return
1583 fi
1584 RECEIPT=$WOK/$PACKAGE/receipt
1585 source_receipt
1586 PACKAGE=${WANTED:-$PACKAGE}
1587 update_wan_db
1588 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1589 RECEIPT=$WOK/$PACKAGE/receipt
1590 source_receipt
1591 update_dep_db
1592 done
1595 check_for_commit()
1597 if ! check_for_pkg_in_wok; then
1598 [ "$?" = 2 ] && return 1
1599 return
1600 fi
1601 for PACKAGE in $(look_for_rwanted) $PACKAGE; do
1602 RECEIPT=$WOK/$PACKAGE/receipt
1603 source_receipt
1605 # We use md5 of cooking stuff in the packaged receipt to check
1606 # commit. We look consecutively in 3 different locations :
1607 # - in the wok/PACKAGE/taz/* folder
1608 # - in the receipt in the package in incoming repository
1609 # - in the receipt in the package in packages repository
1610 # If md5sum match, there's no commit.
1611 check_for_commit_using_md5sum()
1613 if [ ! -f $WOK/$PACKAGE/md5 ]; then
1614 sed -n '/# md5sum of cooking stuff :/,$p' receipt | \
1615 sed -e 1d -e 's/^# //' > $WOK/$PACKAGE/md5
1616 cd $WOK/$PACKAGE
1617 fi
1619 if [ -s md5 ]; then
1620 if md5sum -cs md5; then
1622 # If md5sum check if ok, check for new/missing files in
1623 # cooking stuff.
1624 for file in $([ -f receipt ] && echo receipt; \
1625 [ -f description.txt ] && echo description.txt; \
1626 [ -d stuff ] && find stuff); do
1627 if ! fgrep -q " $file" md5; then
1628 set_commited
1629 fi
1630 done
1631 else
1632 set_commited
1633 fi
1634 else
1635 set_commited
1636 fi
1638 set_commited()
1640 ! grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/commit &&
1641 echo $PACKAGE >> $PACKAGES_REPOSITORY/commit
1642 gen_cookmd5
1643 update_dep_db
1645 taz_dir=$(echo $WOK/$PACKAGE/taz/$PACKAGE-* | fgrep -v '*')
1646 if [ -f $WOK/$PACKAGE/md5 ]; then
1647 cd $WOK/$PACKAGE
1648 check_for_commit_using_md5sum
1649 elif [ "$taz_dir" ]; then
1650 cd $taz_dir
1651 check_for_commit_using_md5sum
1652 else
1653 pkg=$(echo $INCOMING_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
1654 [ "$pkg" ] || pkg=$(echo $PACKAGES_REPOSITORY/$PACKAGE-$VERSION*.tazpkg | fgrep -v '*')
1655 if [ "$pkg" ]; then
1656 get_pkg_files $pkg
1657 check_for_commit_using_md5sum
1658 rm -r $pkg_files_dir
1659 else
1660 set_commited
1661 fi
1662 fi
1663 [ "$forced" ] || echo $PACKAGE >> $tmp/checked
1664 done
1665 return
1668 gen_cook_list()
1670 report step "Scanning wok"
1671 if [ "$pkg" ]; then
1672 scan $pkg --cooklist
1673 else
1674 scan `cat $cooklist` --cooklist
1675 fi
1676 report end-step
1678 [ -s $tmp/checked ] || [ -s $tmp/cooklist ] || return
1679 if [ "$(sed 1!d $PACKAGES_REPOSITORY/cookorder.txt)" = "#PlanSort" ]; then
1680 sed 1d -i $PACKAGES_REPOSITORY/cookorder.txt
1681 plan_regen_cookorder=yes
1682 fi
1684 # Core toolchain should not be cooked unless cook-toolchain is used.
1685 if ! [ -f /etc/config.site.tmptoolchain ] ; then
1686 for PACKAGE in $(scan gcc --look_for=all --with_args --with_wanted); do
1687 grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/blocked || \
1688 echo $PACKAGE >> $PACKAGES_REPOSITORY/blocked
1689 done
1690 fi
1692 if [ -s $PACKAGES_REPOSITORY/commit ] && [ "$COMMAND" != gen-cooklist ]; then
1693 cd $PACKAGES_REPOSITORY
1694 for PACKAGE in $(cat commit); do
1695 WANTED="$(look_for_wanted)"
1696 if [ "$WANTED" ]; then
1697 grep -q ^$WANTED$ broken cooklist blocked commit && continue
1698 fi
1699 grep -q ^$PACKAGE$ blocked cooklist && continue
1700 echo $PACKAGE >> cooklist
1701 done
1702 fi
1703 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
1704 [ "$plan_regen_cookorder" ] && sort_db
1705 sort_cooklist
1708 sort_cooklist()
1710 report step "Sorting cooklist"
1711 if [ -f "$tmp/checked" ]; then
1712 rm -f $tmp/cooklist
1713 cat $tmp/checked | while read PACKAGE; do
1714 grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/cooklist && \
1715 echo $PACKAGE >> $tmp/cooklist
1716 done
1717 elif ! [ "$COMMAND" = gen-cooklist ]; then
1718 cat $PACKAGES_REPOSITORY/blocked | while read PACKAGE; do
1719 sed "/^$PACKAGE/d" -i $tmp/cooklist
1720 done
1721 fi
1723 for PACKAGE in $(cat $tmp/cooklist); do
1724 WANTED="$(look_for_wanted)"
1725 [ "$WANTED" ] || continue
1726 if grep -q ^$WANTED$ $PACKAGES_REPOSITORY/broken $tmp/cooklist; then
1727 sed "/^$PACKAGE$/d" -i $tmp/cooklist
1728 elif [ ! -d $WOK/$WANTED/install ]; then
1729 sed "/^$PACKAGE$/d" -i $tmp/cooklist
1730 echo $WANTED >> $tmp/cooklist
1731 fi
1732 done
1734 # Use cookorder.txt to sort cooklist.
1735 if [ -s $tmp/cooklist ]; then
1736 cat $PACKAGES_REPOSITORY/cookorder.txt | while read PACKAGE; do
1737 if grep -q ^$PACKAGE$ $tmp/cooklist; then
1738 sed "/^$PACKAGE$/d" -i $tmp/cooklist
1739 echo $PACKAGE >> $tmp/cooklist.tmp
1740 fi
1741 done
1743 # Remaining packages in cooklist are thoses without compile_rules.
1744 # They can be cooked first in any order.
1745 if [ -f $tmp/cooklist.tmp ]; then
1746 cat $tmp/cooklist.tmp >> $tmp/cooklist
1747 rm $tmp/cooklist.tmp
1748 fi
1750 cat $tmp/cooklist
1751 [ "$cooklist" = "$PACKAGES_REPOSITORY/cooklist" ] && \
1752 cat $tmp/cooklist > $cooklist
1753 fi
1755 report end-step
1758 check_for_incoming()
1760 [ -s $INCOMING_REPOSITORY/packages.desc ] || {
1761 echo "No packages in $INCOMING_REPOSITORY."
1762 return; }
1763 if [ -s $PACKAGES_REPOSITORY/broken ]; then
1764 echo "Don't move incoming packages to main repository because theses ones are broken:
1765 $(cat $PACKAGES_REPOSITORY/broken)" >&2
1766 return
1767 fi
1768 if [ -s $PACKAGES_REPOSITORY/cooklist ]; then
1769 echo "Don't move incoming packages to main repository because some of them need to be cooked:
1770 $(cat $PACKAGES_REPOSITORY/cooklist)" >&2
1771 return
1772 fi
1773 pkg="$(cut -f 1 -d '|' $INCOMING_REPOSITORY/packages.desc)"
1774 if ! [ "$forced" ]; then
1775 cooklist=$PACKAGES_REPOSITORY/cooklist
1776 gen_cook_list
1777 if [ -s $PACKAGES_REPOSITORY/cooklist ]; then
1778 echo "Don't move incoming packages to main repository because some of them need to be cooked." >&2
1779 return
1780 fi
1781 fi
1782 report step "Moving incoming packages to main repository"
1783 unset EXTRAVERSION
1784 for PACKAGE in $pkg; do
1785 prev_VERSION=$(get_pkg_version $PACKAGES_REPOSITORY)
1786 VERSION=$(get_pkg_version $INCOMING_REPOSITORY)
1787 remove_previous_package $PACKAGES_REPOSITORY
1788 echo "Moving $PACKAGE..."
1789 mv -f $INCOMING_REPOSITORY/$PACKAGE-$VERSION.tazpkg $PACKAGES_REPOSITORY
1790 touch $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
1791 done
1792 report end-step
1793 for file in packages.list packages.equiv packages.md5 packages.desc \
1794 packages.txt; do
1795 echo -n "" > $INCOMING_REPOSITORY/$file
1796 done
1797 rm -r $INCOMING_REPOSITORY/files.list.lzma
1798 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
1801 ########################################################################
1802 # TAZWOK MAIN FUNCTIONS
1803 ########################
1805 clean()
1807 cd $WOK/$PACKAGE
1808 ls -A $WOK/$PACKAGE | grep -q -v -e ^receipt$ -e ^description.txt$ \
1809 -e ^stuff$ || return
1811 [ "$COMMAND" = clean-wok ] || report step "Cleaning $PACKAGE"
1812 # Check for clean_wok function.
1813 if grep -q ^clean_wok $RECEIPT; then
1814 clean_wok
1815 fi
1816 # Clean should only have a receipt, stuff and optional desc.
1817 for f in `ls .`
1818 do
1819 case $f in
1820 receipt|stuff|description.txt|md5)
1821 continue ;;
1822 *)
1823 [ "$COMMAND" = clean-wok ] || echo "Removing: $f"
1824 rm -rf $f
1825 esac
1826 done
1827 [ "$COMMAND" = clean-wok ] || report end-step
1830 # Configure and make a package with the receipt.
1831 compile_package()
1833 check_for_package_on_cmdline
1835 # Include the receipt to get all needed variables and functions
1836 # and cd into the work directory to start the work.
1837 check_for_receipt
1838 source_receipt
1840 # Log the package name and date.
1841 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
1842 echo "package $PACKAGE (compile)" >> $LOG
1844 # Set wanted $src variable to help compiling.
1845 [ ! "$src" ] && set_src_path
1846 check_for_build_depends || return 1
1847 check_for_wanted
1848 unset target
1849 check_for_tarball && check_for_compile_rules
1852 # Cook command also include all features to manage lists which keep
1853 # track of wok/packages state.
1854 cook()
1856 cook_code=
1857 set_common_path
1858 check_for_receipt
1859 source_receipt
1861 # Define log path and start report.
1862 [ -f $LOCAL_REPOSITORY/log/$PACKAGE.html ] && rm $LOCAL_REPOSITORY/log/$PACKAGE.html
1863 report sublog $LOCAL_REPOSITORY/log/$PACKAGE.html
1864 report step "Cooking $PACKAGE"
1865 report open-bloc
1867 clean $PACKAGE
1868 [ -s $tmp/cooklist ] && sed "/^$PACKAGE$/d" -i $tmp/cooklist
1870 if compile_package; then
1871 remove_src
1872 refresh_packages_from_compile
1873 gen_package
1875 # Update packages-incoming repository.
1876 store_pkgname=$PACKAGE
1877 pkg_repository=$INCOMING_REPOSITORY
1878 update_packages_db
1880 PACKAGE=$store_pkgname
1881 unset store_pkgname
1883 # Upgrade to cooked packages if it was previously installed.
1884 report step "Look for package(s) to upgrade"
1885 for pkg in $(look_for_rwanted) $PACKAGE; do
1886 if [ -d $INSTALLED/$pkg ]; then
1887 tazpkg get-install $pkg --forced
1888 fi
1889 done
1890 report end-step
1891 else
1893 # Set package as broken.
1894 if ! grep -q ^$PACKAGE$ $PACKAGES_REPOSITORY/broken; then
1895 echo $PACKAGE >> $PACKAGES_REPOSITORY/broken
1896 fi
1897 gen_cookmd5
1898 cook_code=1
1899 fi
1901 # Remove build_depends in cook mode (if in cooklist, it's done when
1902 # checking build_depends of next package and we remove only unneeded
1903 # packages to keep chroot minimal and gain some time).
1904 if [ "$COMMAND" = cook ]; then
1905 remove_build_depends $MISSING_PACKAGE
1906 [ -x /usr/bin/clean-chroot ] && clean-chroot
1907 fi
1909 # Regen the cooklist if it was planned and command is not cook.
1910 [ "$regen_cooklist" ] && unset regen_cooklist && \
1911 [ "$COMMAND" != cook ] && sort_cooklist
1913 # Some hacks to set the bloc & function status as failed if cook was
1914 # failed.
1915 report_return_code=$cook_code
1916 report close-bloc
1917 report end-sublog
1918 return $cook_code
1921 cook_list()
1923 if [ -s $tmp/cooklist ]; then
1924 if [ -f /usr/bin/tazchroot ]; then
1925 # Note : options -main variables- are automatically keeped by
1926 # the sub-applications tazchroot/tazwok; as well as report data.
1927 cd $LOCAL_REPOSITORY
1928 [ ! -f tazchroot.conf ] && configure_tazchroot
1929 tazchroot tazwok cook-list --SLITAZ_DIR=$SLITAZ_DIR --SLITAZ_VERSION=$SLITAZ_VERSION ${undigest:+ --undigest=$undigest}
1930 return
1931 fi
1932 while [ -s $tmp/cooklist ]; do
1933 PACKAGE=$(sed 1!d $tmp/cooklist)
1934 cook
1935 done
1936 remove_build_depends $MISSING_PACKAGE $remove_later
1937 [ -x /usr/bin/clean-chroot ] && clean-chroot
1938 else
1939 echo "Nothing to cook."
1940 return
1941 fi
1944 configure_tazchroot()
1946 cat > $LOCAL_REPOSITORY/tazchroot.conf << EOF
1947 # Tazchroot configuration file - created by tazwok.
1949 # Default chroot path
1950 SLITAZ_DIR=$SLITAZ_DIR
1951 SLITAZ_VERSION=$SLITAZ_VERSION
1952 $( [ "$undigest" ] && echo "undigest=$undigest" )
1953 LOCAL_REPOSITORY=$SLITAZ_DIR/$(if [ "$undigest" ]; then echo '$undigest'; else echo '$SLITAZ_VERSION'; fi)
1954 chroot_dir=\$LOCAL_REPOSITORY/chroot
1956 # Default scripts path (theses scripts are added in the
1957 # $chroot_dir/usr/bin and can be called with tazchroot script)
1958 script_dir=/var/lib/tazchroot
1960 # List of directories to mount.
1961 list_dir="$(for dir in packages wok src packages-incoming log flavors iso; do echo $LOCAL_REPOSITORY/$dir; done)
1962 $SLITAZ_LOG$( [ "$undigest" ] && echo -e "\n$SLITAZ_DIR/$SLITAZ_VERSION/packages" )"
1964 create_chroot()
1966 mkdir -p \$chroot_dir
1967 for pkg in \$(tazwok build-depends toolchain --SLITAZ_DIR=\$SLITAZ_DIR --SLITAZ_VERSION=\$SLITAZ_VERSION${undigest:+ --undigest=\$undigest}); do
1968 tazpkg get-install \$pkg --root="\$chroot_dir"
1969 done
1971 # Store list of installed packages needed by cleanchroot.
1972 ls -1 \$chroot_dir/\$INSTALLED > \$chroot_dir/\$LOCALSTATE/chroot-pkgs
1974 sed -e "s~^SLITAZ_DIR=.*~SLITAZ_DIR=\$SLITAZ_DIR~" \\
1975 -e "s/^SLITAZ_VERSION=.*/SLITAZ_VERSION=\$SLITAZ_VERSION/" \\
1976 -i \$chroot_dir/etc/slitaz/slitaz.conf
1977 $( [ "$undigest" ] && echo ' echo "undigest='"$undigest"'" >> $chroot_dir/etc/slitaz/tazwok.conf')
1978 sed 's/LC_ALL/LC_ALL=POSIX/' -i \$chroot_dir/etc/profile
1981 mount_chroot()
1983 cp -a /etc/resolv.conf \$chroot_dir/etc/resolv.conf
1984 echo "\$LOCAL_REPOSITORY/packages" > \$chroot_dir\$LOCALSTATE/mirror
1985 mkdir -p \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming
1986 echo "\$LOCAL_REPOSITORY/packages-incoming" > \$chroot_dir\$LOCALSTATE/undigest/\${LOCAL_REPOSITORY##*/}-incoming/mirror
1987 $( [ "$undigest" ] && echo ' mkdir -p $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION
1988 echo "$SLITAZ_DIR/$SLITAZ_VERSION/packages" > $chroot_dir$LOCALSTATE/undigest/$SLITAZ_VERSION/mirror' )
1989 echo -e "\${LOCAL_REPOSITORY##*/}-incoming\nmain" > \$chroot_dir\$LOCALSTATE/priority
1990 mount -t proc proc \$chroot_dir/proc
1991 mount -t sysfs sysfs \$chroot_dir/sys
1992 mount -t devpts devpts \$chroot_dir/dev/pts
1993 mount -t tmpfs shm \$chroot_dir/dev/shm
1994 for dir in \$list_dir; do
1995 mkdir -p \$dir \$chroot_dir\$dir
1996 mount \$dir \$chroot_dir\$dir
1997 done
2000 umount_chroot()
2002 for dir in \$list_dir; do
2003 umount \$chroot_dir\$dir
2004 done
2005 umount \$chroot_dir/dev/shm
2006 umount \$chroot_dir/dev/pts
2007 umount \$chroot_dir/sys
2008 umount \$chroot_dir/proc
2010 EOF
2013 ########################################################################
2014 ######################### END OF NEW FUNCTIONS #########################
2015 ########################################################################
2017 # List packages providing a virtual package
2018 whoprovide()
2020 local i;
2021 for i in $(fgrep -l PROVIDE $WOK/*/receipt); do
2022 . $i
2023 case " $PROVIDE " in
2024 *\ $1\ *|*\ $1:*) echo $(basename $(dirname $i));;
2025 esac
2026 done
2029 ########################################################################
2030 # TAZWOK COMMANDS
2031 ########################
2033 case "$COMMAND" in
2034 stats)
2035 # Tazwok general statistics from the wok config file.
2037 get_tazwok_config
2038 echo -e "\n\033[1mTazwok configuration statistics\033[0m
2039 ================================================================================
2040 Wok directory : $WOK
2041 Packages repository : $PACKAGES_REPOSITORY
2042 Incoming repository : $INCOMING_REPOSITORY
2043 Sources repository : $SOURCES_REPOSITORY
2044 Log directory : $LOCAL_REPOSITORY/log
2045 Packages in the wok : `ls -1 $WOK | wc -l`
2046 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2047 Incoming packages : `ls -1 $INCOMING_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
2048 ================================================================================\n"
2049 ;;
2050 edit)
2051 get_tazwok_config
2052 check_for_package_on_cmdline
2053 check_for_receipt
2054 $EDITOR $WOK/$PACKAGE/receipt
2055 ;;
2056 build-depends)
2057 # List dependencies to rebuild wok, or only a package
2058 get_tazwok_config
2059 report(){ : ; }
2060 if [ ! "$PACKAGE" ] || [ "$PACKAGE" = toolchain ]; then
2061 scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
2062 --look_for=dep --with_dev --with_args
2063 else
2064 check_for_package_on_cmdline
2065 scan $PACKAGE --look_for=bdep --with_dev
2066 fi
2067 ;;
2068 gen-cooklist)
2069 check_root
2070 get_options_list="pkg"
2071 get_tazwok_config
2072 report(){ : ; }
2073 if ! [ "$pkg" ]; then
2074 if [ ! "$LIST" ] || [ "$LIST" = toolchain ]; then
2075 pkg="$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA"
2076 else
2077 cooklist=${LIST:-$PACKAGES_REPOSITORY/cooklist}
2078 fi
2079 fi
2080 gen_cook_list
2081 ;;
2082 check-depends)
2083 # Check package depends /!\
2084 get_tazwok_config
2085 echo ""
2086 echo -e "\033[1mCheck every receipt for DEPENDS - doesn't scan ELF files\033[0m
2087 ================================================================================"
2088 TMPDIR=/tmp/tazwok$$
2089 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
2091 # Build ALL_DEPENDS variable
2092 scan_dep()
2094 local i
2095 ALL_DEPENDS="$ALL_DEPENDS$PACKAGE "
2096 for i in $DEPENDS $SUGGESTED ; do
2097 case " $ALL_DEPENDS " in
2098 *\ $i\ *) continue;;
2099 esac
2100 [ -d $WOK/$i ] || {
2101 ALL_DEPENDS="$ALL_DEPENDS$i "
2102 continue
2104 DEPENDS=""
2105 SUGGESTED=""
2106 . $WOK/$i/receipt
2107 scan_dep
2108 done
2111 # Check for ELF file
2112 is_elf()
2114 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" \
2115 = "ELF" ]
2118 # Print shared library dependencies
2119 ldd()
2121 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
2124 mkdir $TMPDIR
2125 cd $TMPDIR
2126 for i in $LOCALSTATE/files.list.lzma \
2127 $LOCALSTATE/undigest/*/files.list.lzma ; do
2128 [ -f $i ] && lzma d $i -so >> files.list
2129 done
2130 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
2131 tazpkg extract $pkg > /dev/null 2>&1
2132 . */receipt
2133 ALL_DEPENDS="$DEFAULT_DEPENDS "
2134 scan_dep
2135 find */fs -type f | while read file ; do
2136 is_elf $file || continue
2137 case "$file" in
2138 *.o|*.ko|*.ko.gz) continue;;
2139 esac
2140 ldd $file | while read lib rem; do
2141 case "$lib" in
2142 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
2143 continue;;
2144 esac
2145 for dep in $(fgrep $lib files.list | cut -d: -f1); do
2146 case " $ALL_DEPENDS " in
2147 *\ $dep\ *) continue 2;;
2148 esac
2149 for vdep in $(fgrep $dep $LOCALSTATE/packages.equiv | cut -d= -f1); do
2150 case " $ALL_DEPENDS " in
2151 *\ $vdep\ *) continue 3;;
2152 esac
2153 done
2154 done
2155 [ -n "$dep" ] || dep="UNKNOWN"
2156 echo "$(basename $pkg): ${file#*fs} depends on package $dep for the shared library $lib"
2157 done
2158 done
2159 rm -rf */
2160 done
2161 cd /tmp
2162 rm -rf $TMPDIR
2163 ;;
2164 check)
2165 # Check wok consistency
2166 get_tazwok_config
2167 echo ""
2168 echo -e "\033[1mWok and packages checking\033[0m
2169 ================================================================================"
2170 cd $WOK
2171 for pkg in $(ls)
2172 do
2173 [ -f $pkg/receipt ] || continue
2174 RECEIPT= $pkg/receipt
2175 source_receipt
2176 [ "$PACKAGE" = "$pkg" ] || echo "Package $PACKAGE should be $pkg" >&2
2177 [ -n "$VERSION" ] || echo "Package $PACKAGE has no VERSION" >&2
2178 [ -n "$PACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded PACKED_SIZE" >&2
2179 [ -n "$UNPACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded UNPACKED_SIZE" >&2
2180 [ -n "$EXTRAVERSION" ] && echo "Package $PACKAGE has hardcoded EXTRAVERSION" >&2
2181 if [ -n "$WANTED" ]; then
2182 if [ ! -f $WANTED/receipt ]; then
2183 echo "Package $PACKAGE wants unknown $WANTED package" >&2
2184 else
2185 BASEVERSION=$(. $WANTED/receipt ; echo $VERSION)
2186 if [ "$VERSION" = "$WANTED" ]; then
2187 # BASEVERSION is computed in receipt
2188 fgrep -q '_pkg=' $pkg/receipt &&
2189 BASEVERSION=$VERSION
2190 fi
2191 if [ "$VERSION" != "$BASEVERSION" ]; then
2192 echo "Package $PACKAGE ($VERSION) wants $WANTED ($BASEVERSION)" >&2
2193 fi
2194 fi
2195 fi
2197 if [ -n "$CATEGORY" ]; then
2198 case " $(echo $CATEGORIES) " in
2199 *\ $CATEGORY\ *);;
2200 *) echo "Package $PACKAGE has an invalid CATEGORY" >&2;;
2201 esac
2202 else
2203 echo"Package $PACKAGE has no CATEGORY" >&2
2204 fi
2205 [ -n "$SHORT_DESC" ] || echo "Package $PACKAGE has no SHORT_DESC" >&2
2206 [ -n "$MAINTAINER" ] || echo "Package $PACKAGE has no MAINTAINER" >&2
2207 case "$WGET_URL" in
2208 ftp*|http*) busybox wget -s $WGET_URL 2> /dev/null ||
2209 echo "Package $PACKAGE has a wrong WGET_URL" >&2;;
2210 '') ;;
2211 *) echo "Package $PACKAGE has an invalid WGET_URL" >&2;;
2212 esac
2213 case "$WEB_SITE" in
2214 ftp*|http*);;
2215 '') echo "Package $PACKAGE has no WEB_SITE" >&2;;
2216 *) echo "Package $PACKAGE has an invalid WEB_SITE" >&2;;
2217 esac
2218 case "$MAINTAINER" in
2219 *\<*|*\>*) echo "Package $PACKAGE has an invalid MAINTAINER: $MAINTAINER" >&2;;
2220 esac
2221 case "$MAINTAINER" in
2222 *@*);;
2223 *) echo "Package $PACKAGE MAINTAINER is not an email address" >&2;;
2224 esac
2225 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2226 for i in $DEPENDS; do
2227 [ -d $i ] && continue
2228 [ -n "$(whoprovide $i)" ] && continue
2229 echo -e "$MSG $i"
2230 MSG=""
2231 done
2232 MSG="Missing build dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n" >&2
2233 for i in $BUILD_DEPENDS; do
2234 [ -d $i ] && continue
2235 [ -n "$(whoprovide $i)" ] && continue
2236 echo -e "$MSG $i"
2237 MSG=""
2238 done
2239 MSG="Dependencies loop between $PACKAGE and :\n"
2240 ALL_DEPS=""
2241 check_for_deps_loop $PACKAGE $DEPENDS
2242 [ -d $WOK/$pkg/taz ] && for i in $BUILD_DEPENDS; do
2243 [ $WOK/$pkg/taz -nt $INSTALLED/$i/files.list ] && continue
2244 echo "$pkg should be rebuilt after $i installation"
2245 done
2246 done
2247 ;;
2248 list)
2249 # List packages in wok directory. User can specify a category.
2251 get_tazwok_config
2252 if [ "$2" = "category" ]; then
2253 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
2254 exit 0
2255 fi
2256 # Check for an asked category.
2257 if [ -n "$2" ]; then
2258 ASKED_CATEGORY=$2
2259 echo ""
2260 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
2261 echo "================================================================================"
2262 for pkg in $WOK/*
2263 do
2264 [ ! -f $pkg/receipt ] && continue
2265 . $pkg/receipt
2266 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
2267 echo -n "$PACKAGE"
2268 echo -e "\033[28G $VERSION"
2269 packages=$(($packages+1))
2270 fi
2271 done
2272 echo "================================================================================"
2273 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
2274 else
2275 # By default list all packages and version.
2276 echo ""
2277 echo -e "\033[1mList of packages in the wok\033[0m"
2278 echo "================================================================================"
2279 for pkg in $WOK/*
2280 do
2281 [ ! -f $pkg/receipt ] && continue
2282 . $pkg/receipt
2283 echo -n "$PACKAGE"
2284 echo -en "\033[28G $VERSION"
2285 echo -e "\033[42G $CATEGORY"
2286 packages=$(($packages+1))
2287 done
2288 echo "================================================================================"
2289 echo -e "$packages packages available in the wok.\n"
2290 fi
2291 ;;
2292 info)
2293 # Information about a package.
2295 get_tazwok_config
2296 check_for_package_on_cmdline
2297 check_for_receipt
2298 . $WOK/$PACKAGE/receipt
2299 echo ""
2300 echo -e "\033[1mTazwok package information\033[0m
2301 ================================================================================
2302 Package : $PACKAGE
2303 Version : $VERSION
2304 Category : $CATEGORY
2305 Short desc : $SHORT_DESC
2306 Maintainer : $MAINTAINER"
2307 if [ ! "$WEB_SITE" = "" ]; then
2308 echo "Web site : $WEB_SITE"
2309 fi
2310 if [ ! "$DEPENDS" = "" ]; then
2311 echo "Depends : $DEPENDS"
2312 fi
2313 if [ ! "$WANTED" = "" ]; then
2314 echo "Wanted src : $WANTED"
2315 fi
2316 echo "================================================================================"
2317 echo ""
2318 ;;
2319 check-log)
2320 # We just cat the file log to view process info.
2322 get_tazwok_config
2323 if [ ! -f "$LOG" ]; then
2324 echo -e "\nNo process log found. The package is probably not cooked.\n" >&2
2325 exit 1
2326 else
2327 echo ""
2328 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
2329 echo "================================================================================"
2330 cat $LOG
2331 echo "================================================================================"
2332 echo ""
2333 if [ -s "$WOK/$PACKAGE/warning.txt" ]; then
2334 echo -e "\033[1mCook warning(s) for :\033[0m $PACKAGE"
2335 echo "================================================================================"
2336 cat "$WOK/$PACKAGE/warning.txt"
2337 echo "================================================================================"
2338 echo ""
2339 fi
2340 fi
2341 ;;
2342 search)
2343 # Search for a package by pattern or name.
2345 get_tazwok_config
2346 if [ -z "$2" ]; then
2347 echo -e "\nPlease specify a pattern or a package name to search." >&2
2348 echo -e "Example : 'tazwok search gcc'.\n" >&2
2349 exit 1
2350 fi
2351 echo ""
2352 echo -e "\033[1mSearch result for :\033[0m $2"
2353 echo "================================================================================"
2354 list=`ls -1 $WOK | fgrep $2`
2355 for pkg in $list
2356 do
2357 . $WOK/$pkg/receipt
2358 echo -n "$PACKAGE "
2359 echo -en "\033[24G $VERSION"
2360 echo -e "\033[42G $CATEGORY"
2361 packages=$(($PACKAGEs+1))
2362 done
2363 echo "================================================================================"
2364 echo "$packages packages found for : $2"
2365 echo ""
2366 ;;
2367 compile)
2368 # Configure and make a package with the receipt.
2370 get_tazwok_config
2371 source_lib report
2372 report start
2373 compile_package
2374 ;;
2375 genpkg)
2376 # Generate a package.
2378 get_tazwok_config
2379 source_lib report
2380 report start
2381 gen_package
2382 ;;
2383 cook)
2384 # Compile and generate a package. Just execute tazwok with
2385 # the good commands.
2387 check_root
2388 get_tazwok_config
2389 source_lib report
2390 report start
2391 update_wan_db
2392 check_for_commit
2393 [ "$plan_sort_depdb" ] && sort -o $dep_db $dep_db && unset plan_sort_depdb
2394 [ "$plan_sort_wandb" ] && sort -o $wan_db $wan_db && unset plan_sort_wandb
2395 if [ "$plan_regen_cookorder" ]; then
2396 grep -q "^#" $PACKAGES_REPOSITORY/cookorder.txt || \
2397 sed 1i"#PlanSort" -i $PACKAGES_REPOSITORY/cookorder.txt
2398 fi
2399 cook
2400 ;;
2401 sort-cooklist)
2402 if [ ! "$LIST" ]; then
2403 echo "Usage : tazwok sort-cooklist cooklist" >&2\
2404 exit 1
2405 fi
2406 get_tazwok_config
2407 source_lib report
2408 report start
2409 cooklist=$LIST
2410 sort_cooklist
2411 cp -af $tmp/cooklist $cooklist
2412 ;;
2413 cook-list)
2414 # Cook all packages listed in a file or in default cooklist.
2415 check_root
2416 get_options_list="pkg forced"
2417 get_tazwok_config
2418 source_lib report
2419 report start
2420 if ! [ "$pkg" ]; then
2421 cooklist=${LIST:-$PACKAGES_REPOSITORY/cooklist}
2422 fi
2423 gen_cook_list
2424 cook_list
2425 ;;
2426 clean)
2427 # Clean up a package work directory + thoses which want it.
2429 get_tazwok_config
2430 check_for_package_on_cmdline
2431 check_for_receipt
2432 source_lib report
2433 report start
2434 . $RECEIPT
2435 clean
2436 ;;
2437 gen-clean-wok)
2438 # Generate a clean wok from the current wok by copying all receipts
2439 # and stuff directory.
2441 get_tazwok_config
2442 source_lib report
2443 report start
2444 if [ -z "$ARG" ]; then
2445 echo -e "\nPlease specify the destination for the new clean wok.\n" >&2
2446 exit 1
2447 else
2448 dest=$ARG
2449 mkdir -p $dest
2450 fi
2451 report step "Creating clean wok in : $dest"
2452 for pkg in `ls -1 $WOK`
2453 do
2454 mkdir -p $dest/$pkg
2455 cp -a $WOK/$pkg/receipt $dest/$pkg
2456 [ -f $WOK/$pkg/description.txt ] && \
2457 cp -a $WOK/$pkg/description.txt $dest/$pkg
2458 if [ -d "$WOK/$pkg/stuff" ]; then
2459 cp -a $WOK/$pkg/stuff $dest/$pkg
2460 fi
2461 done
2462 [ -d $WOK/.hg ] && cp -a $WOK/.hg $dest
2463 report end-step
2464 echo "Packages cleaned : `ls -1 $dest | wc -l`"
2465 echo ""
2466 ;;
2467 clean-wok)
2468 # Clean all packages in the work directory
2470 get_tazwok_config
2471 source_lib report
2472 report start
2473 report step "Cleaning wok"
2474 for PACKAGE in `ls -1 $WOK`
2475 do
2476 set_common_path
2477 source_receipt
2478 clean
2479 done
2480 echo "`ls -1 $WOK | wc -l` packages cleaned."
2481 ;;
2482 gen-list)
2483 get_tazwok_config
2484 if [ "$2" ]; then
2485 if [ -d "$2" ]; then
2486 pkg_repository=$2
2487 else
2488 echo -e "\nUnable to find directory : $2\n" >&2
2489 exit 1
2490 fi
2491 fi
2493 source_lib report
2494 report start
2495 if [ "$pkg_repository" ]; then
2496 gen_packages_db
2497 else
2498 pkg_repository=$PACKAGES_REPOSITORY && gen_packages_db
2499 pkg_repository=$INCOMING_REPOSITORY && gen_packages_db
2500 fi
2501 ;;
2502 check-list)
2503 # The directory to move into by default is the repository,
2504 # if $2 is not empty cd into $2.
2506 get_tazwok_config
2507 if [ "$2" ]; then
2508 if [ -d "$2" ]; then
2509 pkg_repository=$2
2510 else
2511 echo -e "\nUnable to find directory : $2\n" >&2
2512 exit 1
2513 fi
2514 fi
2516 source_lib report
2517 report start
2518 if [ "$pkg_repository" ]; then
2519 update_packages_db
2520 else
2521 pkg_repository=$PACKAGES_REPOSITORY && update_packages_db
2522 pkg_repository=$INCOMING_REPOSITORY && update_packages_db
2523 fi
2524 ;;
2525 new-tree)
2526 # Just create a few directories and generate an empty receipt to prepare
2527 # the creation of a new package.
2529 get_tazwok_config
2530 check_for_package_on_cmdline
2531 if [ -d $WOK/$PACKAGE ]; then
2532 echo -e "\n$PACKAGE package tree already exists.\n" >&2
2533 exit 1
2534 fi
2535 echo "Creating : $WOK/$PACKAGE"
2536 mkdir $WOK/$PACKAGE
2537 cd $WOK/$PACKAGE
2538 echo -n "Preparing the receipt..."
2540 # Default receipt begin.
2542 echo "# SliTaz package receipt." > receipt
2543 echo "" >> receipt
2544 echo "PACKAGE=\"$PACKAGE\"" >> receipt
2545 # Finish the empty receipt.
2546 cat >> receipt << "EOF"
2547 VERSION=""
2548 CATEGORY=""
2549 SHORT_DESC=""
2550 MAINTAINER=""
2551 DEPENDS=""
2552 TARBALL="$PACKAGE-$VERSION.tar.gz"
2553 WEB_SITE=""
2554 WGET_URL=""
2556 # Rules to configure and make the package.
2557 compile_rules()
2559 cd $src
2560 ./configure && make && make install
2563 # Rules to gen a SliTaz package suitable for Tazpkg.
2564 genpkg_rules()
2566 mkdir -p $fs/usr
2567 cp -a $_pkg/usr/bin $fs/usr
2570 EOF
2572 # Default receipt end.
2574 status
2575 # Interactive mode, asking and seding.
2576 if [ "$3" = "--interactive" ]; then
2577 echo "Entering into interactive mode..."
2578 echo "================================================================================"
2579 echo "Package : $PACKAGE"
2580 # Version.
2581 echo -n "Version : " ; read anser
2582 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
2583 # Category.
2584 echo -n "Category : " ; read anser
2585 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
2586 # Short description.
2587 echo -n "Short desc : " ; read anser
2588 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
2589 # Maintainer.
2590 echo -n "Maintainer : " ; read anser
2591 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
2592 # Web site.
2593 echo -n "Web site : " ; read anser
2594 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
2595 echo ""
2596 # Wget URL.
2597 echo "Wget URL to download source tarball."
2598 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
2599 echo -n "Wget url : " ; read anser
2600 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
2601 # Ask for a stuff dir.
2602 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
2603 if [ "$anser" = "y" ]; then
2604 echo -n "Creating the stuff directory..."
2605 mkdir stuff && status
2606 fi
2607 # Ask for a description file.
2608 echo -n "Are you going to write a description ? (y/N) : " ; read anser
2609 if [ "$anser" = "y" ]; then
2610 echo -n "Creating the description.txt file..."
2611 echo "" > description.txt && status
2612 fi
2613 echo "================================================================================"
2614 echo ""
2615 fi
2616 ;;
2617 remove)
2618 # Remove a package from the wok.
2620 get_tazwok_config
2621 check_for_package_on_cmdline
2622 echo ""
2623 echo -n "Please confirm deletion (y/N) : "; read anser
2624 if [ "$anser" = "y" ]; then
2625 echo -n "Removing $PACKAGE..."
2626 rm -rf $WOK/$PACKAGE && status
2627 echo ""
2628 fi
2629 ;;
2630 hgup)
2631 # Pull and update a Hg wok.
2632 get_tazwok_config
2633 if ls -l $WOK/.hg/hgrc | fgrep -q "root"; then
2634 check_root
2635 fi
2636 cd $WOK
2637 hg pull && hg update
2638 ;;
2639 maintainers)
2640 get_tazwok_config
2641 echo ""
2642 echo "List of maintainers for: $WOK"
2643 echo "================================================================================"
2644 touch /tmp/slitaz-maintainers
2645 for pkg in $WOK/*
2646 do
2647 . $pkg/receipt
2648 if ! fgrep -q "$MAINTAINER" /tmp/slitaz-maintainers; then
2649 echo "$MAINTAINER" >> /tmp/slitaz-maintainers
2650 echo "$MAINTAINER"
2651 fi
2652 done
2653 echo "================================================================================"
2654 echo "Maintainers: `cat /tmp/slitaz-maintainers | wc -l`"
2655 echo ""
2656 # Remove tmp files
2657 rm -f /tmp/slitaz-maintainers
2658 ;;
2659 maintained-by)
2660 # Search for packages maintained by a contributor.
2661 get_tazwok_config
2662 if [ ! -n "$2" ]; then
2663 echo "Specify a name or email of a maintainer." >&2
2664 exit 1
2665 fi
2666 echo "Maintainer packages"
2667 echo "================================================================================"
2668 for pkg in $WOK/*
2669 do
2670 . $pkg/receipt
2671 if echo "$MAINTAINER" | fgrep -q "$2"; then
2672 echo "$PACKAGE"
2673 packages=$(($PACKAGEs+1))
2674 fi
2675 done
2676 echo "================================================================================"
2677 echo "Packages maintained by $2: $PACKAGEs"
2678 echo ""
2679 ;;
2680 check-src)
2681 # Verify if upstream package is still available
2683 get_tazwok_config
2684 check_for_package_on_cmdline
2685 check_for_receipt
2686 source_receipt
2687 check_src()
2689 for url in $@; do
2690 busybox wget -s $url 2>/dev/null && break
2691 done
2693 if [ "$WGET_URL" ];then
2694 echo -n "$PACKAGE : "
2695 check_src $WGET_URL
2696 status
2697 else
2698 echo "No tarball to check for $PACKAGE"
2699 fi
2700 ;;
2701 get-src)
2702 check_root
2703 get_options_list="target nounpack"
2704 get_tazwok_config
2705 check_for_package_on_cmdline
2706 check_for_receipt
2707 source_receipt
2708 if [ "$WGET_URL" ];then
2709 source_lib report
2710 report start
2711 check_for_tarball
2712 else
2713 echo "No tarball to download for $PACKAGE"
2714 fi
2715 ;;
2716 check-commit)
2717 check_root
2718 get_options_list="missing forced"
2719 get_tazwok_config
2720 source_lib report
2721 report start
2722 if [ "$forced" ]; then
2723 rm -f $WOK/*/md5
2724 unset forced
2725 fi
2726 if [ "$missing" ]; then
2727 pkg=$(ls -1 $WOK)
2728 else
2729 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
2730 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
2731 } | sort -u)"
2732 fi
2733 cooklist=$PACKAGES_REPOSITORY/cooklist
2734 gen_cook_list
2735 ;;
2736 cook-commit)
2737 check_root
2738 get_options_list="missing forced"
2739 get_tazwok_config
2740 source_lib report
2741 report start
2742 if [ "$forced" ]; then
2743 rm -f $WOK/*/md5
2744 unset forced
2745 fi
2746 if [ "$missing" ]; then
2747 pkg=$(ls -1 $WOK)
2748 else
2749 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
2750 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
2751 } | sort -u)"
2752 fi
2753 cooklist=$PACKAGES_REPOSITORY/cooklist
2754 gen_cook_list
2755 cook_list
2756 ;;
2757 cook-all)
2758 check_root
2759 get_options_list="forced missing"
2760 get_tazwok_config
2761 source_lib report
2762 report start
2763 if [ "$missing" ]; then
2764 pkg=$(ls -1 $WOK)
2765 else
2766 pkg="$({ grep ^[a-zA-Z0-9] $PACKAGES_REPOSITORY/packages.txt
2767 grep ^[a-zA-Z0-9] $INCOMING_REPOSITORY/packages.txt
2768 } | sort -u)"
2769 fi
2770 cooklist=$PACKAGES_REPOSITORY/cooklist
2771 gen_cook_list
2772 cook_list
2773 ;;
2774 gen-wok-db)
2775 check_root
2776 get_tazwok_config
2777 source_lib report
2778 report start
2779 gen_wok_db
2780 ;;
2781 report)
2782 check_root
2783 get_tazwok_config
2784 cd $PACKAGES_REPOSITORY
2785 if [ "$2" ]; then
2786 case $2 in
2787 commit|cooklist|incoming|broken|blocked)
2788 show="$2"
2789 ;;
2790 *)
2791 echo "usage : tazwok report [commit|cooklist|incoming|broken|blocked]" >&2
2792 exit 1
2793 ;;
2794 esac
2795 else
2796 show="commit cooklist incoming broken blocked"
2797 fi
2798 for i in $show; do
2799 if [ -s $i ]; then
2800 echo ""
2801 echo -e "\033[1m$i\033[0m"
2802 echo "================================================================================"
2803 cat $i
2804 echo "================================================================================"
2805 echo ""
2806 fi
2807 done
2808 ;;
2809 check-incoming)
2810 check_root
2811 get_options_list="forced"
2812 get_tazwok_config
2813 source_lib report
2814 report start
2815 check_for_incoming
2816 ;;
2817 configure-chroot)
2818 check_root
2819 get_tazwok_config
2820 if [ -f /usr/bin/tazchroot ]; then
2821 cd $LOCAL_REPOSITORY
2822 configure_tazchroot
2823 else
2824 echo "The packages tazchroot need to be installed" >&2
2825 exit 1
2826 fi
2827 ;;
2828 chroot)
2829 check_root
2830 get_tazwok_config
2831 # Merge this and the other chroot function ?.
2832 if [ -f /usr/bin/tazchroot ]; then
2833 cd $LOCAL_REPOSITORY
2834 [ ! -f tazchroot.conf ] && configure_tazchroot
2835 tazchroot
2836 else
2837 echo "The packages tazchroot need to be installed" >&2
2838 exit 1
2839 fi
2840 ;;
2841 cook-toolchain)
2842 check_root
2843 get_tazwok_config
2844 echo -n "" > $PACKAGES_REPOSITORY/broken
2845 if [ -f /usr/bin/tazchroot ]; then
2846 cd $LOCAL_REPOSITORY
2847 [ ! -f tazchroot.conf ] && configure_tazchroot
2848 tazchroot cook-toolchain
2849 # Buggy : chroot can be elsewhere.
2850 rm -r $LOCAL_REPOSITORY/chroot
2851 # /!\ to be writed :
2852 # next rm chroot and plan cook-all by pushing all packages
2853 # in cooklist.
2854 else
2855 echo "The packages tazchroot need to be installed" >&2
2856 exit 1
2857 fi
2858 ;;
2859 webserver)
2860 check_root
2861 get_tazwok_config
2862 if [ "$ARG" = on ]; then
2863 if [ "$WEBSERVER" ] && [ -f "$WEBSERVER/repositories.list" ] && \
2864 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
2865 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
2866 exit 1
2867 fi
2868 if ! [ -f $LOCAL_REPOSITORY/tazchroot.conf ]; then
2869 tazwok configure-chroot ${undigest:+--undigest=$undigest} --SLITAZ_VERSION=$SLITAZ_VERSION --SLITAZ_DIR=$SLITAZ_DIR
2870 fi
2871 for pkg in php lighttpd; do
2872 [ -d $INSTALLED/$pkg ] || missing="$missing $pkg"
2873 done
2874 if [ "$missing" ]; then
2875 echo "You need to install those packages to start webserver: $missing." >&2
2876 exit 1
2877 fi
2878 if [ ! -f "$LOCAL_REPOSITORY/tazwok.conf" ]; then
2879 echo "Copying /etc/slitaz/tazwok.conf to $LOCAL_REPOSITORY/tazwok.conf: webserver is configured repository-by-repository."
2880 cp /etc/slitaz/tazwok.conf $LOCAL_REPOSITORY
2881 fi
2882 if ! [ "$WEBSERVER" ]; then
2883 echo -n "Where to store php pages (default: /var/www/vhosts/bb)? "
2884 read WEBSERVER
2885 [ "$WEBSERVER" ] || WEBSERVER="/var/www/vhosts/bb"
2886 fi
2887 if [ -f "$WEBSERVER/repositories.list" ] && \
2888 grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
2889 echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
2890 exit 1
2891 fi
2892 mkdir -p $WEBSERVER
2893 echo "${undigest:-$SLITAZ_VERSION}" >> $WEBSERVER/repositories.list
2894 for file in index.php log.php; do
2895 [ -f "$WEBSERVER/$file" ] || ln -s /usr/share/slitaz/web-bb/$file $WEBSERVER
2896 done
2897 source $LOCAL_REPOSITORY/tazchroot.conf
2898 echo "<?php
2900 // Web interface configuration
2902 \$version=\"${undigest:-$SLITAZ_VERSION}\";
2903 \$chroot=\"$chroot_dir\";
2904 \$lockfile=\"\$chroot/proc/1\";
2905 \$db_dir=\"$PACKAGES_REPOSITORY\";
2906 \$log_dir=\"$LOCAL_REPOSITORY/log\";
2907 \$packages=\"$PACKAGES_REPOSITORY\";
2908 \$incoming=\"$INCOMING_REPOSITORY\";
2909 \$wok=\"$WOK\";
2911 ?>" > $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
2912 [ -L "$WEBSERVER/web" ] || ln -s /usr/share/slitaz/web $WEBSERVER
2913 echo "WEBSERVER=\"$WEBSERVER\"" >> $LOCAL_REPOSITORY/tazwok.conf
2914 if [ -L "$WEBSERVER/conf.php" ]; then
2915 echo "Do yo want to make ${undigest:-$SLITAZ_VERSION} the default page (y/N) ? "
2916 read answer
2917 if [ "$answer" = y ]; then
2918 rm $WEBSERVER/conf.php
2919 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
2920 fi
2921 else
2922 ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
2923 fi
2924 elif [ "$ARG" = off ]; then
2925 if ! [ "$WEBSERVER" ]; then
2926 echo "No webserver running for ${undigest:-$SLITAZ_VERSION}" >&2
2927 exit 1
2928 fi
2929 sed '/^WEBSERVER/d' -i $LOCAL_REPOSITORY/tazwok.conf
2930 sed "/^${undigest:-$SLITAZ_VERSION}$/d" -i $WEBSERVER/repositories.list
2931 rm $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
2932 if ! [ -s "$WEBSERVER/repositories.list" ]; then
2933 echo "$WEBSERVER/repositories.list is empty; tazwok doesn't remove the server automatically in case you have important stuff in it. If it's not the case, you can remove it using: rm -r $WEBSERVER"
2934 rm $WEBSERVER/conf.php
2935 elif [ "$(readlink $WEBSERVER/conf.php)" = "$WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php" ]; then
2936 echo "${undigest:-$SLITAZ_VERSION} was the default version to use; switched to : $(sed 1!d $WEBSERVER/repositories.list)"
2937 rm $WEBSERVER/conf.php
2938 ln -s $WEBSERVER/conf-$(sed 1!d $WEBSERVER/repositories.list).php $WEBSERVER/conf.php
2939 fi
2940 else
2941 echo "Usage: tazwok webserver on/off" >&2
2942 exit 1
2943 fi
2944 ;;
2945 usage|*)
2946 # Print usage also for all unknown commands.
2948 usage
2949 ;;
2950 esac
2952 report stop 2>/dev/null || exit 0