tazwok view tazwok @ rev 168

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