tazwok view tazwok @ rev 90

tazwok cmp: fix Old package for computed VERSION
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Aug 31 09:22:46 2008 +0000 (2008-08-31)
parents 9fe330525700
children a1ce8666445b
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 *Z) tar xZf $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 exists, to configure and
329 # make the package if it exists.
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 paths,
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 cases, locales 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 added through
371 # genpkg_rules and generic copy can be disabled 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 homemade 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 # Homemade 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 # Create 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 # May compute VERSION
429 if grep -q ^get_version $RECEIPT; then
430 get_version
431 fi
432 check_for_wanted
433 cd $WOK/$PACKAGE
434 # Remove old Tazwok package files.
435 if [ -d "taz" ]; then
436 rm -rf taz
437 fi
438 # Create the package tree and set useful variables.
439 mkdir -p taz/$PACKAGE-$VERSION/fs
440 fs=taz/$PACKAGE-$VERSION/fs
441 # Set $src for standard package and $_pkg variables.
442 if [ "$WANTED" = "" ]; then
443 src=$WOK/$PACKAGE/$PACKAGE-$VERSION
444 _pkg=$src/_pkg
445 fi
446 if [ ! "$SOURCE" = "" ]; then
447 src=$WOK/$PACKAGE/$SOURCE-$VERSION
448 _pkg=$src/_pkg
449 fi
450 cd $WOK/$PACKAGE
451 # Execute genpkg_rules and copy generic files to build the package.
452 echo ""
453 echo "Building $PACKAGE with the receipt..."
454 echo "================================================================================"
455 if grep -q ^genpkg_rules $RECEIPT; then
456 # Log process.
457 echo "executing genpkg_rules" >> $LOG
458 genpkg_rules
459 cd $WOK/$PACKAGE
460 # Skip generic files for packages with a WANTED variable
461 # (dev and splited pkgs).
462 if [ ! "$WANTED" = "" ]; then
463 continue
464 else
465 copy_generic_files
466 fi
467 strip_package
468 else
469 echo "No package rules to gen $PACKAGE..."
470 exit 1
471 fi
472 # Copy the receipt and description (if exists) in the binary package tree.
473 cd $WOK/$PACKAGE
474 echo -n "Copying the receipt..."
475 cp receipt taz/$PACKAGE-$VERSION
476 status
477 if grep -q ^get_version $RECEIPT; then
478 echo -n "Update version in receipt..."
479 sed -i "s/^VERSION=.*/VERSION=\"$VERSION\"/" \
480 taz/$PACKAGE-$VERSION/receipt
481 status
482 fi
483 if [ -f "description.txt" ]; then
484 echo -n "Copying the description file..."
485 cp description.txt taz/$PACKAGE-$VERSION
486 status
487 fi
488 # Create the files.list by redirecting find output.
489 echo -n "Creating the list of files..."
490 cd taz/$PACKAGE-$VERSION
491 LAST_FILE=""
492 ( find fs -print; echo ) | while read file; do
493 if [ "$LAST_FILE" != "" ]; then
494 case "$file" in
495 $LAST_FILE/*)
496 case "$(ls -ld "$LAST_FILE")" in
497 drwxr-xr-x\ *\ root\ *\ root\ *);;
498 *) echo ${LAST_FILE#fs};;
499 esac;;
500 *) echo ${LAST_FILE#fs};;
501 esac
502 fi
503 LAST_FILE="$file"
504 done > files.list
505 status
506 if [ -z "$EXTRAVERSION" ]; then
507 case "$PACKAGE" in
508 linux*);;
509 *) EXTRAVERSION="$(grep '/lib/modules/.*-slitaz/' files.list |\
510 head -1 | sed 's|/lib/modules/\(.*\)-slitaz/.*|_\1|')";;
511 esac
512 fi
513 rm -f $PACKAGES_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg 2> /dev/null
514 echo -n "Creating md5sum of files..."
515 while read file; do
516 [ -L "fs$file" ] && continue
517 [ -f "fs$file" ] || continue
518 md5sum "fs$file" | sed 's/ fs/ /'
519 done < files.list > md5sum
520 status
521 [ -s md5sum ] || rm -f md5sum
522 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
523 2> /dev/null | awk '{ sz=$1 } END { print sz }')
524 # Build cpio archives. Find, cpio and gzip the fs, finish by
525 # removing the fs tree.
526 echo -n "Compressing the fs... "
527 find fs -print | cpio -o -H newc | gzip > fs.cpio.gz && rm -rf fs
528 PACKED_SIZE=$(du -chs fs.cpio.gz receipt files.list md5sum \
529 description.txt 2> /dev/null | awk '{ sz=$1 } END { print sz }')
530 echo -n "Undating receipt sizes..."
531 sed -i s/^PACKED_SIZE.*$// receipt
532 sed -i s/^UNPACKED_SIZE.*$// receipt
533 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
534 sed -i "s/^VERSION=$/VERSION=\"$VERSION\"/" receipt
535 status
536 if [ -n "$EXTRAVERSION" ]; then
537 echo -n "Undating receipt EXTRAVERSION..."
538 sed -i s/^EXTRAVERSION.*$// receipt
539 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
540 status
541 fi
542 echo -n "Creating full cpio archive... "
543 find . -print | cpio -o -H newc > $PACKAGES_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
544 # Restore package tree incase we want to browse it.
545 echo -n "Restoring original package tree... "
546 zcat fs.cpio.gz | cpio -id
547 rm fs.cpio.gz && cd ..
548 # Log process.
549 echo "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg (done)" >> $LOG
550 echo "================================================================================"
551 echo "Package $PACKAGE ($VERSION$EXTRAVERSION) generated."
552 echo "Size : `du -sh $PACKAGES_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
553 echo ""
554 }
556 # Optional text packages list for gen-list.
557 gen_textlist()
558 {
559 rm -f packages.desc
560 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
561 echo -n "Creating the text packages list... "
562 cat >> packages.txt << _EOT_
563 # SliTaz GNU/Linux - Packages list
564 #
565 # Packages : _packages_
566 # Date : $DATE
567 #
568 _EOT_
569 for pkg in $WOK/*
570 do
571 PACKAGE=""
572 PACKED_SIZE=""
573 if [ -f $pkg/taz/*/receipt ]; then
574 . $pkg/taz/*/receipt
575 else
576 . $pkg/receipt
577 fi
578 cat >> packages.txt << _EOT_
580 $PACKAGE
581 $VERSION
582 $SHORT_DESC
583 _EOT_
584 if [ -n "$PACKED_SIZE" ]; then
585 cat >> packages.txt << _EOT_
586 $PACKED_SIZE ($UNPACKED_SIZE installed)
587 _EOT_
588 fi
589 # packages.desc is used by Tazpkgbox <tree>.
590 echo "$PACKAGE | $VERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> packages.desc
591 packages=$(($packages+1))
592 done && status
593 echo -n "Creating the text files list... "
594 for pkg in $WOK/*
595 do
596 if [ -f $pkg/taz/*/files.list ]; then
597 . $pkg/taz/*/receipt
598 ( echo "$PACKAGE"; cat $pkg/taz/*/files.list ) | awk '
599 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }'
600 else
601 echo "No files_list in $pkg" 1>&2
602 fi
603 done | lzma e files.list.lzma -si && status
604 sed -i s/"_packages_"/"$packages"/ packages.txt
605 }
607 ###################
608 # Tazwok commands #
609 ###################
611 case "$COMMAND" in
612 stats)
613 # Tazwok general statistics from the config file the wok.
614 #
615 echo ""
616 echo -e "\033[1mTazwok configuration statistics\033[0m
617 ================================================================================
618 Wok directory : $WOK
619 Packages repository : $PACKAGES_REPOSITORY
620 Sources repository : $SOURCES_REPOSITORY
621 Packages in the wok : `ls -1 $WOK | wc -l`
622 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
623 ================================================================================"
624 echo ""
625 ;;
626 check)
627 # Check wok consistancy
628 echo ""
629 echo -e "\033[1mWok and packages checking\033[0m
630 ================================================================================"
631 cd $WOK
632 for pkg in $(ls)
633 do
634 [ -f $pkg/receipt ] || continue
635 PACKAGE=""
636 VERSION=""
637 CATEGORY=""
638 SHORT_DESC=""
639 MAINTAINER=""
640 WEB_SITE=""
641 DEPENDS=""
642 . $pkg/receipt
643 [ "$PACKAGE" = "$pkg" ] || echo "Package $PACKAGE should be $pkg"
644 [ -n "$VERSION" ] || echo "Package $PACKAGE has no VERSION"
645 [ -n "$CATEGORY" ] || echo "Package $PACKAGE has no CATEGORY"
646 [ -n "$SHORT_DESC" ] || echo "Package $PACKAGE has no SHORT_DESC"
647 [ -n "$MAINTAINER" ] || echo "Package $PACKAGE has no MAINTAINER"
648 [ -n "$WEB_SITE" ] || echo "Package $PACKAGE has no WEB_SITE"
649 case "$MAINTAINER" in
650 *\<*|*\>*) echo "Package $PACKAGE has an invalid MAINTAINER: $MAINTAINER";;
651 esac
652 case "$MAINTAINER" in
653 *@*);;
654 *) echo "Package $PACKAGE MAINTAINER is not an email address";;
655 esac
656 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n"
657 for i in $DEPENDS; do
658 [ -d $i ] && continue
659 echo -e "$MSG $i"
660 MSG=""
661 done
662 MSG="Dependencies loop between $PACKAGE and :\n"
663 ALL_DEPS=""
664 check_for_deps_loop $PACKAGE $DEPENDS
665 done
666 ;;
667 cmp|compare)
668 # Compare the wok and packages repository to help with maintaining
669 # a mirror.
670 echo ""
671 echo -e "\033[1mWok and packages comparison\033[0m
672 ================================================================================"
673 for pkg in $WOK/*
674 do
675 . $pkg/receipt
676 echo "$PACKAGE-$VERSION.tazpkg" >> /tmp/wok.list
677 if [ -z "$(ls $PACKAGES_REPOSITORY/$PACKAGE-$VERSION*.tazpkg 2> /dev/null)" ]; then
678 echo "Missing package: $PACKAGE ($VERSION)"
679 echo "$PACKAGE" >> /tmp/pkgs.missing
680 fi
681 done
682 for pkg in `cd $PACKAGES_REPOSITORY && ls *.tazpkg`
683 do
684 # grep $pkg in /tmp/wok.list
685 # may include EXTRAVERSION or computed VERSION
686 for i in $(grep ^${pkg%-*} /tmp/wok.list); do
687 case "$pkg" in
688 ${i%.tazpkg}*.tazpkg) continue 2;;
689 esac
690 done
691 # Not found
692 echo $pkg >> /tmp/pkgs.old
693 if [ "$2" = "--remove" ]; then
694 echo "Removing package: $pkg"
695 rm $PACKAGES_REPOSITORY/$pkg
696 else
697 echo "Old package: $pkg"
698 fi
699 done
700 cd /tmp
701 echo "================================================================================"
702 echo "Wok: `cat wok.list | wc -l` - \
703 Cooked: `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l` - \
704 Missing: `cat pkgs.missing 2>/dev/null | wc -l` - \
705 Old: `cat pkgs.old 2>/dev/null | wc -l`"
706 echo ""
707 rm -f wok.list pkgs.old pkgs.missing
708 ;;
709 list)
710 # List packages in wok directory. User can specifiy a category
711 #
712 if [ "$2" = "category" ]; then
713 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
714 exit 0
715 fi
716 # Check for an asked category.
717 if [ -n "$2" ]; then
718 ASKED_CATEGORY=$2
719 echo ""
720 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
721 echo "================================================================================"
722 for pkg in $WOK/*
723 do
724 . $pkg/receipt
725 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
726 echo -n "$PACKAGE"
727 echo -e "\033[28G $VERSION"
728 packages=$(($packages+1))
729 fi
730 done
731 echo "================================================================================"
732 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
733 else
734 # By default list all packages and version.
735 echo ""
736 echo -e "\033[1mList of packages in the wok\033[0m"
737 echo "================================================================================"
738 for pkg in $WOK/*
739 do
740 . $pkg/receipt
741 echo -n "$PACKAGE"
742 echo -en "\033[28G $VERSION"
743 echo -e "\033[42G $CATEGORY"
744 packages=$(($packages+1))
745 done
746 echo "================================================================================"
747 echo -e "$packages packages available in the wok.\n"
748 fi
749 ;;
750 info)
751 # Information about a package.
752 #
753 check_for_package_on_cmdline
754 check_for_receipt
755 . $WOK/$PACKAGE/receipt
756 echo ""
757 echo -e "\033[1mTazwok package information\033[0m
758 ================================================================================
759 Package : $PACKAGE
760 Version : $VERSION
761 Category : $CATEGORY
762 Short desc : $SHORT_DESC
763 Maintainer : $MAINTAINER"
764 if [ ! "$WEB_SITE" = "" ]; then
765 echo "Web site : $WEB_SITE"
766 fi
767 if [ ! "$DEPENDS" = "" ]; then
768 echo "Depends : $DEPENDS"
769 fi
770 if [ ! "$WANTED" = "" ]; then
771 echo "Wanted src : $WANTED"
772 fi
773 echo "================================================================================"
774 echo ""
776 ;;
777 check-log)
778 # We just cat the file log to view process info.
779 #
780 if [ ! -f "$LOG" ]; then
781 echo -e "\nNo process log found. The package is probably not cooked.\n"
782 exit 0
783 else
784 echo ""
785 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
786 echo "================================================================================"
787 cat $LOG
788 echo "================================================================================"
789 echo ""
790 fi
791 ;;
792 search)
793 # Search for a package by pattern or name.
794 #
795 if [ -z "$2" ]; then
796 echo -e "\nPlease specify a pattern or a package name to search."
797 echo -e "Example : 'tazwok search gcc'.\n"
798 exit 0
799 fi
800 echo ""
801 echo -e "\033[1mSearch result for :\033[0m $2"
802 echo "================================================================================"
803 list=`ls -1 $WOK | grep $2`
804 for pkg in $list
805 do
806 . $WOK/$pkg/receipt
807 echo -n "$PACKAGE "
808 echo -en "\033[24G $VERSION"
809 echo -e "\033[42G $CATEGORY"
810 packages=$(($packages+1))
811 done
812 echo "================================================================================"
813 echo "$packages packages found for : $2"
814 echo ""
815 ;;
816 compile)
817 # Configure and make a package with the receipt.
818 #
819 compile_package
820 ;;
821 genpkg)
822 # Generate a package
823 #
824 gen_package
825 ;;
826 cook)
827 # Compile and generate a package. Just execute tazwok with
828 # the good commands.
829 #
830 check_root
831 compile_package
832 gen_package
833 ;;
834 cook-list)
835 # Cook all packages listed in a file. The path to the cooklist must
836 # be specified on the cmdline.
837 #
838 check_root
839 check_for_list
840 for pkg in $LIST
841 do
842 tazwok compile $pkg
843 tazwok genpkg $pkg
844 done
845 ;;
846 clean)
847 # Clean up a package work directory.
848 #
849 check_for_package_on_cmdline
850 check_for_receipt
851 . $RECEIPT
852 cd $WOK/$PACKAGE
853 echo ""
854 echo "Cleaning $PACKAGE..."
855 echo "================================================================================"
856 # Check for clean_wok function.
857 if grep -q ^clean_wok $RECEIPT; then
858 clean_wok
859 fi
860 # Remove taz/ and source tree if exists.
861 if [ -d "taz" ]; then
862 echo -n "Removing taz files..."
863 rm -rf taz && status
864 fi
865 if [ -d "$PACKAGE-$VERSION" ]; then
866 echo -n "Removing source files..."
867 rm -rf $PACKAGE-$VERSION && status
868 fi
869 if [ -d "$SOURCE-$VERSION" ]; then
870 echo -n "Removing source files..."
871 rm -rf $SOURCE-$VERSION && status
872 fi
873 # Remove an envental $PACKAGE-build directory.
874 if [ -d "$PACKAGE-build" ]; then
875 echo -n "Removing build tree..."
876 rm -rf $PACKAGE-build && status
877 fi
878 # Remove process log file.
879 if [ -f "process.log" ]; then
880 echo -n "Removing process log file..."
881 rm process.log && status
882 echo "================================================================================"
883 fi
884 echo "$PACKAGE is clean. You can cook it again..."
885 echo ""
886 ;;
887 gen-clean-wok)
888 # Generate a clean wok from the current wok by copying all receipt
889 # and stuff directory.
890 #
891 if [ -z "$2" ]; then
892 echo -e "\nPlease specify the destination for the new clean wok.\n"
893 exit 0
894 else
895 dest=$2
896 mkdir -p $dest
897 fi
898 echo "New wok is going to : $dest"
899 for pkg in `ls -1 $WOK`
900 do
901 echo "----"
902 echo -n "Preparing $pkg..."
903 mkdir -p $dest/$pkg
904 status
905 echo -n "Copying the receipt..."
906 cp -a $WOK/$pkg/receipt $dest/$pkg
907 status
908 if [ -d "$WOK/$pkg/stuff" ]; then
909 echo -n "Copying all the stuff directory..."
910 cp -a $WOK/$pkg/stuff $dest/$pkg
911 status
912 fi
913 done
914 echo "================================================================================"
915 echo "Clean wok generated in : $dest"
916 echo "Packages cleaned : `ls -1 $dest | wc -l`"
917 echo ""
918 ;;
919 clean-wok)
920 # Clean all packages in the work directory
921 #
922 for pkg in `ls -1 $WOK`
923 do
924 tazwok clean $pkg
925 done
926 echo "================================================================================"
927 echo "`ls -1 $WOK | wc -l` packages cleaned."
928 echo ""
929 ;;
930 gen-list)
931 # Sed is used to remove all the .tazpkg extensions from the
932 # packages.list. The directory to move in by default is the repository
933 # if $2 is not empty cd into $2. A text packages list can also be gen
934 # with the option --text.
935 #
936 if [ "$2" == "--text" ]; then
937 textlist="yes"
938 elif [ -z "$2" ]; then
939 PACKAGES_REPOSITORY=$PACKAGES_REPOSITORY
940 else
941 if [ -d "$2" ]; then
942 PACKAGES_REPOSITORY=$2
943 else
944 echo -e "\nUnable to find directory : $2\n"
945 exit 0
946 fi
947 fi
948 cd $PACKAGES_REPOSITORY
949 # Remove old packages.list and md5sum, they will soon be rebuilt.
950 rm -f packages.list packages.md5 packages.txt
951 echo ""
952 echo -e "\033[1mGenerating packages lists\033[0m"
953 echo "================================================================================"
954 echo -n "Repository path : $PACKAGES_REPOSITORY" && status
955 # Generate packages.txt
956 if [ "$textlist" == "yes" ]; then
957 gen_textlist
958 fi
959 echo -n "Creating the raw packages list... "
960 ls -1 *.tazpkg > /tmp/packages.list
961 sed -i s/'.tazpkg'/''/ /tmp/packages.list
962 status
963 echo -n "Building the md5sum for all packages... "
964 md5sum * > packages.md5
965 status
966 mv /tmp/packages.list $PACKAGES_REPOSITORY
967 echo "================================================================================"
968 pkgs=`cat $PACKAGES_REPOSITORY/packages.list | wc -l`
969 echo "$pkgs packages in the repository."
970 echo ""
971 ;;
972 new-tree)
973 # Just create a few directories and generate an empty receipt to prepare
974 # the creation of a new package.
975 #
976 check_for_package_on_cmdline
977 if [ -d $WOK/$PACKAGE ]; then
978 echo -e "\n$PACKAGE package tree already exists.\n"
979 exit 0
980 fi
981 echo "Creating : $WOK/$PACKAGE"
982 mkdir $WOK/$PACKAGE
983 cd $WOK/$PACKAGE
984 echo -n "Preparing the receipt..."
985 #
986 # Default receipt begin.
987 #
988 echo "# SliTaz package receipt." > receipt
989 echo "" >> receipt
990 echo "PACKAGE=\"$PACKAGE\"" >> receipt
991 # Finish the empty receipt.
992 cat >> receipt << "EOF"
993 VERSION=""
994 CATEGORY=""
995 SHORT_DESC=""
996 MAINTAINER=""
997 DEPENDS=""
998 TARBALL="$PACKAGE-$VERSION.tar.gz"
999 WEB_SITE=""
1000 WGET_URL=""
1002 # Rules to configure and make the package.
1003 compile_rules()
1005 cd $src
1006 ./configure --prefix=/usr --infodir=/usr/share/info \
1007 --mandir=/usr/share/man $CONFIGURE_ARGS && \
1008 make && make DESTDIR=$PWD/_pkg install
1011 # Rules to gen a SliTaz package suitable for Tazpkg.
1012 genpkg_rules()
1014 mkdir -p $fs/usr
1015 cp -a $_pkg/usr/bin $fs/usr
1018 EOF
1020 # Default receipt end.
1022 status
1023 # Interactive mode, asking and seding.
1024 if [ "$3" = "--interactive" ]; then
1025 echo "Entering in interactive mode..."
1026 echo "================================================================================"
1027 echo "Package : $PACKAGE"
1028 # Version.
1029 echo -n "Version : " ; read anser
1030 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
1031 # Category.
1032 echo -n "Category : " ; read anser
1033 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
1034 # Short description.
1035 echo -n "Short desc : " ; read anser
1036 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
1037 # Maintainer.
1038 echo -n "Maintainer : " ; read anser
1039 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
1040 # Web site.
1041 echo -n "Web site : " ; read anser
1042 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
1043 echo ""
1044 # Wget URL.
1045 echo "Wget URL to download source tarball."
1046 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
1047 echo -n "Wget url : " ; read anser
1048 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
1049 # Ask for a stuff dir.
1050 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
1051 if [ "$anser" = "y" ]; then
1052 echo -n "Creating the stuff directory..."
1053 mkdir stuff && status
1054 fi
1055 # Ask for a description file.
1056 echo -n "Are you going to write a description ? (y/N) : " ; read anser
1057 if [ "$anser" = "y" ]; then
1058 echo -n "Creating the description.txt file..."
1059 echo "" > description.txt && status
1060 fi
1061 echo "================================================================================"
1062 echo ""
1063 fi
1064 ;;
1065 remove)
1066 # Remove a package from the wok.
1068 check_for_package_on_cmdline
1069 echo ""
1070 echo -n "Please confirm deletion (y/N) : "; read anser
1071 if [ "$anser" = "y" ]; then
1072 echo -n "Removing $PACKAGE..."
1073 rm -rf $WOK/$PACKAGE && status
1074 echo ""
1075 fi
1076 ;;
1077 usage|*)
1078 # Print usage also for all unknown commands.
1080 usage
1081 ;;
1082 esac
1084 exit 0