tazpkg view tazpkg @ rev 19

repack must launch genpkg_rules for slitaz-base-files
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Dec 12 12:27:55 2007 +0100 (2007-12-12)
parents 553e7c704427
children 94a427d2fe71
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 cpio -pd fs < files.list
650 . ./receipt
651 src=$TMP_DIR/nowhere
652 _pkg=$TMP_DIR/nowhere
653 fs=fs
654 # go on if errors and catch exit
655 ( set +e ; genpkg_rules > /dev/null 2>&1 )
656 cd $TMP_DIR
657 find fs | cpio -o -H newc 2> /dev/null | gzip -9 > fs.cpio.gz
658 cpio -o -H newc > $HERE/$PACKAGE-$VERSION.tazpkg 2> /dev/null <<EOT
659 receipt
660 files.list
661 fs.cpio.gz
662 EOT
663 cd $HERE
664 \rm -R $TMP_DIR
665 echo "Package $PACKAGE repacked successfully."
666 echo "Size : `du -sh $PACKAGE-$VERSION.tazpkg`"
667 echo ""
668 ;;
669 pack)
670 # Creat SliTaz package archive using cpio and gzip.
671 #
672 check_for_package_on_cmdline
673 cd $PACKAGE
674 if [ ! -f "receipt" ]; then
675 echo "Receipt is missing. Please read the documentation."
676 exit 0
677 else
678 echo ""
679 echo -e "\033[1mPacking :\033[0m $PACKAGE"
680 echo "================================================================================"
681 # Creat files.list with redirecting find outpout.
682 echo -n "Creating the list of files..." && cd fs
683 find . -type f -print > ../files.list
684 find . -type l -print >> ../files.list
685 cd .. && sed -i s/'^.'/''/ files.list
686 status
687 # Build cpio archives.
688 echo -n "Compressing the fs... "
689 find fs -print | cpio -o -H newc > fs.cpio
690 gzip fs.cpio && rm -rf fs
691 echo -n "Creating full cpio archive... "
692 find . -print | cpio -o -H newc > ../$PACKAGE.tazpkg
693 echo -n "Restoring original package tree... "
694 gzip -d fs.cpio.gz && cpio -id < fs.cpio
695 rm fs.cpio && cd ..
696 echo "================================================================================"
697 echo "Package $PACKAGE compressed successfully."
698 echo "Size : `du -sh $PACKAGE.tazpkg`"
699 echo ""
700 fi
701 ;;
702 recharge)
703 # Recharge packages.list from a mirror.
704 #
705 check_root
706 cd $LOCALSTATE
707 echo ""
708 if [ -f "$LOCALSTATE/packages.list" ]; then
709 echo -n "Creating backup of the last packages list..."
710 mv -f packages.list packages.list.bak
711 status
712 fi
713 download packages.list
714 if [ -f "$LOCALSTATE/packages.list.bak" ]; then
715 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
716 sed -i s/+// packages.diff
717 echo ""
718 echo -e "\033[1mMirrored packages diff\033[0m"
719 echo "================================================================================"
720 cat packages.diff
721 if [ ! "`cat packages.diff | wc -l`" = 0 ]; then
722 echo "================================================================================"
723 echo "`cat packages.diff | wc -l` new packages on the mirror."
724 echo ""
725 else
726 echo "`cat packages.diff | wc -l` new packages on the mirror."
727 echo ""
728 fi
729 else
730 echo -e "
731 ================================================================================
732 Last packages.list is ready to use. Note that next time you recharge the list,
733 a list of differencies will be displayed to show new and upgradable packages.\n"
734 fi
735 ;;
736 upgrade)
737 # Upgrade all installed packages with the new version from the mirror.
738 #
739 check_root
740 check_for_packages_list
741 cd $LOCALSTATE
742 # Touch the blocked pkgs list to avoid errors and remove any old
743 # upgrade list.
744 touch blocked-packages.list
745 rm -f upradable-packages.list
746 echo ""
747 echo -e "\033[1mAvalaible upgrade\033[0m"
748 echo "================================================================================"
749 for pkg in $INSTALLED/*
750 do
751 . $pkg/receipt
752 # Skip specified pkgs listed in $LOCALSTATE/blocked-packages.list
753 if grep -q "^$PACKAGE" $BLOCKED; then
754 blocked=$(($blocked+1))
755 else
756 # Check if the installed package is in the current list (other
757 # mirror or local).
758 if grep -q "^$PACKAGE-[0-9]" packages.list; then
759 # Set new kg and version for futur comparaison
760 NEW_PACKAGE=`grep ^$PACKAGE-[0-9] packages.list`
761 NEW_VERSION=`echo $NEW_PACKAGE | sed s/$PACKAGE-/''/`
762 # Compare version. Upgrade are only avalaible for official
763 # packages, so we control de mirror and it should be ok if
764 # we just check for egality.
765 if [ "$VERSION" != "$NEW_VERSION" ]; then
766 # Version seems different. Check for major, minor or
767 # revision
768 PKG_MAJOR=`echo $VERSION | cut -f1 -d"."`
769 NEW_MAJOR=`echo $NEW_VERSION | cut -f1 -d"."`
770 PKG_MINOR=`echo $VERSION | cut -f2 -d"."`
771 NEW_MINOR=`echo $NEW_VERSION | cut -f2 -d"."`
772 # Major
773 if [ "$NEW_MAJOR" -gt "$PKG_MAJOR" ]; then
774 RELEASE=major
775 fi
776 if [ "$NEW_MAJOR" -lt "$PKG_MAJOR" ]; then
777 RELEASE=$WARNING
778 FIXE=yes
779 fi
780 # Minor
781 if [ "$NEW_MINOR" -gt "$PKG_MINOR" ]; then
782 RELEASE=minor
783 fi
784 if [ "$NEW_MINOR" -lt "$PKG_MINOR" ]; then
785 RELEASE=$WARNING
786 FIXE=yes
787 fi
788 # Default to revision.
789 if [ -z $RELEASE ]; then
790 RELEASE=revision
791 fi
792 echo -n "$PACKAGE"
793 echo -en "\033[24G $VERSION"
794 echo -en "\033[38G --->"
795 echo -en "\033[48G $NEW_VERSION"
796 echo -en "\033[60G $CATEGORY"
797 echo -e "\033[72G $RELEASE"
798 up=$(($up+1))
799 echo "$PACKAGE" >> upradable-packages.list
800 unset RELEASE
801 fi
802 packages=$(($packages+1))
803 fi
804 fi
805 done
806 rm -f $tmpfile
807 if [ ! "$up" = "" ]; then
808 echo "================================================================================"
809 echo "$packages installed and listed packages to consider, $up to upgrade, $blocked blocked."
810 echo ""
811 else
812 echo "$packages installed and listed packages to consider, 0 to upgrade, $blocked blocked."
813 echo ""
814 exit 0
815 fi
816 # What to do if major or minor version is smaller.
817 if [ "$FIXE" == "yes" ]; then
818 echo -e "$WARNING ---> Installed package seems more recent than the mirrored one."
819 echo "You can block packages using the command : 'tazpkg block package'"
820 echo "Or upgrade package at you own risks."
821 echo ""
822 fi
823 # Ask for upgrade, it can be done an other time.
824 echo -n "Upgrade now (y/N) ? "; read anser
825 if [ ! "$anser" = "y" ]; then
826 echo -e "\nExiting. No package upgraded.\n"
827 exit 0
828 fi
829 # If anser is yes (y). Install all new version.
830 for pkg in `cat upradable-packages.list`
831 do
832 tazpkg get-install $pkg --forced
833 done
834 ;;
835 block)
836 # Add a pkg name to the list of blocked packages.
837 #
838 check_root
839 check_for_package_on_cmdline
840 echo ""
841 if grep -q "^$PACKAGE" $BLOCKED; then
842 echo "$PACKAGE is already in the blocked packages list."
843 echo ""
844 exit 0
845 else
846 echo -n "Add $PACKAGE to : $BLOCKED..."
847 echo $PACKAGE >> $BLOCKED
848 status
849 fi
850 echo ""
851 ;;
852 unblock)
853 # Remove a pkg name to the list of blocked packages.
854 #
855 check_root
856 check_for_package_on_cmdline
857 echo ""
858 if grep -q "^$PACKAGE" $BLOCKED; then
859 echo -n "Removing $PACKAGE from : $BLOCKED..."
860 sed -i s/$PACKAGE/''/ $BLOCKED
861 sed -i '/^$/d' $BLOCKED
862 status
863 else
864 echo "$PACKAGE is not in the blocked packages list."
865 echo ""
866 exit 0
867 fi
868 echo ""
869 ;;
870 get)
871 # Downlowd a package with wget.
872 #
873 check_for_package_on_cmdline
874 check_for_packages_list
875 check_for_package_in_list
876 echo ""
877 download $PACKAGE.tazpkg
878 echo ""
879 ;;
880 get-install)
881 # Download and install a package.
882 #
883 check_root
884 check_for_package_on_cmdline
885 check_for_packages_list
886 check_for_package_in_list
887 # Check if forced install.
888 if [ "$3" = "--forced" ]; then
889 rm -f $CACHE_DIR/$PACKAGE.tazpkg
890 else
891 check_for_installed_package
892 fi
893 cd $CACHE_DIR
894 if [ -f "$PACKAGE.tazpkg" ]; then
895 echo "$PACKAGE already in the cache : $CACHE_DIR"
896 else
897 echo ""
898 download $PACKAGE.tazpkg
899 fi
900 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
901 install_package
902 check_for_deps
903 if [ ! "$MISSING_PACKAGE" = "" ]; then
904 install_deps
905 fi
906 ;;
907 clean-cache)
908 # Remove all downloaded packages.
909 #
910 check_root
911 files=`ls -1 $CACHE_DIR | wc -l`
912 echo ""
913 echo -e "\033[1mCleaning cache directory :\033[0m $CACHE_DIR"
914 echo "================================================================================"
915 rm -rf $CACHE_DIR/*
916 echo "$files file(s) removed from cache."
917 echo ""
918 ;;
919 setup-mirror)
920 # Change mirror URL.
921 #
922 check_root
923 # Backup old list.
924 if [ -f "$LOCALSTATE/mirror" ]; then
925 mv -f $LOCALSTATE/mirror $LOCALSTATE/mirror.bak
926 fi
927 echo ""
928 echo -e "\033[1mCurrent mirror(s)\033[0m"
929 echo "================================================================================"
930 echo " `cat $MIRROR`"
931 echo "
932 Please enter URL of the new mirror (http or ftp). You must specify the complet
933 address to the directory of the packages and packages.list file."
934 echo ""
935 echo -n "New mirror URL : "
936 read NEW_MIRROR_URL
937 if [ "$NEW_MIRROR_URL" = "" ]; then
938 echo "Nothing as been change."
939 else
940 echo "Setting mirror(s) to : $NEW_MIRROR_URL"
941 echo "$NEW_MIRROR_URL" > $LOCALSTATE/mirror
942 fi
943 echo ""
944 ;;
945 usage|*)
946 # Print a short help or give usage for an unknow or empty command.
947 #
948 usage
949 ;;
950 esac
952 exit 0