tazpkg view tazpkg @ rev 25

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