tazwok view tazwok @ rev 12

Added tag 1.2 for changeset a900f34b0d9f
author Christophe Lincoln <pankso@slitaz.org>
date Wed Dec 12 19:00:28 2007 +0100 (2007-12-12)
parents
children 6389ab247fd9
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 SliTaz - GNU General Public License.
10 # Author : <pankso@slitaz.org>
11 #
12 VERSION=1.2
14 ####################
15 # Tazwok variables #
16 ####################
18 # Packages categories.
19 CATEGORIES="base-system base-apps x-window extra"
21 # Use words rater than numbers in the code.
22 COMMAND=$1
23 PACKAGE=$2
24 LIST=$2
26 # Include config file or exit if any file found.
27 if [ -f "/etc/tazwok.conf" ]; then
28 . /etc/tazwok.conf
29 else
30 echo -e "\nUnable to find the configuration file : /etc/tazwok.conf"
31 echo -e "Please read the Tazwok documentation.\n"
32 exit 0
33 fi
35 # Creat Taz wok needed directories if user is root.
36 if test $(id -u) = 0 ; then
37 # Check for the wok directory.
38 if [ ! -d "$WOK" ]; then
39 echo "Creating the wok directory..."
40 mkdir -p $WOK
41 chmod 777 $WOK
42 fi
43 # Check for the packages repository.
44 if [ ! -d "$PACKAGES_REPOSITORY" ]; then
45 echo "Creating the packages repository..."
46 mkdir -p $PACKAGES_REPOSITORY
47 fi
48 # Check for the sources repository.
49 if [ ! -d "$SOURCES_REPOSITORY" ]; then
50 echo "Creating the sources repository..."
51 mkdir -p $PACKAGES_REPOSITORY
52 fi
53 fi
55 # The path to the most important file used by Tazwok.
56 # The receipt is used to compile the source code and
57 # gen suitables packages for Tazpkg.
58 RECEIPT="$WOK/$PACKAGE/receipt"
60 # The path to the process log file.
61 LOG="$WOK/$PACKAGE/process.log"
63 ####################
64 # Tazwok functions #
65 ####################
67 # Print the usage (English).
68 usage ()
69 {
70 echo -e "\nSliTaz sources compiler and packages generator - Version: $VERSION\n
71 \033[1mUsage: \033[0m `basename $0` [command] [package|list|category|dir] [--option]
72 \033[1mCommands: \033[0m\n
73 usage Print this short usage.
74 stats Print Tazwok statistics from the config file and the wok.
75 list List all packages in the wok tree or by category.
76 info Get informations about a package in the wok.
77 check-log Check the process log file of a package.
78 search Search for a package in the wok by pattern or name.
79 compile Configure and build the package using the receipt rules.
80 genpkg Generate a suitable package for Tazpkg with the rules.
81 cook Compile and generate a package directly.
82 cook-list Cook all packages specified in the list by order.
83 clean Clean all generated files in the package tree.
84 new-tree Prepare a new package tree and receipt (--interactive).
85 gen-list Generate a packages.list and md5sum for a repository.
86 gen-clean-wok Gen a clean wok in a dir ('clean-wok' cleans current wok).
87 remove Remove a package from the wok.\n"
88 }
90 # Status function.
91 status()
92 {
93 local CHECK=$?
94 echo -en "\\033[70G[ "
95 if [ $CHECK = 0 ]; then
96 echo -en "\\033[1;33mOK"
97 else
98 echo -en "\\033[1;31mFailed"
99 fi
100 echo -e "\\033[0;39m ]"
101 }
103 # Check if user is root.
104 check_root()
105 {
106 if test $(id -u) != 0 ; then
107 echo -e "\nYou must be root to run `basename $0` with this option."
108 echo -e "Please type 'su' and root password to become super-user.\n"
109 exit 0
110 fi
111 }
113 # Check for a package name on cmdline.
114 check_for_package_on_cmdline()
115 {
116 if [ -z "$PACKAGE" ]; then
117 echo -e "\nYou must specify a package name on the command line."
118 echo -e "Example : tazwok $COMMAND package\n"
119 exit 0
120 fi
121 }
123 # Check for the receipt of a package used to cook.
124 check_for_receipt()
125 {
126 if [ ! -f "$RECEIPT" ]; then
127 echo -e "\nUnable to find the receipt : $RECEIPT\n"
128 exit 0
129 fi
130 }
132 # Check for a specified file list on cmdline.
133 check_for_list()
134 {
135 if [ -z "$LIST" ]; then
136 echo -e "\nPlease specify the path to the list of packages to cook.\n"
137 exit 0
138 fi
139 # Check if the list of packages exist.
140 if [ -f "$LIST" ]; then
141 LIST=`cat $LIST`
142 else
143 echo -e "\nUnable to find $LIST packages list.\n"
144 exit 0
145 fi
146 }
148 # Check for the wanted package if specified in WANTED
149 # receipt variable. Set the $src/$_pkg variable to help compiling
150 # and generating packages.
151 check_for_wanted()
152 {
153 if [ ! "$WANTED" = "" ]; then
154 echo -n "Checking for the wanted package..."
155 if [ ! -d "$WOK/$WANTED" ]; then
156 echo -e "\nWanted package is missing in the work directory.\n"
157 exit 0
158 fi
159 status
160 # Set wanted src path.
161 src=$WOK/$WANTED/$WANTED-$VERSION
162 _pkg=$src/_pkg
163 fi
164 }
166 # Configure and make a package with the receipt.
167 compile_package()
168 {
169 check_for_package_on_cmdline
170 # Include the receipt to get all needed variables and functions
171 # and cd into the work directory to start the work.
172 check_for_receipt
173 . $RECEIPT
174 # Log the package name and date.
175 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
176 echo "package $PACKAGE (compile)" >> $LOG
177 # Set wanted $src variable to help compiling.
178 if [ ! "$SOURCE" = "" ]; then
179 src=$WOK/$PACKAGE/$SOURCE-$VERSION
180 else
181 src=$WOK/$PACKAGE/$PACKAGE-$VERSION
182 fi
183 check_for_wanted
184 echo ""
185 echo "Starting to cook $PACKAGE..."
186 echo "================================================================================"
187 # Check for src tarball and wget if needed.
188 if [ ! "$TARBALL" = "" ]; then
189 echo "Checking for source tarball... "
190 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
191 cd $SOURCES_REPOSITORY
192 wget $WGET_URL
193 # Exit if download failed to avoid errors.
194 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
195 echo -e "\nDownload failed, exiting. Please check WGET_URL variable.\n"
196 exit 1
197 fi
198 else
199 echo -n "Source tarball exit... "
200 status
201 fi
202 # Untaring source if necessary. We dont need to extract source if
203 # the package is build with a wanted source package.
204 if [ "$WANTED" = "" ]; then
205 if [ ! -d $src ]; then
206 # Log process.
207 echo "untaring $TARBALL" >> $LOG
208 echo -n "Untaring $TARBALL... "
209 if [ "`basename $TARBALL | grep tar.bz2`" ]; then
210 tar xjf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE
211 else
212 tar xzf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE
213 fi
214 status
215 else
216 echo -n "Source direcory exit... " && status
217 fi
218 fi
219 fi
220 cd $WOK/$PACKAGE
221 # Log and execute compile_rules function if it exist, to configure and
222 # make the package if it exist.
223 if [ `cat $RECEIPT | grep compile_rules` ]; then
224 echo "executing compile_rules" >> $LOG
225 compile_rules
226 # Exit if compilation failed so the binary package
227 # is not generated when using the cook comand.
228 local CHECK=$?
229 if [ $CHECK = 0 ]; then
230 echo "================================================================================"
231 echo "$PACKAGE compiled on : `date +%Y%m%d\ \%H:%M:%S`"
232 echo ""
233 echo "compilation done : `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
234 else
235 echo "================================================================================"
236 echo "Compilation failed. Please read the compilator output."
237 echo "" && exit 1
238 fi
239 else
240 echo "no compile_rules" >> $LOG
241 echo -e "No compile rules for $PACKAGE...\n"
242 fi
243 }
245 # Creat a package tree and build the gziped cpio archive
246 # to make a SliTaz (.tazpkg) package.
247 gen_package()
248 {
249 check_root
250 check_for_package_on_cmdline
251 check_for_receipt
252 . $RECEIPT
253 check_for_wanted
254 cd $WOK/$PACKAGE
255 # Remove old Tazwok package files.
256 if [ -d "taz" ]; then
257 rm -rf taz
258 rm -f $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
259 fi
260 # Creat the package tree and set usful variables.
261 mkdir -p taz/$PACKAGE-$VERSION/fs
262 fs=taz/$PACKAGE-$VERSION/fs
263 # Set $src for standards package and $_pkg variables.
264 if [ "$WANTED" = "" ]; then
265 src=$WOK/$PACKAGE/$PACKAGE-$VERSION
266 _pkg=$src/_pkg
267 fi
268 if [ ! "$SOURCE" = "" ]; then
269 src=$WOK/$PACKAGE/$SOURCE-$VERSION
270 _pkg=$src/_pkg
271 fi
272 cd $WOK/$PACKAGE
273 # Execute genpkg_rules to build the package.
274 echo ""
275 echo "Bulding $PACKAGE with the receipt..."
276 echo "================================================================================"
277 if [ `cat $RECEIPT | grep genpkg_rules` ]; then
278 # Log process.
279 echo "executing genpkg_rules" >> $LOG
280 genpkg_rules
281 else
282 echo "No package rules to gen $PACKAGE..."
283 fi
284 # Copy the receipt and description (if exist) in
285 # the binary package tree.
286 cd $WOK/$PACKAGE
287 echo -n "Copying the receipt..."
288 cp receipt taz/$PACKAGE-$VERSION
289 status
290 if [ -f "description.txt" ]; then
291 echo -n "Copying the description file..."
292 cp description.txt taz/$PACKAGE-$VERSION
293 status
294 fi
295 # Creat the files.list by redirecting find outpout.
296 echo -n "Creating the list of files..."
297 cd taz/$PACKAGE-$VERSION/fs
298 find . -type f -print > ../files.list
299 find . -type l -print >> ../files.list
300 cd .. && sed -i s/'^.'/''/ files.list
301 status
302 # Build cpio archives. Find, cpio and gzip the fs, finish by
303 # removing the fs tree.
304 echo -n "Compressing the fs... "
305 find fs -print | cpio -o -H newc > fs.cpio
306 gzip fs.cpio && rm -rf fs
307 echo -n "Creating full cpio archive... "
308 find . -print | cpio -o -H newc > $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg
309 # Restore package tree in case we want to browse it.
310 echo -n "Restoring original package tree... "
311 gzip -d fs.cpio.gz && cpio -id < fs.cpio
312 rm fs.cpio && cd ..
313 # Log process.
314 echo "$PACKAGE-$VERSION.tazpkg (done)" >> $LOG
315 echo "================================================================================"
316 echo "Package $PACKAGE ($VERSION) generated."
317 echo "Size : `du -sh $PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg`"
318 echo ""
319 }
321 ###################
322 # Tazwok commands #
323 ###################
325 case "$COMMAND" in
326 stats)
327 # Tazwok general statistics from the config file the wok.
328 #
329 echo ""
330 echo -e "\033[1mTazwok configuration statistics\033[0m
331 ================================================================================
332 Wok directory : $WOK
333 Packages repository : $PACKAGES_REPOSITORY
334 Sources repository : $SOURCES_REPOSITORY
335 Packages in the wok : `ls -1 $WOK | wc -l`
336 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg | wc -l`
337 ================================================================================"
338 echo ""
339 ;;
340 list)
341 # List packages in wok directory. User can specifiy a category
342 #
343 if [ "$2" = "category" ]; then
344 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
345 exit 0
346 fi
347 # Check for an asked category.
348 if [ -n "$2" ]; then
349 ASKED_CATEGORY=$2
350 echo ""
351 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
352 echo "================================================================================"
353 for pkg in $WOK/*
354 do
355 . $pkg/receipt
356 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
357 echo -n "$PACKAGE"
358 echo -e "\033[24G $VERSION"
359 packages=$(($packages+1))
360 fi
361 done
362 echo "================================================================================"
363 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
364 else
365 # By default list all packages and version.
366 echo ""
367 echo -e "\033[1mList of packages in the wok\033[0m"
368 echo "================================================================================"
369 for pkg in $WOK/*
370 do
371 . $pkg/receipt
372 echo -n "$PACKAGE"
373 echo -en "\033[24G $VERSION"
374 echo -e "\033[42G $CATEGORY"
375 packages=$(($packages+1))
376 done
377 echo "================================================================================"
378 echo -e "$packages packages avalaible in the wok.\n"
379 fi
380 ;;
381 info)
382 # Informations about package.
383 #
384 check_for_package_on_cmdline
385 check_for_receipt
386 . $WOK/$PACKAGE/receipt
387 echo ""
388 echo -e "\033[1mTazwok package informations\033[0m
389 ================================================================================
390 Package : $PACKAGE
391 Version : $VERSION
392 Category : $CATEGORY
393 Short desc : $SHORT_DESC
394 Maintainer : $MAINTAINER"
395 if [ ! "$WEB_SITE" = "" ]; then
396 echo "Web site : $WEB_SITE"
397 fi
398 if [ ! "$DEPENDS" = "" ]; then
399 echo "Depends : $DEPENDS"
400 fi
401 if [ ! "$WANTED" = "" ]; then
402 echo "Wanted src : $WANTED"
403 fi
404 echo "================================================================================"
405 echo ""
407 ;;
408 check-log)
409 # We just cat the file log to view process info.
410 #
411 if [ ! -f "$LOG" ]; then
412 echo -e "\nNo process log found. The package is probably not cook.\n"
413 exit 0
414 else
415 echo ""
416 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
417 echo "================================================================================"
418 cat $LOG
419 echo "================================================================================"
420 echo ""
421 fi
422 ;;
423 search)
424 # Search for a package by pattern or name.
425 #
426 if [ -z "$2" ]; then
427 echo -e "\nPlease specify a pattern or a package name to search."
428 echo -e "Example : 'tazwok search gcc'.\n"
429 exit 0
430 fi
431 echo ""
432 echo -e "\033[1mSearch result for :\033[0m $2"
433 echo "================================================================================"
434 list=`ls -1 $WOK | grep $2`
435 for pkg in $list
436 do
437 . $WOK/$pkg/receipt
438 echo -n "$PACKAGE "
439 echo -en "\033[24G $VERSION"
440 echo -e "\033[42G $CATEGORY"
441 packages=$(($packages+1))
442 done
443 echo "================================================================================"
444 echo "$packages packages found for : $2"
445 echo ""
446 ;;
447 compile)
448 # Configure and make a package with the receipt.
449 #
450 compile_package
451 ;;
452 genpkg)
453 # Generate a package
454 #
455 gen_package
456 ;;
457 cook)
458 # Compile and generate a package. Just execute tazwok with
459 # the good commands.
460 #
461 check_root
462 compile_package
463 gen_package
464 ;;
465 cook-list)
466 # Cook all packages listed in a file. The path to the cooklist must
467 # be specified on the cmdline.
468 #
469 check_root
470 check_for_list
471 for pkg in $LIST
472 do
473 tazwok compile $pkg
474 tazwok genpkg $pkg
475 done
476 ;;
477 clean)
478 # Clean up a package work directory.
479 #
480 check_for_package_on_cmdline
481 check_for_receipt
482 . $RECEIPT
483 cd $WOK/$PACKAGE
484 echo ""
485 echo "Cleaning $PACKAGE..."
486 echo "================================================================================"
487 if [ -d "taz" ]; then
488 echo -n "Removing taz files..."
489 rm -rf taz && status
490 fi
491 # Remove source tree if exist.
492 if [ -d "$PACKAGE-$VERSION" ]; then
493 echo -n "Removing source files..."
494 rm -rf $PACKAGE-$VERSION && status
495 fi
496 if [ -d "$SOURCE-$VERSION" ]; then
497 echo -n "Removing source files..."
498 rm -rf $SOURCE-$VERSION && status
499 fi
500 # Remove an envental $PACKAGE-build directory.
501 if [ -d "$PACKAGE-build" ]; then
502 echo -n "Removing build tree..."
503 rm -rf $PACKAGE-build && status
504 fi
505 # Remove process log file.
506 if [ -f "process.log" ]; then
507 echo -n "Removing process log file..."
508 rm process.log && status
509 fi
510 echo "$PACKAGE is clean. You can cook it again..."
511 echo ""
512 ;;
513 gen-clean-wok)
514 # Generate a clean wok from the current wok by copying all receipt
515 # and stuff directory.
516 #
517 if [ -z "$2" ]; then
518 echo -e "\nPlease specify the destination for the new clean wok.\n"
519 exit 0
520 else
521 dest=$2
522 mkdir -p $dest
523 fi
524 echo "New wok is going to : $dest"
525 for pkg in `ls -1 $WOK`
526 do
527 echo "----"
528 echo -n "Preparing $pkg..."
529 mkdir -p $dest/$pkg
530 status
531 echo -n "Copying the receipt..."
532 cp -a $WOK/$pkg/receipt $dest/$pkg
533 status
534 if [ -d "$WOK/$pkg/stuff" ]; then
535 echo -n "Copying all the stuff directory..."
536 cp -a $WOK/$pkg/stuff $dest/$pkg
537 status
538 fi
539 done
540 echo "================================================================================"
541 echo "Clean wok generated in : $dest"
542 echo "Packages cleaned : `ls -1 $dest | wc -l`"
543 echo ""
544 ;;
545 clean-wok)
546 # Clean all packages in the work directory
547 #
548 for pkg in `ls -1 $WOK`
549 do
550 tazwok clean $pkg
551 done
552 echo "================================================================================"
553 echo "`ls -1 $WOK | wc -l` packages cleaned."
554 echo ""
555 ;;
556 gen-list)
557 # cd in the directory to creat a packages.list and the md5sum file.
558 # Sed is used to remove all the .tazpkg extensions from the
559 # packages.list. The directory to move in by default is the repository
560 # if $3 is not empty cd into $3.
561 #
562 if [ -z "$2" ]; then
563 PACKAGES_REPOSITORY=$PACKAGES_REPOSITORY
564 else
565 if [ -d "$2" ]; then
566 PACKAGES_REPOSITORY=$2
567 else
568 echo -e "\nUnable to find directory : $2\n"
569 exit 0
570 fi
571 fi
572 cd $PACKAGES_REPOSITORY
573 # Remove old packages.list and md5sum, it well be soon rebuild.
574 rm -f packages.list packages.md5
575 echo ""
576 echo "Repository path : $PACKAGES_REPOSITORY"
577 echo -n "Creating the packages list... "
578 ls -1 > /tmp/packages.list
579 sed -i s/'.tazpkg'/''/ /tmp/packages.list
580 status
581 echo -n "Building the md5sum for all packages... "
582 md5sum * > packages.md5
583 status
584 mv /tmp/packages.list $PACKAGES_REPOSITORY
585 echo "================================================================================"
586 pkgs=`cat $PACKAGES_REPOSITORY/packages.list | wc -l`
587 echo "$pkgs packages in the repository."
588 echo ""
589 ;;
590 new-tree)
591 # Just creat a few directories and gen a empty receipt to prepare
592 # the creation of a new package.
593 #
594 check_for_package_on_cmdline
595 if [ -d $WOK/$PACKAGE ]; then
596 echo -e "\n$PACKAGE package tree already exist.\n"
597 exit 0
598 fi
599 echo "Creating : $WOK/$PACKAGE"
600 mkdir $WOK/$PACKAGE
601 cd $WOK/$PACKAGE
602 echo -n "Preparing the receipt..."
603 #
604 # Default receipt begin.
605 #
606 echo "# SliTaz package receipt." > receipt
607 echo "" >> receipt
608 echo "PACKAGE=\"$PACKAGE\"" >> receipt
609 # Finish the empty receipt.
610 cat >> receipt << "EOF"
611 VERSION=""
612 CATEGORY=""
613 SHORT_DESC=""
614 MAINTAINER=""
615 DEPENDS=""
616 TARBALL="$PACKAGE-$VERSION.tar.gz"
617 WEB_SITE=""
618 WGET_URL=""
620 # Rules to configure and make the package.
621 compile_rules()
622 {
623 cd $src
624 ./configure --prefix=/usr --infodir=/usr/share/info \
625 --mandir=/usr/share/man $CONFIGURE_ARGS
626 make
627 make DESTDIR=$PWD/_pkg install
628 }
630 # Rules to gen a SliTaz package suitable for Tazpkg.
631 genpkg_rules()
632 {
633 mkdir -p $fs/usr
634 cp -a $_pkg/usr/bin $fs/usr
635 strip -s $fs/usr/bin/*
636 }
638 EOF
639 #
640 # Default receipt end.
641 #
642 status
643 # Interactive mode, asking and seding.
644 if [ "$3" = "--interactive" ]; then
645 echo "Entering in interactive mode..."
646 echo "================================================================================"
647 echo "Package : $PACKAGE"
648 # Version.
649 echo -n "Version : " ; read anser
650 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
651 # Category.
652 echo -n "Category : " ; read anser
653 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
654 # Short description.
655 echo -n "Short desc : " ; read anser
656 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
657 # Maintainer.
658 echo -n "Maintainer : " ; read anser
659 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
660 # Web site.
661 echo -n "Web site : " ; read anser
662 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
663 echo ""
664 # Wget URL.
665 echo "Wget URL to download source tarball."
666 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
667 echo -n "Wget url : " ; read anser
668 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
669 # Ask for a stuff dir.
670 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
671 if [ "$anser" = "y" ]; then
672 echo -n "Creating the stuff directory..."
673 mkdir stuff && status
674 fi
675 # Ask for a description file.
676 echo -n "Are you going to write a description ? (y/N) : " ; read anser
677 if [ "$anser" = "y" ]; then
678 echo -n "Creating the description.txt file..."
679 echo "" > description.txt && status
680 fi
681 echo "================================================================================"
682 echo ""
683 fi
684 ;;
685 remove)
686 # Remove a package from the wok.
687 #
688 check_for_package_on_cmdline
689 echo ""
690 echo -n "Removing $PACKAGE..."
691 rm -rf $WOK/$PACKAGE && status
692 echo ""
693 ;;
694 usage|*)
695 # Print usage also for all unknow commands.
696 #
697 usage
698 ;;
699 esac
701 exit 0