tazpkg view tazpkg @ rev 41

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