tazpkg view tazpkg @ rev 107

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