tazpkg view tazpkg @ rev 10

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