tazpkg view tazpkg @ rev 18

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