tazwok view tazwok @ rev 177

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