tazpkg view tazpkg @ rev 38

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