tazwok view tazwok @ rev 76

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