tazpkg view tazpkg @ rev 122

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