tazpkg view tazpkg @ rev 48

add post_remove
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Feb 18 11:34:24 2008 +0100 (2008-02-18)
parents 26e8decc233d
children d18209325623
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
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$@ && break
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" = "blocked" ]; then
417 if [ -f $BLOCKED ]; then
418 LIST=`cat $BLOCKED`
419 fi
420 echo ""
421 echo -e "\033[1mBlocked packages\033[0m"
422 echo "================================================================================"
423 if [ -n $LIST ];then
424 echo $LIST
425 echo ""
426 else
427 echo -e "No blocked packages found.\n"
428 fi
429 exit 0
430 fi
431 # Display the list of categories.
432 if [ "$2" = "cat" -o "$2" = "categories" ]; then
433 echo ""
434 echo -e "\033[1mPackages categories :\033[0m"
435 echo "================================================================================"
436 for i in $CATEGORIES
437 do
438 echo $i
439 categories=$(($categories+1))
440 done
441 echo "================================================================================"
442 echo "$categories categories"
443 echo ""
444 exit 0
445 fi
446 # Check for an asked category.
447 if [ -n "$2" ]; then
448 ASKED_CATEGORY=$2
449 echo ""
450 echo -e "\033[1mInstalled packages of category :\033[0m $ASKED_CATEGORY"
451 echo "================================================================================"
452 for pkg in $INSTALLED/*
453 do
454 . $pkg/receipt
455 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
456 echo -n "$PACKAGE"
457 echo -e "\033[24G $VERSION"
458 packages=$(($packages+1))
459 fi
460 done
461 echo "================================================================================"
462 echo -e "$packages packages installed of category $ASKED_CATEGORY."
463 echo ""
464 else
465 # By default list all packages and version.
466 echo ""
467 echo -e "\033[1mList of all installed packages\033[0m"
468 echo "================================================================================"
469 for pkg in $INSTALLED/*
470 do
471 . $pkg/receipt
472 echo -n "$PACKAGE"
473 echo -en "\033[24G $VERSION"
474 echo -e "\033[42G $CATEGORY"
475 packages=$(($packages+1))
476 done
477 echo "================================================================================"
478 echo "$packages packages installed."
479 echo ""
480 fi
481 ;;
482 xhtml-list)
483 # Get infos in receipts and build list.
484 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
485 if [ -n "$2" ]; then
486 XHTML_LIST=$2
487 else
488 XHTML_LIST=installed-packages.html
489 fi
490 echo ""
491 echo -e "\033[1mCreating xHTML list of installed packages\033[0m"
492 echo "================================================================================"
493 echo -n "Generating xHTML header..."
494 xhtml_header
495 status
496 # Packages
497 echo -n "Creating packages informations..."
498 for pkg in $INSTALLED/*
499 do
500 . $pkg/receipt
501 xhtml_pkg_info
502 packages=$(($packages+1))
503 done
504 status
505 echo -n "Generating xHTML footer..."
506 xhtml_footer
507 status
508 # sed pkgs nb in header.
509 sed -i s/'_packages_'/"$packages"/ $XHTML_LIST
510 echo "================================================================================"
511 echo "$XHTML_LIST created - $packages packages."
512 echo ""
513 ;;
514 list-mirror)
515 # List all available packages on the mirror. Option --diff display
516 # last mirrored packages diff (see recharge).
517 check_for_packages_list
518 if [ "$2" = "--diff" ]; then
519 if [ -f "$LOCALSTATE/packages.diff" ]; then
520 echo ""
521 echo -e "\033[1mMirrored packages diff\033[0m"
522 echo "================================================================================"
523 cat $LOCALSTATE/packages.diff
524 echo "================================================================================"
525 pkgs=`cat $LOCALSTATE/packages.diff | wc -l`
526 echo "$pkgs new packages listed on the mirror."
527 echo ""
528 else
529 echo -e "\nUnable to list anything, no packages.diff found."
530 echo -e "Recharge your current list to creat a first diff.\n"
531 fi
532 else
533 echo ""
534 echo -e "\033[1mList of available packages on the mirror\033[0m"
535 echo "================================================================================"
536 cat $LOCALSTATE/packages.list
537 echo "================================================================================"
538 pkgs=`cat $LOCALSTATE/packages.list | wc -l`
539 echo "$pkgs packages in the last recharged list."
540 echo ""
541 fi
542 ;;
543 list-files)
544 # List files installed with the package.
545 #
546 check_for_package_on_cmdline
547 check_for_receipt
548 echo ""
549 echo -e "\033[1mInstalled files with :\033[0m $PACKAGE"
550 echo "================================================================================"
551 cat $INSTALLED/$PACKAGE/files.list | sort
552 echo "================================================================================"
553 files=`cat $INSTALLED/$PACKAGE/files.list | wc -l`
554 echo "$files files installed with $PACKAGE."
555 echo ""
556 ;;
557 info)
558 # Informations about package.
559 #
560 check_for_package_on_cmdline
561 check_for_receipt
562 . $INSTALLED/$PACKAGE/receipt
563 echo ""
564 echo -e "\033[1mTazpkg informations\033[0m
565 ================================================================================
566 Package : $PACKAGE
567 Version : $VERSION
568 Category : $CATEGORY
569 Short desc : $SHORT_DESC
570 Maintainer : $MAINTAINER"
571 if [ ! "$DEPENDS" = "" ]; then
572 echo -e "Depends : $DEPENDS"
573 fi
574 if [ ! "$SUGGESTED" = "" ]; then
575 echo -e "Suggested : $SUGGESTED"
576 fi
577 if [ ! "$BUILD_DEPENDS" = "" ]; then
578 echo -e "Build deps : $BUILD_DEPENDS"
579 fi
580 if [ ! "$WANTED" = "" ]; then
581 echo -e "Wanted src : $WANTED"
582 fi
583 if [ ! "$WEB_SITE" = "" ]; then
584 echo -e "Web site : $WEB_SITE"
585 fi
586 echo "================================================================================"
587 echo ""
588 ;;
589 desc)
590 # Display package description.txt if available.
591 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
592 echo ""
593 echo -e "\033[1mDescription of :\033[0m $PACKAGE"
594 echo "================================================================================"
595 cat $INSTALLED/$PACKAGE/description.txt
596 echo "================================================================================"
597 echo ""
598 else
599 echo -e "\nSorry, no description available for this package.\n"
600 fi
601 ;;
602 search)
603 # Search for a package by pattern or name.
604 #
605 if [ -z "$2" ]; then
606 echo -e "\nPlease specify a pattern or a package name to search."
607 echo -e "Example : 'tazpkg search paint'. \n"
608 exit 0
609 fi
610 echo ""
611 echo -e "\033[1mSearch result for :\033[0m $2"
612 echo ""
613 echo "Installed packages"
614 echo "================================================================================"
615 list=`ls -1 $INSTALLED | grep $2`
616 for pkg in $list
617 do
618 . $INSTALLED/$pkg/receipt
619 echo -n "$PACKAGE "
620 echo -en "\033[24G $VERSION"
621 echo -e "\033[42G $CATEGORY"
622 packages=$(($packages+1))
623 done
624 # Set correct ending messages.
625 if [ "$packages" = "" ]; then
626 echo "0 installed packages found for : $2"
627 echo ""
628 else
629 echo "================================================================================"
630 echo "$packages installed package(s) found for : $2"
631 echo ""
632 fi
633 echo "Available packages"
634 echo "================================================================================"
635 if [ -f "$LOCALSTATE/packages.list" ]; then
636 cat $LOCALSTATE/packages.list | grep $2
637 packages=`cat $LOCALSTATE/packages.list | grep $2 | wc -l`
638 else
639 echo -e "
640 No 'packages.list' found to check for mirrored packages. For more results,
641 please run once 'tazpkg recharge' as root before searching.\n"
642 fi
643 if [ "$packages" = "0" ]; then
644 echo "0 available packages found for : $2"
645 echo ""
646 else
647 echo "================================================================================"
648 echo "$packages available package(s) found for : $2"
649 echo ""
650 fi
651 ;;
652 search-file)
653 # Search for a file by pattern or name in all files.list.
654 #
655 if [ -z "$2" ]; then
656 echo -e "\nPlease specify a pattern or a file name to search."
657 echo -e "Example : 'tazpkg search-file libnss'. \n"
658 exit 0
659 fi
660 echo ""
661 echo -e "\033[1mSearch result for file :\033[0m $2"
662 echo "================================================================================"
663 # Check all pkg files.list in search match with specify the package
664 # name and the full path to the file(s).
665 for pkg in $INSTALLED/*
666 do
667 if grep -q $2 $pkg/files.list; then
668 . $pkg/receipt
669 echo ""
670 echo -e "\033[1mPackage $PACKAGE :\033[0m"
671 grep $2 $pkg/files.list
672 files=`grep $2 $pkg/files.list | wc -l`
673 match=$(($match+$files))
674 fi
675 done
676 if [ "$match" = "" ]; then
677 echo "0 file found for : $2"
678 echo ""
679 else
680 echo ""
681 echo "================================================================================"
682 echo "$match file(s) found for : $2"
683 echo ""
684 fi
685 ;;
686 install)
687 # Install .tazpkg packages.
688 #
689 check_root
690 check_for_package_on_cmdline
691 check_for_package_file
692 # Check if forced install.
693 DO_CHECK="yes"
694 while [ -n "$3" ]; do
695 case "$3" in
696 --forced)
697 DO_CHECK="no"
698 ;;
699 --root=*)
700 install_package ${3#--root=}
701 exit $?
702 ;;
703 *) shift 2
704 echo -e "\nUnknown option $*.\n"
705 exit 1
706 ;;
707 esac
708 shift
709 done
710 if [ "$DO_CHECK" = "yes" ]; then
711 check_for_installed_package
712 fi
713 install_package
714 # Resolv package deps.
715 check_for_deps
716 if [ ! "$MISSING_PACKAGE" = "" ]; then
717 install_deps
718 fi
719 ;;
720 install-list)
721 # Install a set of packages from a list.
722 #
723 check_root
724 if [ -z "$2" ]; then
725 echo -e "
726 Please change directory (cd) to the packages repository, and specify the
727 list of packages to install. Example : tazpkg install-list packages.list\n"
728 exit 0
729 fi
730 # Check if the packages list exist.
731 if [ ! -f "$2" ]; then
732 echo "Unable to find : $2"
733 exit 0
734 else
735 LIST=`cat $2`
736 fi
737 # Install all packages.
738 for pkg in $LIST
739 do
740 if [ "$3" = "--forced" ]; then
741 tazpkg install $pkg --forced
742 else
743 tazpkg install $pkg
744 fi
745 done
746 ;;
747 remove)
748 # Remove packages.
749 #
750 check_root
751 check_for_package_on_cmdline
752 if [ ! -d "$INSTALLED/$PACKAGE" ]; then
753 echo -e "\n$PACKAGE is not installed.\n"
754 exit 0
755 else
756 ALTERED=""
757 THE_PACKAGE=$PACKAGE # altered by receipt
758 for i in $(cd $INSTALLED ; ls); do
759 DEPENDS=""
760 . $INSTALLED/$i/receipt
761 case " $(echo $DEPENDS) " in
762 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
763 esac
764 done
765 . $INSTALLED/$THE_PACKAGE/receipt
766 fi
767 echo ""
768 if [ -n "$ALTERED" ]; then
769 echo "The following packages depend on $PACKAGE :"
770 for i in $ALTERED; do
771 echo " $i"
772 done
773 fi
774 echo "Remove $PACKAGE ($VERSION) ?"
775 echo -n "Please confirm uninstallation (y/N) : "; read anser
776 if [ "$anser" = "y" ]; then
777 echo ""
778 echo -e "\033[1mRemoving :\033[0m $PACKAGE"
779 echo "================================================================================"
780 # Pre remove commands.
781 if grep -q ^pre_remove $INSTALLED/$PACKAGE/receipt; then
782 pre_remove
783 fi
784 echo -n "Removing all files installed..."
785 for file in `cat $INSTALLED/$PACKAGE/files.list`
786 do
787 rm -f $file 2>/dev/null
788 done
789 status
790 # Remove package receipt.
791 echo -n "Removing package receipt..."
792 rm -rf $INSTALLED/$PACKAGE
793 status
794 if grep -q ^post_remove $INSTALLED/$PACKAGE/receipt; then
795 post_remove
796 fi
797 if [ -n "$ALTERED" ]; then
798 echo -n "Remove packages depending on $PACKAGE"
799 echo -n " (y/N) ? "; read anser
800 if [ "$anser" = "y" ]; then
801 for i in $ALTERED; do
802 if [ -d "$INSTALLED/$i" ]; then
803 tazpkg remove $i
804 fi
805 done
806 fi
807 fi
808 else
809 echo ""
810 echo "Uninstallation of $PACKAGE cancelled."
811 fi
812 echo ""
813 ;;
814 extract)
815 # Extract .tazpkg cpio archive into a directory.
816 #
817 check_for_package_on_cmdline
818 check_for_package_file
819 echo ""
820 echo -e "\033[1mExtracting :\033[0m $PACKAGE"
821 echo "================================================================================"
822 # If any directory destination is found on the cmdline
823 # we creat one in the current dir using the package name.
824 if [ -n "$TARGET_DIR" ]; then
825 DESTDIR=$TARGET_DIR/$PACKAGE
826 else
827 DESTDIR=$PACKAGE
828 fi
829 mkdir -p $DESTDIR
830 echo -n "Copying original package..."
831 cp $PACKAGE_FILE $DESTDIR
832 status
833 cd $DESTDIR
834 extract_package
835 echo "================================================================================"
836 echo "$PACKAGE is extracted to : $DESTDIR"
837 echo ""
838 ;;
839 repack)
840 # Creat SliTaz package archive from an installed package.
841 #
842 check_for_package_on_cmdline
843 check_for_receipt
844 eval $(grep ^VERSION= $INSTALLED/$PACKAGE/receipt)
845 echo ""
846 echo -e "\033[1mRepacking :\033[0m $PACKAGE-$VERSION.tazpkg"
847 echo "================================================================================"
848 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
849 echo "Can't repack $PACKAGE"
850 exit 1
851 fi
852 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
853 echo "Can't repack, $PACKAGE files have been modified by:"
854 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
855 echo " $i"
856 done
857 exit 1
858 fi
859 MISSING=""
860 for i in $(sed 's,^fs,,g' < $INSTALLED/$PACKAGE/files.list); do
861 [ -e "$i" ] && continue
862 [ -L "$i" ] || MISSING="$MISSING $i"
863 done
864 if [ -n "$MISSING" ]; then
865 echo "Can't repack, the following files are lost:"
866 for i in $MISSING; do
867 echo " $i"
868 done
869 exit 1
870 fi
871 HERE=`pwd`
872 mkdir -p $TMP_DIR && cd $TMP_DIR
873 FILES="fs.cpio.gz\n"
874 for i in $(ls $INSTALLED/$PACKAGE) ; do
875 cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
876 done
877 cpio -pd fs < files.list 2> /dev/null
878 find fs | cpio -o -H newc 2> /dev/null | gzip -9 > fs.cpio.gz
879 echo -e "$FILES" | cpio -o -H newc 2> /dev/null > \
880 $HERE/$PACKAGE-$VERSION.tazpkg
881 cd $HERE
882 \rm -R $TMP_DIR
883 echo "Package $PACKAGE repacked successfully."
884 echo "Size : `du -sh $PACKAGE-$VERSION.tazpkg`"
885 echo ""
886 ;;
887 pack)
888 # Creat SliTaz package archive using cpio and gzip.
889 #
890 check_for_package_on_cmdline
891 cd $PACKAGE
892 if [ ! -f "receipt" ]; then
893 echo "Receipt is missing. Please read the documentation."
894 exit 0
895 else
896 echo ""
897 echo -e "\033[1mPacking :\033[0m $PACKAGE"
898 echo "================================================================================"
899 # Creat files.list with redirecting find outpout.
900 echo -n "Creating the list of files..." && cd fs
901 find . -type f -print > ../files.list
902 find . -type l -print >> ../files.list
903 cd .. && sed -i s/'^.'/''/ files.list
904 status
905 # Build cpio archives.
906 echo -n "Compressing the fs... "
907 find fs -print | cpio -o -H newc > fs.cpio
908 gzip fs.cpio && rm -rf fs
909 echo -n "Creating full cpio archive... "
910 find . -print | cpio -o -H newc > ../$PACKAGE.tazpkg
911 echo -n "Restoring original package tree... "
912 gzip -d fs.cpio.gz && cpio -id < fs.cpio
913 rm fs.cpio && cd ..
914 echo "================================================================================"
915 echo "Package $PACKAGE compressed successfully."
916 echo "Size : `du -sh $PACKAGE.tazpkg`"
917 echo ""
918 fi
919 ;;
920 recharge)
921 # Recharge packages.list from a mirror.
922 #
923 check_root
924 cd $LOCALSTATE
925 echo ""
926 if [ -f "$LOCALSTATE/packages.list" ]; then
927 echo -n "Creating backup of the last packages list..."
928 mv -f packages.txt packages.txt.bak 2>/dev/null
929 mv -f packages.list packages.list.bak
930 status
931 fi
932 download packages.txt
933 download packages.list
934 if [ -f "$LOCALSTATE/packages.list.bak" ]; then
935 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
936 sed -i s/+// packages.diff
937 echo ""
938 echo -e "\033[1mMirrored packages diff\033[0m"
939 echo "================================================================================"
940 cat packages.diff
941 if [ ! "`cat packages.diff | wc -l`" = 0 ]; then
942 echo "================================================================================"
943 echo "`cat packages.diff | wc -l` new packages on the mirror."
944 echo ""
945 else
946 echo "`cat packages.diff | wc -l` new packages on the mirror."
947 echo ""
948 fi
949 else
950 echo -e "
951 ================================================================================
952 Last packages.list is ready to use. Note that next time you recharge the list,
953 a list of differencies will be displayed to show new and upgradable packages.\n"
954 fi
955 ;;
956 upgrade)
957 # Upgrade all installed packages with the new version from the mirror.
958 #
959 check_root
960 check_for_packages_list
961 cd $LOCALSTATE
962 # Touch the blocked pkgs list to avoid errors and remove any old
963 # upgrade list.
964 touch blocked-packages.list
965 rm -f upradable-packages.list
966 echo ""
967 echo -e "\033[1mAvalaible upgrade\033[0m"
968 echo "================================================================================"
969 for pkg in $INSTALLED/*
970 do
971 . $pkg/receipt
972 # Skip specified pkgs listed in $LOCALSTATE/blocked-packages.list
973 if grep -q "^$PACKAGE" $BLOCKED; then
974 blocked=$(($blocked+1))
975 else
976 # Check if the installed package is in the current list (other
977 # mirror or local).
978 if grep -q "^$PACKAGE-[0-9]" packages.list; then
979 # Set new pkg and version for futur comparaison
980 NEW_PACKAGE=`grep ^$PACKAGE-[0-9] packages.list`
981 NEW_VERSION=`echo $NEW_PACKAGE | sed s/$PACKAGE-/''/`
982 # Change '-' and 'pre' to points.
983 NEW_VERSION=`echo $NEW_VERSION | sed s/'-'/'.'/`
984 VERSION=`echo $VERSION | sed s/'-'/'.'/`
985 NEW_VERSION=`echo $NEW_VERSION | sed s/'pre'/'.'/`
986 VERSION=`echo $VERSION | sed s/'pre'/'.'/`
988 # Compare version. Upgrade are only avalaible for official
989 # packages, so we control de mirror and it should be ok if
990 # we just check for egality.
991 if [ "$VERSION" != "$NEW_VERSION" ]; then
992 # Version seems different. Check for major, minor or
993 # revision
994 PKG_MAJOR=`echo $VERSION | cut -f1 -d"."`
995 NEW_MAJOR=`echo $NEW_VERSION | cut -f1 -d"."`
996 PKG_MINOR=`echo $VERSION | cut -f2 -d"."`
997 NEW_MINOR=`echo $NEW_VERSION | cut -f2 -d"."`
998 # Minor
999 if [ "$NEW_MINOR" -gt "$PKG_MINOR" ]; then
1000 RELEASE=minor
1001 fi
1002 if [ "$NEW_MINOR" -lt "$PKG_MINOR" ]; then
1003 RELEASE=$WARNING
1004 FIXE=yes
1005 fi
1006 # Major
1007 if [ "$NEW_MAJOR" -gt "$PKG_MAJOR" ]; then
1008 RELEASE=major
1009 FIXE=""
1010 fi
1011 if [ "$NEW_MAJOR" -lt "$PKG_MAJOR" ]; then
1012 RELEASE=$WARNING
1013 FIXE=yes
1014 fi
1015 # Default to revision.
1016 if [ -z $RELEASE ]; then
1017 RELEASE=revision
1018 fi
1019 echo -n "$PACKAGE"
1020 echo -en "\033[24G $VERSION"
1021 echo -en "\033[38G --->"
1022 echo -en "\033[43G $NEW_VERSION"
1023 echo -en "\033[58G $CATEGORY"
1024 echo -e "\033[72G $RELEASE"
1025 up=$(($up+1))
1026 echo "$PACKAGE" >> upradable-packages.list
1027 unset RELEASE
1028 fi
1029 packages=$(($packages+1))
1030 fi
1031 fi
1032 done
1033 rm -f $tmpfile
1034 if [ -z $blocked ]; then
1035 blocked=0
1036 fi
1037 if [ ! "$up" = "" ]; then
1038 echo "================================================================================"
1039 echo "$packages installed and listed packages to consider, $up to upgrade, $blocked blocked."
1040 echo ""
1041 else
1042 echo "$packages installed and listed packages to consider, 0 to upgrade, $blocked blocked."
1043 echo ""
1044 exit 0
1045 fi
1046 # What to do if major or minor version is smaller.
1047 if [ "$FIXE" == "yes" ]; then
1048 echo -e "$WARNING ---> Installed package seems more recent than the mirrored one."
1049 echo "You can block packages using the command : 'tazpkg block package'"
1050 echo "Or upgrade package at you own risks."
1051 echo ""
1052 fi
1053 # Ask for upgrade, it can be done an other time.
1054 echo -n "Upgrade now (y/N) ? "; read anser
1055 if [ ! "$anser" = "y" ]; then
1056 echo -e "\nExiting. No package upgraded.\n"
1057 exit 0
1058 fi
1059 # If anser is yes (y). Install all new version.
1060 for pkg in `cat upradable-packages.list`
1061 do
1062 tazpkg get-install $pkg --forced
1063 done
1064 ;;
1065 check)
1066 # check installed packages set.
1068 check_root
1069 cd $INSTALLED
1070 for PACKAGE in `ls`; do
1071 DEPENDS=""
1072 . $PACKAGE/receipt
1073 if [ -s $PACKAGE/modifiers ]; then
1074 echo "The package $PACKAGE $VERSION has been modified by :"
1075 for i in $(cat $PACKAGE/modifiers); do
1076 echo " $i"
1077 done
1078 fi
1079 MSG="Files lost from $PACKAGE $VERSION :\n"
1080 while read file; do
1081 [ -e "$file" ] && continue
1082 if [ -L "$file" ]; then
1083 MSG="$MSG target of symlink"
1084 fi
1085 echo -e "$MSG $file"
1086 MSG=""
1087 done < $PACKAGE/files.list
1088 MSG="Missing dependencies for $PACKAGE $VERSION :\n"
1089 for i in $DEPENDS; do
1090 [ -d $i ] && continue
1091 echo -e "$MSG $i"
1092 MSG=""
1093 done
1094 done
1095 echo "Check completed."
1096 ;;
1097 block)
1098 # Add a pkg name to the list of blocked packages.
1100 check_root
1101 check_for_package_on_cmdline
1102 echo ""
1103 if grep -q "^$PACKAGE" $BLOCKED; then
1104 echo "$PACKAGE is already in the blocked packages list."
1105 echo ""
1106 exit 0
1107 else
1108 echo -n "Add $PACKAGE to : $BLOCKED..."
1109 echo $PACKAGE >> $BLOCKED
1110 status
1111 fi
1112 echo ""
1113 ;;
1114 unblock)
1115 # Remove a pkg name to the list of blocked packages.
1117 check_root
1118 check_for_package_on_cmdline
1119 echo ""
1120 if grep -q "^$PACKAGE" $BLOCKED; then
1121 echo -n "Removing $PACKAGE from : $BLOCKED..."
1122 sed -i s/$PACKAGE/''/ $BLOCKED
1123 sed -i '/^$/d' $BLOCKED
1124 status
1125 else
1126 echo "$PACKAGE is not in the blocked packages list."
1127 echo ""
1128 exit 0
1129 fi
1130 echo ""
1131 ;;
1132 get)
1133 # Downlowd a package with wget.
1135 check_for_package_on_cmdline
1136 check_for_packages_list
1137 check_for_package_in_list
1138 echo ""
1139 download $PACKAGE.tazpkg
1140 echo ""
1141 ;;
1142 get-install)
1143 # Download and install a package.
1145 check_root
1146 check_for_package_on_cmdline
1147 check_for_packages_list
1148 check_for_package_in_list
1149 # Check if forced install.
1150 if [ "$3" = "--forced" ]; then
1151 rm -f $CACHE_DIR/$PACKAGE.tazpkg
1152 else
1153 check_for_installed_package
1154 fi
1155 cd $CACHE_DIR
1156 if [ -f "$PACKAGE.tazpkg" ]; then
1157 echo "$PACKAGE already in the cache : $CACHE_DIR"
1158 else
1159 echo ""
1160 download $PACKAGE.tazpkg
1161 fi
1162 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
1163 install_package
1164 check_for_deps
1165 if [ ! "$MISSING_PACKAGE" = "" ]; then
1166 install_deps
1167 fi
1168 ;;
1169 clean-cache)
1170 # Remove all downloaded packages.
1172 check_root
1173 files=`ls -1 $CACHE_DIR | wc -l`
1174 echo ""
1175 echo -e "\033[1mClean cache :\033[0m $CACHE_DIR"
1176 echo "================================================================================"
1177 echo -n "Cleaning cache directory..."
1178 rm -rf $CACHE_DIR/*
1179 status
1180 echo "================================================================================"
1181 echo "$files file(s) removed from cache."
1182 echo ""
1183 ;;
1184 setup-mirror)
1185 # Change mirror URL.
1187 check_root
1188 # Backup old list.
1189 if [ -f "$LOCALSTATE/mirror" ]; then
1190 cp -f $LOCALSTATE/mirror $LOCALSTATE/mirror.bak
1191 fi
1192 echo ""
1193 echo -e "\033[1mCurrent mirror(s)\033[0m"
1194 echo "================================================================================"
1195 echo " `cat $MIRROR`"
1196 echo "
1197 Please enter URL of the new mirror (http or ftp). You must specify the complet
1198 address to the directory of the packages and packages.list file."
1199 echo ""
1200 echo -n "New mirror URL : "
1201 read NEW_MIRROR_URL
1202 if [ "$NEW_MIRROR_URL" = "" ]; then
1203 echo "Nothing as been change."
1204 else
1205 echo "Setting mirror(s) to : $NEW_MIRROR_URL"
1206 echo "$NEW_MIRROR_URL" > $LOCALSTATE/mirror
1207 fi
1208 echo ""
1209 ;;
1210 usage|*)
1211 # Print a short help or give usage for an unknow or empty command.
1213 usage
1214 ;;
1215 esac
1217 exit 0