tazpkg view tazpkg @ rev 13

Documented search-file and update the ChangeLog
author Christophe Lincoln <pankso@slitaz.org>
date Wed Nov 28 18:15:20 2007 +0100 (2007-11-28)
parents fa636cb87e98
children 09b5627e6119
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 SliTaz - GNU General Public License v3.
11 # Initial author : <pankso@slitaz.org>
12 #
13 VERSION=1.4pre
15 ####################
16 # Script variables #
17 ####################
19 # Packages categories.
20 CATEGORIES="base-system base-apps x-window extra devel"
22 # Initialize some variables to use words
23 # rater than numbers for functions and actions.
24 COMMAND=$1
25 if [ -f $2 ]; then
26 # Set pkg basename for install, extract
27 PACKAGE=$(basename ${2%.tazpkg} 2>/dev/null)
28 else
29 # Pkg name for remove, search and all other cmds
30 PACKAGE=${2%.tazpkg}
31 fi
32 PACKAGE_FILE=$2
33 TARGET_DIR=$3
34 TOP_DIR=`pwd`
35 TMP_DIR=/tmp/tazpkg-$$-$RANDOM
37 # Path to tazpkg used dir and configuration files
38 LOCALSTATE=/var/lib/tazpkg
39 INSTALLED=$LOCALSTATE/installed
40 CACHE_DIR=/var/cache/tazpkg
41 MIRROR=$LOCALSTATE/mirror
42 PACKAGES_LIST=$LOCALSTATE/packages.list
43 BLOCKED=$LOCALSTATE/blocked-packages.list
45 # Bold red warnig for upgrade.
46 WARNING="\\033[1;31mWARNING\\033[0;39m"
48 # Check if the directories and files used by Tazpkg
49 # exists. If not and user is root we creat them.
50 if test $(id -u) = 0 ; then
51 if [ ! -d "$CACHE_DIR" ]; then
52 mkdir -p $CACHE_DIR
53 fi
54 if [ ! -d "$INSTALLED" ]; then
55 mkdir -p $INSTALLED
56 fi
57 if [ ! -f "$LOCALSTATE/mirror" ]; then
58 echo "$DEFAULT_MIRROR" > $LOCALSTATE/mirror
59 fi
60 fi
62 ####################
63 # Script functions #
64 ####################
66 # Print the usage.
67 usage ()
68 {
69 echo -e "SliTaz packages manager - Version: $VERSION
70 \033[1mUsage: \033[0m tazpkg [command] [package|dir|pattern|list|cat|--opt] [dir|--opt]
71 \033[1mCommands: \033[0m
72 usage Print this short usage.
73 list List installed packages on the system by category or all.
74 list-mirror List all available packages on the mirror (--diff for new).
75 info Print informations about the package.
76 desc Print description of a package (if it exist).
77 list-files List of files installed with the package.
78 search Search for a package by pattern or name.
79 search-file Search for file(s) in all installed packages files.
80 install Install a local (*.tazpkg) package (--forced to force).
81 install-list Install all packages from a list of packages.
82 remove Remove the specified package and all installed files.
83 extract Extract a (*.tazpkg) package into a directory.
84 pack Pack an unpacked or prepared package tree.
85 recharge Recharge your packages.list from the mirror.
86 upgrade Upgrade all installed and listed packages on the mirror.
87 block|unblock Block an installed package version or unblock it for upgrade.
88 get Download a package into the current directory.
89 get-install Download and install a package from the mirror.
90 clean-cache Clean all packages downloaded in cache directory.
91 setup-mirror Change the mirror url configuration."
92 }
94 # Status function with color (supported by Ash).
95 status()
96 {
97 local CHECK=$?
98 echo -en "\\033[70G[ "
99 if [ $CHECK = 0 ]; then
100 echo -en "\\033[1;33mOK"
101 else
102 echo -en "\\033[1;31mFailed"
103 fi
104 echo -e "\\033[0;39m ]"
105 }
107 # Check if user is root to install, or remove packages.
108 check_root()
109 {
110 if test $(id -u) != 0 ; then
111 echo -e "\nYou must be root to run `basename $0` with this option."
112 echo -e "Please type 'su' and root password to become super-user.\n"
113 exit 0
114 fi
115 }
117 # Check for a package name on cmdline.
118 check_for_package_on_cmdline()
119 {
120 if [ -z "$PACKAGE" ]; then
121 echo -e "\nPlease specify a package name on the command line.\n"
122 exit 0
123 fi
124 }
126 # Check if the package (*.tazpkg) exist before installing or extracting.
127 check_for_package_file()
128 {
129 if [ ! -f "$PACKAGE_FILE" ]; then
130 echo -e "
131 Unable to find : $PACKAGE_FILE\n"
132 exit 0
133 fi
134 }
136 # Check for the receipt of an installed package.
137 check_for_receipt()
138 {
139 if [ ! -f "$INSTALLED/$PACKAGE/receipt" ]; then
140 echo -e "\nUnable to find the receipt : $INSTALLED/$PACKAGE/receipt\n"
141 exit 0
142 fi
143 }
145 # Check if a package is already installed.
146 check_for_installed_package()
147 {
148 if [ -d "$INSTALLED/${PACKAGE%-[0-9]*}" ]; then
149 echo -e "
150 $PACKAGE is already installed. You can use the --forced option to force
151 installation or remove it and reinstall.\n"
152 exit 0
153 fi
154 }
156 # Check for packages.list to download and install packages.
157 check_for_packages_list()
158 {
159 if [ ! -f "$LOCALSTATE/packages.list" ]; then
160 echo -e "
161 Unable to find the list : $LOCALSTATE/packages.list\n
162 You must probably run 'tazpkg recharge' as root to get the last list of
163 packages avalaible on the mirror.\n"
164 exit 0
165 fi
166 }
168 # Check for a package in packages.list. Used by get and get-install to grep
169 # package basename.
170 check_for_package_in_list()
171 {
172 if grep -q "^$PACKAGE-[0-9]" $LOCALSTATE/packages.list; then
173 PACKAGE=`grep ^$PACKAGE-[0-9] $LOCALSTATE/packages.list`
174 else
175 echo -e "\nUnable to find : $PACKAGE in the mirrored packages list.\n"
176 exit 0
177 fi
178 }
180 # Extract a package with cpio and gzip.
181 extract_package()
182 {
183 echo -n "Extracting $PACKAGE..."
184 cpio -id < $PACKAGE.tazpkg && rm -f $PACKAGE.tazpkg
185 gzip -d fs.cpio.gz
186 echo -n "Extracting the pseudo fs... "
187 cpio -id < fs.cpio && rm fs.cpio
188 }
190 # This function install a package in the rootfs.
191 install_package()
192 {
193 mkdir -p $TMP_DIR
194 echo ""
195 echo -e "\033[1mInstallation of :\033[0m $PACKAGE"
196 echo "================================================================================"
197 echo -n "Copying $PACKAGE... "
198 cp $PACKAGE_FILE $TMP_DIR
199 status
200 cd $TMP_DIR
201 extract_package
202 # Include temporary receipt to get the right variables.
203 . $PWD/receipt
204 # Make the installed package data dir to store
205 # the receipt and the files list.
206 mkdir -p $INSTALLED/$PACKAGE
207 cp receipt $INSTALLED/$PACKAGE
208 # Include installed receipt.
209 . $INSTALLED/$PACKAGE/receipt
210 # Copy the list of files and the description if found.
211 cp files.list $INSTALLED/$PACKAGE
212 if [ -f "description.txt" ]; then
213 cp description.txt $INSTALLED/$PACKAGE
214 fi
215 if [ `cat $INSTALLED/$PACKAGE/receipt | grep pre_install` ]; then
216 # Execute post install commands.
217 pre_install
218 fi
219 echo -n "Installing $PACKAGE... "
220 cp -a fs/* /
221 status
222 # Remove the temporary random directory.
223 echo -n "Removing all tmp files... "
224 cd .. && rm -rf $TMP_DIR
225 status
226 if [ `cat $INSTALLED/$PACKAGE/receipt | grep post_install` ]; then
227 # Execute post install commands.
228 post_install
229 fi
230 cd $TOP_DIR
231 echo "================================================================================"
232 echo "$PACKAGE ($VERSION) is installed."
233 echo ""
234 }
236 # Check for missing deps listed in a receipt packages.
237 check_for_deps()
238 {
239 for i in $DEPENDS
240 do
241 if [ ! -d "$INSTALLED/$i" ]; then
242 MISSING_PACKAGE=$i
243 deps=$(($deps+1))
244 fi
245 done
246 if [ ! "$MISSING_PACKAGE" = "" ]; then
247 echo -e "\033[1mTracking dependencies for :\033[0m $PACKAGE"
248 echo "================================================================================"
249 for i in $DEPENDS
250 do
251 if [ ! -d "$INSTALLED/$i" ]; then
252 MISSING_PACKAGE=$i
253 echo "Missing : $MISSING_PACKAGE"
254 fi
255 done
256 echo "================================================================================"
257 echo "$deps missing package(s) to install."
258 fi
259 }
261 # Install all missing deps. First ask user then install all missing deps
262 # from local dir, cdrom, media or from the mirror. In case we want to
263 # install packages from local, we need a packages.list to find the version.
264 install_deps()
265 {
266 echo ""
267 echo -n "Install all missing dependencies (y/N) ? "; read anser
268 if [ "$anser" = "y" ]; then
269 for pkg in $DEPENDS
270 do
271 if [ ! -d "$INSTALLED/$pkg" ]; then
272 # We can install packages from a local dir by greping
273 # the TAZPKG_BASENAME in the local packages.list.
274 if [ -f "$TOP_DIR/packages.list" ]; then
275 echo "Checking if $pkg exist in local list... "
276 TAZPKG_BASENAME=`grep -e ^$pkg-[0-9] $TOP_DIR/packages.list`
277 if [ -f "$TAZPKG_BASENAME.tazpkg" ]; then
278 tazpkg install $TAZPKG_BASENAME.tazpkg
279 fi
280 # Install deps from the mirror.
281 else
282 if [ ! -f "$LOCALSTATE/packages.list" ]; then
283 tazpkg recharge
284 fi
285 tazpkg get-install $pkg
286 fi
287 fi
288 done
289 else
290 echo -e "\nLeaving dependencies for $PACKAGE unsolved."
291 echo -e "The package is installed but will probably not work.\n"
292 fi
293 }
295 ###################
296 # Tazpkg commands #
297 ###################
299 case "$COMMAND" in
300 list)
301 # List all installed packages or a specific category.
302 #
303 if [ "$2" = "category" ]; then
304 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
305 exit 0
306 fi
307 # Check for an asked category.
308 if [ -n "$2" ]; then
309 ASKED_CATEGORY=$2
310 echo ""
311 echo -e "\033[1mInstalled packages of category :\033[0m $ASKED_CATEGORY"
312 echo "================================================================================"
313 for pkg in $INSTALLED/*
314 do
315 . $pkg/receipt
316 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
317 echo -n "$PACKAGE"
318 echo -e "\033[24G $VERSION"
319 packages=$(($packages+1))
320 fi
321 done
322 echo "================================================================================"
323 echo -e "$packages packages installed of category $ASKED_CATEGORY."
324 echo ""
325 else
326 # By default list all packages and version.
327 echo ""
328 echo -e "\033[1mList of all installed packages\033[0m"
329 echo "================================================================================"
330 for pkg in $INSTALLED/*
331 do
332 . $pkg/receipt
333 echo -n "$PACKAGE"
334 echo -en "\033[24G $VERSION"
335 echo -e "\033[42G $CATEGORY"
336 packages=$(($packages+1))
337 done
338 echo "================================================================================"
339 echo "$packages packages installed."
340 echo ""
341 fi
342 ;;
343 list-mirror)
344 # List all available packages on the mirror. Option --diff display
345 # last mirrored packages diff (see recharge).
346 check_for_packages_list
347 if [ "$2" = "--diff" ]; then
348 if [ -f "$LOCALSTATE/packages.diff" ]; then
349 echo ""
350 echo -e "\033[1mMirrored packages diff\033[0m"
351 echo "================================================================================"
352 cat $LOCALSTATE/packages.diff
353 echo "================================================================================"
354 pkgs=`cat $LOCALSTATE/packages.diff | wc -l`
355 echo "$pkgs new packages listed on the mirror."
356 echo ""
357 else
358 echo -e "\nUnable to list anything, no packages.diff found."
359 echo -e "Recharge your current list to creat a first diff.\n"
360 fi
361 else
362 echo ""
363 echo -e "\033[1mList of available packages on the mirror\033[0m"
364 echo "================================================================================"
365 cat $LOCALSTATE/packages.list
366 echo "================================================================================"
367 pkgs=`cat $LOCALSTATE/packages.list | wc -l`
368 echo "$pkgs packages in the last recharged list."
369 echo ""
370 fi
371 ;;
372 list-files)
373 # List files installed with the package.
374 #
375 check_for_package_on_cmdline
376 check_for_receipt
377 echo ""
378 echo -e "\033[1mInstalled files with :\033[0m $PACKAGE"
379 echo "================================================================================"
380 cat $INSTALLED/$PACKAGE/files.list | sort
381 echo "================================================================================"
382 files=`cat $INSTALLED/$PACKAGE/files.list | wc -l`
383 echo "$files files installed with $PACKAGE."
384 echo ""
385 ;;
386 info)
387 # Informations about package.
388 #
389 check_for_package_on_cmdline
390 check_for_receipt
391 . $INSTALLED/$PACKAGE/receipt
392 echo ""
393 echo -e "\033[1mTazpkg informations\033[0m
394 ================================================================================
395 Package : $PACKAGE
396 Version : $VERSION
397 Category : $CATEGORY
398 Short desc : $SHORT_DESC
399 Maintainer : $MAINTAINER"
400 if [ ! "$DEPENDS" = "" ]; then
401 echo -e "Depends : $DEPENDS"
402 fi
403 if [ ! "$WANTED" = "" ]; then
404 echo -e "Wanted src : $WANTED"
405 fi
406 if [ ! "$WEB_SITE" = "" ]; then
407 echo -e "Web site : $WEB_SITE"
408 fi
409 echo "================================================================================"
410 echo ""
411 ;;
412 desc)
413 # Display package description.txt if available.
414 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
415 echo ""
416 echo -e "\033[1mDescription of :\033[0m $PACKAGE"
417 echo "================================================================================"
418 cat $INSTALLED/$PACKAGE/description.txt
419 echo "================================================================================"
420 echo ""
421 else
422 echo -e "\nSorry, no description available for this package.\n"
423 fi
424 ;;
425 search)
426 # Search for a package by pattern or name.
427 #
428 if [ -z "$2" ]; then
429 echo -e "\nPlease specify a pattern or a package name to search."
430 echo -e "Example : 'tazpkg search paint'. \n"
431 exit 0
432 fi
433 echo ""
434 echo -e "\033[1mSearch result for :\033[0m $2"
435 echo ""
436 echo "Installed packages"
437 echo "================================================================================"
438 list=`ls -1 $INSTALLED | grep $2`
439 for pkg in $list
440 do
441 . $INSTALLED/$pkg/receipt
442 echo -n "$PACKAGE "
443 echo -en "\033[24G $VERSION"
444 echo -e "\033[42G $CATEGORY"
445 packages=$(($packages+1))
446 done
447 # Set correct ending messages.
448 if [ "$packages" = "" ]; then
449 echo "0 installed packages found for : $2"
450 echo ""
451 else
452 echo "================================================================================"
453 echo "$packages installed package(s) found for : $2"
454 echo ""
455 fi
456 echo "Available packages"
457 echo "================================================================================"
458 if [ -f "$LOCALSTATE/packages.list" ]; then
459 cat $LOCALSTATE/packages.list | grep $2
460 packages=`cat $LOCALSTATE/packages.list | grep $2 | wc -l`
461 else
462 echo -e "
463 No 'packages.list' found to check for mirrored packages. For more results,
464 please run once 'tazpkg recharge' as root before searching.\n"
465 fi
466 if [ "$packages" = "0" ]; then
467 echo "0 available packages found for : $2"
468 echo ""
469 else
470 echo "================================================================================"
471 echo "$packages available package(s) found for : $2"
472 echo ""
473 fi
474 ;;
475 search-file)
476 # Search for a file by pattern or name in all files.list.
477 #
478 if [ -z "$2" ]; then
479 echo -e "\nPlease specify a pattern or a file name to search."
480 echo -e "Example : 'tazpkg search-file libnss'. \n"
481 exit 0
482 fi
483 echo ""
484 echo -e "\033[1mSearch result for file :\033[0m $2"
485 echo "================================================================================"
486 # Check all pkg files.list in search match with specify the package
487 # name and the full path to the file(s).
488 for pkg in $INSTALLED/*
489 do
490 if grep -q $2 $pkg/files.list; then
491 . $pkg/receipt
492 echo ""
493 echo -e "\033[1mPackage $PACKAGE :\033[0m"
494 grep $2 $pkg/files.list
495 files=`grep $2 $pkg/files.list | wc -l`
496 match=$(($match+$files))
497 fi
498 done
499 if [ "$match" = "" ]; then
500 echo "0 file found for : $2"
501 echo ""
502 else
503 echo ""
504 echo "================================================================================"
505 echo "$match file(s) found for : $2"
506 echo ""
507 fi
508 ;;
509 install)
510 # Install .tazpkg packages.
511 #
512 check_root
513 check_for_package_on_cmdline
514 check_for_package_file
515 # Check if forced install.
516 if [ "$3" = "--forced" ]; then
517 continue
518 else
519 check_for_installed_package
520 fi
521 install_package
522 # Resolv package deps.
523 check_for_deps
524 if [ ! "$MISSING_PACKAGE" = "" ]; then
525 install_deps
526 fi
527 ;;
528 install-list)
529 # Install a set of packages from a list.
530 #
531 check_root
532 if [ -z "$2" ]; then
533 echo -e "
534 Please change directory (cd) to the packages repository, and specify the
535 list of packages to install. Example : tazpkg install-list packages.list\n"
536 exit 0
537 fi
538 # Check if the packages list exist.
539 if [ ! -f "$2" ]; then
540 echo "Unable to find : $2"
541 exit 0
542 else
543 LIST=`cat $2`
544 fi
545 # Install all packages.
546 for pkg in $LIST
547 do
548 if [ "$3" = "--forced" ]; then
549 tazpkg install $pkg --forced
550 else
551 tazpkg install $pkg
552 fi
553 done
554 ;;
555 remove)
556 # Remove packages.
557 #
558 check_root
559 check_for_package_on_cmdline
560 if [ ! -d "$INSTALLED/$PACKAGE" ]; then
561 echo -e "\n$PACKAGE is not installed.\n"
562 exit 0
563 else
564 . $INSTALLED/$PACKAGE/receipt
565 fi
566 echo ""
567 echo "Remove $PACKAGE ($VERSION) ?"
568 echo -n "Please confirm uninstallation (y/N) : "; read anser
569 if [ "$anser" = "y" ]; then
570 echo ""
571 echo -e "\033[1mRemoving :\033[0m $PACKAGE"
572 echo "================================================================================"
573 echo -n "Removing all files installed..."
574 for file in `cat $INSTALLED/$PACKAGE/files.list`
575 do
576 rm -f $file
577 done
578 status
579 # Remove package receipt.
580 echo -n "Removing package receipt..."
581 rm -rf $INSTALLED/$PACKAGE
582 status
583 else
584 echo ""
585 echo "Uninstallation of $PACKAGE cancelled."
586 fi
587 echo ""
588 ;;
589 extract)
590 # Extract .tazpkg cpio archive into a directory.
591 #
592 check_for_package_on_cmdline
593 check_for_package_file
594 echo ""
595 echo -e "\033[1mExtracting :\033[0m $PACKAGE"
596 echo "================================================================================"
597 # If any directory destination is found on the cmdline
598 # we creat one in the current dir using the package name.
599 if [ -n "$TARGET_DIR" ]; then
600 DESTDIR=$TARGET_DIR/$PACKAGE
601 else
602 DESTDIR=$PACKAGE
603 fi
604 mkdir -p $DESTDIR
605 echo -n "Copying original package..."
606 cp $PACKAGE_FILE $DESTDIR
607 status
608 cd $DESTDIR
609 extract_package
610 echo "================================================================================"
611 echo "$PACKAGE is extracted to : $DESTDIR"
612 echo ""
613 ;;
614 pack)
615 # Creat SliTaz package archive using cpio and gzip.
616 #
617 check_for_package_on_cmdline
618 cd $PACKAGE
619 if [ ! -f "receipt" ]; then
620 echo "Receipt is missing. Please read the documentation."
621 exit 0
622 else
623 echo ""
624 echo -e "\033[1mPacking :\033[0m $PACKAGE"
625 echo "================================================================================"
626 # Creat files.list with redirecting find outpout.
627 echo -n "Creating the list of files..." && cd fs
628 find . -type f -print > ../files.list
629 find . -type l -print >> ../files.list
630 cd .. && sed -i s/'^.'/''/ files.list
631 status
632 # Build cpio archives.
633 echo -n "Compressing the fs... "
634 find fs -print | cpio -o -H newc > fs.cpio
635 gzip fs.cpio && rm -rf fs
636 echo -n "Creating full cpio archive... "
637 find . -print | cpio -o -H newc > ../$PACKAGE.tazpkg
638 echo -n "Restoring original package tree... "
639 gzip -d fs.cpio.gz && cpio -id < fs.cpio
640 rm fs.cpio && cd ..
641 echo "================================================================================"
642 echo "Package $PACKAGE compressed succefully."
643 echo "Size : `du -sh $PACKAGE.tazpkg`"
644 echo ""
645 fi
646 ;;
647 recharge)
648 # Recharge packages.list from a mirror.
649 #
650 check_root
651 cd $LOCALSTATE
652 echo ""
653 if [ -f "$LOCALSTATE/packages.list" ]; then
654 echo -n "Creating backup of the last packages list..."
655 mv -f packages.list packages.list.bak
656 status
657 fi
658 wget `cat $MIRROR`/packages.list
659 if [ -f "$LOCALSTATE/packages.list.bak" ]; then
660 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
661 sed -i s/+// packages.diff
662 echo ""
663 echo -e "\033[1mMirrored packages diff\033[0m"
664 echo "================================================================================"
665 cat packages.diff
666 if [ ! "`cat packages.diff | wc -l`" = 0 ]; then
667 echo "================================================================================"
668 echo "`cat packages.diff | wc -l` new packages on the mirror."
669 echo ""
670 else
671 echo "`cat packages.diff | wc -l` new packages on the mirror."
672 echo ""
673 fi
674 else
675 echo -e "
676 ================================================================================
677 Last packages.list is ready to use. Note that next time you recharge the list,
678 a list of differencies will be displayed to show new and upgradable packages.\n"
679 fi
680 ;;
681 upgrade)
682 # Upgrade all installed packages with the new version from the mirror.
683 #
684 check_root
685 check_for_packages_list
686 cd $LOCALSTATE
687 # Touch the blocked pkgs list to avoid errors and remove any old
688 # upgrade list.
689 touch blocked-packages.list
690 rm -f upradable-packages.list
691 echo ""
692 echo -e "\033[1mAvalaible upgrade\033[0m"
693 echo "================================================================================"
694 for pkg in $INSTALLED/*
695 do
696 . $pkg/receipt
697 # Skip specified pkgs listed in $LOCALSTATE/blocked-packages.list
698 if grep -q "^$PACKAGE" $BLOCKED; then
699 blocked=$(($blocked+1))
700 else
701 # Check if the installed package is in the current list (other
702 # mirror or local).
703 if grep -q "^$PACKAGE-[0-9]" packages.list; then
704 # Set new kg and version for futur comparaison
705 NEW_PACKAGE=`grep ^$PACKAGE-[0-9] packages.list`
706 NEW_VERSION=`echo $NEW_PACKAGE | sed s/$PACKAGE-/''/`
707 # Compare version. Upgrade are only avalaible for official
708 # packages, so we control de mirror and it should be ok if
709 # we just check for egality.
710 if [ "$VERSION" != "$NEW_VERSION" ]; then
711 # Version seems different. Check for major, minor or
712 # revision
713 PKG_MAJOR=`echo $VERSION | cut -f1 -d"."`
714 NEW_MAJOR=`echo $NEW_VERSION | cut -f1 -d"."`
715 PKG_MINOR=`echo $VERSION | cut -f2 -d"."`
716 NEW_MINOR=`echo $NEW_VERSION | cut -f2 -d"."`
717 # Major
718 if [ "$NEW_MAJOR" -gt "$PKG_MAJOR" ]; then
719 RELEASE=major
720 fi
721 if [ "$NEW_MAJOR" -lt "$PKG_MAJOR" ]; then
722 RELEASE=$WARNING
723 FIXE=yes
724 fi
725 # Minor
726 if [ "$NEW_MINOR" -gt "$PKG_MINOR" ]; then
727 RELEASE=minor
728 fi
729 if [ "$NEW_MINOR" -lt "$PKG_MINOR" ]; then
730 RELEASE=$WARNING
731 FIXE=yes
732 fi
733 # Default to revision.
734 if [ -z $RELEASE ]; then
735 RELEASE=revision
736 fi
737 echo -n "$PACKAGE"
738 echo -en "\033[24G $VERSION"
739 echo -en "\033[38G --->"
740 echo -en "\033[48G $NEW_VERSION"
741 echo -en "\033[60G $CATEGORY"
742 echo -e "\033[72G $RELEASE"
743 up=$(($up+1))
744 echo "$PACKAGE" >> upradable-packages.list
745 fi
746 packages=$(($packages+1))
747 fi
748 fi
749 done
750 rm -f $tmpfile
751 if [ ! "$up" = "" ]; then
752 echo "================================================================================"
753 echo "$packages installed and listed packages to consider, $up to upgrade, $blocked blocked."
754 echo ""
755 else
756 echo "$packages installed and listed packages to consider, 0 to upgrade, $blocked blocked."
757 echo ""
758 exit 0
759 fi
760 # What to do if major or minor version is smaller.
761 if [ "$FIXE" == "yes" ]; then
762 echo -e "$WARNING ---> Installed package seems more recent than the mirrored one."
763 echo "You can block packages using the command : 'tazpkg block package'"
764 echo "Or upgrade package at you own risks."
765 echo ""
766 fi
767 # Ask for upgrade, it can be done an other time.
768 echo -n "Upgrade now (y/N) ? "; read anser
769 if [ ! "$anser" = "y" ]; then
770 echo -e "\nExiting. No package upgraded.\n"
771 exit 0
772 fi
773 # If anser is yes (y). Install all new version.
774 for pkg in `cat upradable-packages.list`
775 do
776 tazpkg get-install $pkg --forced
777 done
778 ;;
779 block)
780 # Add a pkg name to the list of blocked packages.
781 #
782 check_root
783 check_for_package_on_cmdline
784 echo ""
785 if grep -q "^$PACKAGE" $BLOCKED; then
786 echo "$PACKAGE is already in the blocked packages list."
787 echo ""
788 exit 0
789 else
790 echo -n "Add $PACKAGE to : $BLOCKED..."
791 echo $PACKAGE >> $BLOCKED
792 status
793 fi
794 echo ""
795 ;;
796 unblock)
797 # Remove a pkg name to the list of blocked packages.
798 #
799 check_root
800 check_for_package_on_cmdline
801 echo ""
802 if grep -q "^$PACKAGE" $BLOCKED; then
803 echo -n "Removing $PACKAGE from : $BLOCKED..."
804 sed -i s/$PACKAGE/''/ $BLOCKED
805 sed -i '/^$/d' $BLOCKED
806 status
807 else
808 echo "$PACKAGE is not in the blocked packages list."
809 echo ""
810 exit 0
811 fi
812 echo ""
813 ;;
814 get)
815 # Downlowd a package with wget.
816 #
817 check_for_package_on_cmdline
818 check_for_packages_list
819 check_for_package_in_list
820 echo ""
821 wget `cat $MIRROR`/$PACKAGE.tazpkg
822 echo ""
823 ;;
824 get-install)
825 # Download and install a package.
826 #
827 check_root
828 check_for_package_on_cmdline
829 check_for_packages_list
830 check_for_package_in_list
831 # Check if forced install.
832 if [ "$3" = "--forced" ]; then
833 rm -f $CACHE_DIR/$PACKAGE.tazpkg
834 else
835 check_for_installed_package
836 fi
837 cd $CACHE_DIR
838 if [ -f "$PACKAGE.tazpkg" ]; then
839 echo "$PACKAGE already in the cache : $CACHE_DIR"
840 else
841 echo ""
842 wget `cat $MIRROR`/$PACKAGE.tazpkg
843 fi
844 install_package
845 check_for_deps
846 if [ ! "$MISSING_PACKAGE" = "" ]; then
847 install_deps
848 fi
849 ;;
850 clean-cache)
851 # Remove all downloaded packages.
852 #
853 check_root
854 files=`ls -1 $CACHE_DIR | wc -l`
855 echo ""
856 echo -e "\033[1mCleaning cache directory :\033[0m $CACHE_DIR"
857 echo "================================================================================"
858 rm -rf $CACHE_DIR/*
859 echo "$files file(s) removed from cache."
860 echo ""
861 ;;
862 setup-mirror)
863 # Change mirror URL.
864 #
865 check_root
866 # Backup old list.
867 if [ -f "$LOCALSTATE/mirror" ]; then
868 mv -f $LOCALSTATE/mirror $LOCALSTATE/mirror.bak
869 fi
870 echo ""
871 echo -e "\033[1mCurrent mirror\033[0m"
872 echo "================================================================================"
873 echo " `cat $MIRROR`"
874 echo "
875 Please enter URL of the new mirror (http or ftp). You must specify the complet
876 address to the directory of the packages and packages.list file."
877 echo ""
878 echo -n "New mirror URL : "
879 read NEW_MIRROR_URL
880 if [ "$NEW_MIRROR_URL" = "" ]; then
881 echo "Nothing as been change."
882 else
883 echo "Setting mirror to : $NEW_MIRROR_URL"
884 echo "$NEW_MIRROR_URL" > $LOCALSTATE/mirror
885 fi
886 echo ""
887 ;;
888 usage|*)
889 # Print a short help or give usage for an unknow or empty command.
890 #
891 usage
892 ;;
893 esac
895 exit 0