tazpkg view tazpkg @ rev 66

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