tazpkg view tazpkg @ rev 57

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