tazpkg view tazpkg @ rev 70

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