tazwok view tazwok @ rev 151

tazwok: no continue outside loops
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Sep 23 16:59:18 2009 +0200 (2009-09-23)
parents 6f7455cdc772
children 1ce23075b63f
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-2009 SliTaz - GNU General Public License.
10 #
11 VERSION=3.0
13 ####################
14 # Tazwok variables #
15 ####################
17 # Packages categories
18 #
19 # We may move this to a centralized config for Tazwok, Tazpkg and Tazbb.
20 # /var/lib/tazpkg/categories ?
21 #
22 CATEGORIES="
23 base-system
24 x-window
25 utilities
26 network
27 graphics
28 multimedia
29 office
30 development
31 system-tools
32 security
33 games
34 misc
35 meta
36 non-free"
38 # Use words rather than numbers in the code.
39 COMMAND=$1
40 PACKAGE=$2
41 LIST=$2
43 LOCALSTATE=/var/lib/tazpkg
44 INSTALLED=$LOCALSTATE/installed
46 # Include config file or exit if no file found.
47 if [ -f "./tazwok.conf" ]; then
48 . ./tazwok.conf
49 elif [ -f "/etc/tazwok.conf" ]; then
50 . /etc/tazwok.conf
51 else
52 echo -e "\nUnable to find the configuration file : /etc/tazwok.conf"
53 echo -e "Please read the Tazwok documentation.\n"
54 exit 0
55 fi
57 # Create Taz wok needed directories if user is root.
58 if test $(id -u) = 0 ; then
59 # Check for the wok directory.
60 if [ ! -d "$WOK" ]; then
61 echo "Creating the wok directory..."
62 mkdir -p $WOK
63 chmod 777 $WOK
64 fi
65 # Check for the packages repository.
66 if [ ! -d "$PACKAGES_REPOSITORY" ]; then
67 echo "Creating the packages repository..."
68 mkdir -p $PACKAGES_REPOSITORY
69 fi
70 # Check for the sources repository.
71 if [ ! -d "$SOURCES_REPOSITORY" ]; then
72 echo "Creating the sources repository..."
73 mkdir -p $SOURCES_REPOSITORY
74 fi
75 fi
77 # The path to the most important file used by Tazwok.
78 # The receipt is used to compile the source code and
79 # generate suitable packages for Tazpkg.
80 RECEIPT="$WOK/$PACKAGE/receipt"
82 # The path to the process log file.
83 LOG="$WOK/$PACKAGE/process.log"
85 ####################
86 # Tazwok functions #
87 ####################
89 # Print the usage (English).
90 usage ()
91 {
92 echo -e "\nSliTaz sources compiler and packages generator - Version: $VERSION\n
93 \033[1mUsage: \033[0m `basename $0` [command] [package|list|category|dir|id] [--option]
94 \033[1mCommands: \033[0m\n
95 usage Print this short usage.
96 stats Print Tazwok statistics from the config file and the wok.
97 edit Edit a package receipt in the current wok.
98 build-depends Generate a list of packages to build a wok.
99 cmp|compare Compare the wok and the cooked pkgs (--remove old pkgs).
100 list List all packages in the wok tree or by category.
101 info Get information about a package in the wok.
102 check Check every receipt for common errors.
103 check-log Check the process log file of a package.
104 check-depends Check every receipt for DEPENDS - doesn't scan ELF files.
105 search Search for a package in the wok by pattern or name.
106 compile Configure and build a package using the receipt rules.
107 genpkg Generate a suitable package for Tazpkg with the rules.
108 cook Compile and generate a package directly.
109 cook-list Cook all packages specified in the list by order.
110 clean Clean all generated files in the package tree.
111 new-tree Prepare a new package tree and receipt (--interactive).
112 gen-list Generate a packages list for a repository (--text).
113 gen-clean-wok Gen a clean wok in a dir ('clean-wok' cleans current wok).
114 remove Remove a package from the wok.
115 hgup Pull and update a wok under Hg.
116 maintainers List all maintainers in the wok.
117 maintained-by List packages maintained by a contributor.\n"
118 }
120 # Status function.
121 status()
122 {
123 local CHECK=$?
124 echo -en "\\033[70G[ "
125 if [ $CHECK = 0 ]; then
126 echo -en "\\033[1;33mOK"
127 else
128 echo -en "\\033[1;31mFailed"
129 fi
130 echo -e "\\033[0;39m ]"
131 }
133 # Check if user is root.
134 check_root()
135 {
136 if test $(id -u) != 0 ; then
137 echo -e "\nYou must be root to run `basename $0` with this option."
138 echo -e "Please type 'su' and root password to become super-user.\n"
139 exit 0
140 fi
141 }
143 # Check for a package name on cmdline.
144 check_for_package_on_cmdline()
145 {
146 if [ -z "$PACKAGE" ]; then
147 echo -e "\nYou must specify a package name on the command line."
148 echo -e "Example : tazwok $COMMAND package\n"
149 exit 0
150 fi
151 }
153 # Check for the receipt of a package used to cook.
154 check_for_receipt()
155 {
156 if [ ! -f "$RECEIPT" ]; then
157 echo -e "\nUnable to find the receipt : $RECEIPT\n"
158 exit 0
159 fi
160 }
162 # Check for a specified file list on cmdline.
163 check_for_list()
164 {
165 if [ -z "$LIST" ]; then
166 echo -e "\nPlease specify the path to the list of packages to cook.\n"
167 exit 0
168 fi
169 # Check if the list of packages exists.
170 if [ -f "$LIST" ]; then
171 LIST=`cat $LIST`
172 else
173 echo -e "\nUnable to find $LIST packages list.\n"
174 exit 0
175 fi
176 }
178 # Check for the wanted package if specified in WANTED
179 # receipt variable. Set the $src/$_pkg variable to help compiling
180 # and generating packages.
181 check_for_wanted()
182 {
183 if [ ! "$WANTED" = "" ]; then
184 echo -n "Checking for the wanted package..."
185 if [ ! -d "$WOK/$WANTED" ]; then
186 echo -e "\nWanted package is missing in the work directory.\n"
187 exit 0
188 fi
189 # Checking for buildtree of Wanted package
190 if [ ! -d "$WOK/$WANTED/taz" ]; then
191 echo -e "\n\nSource files of wanted package is missing in the work directory."
192 echo -n "Would you like to build the missing package (y/N) ? " ; read anser
193 if [ "$anser" == "y" ]; then
194 tazwok cook $WANTED
195 else
196 echo -e "\nWanted package source tree is missing in the work directory.\n"
197 exit 0
198 fi
199 fi
200 status
201 # Set wanted src path.
202 src=$WOK/$WANTED/$WANTED-$VERSION
203 _pkg=$src/_pkg
204 fi
205 }
208 # Check for build dependencies, notify user and install if specified.
209 check_for_build_depends()
210 {
211 echo "Checking for build dependencies..."
212 for pkg in $BUILD_DEPENDS
213 do
214 if [ ! -d "$INSTALLED/$pkg" ]; then
215 MISSING_PACKAGE=$pkg
216 fi
217 done
218 if [ ! "$MISSING_PACKAGE" = "" ]; then
219 echo "================================================================================"
220 for pkg in $BUILD_DEPENDS
221 do
222 if [ ! -d "$INSTALLED/$pkg" ]; then
223 MISSING_PACKAGE=$pkg
224 echo "Missing : $pkg"
225 fi
226 done
227 echo "================================================================================"
228 echo "You can continue, exit or install missing dependencies."
229 echo -n "Install, continue or exit (install/y/N) ? "; read anser
230 case $anser in
231 install)
232 for pkg in $BUILD_DEPENDS
233 do
234 if [ ! -d "$INSTALLED/$pkg" ]; then
235 tazpkg get-install $pkg
236 fi
237 done ;;
238 y|yes)
239 ;;
240 *)
241 exit 0 ;;
242 esac
243 fi
244 }
246 # Check for loop in deps tree.
247 check_for_deps_loop()
248 {
249 local list
250 local pkg
251 local deps
252 pkg=$1
253 shift
254 [ -n "$1" ] || return
255 list=""
256 # Filter out already processed deps
257 for i in $@; do
258 case " $ALL_DEPS" in
259 *\ $i\ *);;
260 *) list="$list $i";;
261 esac
262 done
263 ALL_DEPS="$ALL_DEPS$list "
264 for i in $list; do
265 [ -f $i/receipt ] || continue
266 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
267 case " $deps " in
268 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
269 *) check_for_deps_loop $pkg $deps;;
270 esac
271 done
272 }
274 download()
275 {
276 for file in $@; do
277 wget $file && break
278 done
279 }
281 # Configure and make a package with the receipt.
282 compile_package()
283 {
284 check_for_package_on_cmdline
285 # Include the receipt to get all needed variables and functions
286 # and cd into the work directory to start the work.
287 check_for_receipt
288 . $RECEIPT
289 # Log the package name and date.
290 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
291 echo "package $PACKAGE (compile)" >> $LOG
292 # Set wanted $src variable to help compiling.
293 if [ ! "$SOURCE" = "" ]; then
294 src=$WOK/$PACKAGE/$SOURCE-$VERSION
295 else
296 src=$WOK/$PACKAGE/$PACKAGE-$VERSION
297 fi
298 check_for_build_depends
299 check_for_wanted
300 echo ""
301 echo "Starting to cook $PACKAGE..."
302 echo "================================================================================"
303 # Check for src tarball and wget if needed.
304 if [ ! "$WGET_URL" = "" ]; then
305 echo "Checking for source tarball... "
306 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
307 cd $SOURCES_REPOSITORY
308 download $WGET_URL
309 #wget $WGET_URL
310 # Exit if download failed to avoid errors.
311 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
312 echo -e "\nDownload failed, exiting. Please check WGET_URL variable.\n"
313 exit 1
314 fi
315 else
316 echo -n "Source tarball exit... "
317 status
318 fi
319 # Untaring source if necessary. We don't need to extract source if
320 # the package is built with a wanted source package.
321 if [ "$WANTED" = "" ]; then
322 if [ ! -d $src ]; then
323 # Log process.
324 echo "untaring $TARBALL" >> $LOG
325 echo -n "Untaring $TARBALL... "
326 case "$TARBALL" in
327 *zip|*xpi) ( cd $WOK/$PACKAGE; unzip -o $SOURCES_REPOSITORY/$TARBALL );;
328 *bz2) tar xjf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
329 *tar) tar xf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
330 *Z) tar xZf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
331 *) tar xzf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
332 esac
333 status
334 # Permissions settings
335 chown -R root.root $WOK/$PACKAGE/$PACKAGE-* 2>/dev/null
336 chown -R root.root $WOK/$PACKAGE/$SOURCE-* 2>/dev/null
337 else
338 echo -n "Source directory exit... " && status
339 fi
340 fi
341 fi
342 cd $WOK/$PACKAGE
343 # Log and execute compile_rules function if it exists, to configure and
344 # make the package if it exists.
345 if grep -q ^compile_rules $RECEIPT; then
346 echo "executing compile_rules" >> $LOG
347 compile_rules
348 # Exit if compilation failed so the binary package
349 # is not generated when using the cook command.
350 local CHECK=$?
351 if [ $CHECK = 0 ]; then
352 echo "================================================================================"
353 echo "$PACKAGE compiled on : `date +%Y%m%d\ \%H:%M:%S`"
354 echo ""
355 echo "compilation done : `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
357 # Regenerate every package who want PACKAGE compiled
358 # make tazwok genpkg happy
359 mkdir $WOK/$PACKAGE/taz
360 for i in $( grep -l "^WANTED=\"$PACKAGE\"" $WOK/*/receipt) ; do
361 tazwok genpkg $(basename $(dirname $i))
362 done
363 # Still need tazwok genpkg for this package
364 rm -rf $WOK/$PACKAGE/taz
365 else
366 echo "================================================================================"
367 echo "Compilation failed. Please read the compilator output."
368 echo "" && exit 1
369 fi
370 else
371 echo "no compile_rules" >> $LOG
372 echo -e "No compile rules for $PACKAGE...\n"
373 fi
374 }
376 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
377 # so some packages need to copy these files with the receipt and genpkg_rules.
378 # This function is executed by gen_package when 'tazwok genpkg'.
379 copy_generic_files()
380 {
381 # In most cases, locales are in $_pkg/usr/share/locale so we copy files
382 # using generic variables and $LOCALE from Tazwok config file.
383 if [ ! "$LOCALE" = "" ]; then
384 if [ -d "$_pkg/usr/share/locale" ]; then
385 for i in $LOCALE
386 do
387 if [ -d "$_pkg/usr/share/locale/$i" ]; then
388 mkdir -p $fs/usr/share/locale
389 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
390 fi
391 done
392 fi
393 fi
394 # Pixmaps (PNG or/and XPM only). Some icons/images can be added through
395 # genpkg_rules and generic copy can be disabled with GENERIC_PIXMAPS="no"
396 # in pkg receipt.
397 if [ ! "$GENERIC_PIXMAPS" = "no" ]; then
398 if [ -d "$_pkg/usr/share/pixmaps" ]; then
399 mkdir -p $fs/usr/share/pixmaps
400 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
401 $fs/usr/share/pixmaps 2>/dev/null
402 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
403 $fs/usr/share/pixmaps 2>/dev/null
404 fi
405 # Custom or homemade PNG pixmap can be in stuff.
406 if [ -f "stuff/$PACKAGE.png" ]; then
407 mkdir -p $fs/usr/share/pixmaps
408 cp -a stuff/$PACKAGE.png $fs/usr/share/pixmaps
409 fi
410 fi
411 # Desktop entry (.desktop).
412 if [ -d "$_pkg/usr/share/applications" ]; then
413 cp -a $_pkg/usr/share/applications $fs/usr/share
414 fi
415 # Homemade desktop file(s) can be in stuff.
416 if [ -d "stuff/applications" ]; then
417 mkdir -p $fs/usr/share
418 cp -a stuff/applications $fs/usr/share
419 fi
420 if [ -f "stuff/$PACKAGE.desktop" ]; then
421 mkdir -p $fs/usr/share/applications
422 cp -a stuff/$PACKAGE.desktop $fs/usr/share/applications
423 fi
424 }
426 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
427 strip_package()
428 {
429 echo -n "Executing strip on all files..."
430 # Binaries.
431 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
432 do
433 if [ -d "$dir" ]; then
434 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
435 fi
436 done
437 # Libraries.
438 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
439 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
440 status
441 }
443 # Check FSH in a slitaz package (Path: /:/usr)
444 check_fsh()
445 {
446 cd $WOK/$PACKAGE/taz/*/fs
447 [ -n "$FSH" ] || FSH="bin boot dev etc home init lib media mnt proc \
448 root sbin share sys tmp usr var vz usr/bin usr/games usr/include usr/lib \
449 usr/local usr/sbin usr/share usr/src"
450 for i in `ls -d * usr/* 2>/dev/null`
451 do
452 if ! echo $FSH | grep -q $i; then
453 echo "Wrong path: /$i"
454 error=1
455 fi
456 done
457 if [ "$error" = "1" ]; then
458 cat << _EOT_
460 Package will install files in a non standard directory and want be generated.
461 You may have a wrong copy path in genpkg_rules or must add some options to
462 configure in compile_rules. Some valid options for SliTaz (Linux FSH):
464 --prefix=/usr
465 --sysconfdir=/etc
466 --libexecdir=/usr/lib/(pkgname)
467 --localstatedir=/var
468 --mandir=/usr/share/man
469 --infodir=/usr/share/info
471 For more information please read SliTaz doc and run: ./configure --help
472 ================================================================================
473 $PACKAGE package generation aborted.
475 _EOT_
476 # Dont generate a corrupted package.
477 cd $WOK/$PACKAGE && rm -rf taz
478 exit 1
479 fi
480 echo ""
481 }
483 # Create a package tree and build the gziped cpio archive
484 # to make a SliTaz (.tazpkg) package.
485 gen_package()
486 {
487 check_root
488 check_for_package_on_cmdline
489 check_for_receipt
490 EXTRAVERSION=""
491 . $RECEIPT
492 # May compute VERSION
493 if grep -q ^get_version $RECEIPT; then
494 get_version
495 fi
496 check_for_wanted
497 cd $WOK/$PACKAGE
498 # Remove old Tazwok package files.
499 if [ -d "taz" ]; then
500 rm -rf taz
501 fi
502 # Create the package tree and set useful variables.
503 mkdir -p taz/$PACKAGE-$VERSION/fs
504 fs=taz/$PACKAGE-$VERSION/fs
505 # Set $src for standard package and $_pkg variables.
506 if [ "$WANTED" = "" ]; then
507 src=$WOK/$PACKAGE/$PACKAGE-$VERSION
508 _pkg=$src/_pkg
509 fi
510 if [ ! "$SOURCE" = "" ]; then
511 src=$WOK/$PACKAGE/$SOURCE-$VERSION
512 _pkg=$src/_pkg
513 fi
514 cd $WOK/$PACKAGE
515 # Execute genpkg_rules, check package and copy generic files to build
516 # the package.
517 echo ""
518 echo "Building $PACKAGE with the receipt..."
519 echo "================================================================================"
520 if grep -q ^genpkg_rules $RECEIPT; then
521 # Log process.
522 echo "executing genpkg_rules" >> $LOG
523 genpkg_rules
524 check_fsh
525 cd $WOK/$PACKAGE
526 # Skip generic files for packages with a WANTED variable
527 # (dev and splited pkgs).
528 if [ "$WANTED" = "" ]; then
529 copy_generic_files
530 fi
531 strip_package
532 else
533 echo "No package rules to gen $PACKAGE..."
534 exit 1
535 fi
536 # Copy the receipt and description (if exists) in the binary package tree.
537 cd $WOK/$PACKAGE
538 echo -n "Copying the receipt..."
539 cp receipt taz/$PACKAGE-$VERSION
540 status
541 if grep -q ^get_version $RECEIPT; then
542 echo -n "Update version in receipt..."
543 sed -i "s/^VERSION=.*/VERSION=\"$VERSION\"/" \
544 taz/$PACKAGE-$VERSION/receipt
545 status
546 fi
547 if [ -f "description.txt" ]; then
548 echo -n "Copying the description file..."
549 cp description.txt taz/$PACKAGE-$VERSION
550 status
551 fi
552 # Create the files.list by redirecting find output.
553 echo -n "Creating the list of files..."
554 cd taz/$PACKAGE-$VERSION
555 LAST_FILE=""
556 ( find fs -print; echo ) | while read file; do
557 if [ "$LAST_FILE" != "" ]; then
558 case "$file" in
559 $LAST_FILE/*)
560 case "$(ls -ld "$LAST_FILE")" in
561 drwxr-xr-x\ *\ root\ *\ root\ *);;
562 *) echo ${LAST_FILE#fs};;
563 esac;;
564 *) echo ${LAST_FILE#fs};;
565 esac
566 fi
567 LAST_FILE="$file"
568 done > files.list
569 status
570 if [ -z "$EXTRAVERSION" ]; then
571 case "$PACKAGE" in
572 linux*);;
573 *) EXTRAVERSION="$(grep '/lib/modules/.*-slitaz/' files.list |\
574 head -1 | sed 's|/lib/modules/\(.*\)-slitaz/.*|_\1|')";;
575 esac
576 fi
577 rm -f $PACKAGES_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg 2> /dev/null
578 echo -n "Creating md5sum of files..."
579 while read file; do
580 [ -L "fs$file" ] && continue
581 [ -f "fs$file" ] || continue
582 md5sum "fs$file" | sed 's/ fs/ /'
583 done < files.list > md5sum
584 #[ -s md5sum ] || rm -f md5sum
585 status
586 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
587 2> /dev/null | awk '{ sz=$1 } END { print sz }')
588 # Build cpio archives. Find, cpio and gzip the fs, finish by
589 # removing the fs tree.
590 echo -n "Compressing the fs... "
591 find fs -print | cpio -o -H newc | case "$PACKAGE-$COMPRESSION" in
592 tazpkg-lzma) gzip > fs.cpio.gz;;
593 *-lzma) lzma e fs.cpio.lzma -si;;
594 *) gzip > fs.cpio.gz;;
595 esac && rm -rf fs
596 PACKED_SIZE=$(du -chs fs.cpio.* receipt files.list md5sum \
597 description.txt 2> /dev/null | awk '{ sz=$1 } END { print sz }')
598 status
599 echo -n "Updating receipt sizes..."
600 sed -i '/^PACKED_SIZE/d' receipt
601 sed -i '/^UNPACKED_SIZE/d' receipt
602 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
603 sed -i "s/^VERSION=$/VERSION=\"$VERSION\"/" receipt
604 status
605 if [ -n "$EXTRAVERSION" ]; then
606 echo -n "Updating receipt EXTRAVERSION..."
607 sed -i s/^EXTRAVERSION.*$// receipt
608 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
609 status
610 fi
611 echo -n "Creating full cpio archive... "
612 find . -print | cpio -o -H newc > $PACKAGES_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
613 status
614 # Restore package tree incase we want to browse it.
615 echo -n "Restoring original package tree... "
616 ( zcat fs.cpio.gz 2> /dev/null || unlzma -c fs.cpio.lzma ) | cpio -id
617 rm fs.cpio.* && cd ..
618 # Log process.
619 echo "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg (done)" >> $LOG
620 echo "================================================================================"
621 echo "Package $PACKAGE ($VERSION$EXTRAVERSION) generated."
622 echo "Size : `du -sh $PACKAGES_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
623 echo ""
624 }
626 # Optional text packages list for gen-list.
627 gen_textlist()
628 {
629 rm -f packages.desc packages.equiv
630 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
631 echo -n "Creating the text packages list... "
632 cat >> packages.txt << _EOT_
633 # SliTaz GNU/Linux - Packages list
634 #
635 # Packages : _packages_
636 # Date : $DATE
637 #
638 _EOT_
639 for pkg in $WOK/*
640 do
641 PROVIDE=""
642 PACKAGE=""
643 PACKED_SIZE=""
644 if [ -f $pkg/taz/*/receipt ]; then
645 . $pkg/taz/*/receipt
646 else
647 . $pkg/receipt
648 fi
649 cat >> packages.txt << _EOT_
651 $PACKAGE
652 $VERSION
653 $SHORT_DESC
654 _EOT_
655 if [ -n "$PACKED_SIZE" ]; then
656 cat >> packages.txt << _EOT_
657 $PACKED_SIZE ($UNPACKED_SIZE installed)
658 _EOT_
659 fi
660 # Packages.desc is used by Tazpkgbox <tree>.
661 echo "$PACKAGE | $VERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> packages.desc
662 # Packages.equiv is used by tazpkg install to check depends
663 touch packages.equiv
664 for i in $PROVIDE; do
665 DEST=""
666 echo $i | grep -q : && DEST="${i#*:}:"
667 if grep -qs ^${i%:*}= packages.equiv; then
668 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" packages.equiv
669 else
670 echo "${i%:*}=$DEST$PACKAGE" >> packages.equiv
671 fi
672 done
673 packages=$(($packages+1))
674 done && status
675 echo -n "Creating the text files list... "
676 for pkg in $WOK/*
677 do
678 if [ -f $pkg/taz/*/files.list ]; then
679 . $pkg/taz/*/receipt
680 ( echo "$PACKAGE"; cat $pkg/taz/*/files.list ) | awk '
681 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }'
682 else
683 echo "No files_list in $pkg" 1>&2
684 fi
685 done | lzma e files.list.lzma -si && status
686 sed -i s/"_packages_"/"$packages"/ packages.txt
687 }
689 # Return the date of the last commit in seconds since Jan 1 1970
690 hgdate()
691 {
692 local pkg
693 local date
694 local mon
695 # Default date is Jan 1 1970
696 [ -d $WOK/.hg -a -x /usr/bin/hg ] || { echo "010100001970"; return; }
697 pkg=$(basename $1)
698 # Get date for last commit
699 date="$( cd $WOK; hg log $(find $pkg/receipt $pkg/stuff -type f \
700 2> /dev/null) | grep date: | head -1 | cut -c 6-)"
701 [ -n "$date" ] || { echo "010100001970"; return; }
702 case "$(echo $date | awk '{ print $2 }')" in
703 Jan) mon="01";; Feb) mon="02";; Mar) mon="03";; Apr) mon="04";;
704 May) mon="05";; Jun) mon="06";; Jul) mon="07";; Aug) mon="08";;
705 Sep) mon="09";; Oct) mon="10";; Nov) mon="11";; Dec) mon="12";;
706 esac
707 # Reformat, don't mind about TZ: we look for days or months delta
708 echo $date | sed "s|[^ ]* [^ ]* \\(.*\\) \\(.*\\):\\(.*\\):\\(.*\\) \\(.*\\) .*|$mon\1\2\3\5|"
709 }
711 # List packages providing a virtual package
712 whoprovide()
713 {
714 local i;
715 for i in $(grep -l PROVIDE $WOK/*/receipt); do
716 . $i
717 case " $PROVIDE " in
718 *\ $1\ *|*\ $1:*) echo $(basename $(dirname $i));;
719 esac
720 done
721 }
723 ###################
724 # Tazwok commands #
725 ###################
727 case "$COMMAND" in
728 stats)
729 # Tazwok general statistics from the config file the wok.
730 #
731 echo ""
732 echo -e "\033[1mTazwok configuration statistics\033[0m
733 ================================================================================
734 Wok directory : $WOK
735 Packages repository : $PACKAGES_REPOSITORY
736 Sources repository : $SOURCES_REPOSITORY
737 Packages in the wok : `ls -1 $WOK | wc -l`
738 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
739 ================================================================================"
740 echo "" ;;
741 edit)
742 check_for_package_on_cmdline
743 check_for_receipt
744 $EDITOR $WOK/$PACKAGE/receipt ;;
745 build-depends)
746 # List dependancies to rebuild wok
747 cd $WOK
748 ALL_DEPS="slitaz-toolchain"
749 echo $ALL_DEPS
750 for pkg in $(ls $2)
751 do
752 [ -f $pkg/receipt ] || continue
753 BUILD_DEPENDS=""
754 . $pkg/receipt
755 for i in $BUILD_DEPENDS; do
756 case " $ALL_DEPS " in
757 *\ $i\ *);;
758 *) ALL_DEPS="$ALL_DEPS $i"
759 echo $i;;
760 esac
761 done
762 done
763 ;;
764 check-depends)
765 # Check package depends
766 echo ""
767 echo -e "\033[1mCheck every receipt for DEPENDS - doesn't scan ELF files\033[0m
768 ================================================================================"
769 TMPDIR=/tmp/tazwok$$
770 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
772 # Build ALL_DEPENDS variable
773 scan_dep()
774 {
775 local i
776 ALL_DEPENDS="$ALL_DEPENDS$PACKAGE "
777 for i in $DEPENDS $SUGGESTED ; do
778 case " $ALL_DEPENDS " in
779 *\ $i\ *) continue;;
780 esac
781 [ -d $WOK/$i ] || {
782 ALL_DEPENDS="$ALL_DEPENDS$i "
783 continue
784 }
785 DEPENDS=""
786 SUGGESTED=""
787 . $WOK/$i/receipt
788 scan_dep
789 done
790 }
792 # Check for ELF file
793 is_elf()
794 {
795 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" \
796 = "ELF" ]
797 }
799 # Print shared library dependencies
800 ldd()
801 {
802 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
803 }
805 mkdir $TMPDIR
806 cd $TMPDIR
807 for i in $LOCALSTATE/files.list.lzma \
808 $LOCALSTATE/undigest/*/files.list.lzma ; do
809 [ -f $i ] && lzma d $i -so >> files.list
810 done
811 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
812 tazpkg extract $pkg > /dev/null 2>&1
813 . */receipt
814 ALL_DEPENDS="$DEFAULT_DEPENDS "
815 scan_dep
816 find */fs -type f | while read file ; do
817 is_elf $file || continue
818 case "$file" in
819 *.o|*.ko|*.ko.gz) continue;;
820 esac
821 ldd $file | while read lib rem; do
822 case "$lib" in
823 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
824 continue;;
825 esac
826 for dep in $(grep $lib files.list | cut -d: -f1); do
827 case " $ALL_DEPENDS " in
828 *\ $dep\ *) continue 2;;
829 esac
830 for vdep in $(grep $dep $LOCALSTATE/packages.equiv | cut -d= -f1); do
831 case " $ALL_DEPENDS " in
832 *\ $vdep\ *) continue 3;;
833 esac
834 done
835 done
836 [ -n "$dep" ] || dep="UNKNOWN"
837 echo "$(basename $pkg): ${file#*fs} depends on package $dep for the shared library $lib"
838 done
839 done
840 rm -rf */
841 done
842 cd /tmp
843 rm -rf $TMPDIR
844 ;;
845 check)
846 # Check wok consistancy
847 echo ""
848 echo -e "\033[1mWok and packages checking\033[0m
849 ================================================================================"
850 cd $WOK
851 for pkg in $(ls)
852 do
853 [ -f $pkg/receipt ] || continue
854 PACKAGE=""
855 VERSION=""
856 EXTRAVERSION=""
857 CATEGORY=""
858 SHORT_DESC=""
859 MAINTAINER=""
860 WEB_SITE=""
861 WGET_URL=""
862 DEPENDS=""
863 BUILD_DEPENDS=""
864 WANTED=""
865 PACKED_SIZE=""
866 UNPACKED_SIZE=""
867 . $pkg/receipt
868 [ "$PACKAGE" = "$pkg" ] || echo "Package $PACKAGE should be $pkg"
869 [ -n "$VERSION" ] || echo "Package $PACKAGE has no VERSION"
870 [ -n "$PACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded PACKED_SIZE"
871 [ -n "$UNPACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded UNPACKED_SIZE"
872 [ -n "$EXTRAVERSION" ] && echo "Package $PACKAGE has hardcoded EXTRAVERSION"
873 if [ -n "$WANTED" ]; then
874 if [ ! -f $WANTED/receipt ]; then
875 echo "Package $PACKAGE wants unknown $WANTED package"
876 else
877 BASEVERSION=$(. $WANTED/receipt ; echo $VERSION)
878 if [ "$VERSION" = "$WANTED" ]; then
879 # BASEVERSION is computed in receipt
880 grep -q '_pkg=' $pkg/receipt &&
881 BASEVERSION=$VERSION
882 fi
883 if [ "$VERSION" != "$BASEVERSION" ]; then
884 echo "Package $PACKAGE ($VERSION) wants $WANTED ($BASEVERSION)"
885 fi
886 fi
887 fi
889 if [ -n "$CATEGORY" ]; then
890 case " $(echo $CATEGORIES) " in
891 *\ $CATEGORY\ *);;
892 *) echo "Package $PACKAGE has an invalid CATEGORY";;
893 esac
894 else
895 echo"Package $PACKAGE has no CATEGORY"
896 fi
897 [ -n "$SHORT_DESC" ] || echo "Package $PACKAGE has no SHORT_DESC"
898 [ -n "$MAINTAINER" ] || echo "Package $PACKAGE has no MAINTAINER"
899 case "$WGET_URL" in
900 ftp*|http*) wget -s $WGET_URL 2> /dev/null ||
901 echo "Package $PACKAGE has a wrong WGET_URL";;
902 '') ;;
903 *) echo "Package $PACKAGE has an invalid WGET_URL";;
904 esac
905 case "$WEB_SITE" in
906 ftp*|http*);;
907 '') echo "Package $PACKAGE has no WEB_SITE";;
908 *) echo "Package $PACKAGE has an invalid WEB_SITE";;
909 esac
910 case "$MAINTAINER" in
911 *\<*|*\>*) echo "Package $PACKAGE has an invalid MAINTAINER: $MAINTAINER";;
912 esac
913 case "$MAINTAINER" in
914 *@*);;
915 *) echo "Package $PACKAGE MAINTAINER is not an email address";;
916 esac
917 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n"
918 for i in $DEPENDS; do
919 [ -d $i ] && continue
920 [ -n "$(whoprovide $i)" ] && continue
921 echo -e "$MSG $i"
922 MSG=""
923 done
924 MSG="Missing build dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n"
925 for i in $BUILD_DEPENDS; do
926 [ -d $i ] && continue
927 [ -n "$(whoprovide $i)" ] && continue
928 echo -e "$MSG $i"
929 MSG=""
930 done
931 MSG="Dependencies loop between $PACKAGE and :\n"
932 ALL_DEPS=""
933 check_for_deps_loop $PACKAGE $DEPENDS
934 [ -d $WOK/$pkg/taz ] && for i in $BUILD_DEPENDS; do
935 [ $WOK/$pkg/taz -nt $INSTALLED/$i/files.list ] && continue
936 echo "$pkg should be rebuilt since $i installation"
937 done
938 done
939 ;;
940 cmp|compare)
941 # Compare the wok and packages repository to help with maintaining
942 # a mirror.
943 echo ""
944 echo -e "\033[1mWok and packages comparison\033[0m
945 ================================================================================"
946 for pkg in $WOK/*
947 do
948 WANTED=""
949 . $pkg/receipt
950 echo "$PACKAGE-$VERSION.tazpkg" >> /tmp/wok.list.$$
951 tpkg="$(ls $PACKAGES_REPOSITORY/$PACKAGE-$VERSION*.tazpkg 2> /dev/null | head -1)"
952 if [ -z "$tpkg" ]; then
953 echo "Missing package: $PACKAGE ($VERSION)"
954 echo "$PACKAGE" >> /tmp/pkgs.missing.$$
955 elif [ -f $pkg/taz/*/receipt -a ! -f $pkg/taz/*/md5sum ]; then
956 echo "Obsolete package: $PACKAGE ($VERSION)"
957 echo "$PACKAGE" >> /tmp/pkgs.missing.$$
958 elif [ $pkg/receipt -nt $tpkg ]; then
959 echo "Refresh package: $PACKAGE ($VERSION)"
960 echo "$PACKAGE" >> /tmp/pkgs.missing.$$
961 else
962 srcdate=$(hgdate $pkg)
963 pkgdate=$(date -u -r $tpkg '+%m%d%H%M%Y')
964 if [ $(date -d $pkgdate +%s) -lt $(date -d $srcdate +%s) ]; then
965 echo "Rebuild package: $PACKAGE ($VERSION) cooked $(date -d $pkgdate "+%x %X"), modified $(date -d $srcdate "+%x %X")"
966 echo "$PACKAGE" >> /tmp/pkgs.missing.$$
967 else
968 continue
969 fi
970 fi
971 if [ "$2" = "--cook" ]; then
972 if [ -n "$WANTED" -a ! -d $WOK/$WANTED/taz ]; then
973 yes '' | tazwok cook $WANTED
974 fi
975 yes '' | tazwok cook $PACKAGE
976 fi
977 done
978 for pkg in `cd $PACKAGES_REPOSITORY && ls *.tazpkg`
979 do
980 # grep $pkg in /tmp/wok.list.$$
981 # may include EXTRAVERSION or computed VERSION
982 for i in $(grep ^${pkg%-*} /tmp/wok.list.$$); do
983 case "$pkg" in
984 ${i%.tazpkg}*.tazpkg) continue 2;;
985 esac
986 done
987 # Not found
988 echo $pkg >> /tmp/pkgs.old.$$
989 if [ "$2" = "--remove" ]; then
990 echo "Removing package: $pkg"
991 rm $PACKAGES_REPOSITORY/$pkg
992 else
993 echo "Old package: $pkg"
994 fi
995 done
996 cd /tmp
997 echo "================================================================================"
998 echo "Wok: `cat wok.list.$$ | wc -l` - \
999 Cooked: `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l` - \
1000 Missing: `cat pkgs.missing.$$ 2>/dev/null | wc -l` - \
1001 Old: `cat pkgs.old.$$ 2>/dev/null | wc -l`"
1002 echo ""
1003 rm -f wok.list.$$ pkgs.old.$$ pkgs.missing.$$
1004 ;;
1005 list)
1006 # List packages in wok directory. User can specify a category
1008 if [ "$2" = "category" ]; then
1009 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
1010 exit 0
1011 fi
1012 # Check for an asked category.
1013 if [ -n "$2" ]; then
1014 ASKED_CATEGORY=$2
1015 echo ""
1016 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
1017 echo "================================================================================"
1018 for pkg in $WOK/*
1019 do
1020 . $pkg/receipt
1021 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
1022 echo -n "$PACKAGE"
1023 echo -e "\033[28G $VERSION"
1024 packages=$(($packages+1))
1025 fi
1026 done
1027 echo "================================================================================"
1028 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
1029 else
1030 # By default list all packages and version.
1031 echo ""
1032 echo -e "\033[1mList of packages in the wok\033[0m"
1033 echo "================================================================================"
1034 for pkg in $WOK/*
1035 do
1036 . $pkg/receipt
1037 echo -n "$PACKAGE"
1038 echo -en "\033[28G $VERSION"
1039 echo -e "\033[42G $CATEGORY"
1040 packages=$(($packages+1))
1041 done
1042 echo "================================================================================"
1043 echo -e "$packages packages available in the wok.\n"
1044 fi
1045 ;;
1046 info)
1047 # Information about a package.
1049 check_for_package_on_cmdline
1050 check_for_receipt
1051 . $WOK/$PACKAGE/receipt
1052 echo ""
1053 echo -e "\033[1mTazwok package information\033[0m
1054 ================================================================================
1055 Package : $PACKAGE
1056 Version : $VERSION
1057 Category : $CATEGORY
1058 Short desc : $SHORT_DESC
1059 Maintainer : $MAINTAINER"
1060 if [ ! "$WEB_SITE" = "" ]; then
1061 echo "Web site : $WEB_SITE"
1062 fi
1063 if [ ! "$DEPENDS" = "" ]; then
1064 echo "Depends : $DEPENDS"
1065 fi
1066 if [ ! "$WANTED" = "" ]; then
1067 echo "Wanted src : $WANTED"
1068 fi
1069 echo "================================================================================"
1070 echo ""
1072 ;;
1073 check-log)
1074 # We just cat the file log to view process info.
1076 if [ ! -f "$LOG" ]; then
1077 echo -e "\nNo process log found. The package is probably not cooked.\n"
1078 exit 0
1079 else
1080 echo ""
1081 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
1082 echo "================================================================================"
1083 cat $LOG
1084 echo "================================================================================"
1085 echo ""
1086 fi
1087 ;;
1088 search)
1089 # Search for a package by pattern or name.
1091 if [ -z "$2" ]; then
1092 echo -e "\nPlease specify a pattern or a package name to search."
1093 echo -e "Example : 'tazwok search gcc'.\n"
1094 exit 0
1095 fi
1096 echo ""
1097 echo -e "\033[1mSearch result for :\033[0m $2"
1098 echo "================================================================================"
1099 list=`ls -1 $WOK | grep $2`
1100 for pkg in $list
1101 do
1102 . $WOK/$pkg/receipt
1103 echo -n "$PACKAGE "
1104 echo -en "\033[24G $VERSION"
1105 echo -e "\033[42G $CATEGORY"
1106 packages=$(($packages+1))
1107 done
1108 echo "================================================================================"
1109 echo "$packages packages found for : $2"
1110 echo ""
1111 ;;
1112 compile)
1113 # Configure and make a package with the receipt.
1115 compile_package
1116 ;;
1117 genpkg)
1118 # Generate a package.
1120 gen_package
1121 ;;
1122 cook)
1123 # Compile and generate a package. Just execute tazwok with
1124 # the good commands.
1126 check_root
1127 compile_package
1128 gen_package
1129 ;;
1130 cook-list)
1131 # Cook all packages listed in a file. The path to the cooklist must
1132 # be specified on the cmdline.
1134 check_root
1135 check_for_list
1136 for pkg in $LIST
1137 do
1138 tazwok compile $pkg
1139 tazwok genpkg $pkg
1140 done
1141 ;;
1142 clean)
1143 # Clean up a package work directory.
1145 check_for_package_on_cmdline
1146 check_for_receipt
1147 . $RECEIPT
1148 cd $WOK/$PACKAGE
1149 echo ""
1150 echo "Cleaning $PACKAGE..."
1151 echo "================================================================================"
1152 # Check for clean_wok function.
1153 if grep -q ^clean_wok $RECEIPT; then
1154 clean_wok
1155 fi
1156 # Remove taz/ and source tree if exists.
1157 if [ -d "taz" ]; then
1158 echo -n "Removing taz files..."
1159 rm -rf taz
1160 status
1161 fi
1162 for i in $PACKAGE-$VERSION $SOURCE-$VERSION ; do
1163 [ -e "$i" ] || continue
1164 echo -n "Removing source files..."
1165 if [ -L $i ]; then
1166 target=$(readlink $i)
1167 [ -d "$target" ] && case "$target" in
1168 /*|.|./*|..|../*);;
1169 *) rm -rf $target;;
1170 esac
1171 fi
1172 rm -rf $i
1173 status
1174 done
1175 # Remove an eventual $PACKAGE-build directory.
1176 if [ -d "$PACKAGE-build" ]; then
1177 echo -n "Removing build tree..."
1178 rm -rf $PACKAGE-build && status
1179 fi
1180 # Remove process log file.
1181 if [ -f "process.log" ]; then
1182 echo -n "Removing process log file..."
1183 rm process.log && status
1184 echo "================================================================================"
1185 fi
1186 echo "$PACKAGE is clean. You can cook it again..."
1187 echo ""
1188 ;;
1189 gen-clean-wok)
1190 # Generate a clean wok from the current wok by copying all receipts
1191 # and stuff directory.
1193 if [ -z "$2" ]; then
1194 echo -e "\nPlease specify the destination for the new clean wok.\n"
1195 exit 0
1196 else
1197 dest=$2
1198 mkdir -p $dest
1199 fi
1200 echo "New wok is going to : $dest"
1201 for pkg in `ls -1 $WOK`
1202 do
1203 echo "----"
1204 echo -n "Preparing $pkg..."
1205 mkdir -p $dest/$pkg
1206 status
1207 echo -n "Copying the receipt..."
1208 cp -a $WOK/$pkg/receipt $dest/$pkg
1209 status
1210 if [ -d "$WOK/$pkg/stuff" ]; then
1211 echo -n "Copying all the stuff directory..."
1212 cp -a $WOK/$pkg/stuff $dest/$pkg
1213 status
1214 fi
1215 done
1216 echo "================================================================================"
1217 echo "Clean wok generated in : $dest"
1218 echo "Packages cleaned : `ls -1 $dest | wc -l`"
1219 echo ""
1220 ;;
1221 clean-wok)
1222 # Clean all packages in the work directory
1224 for pkg in `ls -1 $WOK`
1225 do
1226 tazwok clean $pkg
1227 done
1228 echo "================================================================================"
1229 echo "`ls -1 $WOK | wc -l` packages cleaned."
1230 echo ""
1231 ;;
1232 gen-list)
1233 # Sed is used to remove all the .tazpkg extensions from the
1234 # packages.list. The directory to move in by default is the repository
1235 # if $2 is not empty cd into $2. A text packages list can also be gen
1236 # with the option --text.
1238 fakewok=""
1239 if [ "$2" == "--text" ]; then
1240 textlist="yes"
1241 if [ "$3" == "--fakewok" ]; then
1242 WOK=/tmp/fakewok-$$
1243 fakewok="$WOK"
1244 mkdir -p $WOK
1245 for i in $PACKAGES_REPOSITORY/*.tazpkg; do
1246 (cd $WOK; cpio -i receipt files.list 2>/dev/null) < $i
1247 . $WOK/receipt
1248 mkdir -p $WOK/$PACKAGE/taz/$PACKAGE-$VERSION
1249 mv $WOK/receipt $WOK/files.list \
1250 $WOK/$PACKAGE/taz/$PACKAGE-$VERSION
1251 ln $WOK/$PACKAGE/taz/$PACKAGE-$VERSION/receipt $WOK/$PACKAGE
1252 done
1253 fi
1254 elif [ -z "$2" ]; then
1255 PACKAGES_REPOSITORY=$PACKAGES_REPOSITORY
1256 else
1257 if [ -d "$2" ]; then
1258 PACKAGES_REPOSITORY=$2
1259 else
1260 echo -e "\nUnable to find directory : $2\n"
1261 exit 0
1262 fi
1263 fi
1264 cd $PACKAGES_REPOSITORY
1265 # Remove old packages.list and md5sum, they will soon be rebuilt.
1266 rm -f packages.list packages.md5 packages.txt
1267 echo ""
1268 echo -e "\033[1mGenerating packages lists\033[0m"
1269 echo "================================================================================"
1270 echo -n "Repository path : $PACKAGES_REPOSITORY" && status
1271 # Generate packages.txt
1272 if [ "$textlist" == "yes" ]; then
1273 gen_textlist
1274 [ "$fakewok" == "" ] || rm -rf $fakewok
1275 fi
1276 echo -n "Creating the raw packages list... "
1277 ls -1 *.tazpkg > /tmp/packages.list
1278 sed -i s/'.tazpkg'/''/ /tmp/packages.list
1279 status
1280 echo -n "Building the md5sum for all packages... "
1281 md5sum *.tazpkg > packages.md5
1282 status
1283 mv /tmp/packages.list $PACKAGES_REPOSITORY
1284 echo "================================================================================"
1285 pkgs=`cat $PACKAGES_REPOSITORY/packages.list | wc -l`
1286 echo "$pkgs packages in the repository."
1287 echo ""
1288 ;;
1289 new-tree)
1290 # Just create a few directories and generate an empty receipt to prepare
1291 # the creation of a new package.
1293 check_for_package_on_cmdline
1294 if [ -d $WOK/$PACKAGE ]; then
1295 echo -e "\n$PACKAGE package tree already exists.\n"
1296 exit 0
1297 fi
1298 echo "Creating : $WOK/$PACKAGE"
1299 mkdir $WOK/$PACKAGE
1300 cd $WOK/$PACKAGE
1301 echo -n "Preparing the receipt..."
1303 # Default receipt begin.
1305 echo "# SliTaz package receipt." > receipt
1306 echo "" >> receipt
1307 echo "PACKAGE=\"$PACKAGE\"" >> receipt
1308 # Finish the empty receipt.
1309 cat >> receipt << "EOF"
1310 VERSION=""
1311 CATEGORY=""
1312 SHORT_DESC=""
1313 MAINTAINER=""
1314 DEPENDS=""
1315 TARBALL="$PACKAGE-$VERSION.tar.gz"
1316 WEB_SITE=""
1317 WGET_URL=""
1319 # Rules to configure and make the package.
1320 compile_rules()
1322 cd $src
1323 ./configure \
1324 --prefix=/usr \
1325 --infodir=/usr/share/info \
1326 --mandir=/usr/share/man \
1327 $CONFIGURE_ARGS &&
1328 make && make DESTDIR=$PWD/_pkg install
1331 # Rules to gen a SliTaz package suitable for Tazpkg.
1332 genpkg_rules()
1334 mkdir -p $fs/usr
1335 cp -a $_pkg/usr/bin $fs/usr
1338 EOF
1340 # Default receipt end.
1342 status
1343 # Interactive mode, asking and seding.
1344 if [ "$3" = "--interactive" ]; then
1345 echo "Entering in interactive mode..."
1346 echo "================================================================================"
1347 echo "Package : $PACKAGE"
1348 # Version.
1349 echo -n "Version : " ; read anser
1350 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
1351 # Category.
1352 echo -n "Category : " ; read anser
1353 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
1354 # Short description.
1355 echo -n "Short desc : " ; read anser
1356 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
1357 # Maintainer.
1358 echo -n "Maintainer : " ; read anser
1359 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
1360 # Web site.
1361 echo -n "Web site : " ; read anser
1362 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
1363 echo ""
1364 # Wget URL.
1365 echo "Wget URL to download source tarball."
1366 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
1367 echo -n "Wget url : " ; read anser
1368 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
1369 # Ask for a stuff dir.
1370 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
1371 if [ "$anser" = "y" ]; then
1372 echo -n "Creating the stuff directory..."
1373 mkdir stuff && status
1374 fi
1375 # Ask for a description file.
1376 echo -n "Are you going to write a description ? (y/N) : " ; read anser
1377 if [ "$anser" = "y" ]; then
1378 echo -n "Creating the description.txt file..."
1379 echo "" > description.txt && status
1380 fi
1381 echo "================================================================================"
1382 echo ""
1383 fi
1384 ;;
1385 remove)
1386 # Remove a package from the wok.
1388 check_for_package_on_cmdline
1389 echo ""
1390 echo -n "Please confirm deletion (y/N) : "; read anser
1391 if [ "$anser" = "y" ]; then
1392 echo -n "Removing $PACKAGE..."
1393 rm -rf $WOK/$PACKAGE && status
1394 echo ""
1395 fi
1396 ;;
1397 hgup)
1398 # Pull and update an Hg wok.
1399 if ls -l $WOK/.hg/hgrc | grep -q "root"; then
1400 check_root
1401 fi
1402 cd $WOK
1403 hg pull && hg update ;;
1404 maintainers)
1405 echo ""
1406 echo "List of maintainers for: $WOK"
1407 echo "================================================================================"
1408 touch /tmp/slitaz-maintainers
1409 for pkg in $WOK/*
1410 do
1411 . $pkg/receipt
1412 if ! grep -q "$MAINTAINER" /tmp/slitaz-maintainers; then
1413 echo "$MAINTAINER" >> /tmp/slitaz-maintainers
1414 echo "$MAINTAINER"
1415 fi
1416 done
1417 echo "================================================================================"
1418 echo "Maintainers: `cat /tmp/slitaz-maintainers | wc -l`"
1419 echo ""
1420 # Remove tmp files
1421 rm -f /tmp/slitaz-maintainers ;;
1422 maintained-by)
1423 # Search for packages maintained by a packagers.
1424 if [ ! -n "$2" ]; then
1425 echo "Specify a name or mail of a maintainer."
1426 exit 0
1427 fi
1428 echo "Maintainer packages"
1429 echo "================================================================================"
1430 for pkg in $WOK/*
1431 do
1432 . $pkg/receipt
1433 if echo "$MAINTAINER" | grep -q "$2"; then
1434 echo "$PACKAGE"
1435 packages=$(($packages+1))
1436 fi
1437 done
1438 echo "================================================================================"
1439 echo "Packages maintained by $2: $packages"
1440 echo "" ;;
1441 usage|*)
1442 # Print usage also for all unknown commands.
1444 usage
1445 ;;
1446 esac
1448 exit 0