tazpkg view tazpkg @ rev 29

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