tazpkg view tazpkg @ rev 36

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