tazwok view tazwok @ rev 82

Fix typos
author Mike D. Smith <MikeDSmith25@gmail.com>
date Sat Jul 19 05:46:08 2008 +0000 (2008-07-19)
parents 093a2c27d4b7
children c55016507431
line source
1 #!/bin/sh
2 # Tazwok - SliTaz source compiler and binary packages generator/cooker.
3 #
4 # Tazwok can compile source packages and create binary packages suitable for
5 # Tazpkg (Tiny Autonomous zone package manager). You can build individual
6 # packages or a list of 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=2.0
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 rather than numbers in the code.
34 COMMAND=$1
35 PACKAGE=$2
36 LIST=$2
38 # Include config file or exit if no file found.
39 if [ -f "./tazwok.conf" ]; then
40 . ./tazwok.conf
41 elif [ -f "/etc/tazwok.conf" ]; then
42 . /etc/tazwok.conf
43 else
44 echo -e "\nUnable to find the configuration file : /etc/tazwok.conf"
45 echo -e "Please read the Tazwok documentation.\n"
46 exit 0
47 fi
49 # Create Taz wok needed directories if user is root.
50 if test $(id -u) = 0 ; then
51 # Check for the wok directory.
52 if [ ! -d "$WOK" ]; then
53 echo "Creating the wok directory..."
54 mkdir -p $WOK
55 chmod 777 $WOK
56 fi
57 # Check for the packages repository.
58 if [ ! -d "$PACKAGES_REPOSITORY" ]; then
59 echo "Creating the packages repository..."
60 mkdir -p $PACKAGES_REPOSITORY
61 fi
62 # Check for the sources repository.
63 if [ ! -d "$SOURCES_REPOSITORY" ]; then
64 echo "Creating the sources repository..."
65 mkdir -p $SOURCES_REPOSITORY
66 fi
67 fi
69 # The path to the most important file used by Tazwok.
70 # The receipt is used to compile the source code and
71 # generate suitable packages for Tazpkg.
72 RECEIPT="$WOK/$PACKAGE/receipt"
74 # The path to the process log file.
75 LOG="$WOK/$PACKAGE/process.log"
77 ####################
78 # Tazwok functions #
79 ####################
81 # Print the usage (English).
82 usage ()
83 {
84 echo -e "\nSliTaz sources compiler and packages generator - Version: $VERSION\n
85 \033[1mUsage: \033[0m `basename $0` [command] [package|list|category|dir] [--option]
86 \033[1mCommands: \033[0m\n
87 usage Print this short usage.
88 stats Print Tazwok statistics from the config file and the wok.
89 cmp|compare Compare the wok and the cooked pkgs (--remove old pkgs).
90 list List all packages in the wok tree or by category.
91 info Get information 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 a 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 list 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 exists.
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 # Check for loop in deps tree.
232 check_for_deps_loop()
233 {
234 local list
235 local pkg
236 local deps
237 pkg=$1
238 shift
239 [ -n "$1" ] || return
240 list=""
241 # Filter out already processed deps
242 for i in $@; do
243 case " $ALL_DEPS" in
244 *\ $i\ *);;
245 *) list="$list $i";;
246 esac
247 done
248 ALL_DEPS="$ALL_DEPS$list "
249 for i in $list; do
250 [ -f $i/receipt ] || continue
251 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
252 case " $deps " in
253 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
254 *) check_for_deps_loop $pkg $deps;;
255 esac
256 done
257 }
259 download()
260 {
261 for file in $@; do
262 wget $file && break
263 done
264 }
266 # Configure and make a package with the receipt.
267 compile_package()
268 {
269 check_for_package_on_cmdline
270 # Include the receipt to get all needed variables and functions
271 # and cd into the work directory to start the work.
272 check_for_receipt
273 . $RECEIPT
274 # Log the package name and date.
275 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
276 echo "package $PACKAGE (compile)" >> $LOG
277 # Set wanted $src variable to help compiling.
278 if [ ! "$SOURCE" = "" ]; then
279 src=$WOK/$PACKAGE/$SOURCE-$VERSION
280 else
281 src=$WOK/$PACKAGE/$PACKAGE-$VERSION
282 fi
283 check_for_build_depends
284 check_for_wanted
285 echo ""
286 echo "Starting to cook $PACKAGE..."
287 echo "================================================================================"
288 # Check for src tarball and wget if needed.
289 if [ ! "$WGET_URL" = "" ]; then
290 echo "Checking for source tarball... "
291 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
292 cd $SOURCES_REPOSITORY
293 download $WGET_URL
294 #wget $WGET_URL
295 # Exit if download failed to avoid errors.
296 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
297 echo -e "\nDownload failed, exiting. Please check WGET_URL variable.\n"
298 exit 1
299 fi
300 else
301 echo -n "Source tarball exit... "
302 status
303 fi
304 # Untaring source if necessary. We don't need to extract source if
305 # the package is built with a wanted source package.
306 if [ "$WANTED" = "" ]; then
307 if [ ! -d $src ]; then
308 # Log process.
309 echo "untaring $TARBALL" >> $LOG
310 echo -n "Untaring $TARBALL... "
311 case "$TARBALL" in
312 *zip) ( cd $WOK/$PACKAGE; unzip $SOURCES_REPOSITORY/$TARBALL );;
313 *bz2) tar xjf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
314 *tar) tar xf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
315 *) tar xzf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
316 esac
317 status
318 # Permissions settings
319 chown -R root.root $WOK/$PACKAGE/$PACKAGE-* 2>/dev/null
320 chown -R root.root $WOK/$PACKAGE/$SOURCE-* 2>/dev/null
321 else
322 echo -n "Source direcory exit... " && status
323 fi
324 fi
325 fi
326 cd $WOK/$PACKAGE
327 # Log and execute compile_rules function if it exists, to configure and
328 # make the package if it exists.
329 if grep -q ^compile_rules $RECEIPT; then
330 echo "executing compile_rules" >> $LOG
331 compile_rules
332 # Exit if compilation failed so the binary package
333 # is not generated when using the cook comand.
334 local CHECK=$?
335 if [ $CHECK = 0 ]; then
336 echo "================================================================================"
337 echo "$PACKAGE compiled on : `date +%Y%m%d\ \%H:%M:%S`"
338 echo ""
339 echo "compilation done : `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
340 else
341 echo "================================================================================"
342 echo "Compilation failed. Please read the compilator output."
343 echo "" && exit 1
344 fi
345 else
346 echo "no compile_rules" >> $LOG
347 echo -e "No compile rules for $PACKAGE...\n"
348 fi
349 }
351 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
352 # so some packages need to copy these files with the receipt and genpkg_rules.
353 # This function is executed by gen_package when 'tazwok genpkg'.
354 copy_generic_files()
355 {
356 # In most cases, locales are in $_pkg/usr/share/locale so we copy files
357 # using generic variables and $LOCALE from Tazwok config file.
358 if [ ! "$LOCALE" = "" ]; then
359 if [ -d "$_pkg/usr/share/locale" ]; then
360 for i in $LOCALE
361 do
362 if [ -d "$_pkg/usr/share/locale/$i" ]; then
363 mkdir -p $fs/usr/share/locale
364 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
365 fi
366 done
367 fi
368 fi
369 # Pixmaps (PNG or/and XPM only). Some icons/images can be added through
370 # genpkg_rules and generic copy can be disabled with GENERIC_PIXMAPS="no"
371 # in pkg receipt.
372 if [ ! "$GENERIC_PIXMAPS" = "no" ]; then
373 if [ -d "$_pkg/usr/share/pixmaps" ]; then
374 mkdir -p $fs/usr/share/pixmaps
375 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
376 $fs/usr/share/pixmaps 2>/dev/null
377 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
378 $fs/usr/share/pixmaps 2>/dev/null
379 fi
380 # Custom or homemade PNG pixmap can be in stuff.
381 if [ -f "stuff/$PACKAGE.png" ]; then
382 mkdir -p $fs/usr/share/pixmaps
383 cp -a stuff/$PACKAGE.png $fs/usr/share/pixmaps
384 fi
385 fi
386 # Desktop entry (.desktop).
387 if [ -d "$_pkg/usr/share/applications" ]; then
388 cp -a $_pkg/usr/share/applications $fs/usr/share
389 fi
390 # Homemade desktop file(s) can be in stuff.
391 if [ -d "stuff/applications" ]; then
392 mkdir -p $fs/usr/share
393 cp -a stuff/applications $fs/usr/share
394 fi
395 if [ -f "stuff/$PACKAGE.desktop" ]; then
396 mkdir -p $fs/usr/share/applications
397 cp -a stuff/$PACKAGE.desktop $fs/usr/share/applications
398 fi
399 }
401 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
402 strip_package()
403 {
404 echo -n "Executing strip on all files..."
405 # Binaries.
406 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
407 do
408 if [ -d "$dir" ]; then
409 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
410 fi
411 done
412 # Libraries.
413 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
414 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
415 status
416 }
418 # Create a package tree and build the gziped cpio archive
419 # to make a SliTaz (.tazpkg) package.
420 gen_package()
421 {
422 check_root
423 check_for_package_on_cmdline
424 check_for_receipt
425 EXTRAVERSION=""
426 . $RECEIPT
427 check_for_wanted
428 cd $WOK/$PACKAGE
429 # Remove old Tazwok package files.
430 if [ -d "taz" ]; then
431 rm -rf taz
432 rm -f $PACKAGES_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
433 fi
434 # Create the package tree and set useful variables.
435 mkdir -p taz/$PACKAGE-$VERSION/fs
436 fs=taz/$PACKAGE-$VERSION/fs
437 # Set $src for standard package and $_pkg variables.
438 if [ "$WANTED" = "" ]; then
439 src=$WOK/$PACKAGE/$PACKAGE-$VERSION
440 _pkg=$src/_pkg
441 fi
442 if [ ! "$SOURCE" = "" ]; then
443 src=$WOK/$PACKAGE/$SOURCE-$VERSION
444 _pkg=$src/_pkg
445 fi
446 cd $WOK/$PACKAGE
447 # Execute genpkg_rules and copy generic files to build the package.
448 echo ""
449 echo "Bulding $PACKAGE with the receipt..."
450 echo "================================================================================"
451 if grep -q ^genpkg_rules $RECEIPT; then
452 # Log process.
453 echo "executing genpkg_rules" >> $LOG
454 genpkg_rules
455 cd $WOK/$PACKAGE
456 # Skip generic files for packages with a WANTED variable
457 # (dev and splited pkgs).
458 if [ ! "$WANTED" = "" ]; then
459 continue
460 else
461 copy_generic_files
462 fi
463 strip_package
464 else
465 echo "No package rules to gen $PACKAGE..."
466 exit 1
467 fi
468 # Copy the receipt and description (if exists) in the binary package tree.
469 cd $WOK/$PACKAGE
470 echo -n "Copying the receipt..."
471 cp receipt taz/$PACKAGE-$VERSION
472 status
473 if [ -f "description.txt" ]; then
474 echo -n "Copying the description file..."
475 cp description.txt taz/$PACKAGE-$VERSION
476 status
477 fi
478 # Create the files.list by redirecting find output.
479 echo -n "Creating the list of files..."
480 cd taz/$PACKAGE-$VERSION
481 LAST_FILE=""
482 ( find fs -print; echo ) | while read file; do
483 if [ "$LAST_FILE" != "" ]; then
484 case "$file" in
485 $LAST_FILE/*)
486 case "$(ls -ld "$LAST_FILE")" in
487 drwxr-xr-x\ *\ root\ *\ root\ *);;
488 *) echo ${LAST_FILE#fs};;
489 esac;;
490 *) echo ${LAST_FILE#fs};;
491 esac
492 fi
493 LAST_FILE="$file"
494 done > files.list
495 status
496 echo -n "Creating md5sum of files..."
497 while read file; do
498 [ -L "fs$file" ] && continue
499 [ -f "fs$file" ] || continue
500 md5sum "fs$file" | sed 's/ fs/ /'
501 done < files.list > md5sum
502 status
503 [ -s md5sum ] || rm -f md5sum
504 UNPACKED_SIZE=$(du -hs . | awk '{ print $1 }')
505 # Build cpio archives. Find, cpio and gzip the fs, finish by
506 # removing the fs tree.
507 echo -n "Compressing the fs... "
508 find fs -print | cpio -o -H newc | gzip > fs.cpio.gz && rm -rf fs
509 PACKED_SIZE=$(du -hs . | awk '{ print $1 }')
510 echo -n "Undating receipt sizes..."
511 sed -i s/^PACKED_SIZE.*$// receipt
512 sed -i s/^UNPACKED_SIZE.*$// receipt
513 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
514 status
515 if [ -n "$EXTRAVERSION" ]; then
516 echo -n "Undating receipt EXTRAVERSION..."
517 sed -i s/^EXTRAVERSION.*$// receipt
518 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
519 status
520 fi
521 echo -n "Creating full cpio archive... "
522 find . -print | cpio -o -H newc > $PACKAGES_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
523 # Restore package tree incase we want to browse it.
524 echo -n "Restoring original package tree... "
525 zcat fs.cpio.gz | cpio -id
526 rm fs.cpio.gz && cd ..
527 # Log process.
528 echo "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg (done)" >> $LOG
529 echo "================================================================================"
530 echo "Package $PACKAGE ($VERSION$EXTRAVERSION) generated."
531 echo "Size : `du -sh $PACKAGES_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
532 echo ""
533 }
535 # Optional text packages list for gen-list.
536 gen_textlist()
537 {
538 rm -f packages.desc
539 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
540 echo -n "Creating the text packages list... "
541 cat >> packages.txt << _EOT_
542 # SliTaz GNU/Linux - Packages list
543 #
544 # Packages : _packages_
545 # Date : $DATE
546 #
547 _EOT_
548 for pkg in $WOK/*
549 do
550 PACKAGE=""
551 PACKED_SIZE=""
552 if [ -f $pkg/taz/*/receipt ]; then
553 . $pkg/taz/*/receipt
554 else
555 . $pkg/receipt
556 fi
557 cat >> packages.txt << _EOT_
559 $PACKAGE
560 $VERSION
561 $SHORT_DESC
562 _EOT_
563 if [ -n "$PACKED_SIZE" ]; then
564 cat >> packages.txt << _EOT_
565 $PACKED_SIZE ($UNPACKED_SIZE installed)
566 _EOT_
567 fi
568 # packages.desc is used by Tazpkgbox <tree>.
569 echo "$PACKAGE | $VERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> packages.desc
570 packages=$(($packages+1))
571 done && status
572 echo -n "Creating the text files list... "
573 for pkg in $WOK/*
574 do
575 if [ -f $pkg/taz/*/files.list ]; then
576 . $pkg/taz/*/receipt
577 ( echo "$PACKAGE"; cat $pkg/taz/*/files.list ) | awk '
578 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }'
579 else
580 echo "No files_list in $pkg" 1>&2
581 fi
582 done | lzma e files.list.lzma -si && status
583 sed -i s/"_packages_"/"$packages"/ packages.txt
584 }
586 ###################
587 # Tazwok commands #
588 ###################
590 case "$COMMAND" in
591 stats)
592 # Tazwok general statistics from the config file the wok.
593 #
594 echo ""
595 echo -e "\033[1mTazwok configuration statistics\033[0m
596 ================================================================================
597 Wok directory : $WOK
598 Packages repository : $PACKAGES_REPOSITORY
599 Sources repository : $SOURCES_REPOSITORY
600 Packages in the wok : `ls -1 $WOK | wc -l`
601 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
602 ================================================================================"
603 echo ""
604 ;;
605 check)
606 # Check wok consistancy
607 echo ""
608 echo -e "\033[1mWok and packages checking\033[0m
609 ================================================================================"
610 cd $WOK
611 for pkg in $(ls)
612 do
613 [ -f $pkg/receipt ] || continue
614 PACKAGE=""
615 VERSION=""
616 CATEGORY=""
617 SHORT_DESC=""
618 MAINTAINER=""
619 WEB_SITE=""
620 DEPENDS=""
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 with maintaining
648 # a mirror.
649 echo ""
650 echo -e "\033[1mWok and packages comparison\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 available in the wok.\n"
726 fi
727 ;;
728 info)
729 # Information about a package.
730 #
731 check_for_package_on_cmdline
732 check_for_receipt
733 . $WOK/$PACKAGE/receipt
734 echo ""
735 echo -e "\033[1mTazwok package information\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 cooked.\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 exists.
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, they will soon be rebuilt.
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 # Generate 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 create a few directories and generate an 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 exists.\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 unknown commands.
1057 usage
1058 ;;
1059 esac
1061 exit 0