tazwok view tazwok @ rev 107

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