tazwok view tazwok @ rev 84

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