tazpkg view tazpkg @ rev 136

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