tazpkg view tazpkg @ rev 9

Basename patch to install path/to/pkgs
author Christophe Lincoln <pankso@slitaz.org>
date Mon Nov 26 21:20:21 2007 +0100 (2007-11-26)
parents 279e8fb2bfb0
children fa636cb87e98
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 # Author : <pankso@slitaz.org>
12 #
13 VERSION=1.4pre
15 ####################
16 # Script variables #
17 ####################
19 # Packages categories.
20 CATEGORIES="base-system base-apps x-window extra"
22 # Initialize some variables to use words
23 # rater than numbers for functions and actions.
24 COMMAND=$1
25 PACKAGE=$(basename ${2%.tazpkg})
26 PACKAGE_FILE=$2
27 TARGET_DIR=$3
28 TOP_DIR=`pwd`
29 TMP_DIR=/tmp/tazpkg-$$-$RANDOM
31 # Path to tazpkg used dir and configuration files
32 LOCALSTATE=/var/lib/tazpkg
33 INSTALLED=$LOCALSTATE/installed
34 CACHE_DIR=/var/cache/tazpkg
35 MIRROR=$LOCALSTATE/mirror
36 PACKAGES_LIST=$LOCALSTATE/packages.list
39 # Check if the directories and files used by Tazpkg
40 # exists. If not and user is root we creat them.
41 if test $(id -u) = 0 ; then
42 if [ ! -d "$CACHE_DIR" ]; then
43 mkdir -p $CACHE_DIR
44 fi
45 if [ ! -d "$INSTALLED" ]; then
46 mkdir -p $INSTALLED
47 fi
48 if [ ! -f "$LOCALSTATE/mirror" ]; then
49 echo "$DEFAULT_MIRROR" > $LOCALSTATE/mirror
50 fi
51 fi
53 ####################
54 # Script functions #
55 ####################
57 # Print the usage.
58 usage ()
59 {
60 echo -e "SliTaz packages manager - Version: $VERSION\n
61 \033[1mUsage: \033[0m tazpkg [command] [package|dir|pattern|list|cat|--opt] [dir|--opt]
62 \033[1mCommands: \033[0m
63 usage Print this short usage.
64 list List installed packages on the system by category or all.
65 list-mirror List all available packages on the mirror (--diff for new).
66 info Print informations about the package.
67 desc Print description of a package (if it exist).
68 list-files List of files installed with the package.
69 search Search for a package by pattern or name.
70 install Install a local (*.tazpkg) package (--forced to force).
71 install-list Install all packages from a list of packages.
72 remove Remove the specified package and all installed files.
73 extract Extract a (*.tazpkg) package into a directory.
74 pack Pack an unpacked or prepared package tree.
75 recharge Recharge your packages.list from the mirror.
76 upgrade Upgrade all installed and listed packages on the mirror.
77 get Download a package into the current directory.
78 get-install Download and install a package from the mirror.
79 clean-cache Clean all packages downloaded in cache directory.
80 setup-mirror Change the mirror url configuration.\n"
81 }
83 # Status function with color (supported by Ash).
84 status()
85 {
86 local CHECK=$?
87 echo -en "\\033[70G[ "
88 if [ $CHECK = 0 ]; then
89 echo -en "\\033[1;33mOK"
90 else
91 echo -en "\\033[1;31mFailed"
92 fi
93 echo -e "\\033[0;39m ]"
94 }
96 # Check if user is root to install, or remove packages.
97 check_root()
98 {
99 if test $(id -u) != 0 ; then
100 echo -e "\nYou must be root to run `basename $0` with this option."
101 echo -e "Please type 'su' and root password to become super-user.\n"
102 exit 0
103 fi
104 }
106 # Check for a package name on cmdline.
107 check_for_package_on_cmdline()
108 {
109 if [ -z "$PACKAGE" ]; then
110 echo -e "\nPlease specify a package name on the command line.\n"
111 exit 0
112 fi
113 }
115 # Check if the package (*.tazpkg) exist before installing or extracting.
116 check_for_package_file()
117 {
118 if [ ! -f "$PACKAGE_FILE" ]; then
119 echo -e "
120 Unable to find : $PACKAGE_FILE\n"
121 exit 0
122 fi
123 }
125 # Check for the receipt of an installed package.
126 check_for_receipt()
127 {
128 if [ ! -f "$INSTALLED/$PACKAGE/receipt" ]; then
129 echo -e "\nUnable to find the receipt : $INSTALLED/$PACKAGE/receipt\n"
130 exit 0
131 fi
132 }
134 # Check if a package is already installed.
135 check_for_installed_package()
136 {
137 if [ -d "$INSTALLED/${PACKAGE%-[0-9]*}" ]; then
138 echo -e "
139 $PACKAGE is already installed. You can use the --forced option to force
140 installation or remove it and reinstall.\n"
141 exit 0
142 fi
143 }
145 # Check for packages.list to download and install packages.
146 check_for_packages_list()
147 {
148 if [ ! -f "$LOCALSTATE/packages.list" ]; then
149 echo -e "
150 Unable to find the list : $LOCALSTATE/packages.list\n
151 You must probably run 'tazpkg recharge' as root to get the last list of
152 packages avalaible on the mirror.\n"
153 exit 0
154 fi
155 }
157 # Check for a package in packages.list. Used by get and get-install to grep
158 # package basename.
159 check_for_package_in_list()
160 {
161 if grep -q "^$PACKAGE-[0-9]" $LOCALSTATE/packages.list; then
162 PACKAGE=`grep ^$PACKAGE-[0-9] $LOCALSTATE/packages.list`
163 else
164 echo -e "\nUnable to find : $PACKAGE in the mirrored packages list.\n"
165 exit 0
166 fi
167 }
169 # Extract a package with cpio and gzip.
170 extract_package()
171 {
172 echo -n "Extracting $PACKAGE..."
173 cpio -id < $PACKAGE.tazpkg && rm -f $PACKAGE.tazpkg
174 gzip -d fs.cpio.gz
175 echo -n "Extracting the pseudo fs... "
176 cpio -id < fs.cpio && rm fs.cpio
177 }
179 # This function install a package in the rootfs.
180 install_package()
181 {
182 mkdir -p $TMP_DIR
183 echo ""
184 echo -e "\033[1mInstallation of :\033[0m $PACKAGE"
185 echo "================================================================================"
186 echo -n "Copying $PACKAGE... "
187 cp $PACKAGE_FILE $TMP_DIR
188 status
189 cd $TMP_DIR
190 extract_package
191 # Include temporary receipt to get the right variables.
192 . $PWD/receipt
193 # Make the installed package data dir to store
194 # the receipt and the files list.
195 mkdir -p $INSTALLED/$PACKAGE
196 cp receipt $INSTALLED/$PACKAGE
197 # Include installed receipt.
198 . $INSTALLED/$PACKAGE/receipt
199 # Copy the list of files and the description if found.
200 cp files.list $INSTALLED/$PACKAGE
201 if [ -f "description.txt" ]; then
202 cp description.txt $INSTALLED/$PACKAGE
203 fi
204 if [ `cat $INSTALLED/$PACKAGE/receipt | grep pre_install` ]; then
205 # Execute post install commands.
206 pre_install
207 fi
208 echo -n "Installing $PACKAGE... "
209 cp -a fs/* /
210 status
211 # Remove the temporary random directory.
212 echo -n "Removing all tmp files... "
213 cd .. && rm -rf $TMP_DIR
214 status
215 if [ `cat $INSTALLED/$PACKAGE/receipt | grep post_install` ]; then
216 # Execute post install commands.
217 post_install
218 fi
219 cd $TOP_DIR
220 echo "================================================================================"
221 echo "$PACKAGE ($VERSION) is installed."
222 echo ""
223 }
225 # Check for missing deps listed in a receipt packages.
226 check_for_deps()
227 {
228 for i in $DEPENDS
229 do
230 if [ ! -d "$INSTALLED/$i" ]; then
231 MISSING_PACKAGE=$i
232 deps=$(($deps+1))
233 fi
234 done
235 if [ ! "$MISSING_PACKAGE" = "" ]; then
236 echo -e "\033[1mTracking dependencies for :\033[0m $PACKAGE"
237 echo "================================================================================"
238 for i in $DEPENDS
239 do
240 if [ ! -d "$INSTALLED/$i" ]; then
241 MISSING_PACKAGE=$i
242 echo "Missing : $MISSING_PACKAGE"
243 fi
244 done
245 echo "================================================================================"
246 echo "$deps missing package(s) to install."
247 fi
248 }
250 # Install all missing deps. First ask user then install all missing deps
251 # from local dir, cdrom, media or from the mirror. In case we want to
252 # install packages from local, we need a packages.list to find the version.
253 install_deps()
254 {
255 echo ""
256 echo -n "Install all missing dependencies(y/N) ? "; read anser
257 if [ "$anser" = "y" ]; then
258 for pkg in $DEPENDS
259 do
260 if [ ! -d "$INSTALLED/$pkg" ]; then
261 # We can install packages from a local dir by greping
262 # the TAZPKG_BASENAME in the local packages.list.
263 if [ -f "$TOP_DIR/packages.list" ]; then
264 echo "Checking if $pkg exist in local list... "
265 TAZPKG_BASENAME=`grep -e ^$pkg-[0-9] $TOP_DIR/packages.list`
266 if [ -f "$TAZPKG_BASENAME.tazpkg" ]; then
267 tazpkg install $TAZPKG_BASENAME.tazpkg
268 fi
269 # Install deps from the mirror.
270 else
271 if [ ! -f "$LOCALSTATE/packages.list" ]; then
272 tazpkg recharge
273 fi
274 tazpkg get-install $pkg
275 fi
276 fi
277 done
278 else
279 echo -e "\nLeaving dependencies for $PACKAGE unsolved."
280 echo -e "The package is installed but will probably not work.\n"
281 fi
282 }
284 # Sed package version temp file. we need 123 not 1.2.3 to use -gt. Few
285 # pacakges also use letters, so a is 1, b is 2, c is 3, etc.
286 #
287 sed_tmpfile()
288 {
289 sed -i s/"$PACKAGE-"/''/ $tmpfile
290 sed -i s/'\.'//g $tmpfile
291 sed -i s/'-'//g $tmpfile
292 sed -i s/'pre'// $tmpfile
293 sed -i s/'a'/'1'/ $tmpfile
294 sed -i s/'b'/'2'/ $tmpfile
295 sed -i s/'c'/'3'/ $tmpfile
296 sed -i s/'d'/'4'/ $tmpfile
297 sed -i s/'e'/'5'/ $tmpfile
298 }
300 ###################
301 # Tazpkg commands #
302 ###################
304 case "$COMMAND" in
305 list)
306 # List all installed packages or a specific category.
307 #
308 if [ "$2" = "category" ]; then
309 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
310 exit 0
311 fi
312 # Check for an asked category.
313 if [ -n "$2" ]; then
314 ASKED_CATEGORY=$2
315 echo ""
316 echo -e "\033[1mInstalled packages of category :\033[0m $ASKED_CATEGORY"
317 echo "================================================================================"
318 for pkg in $INSTALLED/*
319 do
320 . $pkg/receipt
321 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
322 echo -n "$PACKAGE"
323 echo -e "\033[24G $VERSION"
324 packages=$(($packages+1))
325 fi
326 done
327 echo "================================================================================"
328 echo -e "$packages packages installed of category $ASKED_CATEGORY."
329 echo ""
330 else
331 # By default list all packages and version.
332 echo ""
333 echo -e "\033[1mList of all installed packages\033[0m"
334 echo "================================================================================"
335 for pkg in $INSTALLED/*
336 do
337 . $pkg/receipt
338 echo -n "$PACKAGE"
339 echo -en "\033[24G $VERSION"
340 echo -e "\033[42G $CATEGORY"
341 packages=$(($packages+1))
342 done
343 echo "================================================================================"
344 echo "$packages packages installed."
345 echo ""
346 fi
347 ;;
348 list-mirror)
349 # List all available packages on the mirror. Option --diff display
350 # last mirrored packages diff (see recharge).
351 check_for_packages_list
352 if [ "$2" = "--diff" ]; then
353 if [ -f "$LOCALSTATE/packages.diff" ]; then
354 echo ""
355 echo -e "\033[1mMirrored packages diff\033[0m"
356 echo "================================================================================"
357 cat $LOCALSTATE/packages.diff
358 echo "================================================================================"
359 pkgs=`cat $LOCALSTATE/packages.diff | wc -l`
360 echo "$pkgs new packages listed on the mirror."
361 echo ""
362 else
363 echo -e "\nUnable to list anything, no packages.diff found."
364 echo -e "Recharge your current list to creat a first diff.\n"
365 fi
366 else
367 echo ""
368 echo -e "\033[1mList of available packages on the mirror\033[0m"
369 echo "================================================================================"
370 cat $LOCALSTATE/packages.list
371 echo "================================================================================"
372 pkgs=`cat $LOCALSTATE/packages.list | wc -l`
373 echo "$pkgs packages in the last recharged list."
374 echo ""
375 fi
376 ;;
377 list-files)
378 # List files installed with the package.
379 #
380 check_for_package_on_cmdline
381 check_for_receipt
382 echo ""
383 echo -e "\033[1mInstalled files with :\033[0m $PACKAGE"
384 echo "================================================================================"
385 cat $INSTALLED/$PACKAGE/files.list | sort
386 echo "================================================================================"
387 files=`cat $INSTALLED/$PACKAGE/files.list | wc -l`
388 echo "$files files installed with $PACKAGE."
389 echo ""
390 ;;
391 info)
392 # Informations about package.
393 #
394 check_for_package_on_cmdline
395 check_for_receipt
396 . $INSTALLED/$PACKAGE/receipt
397 echo ""
398 echo -e "\033[1mTazpkg informations\033[0m
399 ================================================================================
400 Package : $PACKAGE
401 Version : $VERSION
402 Category : $CATEGORY
403 Short desc : $SHORT_DESC
404 Maintainer : $MAINTAINER"
405 if [ ! "$DEPENDS" = "" ]; then
406 echo -e "Depends : $DEPENDS"
407 fi
408 if [ ! "$WANTED" = "" ]; then
409 echo -e "Wanted src : $WANTED"
410 fi
411 if [ ! "$WEB_SITE" = "" ]; then
412 echo -e "Web site : $WEB_SITE"
413 fi
414 echo "================================================================================"
415 echo ""
416 ;;
417 desc)
418 # Display package description.txt if available.
419 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
420 echo ""
421 echo -e "\033[1mDescription of :\033[0m $PACKAGE"
422 echo "================================================================================"
423 cat $INSTALLED/$PACKAGE/description.txt
424 echo "================================================================================"
425 echo ""
426 else
427 echo -e "\nSorry, no description available for this package.\n"
428 fi
429 ;;
430 search)
431 # Search for a package by pattern or name.
432 #
433 if [ -z "$2" ]; then
434 echo -e "\nPlease specify a pattern or a package name to search."
435 echo -e "Example : 'tazpkg search paint'. \n"
436 exit 0
437 fi
438 echo ""
439 echo -e "\033[1mSearch result for :\033[0m $2"
440 echo ""
441 echo "Installed packages"
442 echo "================================================================================"
443 list=`ls -1 $INSTALLED | grep $2`
444 for pkg in $list
445 do
446 . $INSTALLED/$pkg/receipt
447 echo -n "$PACKAGE "
448 echo -en "\033[24G $VERSION"
449 echo -e "\033[42G $CATEGORY"
450 packages=$(($packages+1))
451 done
452 if [ "$packages" = "" ]; then
453 echo "0 installed packages found for : $2"
454 echo ""
455 else
456 echo "================================================================================"
457 echo "$packages installed packages found for : $2"
458 echo ""
459 fi
460 echo "Available packages"
461 echo "================================================================================"
462 if [ -f "$LOCALSTATE/packages.list" ]; then
463 cat $LOCALSTATE/packages.list | grep $2
464 else
465 echo -e "
466 No 'packages.list' found to check for mirrored packages. For more results,
467 please run once 'tazpkg recharge' as root before searching.\n"
468 fi
469 echo "================================================================================"
470 packages=`cat $LOCALSTATE/packages.list | grep $2 | wc -l`
471 echo "$packages avalaible on the mirror."
472 echo ""
473 ;;
474 install)
475 # Install .tazpkg packages.
476 #
477 check_root
478 check_for_package_on_cmdline
479 check_for_package_file
480 # Check if forced install.
481 if [ "$3" = "--forced" ]; then
482 continue
483 else
484 check_for_installed_package
485 fi
486 install_package
487 # Resolv package deps.
488 check_for_deps
489 if [ ! "$MISSING_PACKAGE" = "" ]; then
490 install_deps
491 fi
492 ;;
493 install-list)
494 # Install a set of packages from a list.
495 #
496 check_root
497 if [ -z "$2" ]; then
498 echo -e "
499 Please change directory (cd) to the packages repository, and specify the
500 list of packages to install. Example : tazpkg install-list packages.list\n"
501 exit 0
502 fi
503 # Check if the packages list exist.
504 if [ ! -f "$2" ]; then
505 echo "Unable to find : $2"
506 exit 0
507 else
508 LIST=`cat $2`
509 fi
510 # Install all packages.
511 for pkg in $LIST
512 do
513 if [ "$3" = "--forced" ]; then
514 tazpkg install $pkg --forced
515 else
516 tazpkg install $pkg
517 fi
518 done
519 ;;
520 remove)
521 # Remove packages.
522 #
523 check_root
524 check_for_package_on_cmdline
525 if [ ! -d "$INSTALLED/$PACKAGE" ]; then
526 echo -e "\n$PACKAGE is not installed.\n"
527 exit 0
528 else
529 . $INSTALLED/$PACKAGE/receipt
530 fi
531 echo ""
532 echo "Remove $PACKAGE ($VERSION) ?"
533 echo -n "Please confirm uninstallation (y/N) : "; read anser
534 if [ "$anser" = "y" ]; then
535 echo ""
536 echo -e "\033[1mRemoving :\033[0m $PACKAGE"
537 echo "================================================================================"
538 echo -n "Removing all files installed..."
539 for file in `cat $INSTALLED/$PACKAGE/files.list`
540 do
541 rm -f $file
542 done
543 status
544 # Remove package receipt.
545 echo -n "Removing package receipt..."
546 rm -rf $INSTALLED/$PACKAGE
547 status
548 else
549 echo ""
550 echo "Uninstallation of $PACKAGE cancelled."
551 fi
552 echo ""
553 ;;
554 extract)
555 # Extract .tazpkg cpio archive into a directory.
556 #
557 check_for_package_on_cmdline
558 check_for_package_file
559 echo ""
560 echo -e "\033[1mExtracting :\033[0m $PACKAGE"
561 echo "================================================================================"
562 # If any directory destination is found on the cmdline
563 # we creat one in the current dir using the package name.
564 if [ -n "$TARGET_DIR" ]; then
565 DESTDIR=$TARGET_DIR/$PACKAGE
566 else
567 DESTDIR=$PACKAGE
568 fi
569 mkdir -p $DESTDIR
570 echo -n "Copying original package..."
571 cp $PACKAGE_FILE $DESTDIR
572 status
573 cd $DESTDIR
574 extract_package
575 echo "================================================================================"
576 echo "$PACKAGE is extracted to : $DESTDIR"
577 echo ""
578 ;;
579 pack)
580 # Creat SliTaz package archive using cpio and gzip.
581 #
582 check_for_package_on_cmdline
583 cd $PACKAGE
584 if [ ! -f "receipt" ]; then
585 echo "Receipt is missing. Please read the documentation."
586 exit 0
587 else
588 echo ""
589 echo -e "\033[1mPacking :\033[0m $PACKAGE"
590 echo "================================================================================"
591 # Creat files.list with redirecting find outpout.
592 echo -n "Creating the list of files..." && cd fs
593 find . -type f -print > ../files.list
594 find . -type l -print >> ../files.list
595 cd .. && sed -i s/'^.'/''/ files.list
596 status
597 # Build cpio archives.
598 echo -n "Compressing the fs... "
599 find fs -print | cpio -o -H newc > fs.cpio
600 gzip fs.cpio && rm -rf fs
601 echo -n "Creating full cpio archive... "
602 find . -print | cpio -o -H newc > ../$PACKAGE.tazpkg
603 echo -n "Restoring original package tree... "
604 gzip -d fs.cpio.gz && cpio -id < fs.cpio
605 rm fs.cpio && cd ..
606 echo "================================================================================"
607 echo "Package $PACKAGE compressed succefully."
608 echo "Size : `du -sh $PACKAGE.tazpkg`"
609 echo ""
610 fi
611 ;;
612 recharge)
613 # Recharge packages.list from a mirror.
614 #
615 check_root
616 cd $LOCALSTATE
617 echo ""
618 if [ -f "$LOCALSTATE/packages.list" ]; then
619 echo -n "Creating backup of the last packages list..."
620 mv -f packages.list packages.list.bak
621 status
622 fi
623 wget `cat $MIRROR`/packages.list
624 if [ -f "$LOCALSTATE/packages.list.bak" ]; then
625 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
626 sed -i s/+// packages.diff
627 echo ""
628 echo -e "\033[1mMirrored packages diff\033[0m"
629 echo "================================================================================"
630 cat packages.diff
631 if [ ! "`cat packages.diff | wc -l`" = 0 ]; then
632 echo "================================================================================"
633 echo "`cat packages.diff | wc -l` new packages on the mirror."
634 echo ""
635 else
636 echo "`cat packages.diff | wc -l` new packages on the mirror."
637 echo ""
638 fi
639 else
640 echo -e "
641 ================================================================================
642 Last packages.list is ready to use. Note that next time you recharge the list,
643 a list of differencies will be displayed to show new and upgradable packages.\n"
644 fi
645 ;;
646 upgrade)
647 # Upgrade all installed packages with the new version from the mirror.
648 #
649 check_root
650 check_for_packages_list
651 cd $LOCALSTATE
652 rm -f upradable-packages.list
653 echo ""
654 echo -e "\033[1mAvalaible upgrade\033[0m"
655 echo "================================================================================"
656 for pkg in $INSTALLED/*
657 do
658 . $pkg/receipt
659 # We need a temp file to sed the package version.
660 tmpfile=/tmp/pkg.version
661 # Check if the installed package is in the current list (other
662 # mirror or local).
663 if grep -q "^$PACKAGE-[0-9]" packages.list; then
664 newpkg=`grep ^$PACKAGE-[0-9] packages.list`
665 # Get last and current version without points using
666 # function sed_tmpfile().
667 echo $newpkg > $tmpfile
668 sed_tmpfile
669 NEW_VERSION=`cat $tmpfile`
670 echo $VERSION > $tmpfile
671 sed_tmpfile
672 CURRENT_VERSION=`cat $tmpfile`
673 # Compare version.
674 if [ "$NEW_VERSION" -gt "$CURRENT_VERSION" ]; then
675 echo $newpkg > $tmpfile
676 sed -i s/"$PACKAGE-"/''/ $tmpfile
677 newversion=`cat $tmpfile`
678 rm -f $tmpfile
679 echo -n "$PACKAGE"
680 echo -en "\033[24G $VERSION"
681 echo -en "\033[38G --->"
682 echo -en "\033[48G $newversion"
683 echo -e "\033[68G $CATEGORY"
684 up=$(($up+1))
685 echo "$PACKAGE" >> upradable-packages.list
686 fi
687 packages=$(($packages+1))
688 fi
689 done
690 rm -f $tmpfile
691 if [ ! "$up" = "" ]; then
692 echo "================================================================================"
693 echo "$packages installed and listed packages to consider, $up to upgrade."
694 echo ""
695 else
696 echo "$packages installed and listed packages to consider, 0 to upgrade."
697 echo ""
698 exit 0
699 fi
700 # Ask for upgrade, it can be done an other time.
701 echo -n "Upgrade now (y/N) ? "; read anser
702 if [ ! "$anser" = "y" ]; then
703 echo -e "\nExiting. No package upgraded.\n"
704 exit 0
705 fi
706 # If anser is yes (y). Install all new version.
707 for pkg in `cat upradable-packages.list`
708 do
709 tazpkg get-install $pkg --forced
710 done
711 ;;
712 get)
713 # Downlowd a package with wget.
714 #
715 check_for_package_on_cmdline
716 check_for_packages_list
717 check_for_package_in_list
718 echo ""
719 wget `cat $MIRROR`/$PACKAGE.tazpkg
720 echo ""
721 ;;
722 get-install)
723 # Download and install a package.
724 #
725 check_root
726 check_for_package_on_cmdline
727 check_for_packages_list
728 check_for_package_in_list
729 # Check if forced install.
730 if [ "$3" = "--forced" ]; then
731 rm -f $CACHE_DIR/$PACKAGE.tazpkg
732 else
733 check_for_installed_package
734 fi
735 cd $CACHE_DIR
736 if [ -f "$PACKAGE.tazpkg" ]; then
737 echo "$PACKAGE already in the cache : $CACHE_DIR"
738 else
739 echo ""
740 wget `cat $MIRROR`/$PACKAGE.tazpkg
741 fi
742 install_package
743 check_for_deps
744 if [ ! "$MISSING_PACKAGE" = "" ]; then
745 install_deps
746 fi
747 ;;
748 clean-cache)
749 # Remove all downloaded packages.
750 #
751 check_root
752 files=`ls -1 $CACHE_DIR | wc -l`
753 echo ""
754 echo -e "\033[1mCleaning cache directory :\033[0m $CACHE_DIR"
755 echo "================================================================================"
756 rm -rf $CACHE_DIR/*
757 echo "$files file(s) removed from cache."
758 echo ""
759 ;;
760 setup-mirror)
761 # Change mirror URL.
762 #
763 check_root
764 # Backup old list.
765 if [ -f "$LOCALSTATE/mirror" ]; then
766 mv -f $LOCALSTATE/mirror $LOCALSTATE/mirror.bak
767 fi
768 echo ""
769 echo -e "\033[1mCurrent mirror\033[0m"
770 echo "================================================================================"
771 echo " `cat $MIRROR`"
772 echo "
773 Please enter URL of the new mirror (http or ftp). You must specify the complet
774 address to the directory of the packages and packages.list file."
775 echo ""
776 echo -n "New mirror URL : "
777 read NEW_MIRROR_URL
778 if [ "$NEW_MIRROR_URL" = "" ]; then
779 echo "Nothing as been change."
780 else
781 echo "Setting mirror to : $NEW_MIRROR_URL"
782 echo "$NEW_MIRROR_URL" > $LOCALSTATE/mirror
783 fi
784 echo ""
785 ;;
786 usage|*)
787 # Print a short help or give usage for an unknow or empty command.
788 #
789 usage
790 ;;
791 esac
793 exit 0