tazwok view tazwok @ rev 96

cmp --cook: skip dependancy misses
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Oct 03 08:56:44 2008 +0000 (2008-10-03)
parents b46797cbef05
children 512988521ab9
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-2008 SliTaz - GNU General Public License.
10 #
11 VERSION=2.0
13 ####################
14 # Tazwok variables #
15 ####################
17 # Packages categories.
18 CATEGORIES="
19 base-system
20 x-window
21 utilities
22 network
23 graphics
24 multimedia
25 office
26 development
27 system-tools
28 security
29 games
30 misc
31 meta
32 non-free"
34 # Use words rather than numbers in the code.
35 COMMAND=$1
36 PACKAGE=$2
37 LIST=$2
39 # Include config file or exit if no file found.
40 if [ -f "./tazwok.conf" ]; then
41 . ./tazwok.conf
42 elif [ -f "/etc/tazwok.conf" ]; then
43 . /etc/tazwok.conf
44 else
45 echo -e "\nUnable to find the configuration file : /etc/tazwok.conf"
46 echo -e "Please read the Tazwok documentation.\n"
47 exit 0
48 fi
50 # Create Taz wok needed directories if user is root.
51 if test $(id -u) = 0 ; then
52 # Check for the wok directory.
53 if [ ! -d "$WOK" ]; then
54 echo "Creating the wok directory..."
55 mkdir -p $WOK
56 chmod 777 $WOK
57 fi
58 # Check for the packages repository.
59 if [ ! -d "$PACKAGES_REPOSITORY" ]; then
60 echo "Creating the packages repository..."
61 mkdir -p $PACKAGES_REPOSITORY
62 fi
63 # Check for the sources repository.
64 if [ ! -d "$SOURCES_REPOSITORY" ]; then
65 echo "Creating the sources repository..."
66 mkdir -p $SOURCES_REPOSITORY
67 fi
68 fi
70 # The path to the most important file used by Tazwok.
71 # The receipt is used to compile the source code and
72 # generate suitable packages for Tazpkg.
73 RECEIPT="$WOK/$PACKAGE/receipt"
75 # The path to the process log file.
76 LOG="$WOK/$PACKAGE/process.log"
78 ####################
79 # Tazwok functions #
80 ####################
82 # Print the usage (English).
83 usage ()
84 {
85 echo -e "\nSliTaz sources compiler and packages generator - Version: $VERSION\n
86 \033[1mUsage: \033[0m `basename $0` [command] [package|list|category|dir] [--option]
87 \033[1mCommands: \033[0m\n
88 usage Print this short usage.
89 stats Print Tazwok statistics from the config file and the wok.
90 cmp|compare Compare the wok and the cooked pkgs (--remove old pkgs).
91 list List all packages in the wok tree or by category.
92 info Get information about a package in the wok.
93 check Check every receipt for common errors.
94 check-log Check the process log file of a package.
95 search Search for a package in the wok by pattern or name.
96 compile Configure and build a package using the receipt rules.
97 genpkg Generate a suitable package for Tazpkg with the rules.
98 cook Compile and generate a package directly.
99 cook-list Cook all packages specified in the list by order.
100 clean Clean all generated files in the package tree.
101 new-tree Prepare a new package tree and receipt (--interactive).
102 gen-list Generate a packages list for a repository (--text).
103 gen-clean-wok Gen a clean wok in a dir ('clean-wok' cleans current wok).
104 remove Remove a package from the wok.\n"
105 }
107 # Status function.
108 status()
109 {
110 local CHECK=$?
111 echo -en "\\033[70G[ "
112 if [ $CHECK = 0 ]; then
113 echo -en "\\033[1;33mOK"
114 else
115 echo -en "\\033[1;31mFailed"
116 fi
117 echo -e "\\033[0;39m ]"
118 }
120 # Check if user is root.
121 check_root()
122 {
123 if test $(id -u) != 0 ; then
124 echo -e "\nYou must be root to run `basename $0` with this option."
125 echo -e "Please type 'su' and root password to become super-user.\n"
126 exit 0
127 fi
128 }
130 # Check for a package name on cmdline.
131 check_for_package_on_cmdline()
132 {
133 if [ -z "$PACKAGE" ]; then
134 echo -e "\nYou must specify a package name on the command line."
135 echo -e "Example : tazwok $COMMAND package\n"
136 exit 0
137 fi
138 }
140 # Check for the receipt of a package used to cook.
141 check_for_receipt()
142 {
143 if [ ! -f "$RECEIPT" ]; then
144 echo -e "\nUnable to find the receipt : $RECEIPT\n"
145 exit 0
146 fi
147 }
149 # Check for a specified file list on cmdline.
150 check_for_list()
151 {
152 if [ -z "$LIST" ]; then
153 echo -e "\nPlease specify the path to the list of packages to cook.\n"
154 exit 0
155 fi
156 # Check if the list of packages exists.
157 if [ -f "$LIST" ]; then
158 LIST=`cat $LIST`
159 else
160 echo -e "\nUnable to find $LIST packages list.\n"
161 exit 0
162 fi
163 }
165 # Check for the wanted package if specified in WANTED
166 # receipt variable. Set the $src/$_pkg variable to help compiling
167 # and generating packages.
168 check_for_wanted()
169 {
170 if [ ! "$WANTED" = "" ]; then
171 echo -n "Checking for the wanted package..."
172 if [ ! -d "$WOK/$WANTED" ]; then
173 echo -e "\nWanted package is missing in the work directory.\n"
174 exit 0
175 fi
176 # Checking for buildtree of Wanted package
177 if [ ! -d "$WOK/$WANTED/taz" ]; then
178 echo -e "\n\nSource files of wanted package is missing in the work directory."
179 echo -n "Would you like to build the missing package (y/N) ? " ; read anser
180 if [ "$anser" == "y" ]; then
181 tazwok cook $WANTED
182 else
183 echo -e "\nWanted package source tree is missing in the work directory.\n"
184 exit 0
185 fi
186 fi
187 status
188 # Set wanted src path.
189 src=$WOK/$WANTED/$WANTED-$VERSION
190 _pkg=$src/_pkg
191 fi
192 }
195 # Check for build dependencies, notify user and install if specified.
196 check_for_build_depends()
197 {
198 echo "Checking for build dependencies..."
199 for pkg in $BUILD_DEPENDS
200 do
201 if [ ! -d "/var/lib/tazpkg/installed/$pkg" ]; then
202 MISSING_PACKAGE=$pkg
203 fi
204 done
205 if [ ! "$MISSING_PACKAGE" = "" ]; then
206 echo "================================================================================"
207 for pkg in $BUILD_DEPENDS
208 do
209 if [ ! -d "/var/lib/tazpkg/installed/$pkg" ]; then
210 MISSING_PACKAGE=$pkg
211 echo "Missing : $pkg"
212 fi
213 done
214 echo "================================================================================"
215 echo "You can continue, exit or install missing dependencies."
216 echo -n "Install, continue or exit (install/y/N) ? "; read anser
217 case $anser in
218 install)
219 for pkg in $BUILD_DEPENDS
220 do
221 if [ ! -d "/var/lib/tazpkg/installed/$pkg" ]; then
222 tazpkg get-install $pkg
223 fi
224 done ;;
225 y|yes)
226 continue ;;
227 *)
228 exit 0 ;;
229 esac
230 fi
231 }
233 # Check for loop in deps tree.
234 check_for_deps_loop()
235 {
236 local list
237 local pkg
238 local deps
239 pkg=$1
240 shift
241 [ -n "$1" ] || return
242 list=""
243 # Filter out already processed deps
244 for i in $@; do
245 case " $ALL_DEPS" in
246 *\ $i\ *);;
247 *) list="$list $i";;
248 esac
249 done
250 ALL_DEPS="$ALL_DEPS$list "
251 for i in $list; do
252 [ -f $i/receipt ] || continue
253 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
254 case " $deps " in
255 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
256 *) check_for_deps_loop $pkg $deps;;
257 esac
258 done
259 }
261 download()
262 {
263 for file in $@; do
264 wget $file && break
265 done
266 }
268 # Configure and make a package with the receipt.
269 compile_package()
270 {
271 check_for_package_on_cmdline
272 # Include the receipt to get all needed variables and functions
273 # and cd into the work directory to start the work.
274 check_for_receipt
275 . $RECEIPT
276 # Log the package name and date.
277 echo "date `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
278 echo "package $PACKAGE (compile)" >> $LOG
279 # Set wanted $src variable to help compiling.
280 if [ ! "$SOURCE" = "" ]; then
281 src=$WOK/$PACKAGE/$SOURCE-$VERSION
282 else
283 src=$WOK/$PACKAGE/$PACKAGE-$VERSION
284 fi
285 check_for_build_depends
286 check_for_wanted
287 echo ""
288 echo "Starting to cook $PACKAGE..."
289 echo "================================================================================"
290 # Check for src tarball and wget if needed.
291 if [ ! "$WGET_URL" = "" ]; then
292 echo "Checking for source tarball... "
293 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
294 cd $SOURCES_REPOSITORY
295 download $WGET_URL
296 #wget $WGET_URL
297 # Exit if download failed to avoid errors.
298 if [ ! -f "$SOURCES_REPOSITORY/$TARBALL" ]; then
299 echo -e "\nDownload failed, exiting. Please check WGET_URL variable.\n"
300 exit 1
301 fi
302 else
303 echo -n "Source tarball exit... "
304 status
305 fi
306 # Untaring source if necessary. We don't need to extract source if
307 # the package is built with a wanted source package.
308 if [ "$WANTED" = "" ]; then
309 if [ ! -d $src ]; then
310 # Log process.
311 echo "untaring $TARBALL" >> $LOG
312 echo -n "Untaring $TARBALL... "
313 case "$TARBALL" in
314 *zip) ( cd $WOK/$PACKAGE; unzip $SOURCES_REPOSITORY/$TARBALL );;
315 *bz2) tar xjf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
316 *tar) tar xf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
317 *Z) tar xZf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
318 *) tar xzf $SOURCES_REPOSITORY/$TARBALL -C $WOK/$PACKAGE;;
319 esac
320 status
321 # Permissions settings
322 chown -R root.root $WOK/$PACKAGE/$PACKAGE-* 2>/dev/null
323 chown -R root.root $WOK/$PACKAGE/$SOURCE-* 2>/dev/null
324 else
325 echo -n "Source direcory exit... " && status
326 fi
327 fi
328 fi
329 cd $WOK/$PACKAGE
330 # Log and execute compile_rules function if it exists, to configure and
331 # make the package if it exists.
332 if grep -q ^compile_rules $RECEIPT; then
333 echo "executing compile_rules" >> $LOG
334 compile_rules
335 # Exit if compilation failed so the binary package
336 # is not generated when using the cook comand.
337 local CHECK=$?
338 if [ $CHECK = 0 ]; then
339 echo "================================================================================"
340 echo "$PACKAGE compiled on : `date +%Y%m%d\ \%H:%M:%S`"
341 echo ""
342 echo "compilation done : `date +%Y%m%d\ \%H:%M:%S`" >> $LOG
343 else
344 echo "================================================================================"
345 echo "Compilation failed. Please read the compilator output."
346 echo "" && exit 1
347 fi
348 else
349 echo "no compile_rules" >> $LOG
350 echo -e "No compile rules for $PACKAGE...\n"
351 fi
352 }
354 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
355 # so some packages need to copy these files with the receipt and genpkg_rules.
356 # This function is executed by gen_package when 'tazwok genpkg'.
357 copy_generic_files()
358 {
359 # In most cases, locales are in $_pkg/usr/share/locale so we copy files
360 # using generic variables and $LOCALE from Tazwok config file.
361 if [ ! "$LOCALE" = "" ]; then
362 if [ -d "$_pkg/usr/share/locale" ]; then
363 for i in $LOCALE
364 do
365 if [ -d "$_pkg/usr/share/locale/$i" ]; then
366 mkdir -p $fs/usr/share/locale
367 cp -a $_pkg/usr/share/locale/$i $fs/usr/share/locale
368 fi
369 done
370 fi
371 fi
372 # Pixmaps (PNG or/and XPM only). Some icons/images can be added through
373 # genpkg_rules and generic copy can be disabled with GENERIC_PIXMAPS="no"
374 # in pkg receipt.
375 if [ ! "$GENERIC_PIXMAPS" = "no" ]; then
376 if [ -d "$_pkg/usr/share/pixmaps" ]; then
377 mkdir -p $fs/usr/share/pixmaps
378 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.png \
379 $fs/usr/share/pixmaps 2>/dev/null
380 cp -a $_pkg/usr/share/pixmaps/$PACKAGE.xpm \
381 $fs/usr/share/pixmaps 2>/dev/null
382 fi
383 # Custom or homemade PNG pixmap can be in stuff.
384 if [ -f "stuff/$PACKAGE.png" ]; then
385 mkdir -p $fs/usr/share/pixmaps
386 cp -a stuff/$PACKAGE.png $fs/usr/share/pixmaps
387 fi
388 fi
389 # Desktop entry (.desktop).
390 if [ -d "$_pkg/usr/share/applications" ]; then
391 cp -a $_pkg/usr/share/applications $fs/usr/share
392 fi
393 # Homemade desktop file(s) can be in stuff.
394 if [ -d "stuff/applications" ]; then
395 mkdir -p $fs/usr/share
396 cp -a stuff/applications $fs/usr/share
397 fi
398 if [ -f "stuff/$PACKAGE.desktop" ]; then
399 mkdir -p $fs/usr/share/applications
400 cp -a stuff/$PACKAGE.desktop $fs/usr/share/applications
401 fi
402 }
404 # Find and strip : --strip-all (-s) or --strip-debug on static libs.
405 strip_package()
406 {
407 echo -n "Executing strip on all files..."
408 # Binaries.
409 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
410 do
411 if [ -d "$dir" ]; then
412 find $dir -type f -exec strip -s '{}' 2>/dev/null \;
413 fi
414 done
415 # Libraries.
416 find $fs -name "*.so*" -exec strip -s '{}' 2>/dev/null \;
417 find $fs -name "*.a" -exec strip --strip-debug '{}' 2>/dev/null \;
418 status
419 }
421 # Create a package tree and build the gziped cpio archive
422 # to make a SliTaz (.tazpkg) package.
423 gen_package()
424 {
425 check_root
426 check_for_package_on_cmdline
427 check_for_receipt
428 EXTRAVERSION=""
429 . $RECEIPT
430 # May compute VERSION
431 if grep -q ^get_version $RECEIPT; then
432 get_version
433 fi
434 check_for_wanted
435 cd $WOK/$PACKAGE
436 # Remove old Tazwok package files.
437 if [ -d "taz" ]; then
438 rm -rf taz
439 fi
440 # Create the package tree and set useful variables.
441 mkdir -p taz/$PACKAGE-$VERSION/fs
442 fs=taz/$PACKAGE-$VERSION/fs
443 # Set $src for standard package and $_pkg variables.
444 if [ "$WANTED" = "" ]; then
445 src=$WOK/$PACKAGE/$PACKAGE-$VERSION
446 _pkg=$src/_pkg
447 fi
448 if [ ! "$SOURCE" = "" ]; then
449 src=$WOK/$PACKAGE/$SOURCE-$VERSION
450 _pkg=$src/_pkg
451 fi
452 cd $WOK/$PACKAGE
453 # Execute genpkg_rules and copy generic files to build the package.
454 echo ""
455 echo "Building $PACKAGE with the receipt..."
456 echo "================================================================================"
457 if grep -q ^genpkg_rules $RECEIPT; then
458 # Log process.
459 echo "executing genpkg_rules" >> $LOG
460 genpkg_rules
461 cd $WOK/$PACKAGE
462 # Skip generic files for packages with a WANTED variable
463 # (dev and splited pkgs).
464 if [ ! "$WANTED" = "" ]; then
465 continue
466 else
467 copy_generic_files
468 fi
469 strip_package
470 else
471 echo "No package rules to gen $PACKAGE..."
472 exit 1
473 fi
474 # Copy the receipt and description (if exists) in the binary package tree.
475 cd $WOK/$PACKAGE
476 echo -n "Copying the receipt..."
477 cp receipt taz/$PACKAGE-$VERSION
478 status
479 if grep -q ^get_version $RECEIPT; then
480 echo -n "Update version in receipt..."
481 sed -i "s/^VERSION=.*/VERSION=\"$VERSION\"/" \
482 taz/$PACKAGE-$VERSION/receipt
483 status
484 fi
485 if [ -f "description.txt" ]; then
486 echo -n "Copying the description file..."
487 cp description.txt taz/$PACKAGE-$VERSION
488 status
489 fi
490 # Create the files.list by redirecting find output.
491 echo -n "Creating the list of files..."
492 cd taz/$PACKAGE-$VERSION
493 LAST_FILE=""
494 ( find fs -print; echo ) | while read file; do
495 if [ "$LAST_FILE" != "" ]; then
496 case "$file" in
497 $LAST_FILE/*)
498 case "$(ls -ld "$LAST_FILE")" in
499 drwxr-xr-x\ *\ root\ *\ root\ *);;
500 *) echo ${LAST_FILE#fs};;
501 esac;;
502 *) echo ${LAST_FILE#fs};;
503 esac
504 fi
505 LAST_FILE="$file"
506 done > files.list
507 status
508 if [ -z "$EXTRAVERSION" ]; then
509 case "$PACKAGE" in
510 linux*);;
511 *) EXTRAVERSION="$(grep '/lib/modules/.*-slitaz/' files.list |\
512 head -1 | sed 's|/lib/modules/\(.*\)-slitaz/.*|_\1|')";;
513 esac
514 fi
515 rm -f $PACKAGES_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg 2> /dev/null
516 echo -n "Creating md5sum of files..."
517 while read file; do
518 [ -L "fs$file" ] && continue
519 [ -f "fs$file" ] || continue
520 md5sum "fs$file" | sed 's/ fs/ /'
521 done < files.list > md5sum
522 status
523 [ -s md5sum ] || rm -f md5sum
524 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
525 2> /dev/null | awk '{ sz=$1 } END { print sz }')
526 # Build cpio archives. Find, cpio and gzip the fs, finish by
527 # removing the fs tree.
528 echo -n "Compressing the fs... "
529 find fs -print | cpio -o -H newc | gzip > fs.cpio.gz && rm -rf fs
530 PACKED_SIZE=$(du -chs fs.cpio.gz receipt files.list md5sum \
531 description.txt 2> /dev/null | awk '{ sz=$1 } END { print sz }')
532 echo -n "Undating receipt sizes..."
533 sed -i s/^PACKED_SIZE.*$// receipt
534 sed -i s/^UNPACKED_SIZE.*$// receipt
535 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
536 sed -i "s/^VERSION=$/VERSION=\"$VERSION\"/" receipt
537 status
538 if [ -n "$EXTRAVERSION" ]; then
539 echo -n "Undating receipt EXTRAVERSION..."
540 sed -i s/^EXTRAVERSION.*$// receipt
541 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
542 status
543 fi
544 echo -n "Creating full cpio archive... "
545 find . -print | cpio -o -H newc > $PACKAGES_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
546 # Restore package tree incase we want to browse it.
547 echo -n "Restoring original package tree... "
548 zcat fs.cpio.gz | cpio -id
549 rm fs.cpio.gz && cd ..
550 # Log process.
551 echo "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg (done)" >> $LOG
552 echo "================================================================================"
553 echo "Package $PACKAGE ($VERSION$EXTRAVERSION) generated."
554 echo "Size : `du -sh $PACKAGES_REPOSITORY/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
555 echo ""
556 }
558 # Optional text packages list for gen-list.
559 gen_textlist()
560 {
561 rm -f packages.desc
562 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
563 echo -n "Creating the text packages list... "
564 cat >> packages.txt << _EOT_
565 # SliTaz GNU/Linux - Packages list
566 #
567 # Packages : _packages_
568 # Date : $DATE
569 #
570 _EOT_
571 for pkg in $WOK/*
572 do
573 PACKAGE=""
574 PACKED_SIZE=""
575 if [ -f $pkg/taz/*/receipt ]; then
576 . $pkg/taz/*/receipt
577 else
578 . $pkg/receipt
579 fi
580 cat >> packages.txt << _EOT_
582 $PACKAGE
583 $VERSION
584 $SHORT_DESC
585 _EOT_
586 if [ -n "$PACKED_SIZE" ]; then
587 cat >> packages.txt << _EOT_
588 $PACKED_SIZE ($UNPACKED_SIZE installed)
589 _EOT_
590 fi
591 # packages.desc is used by Tazpkgbox <tree>.
592 echo "$PACKAGE | $VERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" >> packages.desc
593 packages=$(($packages+1))
594 done && status
595 echo -n "Creating the text files list... "
596 for pkg in $WOK/*
597 do
598 if [ -f $pkg/taz/*/files.list ]; then
599 . $pkg/taz/*/receipt
600 ( echo "$PACKAGE"; cat $pkg/taz/*/files.list ) | awk '
601 BEGIN { name="" } { if (name == "") name=$0; else printf("%s: %s\n",name,$0); }'
602 else
603 echo "No files_list in $pkg" 1>&2
604 fi
605 done | lzma e files.list.lzma -si && status
606 sed -i s/"_packages_"/"$packages"/ packages.txt
607 }
609 # Return the date of the last commit in seconds since Jan 1 1970
610 hgdate()
611 {
612 local pkg
613 local date
614 local mon
615 # Default date is Jan 1 1970
616 [ -d $WOK/.hg -a -x /usr/bin/hg ] || { echo "0"; return; }
617 pkg=$(basename $1)
618 # Get date for last commit
619 date="$( cd $WOK; hg log $(find $pkg/receipt $pkg/stuff -type f \
620 2> /dev/null) | grep date: | head -1 | cut -c 6-)"
621 case "$(echo $date | awk '{ print $2 }')" in
622 Jan) mon="01";; Feb) mon="02";; Mar) mon="03";; Apr) mon="04";;
623 May) mon="05";; Jun) mon="06";; Jul) mon="07";; Aug) mon="08";;
624 Sep) mon="09";; Oct) mon="10";; Nov) mon="11";; Dec) mon="12";;
625 esac
626 # Reformat, don't mind about TZ: we look for days or months delta
627 echo $date | sed "s|[^ ]* [^ ]* \\(.*\\) \\(.*\\):\\(.*\\):\\(.*\\) \\(.*\\) .*|$mon\1\2\3\5|"
628 }
630 ###################
631 # Tazwok commands #
632 ###################
634 case "$COMMAND" in
635 stats)
636 # Tazwok general statistics from the config file the wok.
637 #
638 echo ""
639 echo -e "\033[1mTazwok configuration statistics\033[0m
640 ================================================================================
641 Wok directory : $WOK
642 Packages repository : $PACKAGES_REPOSITORY
643 Sources repository : $SOURCES_REPOSITORY
644 Packages in the wok : `ls -1 $WOK | wc -l`
645 Cooked packages : `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l`
646 ================================================================================"
647 echo ""
648 ;;
649 check)
650 # Check wok consistancy
651 echo ""
652 echo -e "\033[1mWok and packages checking\033[0m
653 ================================================================================"
654 cd $WOK
655 for pkg in $(ls)
656 do
657 [ -f $pkg/receipt ] || continue
658 PACKAGE=""
659 VERSION=""
660 CATEGORY=""
661 SHORT_DESC=""
662 MAINTAINER=""
663 WEB_SITE=""
664 DEPENDS=""
665 BUILD_DEPENDS=""
666 . $pkg/receipt
667 [ "$PACKAGE" = "$pkg" ] || echo "Package $PACKAGE should be $pkg"
668 [ -n "$VERSION" ] || echo "Package $PACKAGE has no VERSION"
669 if [ -n "$CATEGORY" ]; then
670 case " $(echo $CATEGORIES) " in
671 *\ $CATEGORY\ *);;
672 *) echo "Package $PACKAGE has can invalid CATEGORY";;
673 esac
674 else
675 echo"Package $PACKAGE has no CATEGORY"
676 fi
677 [ -n "$SHORT_DESC" ] || echo "Package $PACKAGE has no SHORT_DESC"
678 [ -n "$MAINTAINER" ] || echo "Package $PACKAGE has no MAINTAINER"
679 [ -n "$WEB_SITE" ] || echo "Package $PACKAGE has no WEB_SITE"
680 case "$MAINTAINER" in
681 *\<*|*\>*) echo "Package $PACKAGE has an invalid MAINTAINER: $MAINTAINER";;
682 esac
683 case "$MAINTAINER" in
684 *@*);;
685 *) echo "Package $PACKAGE MAINTAINER is not an email address";;
686 esac
687 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n"
688 for i in $DEPENDS; do
689 [ -d $i ] && continue
690 echo -e "$MSG $i"
691 MSG=""
692 done
693 MSG="Missing build dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n"
694 for i in $BUILD_DEPENDS; do
695 [ -d $i ] && continue
696 echo -e "$MSG $i"
697 MSG=""
698 done
699 MSG="Dependencies loop between $PACKAGE and :\n"
700 ALL_DEPS=""
701 check_for_deps_loop $PACKAGE $DEPENDS
702 done
703 ;;
704 cmp|compare)
705 # Compare the wok and packages repository to help with maintaining
706 # a mirror.
707 echo ""
708 echo -e "\033[1mWok and packages comparison\033[0m
709 ================================================================================"
710 for pkg in $WOK/*
711 do
712 . $pkg/receipt
713 echo "$PACKAGE-$VERSION.tazpkg" >> /tmp/wok.list.$$
714 tpkg="$(ls $PACKAGES_REPOSITORY/$PACKAGE-$VERSION*.tazpkg 2> /dev/null)"
715 if [ -z "$tpkg" ]; then
716 echo "Missing package: $PACKAGE ($VERSION)"
717 echo "$PACKAGE" >> /tmp/pkgs.missing.$$
718 elif [ -f $pkg/taz/*/receipt -a ! -f $pkg/taz/*/md5sum ]; then
719 echo "Obsolete package: $PACKAGE ($VERSION)"
720 echo "$PACKAGE" >> /tmp/pkgs.missing.$$
721 else
722 srcdate=$(hgdate $pkg)
723 pkgdate=$(date -u -r $tpkg '+%m%d%H%M%Y')
724 if [ $(date -d $pkgdate +%s) -lt $(date -d $srcdate +%s) ]; then
725 echo "Rebuild package: $PACKAGE ($VERSION) cooked $(date -d $pkgdate "+%x %X"), modified $(date -d $srcdate "+%x %X")"
726 echo "$PACKAGE" >> /tmp/pkgs.missing.$$
727 else
728 continue
729 fi
730 fi
731 if [ "$2" = "--cook" ]; then
732 yes '' | tazwok cook $PACKAGE
733 fi
734 done
735 for pkg in `cd $PACKAGES_REPOSITORY && ls *.tazpkg`
736 do
737 # grep $pkg in /tmp/wok.list.$$
738 # may include EXTRAVERSION or computed VERSION
739 for i in $(grep ^${pkg%-*} /tmp/wok.list.$$); do
740 case "$pkg" in
741 ${i%.tazpkg}*.tazpkg) continue 2;;
742 esac
743 done
744 # Not found
745 echo $pkg >> /tmp/pkgs.old.$$
746 if [ "$2" = "--remove" ]; then
747 echo "Removing package: $pkg"
748 rm $PACKAGES_REPOSITORY/$pkg
749 else
750 echo "Old package: $pkg"
751 fi
752 done
753 cd /tmp
754 echo "================================================================================"
755 echo "Wok: `cat wok.list.$$ | wc -l` - \
756 Cooked: `ls -1 $PACKAGES_REPOSITORY/*.tazpkg 2>/dev/null | wc -l` - \
757 Missing: `cat pkgs.missing.$$ 2>/dev/null | wc -l` - \
758 Old: `cat pkgs.old.$$ 2>/dev/null | wc -l`"
759 echo ""
760 rm -f wok.list.$$ pkgs.old.$$ pkgs.missing.$$
761 ;;
762 list)
763 # List packages in wok directory. User can specifiy a category
764 #
765 if [ "$2" = "category" ]; then
766 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
767 exit 0
768 fi
769 # Check for an asked category.
770 if [ -n "$2" ]; then
771 ASKED_CATEGORY=$2
772 echo ""
773 echo -e "\033[1mPackages in category :\033[0m $ASKED_CATEGORY"
774 echo "================================================================================"
775 for pkg in $WOK/*
776 do
777 . $pkg/receipt
778 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
779 echo -n "$PACKAGE"
780 echo -e "\033[28G $VERSION"
781 packages=$(($packages+1))
782 fi
783 done
784 echo "================================================================================"
785 echo -e "$packages packages in category $ASKED_CATEGORY.\n"
786 else
787 # By default list all packages and version.
788 echo ""
789 echo -e "\033[1mList of packages in the wok\033[0m"
790 echo "================================================================================"
791 for pkg in $WOK/*
792 do
793 . $pkg/receipt
794 echo -n "$PACKAGE"
795 echo -en "\033[28G $VERSION"
796 echo -e "\033[42G $CATEGORY"
797 packages=$(($packages+1))
798 done
799 echo "================================================================================"
800 echo -e "$packages packages available in the wok.\n"
801 fi
802 ;;
803 info)
804 # Information about a package.
805 #
806 check_for_package_on_cmdline
807 check_for_receipt
808 . $WOK/$PACKAGE/receipt
809 echo ""
810 echo -e "\033[1mTazwok package information\033[0m
811 ================================================================================
812 Package : $PACKAGE
813 Version : $VERSION
814 Category : $CATEGORY
815 Short desc : $SHORT_DESC
816 Maintainer : $MAINTAINER"
817 if [ ! "$WEB_SITE" = "" ]; then
818 echo "Web site : $WEB_SITE"
819 fi
820 if [ ! "$DEPENDS" = "" ]; then
821 echo "Depends : $DEPENDS"
822 fi
823 if [ ! "$WANTED" = "" ]; then
824 echo "Wanted src : $WANTED"
825 fi
826 echo "================================================================================"
827 echo ""
829 ;;
830 check-log)
831 # We just cat the file log to view process info.
832 #
833 if [ ! -f "$LOG" ]; then
834 echo -e "\nNo process log found. The package is probably not cooked.\n"
835 exit 0
836 else
837 echo ""
838 echo -e "\033[1mPackage process log for :\033[0m $PACKAGE"
839 echo "================================================================================"
840 cat $LOG
841 echo "================================================================================"
842 echo ""
843 fi
844 ;;
845 search)
846 # Search for a package by pattern or name.
847 #
848 if [ -z "$2" ]; then
849 echo -e "\nPlease specify a pattern or a package name to search."
850 echo -e "Example : 'tazwok search gcc'.\n"
851 exit 0
852 fi
853 echo ""
854 echo -e "\033[1mSearch result for :\033[0m $2"
855 echo "================================================================================"
856 list=`ls -1 $WOK | grep $2`
857 for pkg in $list
858 do
859 . $WOK/$pkg/receipt
860 echo -n "$PACKAGE "
861 echo -en "\033[24G $VERSION"
862 echo -e "\033[42G $CATEGORY"
863 packages=$(($packages+1))
864 done
865 echo "================================================================================"
866 echo "$packages packages found for : $2"
867 echo ""
868 ;;
869 compile)
870 # Configure and make a package with the receipt.
871 #
872 compile_package
873 ;;
874 genpkg)
875 # Generate a package
876 #
877 gen_package
878 ;;
879 cook)
880 # Compile and generate a package. Just execute tazwok with
881 # the good commands.
882 #
883 check_root
884 compile_package
885 gen_package
886 ;;
887 cook-list)
888 # Cook all packages listed in a file. The path to the cooklist must
889 # be specified on the cmdline.
890 #
891 check_root
892 check_for_list
893 for pkg in $LIST
894 do
895 tazwok compile $pkg
896 tazwok genpkg $pkg
897 done
898 ;;
899 clean)
900 # Clean up a package work directory.
901 #
902 check_for_package_on_cmdline
903 check_for_receipt
904 . $RECEIPT
905 cd $WOK/$PACKAGE
906 echo ""
907 echo "Cleaning $PACKAGE..."
908 echo "================================================================================"
909 # Check for clean_wok function.
910 if grep -q ^clean_wok $RECEIPT; then
911 clean_wok
912 fi
913 # Remove taz/ and source tree if exists.
914 if [ -d "taz" ]; then
915 echo -n "Removing taz files..."
916 rm -rf taz
917 status
918 fi
919 for i in $PACKAGE-$VERSION $SOURCE-$VERSION ; do
920 [ -e "$i" ] || continue
921 echo -n "Removing source files..."
922 if [ -L $i ]; then
923 target=$(readlink $i)
924 [ -d "$target" ] && case "$target" in
925 /*|.|./*|..|../*);;
926 *) rm -rf $target;;
927 esac
928 fi
929 rm -rf $i
930 status
931 done
932 # Remove an envental $PACKAGE-build directory.
933 if [ -d "$PACKAGE-build" ]; then
934 echo -n "Removing build tree..."
935 rm -rf $PACKAGE-build && status
936 fi
937 # Remove process log file.
938 if [ -f "process.log" ]; then
939 echo -n "Removing process log file..."
940 rm process.log && status
941 echo "================================================================================"
942 fi
943 echo "$PACKAGE is clean. You can cook it again..."
944 echo ""
945 ;;
946 gen-clean-wok)
947 # Generate a clean wok from the current wok by copying all receipt
948 # and stuff directory.
949 #
950 if [ -z "$2" ]; then
951 echo -e "\nPlease specify the destination for the new clean wok.\n"
952 exit 0
953 else
954 dest=$2
955 mkdir -p $dest
956 fi
957 echo "New wok is going to : $dest"
958 for pkg in `ls -1 $WOK`
959 do
960 echo "----"
961 echo -n "Preparing $pkg..."
962 mkdir -p $dest/$pkg
963 status
964 echo -n "Copying the receipt..."
965 cp -a $WOK/$pkg/receipt $dest/$pkg
966 status
967 if [ -d "$WOK/$pkg/stuff" ]; then
968 echo -n "Copying all the stuff directory..."
969 cp -a $WOK/$pkg/stuff $dest/$pkg
970 status
971 fi
972 done
973 echo "================================================================================"
974 echo "Clean wok generated in : $dest"
975 echo "Packages cleaned : `ls -1 $dest | wc -l`"
976 echo ""
977 ;;
978 clean-wok)
979 # Clean all packages in the work directory
980 #
981 for pkg in `ls -1 $WOK`
982 do
983 tazwok clean $pkg
984 done
985 echo "================================================================================"
986 echo "`ls -1 $WOK | wc -l` packages cleaned."
987 echo ""
988 ;;
989 gen-list)
990 # Sed is used to remove all the .tazpkg extensions from the
991 # packages.list. The directory to move in by default is the repository
992 # if $2 is not empty cd into $2. A text packages list can also be gen
993 # with the option --text.
994 #
995 if [ "$2" == "--text" ]; then
996 textlist="yes"
997 elif [ -z "$2" ]; then
998 PACKAGES_REPOSITORY=$PACKAGES_REPOSITORY
999 else
1000 if [ -d "$2" ]; then
1001 PACKAGES_REPOSITORY=$2
1002 else
1003 echo -e "\nUnable to find directory : $2\n"
1004 exit 0
1005 fi
1006 fi
1007 cd $PACKAGES_REPOSITORY
1008 # Remove old packages.list and md5sum, they will soon be rebuilt.
1009 rm -f packages.list packages.md5 packages.txt
1010 echo ""
1011 echo -e "\033[1mGenerating packages lists\033[0m"
1012 echo "================================================================================"
1013 echo -n "Repository path : $PACKAGES_REPOSITORY" && status
1014 # Generate packages.txt
1015 if [ "$textlist" == "yes" ]; then
1016 gen_textlist
1017 fi
1018 echo -n "Creating the raw packages list... "
1019 ls -1 *.tazpkg > /tmp/packages.list
1020 sed -i s/'.tazpkg'/''/ /tmp/packages.list
1021 status
1022 echo -n "Building the md5sum for all packages... "
1023 md5sum * > packages.md5
1024 status
1025 mv /tmp/packages.list $PACKAGES_REPOSITORY
1026 echo "================================================================================"
1027 pkgs=`cat $PACKAGES_REPOSITORY/packages.list | wc -l`
1028 echo "$pkgs packages in the repository."
1029 echo ""
1030 ;;
1031 new-tree)
1032 # Just create a few directories and generate an empty receipt to prepare
1033 # the creation of a new package.
1035 check_for_package_on_cmdline
1036 if [ -d $WOK/$PACKAGE ]; then
1037 echo -e "\n$PACKAGE package tree already exists.\n"
1038 exit 0
1039 fi
1040 echo "Creating : $WOK/$PACKAGE"
1041 mkdir $WOK/$PACKAGE
1042 cd $WOK/$PACKAGE
1043 echo -n "Preparing the receipt..."
1045 # Default receipt begin.
1047 echo "# SliTaz package receipt." > receipt
1048 echo "" >> receipt
1049 echo "PACKAGE=\"$PACKAGE\"" >> receipt
1050 # Finish the empty receipt.
1051 cat >> receipt << "EOF"
1052 VERSION=""
1053 CATEGORY=""
1054 SHORT_DESC=""
1055 MAINTAINER=""
1056 DEPENDS=""
1057 TARBALL="$PACKAGE-$VERSION.tar.gz"
1058 WEB_SITE=""
1059 WGET_URL=""
1061 # Rules to configure and make the package.
1062 compile_rules()
1064 cd $src
1065 ./configure --prefix=/usr --infodir=/usr/share/info \
1066 --mandir=/usr/share/man $CONFIGURE_ARGS && \
1067 make && make DESTDIR=$PWD/_pkg install
1070 # Rules to gen a SliTaz package suitable for Tazpkg.
1071 genpkg_rules()
1073 mkdir -p $fs/usr
1074 cp -a $_pkg/usr/bin $fs/usr
1077 EOF
1079 # Default receipt end.
1081 status
1082 # Interactive mode, asking and seding.
1083 if [ "$3" = "--interactive" ]; then
1084 echo "Entering in interactive mode..."
1085 echo "================================================================================"
1086 echo "Package : $PACKAGE"
1087 # Version.
1088 echo -n "Version : " ; read anser
1089 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
1090 # Category.
1091 echo -n "Category : " ; read anser
1092 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
1093 # Short description.
1094 echo -n "Short desc : " ; read anser
1095 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
1096 # Maintainer.
1097 echo -n "Maintainer : " ; read anser
1098 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
1099 # Web site.
1100 echo -n "Web site : " ; read anser
1101 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
1102 echo ""
1103 # Wget URL.
1104 echo "Wget URL to download source tarball."
1105 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
1106 echo -n "Wget url : " ; read anser
1107 sed -i s#'WGET_URL=\"\"'#"WGET_URL=\"$anser\""# receipt
1108 # Ask for a stuff dir.
1109 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
1110 if [ "$anser" = "y" ]; then
1111 echo -n "Creating the stuff directory..."
1112 mkdir stuff && status
1113 fi
1114 # Ask for a description file.
1115 echo -n "Are you going to write a description ? (y/N) : " ; read anser
1116 if [ "$anser" = "y" ]; then
1117 echo -n "Creating the description.txt file..."
1118 echo "" > description.txt && status
1119 fi
1120 echo "================================================================================"
1121 echo ""
1122 fi
1123 ;;
1124 remove)
1125 # Remove a package from the wok.
1127 check_for_package_on_cmdline
1128 echo ""
1129 echo -n "Please confirm deletion (y/N) : "; read anser
1130 if [ "$anser" = "y" ]; then
1131 echo -n "Removing $PACKAGE..."
1132 rm -rf $WOK/$PACKAGE && status
1133 echo ""
1134 fi
1135 ;;
1136 usage|*)
1137 # Print usage also for all unknown commands.
1139 usage
1140 ;;
1141 esac
1143 exit 0