tazpkg view tazpkg @ rev 46

Updated manual (list blocked + cat) changed release string to 1.8
author Christophe Lincoln <pankso@slitaz.org>
date Fri Feb 15 15:32:33 2008 +0100 (2008-02-15)
parents 57ee801d7242
children 3071a3b8b089
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 [ -n "$ALTERED" ]; then
795 echo -n "Remove packages depending on $PACKAGE"
796 echo -n " (y/N) ? "; read anser
797 if [ "$anser" = "y" ]; then
798 for i in $ALTERED; do
799 if [ -d "$INSTALLED/$i" ]; then
800 tazpkg remove $i
801 fi
802 done
803 fi
804 fi
805 else
806 echo ""
807 echo "Uninstallation of $PACKAGE cancelled."
808 fi
809 echo ""
810 ;;
811 extract)
812 # Extract .tazpkg cpio archive into a directory.
813 #
814 check_for_package_on_cmdline
815 check_for_package_file
816 echo ""
817 echo -e "\033[1mExtracting :\033[0m $PACKAGE"
818 echo "================================================================================"
819 # If any directory destination is found on the cmdline
820 # we creat one in the current dir using the package name.
821 if [ -n "$TARGET_DIR" ]; then
822 DESTDIR=$TARGET_DIR/$PACKAGE
823 else
824 DESTDIR=$PACKAGE
825 fi
826 mkdir -p $DESTDIR
827 echo -n "Copying original package..."
828 cp $PACKAGE_FILE $DESTDIR
829 status
830 cd $DESTDIR
831 extract_package
832 echo "================================================================================"
833 echo "$PACKAGE is extracted to : $DESTDIR"
834 echo ""
835 ;;
836 repack)
837 # Creat SliTaz package archive from an installed package.
838 #
839 check_for_package_on_cmdline
840 check_for_receipt
841 eval $(grep ^VERSION= $INSTALLED/$PACKAGE/receipt)
842 echo ""
843 echo -e "\033[1mRepacking :\033[0m $PACKAGE-$VERSION.tazpkg"
844 echo "================================================================================"
845 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
846 echo "Can't repack $PACKAGE"
847 exit 1
848 fi
849 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
850 echo "Can't repack, $PACKAGE files have been modified by:"
851 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
852 echo " $i"
853 done
854 exit 1
855 fi
856 MISSING=""
857 for i in $(sed 's,^fs,,g' < $INSTALLED/$PACKAGE/files.list); do
858 [ -e "$i" ] && continue
859 [ -L "$i" ] || MISSING="$MISSING $i"
860 done
861 if [ -n "$MISSING" ]; then
862 echo "Can't repack, the following files are lost:"
863 for i in $MISSING; do
864 echo " $i"
865 done
866 exit 1
867 fi
868 HERE=`pwd`
869 mkdir -p $TMP_DIR && cd $TMP_DIR
870 FILES="fs.cpio.gz\n"
871 for i in $(ls $INSTALLED/$PACKAGE) ; do
872 cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
873 done
874 cpio -pd fs < files.list 2> /dev/null
875 find fs | cpio -o -H newc 2> /dev/null | gzip -9 > fs.cpio.gz
876 echo -e "$FILES" | cpio -o -H newc 2> /dev/null > \
877 $HERE/$PACKAGE-$VERSION.tazpkg
878 cd $HERE
879 \rm -R $TMP_DIR
880 echo "Package $PACKAGE repacked successfully."
881 echo "Size : `du -sh $PACKAGE-$VERSION.tazpkg`"
882 echo ""
883 ;;
884 pack)
885 # Creat SliTaz package archive using cpio and gzip.
886 #
887 check_for_package_on_cmdline
888 cd $PACKAGE
889 if [ ! -f "receipt" ]; then
890 echo "Receipt is missing. Please read the documentation."
891 exit 0
892 else
893 echo ""
894 echo -e "\033[1mPacking :\033[0m $PACKAGE"
895 echo "================================================================================"
896 # Creat files.list with redirecting find outpout.
897 echo -n "Creating the list of files..." && cd fs
898 find . -type f -print > ../files.list
899 find . -type l -print >> ../files.list
900 cd .. && sed -i s/'^.'/''/ files.list
901 status
902 # Build cpio archives.
903 echo -n "Compressing the fs... "
904 find fs -print | cpio -o -H newc > fs.cpio
905 gzip fs.cpio && rm -rf fs
906 echo -n "Creating full cpio archive... "
907 find . -print | cpio -o -H newc > ../$PACKAGE.tazpkg
908 echo -n "Restoring original package tree... "
909 gzip -d fs.cpio.gz && cpio -id < fs.cpio
910 rm fs.cpio && cd ..
911 echo "================================================================================"
912 echo "Package $PACKAGE compressed successfully."
913 echo "Size : `du -sh $PACKAGE.tazpkg`"
914 echo ""
915 fi
916 ;;
917 recharge)
918 # Recharge packages.list from a mirror.
919 #
920 check_root
921 cd $LOCALSTATE
922 echo ""
923 if [ -f "$LOCALSTATE/packages.list" ]; then
924 echo -n "Creating backup of the last packages list..."
925 mv -f packages.txt packages.txt.bak 2>/dev/null
926 mv -f packages.list packages.list.bak
927 status
928 fi
929 download packages.txt
930 download packages.list
931 if [ -f "$LOCALSTATE/packages.list.bak" ]; then
932 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
933 sed -i s/+// packages.diff
934 echo ""
935 echo -e "\033[1mMirrored packages diff\033[0m"
936 echo "================================================================================"
937 cat packages.diff
938 if [ ! "`cat packages.diff | wc -l`" = 0 ]; then
939 echo "================================================================================"
940 echo "`cat packages.diff | wc -l` new packages on the mirror."
941 echo ""
942 else
943 echo "`cat packages.diff | wc -l` new packages on the mirror."
944 echo ""
945 fi
946 else
947 echo -e "
948 ================================================================================
949 Last packages.list is ready to use. Note that next time you recharge the list,
950 a list of differencies will be displayed to show new and upgradable packages.\n"
951 fi
952 ;;
953 upgrade)
954 # Upgrade all installed packages with the new version from the mirror.
955 #
956 check_root
957 check_for_packages_list
958 cd $LOCALSTATE
959 # Touch the blocked pkgs list to avoid errors and remove any old
960 # upgrade list.
961 touch blocked-packages.list
962 rm -f upradable-packages.list
963 echo ""
964 echo -e "\033[1mAvalaible upgrade\033[0m"
965 echo "================================================================================"
966 for pkg in $INSTALLED/*
967 do
968 . $pkg/receipt
969 # Skip specified pkgs listed in $LOCALSTATE/blocked-packages.list
970 if grep -q "^$PACKAGE" $BLOCKED; then
971 blocked=$(($blocked+1))
972 else
973 # Check if the installed package is in the current list (other
974 # mirror or local).
975 if grep -q "^$PACKAGE-[0-9]" packages.list; then
976 # Set new pkg and version for futur comparaison
977 NEW_PACKAGE=`grep ^$PACKAGE-[0-9] packages.list`
978 NEW_VERSION=`echo $NEW_PACKAGE | sed s/$PACKAGE-/''/`
979 # Change '-' and 'pre' to points.
980 NEW_VERSION=`echo $NEW_VERSION | sed s/'-'/'.'/`
981 VERSION=`echo $VERSION | sed s/'-'/'.'/`
982 NEW_VERSION=`echo $NEW_VERSION | sed s/'pre'/'.'/`
983 VERSION=`echo $VERSION | sed s/'pre'/'.'/`
985 # Compare version. Upgrade are only avalaible for official
986 # packages, so we control de mirror and it should be ok if
987 # we just check for egality.
988 if [ "$VERSION" != "$NEW_VERSION" ]; then
989 # Version seems different. Check for major, minor or
990 # revision
991 PKG_MAJOR=`echo $VERSION | cut -f1 -d"."`
992 NEW_MAJOR=`echo $NEW_VERSION | cut -f1 -d"."`
993 PKG_MINOR=`echo $VERSION | cut -f2 -d"."`
994 NEW_MINOR=`echo $NEW_VERSION | cut -f2 -d"."`
995 # Minor
996 if [ "$NEW_MINOR" -gt "$PKG_MINOR" ]; then
997 RELEASE=minor
998 fi
999 if [ "$NEW_MINOR" -lt "$PKG_MINOR" ]; then
1000 RELEASE=$WARNING
1001 FIXE=yes
1002 fi
1003 # Major
1004 if [ "$NEW_MAJOR" -gt "$PKG_MAJOR" ]; then
1005 RELEASE=major
1006 FIXE=""
1007 fi
1008 if [ "$NEW_MAJOR" -lt "$PKG_MAJOR" ]; then
1009 RELEASE=$WARNING
1010 FIXE=yes
1011 fi
1012 # Default to revision.
1013 if [ -z $RELEASE ]; then
1014 RELEASE=revision
1015 fi
1016 echo -n "$PACKAGE"
1017 echo -en "\033[24G $VERSION"
1018 echo -en "\033[38G --->"
1019 echo -en "\033[43G $NEW_VERSION"
1020 echo -en "\033[58G $CATEGORY"
1021 echo -e "\033[72G $RELEASE"
1022 up=$(($up+1))
1023 echo "$PACKAGE" >> upradable-packages.list
1024 unset RELEASE
1025 fi
1026 packages=$(($packages+1))
1027 fi
1028 fi
1029 done
1030 rm -f $tmpfile
1031 if [ -z $blocked ]; then
1032 blocked=0
1033 fi
1034 if [ ! "$up" = "" ]; then
1035 echo "================================================================================"
1036 echo "$packages installed and listed packages to consider, $up to upgrade, $blocked blocked."
1037 echo ""
1038 else
1039 echo "$packages installed and listed packages to consider, 0 to upgrade, $blocked blocked."
1040 echo ""
1041 exit 0
1042 fi
1043 # What to do if major or minor version is smaller.
1044 if [ "$FIXE" == "yes" ]; then
1045 echo -e "$WARNING ---> Installed package seems more recent than the mirrored one."
1046 echo "You can block packages using the command : 'tazpkg block package'"
1047 echo "Or upgrade package at you own risks."
1048 echo ""
1049 fi
1050 # Ask for upgrade, it can be done an other time.
1051 echo -n "Upgrade now (y/N) ? "; read anser
1052 if [ ! "$anser" = "y" ]; then
1053 echo -e "\nExiting. No package upgraded.\n"
1054 exit 0
1055 fi
1056 # If anser is yes (y). Install all new version.
1057 for pkg in `cat upradable-packages.list`
1058 do
1059 tazpkg get-install $pkg --forced
1060 done
1061 ;;
1062 check)
1063 # check installed packages set.
1065 check_root
1066 cd $INSTALLED
1067 for PACKAGE in `ls`; do
1068 DEPENDS=""
1069 . $PACKAGE/receipt
1070 if [ -s $PACKAGE/modifiers ]; then
1071 echo "The package $PACKAGE $VERSION has been modified by :"
1072 for i in $(cat $PACKAGE/modifiers); do
1073 echo " $i"
1074 done
1075 fi
1076 MSG="Files lost from $PACKAGE $VERSION :\n"
1077 while read file; do
1078 [ -e "$file" ] && continue
1079 if [ -L "$file" ]; then
1080 MSG="$MSG target of symlink"
1081 fi
1082 echo -e "$MSG $file"
1083 MSG=""
1084 done < $PACKAGE/files.list
1085 MSG="Missing dependencies for $PACKAGE $VERSION :\n"
1086 for i in $DEPENDS; do
1087 [ -d $i ] && continue
1088 echo -e "$MSG $i"
1089 MSG=""
1090 done
1091 done
1092 echo "Check completed."
1093 ;;
1094 block)
1095 # Add a pkg name to the list of blocked packages.
1097 check_root
1098 check_for_package_on_cmdline
1099 echo ""
1100 if grep -q "^$PACKAGE" $BLOCKED; then
1101 echo "$PACKAGE is already in the blocked packages list."
1102 echo ""
1103 exit 0
1104 else
1105 echo -n "Add $PACKAGE to : $BLOCKED..."
1106 echo $PACKAGE >> $BLOCKED
1107 status
1108 fi
1109 echo ""
1110 ;;
1111 unblock)
1112 # Remove a pkg name to the list of blocked packages.
1114 check_root
1115 check_for_package_on_cmdline
1116 echo ""
1117 if grep -q "^$PACKAGE" $BLOCKED; then
1118 echo -n "Removing $PACKAGE from : $BLOCKED..."
1119 sed -i s/$PACKAGE/''/ $BLOCKED
1120 sed -i '/^$/d' $BLOCKED
1121 status
1122 else
1123 echo "$PACKAGE is not in the blocked packages list."
1124 echo ""
1125 exit 0
1126 fi
1127 echo ""
1128 ;;
1129 get)
1130 # Downlowd a package with wget.
1132 check_for_package_on_cmdline
1133 check_for_packages_list
1134 check_for_package_in_list
1135 echo ""
1136 download $PACKAGE.tazpkg
1137 echo ""
1138 ;;
1139 get-install)
1140 # Download and install a package.
1142 check_root
1143 check_for_package_on_cmdline
1144 check_for_packages_list
1145 check_for_package_in_list
1146 # Check if forced install.
1147 if [ "$3" = "--forced" ]; then
1148 rm -f $CACHE_DIR/$PACKAGE.tazpkg
1149 else
1150 check_for_installed_package
1151 fi
1152 cd $CACHE_DIR
1153 if [ -f "$PACKAGE.tazpkg" ]; then
1154 echo "$PACKAGE already in the cache : $CACHE_DIR"
1155 else
1156 echo ""
1157 download $PACKAGE.tazpkg
1158 fi
1159 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
1160 install_package
1161 check_for_deps
1162 if [ ! "$MISSING_PACKAGE" = "" ]; then
1163 install_deps
1164 fi
1165 ;;
1166 clean-cache)
1167 # Remove all downloaded packages.
1169 check_root
1170 files=`ls -1 $CACHE_DIR | wc -l`
1171 echo ""
1172 echo -e "\033[1mClean cache :\033[0m $CACHE_DIR"
1173 echo "================================================================================"
1174 echo -n "Cleaning cache directory..."
1175 rm -rf $CACHE_DIR/*
1176 status
1177 echo "================================================================================"
1178 echo "$files file(s) removed from cache."
1179 echo ""
1180 ;;
1181 setup-mirror)
1182 # Change mirror URL.
1184 check_root
1185 # Backup old list.
1186 if [ -f "$LOCALSTATE/mirror" ]; then
1187 cp -f $LOCALSTATE/mirror $LOCALSTATE/mirror.bak
1188 fi
1189 echo ""
1190 echo -e "\033[1mCurrent mirror(s)\033[0m"
1191 echo "================================================================================"
1192 echo " `cat $MIRROR`"
1193 echo "
1194 Please enter URL of the new mirror (http or ftp). You must specify the complet
1195 address to the directory of the packages and packages.list file."
1196 echo ""
1197 echo -n "New mirror URL : "
1198 read NEW_MIRROR_URL
1199 if [ "$NEW_MIRROR_URL" = "" ]; then
1200 echo "Nothing as been change."
1201 else
1202 echo "Setting mirror(s) to : $NEW_MIRROR_URL"
1203 echo "$NEW_MIRROR_URL" > $LOCALSTATE/mirror
1204 fi
1205 echo ""
1206 ;;
1207 usage|*)
1208 # Print a short help or give usage for an unknow or empty command.
1210 usage
1211 ;;
1212 esac
1214 exit 0