tazwok view tazwok @ rev 52

Chown 0.0 before compiling
author Christophe Lincoln <pankso@slitaz.org>
date Tue Mar 18 12:31:04 2008 +0100 (2008-03-18)
parents cf0fe7f9801b
children 53d5ede9c0fb
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 }
231 # Configure and make a package with the receipt.
232 compile_package()
233 {
234 check_for_package_on_cmdline
235 # Include the receipt to get all needed variables and functions
236 # and cd into the work directory to start the work.
237 check_for_receipt
238 . $RECEIPT
239 # Log the package name and date.
240 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
241 echo "package $PACKAGE (compile)" >> $LOG
242 # Set wanted $src variable to help compiling.
243 if [ ! "$SOURCE" = "" ]; then
244 src=$WOK/$PACKAGE/$SOURCE-$VERSION
245 else
246 src=$WOK/$PACKAGE/$PACKAGE-$VERSION
247 fi
248 check_for_build_depends
249 check_for_wanted
250 echo ""
251 echo "Starting to cook $PACKAGE..."
252 echo "================================================================================"
253 # Check for src tarball and wget if needed.
254 if [ ! "$WGET_URL" = "" ]; then
255 echo "Checking for source tarball... "
256 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
257 cd $SOURCES_REPOSITORY
258 wget $WGET_URL
259 # Exit if download failed to avoid errors.
260 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
261 echo -e "\nDownload failed, exiting. Please check WGET_URL variable.\n"
262 exit 1
263 fi
264 else
265 echo -n "Source tarball exit... "
266 status
267 fi
268 # Untaring source if necessary. We dont need to extract source if
269 # the package is build with a wanted source package.
270 if [ "$WANTED" = "" ]; then
271 if [ ! -d $src ]; then
272 # Log process.
273 echo "untaring $TARBALL" >> $LOG
274 echo -n "Untaring $TARBALL... "
275 case "$TARBALL" in
276 *zip) ( cd $WOK/$PACKAGE; unzip $SOURCES_REPOSITORY/$TARBALL );;
277 *bz2) tar xjf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
278 *tar) tar xf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
279 *) tar xzf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
280 esac
281 status
282 # Permissions settings
283 chown -R root.root $WOK/$PACKAGE/$PACKAGE-* 2>/dev/null
284 chown -R root.root $WOK/$PACKAGE/$SOURCE-* 2>/dev/null
285 else
286 echo -n "Source direcory exit... " && status
287 fi
288 fi
289 fi
290 cd $WOK/$PACKAGE
291 # Log and execute compile_rules function if it exist, to configure and
292 # make the package if it exist.
293 if grep -q ^compile_rules $RECEIPT; then
294 echo "executing compile_rules" >> $LOG
295 compile_rules
296 # Exit if compilation failed so the binary package
297 # is not generated when using the cook comand.
298 local CHECK=$?
299 if [ $CHECK = 0 ]; then
300 echo "================================================================================"
301 echo "$PACKAGE compiled on : `date +%Y%m%d\ \%H:%M:%S`"
302 echo ""
303 echo "compilation done : `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
304 else
305 echo "================================================================================"
306 echo "Compilation failed. Please read the compilator output."
307 echo "" && exit 1
308 fi
309 else
310 echo "no compile_rules" >> $LOG
311 echo -e "No compile rules for $PACKAGE...\n"
312 fi
313 }
315 # Copy all generic files (locale, pixmaps, .desktop). We use standard path,
316 # so some packages need to copy these files with the receipt and genpkg_rules.
317 # This function is executed by gen_package when 'tazwok genpkg'.
318 copy_generic_files()
319 {
320 # In most case locale are in $_pkg/usr/share/locale so we copy files
321 # using generic variables and $LOCALE from Tazwok config file.
322 if [ ! "$LOCALE" = "" ]; then
323 if [ -d "$_pkg/usr/share/locale" ]; then
324 for i in $LOCALE
325 do
326 if [ -d "$_pkg/usr/share/locale/$i" ]; then
327 mkdir -p $fs/usr/share/locale
328 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
329 fi
330 done
331 fi
332 fi
333 # Pixmaps (PNG or/and XPM only). Some icons/images can be add trough
334 # genpkg_rules and generic copy can be disable with GENERIC_PIXMAPS="no"
335 # in pkg receipt.
336 if [ ! "$GENERIC_PIXMAPS" = "no" ]; then
337 if [ -d "$_pkg/usr/share/pixmaps" ]; then
338 mkdir -p $fs/usr/share/pixmaps
339 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
340 $fs/usr/share/pixmaps 2>/dev/null
341 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
342 $fs/usr/share/pixmaps 2>/dev/null
343 fi
344 # Custom or home made PNG pixmap can be in stuff.
345 if [ -f "stuff/$PACKAGE.png" ]; then
346 mkdir -p $fs/usr/share/pixmaps
347 cp -a stuff/$PACKAGE.png $fs/usr/share/pixmaps
348 fi
349 fi
350 # Desktop entry (.desktop).
351 if [ -d "$_pkg/usr/share/applications" ]; then
352 cp -a $_pkg/usr/share/applications $fs/usr/share
353 fi
354 # Home made desktop file(s) can be in stuff.
355 if [ -d "stuff/applications" ]; then
356 mkdir -p $fs/usr/share
357 cp -a stuff/applications $fs/usr/share
358 fi
359 if [ -f "stuff/$PACKAGE.desktop" ]; then
360 mkdir -p $fs/usr/share/applications
361 cp -a stuff/$PACKAGE.desktop $fs/usr/share/applications
362 fi
363 }
365 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
366 strip_package()
367 {
368 echo -n "Executing strip on all files..."
369 # Binaries.
370 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
371 do
372 if [ -d "$dir" ]; then
373 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
374 fi
375 done
376 # Libraries.
377 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
378 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
379 status
380 }
382 # Creat a package tree and build the gziped cpio archive
383 # to make a SliTaz (.tazpkg) package.
384 gen_package()
385 {
386 check_root
387 check_for_package_on_cmdline
388 check_for_receipt
389 . $RECEIPT
390 check_for_wanted
391 cd $WOK/$PACKAGE
392 # Remove old Tazwok package files.
393 if [ -d "taz" ]; then
394 rm -rf taz
395 rm -f $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
396 fi
397 # Creat the package tree and set usful variables.
398 mkdir -p taz/$PACKAGE-$VERSION/fs
399 fs=taz/$PACKAGE-$VERSION/fs
400 # Set $src for standards package and $_pkg variables.
401 if [ "$WANTED" = "" ]; then
402 src=$WOK/$PACKAGE/$PACKAGE-$VERSION
403 _pkg=$src/_pkg
404 fi
405 if [ ! "$SOURCE" = "" ]; then
406 src=$WOK/$PACKAGE/$SOURCE-$VERSION
407 _pkg=$src/_pkg
408 fi
409 cd $WOK/$PACKAGE
410 # Execute genpkg_rules and copy generic files to build the package.
411 echo ""
412 echo "Bulding $PACKAGE with the receipt..."
413 echo "================================================================================"
414 if grep -q ^genpkg_rules $RECEIPT; then
415 # Log process.
416 echo "executing genpkg_rules" >> $LOG
417 genpkg_rules
418 cd $WOK/$PACKAGE
419 # Skip generic files for packages with a WANTED variable
420 # (dev and splited pkgs).
421 if [ ! "$WANTED" = "" ]; then
422 continue
423 else
424 copy_generic_files
425 fi
426 strip_package
427 else
428 echo "No package rules to gen $PACKAGE..."
429 exit 1
430 fi
431 # Copy the receipt and description (if exist) in the binary package tree.
432 cd $WOK/$PACKAGE
433 echo -n "Copying the receipt..."
434 cp receipt taz/$PACKAGE-$VERSION
435 status
436 if [ -f "description.txt" ]; then
437 echo -n "Copying the description file..."
438 cp description.txt taz/$PACKAGE-$VERSION
439 status
440 fi
441 # Creat the files.list by redirecting find outpout.
442 echo -n "Creating the list of files..."
443 cd taz/$PACKAGE-$VERSION
444 LAST_FILE=""
445 ( find fs -print; echo ) | while read file; do
446 if [ "$LAST_FILE" != "" ]; then
447 case "$file" in
448 $LAST_FILE/*)
449 case "$(ls -ld "$LAST_FILE")" in
450 drwxr-xr-x\ *\ root\ *\ root\ *);;
451 *) echo ${LAST_FILE#fs};;
452 esac;;
453 *) echo ${LAST_FILE#fs};;
454 esac
455 fi
456 LAST_FILE="$file"
457 done > files.list
458 status
459 # Build cpio archives. Find, cpio and gzip the fs, finish by
460 # removing the fs tree.
461 echo -n "Compressing the fs... "
462 find fs -print | cpio -o -H newc | gzip > fs.cpio.gz && rm -rf fs
463 echo -n "Creating full cpio archive... "
464 find . -print | cpio -o -H newc > $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
465 # Restore package tree in case we want to browse it.
466 echo -n "Restoring original package tree... "
467 zcat fs.cpio.gz | cpio -id
468 rm fs.cpio.gz && cd ..
469 # Log process.
470 echo "$PACKAGE-$VERSION.tazpkg (done)" >> $LOG
471 echo "================================================================================"
472 echo "Package $PACKAGE ($VERSION) generated."
473 echo "Size : `du -sh $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg`"
474 echo ""
475 }
477 # Optional text packages list for gen-list.
478 gen_textlist()
479 {
480 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
481 echo -n "Creating the text packages list... "
482 cat >> packages.txt << _EOT_
483 # SliTaz GNU/Linux - Packages list
484 #
485 # Packages : _packages_
486 # Date : $DATE
487 #
488 _EOT_
489 for pkg in $WOK/*
490 do
491 . $pkg/receipt
492 cat >> packages.txt << _EOT_
494 $PACKAGE
495 $VERSION
496 $SHORT_DESC
497 _EOT_
498 packages=$(($packages+1))
499 done && status
500 sed -i s/"_packages_"/"$packages"/ packages.txt
501 }
503 ###################
504 # Tazwok commands #
505 ###################
507 case "$COMMAND" in
508 stats)
509 # Tazwok general statistics from the config file the wok.
510 #
511 echo ""
512 echo -e "\033[1mTazwok configuration statistics\033[0m
513 ================================================================================
514 Wok directory : $WOK
515 Packages repository : $PACKAGES_REPOSITORY
516 Sources repository : $SOURCES_REPOSITORY
517 Packages in the wok : `ls -1 $WOK | wc -l`
518 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
519 ================================================================================"
520 echo ""
521 ;;
522 list)
523 # List packages in wok directory. User can specifiy a category
524 #
525 if [ "$2" = "category" ]; then
526 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
527 exit 0
528 fi
529 # Check for an asked category.
530 if [ -n "$2" ]; then
531 ASKED_CATEGORY=$2
532 echo ""
533 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
534 echo "================================================================================"
535 for pkg in $WOK/*
536 do
537 . $pkg/receipt
538 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
539 echo -n "$PACKAGE"
540 echo -e "\033[28G $VERSION"
541 packages=$(($packages+1))
542 fi
543 done
544 echo "================================================================================"
545 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
546 else
547 # By default list all packages and version.
548 echo ""
549 echo -e "\033[1mList of packages in the wok\033[0m"
550 echo "================================================================================"
551 for pkg in $WOK/*
552 do
553 . $pkg/receipt
554 echo -n "$PACKAGE"
555 echo -en "\033[28G $VERSION"
556 echo -e "\033[42G $CATEGORY"
557 packages=$(($packages+1))
558 done
559 echo "================================================================================"
560 echo -e "$packages packages avalaible in the wok.\n"
561 fi
562 ;;
563 info)
564 # Informations about package.
565 #
566 check_for_package_on_cmdline
567 check_for_receipt
568 . $WOK/$PACKAGE/receipt
569 echo ""
570 echo -e "\033[1mTazwok package informations\033[0m
571 ================================================================================
572 Package : $PACKAGE
573 Version : $VERSION
574 Category : $CATEGORY
575 Short desc : $SHORT_DESC
576 Maintainer : $MAINTAINER"
577 if [ ! "$WEB_SITE" = "" ]; then
578 echo "Web site : $WEB_SITE"
579 fi
580 if [ ! "$DEPENDS" = "" ]; then
581 echo "Depends : $DEPENDS"
582 fi
583 if [ ! "$WANTED" = "" ]; then
584 echo "Wanted src : $WANTED"
585 fi
586 echo "================================================================================"
587 echo ""
589 ;;
590 check-log)
591 # We just cat the file log to view process info.
592 #
593 if [ ! -f "$LOG" ]; then
594 echo -e "\nNo process log found. The package is probably not cook.\n"
595 exit 0
596 else
597 echo ""
598 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
599 echo "================================================================================"
600 cat $LOG
601 echo "================================================================================"
602 echo ""
603 fi
604 ;;
605 search)
606 # Search for a package by pattern or name.
607 #
608 if [ -z "$2" ]; then
609 echo -e "\nPlease specify a pattern or a package name to search."
610 echo -e "Example : 'tazwok search gcc'.\n"
611 exit 0
612 fi
613 echo ""
614 echo -e "\033[1mSearch result for :\033[0m $2"
615 echo "================================================================================"
616 list=`ls -1 $WOK | grep $2`
617 for pkg in $list
618 do
619 . $WOK/$pkg/receipt
620 echo -n "$PACKAGE "
621 echo -en "\033[24G $VERSION"
622 echo -e "\033[42G $CATEGORY"
623 packages=$(($packages+1))
624 done
625 echo "================================================================================"
626 echo "$packages packages found for : $2"
627 echo ""
628 ;;
629 compile)
630 # Configure and make a package with the receipt.
631 #
632 compile_package
633 ;;
634 genpkg)
635 # Generate a package
636 #
637 gen_package
638 ;;
639 cook)
640 # Compile and generate a package. Just execute tazwok with
641 # the good commands.
642 #
643 check_root
644 compile_package
645 gen_package
646 ;;
647 cook-list)
648 # Cook all packages listed in a file. The path to the cooklist must
649 # be specified on the cmdline.
650 #
651 check_root
652 check_for_list
653 for pkg in $LIST
654 do
655 tazwok compile $pkg
656 tazwok genpkg $pkg
657 done
658 ;;
659 clean)
660 # Clean up a package work directory.
661 #
662 check_for_package_on_cmdline
663 check_for_receipt
664 . $RECEIPT
665 cd $WOK/$PACKAGE
666 echo ""
667 echo "Cleaning $PACKAGE..."
668 echo "================================================================================"
669 # Check for clean_wok function.
670 if grep -q ^clean_wok $RECEIPT; then
671 clean_wok
672 fi
673 # Remove taz/ and source tree if exist.
674 if [ -d "taz" ]; then
675 echo -n "Removing taz files..."
676 rm -rf taz && status
677 fi
678 if [ -d "$PACKAGE-$VERSION" ]; then
679 echo -n "Removing source files..."
680 rm -rf $PACKAGE-$VERSION && status
681 fi
682 if [ -d "$SOURCE-$VERSION" ]; then
683 echo -n "Removing source files..."
684 rm -rf $SOURCE-$VERSION && status
685 fi
686 # Remove an envental $PACKAGE-build directory.
687 if [ -d "$PACKAGE-build" ]; then
688 echo -n "Removing build tree..."
689 rm -rf $PACKAGE-build && status
690 fi
691 # Remove process log file.
692 if [ -f "process.log" ]; then
693 echo -n "Removing process log file..."
694 rm process.log && status
695 echo "================================================================================"
696 fi
697 echo "$PACKAGE is clean. You can cook it again..."
698 echo ""
699 ;;
700 gen-clean-wok)
701 # Generate a clean wok from the current wok by copying all receipt
702 # and stuff directory.
703 #
704 if [ -z "$2" ]; then
705 echo -e "\nPlease specify the destination for the new clean wok.\n"
706 exit 0
707 else
708 dest=$2
709 mkdir -p $dest
710 fi
711 echo "New wok is going to : $dest"
712 for pkg in `ls -1 $WOK`
713 do
714 echo "----"
715 echo -n "Preparing $pkg..."
716 mkdir -p $dest/$pkg
717 status
718 echo -n "Copying the receipt..."
719 cp -a $WOK/$pkg/receipt $dest/$pkg
720 status
721 if [ -d "$WOK/$pkg/stuff" ]; then
722 echo -n "Copying all the stuff directory..."
723 cp -a $WOK/$pkg/stuff $dest/$pkg
724 status
725 fi
726 done
727 echo "================================================================================"
728 echo "Clean wok generated in : $dest"
729 echo "Packages cleaned : `ls -1 $dest | wc -l`"
730 echo ""
731 ;;
732 clean-wok)
733 # Clean all packages in the work directory
734 #
735 for pkg in `ls -1 $WOK`
736 do
737 tazwok clean $pkg
738 done
739 echo "================================================================================"
740 echo "`ls -1 $WOK | wc -l` packages cleaned."
741 echo ""
742 ;;
743 gen-list)
744 # Sed is used to remove all the .tazpkg extensions from the
745 # packages.list. The directory to move in by default is the repository
746 # if $2 is not empty cd into $2. A text packages list can also be gen
747 # with the option --text.
748 #
749 if [ "$2" == "--text" ]; then
750 textlist="yes"
751 elif [ -z "$2" ]; then
752 PACKAGES_REPOSITORY=$PACKAGES_REPOSITORY
753 else
754 if [ -d "$2" ]; then
755 PACKAGES_REPOSITORY=$2
756 else
757 echo -e "\nUnable to find directory : $2\n"
758 exit 0
759 fi
760 fi
761 cd $PACKAGES_REPOSITORY
762 # Remove old packages.list and md5sum, it well be soon rebuild.
763 rm -f packages.list packages.md5 packages.txt
764 echo ""
765 echo -e "\033[1mGenerating packages lists\033[0m"
766 echo "================================================================================"
767 echo -n "Repository path : $PACKAGES_REPOSITORY" && status
768 # Gen packages.txt
769 if [ "$textlist" == "yes" ]; then
770 gen_textlist
771 fi
772 echo -n "Creating the raw packages list... "
773 ls -1 *.tazpkg > /tmp/packages.list
774 sed -i s/'.tazpkg'/''/ /tmp/packages.list
775 status
776 echo -n "Building the md5sum for all packages... "
777 md5sum * > packages.md5
778 status
779 mv /tmp/packages.list $PACKAGES_REPOSITORY
780 echo "================================================================================"
781 pkgs=`cat $PACKAGES_REPOSITORY/packages.list | wc -l`
782 echo "$pkgs packages in the repository."
783 echo ""
784 ;;
785 new-tree)
786 # Just creat a few directories and gen a empty receipt to prepare
787 # the creation of a new package.
788 #
789 check_for_package_on_cmdline
790 if [ -d $WOK/$PACKAGE ]; then
791 echo -e "\n$PACKAGE package tree already exist.\n"
792 exit 0
793 fi
794 echo "Creating : $WOK/$PACKAGE"
795 mkdir $WOK/$PACKAGE
796 cd $WOK/$PACKAGE
797 echo -n "Preparing the receipt..."
798 #
799 # Default receipt begin.
800 #
801 echo "# SliTaz package receipt." > receipt
802 echo "" >> receipt
803 echo "PACKAGE=\"$PACKAGE\"" >> receipt
804 # Finish the empty receipt.
805 cat >> receipt << "EOF"
806 VERSION=""
807 CATEGORY=""
808 SHORT_DESC=""
809 MAINTAINER=""
810 DEPENDS=""
811 TARBALL="$PACKAGE-$VERSION.tar.gz"
812 WEB_SITE=""
813 WGET_URL=""
815 # Rules to configure and make the package.
816 compile_rules()
817 {
818 cd $src
819 ./configure --prefix=/usr --infodir=/usr/share/info \
820 --mandir=/usr/share/man $CONFIGURE_ARGS
821 make
822 make DESTDIR=$PWD/_pkg install
823 }
825 # Rules to gen a SliTaz package suitable for Tazpkg.
826 genpkg_rules()
827 {
828 mkdir -p $fs/usr
829 cp -a $_pkg/usr/bin $fs/usr
830 strip -s $fs/usr/bin/*
831 }
833 EOF
834 #
835 # Default receipt end.
836 #
837 status
838 # Interactive mode, asking and seding.
839 if [ "$3" = "--interactive" ]; then
840 echo "Entering in interactive mode..."
841 echo "================================================================================"
842 echo "Package : $PACKAGE"
843 # Version.
844 echo -n "Version : " ; read anser
845 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
846 # Category.
847 echo -n "Category : " ; read anser
848 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
849 # Short description.
850 echo -n "Short desc : " ; read anser
851 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
852 # Maintainer.
853 echo -n "Maintainer : " ; read anser
854 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
855 # Web site.
856 echo -n "Web site : " ; read anser
857 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
858 echo ""
859 # Wget URL.
860 echo "Wget URL to download source tarball."
861 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
862 echo -n "Wget url : " ; read anser
863 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
864 # Ask for a stuff dir.
865 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
866 if [ "$anser" = "y" ]; then
867 echo -n "Creating the stuff directory..."
868 mkdir stuff && status
869 fi
870 # Ask for a description file.
871 echo -n "Are you going to write a description ? (y/N) : " ; read anser
872 if [ "$anser" = "y" ]; then
873 echo -n "Creating the description.txt file..."
874 echo "" > description.txt && status
875 fi
876 echo "================================================================================"
877 echo ""
878 fi
879 ;;
880 remove)
881 # Remove a package from the wok.
882 #
883 check_for_package_on_cmdline
884 echo ""
885 echo -n "Removing $PACKAGE..."
886 rm -rf $WOK/$PACKAGE && status
887 echo ""
888 ;;
889 usage|*)
890 # Print usage also for all unknow commands.
891 #
892 usage
893 ;;
894 esac
896 exit 0