tazpkg view tazpkg @ rev 106

add md5sum support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Jun 26 20:04:57 2008 +0000 (2008-06-26)
parents 8874901b805a
children 8c29692a0de3
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 if [ -f $INSTALLED/$PACKAGE/md5sum ]; then
1031 if ! md5sum -s -c $INSTALLED/$PACKAGE/md5sum; then
1032 echo -n "Can't repack, md5sum error."
1033 exit 1
1034 fi
1035 fi
1036 mkdir -p $TMP_DIR && cd $TMP_DIR
1037 FILES="fs.cpio.gz\n"
1038 for i in $(ls $INSTALLED/$PACKAGE) ; do
1039 cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
1040 done
1041 ln -s / rootfs
1042 mkdir tmp
1043 sed 's/^/rootfs/' < files.list | cpio -o -H newc 2>/dev/null |\
1044 ( cd tmp ; cpio -id 2>/dev/null )
1045 mv tmp/rootfs fs
1046 find fs | cpio -o -H newc 2> /dev/null | gzip -9 > fs.cpio.gz
1047 echo -e "$FILES" | cpio -o -H newc 2> /dev/null > \
1048 $TOP_DIR/$PACKAGE-$VERSION.tazpkg
1049 cd $TOP_DIR
1050 \rm -R $TMP_DIR
1051 echo "Package $PACKAGE repacked successfully."
1052 echo "Size : `du -sh $PACKAGE-$VERSION.tazpkg`"
1053 echo ""
1054 ;;
1055 pack)
1056 # Creat SliTaz package archive using cpio and gzip.
1058 check_for_package_on_cmdline
1059 cd $PACKAGE
1060 if [ ! -f "receipt" ]; then
1061 echo "Receipt is missing. Please read the documentation."
1062 exit 0
1063 else
1064 echo ""
1065 echo -e "\033[1mPacking :\033[0m $PACKAGE"
1066 echo "================================================================================"
1067 # Creat files.list with redirecting find outpout.
1068 echo -n "Creating the list of files..." && cd fs
1069 find . -type f -print > ../files.list
1070 find . -type l -print >> ../files.list
1071 cd .. && sed -i s/'^.'/''/ files.list
1072 status
1073 # Build cpio archives.
1074 echo -n "Compressing the fs... "
1075 find fs -print | cpio -o -H newc > fs.cpio
1076 gzip fs.cpio && rm -rf fs
1077 echo -n "Creating full cpio archive... "
1078 find . -print | cpio -o -H newc > ../$PACKAGE.tazpkg
1079 echo -n "Restoring original package tree... "
1080 gzip -d fs.cpio.gz && cpio -id < fs.cpio
1081 rm fs.cpio && cd ..
1082 echo "================================================================================"
1083 echo "Package $PACKAGE compressed successfully."
1084 echo "Size : `du -sh $PACKAGE.tazpkg`"
1085 echo ""
1086 fi
1087 ;;
1088 recharge)
1089 # Recharge packages.list from a mirror.
1091 check_root
1092 cd $LOCALSTATE
1093 echo ""
1094 if [ -f "$LOCALSTATE/packages.list" ]; then
1095 echo -n "Creating backup of the last packages list..."
1096 mv -f packages.desc packages.desc.bak 2>/dev/null
1097 mv -f packages.txt packages.txt.bak 2>/dev/null
1098 mv -f packages.list packages.list.bak 2>/dev/null
1099 mv -f files.list.lzma files.list.lzma.bak 2> /dev/nul
1100 status
1101 fi
1102 download packages.desc
1103 download packages.txt
1104 download packages.list
1105 download files.list.lzma
1106 if [ -f "$LOCALSTATE/packages.list.bak" ]; then
1107 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
1108 sed -i s/+// packages.diff
1109 echo ""
1110 echo -e "\033[1mMirrored packages diff\033[0m"
1111 echo "================================================================================"
1112 cat packages.diff
1113 if [ ! "`cat packages.diff | wc -l`" = 0 ]; then
1114 echo "================================================================================"
1115 echo "`cat packages.diff | wc -l` new packages on the mirror."
1116 echo ""
1117 else
1118 echo "`cat packages.diff | wc -l` new packages on the mirror."
1119 echo ""
1120 fi
1121 else
1122 echo -e "
1123 ================================================================================
1124 Last packages.list is ready to use. Note that next time you recharge the list,
1125 a list of differencies will be displayed to show new and upgradable packages.\n"
1126 fi
1127 ;;
1128 upgrade)
1129 # Upgrade all installed packages with the new version from the mirror.
1131 check_root
1132 check_for_packages_list
1133 cd $LOCALSTATE
1134 # Touch the blocked pkgs list to avoid errors and remove any old
1135 # upgrade list.
1136 touch blocked-packages.list
1137 rm -f upradable-packages.list
1138 echo ""
1139 echo -e "\033[1mAvalaible upgrade\033[0m"
1140 echo "================================================================================"
1141 echo ""
1142 # Some packages must be installed first
1143 FIRST_CLASS_PACKAGE=" glibc-base "
1144 FIRST_CLASS=""
1145 for pkg in $INSTALLED/*
1146 do
1147 . $pkg/receipt
1148 # Diplay package name to show that Tazpkg is working...
1149 echo -en "\\033[0G "
1150 echo -en "\\033[0G$PACKAGE"
1151 # Skip specified pkgs listed in $LOCALSTATE/blocked-packages.list
1152 if grep -q "^$PACKAGE" $BLOCKED; then
1153 blocked=$(($blocked+1))
1154 else
1155 # Check if the installed package is in the current list (other
1156 # mirror or local).
1157 if grep -q "^$PACKAGE-[0-9A-Z]" packages.list; then
1158 # Set new pkg and version for futur comparaison
1159 NEW_PACKAGE=`grep ^$PACKAGE-[0-9A-Z] packages.list`
1160 NEW_VERSION=`echo $NEW_PACKAGE | sed s/$PACKAGE-/''/`
1161 # Change '-' and 'pre' to points.
1162 NEW_VERSION=`echo $NEW_VERSION | sed s/'-'/'.'/`
1163 VERSION=`echo $VERSION | sed s/'-'/'.'/`
1164 NEW_VERSION=`echo $NEW_VERSION | sed s/'pre'/'.'/`
1165 VERSION=`echo $VERSION | sed s/'pre'/'.'/`
1166 # Compare version. Upgrade are only avalaible for official
1167 # packages, so we control de mirror and it should be ok if
1168 # we just check for egality.
1169 if [ "$VERSION" != "$NEW_VERSION" ]; then
1170 # Version seems different. Check for major, minor or
1171 # revision
1172 PKG_MAJOR=`echo ${VERSION%_*} | cut -f1 -d"."`
1173 NEW_MAJOR=`echo ${NEW_VERSION%_*} | cut -f1 -d"."`
1174 PKG_MINOR=`echo ${VERSION%_*} | cut -f2 -d"."`
1175 NEW_MINOR=`echo ${NEW_VERSION%_*} | cut -f2 -d"."`
1176 # Minor
1177 if [ "$NEW_MINOR" -gt "$PKG_MINOR" ]; then
1178 RELEASE=minor
1179 fi
1180 if [ "$NEW_MINOR" -lt "$PKG_MINOR" ]; then
1181 RELEASE=$WARNING
1182 FIXE=yes
1183 fi
1184 # Major
1185 if [ "$NEW_MAJOR" -gt "$PKG_MAJOR" ]; then
1186 RELEASE=major
1187 FIXE=""
1188 fi
1189 if [ "$NEW_MAJOR" -lt "$PKG_MAJOR" ]; then
1190 RELEASE=$WARNING
1191 FIXE=yes
1192 fi
1193 # Default to revision.
1194 if [ -z $RELEASE ]; then
1195 RELEASE=revision
1196 fi
1197 # Pkg name is already displayed by the check process.
1198 echo -en "\033[24G $VERSION"
1199 echo -en "\033[38G --->"
1200 echo -en "\033[43G $NEW_VERSION"
1201 echo -en "\033[58G $CATEGORY"
1202 echo -e "\033[72G $RELEASE"
1203 up=$(($up+1))
1204 echo "$PACKAGE" >> upradable-packages.list
1205 case "$FIRST_CLASS_PACKAGE" in
1206 *\ $PACKAGE\ *) FIRST_CLASS="$FIRST_CLASS $PACKAGE";;
1207 esac
1208 unset RELEASE
1209 fi
1210 packages=$(($packages+1))
1211 fi
1212 fi
1213 done
1214 if [ -z $blocked ]; then
1215 blocked=0
1216 fi
1217 # Clean last checked package and display summary.
1218 if [ ! "$up" = "" ]; then
1219 echo -e "\\033[0G "
1220 echo "================================================================================"
1221 echo "$packages installed and listed packages to consider, $up to upgrade, $blocked blocked."
1222 echo ""
1223 else
1224 echo -e "\\033[0GSystem is up to date. "
1225 echo ""
1226 echo "================================================================================"
1227 echo "$packages installed and listed packages to consider, 0 to upgrade, $blocked blocked."
1228 echo ""
1229 exit 0
1230 fi
1231 # What to do if major or minor version is smaller.
1232 if [ "$FIXE" == "yes" ]; then
1233 echo -e "$WARNING ---> Installed package seems more recent than the mirrored one."
1234 echo "You can block packages using the command : 'tazpkg block package'"
1235 echo "Or upgrade package at you own risks."
1236 echo ""
1237 fi
1238 # Ask for upgrade, it can be done an other time.
1239 echo -n "Upgrade now (y/N) ? "; read anser
1240 if [ ! "$anser" = "y" ]; then
1241 echo -e "\nExiting. No package upgraded.\n"
1242 exit 0
1243 fi
1244 # If anser is yes (y). Install all new version.
1245 for pkg in $FIRST_CLASS `cat upradable-packages.list`
1246 do
1247 tazpkg get-install $pkg --forced
1248 done
1249 ;;
1250 check)
1251 # check installed packages set.
1253 check_root
1254 cd $INSTALLED
1255 for PACKAGE in `ls`; do
1256 DEPENDS=""
1257 . $PACKAGE/receipt
1258 if [ -s $PACKAGE/modifiers ]; then
1259 echo "The package $PACKAGE $VERSION has been modified by :"
1260 for i in $(cat $PACKAGE/modifiers); do
1261 echo " $i"
1262 done
1263 fi
1264 MSG="Files lost from $PACKAGE $VERSION :\n"
1265 while read file; do
1266 [ -e "$file" ] && continue
1267 if [ -L "$file" ]; then
1268 MSG="$MSG target of symlink"
1269 fi
1270 echo -e "$MSG $file"
1271 MSG=""
1272 done < $PACKAGE/files.list
1273 MSG="Missing dependencies for $PACKAGE $VERSION :\n"
1274 for i in $DEPENDS; do
1275 [ -d $i ] && continue
1276 echo -e "$MSG $i"
1277 MSG=""
1278 done
1279 done
1280 if [ "$PACKAGE_FILE" = "--full" ]; then
1281 for file in */md5sum; do
1282 [ -s "$file" ] || continue
1283 md5sum -c "$file" 2> /dev/null | grep -v OK$
1284 done
1285 FILES=" "
1286 for file in $(cat */files.list); do
1287 [ -d "$file" ] && continue
1288 case "$FILES" in *\ $file\ *) continue;; esac
1289 [ $(grep "^$file$" */files.list 2> /dev/null | \
1290 wc -l) -gt 1 ] || continue
1291 FILES="$FILES$file "
1292 echo "The following packages provide $file :"
1293 grep -l "^$file$" */files.list | while read f
1294 do
1295 pkg=${f%/files.list}
1296 echo -n " $pkg"
1297 if [ -f $pkg/modifiers ]; then
1298 echo -n " (known as overridden by $(cat $pkg/modifiers))"
1299 fi
1300 echo ""
1301 done
1302 done
1303 MSG="No package has installed the following files:\n"
1304 find /etc /bin /sbin /lib /usr /var/www -not -type d | while read file; do
1305 case "$file" in *\[*) continue;; esac
1306 grep -q "^$file$" */files.list && continue
1307 echo -e "$MSG $file"
1308 MSG=""
1309 done
1310 fi
1311 echo "Check completed."
1312 ;;
1313 block)
1314 # Add a pkg name to the list of blocked packages.
1316 check_root
1317 check_for_package_on_cmdline
1318 echo ""
1319 if grep -q "^$PACKAGE" $BLOCKED; then
1320 echo "$PACKAGE is already in the blocked packages list."
1321 echo ""
1322 exit 0
1323 else
1324 echo -n "Add $PACKAGE to : $BLOCKED..."
1325 echo $PACKAGE >> $BLOCKED
1326 status
1327 fi
1328 echo ""
1329 ;;
1330 unblock)
1331 # Remove a pkg name to the list of blocked packages.
1333 check_root
1334 check_for_package_on_cmdline
1335 echo ""
1336 if grep -q "^$PACKAGE" $BLOCKED; then
1337 echo -n "Removing $PACKAGE from : $BLOCKED..."
1338 sed -i s/$PACKAGE/''/ $BLOCKED
1339 sed -i '/^$/d' $BLOCKED
1340 status
1341 else
1342 echo "$PACKAGE is not in the blocked packages list."
1343 echo ""
1344 exit 0
1345 fi
1346 echo ""
1347 ;;
1348 get)
1349 # Downlowd a package with wget.
1351 check_for_package_on_cmdline
1352 check_for_packages_list
1353 check_for_package_in_list
1354 echo ""
1355 download $PACKAGE.tazpkg
1356 echo ""
1357 ;;
1358 get-install)
1359 # Download and install a package.
1361 check_root
1362 check_for_package_on_cmdline
1363 check_for_packages_list
1364 check_for_package_in_list
1365 # Check if forced install.
1366 if [ "$3" = "--forced" ]; then
1367 rm -f $CACHE_DIR/$PACKAGE.tazpkg
1368 else
1369 check_for_installed_package
1370 fi
1371 cd $CACHE_DIR
1372 if [ -f "$PACKAGE.tazpkg" ]; then
1373 echo "$PACKAGE already in the cache : $CACHE_DIR"
1374 else
1375 echo ""
1376 download $PACKAGE.tazpkg
1377 fi
1378 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
1379 install_package
1380 check_for_deps
1381 if [ ! "$MISSING_PACKAGE" = "" ]; then
1382 install_deps
1383 fi
1384 ;;
1385 clean-cache)
1386 # Remove all downloaded packages.
1388 check_root
1389 files=`ls -1 $CACHE_DIR | wc -l`
1390 echo ""
1391 echo -e "\033[1mClean cache :\033[0m $CACHE_DIR"
1392 echo "================================================================================"
1393 echo -n "Cleaning cache directory..."
1394 rm -rf $CACHE_DIR/*
1395 status
1396 echo "================================================================================"
1397 echo "$files file(s) removed from cache."
1398 echo ""
1399 ;;
1400 setup-mirror)
1401 # Change mirror URL.
1403 check_root
1404 # Backup old list.
1405 if [ -f "$LOCALSTATE/mirror" ]; then
1406 cp -f $LOCALSTATE/mirror $LOCALSTATE/mirror.bak
1407 fi
1408 echo ""
1409 echo -e "\033[1mCurrent mirror(s)\033[0m"
1410 echo "================================================================================"
1411 echo " `cat $MIRROR`"
1412 echo "
1413 Please enter URL of the new mirror (http or ftp). You must specify the complet
1414 address to the directory of the packages and packages.list file."
1415 echo ""
1416 echo -n "New mirror URL : "
1417 read NEW_MIRROR_URL
1418 if [ "$NEW_MIRROR_URL" = "" ]; then
1419 echo "Nothing as been change."
1420 else
1421 echo "Setting mirror(s) to : $NEW_MIRROR_URL"
1422 echo "$NEW_MIRROR_URL" > $LOCALSTATE/mirror
1423 fi
1424 echo ""
1425 ;;
1426 reconfigure)
1427 # Replay post_install from receipt
1429 check_for_package_on_cmdline
1430 check_root
1431 if [ -d "$INSTALLED/$PACKAGE" ]; then
1432 check_for_receipt
1433 # Check for post_install
1434 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
1435 . $INSTALLED/$PACKAGE/receipt
1436 post_install
1437 else
1438 echo -e "\nNothing to do for $PACKAGE."
1439 fi
1440 else
1441 echo -e "\npackage $PACKAGE is not installed."
1442 echo -e "Install package with 'tazpkg install' or 'tazpkg get-install'\n"
1443 fi
1444 ;;
1445 shell)
1446 # Tazpkg SHell
1448 if test $(id -u) = 0 ; then
1449 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
1450 else
1451 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
1452 fi
1453 if [ ! "$2" = "--noheader" ]; then
1454 clear
1455 echo ""
1456 echo -e "\033[1mTazpkg SHell.\033[0m"
1457 echo "================================================================================"
1458 echo "Type 'usage' to list all avalaible commands and 'quit' or 'q' to exit."
1459 echo ""
1460 fi
1461 while true
1462 do
1463 echo -en "$PROMPT"; read cmd
1464 case $cmd in
1465 q|quit)
1466 break ;;
1467 shell)
1468 echo "You are already running a Tazpkg SHell." ;;
1469 su)
1470 su -c 'exec tazpkg shell --noheader' && break ;;
1471 "")
1472 continue ;;
1473 *)
1474 tazpkg $cmd ;;
1475 esac
1476 done
1477 ;;
1478 usage|*)
1479 # Print a short help or give usage for an unknow or empty command.
1481 usage
1482 ;;
1483 esac
1485 exit 0