tazwok view tazwok @ rev 183

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