tazwok view tazwok @ rev 93

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