tazwok view tazwok @ rev 66

Improved 'cmp' command
author Christophe Lincoln <pankso@slitaz.org>
date Fri Jun 06 14:01:57 2008 +0200 (2008-06-06)
parents b9c07e7e2c49
children d01cb4c66571
line source
1 #!/bin/sh
2 # Tazwok - SliTaz source compiler and binary packages generator/cooker.
3 #
4 # Tazwok can compile source package and creat binary packages suitable for
5 # Tazpkg (Tiny Autonomus zone package manager). You can build individuals
6 # package or a list a 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-2008 SliTaz - GNU General Public License.
10 #
11 VERSION=1.6
13 ####################
14 # Tazwok variables #
15 ####################
17 # Packages categories.
18 CATEGORIES="
19 base-system
20 utilities
21 network
22 graphics
23 multimedia
24 office
25 development
26 system-tools
27 security
28 games
29 misc
30 meta
31 non-free"
33 # Use words rater than numbers in the code.
34 COMMAND=$1
35 PACKAGE=$2
36 LIST=$2
38 # Include config file or exit if any 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 # Creat 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 # gen suitables 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] [--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 cmp|compare Compare the wok and the cooked pkgs (--remove old pkgs).
91 list List all packages in the wok tree or by category.
92 info Get informations about a package in the wok.
93 check-log Check the process log file of a package.
94 search Search for a package in the wok by pattern or name.
95 compile Configure and build the package using the receipt rules.
96 genpkg Generate a suitable package for Tazpkg with the rules.
97 cook Compile and generate a package directly.
98 cook-list Cook all packages specified in the list by order.
99 clean Clean all generated files in the package tree.
100 new-tree Prepare a new package tree and receipt (--interactive).
101 gen-list Generate a packages lists for a repository (--text).
102 gen-clean-wok Gen a clean wok in a dir ('clean-wok' cleans current wok).
103 remove Remove a package from the wok.\n"
104 }
106 # Status function.
107 status()
108 {
109 local CHECK=$?
110 echo -en "\\033[70G[ "
111 if [ $CHECK = 0 ]; then
112 echo -en "\\033[1;33mOK"
113 else
114 echo -en "\\033[1;31mFailed"
115 fi
116 echo -e "\\033[0;39m ]"
117 }
119 # Check if user is root.
120 check_root()
121 {
122 if test $(id -u) != 0 ; then
123 echo -e "\nYou must be root to run `basename $0` with this option."
124 echo -e "Please type 'su' and root password to become super-user.\n"
125 exit 0
126 fi
127 }
129 # Check for a package name on cmdline.
130 check_for_package_on_cmdline()
131 {
132 if [ -z "$PACKAGE" ]; then
133 echo -e "\nYou must specify a package name on the command line."
134 echo -e "Example : tazwok $COMMAND package\n"
135 exit 0
136 fi
137 }
139 # Check for the receipt of a package used to cook.
140 check_for_receipt()
141 {
142 if [ ! -f "$RECEIPT" ]; then
143 echo -e "\nUnable to find the receipt : $RECEIPT\n"
144 exit 0
145 fi
146 }
148 # Check for a specified file list on cmdline.
149 check_for_list()
150 {
151 if [ -z "$LIST" ]; then
152 echo -e "\nPlease specify the path to the list of packages to cook.\n"
153 exit 0
154 fi
155 # Check if the list of packages exist.
156 if [ -f "$LIST" ]; then
157 LIST=`cat $LIST`
158 else
159 echo -e "\nUnable to find $LIST packages list.\n"
160 exit 0
161 fi
162 }
164 # Check for the wanted package if specified in WANTED
165 # receipt variable. Set the $src/$_pkg variable to help compiling
166 # and generating packages.
167 check_for_wanted()
168 {
169 if [ ! "$WANTED" = "" ]; then
170 echo -n "Checking for the wanted package..."
171 if [ ! -d "$WOK/$WANTED" ]; then
172 echo -e "\nWanted package is missing in the work directory.\n"
173 exit 0
174 fi
175 # Checking for buildtree of Wanted package
176 if [ ! -d "$WOK/$WANTED/taz" ]; then
177 echo -e "\n\nSource files of wanted package is missing in the work directory."
178 echo -n "Would you like to build the missing package (y/N) ? " ; read anser
179 if [ "$anser" == "y" ]; then
180 tazwok cook $WANTED
181 else
182 echo -e "\nWanted package source tree is missing in the work directory.\n"
183 exit 0
184 fi
185 fi
186 status
187 # Set wanted src path.
188 src=$WOK/$WANTED/$WANTED-$VERSION
189 _pkg=$src/_pkg
190 fi
191 }
194 # Check for build dependencies, notify user and install if specified.
195 check_for_build_depends()
196 {
197 echo "Checking for build dependencies..."
198 for pkg in $BUILD_DEPENDS
199 do
200 if [ ! -d "/var/lib/tazpkg/installed/$pkg" ]; then
201 MISSING_PACKAGE=$pkg
202 fi
203 done
204 if [ ! "$MISSING_PACKAGE" = "" ]; then
205 echo "================================================================================"
206 for pkg in $BUILD_DEPENDS
207 do
208 if [ ! -d "/var/lib/tazpkg/installed/$pkg" ]; then
209 MISSING_PACKAGE=$pkg
210 echo "Missing : $pkg"
211 fi
212 done
213 echo "================================================================================"
214 echo "You can continue, exit or install missing dependencies."
215 echo -n "Install, continue or exit (install/y/N) ? "; read anser
216 case $anser in
217 install)
218 for pkg in $BUILD_DEPENDS
219 do
220 if [ ! -d "/var/lib/tazpkg/installed/$pkg" ]; then
221 tazpkg get-install $pkg
222 fi
223 done ;;
224 y|yes)
225 continue ;;
226 *)
227 exit 0 ;;
228 esac
229 fi
230 }
231 download()
232 {
233 for file in $@; do
234 wget $file && break
235 done
236 }
238 # Configure and make a package with the receipt.
239 compile_package()
240 {
241 check_for_package_on_cmdline
242 # Include the receipt to get all needed variables and functions
243 # and cd into the work directory to start the work.
244 check_for_receipt
245 . $RECEIPT
246 # Log the package name and date.
247 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
248 echo "package $PACKAGE (compile)" >> $LOG
249 # Set wanted $src variable to help compiling.
250 if [ ! "$SOURCE" = "" ]; then
251 src=$WOK/$PACKAGE/$SOURCE-$VERSION
252 else
253 src=$WOK/$PACKAGE/$PACKAGE-$VERSION
254 fi
255 check_for_build_depends
256 check_for_wanted
257 echo ""
258 echo "Starting to cook $PACKAGE..."
259 echo "================================================================================"
260 # Check for src tarball and wget if needed.
261 if [ ! "$WGET_URL" = "" ]; then
262 echo "Checking for source tarball... "
263 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
264 cd $SOURCES_REPOSITORY
265 download $WGET_URL
266 #wget $WGET_URL
267 # Exit if download failed to avoid errors.
268 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
269 echo -e "\nDownload failed, exiting. Please check WGET_URL variable.\n"
270 exit 1
271 fi
272 else
273 echo -n "Source tarball exit... "
274 status
275 fi
276 # Untaring source if necessary. We dont need to extract source if
277 # the package is build with a wanted source package.
278 if [ "$WANTED" = "" ]; then
279 if [ ! -d $src ]; then
280 # Log process.
281 echo "untaring $TARBALL" >> $LOG
282 echo -n "Untaring $TARBALL... "
283 case "$TARBALL" in
284 *zip) ( cd $WOK/$PACKAGE; unzip $SOURCES_REPOSITORY/$TARBALL );;
285 *bz2) tar xjf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
286 *tar) tar xf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
287 *) tar xzf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
288 esac
289 status
290 # Permissions settings
291 chown -R root.root $WOK/$PACKAGE/$PACKAGE-* 2>/dev/null
292 chown -R root.root $WOK/$PACKAGE/$SOURCE-* 2>/dev/null
293 else
294 echo -n "Source direcory exit... " && status
295 fi
296 fi
297 fi
298 cd $WOK/$PACKAGE
299 # Log and execute compile_rules function if it exist, to configure and
300 # make the package if it exist.
301 if grep -q ^compile_rules $RECEIPT; then
302 echo "executing compile_rules" >> $LOG
303 compile_rules
304 # Exit if compilation failed so the binary package
305 # is not generated when using the cook comand.
306 local CHECK=$?
307 if [ $CHECK = 0 ]; then
308 echo "================================================================================"
309 echo "$PACKAGE compiled on : `date +%Y%m%d\ \%H:%M:%S`"
310 echo ""
311 echo "compilation done : `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
312 else
313 echo "================================================================================"
314 echo "Compilation failed. Please read the compilator output."
315 echo "" && exit 1
316 fi
317 else
318 echo "no compile_rules" >> $LOG
319 echo -e "No compile rules for $PACKAGE...\n"
320 fi
321 }
323 # Copy all generic files (locale, pixmaps, .desktop). We use standard path,
324 # so some packages need to copy these files with the receipt and genpkg_rules.
325 # This function is executed by gen_package when 'tazwok genpkg'.
326 copy_generic_files()
327 {
328 # In most case locale are in $_pkg/usr/share/locale so we copy files
329 # using generic variables and $LOCALE from Tazwok config file.
330 if [ ! "$LOCALE" = "" ]; then
331 if [ -d "$_pkg/usr/share/locale" ]; then
332 for i in $LOCALE
333 do
334 if [ -d "$_pkg/usr/share/locale/$i" ]; then
335 mkdir -p $fs/usr/share/locale
336 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
337 fi
338 done
339 fi
340 fi
341 # Pixmaps (PNG or/and XPM only). Some icons/images can be add trough
342 # genpkg_rules and generic copy can be disable with GENERIC_PIXMAPS="no"
343 # in pkg receipt.
344 if [ ! "$GENERIC_PIXMAPS" = "no" ]; then
345 if [ -d "$_pkg/usr/share/pixmaps" ]; then
346 mkdir -p $fs/usr/share/pixmaps
347 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
348 $fs/usr/share/pixmaps 2>/dev/null
349 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
350 $fs/usr/share/pixmaps 2>/dev/null
351 fi
352 # Custom or home made PNG pixmap can be in stuff.
353 if [ -f "stuff/$PACKAGE.png" ]; then
354 mkdir -p $fs/usr/share/pixmaps
355 cp -a stuff/$PACKAGE.png $fs/usr/share/pixmaps
356 fi
357 fi
358 # Desktop entry (.desktop).
359 if [ -d "$_pkg/usr/share/applications" ]; then
360 cp -a $_pkg/usr/share/applications $fs/usr/share
361 fi
362 # Home made desktop file(s) can be in stuff.
363 if [ -d "stuff/applications" ]; then
364 mkdir -p $fs/usr/share
365 cp -a stuff/applications $fs/usr/share
366 fi
367 if [ -f "stuff/$PACKAGE.desktop" ]; then
368 mkdir -p $fs/usr/share/applications
369 cp -a stuff/$PACKAGE.desktop $fs/usr/share/applications
370 fi
371 }
373 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
374 strip_package()
375 {
376 echo -n "Executing strip on all files..."
377 # Binaries.
378 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
379 do
380 if [ -d "$dir" ]; then
381 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
382 fi
383 done
384 # Libraries.
385 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
386 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
387 status
388 }
390 # Creat a package tree and build the gziped cpio archive
391 # to make a SliTaz (.tazpkg) package.
392 gen_package()
393 {
394 check_root
395 check_for_package_on_cmdline
396 check_for_receipt
397 . $RECEIPT
398 check_for_wanted
399 cd $WOK/$PACKAGE
400 # Remove old Tazwok package files.
401 if [ -d "taz" ]; then
402 rm -rf taz
403 rm -f $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
404 fi
405 # Creat the package tree and set usful variables.
406 mkdir -p taz/$PACKAGE-$VERSION/fs
407 fs=taz/$PACKAGE-$VERSION/fs
408 # Set $src for standards package and $_pkg variables.
409 if [ "$WANTED" = "" ]; then
410 src=$WOK/$PACKAGE/$PACKAGE-$VERSION
411 _pkg=$src/_pkg
412 fi
413 if [ ! "$SOURCE" = "" ]; then
414 src=$WOK/$PACKAGE/$SOURCE-$VERSION
415 _pkg=$src/_pkg
416 fi
417 cd $WOK/$PACKAGE
418 # Execute genpkg_rules and copy generic files to build the package.
419 echo ""
420 echo "Bulding $PACKAGE with the receipt..."
421 echo "================================================================================"
422 if grep -q ^genpkg_rules $RECEIPT; then
423 # Log process.
424 echo "executing genpkg_rules" >> $LOG
425 genpkg_rules
426 cd $WOK/$PACKAGE
427 # Skip generic files for packages with a WANTED variable
428 # (dev and splited pkgs).
429 if [ ! "$WANTED" = "" ]; then
430 continue
431 else
432 copy_generic_files
433 fi
434 strip_package
435 else
436 echo "No package rules to gen $PACKAGE..."
437 exit 1
438 fi
439 # Copy the receipt and description (if exist) in the binary package tree.
440 cd $WOK/$PACKAGE
441 echo -n "Copying the receipt..."
442 cp receipt taz/$PACKAGE-$VERSION
443 status
444 if [ -f "description.txt" ]; then
445 echo -n "Copying the description file..."
446 cp description.txt taz/$PACKAGE-$VERSION
447 status
448 fi
449 # Creat the files.list by redirecting find outpout.
450 echo -n "Creating the list of files..."
451 cd taz/$PACKAGE-$VERSION
452 LAST_FILE=""
453 ( find fs -print; echo ) | while read file; do
454 if [ "$LAST_FILE" != "" ]; then
455 case "$file" in
456 $LAST_FILE/*)
457 case "$(ls -ld "$LAST_FILE")" in
458 drwxr-xr-x\ *\ root\ *\ root\ *);;
459 *) echo ${LAST_FILE#fs};;
460 esac;;
461 *) echo ${LAST_FILE#fs};;
462 esac
463 fi
464 LAST_FILE="$file"
465 done > files.list
466 status
467 UNPACKED_SIZE=$(du -hs . | awk '{ print $1 }')
468 # Build cpio archives. Find, cpio and gzip the fs, finish by
469 # removing the fs tree.
470 echo -n "Compressing the fs... "
471 find fs -print | cpio -o -H newc | gzip > fs.cpio.gz && rm -rf fs
472 PACKED_SIZE=$(du -hs . | awk '{ print $1 }')
473 echo -n "Undating receipt sizes..."
474 sed -i s/^PACKED_SIZE.*$// receipt
475 sed -i s/^UNPACKED_SIZE.*$// receipt
476 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
477 status
478 echo -n "Creating full cpio archive... "
479 find . -print | cpio -o -H newc > $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
480 # Restore package tree in case we want to browse it.
481 echo -n "Restoring original package tree... "
482 zcat fs.cpio.gz | cpio -id
483 rm fs.cpio.gz && cd ..
484 # Log process.
485 echo "$PACKAGE-$VERSION.tazpkg (done)" >> $LOG
486 echo "================================================================================"
487 echo "Package $PACKAGE ($VERSION) generated."
488 echo "Size : `du -sh $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg`"
489 echo ""
490 }
492 # Optional text packages list for gen-list.
493 gen_textlist()
494 {
495 rm -f packages.desc
496 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
497 echo -n "Creating the text packages list... "
498 cat >> packages.txt << _EOT_
499 # SliTaz GNU/Linux - Packages list
500 #
501 # Packages : _packages_
502 # Date : $DATE
503 #
504 _EOT_
505 for pkg in $WOK/*
506 do
507 PACKAGE=""
508 PACKED_SIZE=""
509 if [ -f $pkg/taz/*/receipt ]; then
510 . $pkg/taz/*/receipt
511 else
512 . $pkg/receipt
513 fi
514 cat >> packages.txt << _EOT_
516 $PACKAGE
517 $VERSION
518 $SHORT_DESC
519 _EOT_
520 if [ -n "$PACKED_SIZE" ]; then
521 cat >> packages.txt << _EOT_
522 $PACKED_SIZE ($UNPACKED_SIZE installed)
523 _EOT_
524 fi
525 # packages.desv is used by Tazpkgbox <tree>.
526 echo "$PACKAGE | $VERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> packages.desc
527 packages=$(($packages+1))
528 done && status
529 echo -n "Creating the text files list... "
530 for pkg in $WOK/*
531 do
532 if [ -f $pkg/taz/*/files.list ]; then
533 . $pkg/taz/*/receipt
534 ( echo "$PACKAGE"; cat $pkg/taz/*/files.list ) | awk '
535 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }'
536 else
537 echo "No files_list in $pkg" 1>&2
538 fi
539 done | lzma e files.list.lzma -si && status
540 sed -i s/"_packages_"/"$packages"/ packages.txt
541 }
543 ###################
544 # Tazwok commands #
545 ###################
547 case "$COMMAND" in
548 stats)
549 # Tazwok general statistics from the config file the wok.
550 #
551 echo ""
552 echo -e "\033[1mTazwok configuration statistics\033[0m
553 ================================================================================
554 Wok directory : $WOK
555 Packages repository : $PACKAGES_REPOSITORY
556 Sources repository : $SOURCES_REPOSITORY
557 Packages in the wok : `ls -1 $WOK | wc -l`
558 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
559 ================================================================================"
560 echo ""
561 ;;
562 cmp|compare)
563 # Compare the wok and packages repository to help maintaining
564 # a mirror.
565 echo ""
566 echo -e "\033[1mWok and packages comparaison\033[0m
567 ================================================================================"
568 for pkg in $WOK/*
569 do
570 . $pkg/receipt
571 echo "$PACKAGE-$VERSION.tazpkg" >> /tmp/wok.list
572 if [ ! -f $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg ]; then
573 echo "Missing package: $PACKAGE ($VERSION)"
574 fi
575 done
576 for pkg in `cd $PACKAGES_REPOSITORY && ls *.tazpkg`
577 do
578 if ! grep -q ^$pkg /tmp/wok.list; then
579 echo $pkg >> /tmp/pkgs.old
580 if [ "$2" = "--remove" ]; then
581 echo "Removing package: $pkg"
582 rm $PACKAGES_REPOSITORY/$pkg
583 else
584 echo "Old package: $pkg"
585 fi
586 fi
587 done
588 cd /tmp
589 echo "================================================================================"
590 echo "Wok: `cat wok.list | wc -l` - \
591 Cooked: `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l` - \
592 Old: `cat pkgs.old | wc -l`"
593 echo ""
594 rm -f wok.list pkgs.old
595 ;;
596 list)
597 # List packages in wok directory. User can specifiy a category
598 #
599 if [ "$2" = "category" ]; then
600 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
601 exit 0
602 fi
603 # Check for an asked category.
604 if [ -n "$2" ]; then
605 ASKED_CATEGORY=$2
606 echo ""
607 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
608 echo "================================================================================"
609 for pkg in $WOK/*
610 do
611 . $pkg/receipt
612 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
613 echo -n "$PACKAGE"
614 echo -e "\033[28G $VERSION"
615 packages=$(($packages+1))
616 fi
617 done
618 echo "================================================================================"
619 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
620 else
621 # By default list all packages and version.
622 echo ""
623 echo -e "\033[1mList of packages in the wok\033[0m"
624 echo "================================================================================"
625 for pkg in $WOK/*
626 do
627 . $pkg/receipt
628 echo -n "$PACKAGE"
629 echo -en "\033[28G $VERSION"
630 echo -e "\033[42G $CATEGORY"
631 packages=$(($packages+1))
632 done
633 echo "================================================================================"
634 echo -e "$packages packages avalaible in the wok.\n"
635 fi
636 ;;
637 info)
638 # Informations about package.
639 #
640 check_for_package_on_cmdline
641 check_for_receipt
642 . $WOK/$PACKAGE/receipt
643 echo ""
644 echo -e "\033[1mTazwok package informations\033[0m
645 ================================================================================
646 Package : $PACKAGE
647 Version : $VERSION
648 Category : $CATEGORY
649 Short desc : $SHORT_DESC
650 Maintainer : $MAINTAINER"
651 if [ ! "$WEB_SITE" = "" ]; then
652 echo "Web site : $WEB_SITE"
653 fi
654 if [ ! "$DEPENDS" = "" ]; then
655 echo "Depends : $DEPENDS"
656 fi
657 if [ ! "$WANTED" = "" ]; then
658 echo "Wanted src : $WANTED"
659 fi
660 echo "================================================================================"
661 echo ""
663 ;;
664 check-log)
665 # We just cat the file log to view process info.
666 #
667 if [ ! -f "$LOG" ]; then
668 echo -e "\nNo process log found. The package is probably not cook.\n"
669 exit 0
670 else
671 echo ""
672 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
673 echo "================================================================================"
674 cat $LOG
675 echo "================================================================================"
676 echo ""
677 fi
678 ;;
679 search)
680 # Search for a package by pattern or name.
681 #
682 if [ -z "$2" ]; then
683 echo -e "\nPlease specify a pattern or a package name to search."
684 echo -e "Example : 'tazwok search gcc'.\n"
685 exit 0
686 fi
687 echo ""
688 echo -e "\033[1mSearch result for :\033[0m $2"
689 echo "================================================================================"
690 list=`ls -1 $WOK | grep $2`
691 for pkg in $list
692 do
693 . $WOK/$pkg/receipt
694 echo -n "$PACKAGE "
695 echo -en "\033[24G $VERSION"
696 echo -e "\033[42G $CATEGORY"
697 packages=$(($packages+1))
698 done
699 echo "================================================================================"
700 echo "$packages packages found for : $2"
701 echo ""
702 ;;
703 compile)
704 # Configure and make a package with the receipt.
705 #
706 compile_package
707 ;;
708 genpkg)
709 # Generate a package
710 #
711 gen_package
712 ;;
713 cook)
714 # Compile and generate a package. Just execute tazwok with
715 # the good commands.
716 #
717 check_root
718 compile_package
719 gen_package
720 ;;
721 cook-list)
722 # Cook all packages listed in a file. The path to the cooklist must
723 # be specified on the cmdline.
724 #
725 check_root
726 check_for_list
727 for pkg in $LIST
728 do
729 tazwok compile $pkg
730 tazwok genpkg $pkg
731 done
732 ;;
733 clean)
734 # Clean up a package work directory.
735 #
736 check_for_package_on_cmdline
737 check_for_receipt
738 . $RECEIPT
739 cd $WOK/$PACKAGE
740 echo ""
741 echo "Cleaning $PACKAGE..."
742 echo "================================================================================"
743 # Check for clean_wok function.
744 if grep -q ^clean_wok $RECEIPT; then
745 clean_wok
746 fi
747 # Remove taz/ and source tree if exist.
748 if [ -d "taz" ]; then
749 echo -n "Removing taz files..."
750 rm -rf taz && status
751 fi
752 if [ -d "$PACKAGE-$VERSION" ]; then
753 echo -n "Removing source files..."
754 rm -rf $PACKAGE-$VERSION && status
755 fi
756 if [ -d "$SOURCE-$VERSION" ]; then
757 echo -n "Removing source files..."
758 rm -rf $SOURCE-$VERSION && status
759 fi
760 # Remove an envental $PACKAGE-build directory.
761 if [ -d "$PACKAGE-build" ]; then
762 echo -n "Removing build tree..."
763 rm -rf $PACKAGE-build && status
764 fi
765 # Remove process log file.
766 if [ -f "process.log" ]; then
767 echo -n "Removing process log file..."
768 rm process.log && status
769 echo "================================================================================"
770 fi
771 echo "$PACKAGE is clean. You can cook it again..."
772 echo ""
773 ;;
774 gen-clean-wok)
775 # Generate a clean wok from the current wok by copying all receipt
776 # and stuff directory.
777 #
778 if [ -z "$2" ]; then
779 echo -e "\nPlease specify the destination for the new clean wok.\n"
780 exit 0
781 else
782 dest=$2
783 mkdir -p $dest
784 fi
785 echo "New wok is going to : $dest"
786 for pkg in `ls -1 $WOK`
787 do
788 echo "----"
789 echo -n "Preparing $pkg..."
790 mkdir -p $dest/$pkg
791 status
792 echo -n "Copying the receipt..."
793 cp -a $WOK/$pkg/receipt $dest/$pkg
794 status
795 if [ -d "$WOK/$pkg/stuff" ]; then
796 echo -n "Copying all the stuff directory..."
797 cp -a $WOK/$pkg/stuff $dest/$pkg
798 status
799 fi
800 done
801 echo "================================================================================"
802 echo "Clean wok generated in : $dest"
803 echo "Packages cleaned : `ls -1 $dest | wc -l`"
804 echo ""
805 ;;
806 clean-wok)
807 # Clean all packages in the work directory
808 #
809 for pkg in `ls -1 $WOK`
810 do
811 tazwok clean $pkg
812 done
813 echo "================================================================================"
814 echo "`ls -1 $WOK | wc -l` packages cleaned."
815 echo ""
816 ;;
817 gen-list)
818 # Sed is used to remove all the .tazpkg extensions from the
819 # packages.list. The directory to move in by default is the repository
820 # if $2 is not empty cd into $2. A text packages list can also be gen
821 # with the option --text.
822 #
823 if [ "$2" == "--text" ]; then
824 textlist="yes"
825 elif [ -z "$2" ]; then
826 PACKAGES_REPOSITORY=$PACKAGES_REPOSITORY
827 else
828 if [ -d "$2" ]; then
829 PACKAGES_REPOSITORY=$2
830 else
831 echo -e "\nUnable to find directory : $2\n"
832 exit 0
833 fi
834 fi
835 cd $PACKAGES_REPOSITORY
836 # Remove old packages.list and md5sum, it well be soon rebuild.
837 rm -f packages.list packages.md5 packages.txt
838 echo ""
839 echo -e "\033[1mGenerating packages lists\033[0m"
840 echo "================================================================================"
841 echo -n "Repository path : $PACKAGES_REPOSITORY" && status
842 # Gen packages.txt
843 if [ "$textlist" == "yes" ]; then
844 gen_textlist
845 fi
846 echo -n "Creating the raw packages list... "
847 ls -1 *.tazpkg > /tmp/packages.list
848 sed -i s/'.tazpkg'/''/ /tmp/packages.list
849 status
850 echo -n "Building the md5sum for all packages... "
851 md5sum * > packages.md5
852 status
853 mv /tmp/packages.list $PACKAGES_REPOSITORY
854 echo "================================================================================"
855 pkgs=`cat $PACKAGES_REPOSITORY/packages.list | wc -l`
856 echo "$pkgs packages in the repository."
857 echo ""
858 ;;
859 new-tree)
860 # Just creat a few directories and gen a empty receipt to prepare
861 # the creation of a new package.
862 #
863 check_for_package_on_cmdline
864 if [ -d $WOK/$PACKAGE ]; then
865 echo -e "\n$PACKAGE package tree already exist.\n"
866 exit 0
867 fi
868 echo "Creating : $WOK/$PACKAGE"
869 mkdir $WOK/$PACKAGE
870 cd $WOK/$PACKAGE
871 echo -n "Preparing the receipt..."
872 #
873 # Default receipt begin.
874 #
875 echo "# SliTaz package receipt." > receipt
876 echo "" >> receipt
877 echo "PACKAGE=\"$PACKAGE\"" >> receipt
878 # Finish the empty receipt.
879 cat >> receipt << "EOF"
880 VERSION=""
881 CATEGORY=""
882 SHORT_DESC=""
883 MAINTAINER=""
884 DEPENDS=""
885 TARBALL="$PACKAGE-$VERSION.tar.gz"
886 WEB_SITE=""
887 WGET_URL=""
889 # Rules to configure and make the package.
890 compile_rules()
891 {
892 cd $src
893 ./configure --prefix=/usr --infodir=/usr/share/info \
894 --mandir=/usr/share/man $CONFIGURE_ARGS
895 make
896 make DESTDIR=$PWD/_pkg install
897 }
899 # Rules to gen a SliTaz package suitable for Tazpkg.
900 genpkg_rules()
901 {
902 mkdir -p $fs/usr
903 cp -a $_pkg/usr/bin $fs/usr
904 strip -s $fs/usr/bin/*
905 }
907 EOF
908 #
909 # Default receipt end.
910 #
911 status
912 # Interactive mode, asking and seding.
913 if [ "$3" = "--interactive" ]; then
914 echo "Entering in interactive mode..."
915 echo "================================================================================"
916 echo "Package : $PACKAGE"
917 # Version.
918 echo -n "Version : " ; read anser
919 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
920 # Category.
921 echo -n "Category : " ; read anser
922 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
923 # Short description.
924 echo -n "Short desc : " ; read anser
925 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
926 # Maintainer.
927 echo -n "Maintainer : " ; read anser
928 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
929 # Web site.
930 echo -n "Web site : " ; read anser
931 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
932 echo ""
933 # Wget URL.
934 echo "Wget URL to download source tarball."
935 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
936 echo -n "Wget url : " ; read anser
937 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
938 # Ask for a stuff dir.
939 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
940 if [ "$anser" = "y" ]; then
941 echo -n "Creating the stuff directory..."
942 mkdir stuff && status
943 fi
944 # Ask for a description file.
945 echo -n "Are you going to write a description ? (y/N) : " ; read anser
946 if [ "$anser" = "y" ]; then
947 echo -n "Creating the description.txt file..."
948 echo "" > description.txt && status
949 fi
950 echo "================================================================================"
951 echo ""
952 fi
953 ;;
954 remove)
955 # Remove a package from the wok.
956 #
957 check_for_package_on_cmdline
958 echo ""
959 echo -n "Removing $PACKAGE..."
960 rm -rf $WOK/$PACKAGE && status
961 echo ""
962 ;;
963 usage|*)
964 # Print usage also for all unknow commands.
965 #
966 usage
967 ;;
968 esac
970 exit 0