tazpkg view tazpkg @ rev 33

Set (c) 2008 and prepa for release 1.6
author Christophe Lincoln <pankso@slitaz.org>
date Sun Jan 06 22:31:13 2008 +0100 (2008-01-06)
parents b1ca74925fd0
children ffa554a68d00
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
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 done
619 . $INSTALLED/$THE_PACKAGE/receipt
620 fi
621 echo ""
622 if [ -n "$ALTERED" ]; then
623 echo "The following packages depend on $PACKAGE :"
624 for i in $ALTERED; do
625 echo " $i"
626 done
627 fi
628 echo "Remove $PACKAGE ($VERSION) ?"
629 echo -n "Please confirm uninstallation (y/N) : "; read anser
630 if [ "$anser" = "y" ]; then
631 echo ""
632 echo -e "\033[1mRemoving :\033[0m $PACKAGE"
633 echo "================================================================================"
634 echo -n "Removing all files installed..."
635 for file in `cat $INSTALLED/$PACKAGE/files.list`
636 do
637 rm -f $file 2>/dev/null
638 done
639 status
640 # Remove package receipt.
641 echo -n "Removing package receipt..."
642 rm -rf $INSTALLED/$PACKAGE
643 status
644 if [ -n "$ALTERED" ]; then
645 echo -n "Remove packages depending on $PACKAGE"
646 echo -n " (y/N) ? "; read anser
647 if [ "$anser" = "y" ]; then
648 for i in $ALTERED; do
649 tazpkg remove $i
650 done
651 fi
652 fi
653 else
654 echo ""
655 echo "Uninstallation of $PACKAGE cancelled."
656 fi
657 echo ""
658 ;;
659 extract)
660 # Extract .tazpkg cpio archive into a directory.
661 #
662 check_for_package_on_cmdline
663 check_for_package_file
664 echo ""
665 echo -e "\033[1mExtracting :\033[0m $PACKAGE"
666 echo "================================================================================"
667 # If any directory destination is found on the cmdline
668 # we creat one in the current dir using the package name.
669 if [ -n "$TARGET_DIR" ]; then
670 DESTDIR=$TARGET_DIR/$PACKAGE
671 else
672 DESTDIR=$PACKAGE
673 fi
674 mkdir -p $DESTDIR
675 echo -n "Copying original package..."
676 cp $PACKAGE_FILE $DESTDIR
677 status
678 cd $DESTDIR
679 extract_package
680 echo "================================================================================"
681 echo "$PACKAGE is extracted to : $DESTDIR"
682 echo ""
683 ;;
684 repack)
685 # Creat SliTaz package archive from an installed package.
686 #
687 check_for_package_on_cmdline
688 check_for_receipt
689 eval $(grep ^VERSION= $INSTALLED/$PACKAGE/receipt)
690 echo ""
691 echo -e "\033[1mRepacking :\033[0m $PACKAGE-$VERSION.tazpkg"
692 echo "================================================================================"
693 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
694 echo "Can't repack $PACKAGE"
695 exit 1
696 fi
697 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
698 echo "Can't repack, $PACKAGE files have been modified by:"
699 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
700 echo " $i"
701 done
702 exit 1
703 fi
704 MISSING=""
705 for i in $(sed 's,^fs,,g' < $INSTALLED/$PACKAGE/files.list); do
706 [ -e "$i" ] && continue
707 [ -L "$i" ] || MISSING="$MISSING $i"
708 done
709 if [ -n "$MISSING" ]; then
710 echo "Can't repack, the following files are lost:"
711 for i in $MISSING; do
712 echo " $i"
713 done
714 exit 1
715 fi
716 HERE=`pwd`
717 mkdir -p $TMP_DIR && cd $TMP_DIR
718 FILES="fs.cpio.gz\n"
719 for i in $(ls $INSTALLED/$PACKAGE) ; do
720 cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
721 done
722 cpio -pd fs < files.list 2> /dev/null
723 find fs | cpio -o -H newc 2> /dev/null | gzip -9 > fs.cpio.gz
724 echo -e "$FILES" | cpio -o -H newc 2> /dev/null > \
725 $HERE/$PACKAGE-$VERSION.tazpkg
726 cd $HERE
727 \rm -R $TMP_DIR
728 echo "Package $PACKAGE repacked successfully."
729 echo "Size : `du -sh $PACKAGE-$VERSION.tazpkg`"
730 echo ""
731 ;;
732 pack)
733 # Creat SliTaz package archive using cpio and gzip.
734 #
735 check_for_package_on_cmdline
736 cd $PACKAGE
737 if [ ! -f "receipt" ]; then
738 echo "Receipt is missing. Please read the documentation."
739 exit 0
740 else
741 echo ""
742 echo -e "\033[1mPacking :\033[0m $PACKAGE"
743 echo "================================================================================"
744 # Creat files.list with redirecting find outpout.
745 echo -n "Creating the list of files..." && cd fs
746 find . -type f -print > ../files.list
747 find . -type l -print >> ../files.list
748 cd .. && sed -i s/'^.'/''/ files.list
749 status
750 # Build cpio archives.
751 echo -n "Compressing the fs... "
752 find fs -print | cpio -o -H newc > fs.cpio
753 gzip fs.cpio && rm -rf fs
754 echo -n "Creating full cpio archive... "
755 find . -print | cpio -o -H newc > ../$PACKAGE.tazpkg
756 echo -n "Restoring original package tree... "
757 gzip -d fs.cpio.gz && cpio -id < fs.cpio
758 rm fs.cpio && cd ..
759 echo "================================================================================"
760 echo "Package $PACKAGE compressed successfully."
761 echo "Size : `du -sh $PACKAGE.tazpkg`"
762 echo ""
763 fi
764 ;;
765 recharge)
766 # Recharge packages.list from a mirror.
767 #
768 check_root
769 cd $LOCALSTATE
770 echo ""
771 if [ -f "$LOCALSTATE/packages.list" ]; then
772 echo -n "Creating backup of the last packages list..."
773 mv -f packages.list packages.list.bak
774 status
775 fi
776 download packages.list
777 if [ -f "$LOCALSTATE/packages.list.bak" ]; then
778 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
779 sed -i s/+// packages.diff
780 echo ""
781 echo -e "\033[1mMirrored packages diff\033[0m"
782 echo "================================================================================"
783 cat packages.diff
784 if [ ! "`cat packages.diff | wc -l`" = 0 ]; then
785 echo "================================================================================"
786 echo "`cat packages.diff | wc -l` new packages on the mirror."
787 echo ""
788 else
789 echo "`cat packages.diff | wc -l` new packages on the mirror."
790 echo ""
791 fi
792 else
793 echo -e "
794 ================================================================================
795 Last packages.list is ready to use. Note that next time you recharge the list,
796 a list of differencies will be displayed to show new and upgradable packages.\n"
797 fi
798 ;;
799 upgrade)
800 # Upgrade all installed packages with the new version from the mirror.
801 #
802 check_root
803 check_for_packages_list
804 cd $LOCALSTATE
805 # Touch the blocked pkgs list to avoid errors and remove any old
806 # upgrade list.
807 touch blocked-packages.list
808 rm -f upradable-packages.list
809 echo ""
810 echo -e "\033[1mAvalaible upgrade\033[0m"
811 echo "================================================================================"
812 for pkg in $INSTALLED/*
813 do
814 . $pkg/receipt
815 # Skip specified pkgs listed in $LOCALSTATE/blocked-packages.list
816 if grep -q "^$PACKAGE" $BLOCKED; then
817 blocked=$(($blocked+1))
818 else
819 # Check if the installed package is in the current list (other
820 # mirror or local).
821 if grep -q "^$PACKAGE-[0-9]" packages.list; then
822 # Set new kg and version for futur comparaison
823 NEW_PACKAGE=`grep ^$PACKAGE-[0-9] packages.list`
824 NEW_VERSION=`echo $NEW_PACKAGE | sed s/$PACKAGE-/''/`
825 # Compare version. Upgrade are only avalaible for official
826 # packages, so we control de mirror and it should be ok if
827 # we just check for egality.
828 if [ "$VERSION" != "$NEW_VERSION" ]; then
829 # Version seems different. Check for major, minor or
830 # revision
831 PKG_MAJOR=`echo $VERSION | cut -f1 -d"."`
832 NEW_MAJOR=`echo $NEW_VERSION | cut -f1 -d"."`
833 PKG_MINOR=`echo $VERSION | cut -f2 -d"."`
834 NEW_MINOR=`echo $NEW_VERSION | cut -f2 -d"."`
835 # Major
836 if [ "$NEW_MAJOR" -gt "$PKG_MAJOR" ]; then
837 RELEASE=major
838 fi
839 if [ "$NEW_MAJOR" -lt "$PKG_MAJOR" ]; then
840 RELEASE=$WARNING
841 FIXE=yes
842 fi
843 # Minor
844 if [ "$NEW_MINOR" -gt "$PKG_MINOR" ]; then
845 RELEASE=minor
846 fi
847 if [ "$NEW_MINOR" -lt "$PKG_MINOR" ]; then
848 RELEASE=$WARNING
849 FIXE=yes
850 fi
851 # Default to revision.
852 if [ -z $RELEASE ]; then
853 RELEASE=revision
854 fi
855 echo -n "$PACKAGE"
856 echo -en "\033[24G $VERSION"
857 echo -en "\033[38G --->"
858 echo -en "\033[48G $NEW_VERSION"
859 echo -en "\033[60G $CATEGORY"
860 echo -e "\033[72G $RELEASE"
861 up=$(($up+1))
862 echo "$PACKAGE" >> upradable-packages.list
863 unset RELEASE
864 fi
865 packages=$(($packages+1))
866 fi
867 fi
868 done
869 rm -f $tmpfile
870 if [ ! "$up" = "" ]; then
871 echo "================================================================================"
872 echo "$packages installed and listed packages to consider, $up to upgrade, $blocked blocked."
873 echo ""
874 else
875 echo "$packages installed and listed packages to consider, 0 to upgrade, $blocked blocked."
876 echo ""
877 exit 0
878 fi
879 # What to do if major or minor version is smaller.
880 if [ "$FIXE" == "yes" ]; then
881 echo -e "$WARNING ---> Installed package seems more recent than the mirrored one."
882 echo "You can block packages using the command : 'tazpkg block package'"
883 echo "Or upgrade package at you own risks."
884 echo ""
885 fi
886 # Ask for upgrade, it can be done an other time.
887 echo -n "Upgrade now (y/N) ? "; read anser
888 if [ ! "$anser" = "y" ]; then
889 echo -e "\nExiting. No package upgraded.\n"
890 exit 0
891 fi
892 # If anser is yes (y). Install all new version.
893 for pkg in `cat upradable-packages.list`
894 do
895 tazpkg get-install $pkg --forced
896 done
897 ;;
898 check)
899 # check installed packages set.
900 #
901 check_root
902 cd $INSTALLED
903 for PACKAGE in `ls`; do
904 DEPENDS=""
905 . $PACKAGE/receipt
906 if [ -s $PACKAGE/modifiers ]; then
907 echo "The package $PACKAGE $VERSION has been modified by :"
908 for i in $(cat $PACKAGE/modifiers); do
909 echo " $i"
910 done
911 fi
912 MSG="Files lost from $PACKAGE $VERSION :\n"
913 while read file; do
914 [ -e "$file" ] && continue
915 if [ -L "$file" ]; then
916 MSG="$MSG target of symlink"
917 fi
918 echo -e "$MSG $file"
919 MSG=""
920 done < $PACKAGE/files.list
921 MSG="Missing dependancies for $PACKAGE $VERSION :\n"
922 for i in $DEPENDS; do
923 [ -d $i ] && continue
924 echo -e "$MSG $i"
925 MSG=""
926 done
927 done
928 echo "Check completed."
929 ;;
930 block)
931 # Add a pkg name to the list of blocked packages.
932 #
933 check_root
934 check_for_package_on_cmdline
935 echo ""
936 if grep -q "^$PACKAGE" $BLOCKED; then
937 echo "$PACKAGE is already in the blocked packages list."
938 echo ""
939 exit 0
940 else
941 echo -n "Add $PACKAGE to : $BLOCKED..."
942 echo $PACKAGE >> $BLOCKED
943 status
944 fi
945 echo ""
946 ;;
947 unblock)
948 # Remove a pkg name to the list of blocked packages.
949 #
950 check_root
951 check_for_package_on_cmdline
952 echo ""
953 if grep -q "^$PACKAGE" $BLOCKED; then
954 echo -n "Removing $PACKAGE from : $BLOCKED..."
955 sed -i s/$PACKAGE/''/ $BLOCKED
956 sed -i '/^$/d' $BLOCKED
957 status
958 else
959 echo "$PACKAGE is not in the blocked packages list."
960 echo ""
961 exit 0
962 fi
963 echo ""
964 ;;
965 get)
966 # Downlowd a package with wget.
967 #
968 check_for_package_on_cmdline
969 check_for_packages_list
970 check_for_package_in_list
971 echo ""
972 download $PACKAGE.tazpkg
973 echo ""
974 ;;
975 get-install)
976 # Download and install a package.
977 #
978 check_root
979 check_for_package_on_cmdline
980 check_for_packages_list
981 check_for_package_in_list
982 # Check if forced install.
983 if [ "$3" = "--forced" ]; then
984 rm -f $CACHE_DIR/$PACKAGE.tazpkg
985 else
986 check_for_installed_package
987 fi
988 cd $CACHE_DIR
989 if [ -f "$PACKAGE.tazpkg" ]; then
990 echo "$PACKAGE already in the cache : $CACHE_DIR"
991 else
992 echo ""
993 download $PACKAGE.tazpkg
994 fi
995 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
996 install_package
997 check_for_deps
998 if [ ! "$MISSING_PACKAGE" = "" ]; then
999 install_deps
1000 fi
1001 ;;
1002 clean-cache)
1003 # Remove all downloaded packages.
1005 check_root
1006 files=`ls -1 $CACHE_DIR | wc -l`
1007 echo ""
1008 echo -e "\033[1mCleaning cache directory :\033[0m $CACHE_DIR"
1009 echo "================================================================================"
1010 rm -rf $CACHE_DIR/*
1011 echo "$files file(s) removed from cache."
1012 echo ""
1013 ;;
1014 setup-mirror)
1015 # Change mirror URL.
1017 check_root
1018 # Backup old list.
1019 if [ -f "$LOCALSTATE/mirror" ]; then
1020 mv -f $LOCALSTATE/mirror $LOCALSTATE/mirror.bak
1021 fi
1022 echo ""
1023 echo -e "\033[1mCurrent mirror(s)\033[0m"
1024 echo "================================================================================"
1025 echo " `cat $MIRROR`"
1026 echo "
1027 Please enter URL of the new mirror (http or ftp). You must specify the complet
1028 address to the directory of the packages and packages.list file."
1029 echo ""
1030 echo -n "New mirror URL : "
1031 read NEW_MIRROR_URL
1032 if [ "$NEW_MIRROR_URL" = "" ]; then
1033 echo "Nothing as been change."
1034 else
1035 echo "Setting mirror(s) to : $NEW_MIRROR_URL"
1036 echo "$NEW_MIRROR_URL" > $LOCALSTATE/mirror
1037 fi
1038 echo ""
1039 ;;
1040 usage|*)
1041 # Print a short help or give usage for an unknow or empty command.
1043 usage
1044 ;;
1045 esac
1047 exit 0