tazpkg view tazpkg @ rev 21

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