tazwok view tazwok @ rev 150

tazwok: enable tazpkg lzma compression
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Sep 18 09:53:45 2009 +0200 (2009-09-18)
parents fbcc882cbb65
children e49ca096d97d
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 continue ;;
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 continue
530 else
531 copy_generic_files
532 fi
533 strip_package
534 else
535 echo "No package rules to gen $PACKAGE..."
536 exit 1
537 fi
538 # Copy the receipt and description (if exists) in the binary package tree.
539 cd $WOK/$PACKAGE
540 echo -n "Copying the receipt..."
541 cp receipt taz/$PACKAGE-$VERSION
542 status
543 if grep -q ^get_version $RECEIPT; then
544 echo -n "Update version in receipt..."
545 sed -i "s/^VERSION=.*/VERSION=\"$VERSION\"/" \
546 taz/$PACKAGE-$VERSION/receipt
547 status
548 fi
549 if [ -f "description.txt" ]; then
550 echo -n "Copying the description file..."
551 cp description.txt taz/$PACKAGE-$VERSION
552 status
553 fi
554 # Create the files.list by redirecting find output.
555 echo -n "Creating the list of files..."
556 cd taz/$PACKAGE-$VERSION
557 LAST_FILE=""
558 ( find fs -print; echo ) | while read file; do
559 if [ "$LAST_FILE" != "" ]; then
560 case "$file" in
561 $LAST_FILE/*)
562 case "$(ls -ld "$LAST_FILE")" in
563 drwxr-xr-x\ *\ root\ *\ root\ *);;
564 *) echo ${LAST_FILE#fs};;
565 esac;;
566 *) echo ${LAST_FILE#fs};;
567 esac
568 fi
569 LAST_FILE="$file"
570 done > files.list
571 status
572 if [ -z "$EXTRAVERSION" ]; then
573 case "$PACKAGE" in
574 linux*);;
575 *) EXTRAVERSION="$(grep '/lib/modules/.*-slitaz/' files.list |\
576 head -1 | sed 's|/lib/modules/\(.*\)-slitaz/.*|_\1|')";;
577 esac
578 fi
579 rm -f $PACKAGES_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg 2> /dev/null
580 echo -n "Creating md5sum of files..."
581 while read file; do
582 [ -L "fs$file" ] && continue
583 [ -f "fs$file" ] || continue
584 md5sum "fs$file" | sed 's/ fs/ /'
585 done < files.list > md5sum
586 #[ -s md5sum ] || rm -f md5sum
587 status
588 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
589 2> /dev/null | awk '{ sz=$1 } END { print sz }')
590 # Build cpio archives. Find, cpio and gzip the fs, finish by
591 # removing the fs tree.
592 echo -n "Compressing the fs... "
593 find fs -print | cpio -o -H newc | case "$PACKAGE-$COMPRESSION" in
594 tazpkg-lzma) gzip > fs.cpio.gz;;
595 *-lzma) lzma e fs.cpio.lzma -si;;
596 *) gzip > fs.cpio.gz;;
597 esac && rm -rf fs
598 PACKED_SIZE=$(du -chs fs.cpio.* receipt files.list md5sum \
599 description.txt 2> /dev/null | awk '{ sz=$1 } END { print sz }')
600 status
601 echo -n "Updating receipt sizes..."
602 sed -i '/^PACKED_SIZE/d' receipt
603 sed -i '/^UNPACKED_SIZE/d' receipt
604 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
605 sed -i "s/^VERSION=$/VERSION=\"$VERSION\"/" receipt
606 status
607 if [ -n "$EXTRAVERSION" ]; then
608 echo -n "Updating receipt EXTRAVERSION..."
609 sed -i s/^EXTRAVERSION.*$// receipt
610 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
611 status
612 fi
613 echo -n "Creating full cpio archive... "
614 find . -print | cpio -o -H newc > $PACKAGES_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
615 status
616 # Restore package tree incase we want to browse it.
617 echo -n "Restoring original package tree... "
618 ( zcat fs.cpio.gz 2> /dev/null || unlzma -c fs.cpio.lzma ) | cpio -id
619 rm fs.cpio.* && cd ..
620 # Log process.
621 echo "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg (done)" >> $LOG
622 echo "================================================================================"
623 echo "Package $PACKAGE ($VERSION$EXTRAVERSION) generated."
624 echo "Size : `du -sh $PACKAGES_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
625 echo ""
626 }
628 # Optional text packages list for gen-list.
629 gen_textlist()
630 {
631 rm -f packages.desc packages.equiv
632 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
633 echo -n "Creating the text packages list... "
634 cat >> packages.txt << _EOT_
635 # SliTaz GNU/Linux - Packages list
636 #
637 # Packages : _packages_
638 # Date : $DATE
639 #
640 _EOT_
641 for pkg in $WOK/*
642 do
643 PROVIDE=""
644 PACKAGE=""
645 PACKED_SIZE=""
646 if [ -f $pkg/taz/*/receipt ]; then
647 . $pkg/taz/*/receipt
648 else
649 . $pkg/receipt
650 fi
651 cat >> packages.txt << _EOT_
653 $PACKAGE
654 $VERSION
655 $SHORT_DESC
656 _EOT_
657 if [ -n "$PACKED_SIZE" ]; then
658 cat >> packages.txt << _EOT_
659 $PACKED_SIZE ($UNPACKED_SIZE installed)
660 _EOT_
661 fi
662 # Packages.desc is used by Tazpkgbox <tree>.
663 echo "$PACKAGE | $VERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> packages.desc
664 # Packages.equiv is used by tazpkg install to check depends
665 touch packages.equiv
666 for i in $PROVIDE; do
667 DEST=""
668 echo $i | grep -q : && DEST="${i#*:}:"
669 if grep -qs ^${i%:*}= packages.equiv; then
670 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" packages.equiv
671 else
672 echo "${i%:*}=$DEST$PACKAGE" >> packages.equiv
673 fi
674 done
675 packages=$(($packages+1))
676 done && status
677 echo -n "Creating the text files list... "
678 for pkg in $WOK/*
679 do
680 if [ -f $pkg/taz/*/files.list ]; then
681 . $pkg/taz/*/receipt
682 ( echo "$PACKAGE"; cat $pkg/taz/*/files.list ) | awk '
683 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }'
684 else
685 echo "No files_list in $pkg" 1>&2
686 fi
687 done | lzma e files.list.lzma -si && status
688 sed -i s/"_packages_"/"$packages"/ packages.txt
689 }
691 # Return the date of the last commit in seconds since Jan 1 1970
692 hgdate()
693 {
694 local pkg
695 local date
696 local mon
697 # Default date is Jan 1 1970
698 [ -d $WOK/.hg -a -x /usr/bin/hg ] || { echo "010100001970"; return; }
699 pkg=$(basename $1)
700 # Get date for last commit
701 date="$( cd $WOK; hg log $(find $pkg/receipt $pkg/stuff -type f \
702 2> /dev/null) | grep date: | head -1 | cut -c 6-)"
703 [ -n "$date" ] || { echo "010100001970"; return; }
704 case "$(echo $date | awk '{ print $2 }')" in
705 Jan) mon="01";; Feb) mon="02";; Mar) mon="03";; Apr) mon="04";;
706 May) mon="05";; Jun) mon="06";; Jul) mon="07";; Aug) mon="08";;
707 Sep) mon="09";; Oct) mon="10";; Nov) mon="11";; Dec) mon="12";;
708 esac
709 # Reformat, don't mind about TZ: we look for days or months delta
710 echo $date | sed "s|[^ ]* [^ ]* \\(.*\\) \\(.*\\):\\(.*\\):\\(.*\\) \\(.*\\) .*|$mon\1\2\3\5|"
711 }
713 # List packages providing a virtual package
714 whoprovide()
715 {
716 local i;
717 for i in $(grep -l PROVIDE $WOK/*/receipt); do
718 . $i
719 case " $PROVIDE " in
720 *\ $1\ *|*\ $1:*) echo $(basename $(dirname $i));;
721 esac
722 done
723 }
725 ###################
726 # Tazwok commands #
727 ###################
729 case "$COMMAND" in
730 stats)
731 # Tazwok general statistics from the config file the wok.
732 #
733 echo ""
734 echo -e "\033[1mTazwok configuration statistics\033[0m
735 ================================================================================
736 Wok directory : $WOK
737 Packages repository : $PACKAGES_REPOSITORY
738 Sources repository : $SOURCES_REPOSITORY
739 Packages in the wok : `ls -1 $WOK | wc -l`
740 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
741 ================================================================================"
742 echo "" ;;
743 edit)
744 check_for_package_on_cmdline
745 check_for_receipt
746 $EDITOR $WOK/$PACKAGE/receipt ;;
747 build-depends)
748 # List dependancies to rebuild wok
749 cd $WOK
750 ALL_DEPS="slitaz-toolchain"
751 echo $ALL_DEPS
752 for pkg in $(ls $2)
753 do
754 [ -f $pkg/receipt ] || continue
755 BUILD_DEPENDS=""
756 . $pkg/receipt
757 for i in $BUILD_DEPENDS; do
758 case " $ALL_DEPS " in
759 *\ $i\ *);;
760 *) ALL_DEPS="$ALL_DEPS $i"
761 echo $i;;
762 esac
763 done
764 done
765 ;;
766 check-depends)
767 # Check package depends
768 echo ""
769 echo -e "\033[1mCheck every receipt for DEPENDS - doesn't scan ELF files\033[0m
770 ================================================================================"
771 TMPDIR=/tmp/tazwok$$
772 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
774 # Build ALL_DEPENDS variable
775 scan_dep()
776 {
777 local i
778 ALL_DEPENDS="$ALL_DEPENDS$PACKAGE "
779 for i in $DEPENDS $SUGGESTED ; do
780 case " $ALL_DEPENDS " in
781 *\ $i\ *) continue;;
782 esac
783 [ -d $WOK/$i ] || {
784 ALL_DEPENDS="$ALL_DEPENDS$i "
785 continue
786 }
787 DEPENDS=""
788 SUGGESTED=""
789 . $WOK/$i/receipt
790 scan_dep
791 done
792 }
794 # Check for ELF file
795 is_elf()
796 {
797 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" \
798 = "ELF" ]
799 }
801 # Print shared library dependencies
802 ldd()
803 {
804 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
805 }
807 mkdir $TMPDIR
808 cd $TMPDIR
809 for i in $LOCALSTATE/files.list.lzma \
810 $LOCALSTATE/undigest/*/files.list.lzma ; do
811 [ -f $i ] && lzma d $i -so >> files.list
812 done
813 for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
814 tazpkg extract $pkg > /dev/null 2>&1
815 . */receipt
816 ALL_DEPENDS="$DEFAULT_DEPENDS "
817 scan_dep
818 find */fs -type f | while read file ; do
819 is_elf $file || continue
820 case "$file" in
821 *.o|*.ko|*.ko.gz) continue;;
822 esac
823 ldd $file | while read lib rem; do
824 case "$lib" in
825 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
826 continue;;
827 esac
828 for dep in $(grep $lib files.list | cut -d: -f1); do
829 case " $ALL_DEPENDS " in
830 *\ $dep\ *) continue 2;;
831 esac
832 for vdep in $(grep $dep $LOCALSTATE/packages.equiv | cut -d= -f1); do
833 case " $ALL_DEPENDS " in
834 *\ $vdep\ *) continue 3;;
835 esac
836 done
837 done
838 [ -n "$dep" ] || dep="UNKNOWN"
839 echo "$(basename $pkg): ${file#*fs} depends on package $dep for the shared library $lib"
840 done
841 done
842 rm -rf */
843 done
844 cd /tmp
845 rm -rf $TMPDIR
846 ;;
847 check)
848 # Check wok consistancy
849 echo ""
850 echo -e "\033[1mWok and packages checking\033[0m
851 ================================================================================"
852 cd $WOK
853 for pkg in $(ls)
854 do
855 [ -f $pkg/receipt ] || continue
856 PACKAGE=""
857 VERSION=""
858 EXTRAVERSION=""
859 CATEGORY=""
860 SHORT_DESC=""
861 MAINTAINER=""
862 WEB_SITE=""
863 WGET_URL=""
864 DEPENDS=""
865 BUILD_DEPENDS=""
866 WANTED=""
867 PACKED_SIZE=""
868 UNPACKED_SIZE=""
869 . $pkg/receipt
870 [ "$PACKAGE" = "$pkg" ] || echo "Package $PACKAGE should be $pkg"
871 [ -n "$VERSION" ] || echo "Package $PACKAGE has no VERSION"
872 [ -n "$PACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded PACKED_SIZE"
873 [ -n "$UNPACKED_SIZE" ] && echo "Package $PACKAGE has hardcoded UNPACKED_SIZE"
874 [ -n "$EXTRAVERSION" ] && echo "Package $PACKAGE has hardcoded EXTRAVERSION"
875 if [ -n "$WANTED" ]; then
876 if [ ! -f $WANTED/receipt ]; then
877 echo "Package $PACKAGE wants unknown $WANTED package"
878 else
879 BASEVERSION=$(. $WANTED/receipt ; echo $VERSION)
880 if [ "$VERSION" = "$WANTED" ]; then
881 # BASEVERSION is computed in receipt
882 grep -q '_pkg=' $pkg/receipt &&
883 BASEVERSION=$VERSION
884 fi
885 if [ "$VERSION" != "$BASEVERSION" ]; then
886 echo "Package $PACKAGE ($VERSION) wants $WANTED ($BASEVERSION)"
887 fi
888 fi
889 fi
891 if [ -n "$CATEGORY" ]; then
892 case " $(echo $CATEGORIES) " in
893 *\ $CATEGORY\ *);;
894 *) echo "Package $PACKAGE has an invalid CATEGORY";;
895 esac
896 else
897 echo"Package $PACKAGE has no CATEGORY"
898 fi
899 [ -n "$SHORT_DESC" ] || echo "Package $PACKAGE has no SHORT_DESC"
900 [ -n "$MAINTAINER" ] || echo "Package $PACKAGE has no MAINTAINER"
901 case "$WGET_URL" in
902 ftp*|http*) wget -s $WGET_URL 2> /dev/null ||
903 echo "Package $PACKAGE has a wrong WGET_URL";;
904 '') ;;
905 *) echo "Package $PACKAGE has an invalid WGET_URL";;
906 esac
907 case "$WEB_SITE" in
908 ftp*|http*);;
909 '') echo "Package $PACKAGE has no WEB_SITE";;
910 *) echo "Package $PACKAGE has an invalid WEB_SITE";;
911 esac
912 case "$MAINTAINER" in
913 *\<*|*\>*) echo "Package $PACKAGE has an invalid MAINTAINER: $MAINTAINER";;
914 esac
915 case "$MAINTAINER" in
916 *@*);;
917 *) echo "Package $PACKAGE MAINTAINER is not an email address";;
918 esac
919 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n"
920 for i in $DEPENDS; do
921 [ -d $i ] && continue
922 [ -n "$(whoprovide $i)" ] && continue
923 echo -e "$MSG $i"
924 MSG=""
925 done
926 MSG="Missing build dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n"
927 for i in $BUILD_DEPENDS; do
928 [ -d $i ] && continue
929 [ -n "$(whoprovide $i)" ] && continue
930 echo -e "$MSG $i"
931 MSG=""
932 done
933 MSG="Dependencies loop between $PACKAGE and :\n"
934 ALL_DEPS=""
935 check_for_deps_loop $PACKAGE $DEPENDS
936 [ -d $WOK/$pkg/taz ] && for i in $BUILD_DEPENDS; do
937 [ $WOK/$pkg/taz -nt $INSTALLED/$i/files.list ] && continue
938 echo "$pkg should be rebuilt since $i installation"
939 done
940 done
941 ;;
942 cmp|compare)
943 # Compare the wok and packages repository to help with maintaining
944 # a mirror.
945 echo ""
946 echo -e "\033[1mWok and packages comparison\033[0m
947 ================================================================================"
948 for pkg in $WOK/*
949 do
950 WANTED=""
951 . $pkg/receipt
952 echo "$PACKAGE-$VERSION.tazpkg" >> /tmp/wok.list.$$
953 tpkg="$(ls $PACKAGES_REPOSITORY/$PACKAGE-$VERSION*.tazpkg 2> /dev/null | head -1)"
954 if [ -z "$tpkg" ]; then
955 echo "Missing package: $PACKAGE ($VERSION)"
956 echo "$PACKAGE" >> /tmp/pkgs.missing.$$
957 elif [ -f $pkg/taz/*/receipt -a ! -f $pkg/taz/*/md5sum ]; then
958 echo "Obsolete package: $PACKAGE ($VERSION)"
959 echo "$PACKAGE" >> /tmp/pkgs.missing.$$
960 elif [ $pkg/receipt -nt $tpkg ]; then
961 echo "Refresh package: $PACKAGE ($VERSION)"
962 echo "$PACKAGE" >> /tmp/pkgs.missing.$$
963 else
964 srcdate=$(hgdate $pkg)
965 pkgdate=$(date -u -r $tpkg '+%m%d%H%M%Y')
966 if [ $(date -d $pkgdate +%s) -lt $(date -d $srcdate +%s) ]; then
967 echo "Rebuild package: $PACKAGE ($VERSION) cooked $(date -d $pkgdate "+%x %X"), modified $(date -d $srcdate "+%x %X")"
968 echo "$PACKAGE" >> /tmp/pkgs.missing.$$
969 else
970 continue
971 fi
972 fi
973 if [ "$2" = "--cook" ]; then
974 if [ -n "$WANTED" -a ! -d $WOK/$WANTED/taz ]; then
975 yes '' | tazwok cook $WANTED
976 fi
977 yes '' | tazwok cook $PACKAGE
978 fi
979 done
980 for pkg in `cd $PACKAGES_REPOSITORY && ls *.tazpkg`
981 do
982 # grep $pkg in /tmp/wok.list.$$
983 # may include EXTRAVERSION or computed VERSION
984 for i in $(grep ^${pkg%-*} /tmp/wok.list.$$); do
985 case "$pkg" in
986 ${i%.tazpkg}*.tazpkg) continue 2;;
987 esac
988 done
989 # Not found
990 echo $pkg >> /tmp/pkgs.old.$$
991 if [ "$2" = "--remove" ]; then
992 echo "Removing package: $pkg"
993 rm $PACKAGES_REPOSITORY/$pkg
994 else
995 echo "Old package: $pkg"
996 fi
997 done
998 cd /tmp
999 echo "================================================================================"
1000 echo "Wok: `cat wok.list.$$ | wc -l` - \
1001 Cooked: `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l` - \
1002 Missing: `cat pkgs.missing.$$ 2>/dev/null | wc -l` - \
1003 Old: `cat pkgs.old.$$ 2>/dev/null | wc -l`"
1004 echo ""
1005 rm -f wok.list.$$ pkgs.old.$$ pkgs.missing.$$
1006 ;;
1007 list)
1008 # List packages in wok directory. User can specify a category
1010 if [ "$2" = "category" ]; then
1011 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
1012 exit 0
1013 fi
1014 # Check for an asked category.
1015 if [ -n "$2" ]; then
1016 ASKED_CATEGORY=$2
1017 echo ""
1018 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
1019 echo "================================================================================"
1020 for pkg in $WOK/*
1021 do
1022 . $pkg/receipt
1023 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
1024 echo -n "$PACKAGE"
1025 echo -e "\033[28G $VERSION"
1026 packages=$(($packages+1))
1027 fi
1028 done
1029 echo "================================================================================"
1030 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
1031 else
1032 # By default list all packages and version.
1033 echo ""
1034 echo -e "\033[1mList of packages in the wok\033[0m"
1035 echo "================================================================================"
1036 for pkg in $WOK/*
1037 do
1038 . $pkg/receipt
1039 echo -n "$PACKAGE"
1040 echo -en "\033[28G $VERSION"
1041 echo -e "\033[42G $CATEGORY"
1042 packages=$(($packages+1))
1043 done
1044 echo "================================================================================"
1045 echo -e "$packages packages available in the wok.\n"
1046 fi
1047 ;;
1048 info)
1049 # Information about a package.
1051 check_for_package_on_cmdline
1052 check_for_receipt
1053 . $WOK/$PACKAGE/receipt
1054 echo ""
1055 echo -e "\033[1mTazwok package information\033[0m
1056 ================================================================================
1057 Package : $PACKAGE
1058 Version : $VERSION
1059 Category : $CATEGORY
1060 Short desc : $SHORT_DESC
1061 Maintainer : $MAINTAINER"
1062 if [ ! "$WEB_SITE" = "" ]; then
1063 echo "Web site : $WEB_SITE"
1064 fi
1065 if [ ! "$DEPENDS" = "" ]; then
1066 echo "Depends : $DEPENDS"
1067 fi
1068 if [ ! "$WANTED" = "" ]; then
1069 echo "Wanted src : $WANTED"
1070 fi
1071 echo "================================================================================"
1072 echo ""
1074 ;;
1075 check-log)
1076 # We just cat the file log to view process info.
1078 if [ ! -f "$LOG" ]; then
1079 echo -e "\nNo process log found. The package is probably not cooked.\n"
1080 exit 0
1081 else
1082 echo ""
1083 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
1084 echo "================================================================================"
1085 cat $LOG
1086 echo "================================================================================"
1087 echo ""
1088 fi
1089 ;;
1090 search)
1091 # Search for a package by pattern or name.
1093 if [ -z "$2" ]; then
1094 echo -e "\nPlease specify a pattern or a package name to search."
1095 echo -e "Example : 'tazwok search gcc'.\n"
1096 exit 0
1097 fi
1098 echo ""
1099 echo -e "\033[1mSearch result for :\033[0m $2"
1100 echo "================================================================================"
1101 list=`ls -1 $WOK | grep $2`
1102 for pkg in $list
1103 do
1104 . $WOK/$pkg/receipt
1105 echo -n "$PACKAGE "
1106 echo -en "\033[24G $VERSION"
1107 echo -e "\033[42G $CATEGORY"
1108 packages=$(($packages+1))
1109 done
1110 echo "================================================================================"
1111 echo "$packages packages found for : $2"
1112 echo ""
1113 ;;
1114 compile)
1115 # Configure and make a package with the receipt.
1117 compile_package
1118 ;;
1119 genpkg)
1120 # Generate a package.
1122 gen_package
1123 ;;
1124 cook)
1125 # Compile and generate a package. Just execute tazwok with
1126 # the good commands.
1128 check_root
1129 compile_package
1130 gen_package
1131 ;;
1132 cook-list)
1133 # Cook all packages listed in a file. The path to the cooklist must
1134 # be specified on the cmdline.
1136 check_root
1137 check_for_list
1138 for pkg in $LIST
1139 do
1140 tazwok compile $pkg
1141 tazwok genpkg $pkg
1142 done
1143 ;;
1144 clean)
1145 # Clean up a package work directory.
1147 check_for_package_on_cmdline
1148 check_for_receipt
1149 . $RECEIPT
1150 cd $WOK/$PACKAGE
1151 echo ""
1152 echo "Cleaning $PACKAGE..."
1153 echo "================================================================================"
1154 # Check for clean_wok function.
1155 if grep -q ^clean_wok $RECEIPT; then
1156 clean_wok
1157 fi
1158 # Remove taz/ and source tree if exists.
1159 if [ -d "taz" ]; then
1160 echo -n "Removing taz files..."
1161 rm -rf taz
1162 status
1163 fi
1164 for i in $PACKAGE-$VERSION $SOURCE-$VERSION ; do
1165 [ -e "$i" ] || continue
1166 echo -n "Removing source files..."
1167 if [ -L $i ]; then
1168 target=$(readlink $i)
1169 [ -d "$target" ] && case "$target" in
1170 /*|.|./*|..|../*);;
1171 *) rm -rf $target;;
1172 esac
1173 fi
1174 rm -rf $i
1175 status
1176 done
1177 # Remove an eventual $PACKAGE-build directory.
1178 if [ -d "$PACKAGE-build" ]; then
1179 echo -n "Removing build tree..."
1180 rm -rf $PACKAGE-build && status
1181 fi
1182 # Remove process log file.
1183 if [ -f "process.log" ]; then
1184 echo -n "Removing process log file..."
1185 rm process.log && status
1186 echo "================================================================================"
1187 fi
1188 echo "$PACKAGE is clean. You can cook it again..."
1189 echo ""
1190 ;;
1191 gen-clean-wok)
1192 # Generate a clean wok from the current wok by copying all receipts
1193 # and stuff directory.
1195 if [ -z "$2" ]; then
1196 echo -e "\nPlease specify the destination for the new clean wok.\n"
1197 exit 0
1198 else
1199 dest=$2
1200 mkdir -p $dest
1201 fi
1202 echo "New wok is going to : $dest"
1203 for pkg in `ls -1 $WOK`
1204 do
1205 echo "----"
1206 echo -n "Preparing $pkg..."
1207 mkdir -p $dest/$pkg
1208 status
1209 echo -n "Copying the receipt..."
1210 cp -a $WOK/$pkg/receipt $dest/$pkg
1211 status
1212 if [ -d "$WOK/$pkg/stuff" ]; then
1213 echo -n "Copying all the stuff directory..."
1214 cp -a $WOK/$pkg/stuff $dest/$pkg
1215 status
1216 fi
1217 done
1218 echo "================================================================================"
1219 echo "Clean wok generated in : $dest"
1220 echo "Packages cleaned : `ls -1 $dest | wc -l`"
1221 echo ""
1222 ;;
1223 clean-wok)
1224 # Clean all packages in the work directory
1226 for pkg in `ls -1 $WOK`
1227 do
1228 tazwok clean $pkg
1229 done
1230 echo "================================================================================"
1231 echo "`ls -1 $WOK | wc -l` packages cleaned."
1232 echo ""
1233 ;;
1234 gen-list)
1235 # Sed is used to remove all the .tazpkg extensions from the
1236 # packages.list. The directory to move in by default is the repository
1237 # if $2 is not empty cd into $2. A text packages list can also be gen
1238 # with the option --text.
1240 fakewok=""
1241 if [ "$2" == "--text" ]; then
1242 textlist="yes"
1243 if [ "$3" == "--fakewok" ]; then
1244 WOK=/tmp/fakewok-$$
1245 fakewok="$WOK"
1246 mkdir -p $WOK
1247 for i in $PACKAGES_REPOSITORY/*.tazpkg; do
1248 (cd $WOK; cpio -i receipt files.list 2>/dev/null) < $i
1249 . $WOK/receipt
1250 mkdir -p $WOK/$PACKAGE/taz/$PACKAGE-$VERSION
1251 mv $WOK/receipt $WOK/files.list \
1252 $WOK/$PACKAGE/taz/$PACKAGE-$VERSION
1253 ln $WOK/$PACKAGE/taz/$PACKAGE-$VERSION/receipt $WOK/$PACKAGE
1254 done
1255 fi
1256 elif [ -z "$2" ]; then
1257 PACKAGES_REPOSITORY=$PACKAGES_REPOSITORY
1258 else
1259 if [ -d "$2" ]; then
1260 PACKAGES_REPOSITORY=$2
1261 else
1262 echo -e "\nUnable to find directory : $2\n"
1263 exit 0
1264 fi
1265 fi
1266 cd $PACKAGES_REPOSITORY
1267 # Remove old packages.list and md5sum, they will soon be rebuilt.
1268 rm -f packages.list packages.md5 packages.txt
1269 echo ""
1270 echo -e "\033[1mGenerating packages lists\033[0m"
1271 echo "================================================================================"
1272 echo -n "Repository path : $PACKAGES_REPOSITORY" && status
1273 # Generate packages.txt
1274 if [ "$textlist" == "yes" ]; then
1275 gen_textlist
1276 [ "$fakewok" == "" ] || rm -rf $fakewok
1277 fi
1278 echo -n "Creating the raw packages list... "
1279 ls -1 *.tazpkg > /tmp/packages.list
1280 sed -i s/'.tazpkg'/''/ /tmp/packages.list
1281 status
1282 echo -n "Building the md5sum for all packages... "
1283 md5sum *.tazpkg > packages.md5
1284 status
1285 mv /tmp/packages.list $PACKAGES_REPOSITORY
1286 echo "================================================================================"
1287 pkgs=`cat $PACKAGES_REPOSITORY/packages.list | wc -l`
1288 echo "$pkgs packages in the repository."
1289 echo ""
1290 ;;
1291 new-tree)
1292 # Just create a few directories and generate an empty receipt to prepare
1293 # the creation of a new package.
1295 check_for_package_on_cmdline
1296 if [ -d $WOK/$PACKAGE ]; then
1297 echo -e "\n$PACKAGE package tree already exists.\n"
1298 exit 0
1299 fi
1300 echo "Creating : $WOK/$PACKAGE"
1301 mkdir $WOK/$PACKAGE
1302 cd $WOK/$PACKAGE
1303 echo -n "Preparing the receipt..."
1305 # Default receipt begin.
1307 echo "# SliTaz package receipt." > receipt
1308 echo "" >> receipt
1309 echo "PACKAGE=\"$PACKAGE\"" >> receipt
1310 # Finish the empty receipt.
1311 cat >> receipt << "EOF"
1312 VERSION=""
1313 CATEGORY=""
1314 SHORT_DESC=""
1315 MAINTAINER=""
1316 DEPENDS=""
1317 TARBALL="$PACKAGE-$VERSION.tar.gz"
1318 WEB_SITE=""
1319 WGET_URL=""
1321 # Rules to configure and make the package.
1322 compile_rules()
1324 cd $src
1325 ./configure \
1326 --prefix=/usr \
1327 --infodir=/usr/share/info \
1328 --mandir=/usr/share/man \
1329 $CONFIGURE_ARGS &&
1330 make && make DESTDIR=$PWD/_pkg install
1333 # Rules to gen a SliTaz package suitable for Tazpkg.
1334 genpkg_rules()
1336 mkdir -p $fs/usr
1337 cp -a $_pkg/usr/bin $fs/usr
1340 EOF
1342 # Default receipt end.
1344 status
1345 # Interactive mode, asking and seding.
1346 if [ "$3" = "--interactive" ]; then
1347 echo "Entering in interactive mode..."
1348 echo "================================================================================"
1349 echo "Package : $PACKAGE"
1350 # Version.
1351 echo -n "Version : " ; read anser
1352 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
1353 # Category.
1354 echo -n "Category : " ; read anser
1355 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
1356 # Short description.
1357 echo -n "Short desc : " ; read anser
1358 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
1359 # Maintainer.
1360 echo -n "Maintainer : " ; read anser
1361 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
1362 # Web site.
1363 echo -n "Web site : " ; read anser
1364 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
1365 echo ""
1366 # Wget URL.
1367 echo "Wget URL to download source tarball."
1368 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
1369 echo -n "Wget url : " ; read anser
1370 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
1371 # Ask for a stuff dir.
1372 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
1373 if [ "$anser" = "y" ]; then
1374 echo -n "Creating the stuff directory..."
1375 mkdir stuff && status
1376 fi
1377 # Ask for a description file.
1378 echo -n "Are you going to write a description ? (y/N) : " ; read anser
1379 if [ "$anser" = "y" ]; then
1380 echo -n "Creating the description.txt file..."
1381 echo "" > description.txt && status
1382 fi
1383 echo "================================================================================"
1384 echo ""
1385 fi
1386 ;;
1387 remove)
1388 # Remove a package from the wok.
1390 check_for_package_on_cmdline
1391 echo ""
1392 echo -n "Please confirm deletion (y/N) : "; read anser
1393 if [ "$anser" = "y" ]; then
1394 echo -n "Removing $PACKAGE..."
1395 rm -rf $WOK/$PACKAGE && status
1396 echo ""
1397 fi
1398 ;;
1399 hgup)
1400 # Pull and update an Hg wok.
1401 if ls -l $WOK/.hg/hgrc | grep -q "root"; then
1402 check_root
1403 fi
1404 cd $WOK
1405 hg pull && hg update ;;
1406 maintainers)
1407 echo ""
1408 echo "List of maintainers for: $WOK"
1409 echo "================================================================================"
1410 touch /tmp/slitaz-maintainers
1411 for pkg in $WOK/*
1412 do
1413 . $pkg/receipt
1414 if ! grep -q "$MAINTAINER" /tmp/slitaz-maintainers; then
1415 echo "$MAINTAINER" >> /tmp/slitaz-maintainers
1416 echo "$MAINTAINER"
1417 fi
1418 done
1419 echo "================================================================================"
1420 echo "Maintainers: `cat /tmp/slitaz-maintainers | wc -l`"
1421 echo ""
1422 # Remove tmp files
1423 rm -f /tmp/slitaz-maintainers ;;
1424 maintained-by)
1425 # Search for packages maintained by a packagers.
1426 if [ ! -n "$2" ]; then
1427 echo "Specify a name or mail of a maintainer."
1428 exit 0
1429 fi
1430 echo "Maintainer packages"
1431 echo "================================================================================"
1432 for pkg in $WOK/*
1433 do
1434 . $pkg/receipt
1435 if echo "$MAINTAINER" | grep -q "$2"; then
1436 echo "$PACKAGE"
1437 packages=$(($packages+1))
1438 fi
1439 done
1440 echo "================================================================================"
1441 echo "Packages maintained by $2: $packages"
1442 echo "" ;;
1443 usage|*)
1444 # Print usage also for all unknown commands.
1446 usage
1447 ;;
1448 esac
1450 exit 0