tazpkg view tazpkg @ rev 24

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