tazpkg view tazpkg @ rev 17

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