tazwok view tazwok @ rev 78

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