tazwok view tazwok @ rev 67

Fix and improved 'cmp'
author Christophe Lincoln <pankso@slitaz.org>
date Fri Jun 06 14:14:55 2008 +0200 (2008-06-06)
parents 149dde2d1013
children 78ecb1b4eb61
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 echo "$PACKAGE" >> /tmp/pkgs.missing
575 fi
576 done
577 for pkg in `cd $PACKAGES_REPOSITORY && ls *.tazpkg`
578 do
579 if ! grep -q ^$pkg /tmp/wok.list; then
580 echo $pkg >> /tmp/pkgs.old
581 if [ "$2" = "--remove" ]; then
582 echo "Removing package: $pkg"
583 rm $PACKAGES_REPOSITORY/$pkg
584 else
585 echo "Old package: $pkg"
586 fi
587 fi
588 done
589 cd /tmp
590 echo "================================================================================"
591 echo "Wok: `cat wok.list | wc -l` - \
592 Cooked: `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l` - \
593 Missing: `cat pkgs.missing 2>/dev/null | wc -l` - \
594 Old: `cat pkgs.old 2>/dev/null | wc -l`"
595 echo ""
596 rm -f wok.list pkgs.old pkgs.missing
597 ;;
598 list)
599 # List packages in wok directory. User can specifiy a category
600 #
601 if [ "$2" = "category" ]; then
602 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
603 exit 0
604 fi
605 # Check for an asked category.
606 if [ -n "$2" ]; then
607 ASKED_CATEGORY=$2
608 echo ""
609 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
610 echo "================================================================================"
611 for pkg in $WOK/*
612 do
613 . $pkg/receipt
614 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
615 echo -n "$PACKAGE"
616 echo -e "\033[28G $VERSION"
617 packages=$(($packages+1))
618 fi
619 done
620 echo "================================================================================"
621 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
622 else
623 # By default list all packages and version.
624 echo ""
625 echo -e "\033[1mList of packages in the wok\033[0m"
626 echo "================================================================================"
627 for pkg in $WOK/*
628 do
629 . $pkg/receipt
630 echo -n "$PACKAGE"
631 echo -en "\033[28G $VERSION"
632 echo -e "\033[42G $CATEGORY"
633 packages=$(($packages+1))
634 done
635 echo "================================================================================"
636 echo -e "$packages packages avalaible in the wok.\n"
637 fi
638 ;;
639 info)
640 # Informations about package.
641 #
642 check_for_package_on_cmdline
643 check_for_receipt
644 . $WOK/$PACKAGE/receipt
645 echo ""
646 echo -e "\033[1mTazwok package informations\033[0m
647 ================================================================================
648 Package : $PACKAGE
649 Version : $VERSION
650 Category : $CATEGORY
651 Short desc : $SHORT_DESC
652 Maintainer : $MAINTAINER"
653 if [ ! "$WEB_SITE" = "" ]; then
654 echo "Web site : $WEB_SITE"
655 fi
656 if [ ! "$DEPENDS" = "" ]; then
657 echo "Depends : $DEPENDS"
658 fi
659 if [ ! "$WANTED" = "" ]; then
660 echo "Wanted src : $WANTED"
661 fi
662 echo "================================================================================"
663 echo ""
665 ;;
666 check-log)
667 # We just cat the file log to view process info.
668 #
669 if [ ! -f "$LOG" ]; then
670 echo -e "\nNo process log found. The package is probably not cook.\n"
671 exit 0
672 else
673 echo ""
674 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
675 echo "================================================================================"
676 cat $LOG
677 echo "================================================================================"
678 echo ""
679 fi
680 ;;
681 search)
682 # Search for a package by pattern or name.
683 #
684 if [ -z "$2" ]; then
685 echo -e "\nPlease specify a pattern or a package name to search."
686 echo -e "Example : 'tazwok search gcc'.\n"
687 exit 0
688 fi
689 echo ""
690 echo -e "\033[1mSearch result for :\033[0m $2"
691 echo "================================================================================"
692 list=`ls -1 $WOK | grep $2`
693 for pkg in $list
694 do
695 . $WOK/$pkg/receipt
696 echo -n "$PACKAGE "
697 echo -en "\033[24G $VERSION"
698 echo -e "\033[42G $CATEGORY"
699 packages=$(($packages+1))
700 done
701 echo "================================================================================"
702 echo "$packages packages found for : $2"
703 echo ""
704 ;;
705 compile)
706 # Configure and make a package with the receipt.
707 #
708 compile_package
709 ;;
710 genpkg)
711 # Generate a package
712 #
713 gen_package
714 ;;
715 cook)
716 # Compile and generate a package. Just execute tazwok with
717 # the good commands.
718 #
719 check_root
720 compile_package
721 gen_package
722 ;;
723 cook-list)
724 # Cook all packages listed in a file. The path to the cooklist must
725 # be specified on the cmdline.
726 #
727 check_root
728 check_for_list
729 for pkg in $LIST
730 do
731 tazwok compile $pkg
732 tazwok genpkg $pkg
733 done
734 ;;
735 clean)
736 # Clean up a package work directory.
737 #
738 check_for_package_on_cmdline
739 check_for_receipt
740 . $RECEIPT
741 cd $WOK/$PACKAGE
742 echo ""
743 echo "Cleaning $PACKAGE..."
744 echo "================================================================================"
745 # Check for clean_wok function.
746 if grep -q ^clean_wok $RECEIPT; then
747 clean_wok
748 fi
749 # Remove taz/ and source tree if exist.
750 if [ -d "taz" ]; then
751 echo -n "Removing taz files..."
752 rm -rf taz && status
753 fi
754 if [ -d "$PACKAGE-$VERSION" ]; then
755 echo -n "Removing source files..."
756 rm -rf $PACKAGE-$VERSION && status
757 fi
758 if [ -d "$SOURCE-$VERSION" ]; then
759 echo -n "Removing source files..."
760 rm -rf $SOURCE-$VERSION && status
761 fi
762 # Remove an envental $PACKAGE-build directory.
763 if [ -d "$PACKAGE-build" ]; then
764 echo -n "Removing build tree..."
765 rm -rf $PACKAGE-build && status
766 fi
767 # Remove process log file.
768 if [ -f "process.log" ]; then
769 echo -n "Removing process log file..."
770 rm process.log && status
771 echo "================================================================================"
772 fi
773 echo "$PACKAGE is clean. You can cook it again..."
774 echo ""
775 ;;
776 gen-clean-wok)
777 # Generate a clean wok from the current wok by copying all receipt
778 # and stuff directory.
779 #
780 if [ -z "$2" ]; then
781 echo -e "\nPlease specify the destination for the new clean wok.\n"
782 exit 0
783 else
784 dest=$2
785 mkdir -p $dest
786 fi
787 echo "New wok is going to : $dest"
788 for pkg in `ls -1 $WOK`
789 do
790 echo "----"
791 echo -n "Preparing $pkg..."
792 mkdir -p $dest/$pkg
793 status
794 echo -n "Copying the receipt..."
795 cp -a $WOK/$pkg/receipt $dest/$pkg
796 status
797 if [ -d "$WOK/$pkg/stuff" ]; then
798 echo -n "Copying all the stuff directory..."
799 cp -a $WOK/$pkg/stuff $dest/$pkg
800 status
801 fi
802 done
803 echo "================================================================================"
804 echo "Clean wok generated in : $dest"
805 echo "Packages cleaned : `ls -1 $dest | wc -l`"
806 echo ""
807 ;;
808 clean-wok)
809 # Clean all packages in the work directory
810 #
811 for pkg in `ls -1 $WOK`
812 do
813 tazwok clean $pkg
814 done
815 echo "================================================================================"
816 echo "`ls -1 $WOK | wc -l` packages cleaned."
817 echo ""
818 ;;
819 gen-list)
820 # Sed is used to remove all the .tazpkg extensions from the
821 # packages.list. The directory to move in by default is the repository
822 # if $2 is not empty cd into $2. A text packages list can also be gen
823 # with the option --text.
824 #
825 if [ "$2" == "--text" ]; then
826 textlist="yes"
827 elif [ -z "$2" ]; then
828 PACKAGES_REPOSITORY=$PACKAGES_REPOSITORY
829 else
830 if [ -d "$2" ]; then
831 PACKAGES_REPOSITORY=$2
832 else
833 echo -e "\nUnable to find directory : $2\n"
834 exit 0
835 fi
836 fi
837 cd $PACKAGES_REPOSITORY
838 # Remove old packages.list and md5sum, it well be soon rebuild.
839 rm -f packages.list packages.md5 packages.txt
840 echo ""
841 echo -e "\033[1mGenerating packages lists\033[0m"
842 echo "================================================================================"
843 echo -n "Repository path : $PACKAGES_REPOSITORY" && status
844 # Gen packages.txt
845 if [ "$textlist" == "yes" ]; then
846 gen_textlist
847 fi
848 echo -n "Creating the raw packages list... "
849 ls -1 *.tazpkg > /tmp/packages.list
850 sed -i s/'.tazpkg'/''/ /tmp/packages.list
851 status
852 echo -n "Building the md5sum for all packages... "
853 md5sum * > packages.md5
854 status
855 mv /tmp/packages.list $PACKAGES_REPOSITORY
856 echo "================================================================================"
857 pkgs=`cat $PACKAGES_REPOSITORY/packages.list | wc -l`
858 echo "$pkgs packages in the repository."
859 echo ""
860 ;;
861 new-tree)
862 # Just creat a few directories and gen a empty receipt to prepare
863 # the creation of a new package.
864 #
865 check_for_package_on_cmdline
866 if [ -d $WOK/$PACKAGE ]; then
867 echo -e "\n$PACKAGE package tree already exist.\n"
868 exit 0
869 fi
870 echo "Creating : $WOK/$PACKAGE"
871 mkdir $WOK/$PACKAGE
872 cd $WOK/$PACKAGE
873 echo -n "Preparing the receipt..."
874 #
875 # Default receipt begin.
876 #
877 echo "# SliTaz package receipt." > receipt
878 echo "" >> receipt
879 echo "PACKAGE=\"$PACKAGE\"" >> receipt
880 # Finish the empty receipt.
881 cat >> receipt << "EOF"
882 VERSION=""
883 CATEGORY=""
884 SHORT_DESC=""
885 MAINTAINER=""
886 DEPENDS=""
887 TARBALL="$PACKAGE-$VERSION.tar.gz"
888 WEB_SITE=""
889 WGET_URL=""
891 # Rules to configure and make the package.
892 compile_rules()
893 {
894 cd $src
895 ./configure --prefix=/usr --infodir=/usr/share/info \
896 --mandir=/usr/share/man $CONFIGURE_ARGS
897 make
898 make DESTDIR=$PWD/_pkg install
899 }
901 # Rules to gen a SliTaz package suitable for Tazpkg.
902 genpkg_rules()
903 {
904 mkdir -p $fs/usr
905 cp -a $_pkg/usr/bin $fs/usr
906 strip -s $fs/usr/bin/*
907 }
909 EOF
910 #
911 # Default receipt end.
912 #
913 status
914 # Interactive mode, asking and seding.
915 if [ "$3" = "--interactive" ]; then
916 echo "Entering in interactive mode..."
917 echo "================================================================================"
918 echo "Package : $PACKAGE"
919 # Version.
920 echo -n "Version : " ; read anser
921 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
922 # Category.
923 echo -n "Category : " ; read anser
924 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
925 # Short description.
926 echo -n "Short desc : " ; read anser
927 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
928 # Maintainer.
929 echo -n "Maintainer : " ; read anser
930 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
931 # Web site.
932 echo -n "Web site : " ; read anser
933 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
934 echo ""
935 # Wget URL.
936 echo "Wget URL to download source tarball."
937 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
938 echo -n "Wget url : " ; read anser
939 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
940 # Ask for a stuff dir.
941 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
942 if [ "$anser" = "y" ]; then
943 echo -n "Creating the stuff directory..."
944 mkdir stuff && status
945 fi
946 # Ask for a description file.
947 echo -n "Are you going to write a description ? (y/N) : " ; read anser
948 if [ "$anser" = "y" ]; then
949 echo -n "Creating the description.txt file..."
950 echo "" > description.txt && status
951 fi
952 echo "================================================================================"
953 echo ""
954 fi
955 ;;
956 remove)
957 # Remove a package from the wok.
958 #
959 check_for_package_on_cmdline
960 echo ""
961 echo -n "Removing $PACKAGE..."
962 rm -rf $WOK/$PACKAGE && status
963 echo ""
964 ;;
965 usage|*)
966 # Print usage also for all unknow commands.
967 #
968 usage
969 ;;
970 esac
972 exit 0