tazwok view tazwok @ rev 173

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