tazwok view tazwok @ rev 117

Prepa for release 2.2
author Christophe Lincoln <pankso@slitaz.org>
date Fri Feb 13 00:09:59 2009 +0100 (2009-02-13)
parents 09a5c6aa4f92
children e453ccdea454
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 #
11 VERSION=2.2
13 ####################
14 # Tazwok variables #
15 ####################
17 # Packages categories.
18 CATEGORIES="
19 base-system
20 x-window
21 utilities
22 network
23 graphics
24 multimedia
25 office
26 development
27 system-tools
28 security
29 games
30 misc
31 meta
32 non-free"
34 # Use words rather than numbers in the code.
35 COMMAND=$1
36 PACKAGE=$2
37 LIST=$2
39 # Include config file or exit if no file found.
40 if [ -f "./tazwok.conf" ]; then
41 . ./tazwok.conf
42 elif [ -f "/etc/tazwok.conf" ]; then
43 . /etc/tazwok.conf
44 else
45 echo -e "\nUnable to find the configuration file : /etc/tazwok.conf"
46 echo -e "Please read the Tazwok documentation.\n"
47 exit 0
48 fi
50 # Create Taz wok needed directories if user is root.
51 if test $(id -u) = 0 ; then
52 # Check for the wok directory.
53 if [ ! -d "$WOK" ]; then
54 echo "Creating the wok directory..."
55 mkdir -p $WOK
56 chmod 777 $WOK
57 fi
58 # Check for the packages repository.
59 if [ ! -d "$PACKAGES_REPOSITORY" ]; then
60 echo "Creating the packages repository..."
61 mkdir -p $PACKAGES_REPOSITORY
62 fi
63 # Check for the sources repository.
64 if [ ! -d "$SOURCES_REPOSITORY" ]; then
65 echo "Creating the sources repository..."
66 mkdir -p $SOURCES_REPOSITORY
67 fi
68 fi
70 # The path to the most important file used by Tazwok.
71 # The receipt is used to compile the source code and
72 # generate suitable packages for Tazpkg.
73 RECEIPT="$WOK/$PACKAGE/receipt"
75 # The path to the process log file.
76 LOG="$WOK/$PACKAGE/process.log"
78 ####################
79 # Tazwok functions #
80 ####################
82 # Print the usage (English).
83 usage ()
84 {
85 echo -e "\nSliTaz sources compiler and packages generator - Version: $VERSION\n
86 \033[1mUsage: \033[0m `basename $0` [command] [package|list|category|dir|id] [--option]
87 \033[1mCommands: \033[0m\n
88 usage Print this short usage.
89 stats Print Tazwok statistics from the config file and the wok.
90 build-depends Generate a list of package to build wok.
91 cmp|compare Compare the wok and the cooked pkgs (--remove old pkgs).
92 list List all packages in the wok tree or by category.
93 info Get information about a package in the wok.
94 check Check every receipt for common errors.
95 check-log Check the process log file of a package.
96 search Search for a package in the wok by pattern or name.
97 compile Configure and build a package using the receipt rules.
98 genpkg Generate a suitable package for Tazpkg with the rules.
99 cook Compile and generate a package directly.
100 cook-list Cook all packages specified in the list by order.
101 clean Clean all generated files in the package tree.
102 new-tree Prepare a new package tree and receipt (--interactive).
103 gen-list Generate a packages list for a repository (--text).
104 gen-clean-wok Gen a clean wok in a dir ('clean-wok' cleans current wok).
105 remove Remove a package from the wok.
106 hgup Pull and update a wok under Hg.
107 maintainers List all maintainers in the wok.
108 maintained-by List packages maintained by a contributor\n"
109 }
111 # Status function.
112 status()
113 {
114 local CHECK=$?
115 echo -en "\\033[70G[ "
116 if [ $CHECK = 0 ]; then
117 echo -en "\\033[1;33mOK"
118 else
119 echo -en "\\033[1;31mFailed"
120 fi
121 echo -e "\\033[0;39m ]"
122 }
124 # Check if user is root.
125 check_root()
126 {
127 if test $(id -u) != 0 ; then
128 echo -e "\nYou must be root to run `basename $0` with this option."
129 echo -e "Please type 'su' and root password to become super-user.\n"
130 exit 0
131 fi
132 }
134 # Check for a package name on cmdline.
135 check_for_package_on_cmdline()
136 {
137 if [ -z "$PACKAGE" ]; then
138 echo -e "\nYou must specify a package name on the command line."
139 echo -e "Example : tazwok $COMMAND package\n"
140 exit 0
141 fi
142 }
144 # Check for the receipt of a package used to cook.
145 check_for_receipt()
146 {
147 if [ ! -f "$RECEIPT" ]; then
148 echo -e "\nUnable to find the receipt : $RECEIPT\n"
149 exit 0
150 fi
151 }
153 # Check for a specified file list on cmdline.
154 check_for_list()
155 {
156 if [ -z "$LIST" ]; then
157 echo -e "\nPlease specify the path to the list of packages to cook.\n"
158 exit 0
159 fi
160 # Check if the list of packages exists.
161 if [ -f "$LIST" ]; then
162 LIST=`cat $LIST`
163 else
164 echo -e "\nUnable to find $LIST packages list.\n"
165 exit 0
166 fi
167 }
169 # Check for the wanted package if specified in WANTED
170 # receipt variable. Set the $src/$_pkg variable to help compiling
171 # and generating packages.
172 check_for_wanted()
173 {
174 if [ ! "$WANTED" = "" ]; then
175 echo -n "Checking for the wanted package..."
176 if [ ! -d "$WOK/$WANTED" ]; then
177 echo -e "\nWanted package is missing in the work directory.\n"
178 exit 0
179 fi
180 # Checking for buildtree of Wanted package
181 if [ ! -d "$WOK/$WANTED/taz" ]; then
182 echo -e "\n\nSource files of wanted package is missing in the work directory."
183 echo -n "Would you like to build the missing package (y/N) ? " ; read anser
184 if [ "$anser" == "y" ]; then
185 tazwok cook $WANTED
186 else
187 echo -e "\nWanted package source tree is missing in the work directory.\n"
188 exit 0
189 fi
190 fi
191 status
192 # Set wanted src path.
193 src=$WOK/$WANTED/$WANTED-$VERSION
194 _pkg=$src/_pkg
195 fi
196 }
199 # Check for build dependencies, notify user and install if specified.
200 check_for_build_depends()
201 {
202 echo "Checking for build dependencies..."
203 for pkg in $BUILD_DEPENDS
204 do
205 if [ ! -d "/var/lib/tazpkg/installed/$pkg" ]; then
206 MISSING_PACKAGE=$pkg
207 fi
208 done
209 if [ ! "$MISSING_PACKAGE" = "" ]; then
210 echo "================================================================================"
211 for pkg in $BUILD_DEPENDS
212 do
213 if [ ! -d "/var/lib/tazpkg/installed/$pkg" ]; then
214 MISSING_PACKAGE=$pkg
215 echo "Missing : $pkg"
216 fi
217 done
218 echo "================================================================================"
219 echo "You can continue, exit or install missing dependencies."
220 echo -n "Install, continue or exit (install/y/N) ? "; read anser
221 case $anser in
222 install)
223 for pkg in $BUILD_DEPENDS
224 do
225 if [ ! -d "/var/lib/tazpkg/installed/$pkg" ]; then
226 tazpkg get-install $pkg
227 fi
228 done ;;
229 y|yes)
230 continue ;;
231 *)
232 exit 0 ;;
233 esac
234 fi
235 }
237 # Check for loop in deps tree.
238 check_for_deps_loop()
239 {
240 local list
241 local pkg
242 local deps
243 pkg=$1
244 shift
245 [ -n "$1" ] || return
246 list=""
247 # Filter out already processed deps
248 for i in $@; do
249 case " $ALL_DEPS" in
250 *\ $i\ *);;
251 *) list="$list $i";;
252 esac
253 done
254 ALL_DEPS="$ALL_DEPS$list "
255 for i in $list; do
256 [ -f $i/receipt ] || continue
257 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
258 case " $deps " in
259 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
260 *) check_for_deps_loop $pkg $deps;;
261 esac
262 done
263 }
265 download()
266 {
267 for file in $@; do
268 wget $file && break
269 done
270 }
272 # Configure and make a package with the receipt.
273 compile_package()
274 {
275 check_for_package_on_cmdline
276 # Include the receipt to get all needed variables and functions
277 # and cd into the work directory to start the work.
278 check_for_receipt
279 . $RECEIPT
280 # Log the package name and date.
281 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
282 echo "package $PACKAGE (compile)" >> $LOG
283 # Set wanted $src variable to help compiling.
284 if [ ! "$SOURCE" = "" ]; then
285 src=$WOK/$PACKAGE/$SOURCE-$VERSION
286 else
287 src=$WOK/$PACKAGE/$PACKAGE-$VERSION
288 fi
289 check_for_build_depends
290 check_for_wanted
291 echo ""
292 echo "Starting to cook $PACKAGE..."
293 echo "================================================================================"
294 # Check for src tarball and wget if needed.
295 if [ ! "$WGET_URL" = "" ]; then
296 echo "Checking for source tarball... "
297 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
298 cd $SOURCES_REPOSITORY
299 download $WGET_URL
300 #wget $WGET_URL
301 # Exit if download failed to avoid errors.
302 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
303 echo -e "\nDownload failed, exiting. Please check WGET_URL variable.\n"
304 exit 1
305 fi
306 else
307 echo -n "Source tarball exit... "
308 status
309 fi
310 # Untaring source if necessary. We don't need to extract source if
311 # the package is built with a wanted source package.
312 if [ "$WANTED" = "" ]; then
313 if [ ! -d $src ]; then
314 # Log process.
315 echo "untaring $TARBALL" >> $LOG
316 echo -n "Untaring $TARBALL... "
317 case "$TARBALL" in
318 *zip) ( cd $WOK/$PACKAGE; unzip -o $SOURCES_REPOSITORY/$TARBALL );;
319 *bz2) tar xjf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
320 *tar) tar xf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
321 *Z) tar xZf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
322 *) tar xzf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
323 esac
324 status
325 # Permissions settings
326 chown -R root.root $WOK/$PACKAGE/$PACKAGE-* 2>/dev/null
327 chown -R root.root $WOK/$PACKAGE/$SOURCE-* 2>/dev/null
328 else
329 echo -n "Source direcory exit... " && status
330 fi
331 fi
332 fi
333 cd $WOK/$PACKAGE
334 # Log and execute compile_rules function if it exists, to configure and
335 # make the package if it exists.
336 if grep -q ^compile_rules $RECEIPT; then
337 echo "executing compile_rules" >> $LOG
338 compile_rules
339 # Exit if compilation failed so the binary package
340 # is not generated when using the cook comand.
341 local CHECK=$?
342 if [ $CHECK = 0 ]; then
343 echo "================================================================================"
344 echo "$PACKAGE compiled on : `date +%Y%m%d\ \%H:%M:%S`"
345 echo ""
346 echo "compilation done : `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
347 else
348 echo "================================================================================"
349 echo "Compilation failed. Please read the compilator output."
350 echo "" && exit 1
351 fi
352 else
353 echo "no compile_rules" >> $LOG
354 echo -e "No compile rules for $PACKAGE...\n"
355 fi
356 }
358 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
359 # so some packages need to copy these files with the receipt and genpkg_rules.
360 # This function is executed by gen_package when 'tazwok genpkg'.
361 copy_generic_files()
362 {
363 # In most cases, locales are in $_pkg/usr/share/locale so we copy files
364 # using generic variables and $LOCALE from Tazwok config file.
365 if [ ! "$LOCALE" = "" ]; then
366 if [ -d "$_pkg/usr/share/locale" ]; then
367 for i in $LOCALE
368 do
369 if [ -d "$_pkg/usr/share/locale/$i" ]; then
370 mkdir -p $fs/usr/share/locale
371 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
372 fi
373 done
374 fi
375 fi
376 # Pixmaps (PNG or/and XPM only). Some icons/images can be added through
377 # genpkg_rules and generic copy can be disabled with GENERIC_PIXMAPS="no"
378 # in pkg receipt.
379 if [ ! "$GENERIC_PIXMAPS" = "no" ]; then
380 if [ -d "$_pkg/usr/share/pixmaps" ]; then
381 mkdir -p $fs/usr/share/pixmaps
382 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
383 $fs/usr/share/pixmaps 2>/dev/null
384 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
385 $fs/usr/share/pixmaps 2>/dev/null
386 fi
387 # Custom or homemade PNG pixmap can be in stuff.
388 if [ -f "stuff/$PACKAGE.png" ]; then
389 mkdir -p $fs/usr/share/pixmaps
390 cp -a stuff/$PACKAGE.png $fs/usr/share/pixmaps
391 fi
392 fi
393 # Desktop entry (.desktop).
394 if [ -d "$_pkg/usr/share/applications" ]; then
395 cp -a $_pkg/usr/share/applications $fs/usr/share
396 fi
397 # Homemade desktop file(s) can be in stuff.
398 if [ -d "stuff/applications" ]; then
399 mkdir -p $fs/usr/share
400 cp -a stuff/applications $fs/usr/share
401 fi
402 if [ -f "stuff/$PACKAGE.desktop" ]; then
403 mkdir -p $fs/usr/share/applications
404 cp -a stuff/$PACKAGE.desktop $fs/usr/share/applications
405 fi
406 }
408 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
409 strip_package()
410 {
411 echo -n "Executing strip on all files..."
412 # Binaries.
413 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
414 do
415 if [ -d "$dir" ]; then
416 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
417 fi
418 done
419 # Libraries.
420 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
421 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
422 status
423 }
425 # Create a package tree and build the gziped cpio archive
426 # to make a SliTaz (.tazpkg) package.
427 gen_package()
428 {
429 check_root
430 check_for_package_on_cmdline
431 check_for_receipt
432 EXTRAVERSION=""
433 . $RECEIPT
434 # May compute VERSION
435 if grep -q ^get_version $RECEIPT; then
436 get_version
437 fi
438 check_for_wanted
439 cd $WOK/$PACKAGE
440 # Remove old Tazwok package files.
441 if [ -d "taz" ]; then
442 rm -rf taz
443 fi
444 # Create the package tree and set useful variables.
445 mkdir -p taz/$PACKAGE-$VERSION/fs
446 fs=taz/$PACKAGE-$VERSION/fs
447 # Set $src for standard package and $_pkg variables.
448 if [ "$WANTED" = "" ]; then
449 src=$WOK/$PACKAGE/$PACKAGE-$VERSION
450 _pkg=$src/_pkg
451 fi
452 if [ ! "$SOURCE" = "" ]; then
453 src=$WOK/$PACKAGE/$SOURCE-$VERSION
454 _pkg=$src/_pkg
455 fi
456 cd $WOK/$PACKAGE
457 # Execute genpkg_rules and copy generic files to build the package.
458 echo ""
459 echo "Building $PACKAGE with the receipt..."
460 echo "================================================================================"
461 if grep -q ^genpkg_rules $RECEIPT; then
462 # Log process.
463 echo "executing genpkg_rules" >> $LOG
464 genpkg_rules
465 cd $WOK/$PACKAGE
466 # Skip generic files for packages with a WANTED variable
467 # (dev and splited pkgs).
468 if [ ! "$WANTED" = "" ]; then
469 continue
470 else
471 copy_generic_files
472 fi
473 strip_package
474 else
475 echo "No package rules to gen $PACKAGE..."
476 exit 1
477 fi
478 # Copy the receipt and description (if exists) in the binary package tree.
479 cd $WOK/$PACKAGE
480 echo -n "Copying the receipt..."
481 cp receipt taz/$PACKAGE-$VERSION
482 status
483 if grep -q ^get_version $RECEIPT; then
484 echo -n "Update version in receipt..."
485 sed -i "s/^VERSION=.*/VERSION=\"$VERSION\"/" \
486 taz/$PACKAGE-$VERSION/receipt
487 status
488 fi
489 if [ -f "description.txt" ]; then
490 echo -n "Copying the description file..."
491 cp description.txt taz/$PACKAGE-$VERSION
492 status
493 fi
494 # Create the files.list by redirecting find output.
495 echo -n "Creating the list of files..."
496 cd taz/$PACKAGE-$VERSION
497 LAST_FILE=""
498 ( find fs -print; echo ) | while read file; do
499 if [ "$LAST_FILE" != "" ]; then
500 case "$file" in
501 $LAST_FILE/*)
502 case "$(ls -ld "$LAST_FILE")" in
503 drwxr-xr-x\ *\ root\ *\ root\ *);;
504 *) echo ${LAST_FILE#fs};;
505 esac;;
506 *) echo ${LAST_FILE#fs};;
507 esac
508 fi
509 LAST_FILE="$file"
510 done > files.list
511 status
512 if [ -z "$EXTRAVERSION" ]; then
513 case "$PACKAGE" in
514 linux*);;
515 *) EXTRAVERSION="$(grep '/lib/modules/.*-slitaz/' files.list |\
516 head -1 | sed 's|/lib/modules/\(.*\)-slitaz/.*|_\1|')";;
517 esac
518 fi
519 rm -f $PACKAGES_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg 2> /dev/null
520 echo -n "Creating md5sum of files..."
521 while read file; do
522 [ -L "fs$file" ] && continue
523 [ -f "fs$file" ] || continue
524 md5sum "fs$file" | sed 's/ fs/ /'
525 done < files.list > md5sum
526 #[ -s md5sum ] || rm -f md5sum
527 status
528 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
529 2> /dev/null | awk '{ sz=$1 } END { print sz }')
530 # Build cpio archives. Find, cpio and gzip the fs, finish by
531 # removing the fs tree.
532 echo -n "Compressing the fs... "
533 find fs -print | cpio -o -H newc | gzip > fs.cpio.gz && rm -rf fs
534 PACKED_SIZE=$(du -chs fs.cpio.gz receipt files.list md5sum \
535 description.txt 2> /dev/null | awk '{ sz=$1 } END { print sz }')
536 echo -n "Undating receipt sizes..."
537 sed -i s/^PACKED_SIZE.*$// receipt
538 sed -i s/^UNPACKED_SIZE.*$// receipt
539 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
540 sed -i "s/^VERSION=$/VERSION=\"$VERSION\"/" receipt
541 status
542 if [ -n "$EXTRAVERSION" ]; then
543 echo -n "Undating receipt EXTRAVERSION..."
544 sed -i s/^EXTRAVERSION.*$// receipt
545 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
546 status
547 fi
548 echo -n "Creating full cpio archive... "
549 find . -print | cpio -o -H newc > $PACKAGES_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
550 # Restore package tree incase we want to browse it.
551 echo -n "Restoring original package tree... "
552 zcat fs.cpio.gz | cpio -id
553 rm fs.cpio.gz && cd ..
554 # Log process.
555 echo "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg (done)" >> $LOG
556 echo "================================================================================"
557 echo "Package $PACKAGE ($VERSION$EXTRAVERSION) generated."
558 echo "Size : `du -sh $PACKAGES_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
559 echo ""
560 }
562 # Optional text packages list for gen-list.
563 gen_textlist()
564 {
565 rm -f packages.desc packages.equiv
566 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
567 echo -n "Creating the text packages list... "
568 cat >> packages.txt << _EOT_
569 # SliTaz GNU/Linux - Packages list
570 #
571 # Packages : _packages_
572 # Date : $DATE
573 #
574 _EOT_
575 for pkg in $WOK/*
576 do
577 PROVIDE=""
578 PACKAGE=""
579 PACKED_SIZE=""
580 if [ -f $pkg/taz/*/receipt ]; then
581 . $pkg/taz/*/receipt
582 else
583 . $pkg/receipt
584 fi
585 cat >> packages.txt << _EOT_
587 $PACKAGE
588 $VERSION
589 $SHORT_DESC
590 _EOT_
591 if [ -n "$PACKED_SIZE" ]; then
592 cat >> packages.txt << _EOT_
593 $PACKED_SIZE ($UNPACKED_SIZE installed)
594 _EOT_
595 fi
596 # packages.desc is used by Tazpkgbox <tree>.
597 echo "$PACKAGE | $VERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> packages.desc
598 # packages.equiv is used by tazpkg install to check depends
599 touch packages.equiv
600 for i in $PROVIDE; do
601 DEST=""
602 echo $i | grep -q : && DEST="${i#*:}:"
603 if grep -qs ^${i%:*}= packages.equiv; then
604 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" packages.equiv
605 else
606 echo "${i%:*}=$DEST$PACKAGE" >> packages.equiv
607 fi
608 done
609 packages=$(($packages+1))
610 done && status
611 echo -n "Creating the text files list... "
612 for pkg in $WOK/*
613 do
614 if [ -f $pkg/taz/*/files.list ]; then
615 . $pkg/taz/*/receipt
616 ( echo "$PACKAGE"; cat $pkg/taz/*/files.list ) | awk '
617 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }'
618 else
619 echo "No files_list in $pkg" 1>&2
620 fi
621 done | lzma e files.list.lzma -si && status
622 sed -i s/"_packages_"/"$packages"/ packages.txt
623 }
625 # Return the date of the last commit in seconds since Jan 1 1970
626 hgdate()
627 {
628 local pkg
629 local date
630 local mon
631 # Default date is Jan 1 1970
632 [ -d $WOK/.hg -a -x /usr/bin/hg ] || { echo "010100001970"; return; }
633 pkg=$(basename $1)
634 # Get date for last commit
635 date="$( cd $WOK; hg log $(find $pkg/receipt $pkg/stuff -type f \
636 2> /dev/null) | grep date: | head -1 | cut -c 6-)"
637 [ -n "$date" ] || { echo "010100001970"; return; }
638 case "$(echo $date | awk '{ print $2 }')" in
639 Jan) mon="01";; Feb) mon="02";; Mar) mon="03";; Apr) mon="04";;
640 May) mon="05";; Jun) mon="06";; Jul) mon="07";; Aug) mon="08";;
641 Sep) mon="09";; Oct) mon="10";; Nov) mon="11";; Dec) mon="12";;
642 esac
643 # Reformat, don't mind about TZ: we look for days or months delta
644 echo $date | sed "s|[^ ]* [^ ]* \\(.*\\) \\(.*\\):\\(.*\\):\\(.*\\) \\(.*\\) .*|$mon\1\2\3\5|"
645 }
647 # List packages providing a virtual package
648 whoprovide()
649 {
650 local i;
651 for i in $(grep -l PROVIDE $WOK/*/receipt); do
652 . $i
653 case " $PROVIDE " in
654 *\ $1\ *|*\ $1:*) echo $(basename $(dirname $i));;
655 esac
656 done
657 }
659 ###################
660 # Tazwok commands #
661 ###################
663 case "$COMMAND" in
664 stats)
665 # Tazwok general statistics from the config file the wok.
666 #
667 echo ""
668 echo -e "\033[1mTazwok configuration statistics\033[0m
669 ================================================================================
670 Wok directory : $WOK
671 Packages repository : $PACKAGES_REPOSITORY
672 Sources repository : $SOURCES_REPOSITORY
673 Packages in the wok : `ls -1 $WOK | wc -l`
674 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
675 ================================================================================"
676 echo ""
677 ;;
678 build-depends)
679 # List dependancies to rebuild wok
680 cd $WOK
681 ALL_DEPS="slitaz-toolchain"
682 echo $ALL_DEPS
683 for pkg in $(ls $2)
684 do
685 [ -f $pkg/receipt ] || continue
686 BUILD_DEPENDS=""
687 . $pkg/receipt
688 for i in $BUILD_DEPENDS; do
689 case " $ALL_DEPS " in
690 *\ $i\ *);;
691 *) ALL_DEPS="$ALL_DEPS $i"
692 echo $i;;
693 esac
694 done
695 done
696 ;;
697 check)
698 # Check wok consistancy
699 echo ""
700 echo -e "\033[1mWok and packages checking\033[0m
701 ================================================================================"
702 cd $WOK
703 for pkg in $(ls)
704 do
705 [ -f $pkg/receipt ] || continue
706 PACKAGE=""
707 VERSION=""
708 EXTRAVERSION=""
709 CATEGORY=""
710 SHORT_DESC=""
711 MAINTAINER=""
712 WEB_SITE=""
713 DEPENDS=""
714 BUILD_DEPENDS=""
715 WANTED=""
716 PACKED_SIZE=""
717 UNPACKED_SIZE=""
718 . $pkg/receipt
719 [ "$PACKAGE" = "$pkg" ] || echo "Package $PACKAGE should be $pkg"
720 [ -n "$VERSION" ] || echo "Package $PACKAGE has no VERSION"
721 [ -n "$PACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded PACKED_SIZE"
722 [ -n "$UNPACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded UNPACKED_SIZE"
723 [ -n "$EXTRAVERSION" ] && echo "Package $PACKAGE has hardcoded EXTRAVERSION"
724 if [ -n "$WANTED" ]; then
725 if [ ! -f $WANTED/receipt ]; then
726 echo "Package $PACKAGE want unknown $WANTED package"
727 else
728 BASEVERSION=$(. $WANTED/receipt ; echo $VERSION)
729 if [ "$VERSION" = "$WANTED" ]; then
730 # BASEVERSION is computed in receipt
731 grep -q '_pkg=' $pkg/receipt &&
732 BASEVERSION=$VERSION
733 fi
734 if [ "$VERSION" != "$BASEVERSION" ]; then
735 echo "Package $PACKAGE ($VERSION) want $WANTED ($BASEVERSION)"
736 fi
737 fi
738 fi
740 if [ -n "$CATEGORY" ]; then
741 case " $(echo $CATEGORIES) " in
742 *\ $CATEGORY\ *);;
743 *) echo "Package $PACKAGE has an invalid CATEGORY";;
744 esac
745 else
746 echo"Package $PACKAGE has no CATEGORY"
747 fi
748 [ -n "$SHORT_DESC" ] || echo "Package $PACKAGE has no SHORT_DESC"
749 [ -n "$MAINTAINER" ] || echo "Package $PACKAGE has no MAINTAINER"
750 case "$WEB_SITE" in
751 ftp*|http*);;
752 '') echo "Package $PACKAGE has no WEB_SITE";;
753 *) echo "Package $PACKAGE has an invalid WEB_SITE";;
754 esac
755 case "$MAINTAINER" in
756 *\<*|*\>*) echo "Package $PACKAGE has an invalid MAINTAINER: $MAINTAINER";;
757 esac
758 case "$MAINTAINER" in
759 *@*);;
760 *) echo "Package $PACKAGE MAINTAINER is not an email address";;
761 esac
762 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n"
763 for i in $DEPENDS; do
764 [ -d $i ] && continue
765 [ -n "$(whoprovide $i)" ] && continue
766 echo -e "$MSG $i"
767 MSG=""
768 done
769 MSG="Missing build dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n"
770 for i in $BUILD_DEPENDS; do
771 [ -d $i ] && continue
772 [ -n "$(whoprovide $i)" ] && continue
773 echo -e "$MSG $i"
774 MSG=""
775 done
776 MSG="Dependencies loop between $PACKAGE and :\n"
777 ALL_DEPS=""
778 check_for_deps_loop $PACKAGE $DEPENDS
779 done
780 ;;
781 cmp|compare)
782 # Compare the wok and packages repository to help with maintaining
783 # a mirror.
784 echo ""
785 echo -e "\033[1mWok and packages comparison\033[0m
786 ================================================================================"
787 for pkg in $WOK/*
788 do
789 WANTED=""
790 . $pkg/receipt
791 echo "$PACKAGE-$VERSION.tazpkg" >> /tmp/wok.list.$$
792 tpkg="$(ls $PACKAGES_REPOSITORY/$PACKAGE-$VERSION*.tazpkg 2> /dev/null | head -1)"
793 if [ -z "$tpkg" ]; then
794 echo "Missing package: $PACKAGE ($VERSION)"
795 echo "$PACKAGE" >> /tmp/pkgs.missing.$$
796 elif [ -f $pkg/taz/*/receipt -a ! -f $pkg/taz/*/md5sum ]; then
797 echo "Obsolete package: $PACKAGE ($VERSION)"
798 echo "$PACKAGE" >> /tmp/pkgs.missing.$$
799 elif [ $pkg/receipt -nt $tpkg ]; then
800 echo "Refresh package: $PACKAGE ($VERSION)"
801 echo "$PACKAGE" >> /tmp/pkgs.missing.$$
802 else
803 srcdate=$(hgdate $pkg)
804 pkgdate=$(date -u -r $tpkg '+%m%d%H%M%Y')
805 if [ $(date -d $pkgdate +%s) -lt $(date -d $srcdate +%s) ]; then
806 echo "Rebuild package: $PACKAGE ($VERSION) cooked $(date -d $pkgdate "+%x %X"), modified $(date -d $srcdate "+%x %X")"
807 echo "$PACKAGE" >> /tmp/pkgs.missing.$$
808 else
809 continue
810 fi
811 fi
812 if [ "$2" = "--cook" ]; then
813 if [ -n "$WANTED" -a ! -d $WOK/$WANTED/taz ]; then
814 yes '' | tazwok cook $WANTED
815 fi
816 yes '' | tazwok cook $PACKAGE
817 fi
818 done
819 for pkg in `cd $PACKAGES_REPOSITORY && ls *.tazpkg`
820 do
821 # grep $pkg in /tmp/wok.list.$$
822 # may include EXTRAVERSION or computed VERSION
823 for i in $(grep ^${pkg%-*} /tmp/wok.list.$$); do
824 case "$pkg" in
825 ${i%.tazpkg}*.tazpkg) continue 2;;
826 esac
827 done
828 # Not found
829 echo $pkg >> /tmp/pkgs.old.$$
830 if [ "$2" = "--remove" ]; then
831 echo "Removing package: $pkg"
832 rm $PACKAGES_REPOSITORY/$pkg
833 else
834 echo "Old package: $pkg"
835 fi
836 done
837 cd /tmp
838 echo "================================================================================"
839 echo "Wok: `cat wok.list.$$ | wc -l` - \
840 Cooked: `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l` - \
841 Missing: `cat pkgs.missing.$$ 2>/dev/null | wc -l` - \
842 Old: `cat pkgs.old.$$ 2>/dev/null | wc -l`"
843 echo ""
844 rm -f wok.list.$$ pkgs.old.$$ pkgs.missing.$$
845 ;;
846 list)
847 # List packages in wok directory. User can specifiy a category
848 #
849 if [ "$2" = "category" ]; then
850 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
851 exit 0
852 fi
853 # Check for an asked category.
854 if [ -n "$2" ]; then
855 ASKED_CATEGORY=$2
856 echo ""
857 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
858 echo "================================================================================"
859 for pkg in $WOK/*
860 do
861 . $pkg/receipt
862 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
863 echo -n "$PACKAGE"
864 echo -e "\033[28G $VERSION"
865 packages=$(($packages+1))
866 fi
867 done
868 echo "================================================================================"
869 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
870 else
871 # By default list all packages and version.
872 echo ""
873 echo -e "\033[1mList of packages in the wok\033[0m"
874 echo "================================================================================"
875 for pkg in $WOK/*
876 do
877 . $pkg/receipt
878 echo -n "$PACKAGE"
879 echo -en "\033[28G $VERSION"
880 echo -e "\033[42G $CATEGORY"
881 packages=$(($packages+1))
882 done
883 echo "================================================================================"
884 echo -e "$packages packages available in the wok.\n"
885 fi
886 ;;
887 info)
888 # Information about a package.
889 #
890 check_for_package_on_cmdline
891 check_for_receipt
892 . $WOK/$PACKAGE/receipt
893 echo ""
894 echo -e "\033[1mTazwok package information\033[0m
895 ================================================================================
896 Package : $PACKAGE
897 Version : $VERSION
898 Category : $CATEGORY
899 Short desc : $SHORT_DESC
900 Maintainer : $MAINTAINER"
901 if [ ! "$WEB_SITE" = "" ]; then
902 echo "Web site : $WEB_SITE"
903 fi
904 if [ ! "$DEPENDS" = "" ]; then
905 echo "Depends : $DEPENDS"
906 fi
907 if [ ! "$WANTED" = "" ]; then
908 echo "Wanted src : $WANTED"
909 fi
910 echo "================================================================================"
911 echo ""
913 ;;
914 check-log)
915 # We just cat the file log to view process info.
916 #
917 if [ ! -f "$LOG" ]; then
918 echo -e "\nNo process log found. The package is probably not cooked.\n"
919 exit 0
920 else
921 echo ""
922 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
923 echo "================================================================================"
924 cat $LOG
925 echo "================================================================================"
926 echo ""
927 fi
928 ;;
929 search)
930 # Search for a package by pattern or name.
931 #
932 if [ -z "$2" ]; then
933 echo -e "\nPlease specify a pattern or a package name to search."
934 echo -e "Example : 'tazwok search gcc'.\n"
935 exit 0
936 fi
937 echo ""
938 echo -e "\033[1mSearch result for :\033[0m $2"
939 echo "================================================================================"
940 list=`ls -1 $WOK | grep $2`
941 for pkg in $list
942 do
943 . $WOK/$pkg/receipt
944 echo -n "$PACKAGE "
945 echo -en "\033[24G $VERSION"
946 echo -e "\033[42G $CATEGORY"
947 packages=$(($packages+1))
948 done
949 echo "================================================================================"
950 echo "$packages packages found for : $2"
951 echo ""
952 ;;
953 compile)
954 # Configure and make a package with the receipt.
955 #
956 compile_package
957 ;;
958 genpkg)
959 # Generate a package
960 #
961 gen_package
962 ;;
963 cook)
964 # Compile and generate a package. Just execute tazwok with
965 # the good commands.
966 #
967 check_root
968 compile_package
969 gen_package
970 ;;
971 cook-list)
972 # Cook all packages listed in a file. The path to the cooklist must
973 # be specified on the cmdline.
974 #
975 check_root
976 check_for_list
977 for pkg in $LIST
978 do
979 tazwok compile $pkg
980 tazwok genpkg $pkg
981 done
982 ;;
983 clean)
984 # Clean up a package work directory.
985 #
986 check_for_package_on_cmdline
987 check_for_receipt
988 . $RECEIPT
989 cd $WOK/$PACKAGE
990 echo ""
991 echo "Cleaning $PACKAGE..."
992 echo "================================================================================"
993 # Check for clean_wok function.
994 if grep -q ^clean_wok $RECEIPT; then
995 clean_wok
996 fi
997 # Remove taz/ and source tree if exists.
998 if [ -d "taz" ]; then
999 echo -n "Removing taz files..."
1000 rm -rf taz
1001 status
1002 fi
1003 for i in $PACKAGE-$VERSION $SOURCE-$VERSION ; do
1004 [ -e "$i" ] || continue
1005 echo -n "Removing source files..."
1006 if [ -L $i ]; then
1007 target=$(readlink $i)
1008 [ -d "$target" ] && case "$target" in
1009 /*|.|./*|..|../*);;
1010 *) rm -rf $target;;
1011 esac
1012 fi
1013 rm -rf $i
1014 status
1015 done
1016 # Remove an envental $PACKAGE-build directory.
1017 if [ -d "$PACKAGE-build" ]; then
1018 echo -n "Removing build tree..."
1019 rm -rf $PACKAGE-build && status
1020 fi
1021 # Remove process log file.
1022 if [ -f "process.log" ]; then
1023 echo -n "Removing process log file..."
1024 rm process.log && status
1025 echo "================================================================================"
1026 fi
1027 echo "$PACKAGE is clean. You can cook it again..."
1028 echo ""
1029 ;;
1030 gen-clean-wok)
1031 # Generate a clean wok from the current wok by copying all receipt
1032 # and stuff directory.
1034 if [ -z "$2" ]; then
1035 echo -e "\nPlease specify the destination for the new clean wok.\n"
1036 exit 0
1037 else
1038 dest=$2
1039 mkdir -p $dest
1040 fi
1041 echo "New wok is going to : $dest"
1042 for pkg in `ls -1 $WOK`
1043 do
1044 echo "----"
1045 echo -n "Preparing $pkg..."
1046 mkdir -p $dest/$pkg
1047 status
1048 echo -n "Copying the receipt..."
1049 cp -a $WOK/$pkg/receipt $dest/$pkg
1050 status
1051 if [ -d "$WOK/$pkg/stuff" ]; then
1052 echo -n "Copying all the stuff directory..."
1053 cp -a $WOK/$pkg/stuff $dest/$pkg
1054 status
1055 fi
1056 done
1057 echo "================================================================================"
1058 echo "Clean wok generated in : $dest"
1059 echo "Packages cleaned : `ls -1 $dest | wc -l`"
1060 echo ""
1061 ;;
1062 clean-wok)
1063 # Clean all packages in the work directory
1065 for pkg in `ls -1 $WOK`
1066 do
1067 tazwok clean $pkg
1068 done
1069 echo "================================================================================"
1070 echo "`ls -1 $WOK | wc -l` packages cleaned."
1071 echo ""
1072 ;;
1073 gen-list)
1074 # Sed is used to remove all the .tazpkg extensions from the
1075 # packages.list. The directory to move in by default is the repository
1076 # if $2 is not empty cd into $2. A text packages list can also be gen
1077 # with the option --text.
1079 fakewok=""
1080 if [ "$2" == "--text" ]; then
1081 textlist="yes"
1082 if [ "$3" == "--fakewok" ]; then
1083 WOK=/tmp/fakewok-$$
1084 fakewok="$WOK"
1085 mkdir -p $WOK
1086 for i in $PACKAGES_REPOSITORY/*.tazpkg; do
1087 (cd $WOK; cpio -i receipt files.list 2>/dev/null) < $i
1088 . $WOK/receipt
1089 mkdir -p $WOK/$PACKAGE/taz/$PACKAGE-$VERSION
1090 mv $WOK/receipt $WOK/files.list \
1091 $WOK/$PACKAGE/taz/$PACKAGE-$VERSION
1092 ln $WOK/$PACKAGE/taz/$PACKAGE-$VERSION/receipt $WOK/$PACKAGE
1093 done
1094 fi
1095 elif [ -z "$2" ]; then
1096 PACKAGES_REPOSITORY=$PACKAGES_REPOSITORY
1097 else
1098 if [ -d "$2" ]; then
1099 PACKAGES_REPOSITORY=$2
1100 else
1101 echo -e "\nUnable to find directory : $2\n"
1102 exit 0
1103 fi
1104 fi
1105 cd $PACKAGES_REPOSITORY
1106 # Remove old packages.list and md5sum, they will soon be rebuilt.
1107 rm -f packages.list packages.md5 packages.txt
1108 echo ""
1109 echo -e "\033[1mGenerating packages lists\033[0m"
1110 echo "================================================================================"
1111 echo -n "Repository path : $PACKAGES_REPOSITORY" && status
1112 # Generate packages.txt
1113 if [ "$textlist" == "yes" ]; then
1114 gen_textlist
1115 [ "$fakewok" == "" ] || rm -rf $fakewok
1116 fi
1117 echo -n "Creating the raw packages list... "
1118 ls -1 *.tazpkg > /tmp/packages.list
1119 sed -i s/'.tazpkg'/''/ /tmp/packages.list
1120 status
1121 echo -n "Building the md5sum for all packages... "
1122 md5sum *.tazpkg > packages.md5
1123 status
1124 mv /tmp/packages.list $PACKAGES_REPOSITORY
1125 echo "================================================================================"
1126 pkgs=`cat $PACKAGES_REPOSITORY/packages.list | wc -l`
1127 echo "$pkgs packages in the repository."
1128 echo ""
1129 ;;
1130 new-tree)
1131 # Just create a few directories and generate an empty receipt to prepare
1132 # the creation of a new package.
1134 check_for_package_on_cmdline
1135 if [ -d $WOK/$PACKAGE ]; then
1136 echo -e "\n$PACKAGE package tree already exists.\n"
1137 exit 0
1138 fi
1139 echo "Creating : $WOK/$PACKAGE"
1140 mkdir $WOK/$PACKAGE
1141 cd $WOK/$PACKAGE
1142 echo -n "Preparing the receipt..."
1144 # Default receipt begin.
1146 echo "# SliTaz package receipt." > receipt
1147 echo "" >> receipt
1148 echo "PACKAGE=\"$PACKAGE\"" >> receipt
1149 # Finish the empty receipt.
1150 cat >> receipt << "EOF"
1151 VERSION=""
1152 CATEGORY=""
1153 SHORT_DESC=""
1154 MAINTAINER=""
1155 DEPENDS=""
1156 TARBALL="$PACKAGE-$VERSION.tar.gz"
1157 WEB_SITE=""
1158 WGET_URL=""
1160 # Rules to configure and make the package.
1161 compile_rules()
1163 cd $src
1164 ./configure \
1165 --prefix=/usr \
1166 --infodir=/usr/share/info \
1167 --mandir=/usr/share/man \
1168 $CONFIGURE_ARGS &&
1169 make && make DESTDIR=$PWD/_pkg install
1172 # Rules to gen a SliTaz package suitable for Tazpkg.
1173 genpkg_rules()
1175 mkdir -p $fs/usr
1176 cp -a $_pkg/usr/bin $fs/usr
1179 EOF
1181 # Default receipt end.
1183 status
1184 # Interactive mode, asking and seding.
1185 if [ "$3" = "--interactive" ]; then
1186 echo "Entering in interactive mode..."
1187 echo "================================================================================"
1188 echo "Package : $PACKAGE"
1189 # Version.
1190 echo -n "Version : " ; read anser
1191 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
1192 # Category.
1193 echo -n "Category : " ; read anser
1194 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
1195 # Short description.
1196 echo -n "Short desc : " ; read anser
1197 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
1198 # Maintainer.
1199 echo -n "Maintainer : " ; read anser
1200 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
1201 # Web site.
1202 echo -n "Web site : " ; read anser
1203 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
1204 echo ""
1205 # Wget URL.
1206 echo "Wget URL to download source tarball."
1207 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
1208 echo -n "Wget url : " ; read anser
1209 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
1210 # Ask for a stuff dir.
1211 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
1212 if [ "$anser" = "y" ]; then
1213 echo -n "Creating the stuff directory..."
1214 mkdir stuff && status
1215 fi
1216 # Ask for a description file.
1217 echo -n "Are you going to write a description ? (y/N) : " ; read anser
1218 if [ "$anser" = "y" ]; then
1219 echo -n "Creating the description.txt file..."
1220 echo "" > description.txt && status
1221 fi
1222 echo "================================================================================"
1223 echo ""
1224 fi
1225 ;;
1226 remove)
1227 # Remove a package from the wok.
1229 check_for_package_on_cmdline
1230 echo ""
1231 echo -n "Please confirm deletion (y/N) : "; read anser
1232 if [ "$anser" = "y" ]; then
1233 echo -n "Removing $PACKAGE..."
1234 rm -rf $WOK/$PACKAGE && status
1235 echo ""
1236 fi
1237 ;;
1238 hgup)
1239 # Pull and update an Hg wok.
1240 if ls -l $WOK/.hg/hgrc | grep -q "root"; then
1241 check_root
1242 fi
1243 cd $WOK
1244 hg pull && hg update ;;
1245 maintainers)
1246 echo ""
1247 echo "List of maintainers for: $WOK"
1248 echo "================================================================================"
1249 touch /tmp/slitaz-maintainers
1250 for pkg in $WOK/*
1251 do
1252 . $pkg/receipt
1253 if ! grep -q "$MAINTAINER" /tmp/slitaz-maintainers; then
1254 echo "$MAINTAINER" >> /tmp/slitaz-maintainers
1255 echo "$MAINTAINER"
1256 fi
1257 done
1258 echo "================================================================================"
1259 echo "Maintainers: `cat /tmp/slitaz-maintainers | wc -l`"
1260 echo ""
1261 # Remove tmp files
1262 rm -f /tmp/slitaz-maintainers ;;
1263 maintained-by)
1264 # Search for packages maintained by a packagers.
1265 if [ ! -n "$2" ]; then
1266 echo "Specify a name or mail of a maintainer."
1267 exit 0
1268 fi
1269 echo "Maintainer packages"
1270 echo "================================================================================"
1271 for pkg in $WOK/*
1272 do
1273 . $pkg/receipt
1274 if echo "$MAINTAINER" | grep -q "$2"; then
1275 echo "$PACKAGE"
1276 packages=$(($packages+1))
1277 fi
1278 done
1279 echo "================================================================================"
1280 echo "Packages maintained by $1: $packages"
1281 echo "" ;;
1282 usage|*)
1283 # Print usage also for all unknown commands.
1285 usage
1286 ;;
1287 esac
1289 exit 0