tazpkg view tazpkg @ rev 123

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