tazpkg view tazpkg @ rev 60

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