tazpkg view tazpkg @ rev 73

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