tazpkg view tazpkg @ rev 49

Adding missing DEFAULT_MIRROR variable
author Eric Joseph-Alexandre <erjo@slitaz.org>
date Mon Feb 25 15:46:36 2008 +0100 (2008-02-25)
parents 3071a3b8b089
children 96905f55b36b
line source
1 #!/bin/sh
2 # Tazpkg - Tiny autonomus zone packages manager.
3 #
4 # This is a lightwight packages manager for *.tazpkg files, all written in
5 # SHell script. It works well with Busybox ash shell and bash. Tazpkg let you
6 # list, install, remove, download or get information about a package, you can
7 # use 'tazpkg usage' to get a list of commands with a short description. Tazpkg
8 # also relolv dependencies and can upgrade packages from a mirror.
9 #
10 # (C) 2007-2008 SliTaz - GNU General Public License v3.
11 #
12 # Authors : Christophe Lincoln <pankso@slitaz.org>
13 # Pascal Bellard <pascal.bellard@slitaz.org>
14 #
15 VERSION=1.8
17 ####################
18 # Script variables #
19 ####################
21 # Packages categories.
22 CATEGORIES="
23 base-system
24 utilities
25 network
26 graphics
27 multimedia
28 office
29 development
30 system-tools
31 security
32 games
33 misc
34 meta"
36 # Initialize some variables to use words
37 # rater than numbers for functions and actions.
38 COMMAND=$1
39 if [ -f "$2" ]; then
40 # Set pkg basename for install, extract
41 PACKAGE=$(basename ${2%.tazpkg} 2>/dev/null)
42 else
43 # Pkg name for remove, search and all other cmds
44 PACKAGE=${2%.tazpkg}
45 fi
46 PACKAGE_FILE=$2
47 TARGET_DIR=$3
48 TOP_DIR=`pwd`
49 TMP_DIR=/tmp/tazpkg-$$-$RANDOM
51 # Path to tazpkg used dir and configuration files
52 LOCALSTATE=/var/lib/tazpkg
53 INSTALLED=$LOCALSTATE/installed
54 CACHE_DIR=/var/cache/tazpkg
55 MIRROR=$LOCALSTATE/mirror
56 PACKAGES_LIST=$LOCALSTATE/packages.list
57 BLOCKED=$LOCALSTATE/blocked-packages.list
58 DEFAULT_MIRROR="http://download.tuxfamily.org/slitaz/packages/`cat /etc/slitaz-release`/"
60 # Bold red warnig for upgrade.
61 WARNING="\\033[1;31mWARNING\\033[0;39m"
63 # Check if the directories and files used by Tazpkg
64 # exists. If not and user is root we creat them.
65 if test $(id -u) = 0 ; then
66 if [ ! -d "$CACHE_DIR" ]; then
67 mkdir -p $CACHE_DIR
68 fi
69 if [ ! -d "$INSTALLED" ]; then
70 mkdir -p $INSTALLED
71 fi
72 if [ ! -f "$LOCALSTATE/mirror" ]; then
73 echo "$DEFAULT_MIRROR" > $LOCALSTATE/mirror
74 fi
75 fi
77 ####################
78 # Script functions #
79 ####################
81 # Print the usage.
82 usage ()
83 {
84 echo -e "SliTaz packages manager - Version: $VERSION
85 \033[1mUsage: \033[0m tazpkg [command] [package|dir|pattern|list|cat|--opt] [dir|--opt]
86 \033[1mCommands: \033[0m
87 usage Print this short usage.
88 list List installed packages on the system by category or all.
89 xhtml-list Creat a xHTML list of installed packges.
90 list-mirror List all available packages on the mirror (--diff for new).
91 info Print informations about the package.
92 desc Print description of a package (if it exist).
93 list-files List of files installed with the package.
94 search Search for a package by pattern or name.
95 search-file Search for file(s) in all installed packages files.
96 install Install a local (*.tazpkg) package (--forced to force).
97 install-list Install all packages from a list of packages.
98 remove Remove the specified package and all installed files.
99 extract Extract a (*.tazpkg) package into a directory.
100 pack Pack an unpacked or prepared package tree.
101 recharge Recharge your packages.list from the mirror.
102 repack Creat a package archive from an installed package.
103 upgrade Upgrade all installed and listed packages on the mirror.
104 block|unblock Block an installed package version or unblock it for upgrade.
105 get Download a package into the current directory.
106 get-install Download and install a package from the mirror.
107 check Verify installed packages concistancy.
108 clean-cache Clean all packages downloaded in cache directory.
109 setup-mirror Change the mirror url configuration."
110 }
112 # Status function with color (supported by Ash).
113 status()
114 {
115 local CHECK=$?
116 echo -en "\\033[70G[ "
117 if [ $CHECK = 0 ]; then
118 echo -en "\\033[1;33mOK"
119 else
120 echo -en "\\033[1;31mFailed"
121 fi
122 echo -e "\\033[0;39m ]"
123 return $CHECK
124 }
126 # Check if user is root to install, or remove packages.
127 check_root()
128 {
129 if test $(id -u) != 0 ; then
130 echo -e "\nYou must be root to run `basename $0` with this option."
131 echo -e "Please type 'su' and root password to become super-user.\n"
132 exit 0
133 fi
134 }
136 # Check for a package name on cmdline.
137 check_for_package_on_cmdline()
138 {
139 if [ -z "$PACKAGE" ]; then
140 echo -e "\nPlease specify a package name on the command line.\n"
141 exit 0
142 fi
143 }
145 # Check if the package (*.tazpkg) exist before installing or extracting.
146 check_for_package_file()
147 {
148 if [ ! -f "$PACKAGE_FILE" ]; then
149 echo -e "
150 Unable to find : $PACKAGE_FILE\n"
151 exit 0
152 fi
153 }
155 # Check for the receipt of an installed package.
156 check_for_receipt()
157 {
158 if [ ! -f "$INSTALLED/$PACKAGE/receipt" ]; then
159 echo -e "\nUnable to find the receipt : $INSTALLED/$PACKAGE/receipt\n"
160 exit 0
161 fi
162 }
164 # Check if a package is already installed.
165 check_for_installed_package()
166 {
167 if [ -d "$INSTALLED/${PACKAGE%-[0-9]*}" ]; then
168 echo -e "
169 $PACKAGE is already installed. You can use the --forced option to force
170 installation or remove it and reinstall.\n"
171 exit 0
172 fi
173 }
175 # Check for packages.list to download and install packages.
176 check_for_packages_list()
177 {
178 if [ ! -f "$LOCALSTATE/packages.list" ]; then
179 echo -e "
180 Unable to find the list : $LOCALSTATE/packages.list\n
181 You must probably run 'tazpkg recharge' as root to get the last list of
182 packages avalaible on the mirror.\n"
183 exit 0
184 fi
185 }
187 # Check for a package in packages.list. Used by get and get-install to grep
188 # package basename.
189 check_for_package_in_list()
190 {
191 if grep -q "^$PACKAGE-[0-9]" $LOCALSTATE/packages.list; then
192 PACKAGE=`grep ^$PACKAGE-[0-9] $LOCALSTATE/packages.list`
193 else
194 echo -e "\nUnable to find : $PACKAGE in the mirrored packages list.\n"
195 exit 0
196 fi
197 }
199 # Download a file trying all mirrors
200 download()
201 {
202 for i in $(cat $MIRROR); do
203 wget $i$@ && break
204 done
205 }
207 # Extract a package with cpio and gzip.
208 extract_package()
209 {
210 echo -n "Extracting $PACKAGE..."
211 cpio -id < $PACKAGE.tazpkg && rm -f $PACKAGE.tazpkg
212 gzip -d fs.cpio.gz
213 echo -n "Extracting the pseudo fs... "
214 cpio -id < fs.cpio && rm fs.cpio
215 }
217 # This function install a package in the rootfs.
218 install_package()
219 {
220 ROOT=$1
221 if [ -n "$ROOT" ]; then
222 # get absolute path
223 ROOT=$(cd $ROOT; pwd)
224 fi
225 mkdir -p $TMP_DIR
226 echo ""
227 echo -e "\033[1mInstallation of :\033[0m $PACKAGE"
228 echo "================================================================================"
229 echo -n "Copying $PACKAGE... "
230 cp $PACKAGE_FILE $TMP_DIR
231 status
232 cd $TMP_DIR
233 extract_package
234 SELF_INSTALL=0
235 MODIFY_PACKAGES=""
236 # Include temporary receipt to get the right variables.
237 . $PWD/receipt
238 if [ $SELF_INSTALL -ne 0 -a -n "$ROOT" ]; then
239 echo -n "Checking post install dependencies... "
240 [ -d "$INSTALLED/${PACKAGE%-[0-9]*}" ]
241 if ! status; then
242 echo "Please run 'tazpkg install $PACKAGE_FILE' and retry."
243 cd .. && rm -rf $TMP_DIR
244 exit 1
245 fi
246 fi
247 # Remember modified packages
248 for i in $MODIFY_PACKAGES; do
249 [ -d $ROOT$INSTALLED/$i ] || continue
250 grep -qs ^$PACKAGE$ $ROOT$INSTALLED/$i/modifiers && continue
251 echo "$PACKAGE" >> $ROOT$INSTALLED/$i/modifiers
252 done
253 # Make the installed package data dir to store
254 # the receipt and the files list.
255 mkdir -p $ROOT$INSTALLED/$PACKAGE
256 cp receipt files.list $ROOT$INSTALLED/$PACKAGE
257 # Copy the description if found.
258 if [ -f "description.txt" ]; then
259 cp description.txt $ROOT$INSTALLED/$PACKAGE
260 fi
261 # Pre install commands.
262 if grep -q ^pre_install $ROOT$INSTALLED/$PACKAGE/receipt; then
263 pre_install $ROOT
264 fi
265 echo -n "Installing $PACKAGE... "
266 cp -a fs/* $ROOT/
267 status
268 # Remove the temporary random directory.
269 echo -n "Removing all tmp files... "
270 cd .. && rm -rf $TMP_DIR
271 status
272 # Post install commands.
273 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
274 post_install $ROOT
275 fi
276 cd $TOP_DIR
277 echo "================================================================================"
278 echo "$PACKAGE ($VERSION) is installed."
279 echo ""
280 }
282 # Check for missing deps listed in a receipt packages.
283 check_for_deps()
284 {
285 for i in $DEPENDS
286 do
287 if [ ! -d "$INSTALLED/$i" ]; then
288 MISSING_PACKAGE=$i
289 deps=$(($deps+1))
290 fi
291 done
292 if [ ! "$MISSING_PACKAGE" = "" ]; then
293 echo -e "\033[1mTracking dependencies for :\033[0m $PACKAGE"
294 echo "================================================================================"
295 for i in $DEPENDS
296 do
297 if [ ! -d "$INSTALLED/$i" ]; then
298 MISSING_PACKAGE=$i
299 echo "Missing : $MISSING_PACKAGE"
300 fi
301 done
302 echo "================================================================================"
303 echo "$deps missing package(s) to install."
304 fi
305 }
307 # Install all missing deps. First ask user then install all missing deps
308 # from local dir, cdrom, media or from the mirror. In case we want to
309 # install packages from local, we need a packages.list to find the version.
310 install_deps()
311 {
312 echo ""
313 echo -n "Install all missing dependencies (y/N) ? "; read anser
314 if [ "$anser" = "y" ]; then
315 for pkg in $DEPENDS
316 do
317 if [ ! -d "$INSTALLED/$pkg" ]; then
318 # We can install packages from a local dir by greping
319 # the TAZPKG_BASENAME in the local packages.list.
320 if [ -f "$TOP_DIR/packages.list" ]; then
321 echo "Checking if $pkg exist in local list... "
322 TAZPKG_BASENAME=`grep -e ^$pkg-[0-9] $TOP_DIR/packages.list`
323 if [ -f "$TAZPKG_BASENAME.tazpkg" ]; then
324 tazpkg install $TAZPKG_BASENAME.tazpkg
325 fi
326 # Install deps from the mirror.
327 else
328 if [ ! -f "$LOCALSTATE/packages.list" ]; then
329 tazpkg recharge
330 fi
331 tazpkg get-install $pkg
332 fi
333 fi
334 done
335 else
336 echo -e "\nLeaving dependencies for $PACKAGE unsolved."
337 echo -e "The package is installed but will probably not work.\n"
338 fi
339 }
341 # xHTML packages list header.
342 xhtml_header()
343 {
344 cat > $XHTML_LIST << _EOT_
345 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
346 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
347 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
348 <head>
349 <title>Installed packages list</title>
350 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
351 <meta name="modified" content="$DATE" />
352 <meta name="generator" content="Tazpkg" />
353 <style type="text/css"><!--
354 body { font: 12px sans-serif, vernada, arial; margin: 0; }
355 #header { background: #f0ba08; color: black; height: 50px;
356 border-top: 1px solid black; border-bottom: 1px solid black; }
357 #content { margin: 0px 50px 26px 50px; }
358 #footer { border-top: 1px solid black; padding-top: 10px;}
359 h1 { margin: 14px 0px 0px 16px; }
360 pre { padding-left: 5px; }
361 hr { color: white; background: white; height: 1px; border: 0; }
362 --></style>
363 </head>
364 <body bgcolor="#ffffff">
365 <div id="header">
366 <h1><font color="#3e1220">Installed packages list</font></h1>
367 </div>
368 <hr />
369 <!-- Start content -->
370 <div id="content">
372 <p>
373 _packages_ packages installed - List generated on : $DATE
374 <p>
376 _EOT_
377 }
379 # xHTML content with packages infos.
380 xhtml_pkg_info()
381 {
382 cat >> $XHTML_LIST << _EOT_
383 <h3>$PACKAGE</h3>
384 <pre>
385 Version : $VERSION
386 Short desc : $SHORT_DESC
387 Web site : <a href="$WEB_SITE">$WEB_SITE</a>
388 </pre>
390 _EOT_
391 }
393 # xHTML packages list footer.
394 xhtml_footer()
395 {
396 cat >> $XHTML_LIST << _EOT_
397 <hr />
398 <p id="footer">
399 $packages packages installed - List generated on : $DATE
400 </p>
402 <!-- End content -->
403 </div>
404 </body>
405 </html>
406 _EOT_
407 }
409 ###################
410 # Tazpkg commands #
411 ###################
413 case "$COMMAND" in
414 list)
415 # List all installed packages or a specific category.
416 #
417 if [ "$2" = "blocked" ]; then
418 if [ -f $BLOCKED ]; then
419 LIST=`cat $BLOCKED`
420 fi
421 echo ""
422 echo -e "\033[1mBlocked packages\033[0m"
423 echo "================================================================================"
424 if [ -n $LIST ];then
425 echo $LIST
426 echo ""
427 else
428 echo -e "No blocked packages found.\n"
429 fi
430 exit 0
431 fi
432 # Display the list of categories.
433 if [ "$2" = "cat" -o "$2" = "categories" ]; then
434 echo ""
435 echo -e "\033[1mPackages categories :\033[0m"
436 echo "================================================================================"
437 for i in $CATEGORIES
438 do
439 echo $i
440 categories=$(($categories+1))
441 done
442 echo "================================================================================"
443 echo "$categories categories"
444 echo ""
445 exit 0
446 fi
447 # Check for an asked category.
448 if [ -n "$2" ]; then
449 ASKED_CATEGORY=$2
450 echo ""
451 echo -e "\033[1mInstalled packages of category :\033[0m $ASKED_CATEGORY"
452 echo "================================================================================"
453 for pkg in $INSTALLED/*
454 do
455 . $pkg/receipt
456 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
457 echo -n "$PACKAGE"
458 echo -e "\033[24G $VERSION"
459 packages=$(($packages+1))
460 fi
461 done
462 echo "================================================================================"
463 echo -e "$packages packages installed of category $ASKED_CATEGORY."
464 echo ""
465 else
466 # By default list all packages and version.
467 echo ""
468 echo -e "\033[1mList of all installed packages\033[0m"
469 echo "================================================================================"
470 for pkg in $INSTALLED/*
471 do
472 . $pkg/receipt
473 echo -n "$PACKAGE"
474 echo -en "\033[24G $VERSION"
475 echo -e "\033[42G $CATEGORY"
476 packages=$(($packages+1))
477 done
478 echo "================================================================================"
479 echo "$packages packages installed."
480 echo ""
481 fi
482 ;;
483 xhtml-list)
484 # Get infos in receipts and build list.
485 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
486 if [ -n "$2" ]; then
487 XHTML_LIST=$2
488 else
489 XHTML_LIST=installed-packages.html
490 fi
491 echo ""
492 echo -e "\033[1mCreating xHTML list of installed packages\033[0m"
493 echo "================================================================================"
494 echo -n "Generating xHTML header..."
495 xhtml_header
496 status
497 # Packages
498 echo -n "Creating packages informations..."
499 for pkg in $INSTALLED/*
500 do
501 . $pkg/receipt
502 xhtml_pkg_info
503 packages=$(($packages+1))
504 done
505 status
506 echo -n "Generating xHTML footer..."
507 xhtml_footer
508 status
509 # sed pkgs nb in header.
510 sed -i s/'_packages_'/"$packages"/ $XHTML_LIST
511 echo "================================================================================"
512 echo "$XHTML_LIST created - $packages packages."
513 echo ""
514 ;;
515 list-mirror)
516 # List all available packages on the mirror. Option --diff display
517 # last mirrored packages diff (see recharge).
518 check_for_packages_list
519 if [ "$2" = "--diff" ]; then
520 if [ -f "$LOCALSTATE/packages.diff" ]; then
521 echo ""
522 echo -e "\033[1mMirrored packages diff\033[0m"
523 echo "================================================================================"
524 cat $LOCALSTATE/packages.diff
525 echo "================================================================================"
526 pkgs=`cat $LOCALSTATE/packages.diff | wc -l`
527 echo "$pkgs new packages listed on the mirror."
528 echo ""
529 else
530 echo -e "\nUnable to list anything, no packages.diff found."
531 echo -e "Recharge your current list to creat a first diff.\n"
532 fi
533 else
534 echo ""
535 echo -e "\033[1mList of available packages on the mirror\033[0m"
536 echo "================================================================================"
537 cat $LOCALSTATE/packages.list
538 echo "================================================================================"
539 pkgs=`cat $LOCALSTATE/packages.list | wc -l`
540 echo "$pkgs packages in the last recharged list."
541 echo ""
542 fi
543 ;;
544 list-files)
545 # List files installed with the package.
546 #
547 check_for_package_on_cmdline
548 check_for_receipt
549 echo ""
550 echo -e "\033[1mInstalled files with :\033[0m $PACKAGE"
551 echo "================================================================================"
552 cat $INSTALLED/$PACKAGE/files.list | sort
553 echo "================================================================================"
554 files=`cat $INSTALLED/$PACKAGE/files.list | wc -l`
555 echo "$files files installed with $PACKAGE."
556 echo ""
557 ;;
558 info)
559 # Informations about package.
560 #
561 check_for_package_on_cmdline
562 check_for_receipt
563 . $INSTALLED/$PACKAGE/receipt
564 echo ""
565 echo -e "\033[1mTazpkg informations\033[0m
566 ================================================================================
567 Package : $PACKAGE
568 Version : $VERSION
569 Category : $CATEGORY
570 Short desc : $SHORT_DESC
571 Maintainer : $MAINTAINER"
572 if [ ! "$DEPENDS" = "" ]; then
573 echo -e "Depends : $DEPENDS"
574 fi
575 if [ ! "$SUGGESTED" = "" ]; then
576 echo -e "Suggested : $SUGGESTED"
577 fi
578 if [ ! "$BUILD_DEPENDS" = "" ]; then
579 echo -e "Build deps : $BUILD_DEPENDS"
580 fi
581 if [ ! "$WANTED" = "" ]; then
582 echo -e "Wanted src : $WANTED"
583 fi
584 if [ ! "$WEB_SITE" = "" ]; then
585 echo -e "Web site : $WEB_SITE"
586 fi
587 echo "================================================================================"
588 echo ""
589 ;;
590 desc)
591 # Display package description.txt if available.
592 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
593 echo ""
594 echo -e "\033[1mDescription of :\033[0m $PACKAGE"
595 echo "================================================================================"
596 cat $INSTALLED/$PACKAGE/description.txt
597 echo "================================================================================"
598 echo ""
599 else
600 echo -e "\nSorry, no description available for this package.\n"
601 fi
602 ;;
603 search)
604 # Search for a package by pattern or name.
605 #
606 if [ -z "$2" ]; then
607 echo -e "\nPlease specify a pattern or a package name to search."
608 echo -e "Example : 'tazpkg search paint'. \n"
609 exit 0
610 fi
611 echo ""
612 echo -e "\033[1mSearch result for :\033[0m $2"
613 echo ""
614 echo "Installed packages"
615 echo "================================================================================"
616 list=`ls -1 $INSTALLED | grep $2`
617 for pkg in $list
618 do
619 . $INSTALLED/$pkg/receipt
620 echo -n "$PACKAGE "
621 echo -en "\033[24G $VERSION"
622 echo -e "\033[42G $CATEGORY"
623 packages=$(($packages+1))
624 done
625 # Set correct ending messages.
626 if [ "$packages" = "" ]; then
627 echo "0 installed packages found for : $2"
628 echo ""
629 else
630 echo "================================================================================"
631 echo "$packages installed package(s) found for : $2"
632 echo ""
633 fi
634 echo "Available packages"
635 echo "================================================================================"
636 if [ -f "$LOCALSTATE/packages.list" ]; then
637 cat $LOCALSTATE/packages.list | grep $2
638 packages=`cat $LOCALSTATE/packages.list | grep $2 | wc -l`
639 else
640 echo -e "
641 No 'packages.list' found to check for mirrored packages. For more results,
642 please run once 'tazpkg recharge' as root before searching.\n"
643 fi
644 if [ "$packages" = "0" ]; then
645 echo "0 available packages found for : $2"
646 echo ""
647 else
648 echo "================================================================================"
649 echo "$packages available package(s) found for : $2"
650 echo ""
651 fi
652 ;;
653 search-file)
654 # Search for a file by pattern or name in all files.list.
655 #
656 if [ -z "$2" ]; then
657 echo -e "\nPlease specify a pattern or a file name to search."
658 echo -e "Example : 'tazpkg search-file libnss'. \n"
659 exit 0
660 fi
661 echo ""
662 echo -e "\033[1mSearch result for file :\033[0m $2"
663 echo "================================================================================"
664 # Check all pkg files.list in search match with specify the package
665 # name and the full path to the file(s).
666 for pkg in $INSTALLED/*
667 do
668 if grep -q $2 $pkg/files.list; then
669 . $pkg/receipt
670 echo ""
671 echo -e "\033[1mPackage $PACKAGE :\033[0m"
672 grep $2 $pkg/files.list
673 files=`grep $2 $pkg/files.list | wc -l`
674 match=$(($match+$files))
675 fi
676 done
677 if [ "$match" = "" ]; then
678 echo "0 file found for : $2"
679 echo ""
680 else
681 echo ""
682 echo "================================================================================"
683 echo "$match file(s) found for : $2"
684 echo ""
685 fi
686 ;;
687 install)
688 # Install .tazpkg packages.
689 #
690 check_root
691 check_for_package_on_cmdline
692 check_for_package_file
693 # Check if forced install.
694 DO_CHECK="yes"
695 while [ -n "$3" ]; do
696 case "$3" in
697 --forced)
698 DO_CHECK="no"
699 ;;
700 --root=*)
701 install_package ${3#--root=}
702 exit $?
703 ;;
704 *) shift 2
705 echo -e "\nUnknown option $*.\n"
706 exit 1
707 ;;
708 esac
709 shift
710 done
711 if [ "$DO_CHECK" = "yes" ]; then
712 check_for_installed_package
713 fi
714 install_package
715 # Resolv package deps.
716 check_for_deps
717 if [ ! "$MISSING_PACKAGE" = "" ]; then
718 install_deps
719 fi
720 ;;
721 install-list)
722 # Install a set of packages from a list.
723 #
724 check_root
725 if [ -z "$2" ]; then
726 echo -e "
727 Please change directory (cd) to the packages repository, and specify the
728 list of packages to install. Example : tazpkg install-list packages.list\n"
729 exit 0
730 fi
731 # Check if the packages list exist.
732 if [ ! -f "$2" ]; then
733 echo "Unable to find : $2"
734 exit 0
735 else
736 LIST=`cat $2`
737 fi
738 # Install all packages.
739 for pkg in $LIST
740 do
741 if [ "$3" = "--forced" ]; then
742 tazpkg install $pkg --forced
743 else
744 tazpkg install $pkg
745 fi
746 done
747 ;;
748 remove)
749 # Remove packages.
750 #
751 check_root
752 check_for_package_on_cmdline
753 if [ ! -d "$INSTALLED/$PACKAGE" ]; then
754 echo -e "\n$PACKAGE is not installed.\n"
755 exit 0
756 else
757 ALTERED=""
758 THE_PACKAGE=$PACKAGE # altered by receipt
759 for i in $(cd $INSTALLED ; ls); do
760 DEPENDS=""
761 . $INSTALLED/$i/receipt
762 case " $(echo $DEPENDS) " in
763 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
764 esac
765 done
766 . $INSTALLED/$THE_PACKAGE/receipt
767 fi
768 echo ""
769 if [ -n "$ALTERED" ]; then
770 echo "The following packages depend on $PACKAGE :"
771 for i in $ALTERED; do
772 echo " $i"
773 done
774 fi
775 echo "Remove $PACKAGE ($VERSION) ?"
776 echo -n "Please confirm uninstallation (y/N) : "; read anser
777 if [ "$anser" = "y" ]; then
778 echo ""
779 echo -e "\033[1mRemoving :\033[0m $PACKAGE"
780 echo "================================================================================"
781 # Pre remove commands.
782 if grep -q ^pre_remove $INSTALLED/$PACKAGE/receipt; then
783 pre_remove
784 fi
785 echo -n "Removing all files installed..."
786 for file in `cat $INSTALLED/$PACKAGE/files.list`
787 do
788 rm -f $file 2>/dev/null
789 done
790 status
791 # Remove package receipt.
792 echo -n "Removing package receipt..."
793 rm -rf $INSTALLED/$PACKAGE
794 status
795 if grep -q ^post_remove $INSTALLED/$PACKAGE/receipt; then
796 post_remove
797 fi
798 if [ -n "$ALTERED" ]; then
799 echo -n "Remove packages depending on $PACKAGE"
800 echo -n " (y/N) ? "; read anser
801 if [ "$anser" = "y" ]; then
802 for i in $ALTERED; do
803 if [ -d "$INSTALLED/$i" ]; then
804 tazpkg remove $i
805 fi
806 done
807 fi
808 fi
809 else
810 echo ""
811 echo "Uninstallation of $PACKAGE cancelled."
812 fi
813 echo ""
814 ;;
815 extract)
816 # Extract .tazpkg cpio archive into a directory.
817 #
818 check_for_package_on_cmdline
819 check_for_package_file
820 echo ""
821 echo -e "\033[1mExtracting :\033[0m $PACKAGE"
822 echo "================================================================================"
823 # If any directory destination is found on the cmdline
824 # we creat one in the current dir using the package name.
825 if [ -n "$TARGET_DIR" ]; then
826 DESTDIR=$TARGET_DIR/$PACKAGE
827 else
828 DESTDIR=$PACKAGE
829 fi
830 mkdir -p $DESTDIR
831 echo -n "Copying original package..."
832 cp $PACKAGE_FILE $DESTDIR
833 status
834 cd $DESTDIR
835 extract_package
836 echo "================================================================================"
837 echo "$PACKAGE is extracted to : $DESTDIR"
838 echo ""
839 ;;
840 repack)
841 # Creat SliTaz package archive from an installed package.
842 #
843 check_for_package_on_cmdline
844 check_for_receipt
845 eval $(grep ^VERSION= $INSTALLED/$PACKAGE/receipt)
846 echo ""
847 echo -e "\033[1mRepacking :\033[0m $PACKAGE-$VERSION.tazpkg"
848 echo "================================================================================"
849 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
850 echo "Can't repack $PACKAGE"
851 exit 1
852 fi
853 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
854 echo "Can't repack, $PACKAGE files have been modified by:"
855 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
856 echo " $i"
857 done
858 exit 1
859 fi
860 MISSING=""
861 for i in $(sed 's,^fs,,g' < $INSTALLED/$PACKAGE/files.list); do
862 [ -e "$i" ] && continue
863 [ -L "$i" ] || MISSING="$MISSING $i"
864 done
865 if [ -n "$MISSING" ]; then
866 echo "Can't repack, the following files are lost:"
867 for i in $MISSING; do
868 echo " $i"
869 done
870 exit 1
871 fi
872 HERE=`pwd`
873 mkdir -p $TMP_DIR && cd $TMP_DIR
874 FILES="fs.cpio.gz\n"
875 for i in $(ls $INSTALLED/$PACKAGE) ; do
876 cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
877 done
878 cpio -pd fs < files.list 2> /dev/null
879 find fs | cpio -o -H newc 2> /dev/null | gzip -9 > fs.cpio.gz
880 echo -e "$FILES" | cpio -o -H newc 2> /dev/null > \
881 $HERE/$PACKAGE-$VERSION.tazpkg
882 cd $HERE
883 \rm -R $TMP_DIR
884 echo "Package $PACKAGE repacked successfully."
885 echo "Size : `du -sh $PACKAGE-$VERSION.tazpkg`"
886 echo ""
887 ;;
888 pack)
889 # Creat SliTaz package archive using cpio and gzip.
890 #
891 check_for_package_on_cmdline
892 cd $PACKAGE
893 if [ ! -f "receipt" ]; then
894 echo "Receipt is missing. Please read the documentation."
895 exit 0
896 else
897 echo ""
898 echo -e "\033[1mPacking :\033[0m $PACKAGE"
899 echo "================================================================================"
900 # Creat files.list with redirecting find outpout.
901 echo -n "Creating the list of files..." && cd fs
902 find . -type f -print > ../files.list
903 find . -type l -print >> ../files.list
904 cd .. && sed -i s/'^.'/''/ files.list
905 status
906 # Build cpio archives.
907 echo -n "Compressing the fs... "
908 find fs -print | cpio -o -H newc > fs.cpio
909 gzip fs.cpio && rm -rf fs
910 echo -n "Creating full cpio archive... "
911 find . -print | cpio -o -H newc > ../$PACKAGE.tazpkg
912 echo -n "Restoring original package tree... "
913 gzip -d fs.cpio.gz && cpio -id < fs.cpio
914 rm fs.cpio && cd ..
915 echo "================================================================================"
916 echo "Package $PACKAGE compressed successfully."
917 echo "Size : `du -sh $PACKAGE.tazpkg`"
918 echo ""
919 fi
920 ;;
921 recharge)
922 # Recharge packages.list from a mirror.
923 #
924 check_root
925 cd $LOCALSTATE
926 echo ""
927 if [ -f "$LOCALSTATE/packages.list" ]; then
928 echo -n "Creating backup of the last packages list..."
929 mv -f packages.txt packages.txt.bak 2>/dev/null
930 mv -f packages.list packages.list.bak
931 status
932 fi
933 download packages.txt
934 download packages.list
935 if [ -f "$LOCALSTATE/packages.list.bak" ]; then
936 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
937 sed -i s/+// packages.diff
938 echo ""
939 echo -e "\033[1mMirrored packages diff\033[0m"
940 echo "================================================================================"
941 cat packages.diff
942 if [ ! "`cat packages.diff | wc -l`" = 0 ]; then
943 echo "================================================================================"
944 echo "`cat packages.diff | wc -l` new packages on the mirror."
945 echo ""
946 else
947 echo "`cat packages.diff | wc -l` new packages on the mirror."
948 echo ""
949 fi
950 else
951 echo -e "
952 ================================================================================
953 Last packages.list is ready to use. Note that next time you recharge the list,
954 a list of differencies will be displayed to show new and upgradable packages.\n"
955 fi
956 ;;
957 upgrade)
958 # Upgrade all installed packages with the new version from the mirror.
959 #
960 check_root
961 check_for_packages_list
962 cd $LOCALSTATE
963 # Touch the blocked pkgs list to avoid errors and remove any old
964 # upgrade list.
965 touch blocked-packages.list
966 rm -f upradable-packages.list
967 echo ""
968 echo -e "\033[1mAvalaible upgrade\033[0m"
969 echo "================================================================================"
970 for pkg in $INSTALLED/*
971 do
972 . $pkg/receipt
973 # Skip specified pkgs listed in $LOCALSTATE/blocked-packages.list
974 if grep -q "^$PACKAGE" $BLOCKED; then
975 blocked=$(($blocked+1))
976 else
977 # Check if the installed package is in the current list (other
978 # mirror or local).
979 if grep -q "^$PACKAGE-[0-9]" packages.list; then
980 # Set new pkg and version for futur comparaison
981 NEW_PACKAGE=`grep ^$PACKAGE-[0-9] packages.list`
982 NEW_VERSION=`echo $NEW_PACKAGE | sed s/$PACKAGE-/''/`
983 # Change '-' and 'pre' to points.
984 NEW_VERSION=`echo $NEW_VERSION | sed s/'-'/'.'/`
985 VERSION=`echo $VERSION | sed s/'-'/'.'/`
986 NEW_VERSION=`echo $NEW_VERSION | sed s/'pre'/'.'/`
987 VERSION=`echo $VERSION | sed s/'pre'/'.'/`
989 # Compare version. Upgrade are only avalaible for official
990 # packages, so we control de mirror and it should be ok if
991 # we just check for egality.
992 if [ "$VERSION" != "$NEW_VERSION" ]; then
993 # Version seems different. Check for major, minor or
994 # revision
995 PKG_MAJOR=`echo $VERSION | cut -f1 -d"."`
996 NEW_MAJOR=`echo $NEW_VERSION | cut -f1 -d"."`
997 PKG_MINOR=`echo $VERSION | cut -f2 -d"."`
998 NEW_MINOR=`echo $NEW_VERSION | cut -f2 -d"."`
999 # Minor
1000 if [ "$NEW_MINOR" -gt "$PKG_MINOR" ]; then
1001 RELEASE=minor
1002 fi
1003 if [ "$NEW_MINOR" -lt "$PKG_MINOR" ]; then
1004 RELEASE=$WARNING
1005 FIXE=yes
1006 fi
1007 # Major
1008 if [ "$NEW_MAJOR" -gt "$PKG_MAJOR" ]; then
1009 RELEASE=major
1010 FIXE=""
1011 fi
1012 if [ "$NEW_MAJOR" -lt "$PKG_MAJOR" ]; then
1013 RELEASE=$WARNING
1014 FIXE=yes
1015 fi
1016 # Default to revision.
1017 if [ -z $RELEASE ]; then
1018 RELEASE=revision
1019 fi
1020 echo -n "$PACKAGE"
1021 echo -en "\033[24G $VERSION"
1022 echo -en "\033[38G --->"
1023 echo -en "\033[43G $NEW_VERSION"
1024 echo -en "\033[58G $CATEGORY"
1025 echo -e "\033[72G $RELEASE"
1026 up=$(($up+1))
1027 echo "$PACKAGE" >> upradable-packages.list
1028 unset RELEASE
1029 fi
1030 packages=$(($packages+1))
1031 fi
1032 fi
1033 done
1034 rm -f $tmpfile
1035 if [ -z $blocked ]; then
1036 blocked=0
1037 fi
1038 if [ ! "$up" = "" ]; then
1039 echo "================================================================================"
1040 echo "$packages installed and listed packages to consider, $up to upgrade, $blocked blocked."
1041 echo ""
1042 else
1043 echo "$packages installed and listed packages to consider, 0 to upgrade, $blocked blocked."
1044 echo ""
1045 exit 0
1046 fi
1047 # What to do if major or minor version is smaller.
1048 if [ "$FIXE" == "yes" ]; then
1049 echo -e "$WARNING ---> Installed package seems more recent than the mirrored one."
1050 echo "You can block packages using the command : 'tazpkg block package'"
1051 echo "Or upgrade package at you own risks."
1052 echo ""
1053 fi
1054 # Ask for upgrade, it can be done an other time.
1055 echo -n "Upgrade now (y/N) ? "; read anser
1056 if [ ! "$anser" = "y" ]; then
1057 echo -e "\nExiting. No package upgraded.\n"
1058 exit 0
1059 fi
1060 # If anser is yes (y). Install all new version.
1061 for pkg in `cat upradable-packages.list`
1062 do
1063 tazpkg get-install $pkg --forced
1064 done
1065 ;;
1066 check)
1067 # check installed packages set.
1069 check_root
1070 cd $INSTALLED
1071 for PACKAGE in `ls`; do
1072 DEPENDS=""
1073 . $PACKAGE/receipt
1074 if [ -s $PACKAGE/modifiers ]; then
1075 echo "The package $PACKAGE $VERSION has been modified by :"
1076 for i in $(cat $PACKAGE/modifiers); do
1077 echo " $i"
1078 done
1079 fi
1080 MSG="Files lost from $PACKAGE $VERSION :\n"
1081 while read file; do
1082 [ -e "$file" ] && continue
1083 if [ -L "$file" ]; then
1084 MSG="$MSG target of symlink"
1085 fi
1086 echo -e "$MSG $file"
1087 MSG=""
1088 done < $PACKAGE/files.list
1089 MSG="Missing dependencies for $PACKAGE $VERSION :\n"
1090 for i in $DEPENDS; do
1091 [ -d $i ] && continue
1092 echo -e "$MSG $i"
1093 MSG=""
1094 done
1095 done
1096 echo "Check completed."
1097 ;;
1098 block)
1099 # Add a pkg name to the list of blocked packages.
1101 check_root
1102 check_for_package_on_cmdline
1103 echo ""
1104 if grep -q "^$PACKAGE" $BLOCKED; then
1105 echo "$PACKAGE is already in the blocked packages list."
1106 echo ""
1107 exit 0
1108 else
1109 echo -n "Add $PACKAGE to : $BLOCKED..."
1110 echo $PACKAGE >> $BLOCKED
1111 status
1112 fi
1113 echo ""
1114 ;;
1115 unblock)
1116 # Remove a pkg name to the list of blocked packages.
1118 check_root
1119 check_for_package_on_cmdline
1120 echo ""
1121 if grep -q "^$PACKAGE" $BLOCKED; then
1122 echo -n "Removing $PACKAGE from : $BLOCKED..."
1123 sed -i s/$PACKAGE/''/ $BLOCKED
1124 sed -i '/^$/d' $BLOCKED
1125 status
1126 else
1127 echo "$PACKAGE is not in the blocked packages list."
1128 echo ""
1129 exit 0
1130 fi
1131 echo ""
1132 ;;
1133 get)
1134 # Downlowd a package with wget.
1136 check_for_package_on_cmdline
1137 check_for_packages_list
1138 check_for_package_in_list
1139 echo ""
1140 download $PACKAGE.tazpkg
1141 echo ""
1142 ;;
1143 get-install)
1144 # Download and install a package.
1146 check_root
1147 check_for_package_on_cmdline
1148 check_for_packages_list
1149 check_for_package_in_list
1150 # Check if forced install.
1151 if [ "$3" = "--forced" ]; then
1152 rm -f $CACHE_DIR/$PACKAGE.tazpkg
1153 else
1154 check_for_installed_package
1155 fi
1156 cd $CACHE_DIR
1157 if [ -f "$PACKAGE.tazpkg" ]; then
1158 echo "$PACKAGE already in the cache : $CACHE_DIR"
1159 else
1160 echo ""
1161 download $PACKAGE.tazpkg
1162 fi
1163 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
1164 install_package
1165 check_for_deps
1166 if [ ! "$MISSING_PACKAGE" = "" ]; then
1167 install_deps
1168 fi
1169 ;;
1170 clean-cache)
1171 # Remove all downloaded packages.
1173 check_root
1174 files=`ls -1 $CACHE_DIR | wc -l`
1175 echo ""
1176 echo -e "\033[1mClean cache :\033[0m $CACHE_DIR"
1177 echo "================================================================================"
1178 echo -n "Cleaning cache directory..."
1179 rm -rf $CACHE_DIR/*
1180 status
1181 echo "================================================================================"
1182 echo "$files file(s) removed from cache."
1183 echo ""
1184 ;;
1185 setup-mirror)
1186 # Change mirror URL.
1188 check_root
1189 # Backup old list.
1190 if [ -f "$LOCALSTATE/mirror" ]; then
1191 cp -f $LOCALSTATE/mirror $LOCALSTATE/mirror.bak
1192 fi
1193 echo ""
1194 echo -e "\033[1mCurrent mirror(s)\033[0m"
1195 echo "================================================================================"
1196 echo " `cat $MIRROR`"
1197 echo "
1198 Please enter URL of the new mirror (http or ftp). You must specify the complet
1199 address to the directory of the packages and packages.list file."
1200 echo ""
1201 echo -n "New mirror URL : "
1202 read NEW_MIRROR_URL
1203 if [ "$NEW_MIRROR_URL" = "" ]; then
1204 echo "Nothing as been change."
1205 else
1206 echo "Setting mirror(s) to : $NEW_MIRROR_URL"
1207 echo "$NEW_MIRROR_URL" > $LOCALSTATE/mirror
1208 fi
1209 echo ""
1210 ;;
1211 usage|*)
1212 # Print a short help or give usage for an unknow or empty command.
1214 usage
1215 ;;
1216 esac
1218 exit 0