tazwok view tazwok @ rev 98

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