tazwok view tazwok @ rev 65

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