tazpkg view tazpkg @ rev 137

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