tazpkg view tazpkg @ rev 142

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