tazpkg view tazpkg @ rev 67

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