tazpkg view tazpkg @ rev 119

tazpkg: typos fixed by Mike D. Smith
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Jul 13 21:27:54 2008 +0000 (2008-07-13)
parents 5c2f855b190a
children 60b6743c7eca
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 resolves 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 # Eric Joseph-Alexandre <erjo@slitaz.org>
15 #
16 VERSION=2.2
18 ####################
19 # Script variables #
20 ####################
22 # Packages categories.
23 CATEGORIES="
24 base-system
25 utilities
26 network
27 graphics
28 multimedia
29 office
30 development
31 system-tools
32 security
33 games
34 misc
35 meta
36 non-free"
38 # Initialize some variables to use words
39 # rather than numbers for functions and actions.
40 COMMAND=$1
41 if [ -f "$2" ]; then
42 # Set pkg basename for install, extract
43 PACKAGE=$(basename ${2%.tazpkg} 2>/dev/null)
44 else
45 # Pkg name for remove, search and all other cmds
46 PACKAGE=${2%.tazpkg}
47 fi
48 PACKAGE_FILE=$2
49 TARGET_DIR=$3
50 TOP_DIR=`pwd`
51 TMP_DIR=/tmp/tazpkg-$$-$RANDOM
53 # Path to tazpkg used dir and configuration files
54 LOCALSTATE=/var/lib/tazpkg
55 INSTALLED=$LOCALSTATE/installed
56 CACHE_DIR=/var/cache/tazpkg
57 MIRROR=$LOCALSTATE/mirror
58 PACKAGES_LIST=$LOCALSTATE/packages.list
59 BLOCKED=$LOCALSTATE/blocked-packages.list
60 DEFAULT_MIRROR="http://mirror.slitaz.org/packages/`cat /etc/slitaz-release`/"
62 # Bold red warning for upgrade.
63 WARNING="\\033[1;31mWARNING\\033[0;39m"
65 # Check if the directories and files used by Tazpkg
66 # exists. If not and user is root we create them.
67 if test $(id -u) = 0 ; then
68 if [ ! -d "$CACHE_DIR" ]; then
69 mkdir -p $CACHE_DIR
70 fi
71 if [ ! -d "$INSTALLED" ]; then
72 mkdir -p $INSTALLED
73 fi
74 if [ ! -f "$LOCALSTATE/mirror" ]; then
75 echo "$DEFAULT_MIRROR" > $LOCALSTATE/mirror
76 fi
77 fi
79 ####################
80 # Script functions #
81 ####################
83 # Print the usage.
84 usage ()
85 {
86 echo -e "SliTaz packages manager - Version: $VERSION\n
87 \033[1mUsage:\033[0m tazpkg [command] [package|dir|pattern|list|cat|--opt] [dir|--opt]
88 tazpkg shell\n
89 \033[1mCommands: \033[0m
90 usage Print this short usage.
91 list List installed packages on the system by category or all.
92 xhtml-list Creates a xHTML list of installed packges.
93 list-mirror List all available packages on the mirror (--diff for new).
94 info Print informations about the package.
95 desc Print description of a package (if it exist).
96 list-files List of files installed with the package.
97 search Search for a package by pattern or name (options: -i|-l|-m).
98 search-file Search for file(s) in all installed packages files.
99 install Install a local (*.tazpkg) package (--forced to force).
100 install-list Install all packages from a list of packages.
101 remove Remove the specified package and all installed files.
102 extract Extract a (*.tazpkg) package into a directory.
103 pack Pack an unpacked or prepared package tree.
104 recharge Recharge your packages.list from the mirror.
105 repack Creates a package archive from an installed package.
106 upgrade Upgrade all installed and listed packages on the mirror.
107 block|unblock Block an installed package version or unblock it for upgrade.
108 get Download a package into the current directory.
109 get-install Download and install a package from the mirror.
110 get-install-list Download and install a list of packages from the mirror.
111 check Verify installed packages concistancy.
112 add-flavor Install the flavor list of packages.
113 install-flavor Install the flavor list of packages and remove other ones.
114 set-release Change release and update packages
115 clean-cache Clean all packages downloaded in cache directory.
116 setup-mirror Change the mirror url configuration.
117 reconfigure Replay post install script from package."
118 }
120 # Status function with color (supported by Ash).
121 status()
122 {
123 local CHECK=$?
124 echo -en "\\033[70G[ "
125 if [ $CHECK = 0 ]; then
126 echo -en "\\033[1;33mOK"
127 else
128 echo -en "\\033[1;31mFailed"
129 fi
130 echo -e "\\033[0;39m ]"
131 return $CHECK
132 }
134 # Check if user is root to install, or remove packages.
135 check_root()
136 {
137 if test $(id -u) != 0 ; then
138 echo -e "\nYou must be root to run `basename $0` with this option."
139 echo -e "Please use 'su' and root password to become super-user.\n"
140 exit 0
141 fi
142 }
144 # Check for a package name on cmdline.
145 check_for_package_on_cmdline()
146 {
147 if [ -z "$PACKAGE" ]; then
148 echo -e "\nPlease specify a package name on the command line.\n"
149 exit 0
150 fi
151 }
153 # Check if the package (*.tazpkg) exist before installing or extracting.
154 check_for_package_file()
155 {
156 if [ ! -f "$PACKAGE_FILE" ]; then
157 echo -e "
158 Unable to find : $PACKAGE_FILE\n"
159 exit 0
160 fi
161 }
163 # Check for the receipt of an installed package.
164 check_for_receipt()
165 {
166 if [ ! -f "$INSTALLED/$PACKAGE/receipt" ]; then
167 echo -e "\nUnable to find the receipt : $INSTALLED/$PACKAGE/receipt\n"
168 exit 0
169 fi
170 }
172 # Get package name in a directory
173 package_fullname_in_dir()
174 {
175 EXTRAVERSION=""
176 . $1/receipt
177 echo $PACKAGE-$VERSION$EXTRAVERSION
178 }
180 # Get package name that is already installed.
181 get_installed_package_pathname()
182 {
183 for i in $INSTALLED/${1%%-*}*; do
184 [ -d $i ] || continue
185 if [ "$1" = "$(package_fullname_in_dir $i)" ]; then
186 echo $i
187 return
188 fi
189 done
190 }
192 # Check if a package is already installed.
193 check_for_installed_package()
194 {
195 if [ -n "$(get_installed_package_pathname $PACKAGE)" ]; then
196 echo -e "
197 $PACKAGE is already installed. You can use the --forced option to force
198 installation or remove it and reinstall.\n"
199 exit 0
200 fi
201 }
203 # Check for packages.list to download and install packages.
204 check_for_packages_list()
205 {
206 if [ ! -f "$LOCALSTATE/packages.list" ]; then
207 if test $(id -u) = 0 ; then
208 tazpkg recharge
209 else
210 echo -e "
211 Unable to find the list : $LOCALSTATE/packages.list\n
212 You must probably run 'tazpkg recharge' as root to get the last list of
213 packages avalaible on the mirror.\n"
214 exit 0
215 fi
216 fi
217 }
219 # Check for a package in packages.list. Used by get and get-install to grep
220 # package basename.
221 check_for_package_in_list()
222 {
223 local pkg
224 pkg=$(grep "^$PACKAGE-[0-9]" $LOCALSTATE/packages.list | head -1)
225 [ -n "$pkg" ] || pkg=$(grep "^$PACKAGE-.[\.0-9]" $LOCALSTATE/packages.list | head -1)
226 if [ -n "$pkg" ]; then
227 PACKAGE=$pkg
228 else
229 echo -e "\nUnable to find : $PACKAGE in the mirrored packages list.\n"
230 exit 0
231 fi
232 }
234 # Download a file trying all mirrors
235 download()
236 {
237 for i in $(cat $MIRROR); do
238 wget -c $i$@ && break
239 done
240 }
242 # Extract a package with cpio and gzip.
243 extract_package()
244 {
245 echo -n "Extracting $PACKAGE... "
246 cpio -id < $PACKAGE.tazpkg && rm -f $PACKAGE.tazpkg
247 gzip -d fs.cpio.gz
248 echo -n "Extracting the pseudo fs... "
249 cpio -id < fs.cpio && rm fs.cpio
250 }
252 # This function install a package in the rootfs.
253 install_package()
254 {
255 ROOT=$1
256 if [ -n "$ROOT" ]; then
257 # get absolute path
258 ROOT=$(cd $ROOT; pwd)
259 fi
260 mkdir -p $TMP_DIR
261 echo ""
262 echo -e "\033[1mInstallation of :\033[0m $PACKAGE"
263 echo "================================================================================"
264 echo -n "Copying $PACKAGE... "
265 cp $PACKAGE_FILE $TMP_DIR
266 status
267 cd $TMP_DIR
268 extract_package
269 SELF_INSTALL=0
270 EXTRAVERSION=""
271 # Include temporary receipt to get the right variables.
272 . $PWD/receipt
273 if [ $SELF_INSTALL -ne 0 -a -n "$ROOT" ]; then
274 echo -n "Checking post install dependencies... "
275 [ -n "$(get_installed_package_pathname $PACKAGE)" ]
276 if ! status; then
277 echo "Please run 'tazpkg install $PACKAGE_FILE' in / and retry."
278 cd .. && rm -rf $TMP_DIR
279 exit 1
280 fi
281 fi
282 # Remember modified packages
283 for i in $(grep -v '\[' files.list); do
284 [ -e "$ROOT$i" ] || continue
285 [ -d "$ROOT$i" ] && continue
286 for j in $(grep -l "^$i$" $ROOT$INSTALLED/*/files.list); do
287 [ "$j" = "$ROOT$INSTALLED/$PACKAGE/files.list" ] && continue
288 grep -qs ^$PACKAGE$ $(dirname $j)/modifiers && continue
289 echo "$PACKAGE" >> $(dirname $j)/modifiers
290 done
291 done
292 # Make the installed package data dir to store
293 # the receipt and the files list.
294 mkdir -p $ROOT$INSTALLED/$PACKAGE
295 cp receipt files.list $ROOT$INSTALLED/$PACKAGE
296 # Copy the description if found.
297 if [ -f "description.txt" ]; then
298 cp description.txt $ROOT$INSTALLED/$PACKAGE
299 fi
300 # Pre install commands.
301 if grep -q ^pre_install $ROOT$INSTALLED/$PACKAGE/receipt; then
302 pre_install $ROOT
303 fi
304 echo -n "Installing $PACKAGE... "
305 cp -a fs/* $ROOT/
306 status
307 # Remove the temporary random directory.
308 echo -n "Removing all tmp files... "
309 cd .. && rm -rf $TMP_DIR
310 status
311 # Post install commands.
312 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
313 post_install $ROOT
314 fi
315 cd $TOP_DIR
316 echo "================================================================================"
317 echo "$PACKAGE ($VERSION$EXTRAVERSION) is installed."
318 echo ""
319 }
321 # Check for missing deps listed in a receipt packages.
322 check_for_deps()
323 {
324 local saved;
325 saved=$PACKAGE
326 mkdir -p $TMP_DIR
327 ( cd $TMP_DIR ; cpio -i receipt ) < $PACKAGE_FILE
328 . $TMP_DIR/receipt
329 PACKAGE=$saved
330 rm -rf $TMP_DIR
331 for i in $DEPENDS
332 do
333 if [ ! -d "$INSTALLED/$i" ]; then
334 MISSING_PACKAGE=$i
335 deps=$(($deps+1))
336 fi
337 done
338 if [ ! "$MISSING_PACKAGE" = "" ]; then
339 echo -e "\033[1mTracking dependencies for :\033[0m $PACKAGE"
340 echo "================================================================================"
341 for i in $DEPENDS
342 do
343 if [ ! -d "$INSTALLED/$i" ]; then
344 MISSING_PACKAGE=$i
345 echo "Missing : $MISSING_PACKAGE"
346 fi
347 done
348 echo "================================================================================"
349 echo "$deps missing package(s) to install."
350 fi
351 }
353 # Install all missing deps. First ask user then install all missing deps
354 # from local dir, cdrom, media or from the mirror. In case we want to
355 # install packages from local, we need a packages.list to find the version.
356 install_deps()
357 {
358 echo ""
359 echo -n "Install all missing dependencies (y/N) ? "; read anser
360 if [ "$anser" = "y" ]; then
361 for pkg in $DEPENDS
362 do
363 if [ ! -d "$INSTALLED/$pkg" ]; then
364 # We can install packages from a local dir by greping
365 # the TAZPKG_BASENAME in the local packages.list.
366 if [ -f "$TOP_DIR/packages.list" ]; then
367 echo "Checking if $pkg exist in local list... "
368 mkdir $TMP_DIR
369 for i in $pkg-*.tazpkg; do
370 ( cd $TMP_DIR ; cpio -i receipt ) < $i
371 if grep -q ^$(package_fullname_in_dir $TMP_DIR)$ $TOP_DIR/packages.list
372 then
373 tazpkg install $i
374 break
375 fi
376 done
377 rm -rf $TMP_DIR
378 # Install deps from the mirror.
379 else
380 if [ ! -f "$LOCALSTATE/packages.list" ]; then
381 tazpkg recharge
382 fi
383 tazpkg get-install $pkg
384 fi
385 fi
386 done
387 else
388 echo -e "\nLeaving dependencies for $PACKAGE unsolved."
389 echo -e "The package is installed but will probably not work.\n"
390 fi
391 }
393 # xHTML packages list header.
394 xhtml_header()
395 {
396 cat > $XHTML_LIST << _EOT_
397 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
398 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
399 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
400 <head>
401 <title>Installed packages list</title>
402 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
403 <meta name="modified" content="$DATE" />
404 <meta name="generator" content="Tazpkg" />
405 <style type="text/css"><!--
406 body { font: 12px sans-serif, vernada, arial; margin: 0; }
407 #header { background: #f0ba08; color: black; height: 50px;
408 border-top: 1px solid black; border-bottom: 1px solid black; }
409 #content { margin: 0px 50px 26px 50px; }
410 #footer { border-top: 1px solid black; padding-top: 10px;}
411 h1 { margin: 14px 0px 0px 16px; }
412 pre { padding-left: 5px; }
413 hr { color: white; background: white; height: 1px; border: 0; }
414 --></style>
415 </head>
416 <body bgcolor="#ffffff">
417 <div id="header">
418 <h1><font color="#3e1220">Installed packages list</font></h1>
419 </div>
420 <hr />
421 <!-- Start content -->
422 <div id="content">
424 <p>
425 _packages_ packages installed - List generated on : $DATE
426 <p>
428 _EOT_
429 }
431 # xHTML content with packages infos.
432 xhtml_pkg_info()
433 {
434 cat >> $XHTML_LIST << _EOT_
435 <h3>$PACKAGE</h3>
436 <pre>
437 Version : $VERSION$EXTRAVERSION
438 Short desc : $SHORT_DESC
439 Web site : <a href="$WEB_SITE">$WEB_SITE</a>
440 </pre>
442 _EOT_
443 }
445 # xHTML packages list footer.
446 xhtml_footer()
447 {
448 cat >> $XHTML_LIST << _EOT_
449 <hr />
450 <p id="footer">
451 $packages packages installed - List generated on : $DATE
452 </p>
454 <!-- End content -->
455 </div>
456 </body>
457 </html>
458 _EOT_
459 }
461 # Search pattern in installed packages.
462 search_in_installed_packages()
463 {
464 echo "Installed packages"
465 echo "================================================================================"
466 list=`ls -1 $INSTALLED | grep -i "$PATTERN"`
467 for pkg in $list
468 do
469 EXTRAVERSION=""
470 . $INSTALLED/$pkg/receipt
471 echo -n "$PACKAGE "
472 echo -en "\033[24G $VERSION$EXTRAVERSION"
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 : $PATTERN"
479 echo ""
480 else
481 echo "================================================================================"
482 echo "$packages installed package(s) found for : $PATTERN"
483 echo ""
484 fi
485 }
487 # Search in packages.list for avalaible pkgs.
488 search_in_packages_list()
489 {
490 echo "Available packages name-version"
491 echo "================================================================================"
492 if [ -f "$LOCALSTATE/packages.list" ]; then
493 cat $LOCALSTATE/packages.list | grep -i "$PATTERN"
494 packages=`cat $LOCALSTATE/packages.list | grep "$PATTERN" | wc -l`
495 else
496 echo -e "
497 No 'packages.list' found to check for mirrored packages. For more results,
498 please run once 'tazpkg recharge' as root before searching.\n"
499 fi
500 if [ "$packages" = "0" ]; then
501 echo "0 available packages found for : $PATTERN"
502 echo ""
503 else
504 echo "================================================================================"
505 echo "$packages available package(s) found for : $PATTERN"
506 echo ""
507 fi
508 }
510 # search --mirror: Search in packages.txt for avalaible pkgs and give more
511 # infos than --list or default.
512 search_in_packages_txt()
513 {
514 echo "Matching packages name with version and desc"
515 echo "================================================================================"
516 if [ -f "$LOCALSTATE/packages.txt" ]; then
517 cat $LOCALSTATE/packages.txt | grep -A 2 "^$PATTERN"
518 packages=`cat $LOCALSTATE/packages.txt | grep -i "^$PATTERN" | wc -l`
519 else
520 echo -e "
521 No 'packages.txt' found to check for mirrored packages. For more results,
522 please run once 'tazpkg recharge' as root before searching.\n"
523 fi
524 if [ "$packages" = "0" ]; then
525 echo "0 available packages found for : $PATTERN"
526 echo ""
527 else
528 echo "================================================================================"
529 echo "$packages available package(s) found for : $PATTERN"
530 echo ""
531 fi
532 }
534 # Install package-list from a flavor
535 install_flavor()
536 {
537 check_root
538 FLAVOR=$1
539 ARG=$2
540 mkdir -p $TMP_DIR
541 [ -f $FLAVOR.flavor ] && cp $FLAVOR.flavor $TMP_DIR
542 cd $TMP_DIR
543 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
544 zcat $FLAVOR.flavor | cpio -i 2>/dev/null
545 while read file; do
546 for pkg in $(ls -d $INSTALLED/${file%%-*}*); do
547 [ -d $pkg ] || continue
548 EXTRAVERSION=""
549 . $pkg/receipt
550 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && break
551 done
552 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && continue
553 cd $CACHE_DIR
554 download $file.tazpkg
555 cd $TMP_DIR
556 tazpkg install $CACHE_DIR/$file.tazpkg --forced
557 done < $FLAVOR.pkglist
558 [ -f $FLAVOR.nonfree ] && while read pkg; do
559 [ -d $INSTALLED/$pkg ] || continue
560 [ -d $INSTALLED/get-$pkg ] && tazpkg get-install get-$pkg
561 get-$pkg
562 done < $FLAVOR.nonfree
563 [ "$ARG" == "--purge" ] && for pkg in $(ls $INSTALLED); do
564 [ -d $INSTALLED/$pkg ] || continue
565 EXTRAVERSION=""
566 . $INSTALLED/$pkg/receipt
567 grep -q ^$PACKAGE-$VERSION$EXTRAVERSION$ $FLAVOR.pkglist && continue
568 grep -qs ^$PACKAGE$ $FLAVOR.nonfree && continue
569 tazpkg remove $PACKAGE
570 done
571 else
572 echo "Can't find flavor $FLAVOR Abort."
573 fi
574 cd $TOP_DIR
575 rm -rf $TMP_DIR
576 }
578 ###################
579 # Tazpkg commands #
580 ###################
582 case "$COMMAND" in
583 list)
584 # List all installed packages or a specific category.
585 #
586 if [ "$2" = "blocked" ]; then
587 if [ -f $BLOCKED ]; then
588 LIST=`cat $BLOCKED`
589 fi
590 echo ""
591 echo -e "\033[1mBlocked packages\033[0m"
592 echo "================================================================================"
593 if [ -n $LIST ];then
594 echo $LIST
595 echo ""
596 else
597 echo -e "No blocked packages found.\n"
598 fi
599 exit 0
600 fi
601 # Display the list of categories.
602 if [ "$2" = "cat" -o "$2" = "categories" ]; then
603 echo ""
604 echo -e "\033[1mPackages categories :\033[0m"
605 echo "================================================================================"
606 for i in $CATEGORIES
607 do
608 echo $i
609 categories=$(($categories+1))
610 done
611 echo "================================================================================"
612 echo "$categories categories"
613 echo ""
614 exit 0
615 fi
616 # Check for an asked category.
617 if [ -n "$2" ]; then
618 ASKED_CATEGORY=$2
619 echo ""
620 echo -e "\033[1mInstalled packages of category :\033[0m $ASKED_CATEGORY"
621 echo "================================================================================"
622 for pkg in $INSTALLED/*
623 do
624 EXTRAVERSION=""
625 . $pkg/receipt
626 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
627 echo -n "$PACKAGE"
628 echo -e "\033[24G $VERSION$EXTRAVERSION"
629 packages=$(($packages+1))
630 fi
631 done
632 echo "================================================================================"
633 echo -e "$packages packages installed of category $ASKED_CATEGORY."
634 echo ""
635 else
636 # By default list all packages and version.
637 echo ""
638 echo -e "\033[1mList of all installed packages\033[0m"
639 echo "================================================================================"
640 for pkg in $INSTALLED/*
641 do
642 EXTRAVERSION=""
643 . $pkg/receipt
644 echo -n "$PACKAGE"
645 echo -en "\033[24G $VERSION$EXTRAVERSION"
646 echo -e "\033[42G $CATEGORY"
647 packages=$(($packages+1))
648 done
649 echo "================================================================================"
650 echo "$packages packages installed."
651 echo ""
652 fi
653 ;;
654 xhtml-list)
655 # Get infos in receipts and build list.
656 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
657 if [ -n "$2" ]; then
658 XHTML_LIST=$2
659 else
660 XHTML_LIST=installed-packages.html
661 fi
662 echo ""
663 echo -e "\033[1mCreating xHTML list of installed packages\033[0m"
664 echo "================================================================================"
665 echo -n "Generating xHTML header..."
666 xhtml_header
667 status
668 # Packages
669 echo -n "Creating packages informations..."
670 for pkg in $INSTALLED/*
671 do
672 EXTRAVERSION=""
673 . $pkg/receipt
674 xhtml_pkg_info
675 packages=$(($packages+1))
676 done
677 status
678 echo -n "Generating xHTML footer..."
679 xhtml_footer
680 status
681 # sed pkgs nb in header.
682 sed -i s/'_packages_'/"$packages"/ $XHTML_LIST
683 echo "================================================================================"
684 echo "$XHTML_LIST created - $packages packages."
685 echo ""
686 ;;
687 list-mirror)
688 # List all available packages on the mirror. Option --diff display
689 # last mirrored packages diff (see recharge).
690 check_for_packages_list
691 case $2 in
692 --diff)
693 if [ -f "$LOCALSTATE/packages.diff" ]; then
694 echo ""
695 echo -e "\033[1mMirrored packages diff\033[0m"
696 echo "================================================================================"
697 cat $LOCALSTATE/packages.diff
698 echo "================================================================================"
699 pkgs=`cat $LOCALSTATE/packages.diff | wc -l`
700 echo "$pkgs new packages listed on the mirror."
701 echo ""
702 else
703 echo -e "\nUnable to list anything, no packages.diff found."
704 echo -e "Recharge your current list to creat a first diff.\n"
705 fi && exit 0 ;;
706 --text|--txt)
707 echo ""
708 echo -e "\033[1mList of available packages on the mirror\033[0m"
709 echo "================================================================================"
710 cat $LOCALSTATE/packages.txt ;;
711 --raw|*)
712 echo ""
713 echo -e "\033[1mList of available packages on the mirror\033[0m"
714 echo "================================================================================"
715 cat $LOCALSTATE/packages.list ;;
716 esac
717 echo "================================================================================"
718 pkgs=`cat $LOCALSTATE/packages.list | wc -l`
719 echo "$pkgs packages in the last recharged list."
720 echo ""
721 ;;
722 list-files)
723 # List files installed with the package.
724 #
725 check_for_package_on_cmdline
726 check_for_receipt
727 echo ""
728 echo -e "\033[1mInstalled files with :\033[0m $PACKAGE"
729 echo "================================================================================"
730 cat $INSTALLED/$PACKAGE/files.list | sort
731 echo "================================================================================"
732 files=`cat $INSTALLED/$PACKAGE/files.list | wc -l`
733 echo "$files files installed with $PACKAGE."
734 echo ""
735 ;;
736 info)
737 # Information about package.
738 #
739 check_for_package_on_cmdline
740 check_for_receipt
741 EXTRAVERSION=""
742 . $INSTALLED/$PACKAGE/receipt
743 echo ""
744 echo -e "\033[1mTazpkg informations\033[0m
745 ================================================================================
746 Package : $PACKAGE
747 Version : $VERSION$EXTRAVERSION
748 Category : $CATEGORY
749 Short desc : $SHORT_DESC
750 Maintainer : $MAINTAINER"
751 if [ ! "$DEPENDS" = "" ]; then
752 echo -e "Depends : $DEPENDS"
753 fi
754 if [ ! "$SUGGESTED" = "" ]; then
755 echo -e "Suggested : $SUGGESTED"
756 fi
757 if [ ! "$BUILD_DEPENDS" = "" ]; then
758 echo -e "Build deps : $BUILD_DEPENDS"
759 fi
760 if [ ! "$WANTED" = "" ]; then
761 echo -e "Wanted src : $WANTED"
762 fi
763 if [ ! "$WEB_SITE" = "" ]; then
764 echo -e "Web site : $WEB_SITE"
765 fi
766 echo "================================================================================"
767 echo ""
768 ;;
769 desc)
770 # Display package description.txt if available.
771 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
772 echo ""
773 echo -e "\033[1mDescription of :\033[0m $PACKAGE"
774 echo "================================================================================"
775 cat $INSTALLED/$PACKAGE/description.txt
776 echo "================================================================================"
777 echo ""
778 else
779 echo -e "\nSorry, no description available for this package.\n"
780 fi
781 ;;
782 search)
783 # Search for a package by pattern or name.
784 #
785 PATTERN="$2"
786 if [ -z "$PATTERN" ]; then
787 echo -e "\nPlease specify a pattern or a package name to search."
788 echo -e "Example : 'tazpkg search paint'.\n"
789 exit 0
790 fi
791 echo ""
792 echo -e "\033[1mSearch result for :\033[0m $PATTERN"
793 echo ""
794 # Default is to search in installed pkgs and the raw list.
795 case $3 in
796 -i|--installed)
797 search_in_installed_packages ;;
798 -l|--list)
799 search_in_packages_list ;;
800 -m|--mirror)
801 search_in_packages_txt ;;
802 *)
803 search_in_installed_packages
804 search_in_packages_list ;;
805 esac
806 ;;
807 search-file)
808 # Search for a file by pattern or name in all files.list.
809 #
810 if [ -z "$2" ]; then
811 echo -e "\nPlease specify a pattern or a file name to search."
812 echo -e "Example : 'tazpkg search-file libnss'. \n"
813 exit 0
814 fi
815 echo ""
816 echo -e "\033[1mSearch result for file :\033[0m $2"
817 echo "================================================================================"
819 if [ "$3" == "--mirror" ]; then
821 unlzma -c $LOCALSTATE/files.list.lzma | grep -- ".*:.*$2" | awk '
822 BEGIN { last="" }
823 {
824 pkg=substr($0,0,index($0,":")-1);
825 file=substr($0,index($0,":")+2);
826 if (last != pkg) {
827 last = pkg;
828 printf("\n%c[1mPackage %s :%c[0m\n",27,pkg,27);
829 }
830 printf("%s\n",file);
831 }'
832 match=`unlzma -c $LOCALSTATE/files.list.lzma | \
833 grep -- ".*:.*$2" | wc -l`
835 else
837 # Check all pkg files.list in search match with specify the package
838 # name and the full path to the file(s).
839 for pkg in $INSTALLED/*
840 do
841 if grep -q "$2" $pkg/files.list; then
842 . $pkg/receipt
843 echo ""
844 echo -e "\033[1mPackage $PACKAGE :\033[0m"
845 grep "$2" $pkg/files.list
846 files=`grep $2 $pkg/files.list | wc -l`
847 match=$(($match+$files))
848 fi
849 done
851 fi
853 if [ "$match" = "" ]; then
854 echo "0 file found for : $2"
855 echo ""
856 else
857 echo ""
858 echo "================================================================================"
859 echo "$match file(s) found for : $2"
860 echo ""
861 fi
862 ;;
863 install)
864 # Install .tazpkg packages.
865 #
866 check_root
867 check_for_package_on_cmdline
868 check_for_package_file
869 # Check if forced install.
870 DO_CHECK="yes"
871 while [ -n "$3" ]; do
872 case "$3" in
873 --forced)
874 DO_CHECK="no"
875 ;;
876 --root=*)
877 install_package ${3#--root=}
878 exit $?
879 ;;
880 *) shift 2
881 echo -e "\nUnknown option $*.\n"
882 exit 1
883 ;;
884 esac
885 shift
886 done
887 if [ "$DO_CHECK" = "yes" ]; then
888 check_for_installed_package
889 fi
890 # Resolv package deps.
891 check_for_deps
892 if [ ! "$MISSING_PACKAGE" = "" ]; then
893 install_deps
894 fi
895 install_package
896 ;;
897 install-list|get-install-list)
898 # Install a set of packages from a list.
899 #
900 check_root
901 if [ -z "$2" ]; then
902 echo -e "
903 Please change directory (cd) to the packages repository, and specify the
904 list of packages to install. Example : tazpkg install-list packages.list\n"
905 exit 0
906 fi
907 # Check if the packages list exist.
908 if [ ! -f "$2" ]; then
909 echo "Unable to find : $2"
910 exit 0
911 else
912 LIST=`cat $2`
913 fi
914 # Set $COMMAND and install all packages.
915 if [ "$1" = "get-install-list" ]; then
916 COMMAND=get-install
917 else
918 COMMAND=install
919 fi
920 for pkg in $LIST
921 do
922 if [ "$3" = "--forced" ]; then
923 tazpkg $COMMAND $pkg --forced
924 else
925 tazpkg $COMMAND $pkg
926 fi
927 done
928 ;;
929 add-flavor)
930 # Install a set of packages from a flavor.
931 #
932 install_flavor $2
933 ;;
934 install-flavor)
935 # Install a set of packages from a flavor and purge other ones.
936 #
937 install_flavor $2 --purge
938 ;;
939 set-release)
940 # Change curent release and upgrade packages.
941 #
942 RELEASE=$2
943 if [ -z "$RELEASE" ]; then
944 echo -e "\nPlease specify the release you want on the command line."
945 echo -e "Example: tazpkg set-release cooking\n"
946 exit 0
947 fi
948 rm /var/lib/tazpkg/mirror
949 echo "$RELEASE" > /etc/slitaz-release
950 tazpkg recharge && tazpkg upgrade
951 ;;
952 remove)
953 # Remove packages.
954 #
955 check_root
956 check_for_package_on_cmdline
957 if [ ! -d "$INSTALLED/$PACKAGE" ]; then
958 echo -e "\n$PACKAGE is not installed.\n"
959 exit 0
960 else
961 ALTERED=""
962 THE_PACKAGE=$PACKAGE # altered by receipt
963 for i in $(cd $INSTALLED ; ls); do
964 DEPENDS=""
965 . $INSTALLED/$i/receipt
966 case " $(echo $DEPENDS) " in
967 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
968 esac
969 done
970 EXTRAVERSION=""
971 . $INSTALLED/$THE_PACKAGE/receipt
972 fi
973 echo ""
974 if [ -n "$ALTERED" ]; then
975 echo "The following packages depend on $PACKAGE :"
976 for i in $ALTERED; do
977 echo " $i"
978 done
979 fi
980 echo "Remove $PACKAGE ($VERSION$EXTRAVERSION) ?"
981 echo -n "Please confirm uninstallation (y/N) : "; read anser
982 if [ "$anser" = "y" ]; then
983 echo ""
984 echo -e "\033[1mRemoving :\033[0m $PACKAGE"
985 echo "================================================================================"
986 # Pre remove commands.
987 if grep -q ^pre_remove $INSTALLED/$PACKAGE/receipt; then
988 pre_remove
989 fi
990 echo -n "Removing all files installed..."
991 for file in `cat $INSTALLED/$PACKAGE/files.list`
992 do
993 [ $(grep ^$file$ $INSTALLED/*/files.list | wc -l) -gt 1 ] && continue
994 rm -f $file 2>/dev/null
995 done
996 status
997 if grep -q ^post_remove $INSTALLED/$PACKAGE/receipt; then
998 post_remove
999 fi
1000 # Remove package receipt.
1001 echo -n "Removing package receipt..."
1002 rm -rf $INSTALLED/$PACKAGE
1003 status
1004 if [ -n "$ALTERED" ]; then
1005 echo -n "Remove packages depending on $PACKAGE"
1006 echo -n " (y/N) ? "; read anser
1007 if [ "$anser" = "y" ]; then
1008 for i in $ALTERED; do
1009 if [ -d "$INSTALLED/$i" ]; then
1010 tazpkg remove $i
1011 fi
1012 done
1013 fi
1014 fi
1015 else
1016 echo ""
1017 echo "Uninstallation of $PACKAGE cancelled."
1018 fi
1019 echo ""
1020 ;;
1021 extract)
1022 # Extract .tazpkg cpio archive into a directory.
1024 check_for_package_on_cmdline
1025 check_for_package_file
1026 echo ""
1027 echo -e "\033[1mExtracting :\033[0m $PACKAGE"
1028 echo "================================================================================"
1029 # If any directory destination is found on the cmdline
1030 # we creat one in the current dir using the package name.
1031 if [ -n "$TARGET_DIR" ]; then
1032 DESTDIR=$TARGET_DIR/$PACKAGE
1033 else
1034 DESTDIR=$PACKAGE
1035 fi
1036 mkdir -p $DESTDIR
1037 echo -n "Copying original package..."
1038 cp $PACKAGE_FILE $DESTDIR
1039 status
1040 cd $DESTDIR
1041 extract_package
1042 echo "================================================================================"
1043 echo "$PACKAGE is extracted to : $DESTDIR"
1044 echo ""
1045 ;;
1046 repack)
1047 # Creat SliTaz package archive from an installed package.
1049 check_for_package_on_cmdline
1050 check_for_receipt
1051 EXTRAVERSION=""
1052 . $INSTALLED/$PACKAGE/receipt
1053 echo ""
1054 echo -e "\033[1mRepacking :\033[0m $PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
1055 echo "================================================================================"
1056 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
1057 echo "Can't repack $PACKAGE"
1058 exit 1
1059 fi
1060 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
1061 echo "Can't repack, $PACKAGE files have been modified by:"
1062 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
1063 echo " $i"
1064 done
1065 exit 1
1066 fi
1067 MISSING=""
1068 while read i; do
1069 [ -e "$i" ] && continue
1070 [ -L "$i" ] || MISSING="$MISSING\n $i"
1071 done < $INSTALLED/$PACKAGE/files.list
1072 if [ -n "$MISSING" ]; then
1073 echo -n "Can't repack, the following files are lost:"
1074 echo -e "$MISSING"
1075 exit 1
1076 fi
1077 mkdir -p $TMP_DIR && cd $TMP_DIR
1078 FILES="fs.cpio.gz\n"
1079 for i in $(ls $INSTALLED/$PACKAGE) ; do
1080 cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
1081 done
1082 ln -s / rootfs
1083 mkdir tmp
1084 sed 's/^/rootfs/' < files.list | cpio -o -H newc 2>/dev/null |\
1085 ( cd tmp ; cpio -id 2>/dev/null )
1086 mv tmp/rootfs fs
1087 if grep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
1088 . $INSTALLED/$PACKAGE/receipt
1089 repack_cleanup fs
1090 fi
1091 if [ -f $INSTALLED/$PACKAGE/md5sum ]; then
1092 sed 's, , fs,' < $INSTALLED/$PACKAGE/md5sum | \
1093 if ! md5sum -s -c; then
1094 echo -n "Can't repack, md5sum error."
1095 cd $TOP_DIR
1096 \rm -R $TMP_DIR
1097 exit 1
1098 fi
1099 fi
1100 find fs | cpio -o -H newc 2> /dev/null | gzip -9 > fs.cpio.gz
1101 echo -e "$FILES" | cpio -o -H newc 2> /dev/null > \
1102 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1103 cd $TOP_DIR
1104 \rm -R $TMP_DIR
1105 echo "Package $PACKAGE repacked successfully."
1106 echo "Size : `du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
1107 echo ""
1108 ;;
1109 pack)
1110 # Creat SliTaz package archive using cpio and gzip.
1112 check_for_package_on_cmdline
1113 cd $PACKAGE
1114 if [ ! -f "receipt" ]; then
1115 echo "Receipt is missing. Please read the documentation."
1116 exit 0
1117 else
1118 echo ""
1119 echo -e "\033[1mPacking :\033[0m $PACKAGE"
1120 echo "================================================================================"
1121 # Creat files.list with redirecting find outpout.
1122 echo -n "Creating the list of files..." && cd fs
1123 find . -type f -print > ../files.list
1124 find . -type l -print >> ../files.list
1125 cd .. && sed -i s/'^.'/''/ files.list
1126 status
1127 # Build cpio archives.
1128 echo -n "Compressing the fs... "
1129 find fs -print | cpio -o -H newc > fs.cpio
1130 gzip fs.cpio && rm -rf fs
1131 echo -n "Creating full cpio archive... "
1132 find . -print | cpio -o -H newc > ../$PACKAGE.tazpkg
1133 echo -n "Restoring original package tree... "
1134 gzip -d fs.cpio.gz && cpio -id < fs.cpio
1135 rm fs.cpio && cd ..
1136 echo "================================================================================"
1137 echo "Package $PACKAGE compressed successfully."
1138 echo "Size : `du -sh $PACKAGE.tazpkg`"
1139 echo ""
1140 fi
1141 ;;
1142 recharge)
1143 # Recharge packages.list from a mirror.
1145 check_root
1146 cd $LOCALSTATE
1147 echo ""
1148 if [ -f "$LOCALSTATE/packages.list" ]; then
1149 echo -n "Creating backup of the last packages list..."
1150 mv -f packages.desc packages.desc.bak 2>/dev/null
1151 mv -f packages.txt packages.txt.bak 2>/dev/null
1152 mv -f packages.list packages.list.bak 2>/dev/null
1153 mv -f files.list.lzma files.list.lzma.bak 2> /dev/nul
1154 status
1155 fi
1156 download packages.desc
1157 download packages.txt
1158 download packages.list
1159 download files.list.lzma
1160 if [ -f "$LOCALSTATE/packages.list.bak" ]; then
1161 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
1162 sed -i s/+// packages.diff
1163 echo ""
1164 echo -e "\033[1mMirrored packages diff\033[0m"
1165 echo "================================================================================"
1166 cat packages.diff
1167 if [ ! "`cat packages.diff | wc -l`" = 0 ]; then
1168 echo "================================================================================"
1169 echo "`cat packages.diff | wc -l` new packages on the mirror."
1170 echo ""
1171 else
1172 echo "`cat packages.diff | wc -l` new packages on the mirror."
1173 echo ""
1174 fi
1175 else
1176 echo -e "
1177 ================================================================================
1178 Last packages.list is ready to use. Note that next time you recharge the list,
1179 a list of differencies will be displayed to show new and upgradable packages.\n"
1180 fi
1181 ;;
1182 upgrade)
1183 # Upgrade all installed packages with the new version from the mirror.
1185 check_root
1186 check_for_packages_list
1187 cd $LOCALSTATE
1188 # Touch the blocked pkgs list to avoid errors and remove any old
1189 # upgrade list.
1190 touch blocked-packages.list
1191 rm -f upradable-packages.list
1192 echo ""
1193 echo -e "\033[1mAvalaible upgrade\033[0m"
1194 echo "================================================================================"
1195 echo ""
1196 # Some packages must be installed first
1197 FIRST_CLASS_PACKAGE=" glibc-base "
1198 FIRST_CLASS=""
1199 for pkg in $INSTALLED/*
1200 do
1201 EXTRAVERSION=""
1202 . $pkg/receipt
1203 # Diplay package name to show that Tazpkg is working...
1204 echo -en "\\033[0G "
1205 echo -en "\\033[0G$PACKAGE"
1206 # Skip specified pkgs listed in $LOCALSTATE/blocked-packages.list
1207 if grep -q "^$PACKAGE" $BLOCKED; then
1208 blocked=$(($blocked+1))
1209 else
1210 # Check if the installed package is in the current list (other
1211 # mirror or local).
1212 NEW_PACKAGE=$(grep "^$PACKAGE-[0-9]" packages.list | head -1)
1213 [ -n "$NEW_PACKAGE" ] || NEW_PACKAGE=$(grep "^$PACKAGE-.[\.0-9]" packages.list | head -1)
1215 if [ -n "$NEW_PACKAGE" ]; then
1216 # Set new pkg and version for futur comparaison
1217 NEW_VERSION=`echo $NEW_PACKAGE | sed s/$PACKAGE-/''/`
1218 # Change '-' and 'pre' to points.
1219 NEW_VERSION=`echo $NEW_VERSION | sed s/'-'/'.'/`
1220 VERSION=`echo $VERSION | sed s/'-'/'.'/`$EXTRAVERSION
1221 NEW_VERSION=`echo $NEW_VERSION | sed s/'pre'/'.'/`
1222 VERSION=`echo $VERSION | sed s/'pre'/'.'/`
1223 NEW_VERSION=`echo $NEW_VERSION | sed 's/[A-Z]\.//'`
1224 VERSION=`echo $VERSION | sed 's/[A-Z]\.//'`
1225 # Compare version. Upgrade are only avalaible for official
1226 # packages, so we control de mirror and it should be ok if
1227 # we just check for egality.
1228 if [ "$VERSION" != "$NEW_VERSION" ]; then
1229 # Version seems different. Check for major, minor or
1230 # revision
1231 PKG_MAJOR=`echo ${VERSION%_*} | cut -f1 -d"."`
1232 NEW_MAJOR=`echo ${NEW_VERSION%_*} | cut -f1 -d"."`
1233 PKG_MINOR=`echo ${VERSION%_*} | cut -f2 -d"."`
1234 NEW_MINOR=`echo ${NEW_VERSION%_*} | cut -f2 -d"."`
1235 # Minor
1236 if [ "$NEW_MINOR" -gt "$PKG_MINOR" ]; then
1237 RELEASE=minor
1238 fi
1239 if [ "$NEW_MINOR" -lt "$PKG_MINOR" ]; then
1240 RELEASE=$WARNING
1241 FIXE=yes
1242 fi
1243 # Major
1244 if [ "$NEW_MAJOR" -gt "$PKG_MAJOR" ]; then
1245 RELEASE=major
1246 FIXE=""
1247 fi
1248 if [ "$NEW_MAJOR" -lt "$PKG_MAJOR" ]; then
1249 RELEASE=$WARNING
1250 FIXE=yes
1251 fi
1252 # Default to revision.
1253 if [ -z $RELEASE ]; then
1254 RELEASE=revision
1255 fi
1256 # Pkg name is already displayed by the check process.
1257 echo -en "\033[24G $VERSION"
1258 echo -en "\033[38G --->"
1259 echo -en "\033[43G $NEW_VERSION"
1260 echo -en "\033[58G $CATEGORY"
1261 echo -e "\033[72G $RELEASE"
1262 up=$(($up+1))
1263 echo "$PACKAGE" >> upradable-packages.list
1264 case "$FIRST_CLASS_PACKAGE" in
1265 *\ $PACKAGE\ *) FIRST_CLASS="$FIRST_CLASS $PACKAGE";;
1266 esac
1267 unset RELEASE
1268 fi
1269 packages=$(($packages+1))
1270 fi
1271 fi
1272 done
1273 if [ -z $blocked ]; then
1274 blocked=0
1275 fi
1276 # Clean last checked package and display summary.
1277 if [ ! "$up" = "" ]; then
1278 echo -e "\\033[0G "
1279 echo "================================================================================"
1280 echo "$packages installed and listed packages to consider, $up to upgrade, $blocked blocked."
1281 echo ""
1282 else
1283 echo -e "\\033[0GSystem is up to date. "
1284 echo ""
1285 echo "================================================================================"
1286 echo "$packages installed and listed packages to consider, 0 to upgrade, $blocked blocked."
1287 echo ""
1288 exit 0
1289 fi
1290 # What to do if major or minor version is smaller.
1291 if [ "$FIXE" == "yes" ]; then
1292 echo -e "$WARNING ---> Installed package seems more recent than the mirrored one."
1293 echo "You can block packages using the command : 'tazpkg block package'"
1294 echo "Or upgrade package at you own risks."
1295 echo ""
1296 fi
1297 # Ask for upgrade, it can be done an other time.
1298 echo -n "Upgrade now (y/N) ? "; read anser
1299 if [ ! "$anser" = "y" ]; then
1300 echo -e "\nExiting. No package upgraded.\n"
1301 exit 0
1302 fi
1303 # If anser is yes (y). Install all new version.
1304 for pkg in $FIRST_CLASS `cat upradable-packages.list`
1305 do
1306 tazpkg get-install $pkg --forced
1307 done
1308 ;;
1309 check)
1310 # check installed packages set.
1312 check_root
1313 cd $INSTALLED
1314 for PACKAGE in `ls`; do
1315 DEPENDS=""
1316 EXTRAVERSION=""
1317 . $PACKAGE/receipt
1318 if [ -s $PACKAGE/modifiers ]; then
1319 echo "The package $PACKAGE $VERSION$EXTRAVERSION has been modified by :"
1320 for i in $(cat $PACKAGE/modifiers); do
1321 echo " $i"
1322 done
1323 fi
1324 MSG="Files lost from $PACKAGE $VERSION$EXTRAVERSION :\n"
1325 while read file; do
1326 [ -e "$file" ] && continue
1327 if [ -L "$file" ]; then
1328 MSG="$MSG target of symlink"
1329 fi
1330 echo -e "$MSG $file"
1331 MSG=""
1332 done < $PACKAGE/files.list
1333 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n"
1334 for i in $DEPENDS; do
1335 [ -d $i ] && continue
1336 echo -e "$MSG $i"
1337 MSG=""
1338 done
1339 done
1340 if [ "$PACKAGE_FILE" = "--full" ]; then
1341 for file in */md5sum; do
1342 [ -s "$file" ] || continue
1343 md5sum -c "$file" 2> /dev/null | grep -v OK$
1344 done
1345 FILES=" "
1346 for file in $(cat */files.list); do
1347 [ -d "$file" ] && continue
1348 case "$FILES" in *\ $file\ *) continue;; esac
1349 [ $(grep "^$file$" */files.list 2> /dev/null | \
1350 wc -l) -gt 1 ] || continue
1351 FILES="$FILES$file "
1352 echo "The following packages provide $file :"
1353 grep -l "^$file$" */files.list | while read f
1354 do
1355 pkg=${f%/files.list}
1356 echo -n " $pkg"
1357 if [ -f $pkg/modifiers ]; then
1358 echo -n " (known as overridden by $(cat $pkg/modifiers))"
1359 fi
1360 echo ""
1361 done
1362 done
1363 MSG="No package has installed the following files:\n"
1364 find /etc /bin /sbin /lib /usr /var/www -not -type d | while read file; do
1365 case "$file" in *\[*) continue;; esac
1366 grep -q "^$file$" */files.list && continue
1367 echo -e "$MSG $file"
1368 MSG=""
1369 done
1370 fi
1371 echo "Check completed."
1372 ;;
1373 block)
1374 # Add a pkg name to the list of blocked packages.
1376 check_root
1377 check_for_package_on_cmdline
1378 echo ""
1379 if grep -q "^$PACKAGE" $BLOCKED; then
1380 echo "$PACKAGE is already in the blocked packages list."
1381 echo ""
1382 exit 0
1383 else
1384 echo -n "Add $PACKAGE to : $BLOCKED..."
1385 echo $PACKAGE >> $BLOCKED
1386 status
1387 fi
1388 echo ""
1389 ;;
1390 unblock)
1391 # Remove a pkg name to the list of blocked packages.
1393 check_root
1394 check_for_package_on_cmdline
1395 echo ""
1396 if grep -q "^$PACKAGE" $BLOCKED; then
1397 echo -n "Removing $PACKAGE from : $BLOCKED..."
1398 sed -i s/$PACKAGE/''/ $BLOCKED
1399 sed -i '/^$/d' $BLOCKED
1400 status
1401 else
1402 echo "$PACKAGE is not in the blocked packages list."
1403 echo ""
1404 exit 0
1405 fi
1406 echo ""
1407 ;;
1408 get)
1409 # Downlowd a package with wget.
1411 check_for_package_on_cmdline
1412 check_for_packages_list
1413 check_for_package_in_list
1414 echo ""
1415 download $PACKAGE.tazpkg
1416 echo ""
1417 ;;
1418 get-install)
1419 # Download and install a package.
1421 check_root
1422 check_for_package_on_cmdline
1423 check_for_packages_list
1424 check_for_package_in_list
1425 # Check if forced install.
1426 if [ "$3" = "--forced" ]; then
1427 rm -f $CACHE_DIR/$PACKAGE.tazpkg
1428 else
1429 check_for_installed_package
1430 fi
1431 cd $CACHE_DIR
1432 if [ -f "$PACKAGE.tazpkg" ]; then
1433 echo "$PACKAGE already in the cache : $CACHE_DIR"
1434 # check package download was finished
1435 tail -c 2k $PACKAGE.tazpkg | grep -q 00000000TRAILER || {
1436 echo "Continue $PACKAGE download"
1437 download $PACKAGE.tazpkg
1439 else
1440 echo ""
1441 download $PACKAGE.tazpkg
1442 fi
1443 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
1444 check_for_deps
1445 if [ ! "$MISSING_PACKAGE" = "" ]; then
1446 install_deps
1447 fi
1448 install_package
1449 ;;
1450 clean-cache)
1451 # Remove all downloaded packages.
1453 check_root
1454 files=`ls -1 $CACHE_DIR | wc -l`
1455 echo ""
1456 echo -e "\033[1mClean cache :\033[0m $CACHE_DIR"
1457 echo "================================================================================"
1458 echo -n "Cleaning cache directory..."
1459 rm -rf $CACHE_DIR/*
1460 status
1461 echo "================================================================================"
1462 echo "$files file(s) removed from cache."
1463 echo ""
1464 ;;
1465 setup-mirror)
1466 # Change mirror URL.
1468 check_root
1469 # Backup old list.
1470 if [ -f "$LOCALSTATE/mirror" ]; then
1471 cp -f $LOCALSTATE/mirror $LOCALSTATE/mirror.bak
1472 fi
1473 echo ""
1474 echo -e "\033[1mCurrent mirror(s)\033[0m"
1475 echo "================================================================================"
1476 echo " `cat $MIRROR`"
1477 echo "
1478 Please enter URL of the new mirror (http or ftp). You must specify the complet
1479 address to the directory of the packages and packages.list file."
1480 echo ""
1481 echo -n "New mirror URL : "
1482 read NEW_MIRROR_URL
1483 if [ "$NEW_MIRROR_URL" = "" ]; then
1484 echo "Nothing as been change."
1485 else
1486 echo "Setting mirror(s) to : $NEW_MIRROR_URL"
1487 echo "$NEW_MIRROR_URL" > $LOCALSTATE/mirror
1488 fi
1489 echo ""
1490 ;;
1491 reconfigure)
1492 # Replay post_install from receipt
1494 check_for_package_on_cmdline
1495 check_root
1496 if [ -d "$INSTALLED/$PACKAGE" ]; then
1497 check_for_receipt
1498 # Check for post_install
1499 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
1500 . $INSTALLED/$PACKAGE/receipt
1501 post_install
1502 else
1503 echo -e "\nNothing to do for $PACKAGE."
1504 fi
1505 else
1506 echo -e "\npackage $PACKAGE is not installed."
1507 echo -e "Install package with 'tazpkg install' or 'tazpkg get-install'\n"
1508 fi
1509 ;;
1510 shell)
1511 # Tazpkg SHell
1513 if test $(id -u) = 0 ; then
1514 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
1515 else
1516 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
1517 fi
1518 if [ ! "$2" = "--noheader" ]; then
1519 clear
1520 echo ""
1521 echo -e "\033[1mTazpkg SHell.\033[0m"
1522 echo "================================================================================"
1523 echo "Type 'usage' to list all avalaible commands and 'quit' or 'q' to exit."
1524 echo ""
1525 fi
1526 while true
1527 do
1528 echo -en "$PROMPT"; read cmd
1529 case $cmd in
1530 q|quit)
1531 break ;;
1532 shell)
1533 echo "You are already running a Tazpkg SHell." ;;
1534 su)
1535 su -c 'exec tazpkg shell --noheader' && break ;;
1536 "")
1537 continue ;;
1538 *)
1539 tazpkg $cmd ;;
1540 esac
1541 done
1542 ;;
1543 usage|*)
1544 # Print a short help or give usage for an unknown or empty command.
1546 usage
1547 ;;
1548 esac
1550 exit 0