tazpkg view tazpkg @ rev 37

Support for creating xHTML list of installed packages
author Christophe Lincoln <pankso@slitaz.org>
date Tue Feb 05 14:12:19 2008 +0100 (2008-02-05)
parents 695f9848b93a
children abe47a57b67b
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 relolv 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 #
15 VERSION=1.6.1
17 ####################
18 # Script variables #
19 ####################
21 # Packages categories.
22 CATEGORIES="base-system base-apps x-window extra devel"
24 # Initialize some variables to use words
25 # rater than numbers for functions and actions.
26 COMMAND=$1
27 if [ -f "$2" ]; then
28 # Set pkg basename for install, extract
29 PACKAGE=$(basename ${2%.tazpkg} 2>/dev/null)
30 else
31 # Pkg name for remove, search and all other cmds
32 PACKAGE=${2%.tazpkg}
33 fi
34 PACKAGE_FILE=$2
35 TARGET_DIR=$3
36 TOP_DIR=`pwd`
37 TMP_DIR=/tmp/tazpkg-$$-$RANDOM
39 # Path to tazpkg used dir and configuration files
40 LOCALSTATE=/var/lib/tazpkg
41 INSTALLED=$LOCALSTATE/installed
42 CACHE_DIR=/var/cache/tazpkg
43 MIRROR=$LOCALSTATE/mirror
44 PACKAGES_LIST=$LOCALSTATE/packages.list
45 BLOCKED=$LOCALSTATE/blocked-packages.list
47 # Bold red warnig for upgrade.
48 WARNING="\\033[1;31mWARNING\\033[0;39m"
50 # Check if the directories and files used by Tazpkg
51 # exists. If not and user is root we creat them.
52 if test $(id -u) = 0 ; then
53 if [ ! -d "$CACHE_DIR" ]; then
54 mkdir -p $CACHE_DIR
55 fi
56 if [ ! -d "$INSTALLED" ]; then
57 mkdir -p $INSTALLED
58 fi
59 if [ ! -f "$LOCALSTATE/mirror" ]; then
60 echo "$DEFAULT_MIRROR" > $LOCALSTATE/mirror
61 fi
62 fi
64 ####################
65 # Script functions #
66 ####################
68 # Print the usage.
69 usage ()
70 {
71 echo -e "SliTaz packages manager - Version: $VERSION
72 \033[1mUsage: \033[0m tazpkg [command] [package|dir|pattern|list|cat|--opt] [dir|--opt]
73 \033[1mCommands: \033[0m
74 usage Print this short usage.
75 list List installed packages on the system by category or all.
76 xhtml-list Creat a xHTML list of installed packges.
77 list-mirror List all available packages on the mirror (--diff for new).
78 info Print informations about the package.
79 desc Print description of a package (if it exist).
80 list-files List of files installed with the package.
81 search Search for a package by pattern or name.
82 search-file Search for file(s) in all installed packages files.
83 install Install a local (*.tazpkg) package (--forced to force).
84 install-list Install all packages from a list of packages.
85 remove Remove the specified package and all installed files.
86 extract Extract a (*.tazpkg) package into a directory.
87 pack Pack an unpacked or prepared package tree.
88 recharge Recharge your packages.list from the mirror.
89 repack Creat a package archive from an installed package.
90 upgrade Upgrade all installed and listed packages on the mirror.
91 block|unblock Block an installed package version or unblock it for upgrade.
92 get Download a package into the current directory.
93 get-install Download and install a package from the mirror.
94 check Verify installed packages concistancy.
95 clean-cache Clean all packages downloaded in cache directory.
96 setup-mirror Change the mirror url configuration."
97 }
99 # Status function with color (supported by Ash).
100 status()
101 {
102 local CHECK=$?
103 echo -en "\\033[70G[ "
104 if [ $CHECK = 0 ]; then
105 echo -en "\\033[1;33mOK"
106 else
107 echo -en "\\033[1;31mFailed"
108 fi
109 echo -e "\\033[0;39m ]"
110 return $CHECK
111 }
113 # Check if user is root to install, or remove packages.
114 check_root()
115 {
116 if test $(id -u) != 0 ; then
117 echo -e "\nYou must be root to run `basename $0` with this option."
118 echo -e "Please type 'su' and root password to become super-user.\n"
119 exit 0
120 fi
121 }
123 # Check for a package name on cmdline.
124 check_for_package_on_cmdline()
125 {
126 if [ -z "$PACKAGE" ]; then
127 echo -e "\nPlease specify a package name on the command line.\n"
128 exit 0
129 fi
130 }
132 # Check if the package (*.tazpkg) exist before installing or extracting.
133 check_for_package_file()
134 {
135 if [ ! -f "$PACKAGE_FILE" ]; then
136 echo -e "
137 Unable to find : $PACKAGE_FILE\n"
138 exit 0
139 fi
140 }
142 # Check for the receipt of an installed package.
143 check_for_receipt()
144 {
145 if [ ! -f "$INSTALLED/$PACKAGE/receipt" ]; then
146 echo -e "\nUnable to find the receipt : $INSTALLED/$PACKAGE/receipt\n"
147 exit 0
148 fi
149 }
151 # Check if a package is already installed.
152 check_for_installed_package()
153 {
154 if [ -d "$INSTALLED/${PACKAGE%-[0-9]*}" ]; then
155 echo -e "
156 $PACKAGE is already installed. You can use the --forced option to force
157 installation or remove it and reinstall.\n"
158 exit 0
159 fi
160 }
162 # Check for packages.list to download and install packages.
163 check_for_packages_list()
164 {
165 if [ ! -f "$LOCALSTATE/packages.list" ]; then
166 echo -e "
167 Unable to find the list : $LOCALSTATE/packages.list\n
168 You must probably run 'tazpkg recharge' as root to get the last list of
169 packages avalaible on the mirror.\n"
170 exit 0
171 fi
172 }
174 # Check for a package in packages.list. Used by get and get-install to grep
175 # package basename.
176 check_for_package_in_list()
177 {
178 if grep -q "^$PACKAGE-[0-9]" $LOCALSTATE/packages.list; then
179 PACKAGE=`grep ^$PACKAGE-[0-9] $LOCALSTATE/packages.list`
180 else
181 echo -e "\nUnable to find : $PACKAGE in the mirrored packages list.\n"
182 exit 0
183 fi
184 }
186 # Download a file trying all mirrors
187 download()
188 {
189 for i in $(cat $MIRROR); do
190 wget $i$@
191 done
192 }
194 # Extract a package with cpio and gzip.
195 extract_package()
196 {
197 echo -n "Extracting $PACKAGE..."
198 cpio -id < $PACKAGE.tazpkg && rm -f $PACKAGE.tazpkg
199 gzip -d fs.cpio.gz
200 echo -n "Extracting the pseudo fs... "
201 cpio -id < fs.cpio && rm fs.cpio
202 }
204 # This function install a package in the rootfs.
205 install_package()
206 {
207 ROOT=$1
208 if [ -n "$ROOT" ]; then
209 # get absolute path
210 ROOT=$(cd $ROOT; pwd)
211 fi
212 mkdir -p $TMP_DIR
213 echo ""
214 echo -e "\033[1mInstallation of :\033[0m $PACKAGE"
215 echo "================================================================================"
216 echo -n "Copying $PACKAGE... "
217 cp $PACKAGE_FILE $TMP_DIR
218 status
219 cd $TMP_DIR
220 extract_package
221 SELF_INSTALL=0
222 MODIFY_PACKAGES=""
223 # Include temporary receipt to get the right variables.
224 . $PWD/receipt
225 if [ $SELF_INSTALL -ne 0 -a -n "$ROOT" ]; then
226 echo -n "Checking post install dependencies... "
227 [ -d "$INSTALLED/${PACKAGE%-[0-9]*}" ]
228 if ! status; then
229 echo "Please run 'tazpkg install $PACKAGE_FILE' and retry."
230 cd .. && rm -rf $TMP_DIR
231 exit 1
232 fi
233 fi
234 # Remember modified packages
235 for i in $MODIFY_PACKAGES; do
236 [ -d $ROOT$INSTALLED/$i ] || continue
237 grep -qs ^$PACKAGE$ $ROOT$INSTALLED/$i/modifiers && continue
238 echo "$PACKAGE" >> $ROOT$INSTALLED/$i/modifiers
239 done
240 # Make the installed package data dir to store
241 # the receipt and the files list.
242 mkdir -p $ROOT$INSTALLED/$PACKAGE
243 cp receipt files.list $ROOT$INSTALLED/$PACKAGE
244 # Copy the description if found.
245 if [ -f "description.txt" ]; then
246 cp description.txt $ROOT$INSTALLED/$PACKAGE
247 fi
248 if grep -q pre_install $ROOT$INSTALLED/$PACKAGE/receipt; then
249 # Execute post install commands.
250 pre_install $ROOT
251 fi
252 echo -n "Installing $PACKAGE... "
253 cp -a fs/* $ROOT/
254 status
255 # Remove the temporary random directory.
256 echo -n "Removing all tmp files... "
257 cd .. && rm -rf $TMP_DIR
258 status
259 if grep -q post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
260 # Execute post install commands.
261 post_install $ROOT
262 fi
263 cd $TOP_DIR
264 echo "================================================================================"
265 echo "$PACKAGE ($VERSION) is installed."
266 echo ""
267 }
269 # Check for missing deps listed in a receipt packages.
270 check_for_deps()
271 {
272 for i in $DEPENDS
273 do
274 if [ ! -d "$INSTALLED/$i" ]; then
275 MISSING_PACKAGE=$i
276 deps=$(($deps+1))
277 fi
278 done
279 if [ ! "$MISSING_PACKAGE" = "" ]; then
280 echo -e "\033[1mTracking dependencies for :\033[0m $PACKAGE"
281 echo "================================================================================"
282 for i in $DEPENDS
283 do
284 if [ ! -d "$INSTALLED/$i" ]; then
285 MISSING_PACKAGE=$i
286 echo "Missing : $MISSING_PACKAGE"
287 fi
288 done
289 echo "================================================================================"
290 echo "$deps missing package(s) to install."
291 fi
292 }
294 # Install all missing deps. First ask user then install all missing deps
295 # from local dir, cdrom, media or from the mirror. In case we want to
296 # install packages from local, we need a packages.list to find the version.
297 install_deps()
298 {
299 echo ""
300 echo -n "Install all missing dependencies (y/N) ? "; read anser
301 if [ "$anser" = "y" ]; then
302 for pkg in $DEPENDS
303 do
304 if [ ! -d "$INSTALLED/$pkg" ]; then
305 # We can install packages from a local dir by greping
306 # the TAZPKG_BASENAME in the local packages.list.
307 if [ -f "$TOP_DIR/packages.list" ]; then
308 echo "Checking if $pkg exist in local list... "
309 TAZPKG_BASENAME=`grep -e ^$pkg-[0-9] $TOP_DIR/packages.list`
310 if [ -f "$TAZPKG_BASENAME.tazpkg" ]; then
311 tazpkg install $TAZPKG_BASENAME.tazpkg
312 fi
313 # Install deps from the mirror.
314 else
315 if [ ! -f "$LOCALSTATE/packages.list" ]; then
316 tazpkg recharge
317 fi
318 tazpkg get-install $pkg
319 fi
320 fi
321 done
322 else
323 echo -e "\nLeaving dependencies for $PACKAGE unsolved."
324 echo -e "The package is installed but will probably not work.\n"
325 fi
326 }
328 # xHTML packages list header.
329 xhtml_header()
330 {
331 cat > $XHTML_LIST << _EOT_
332 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
333 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
334 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
335 <head>
336 <title>Installed packages list</title>
337 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
338 <meta name="modified" content="$DATE" />
339 <meta name="generator" content="Tazpkg" />
340 <style type="text/css"><!--
341 body { font: 12px sans-serif, vernada, arial; margin: 0; }
342 #header { background: #f0ba08; color: black; height: 50px;
343 border-top: 1px solid black; border-bottom: 1px solid black; }
344 #content { margin: 0px 50px 26px 50px; }
345 #footer { border-top: 1px solid black; padding-top: 10px;}
346 h1 { margin: 14px 0px 0px 16px; }
347 pre { padding-left: 5px; }
348 hr { color: white; background: white; height: 1px; border: 0; }
349 --></style>
350 </head>
351 <body bgcolor="#ffffff">
352 <div id="header">
353 <h1><font color="#3e1220">Installed packages list</font></h1>
354 </div>
355 <hr />
356 <!-- Start content -->
357 <div id="content">
359 <p>
360 _packages_ packages installed - List generated on : $DATE
361 <p>
363 _EOT_
364 }
366 # xHTML content with packages infos.
367 xhtml_pkg_info()
368 {
369 cat >> $XHTML_LIST << _EOT_
370 <h3>$PACKAGE</h3>
371 <pre>
372 Version : $VERSION
373 Short desc : $SHORT_DESC
374 Web site : <a href="$WEB_SITE">$WEB_SITE</a>
375 </pre>
377 _EOT_
378 }
380 # xHTML packages list footer.
381 xhtml_footer()
382 {
383 cat >> $XHTML_LIST << _EOT_
384 <hr />
385 <p id="footer">
386 $packages packages installed - List generated on : $DATE
387 </p>
389 <!-- End content -->
390 </div>
391 </body>
392 </html>
393 _EOT_
394 }
396 ###################
397 # Tazpkg commands #
398 ###################
400 case "$COMMAND" in
401 list)
402 # List all installed packages or a specific category.
403 #
404 if [ "$2" = "category" ]; then
405 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
406 exit 0
407 fi
408 # Check for an asked category.
409 if [ -n "$2" ]; then
410 ASKED_CATEGORY=$2
411 echo ""
412 echo -e "\033[1mInstalled packages of category :\033[0m $ASKED_CATEGORY"
413 echo "================================================================================"
414 for pkg in $INSTALLED/*
415 do
416 . $pkg/receipt
417 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
418 echo -n "$PACKAGE"
419 echo -e "\033[24G $VERSION"
420 packages=$(($packages+1))
421 fi
422 done
423 echo "================================================================================"
424 echo -e "$packages packages installed of category $ASKED_CATEGORY."
425 echo ""
426 else
427 # By default list all packages and version.
428 echo ""
429 echo -e "\033[1mList of all installed packages\033[0m"
430 echo "================================================================================"
431 for pkg in $INSTALLED/*
432 do
433 . $pkg/receipt
434 echo -n "$PACKAGE"
435 echo -en "\033[24G $VERSION"
436 echo -e "\033[42G $CATEGORY"
437 packages=$(($packages+1))
438 done
439 echo "================================================================================"
440 echo "$packages packages installed."
441 echo ""
442 fi
443 ;;
444 xhtml-list)
445 # Get infos in receipts and build list.
446 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
447 if [ -n "$2" ]; then
448 XHTML_LIST=$2
449 else
450 XHTML_LIST=packages.html
451 fi
452 echo ""
453 echo -e "\033[1mCreating xHTML list of installed packages\033[0m"
454 echo "================================================================================"
455 echo -n "Generating xHTML header..."
456 xhtml_header
457 status
458 # Packages
459 echo -n "Creating packages informations..."
460 for pkg in $INSTALLED/*
461 do
462 . $pkg/receipt
463 xhtml_pkg_info
464 packages=$(($packages+1))
465 done
466 status
467 echo -n "Generating xHTML footer..."
468 xhtml_footer
469 status
470 # sed pkgs nb in header.
471 sed -i s/'_packages_'/"$packages"/ $XHTML_LIST
472 echo "================================================================================"
473 echo "$XHTML_LIST created - $packages packages."
474 echo ""
475 ;;
476 list-mirror)
477 # List all available packages on the mirror. Option --diff display
478 # last mirrored packages diff (see recharge).
479 check_for_packages_list
480 if [ "$2" = "--diff" ]; then
481 if [ -f "$LOCALSTATE/packages.diff" ]; then
482 echo ""
483 echo -e "\033[1mMirrored packages diff\033[0m"
484 echo "================================================================================"
485 cat $LOCALSTATE/packages.diff
486 echo "================================================================================"
487 pkgs=`cat $LOCALSTATE/packages.diff | wc -l`
488 echo "$pkgs new packages listed on the mirror."
489 echo ""
490 else
491 echo -e "\nUnable to list anything, no packages.diff found."
492 echo -e "Recharge your current list to creat a first diff.\n"
493 fi
494 else
495 echo ""
496 echo -e "\033[1mList of available packages on the mirror\033[0m"
497 echo "================================================================================"
498 cat $LOCALSTATE/packages.list
499 echo "================================================================================"
500 pkgs=`cat $LOCALSTATE/packages.list | wc -l`
501 echo "$pkgs packages in the last recharged list."
502 echo ""
503 fi
504 ;;
505 list-files)
506 # List files installed with the package.
507 #
508 check_for_package_on_cmdline
509 check_for_receipt
510 echo ""
511 echo -e "\033[1mInstalled files with :\033[0m $PACKAGE"
512 echo "================================================================================"
513 cat $INSTALLED/$PACKAGE/files.list | sort
514 echo "================================================================================"
515 files=`cat $INSTALLED/$PACKAGE/files.list | wc -l`
516 echo "$files files installed with $PACKAGE."
517 echo ""
518 ;;
519 info)
520 # Informations about package.
521 #
522 check_for_package_on_cmdline
523 check_for_receipt
524 . $INSTALLED/$PACKAGE/receipt
525 echo ""
526 echo -e "\033[1mTazpkg informations\033[0m
527 ================================================================================
528 Package : $PACKAGE
529 Version : $VERSION
530 Category : $CATEGORY
531 Short desc : $SHORT_DESC
532 Maintainer : $MAINTAINER"
533 if [ ! "$DEPENDS" = "" ]; then
534 echo -e "Depends : $DEPENDS"
535 fi
536 if [ ! "$WANTED" = "" ]; then
537 echo -e "Wanted src : $WANTED"
538 fi
539 if [ ! "$WEB_SITE" = "" ]; then
540 echo -e "Web site : $WEB_SITE"
541 fi
542 echo "================================================================================"
543 echo ""
544 ;;
545 desc)
546 # Display package description.txt if available.
547 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
548 echo ""
549 echo -e "\033[1mDescription of :\033[0m $PACKAGE"
550 echo "================================================================================"
551 cat $INSTALLED/$PACKAGE/description.txt
552 echo "================================================================================"
553 echo ""
554 else
555 echo -e "\nSorry, no description available for this package.\n"
556 fi
557 ;;
558 search)
559 # Search for a package by pattern or name.
560 #
561 if [ -z "$2" ]; then
562 echo -e "\nPlease specify a pattern or a package name to search."
563 echo -e "Example : 'tazpkg search paint'. \n"
564 exit 0
565 fi
566 echo ""
567 echo -e "\033[1mSearch result for :\033[0m $2"
568 echo ""
569 echo "Installed packages"
570 echo "================================================================================"
571 list=`ls -1 $INSTALLED | grep $2`
572 for pkg in $list
573 do
574 . $INSTALLED/$pkg/receipt
575 echo -n "$PACKAGE "
576 echo -en "\033[24G $VERSION"
577 echo -e "\033[42G $CATEGORY"
578 packages=$(($packages+1))
579 done
580 # Set correct ending messages.
581 if [ "$packages" = "" ]; then
582 echo "0 installed packages found for : $2"
583 echo ""
584 else
585 echo "================================================================================"
586 echo "$packages installed package(s) found for : $2"
587 echo ""
588 fi
589 echo "Available packages"
590 echo "================================================================================"
591 if [ -f "$LOCALSTATE/packages.list" ]; then
592 cat $LOCALSTATE/packages.list | grep $2
593 packages=`cat $LOCALSTATE/packages.list | grep $2 | wc -l`
594 else
595 echo -e "
596 No 'packages.list' found to check for mirrored packages. For more results,
597 please run once 'tazpkg recharge' as root before searching.\n"
598 fi
599 if [ "$packages" = "0" ]; then
600 echo "0 available packages found for : $2"
601 echo ""
602 else
603 echo "================================================================================"
604 echo "$packages available package(s) found for : $2"
605 echo ""
606 fi
607 ;;
608 search-file)
609 # Search for a file by pattern or name in all files.list.
610 #
611 if [ -z "$2" ]; then
612 echo -e "\nPlease specify a pattern or a file name to search."
613 echo -e "Example : 'tazpkg search-file libnss'. \n"
614 exit 0
615 fi
616 echo ""
617 echo -e "\033[1mSearch result for file :\033[0m $2"
618 echo "================================================================================"
619 # Check all pkg files.list in search match with specify the package
620 # name and the full path to the file(s).
621 for pkg in $INSTALLED/*
622 do
623 if grep -q $2 $pkg/files.list; then
624 . $pkg/receipt
625 echo ""
626 echo -e "\033[1mPackage $PACKAGE :\033[0m"
627 grep $2 $pkg/files.list
628 files=`grep $2 $pkg/files.list | wc -l`
629 match=$(($match+$files))
630 fi
631 done
632 if [ "$match" = "" ]; then
633 echo "0 file found for : $2"
634 echo ""
635 else
636 echo ""
637 echo "================================================================================"
638 echo "$match file(s) found for : $2"
639 echo ""
640 fi
641 ;;
642 install)
643 # Install .tazpkg packages.
644 #
645 check_root
646 check_for_package_on_cmdline
647 check_for_package_file
648 # Check if forced install.
649 DO_CHECK="yes"
650 while [ -n "$3" ]; do
651 case "$3" in
652 --forced)
653 DO_CHECK="no"
654 ;;
655 --root=*)
656 install_package ${3#--root=}
657 exit $?
658 ;;
659 *) shift 2
660 echo -e "\nUnknown option $*.\n"
661 exit 1
662 ;;
663 esac
664 shift
665 done
666 if [ "$DO_CHECK" = "yes" ]; then
667 check_for_installed_package
668 fi
669 install_package
670 # Resolv package deps.
671 check_for_deps
672 if [ ! "$MISSING_PACKAGE" = "" ]; then
673 install_deps
674 fi
675 ;;
676 install-list)
677 # Install a set of packages from a list.
678 #
679 check_root
680 if [ -z "$2" ]; then
681 echo -e "
682 Please change directory (cd) to the packages repository, and specify the
683 list of packages to install. Example : tazpkg install-list packages.list\n"
684 exit 0
685 fi
686 # Check if the packages list exist.
687 if [ ! -f "$2" ]; then
688 echo "Unable to find : $2"
689 exit 0
690 else
691 LIST=`cat $2`
692 fi
693 # Install all packages.
694 for pkg in $LIST
695 do
696 if [ "$3" = "--forced" ]; then
697 tazpkg install $pkg --forced
698 else
699 tazpkg install $pkg
700 fi
701 done
702 ;;
703 remove)
704 # Remove packages.
705 #
706 check_root
707 check_for_package_on_cmdline
708 if [ ! -d "$INSTALLED/$PACKAGE" ]; then
709 echo -e "\n$PACKAGE is not installed.\n"
710 exit 0
711 else
712 ALTERED=""
713 THE_PACKAGE=$PACKAGE # altered by receipt
714 for i in $(cd $INSTALLED ; ls); do
715 DEPENDS=""
716 . $INSTALLED/$i/receipt
717 case " $(echo $DEPENDS) " in
718 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
719 esac
720 done
721 . $INSTALLED/$THE_PACKAGE/receipt
722 fi
723 echo ""
724 if [ -n "$ALTERED" ]; then
725 echo "The following packages depend on $PACKAGE :"
726 for i in $ALTERED; do
727 echo " $i"
728 done
729 fi
730 echo "Remove $PACKAGE ($VERSION) ?"
731 echo -n "Please confirm uninstallation (y/N) : "; read anser
732 if [ "$anser" = "y" ]; then
733 echo ""
734 echo -e "\033[1mRemoving :\033[0m $PACKAGE"
735 echo "================================================================================"
736 echo -n "Removing all files installed..."
737 for file in `cat $INSTALLED/$PACKAGE/files.list`
738 do
739 rm -f $file 2>/dev/null
740 done
741 status
742 # Remove package receipt.
743 echo -n "Removing package receipt..."
744 rm -rf $INSTALLED/$PACKAGE
745 status
746 if [ -n "$ALTERED" ]; then
747 echo -n "Remove packages depending on $PACKAGE"
748 echo -n " (y/N) ? "; read anser
749 if [ "$anser" = "y" ]; then
750 for i in $ALTERED; do
751 if [ -d "$INSTALLED/$i" ]; then
752 tazpkg remove $i
753 fi
754 done
755 fi
756 fi
757 else
758 echo ""
759 echo "Uninstallation of $PACKAGE cancelled."
760 fi
761 echo ""
762 ;;
763 extract)
764 # Extract .tazpkg cpio archive into a directory.
765 #
766 check_for_package_on_cmdline
767 check_for_package_file
768 echo ""
769 echo -e "\033[1mExtracting :\033[0m $PACKAGE"
770 echo "================================================================================"
771 # If any directory destination is found on the cmdline
772 # we creat one in the current dir using the package name.
773 if [ -n "$TARGET_DIR" ]; then
774 DESTDIR=$TARGET_DIR/$PACKAGE
775 else
776 DESTDIR=$PACKAGE
777 fi
778 mkdir -p $DESTDIR
779 echo -n "Copying original package..."
780 cp $PACKAGE_FILE $DESTDIR
781 status
782 cd $DESTDIR
783 extract_package
784 echo "================================================================================"
785 echo "$PACKAGE is extracted to : $DESTDIR"
786 echo ""
787 ;;
788 repack)
789 # Creat SliTaz package archive from an installed package.
790 #
791 check_for_package_on_cmdline
792 check_for_receipt
793 eval $(grep ^VERSION= $INSTALLED/$PACKAGE/receipt)
794 echo ""
795 echo -e "\033[1mRepacking :\033[0m $PACKAGE-$VERSION.tazpkg"
796 echo "================================================================================"
797 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
798 echo "Can't repack $PACKAGE"
799 exit 1
800 fi
801 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
802 echo "Can't repack, $PACKAGE files have been modified by:"
803 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
804 echo " $i"
805 done
806 exit 1
807 fi
808 MISSING=""
809 for i in $(sed 's,^fs,,g' < $INSTALLED/$PACKAGE/files.list); do
810 [ -e "$i" ] && continue
811 [ -L "$i" ] || MISSING="$MISSING $i"
812 done
813 if [ -n "$MISSING" ]; then
814 echo "Can't repack, the following files are lost:"
815 for i in $MISSING; do
816 echo " $i"
817 done
818 exit 1
819 fi
820 HERE=`pwd`
821 mkdir -p $TMP_DIR && cd $TMP_DIR
822 FILES="fs.cpio.gz\n"
823 for i in $(ls $INSTALLED/$PACKAGE) ; do
824 cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
825 done
826 cpio -pd fs < files.list 2> /dev/null
827 find fs | cpio -o -H newc 2> /dev/null | gzip -9 > fs.cpio.gz
828 echo -e "$FILES" | cpio -o -H newc 2> /dev/null > \
829 $HERE/$PACKAGE-$VERSION.tazpkg
830 cd $HERE
831 \rm -R $TMP_DIR
832 echo "Package $PACKAGE repacked successfully."
833 echo "Size : `du -sh $PACKAGE-$VERSION.tazpkg`"
834 echo ""
835 ;;
836 pack)
837 # Creat SliTaz package archive using cpio and gzip.
838 #
839 check_for_package_on_cmdline
840 cd $PACKAGE
841 if [ ! -f "receipt" ]; then
842 echo "Receipt is missing. Please read the documentation."
843 exit 0
844 else
845 echo ""
846 echo -e "\033[1mPacking :\033[0m $PACKAGE"
847 echo "================================================================================"
848 # Creat files.list with redirecting find outpout.
849 echo -n "Creating the list of files..." && cd fs
850 find . -type f -print > ../files.list
851 find . -type l -print >> ../files.list
852 cd .. && sed -i s/'^.'/''/ files.list
853 status
854 # Build cpio archives.
855 echo -n "Compressing the fs... "
856 find fs -print | cpio -o -H newc > fs.cpio
857 gzip fs.cpio && rm -rf fs
858 echo -n "Creating full cpio archive... "
859 find . -print | cpio -o -H newc > ../$PACKAGE.tazpkg
860 echo -n "Restoring original package tree... "
861 gzip -d fs.cpio.gz && cpio -id < fs.cpio
862 rm fs.cpio && cd ..
863 echo "================================================================================"
864 echo "Package $PACKAGE compressed successfully."
865 echo "Size : `du -sh $PACKAGE.tazpkg`"
866 echo ""
867 fi
868 ;;
869 recharge)
870 # Recharge packages.list from a mirror.
871 #
872 check_root
873 cd $LOCALSTATE
874 echo ""
875 if [ -f "$LOCALSTATE/packages.list" ]; then
876 echo -n "Creating backup of the last packages list..."
877 mv -f packages.list packages.list.bak
878 status
879 fi
880 download packages.list
881 if [ -f "$LOCALSTATE/packages.list.bak" ]; then
882 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
883 sed -i s/+// packages.diff
884 echo ""
885 echo -e "\033[1mMirrored packages diff\033[0m"
886 echo "================================================================================"
887 cat packages.diff
888 if [ ! "`cat packages.diff | wc -l`" = 0 ]; then
889 echo "================================================================================"
890 echo "`cat packages.diff | wc -l` new packages on the mirror."
891 echo ""
892 else
893 echo "`cat packages.diff | wc -l` new packages on the mirror."
894 echo ""
895 fi
896 else
897 echo -e "
898 ================================================================================
899 Last packages.list is ready to use. Note that next time you recharge the list,
900 a list of differencies will be displayed to show new and upgradable packages.\n"
901 fi
902 ;;
903 upgrade)
904 # Upgrade all installed packages with the new version from the mirror.
905 #
906 check_root
907 check_for_packages_list
908 cd $LOCALSTATE
909 # Touch the blocked pkgs list to avoid errors and remove any old
910 # upgrade list.
911 touch blocked-packages.list
912 rm -f upradable-packages.list
913 echo ""
914 echo -e "\033[1mAvalaible upgrade\033[0m"
915 echo "================================================================================"
916 for pkg in $INSTALLED/*
917 do
918 . $pkg/receipt
919 # Skip specified pkgs listed in $LOCALSTATE/blocked-packages.list
920 if grep -q "^$PACKAGE" $BLOCKED; then
921 blocked=$(($blocked+1))
922 else
923 # Check if the installed package is in the current list (other
924 # mirror or local).
925 if grep -q "^$PACKAGE-[0-9]" packages.list; then
926 # Set new kg and version for futur comparaison
927 NEW_PACKAGE=`grep ^$PACKAGE-[0-9] packages.list`
928 NEW_VERSION=`echo $NEW_PACKAGE | sed s/$PACKAGE-/''/`
929 # Compare version. Upgrade are only avalaible for official
930 # packages, so we control de mirror and it should be ok if
931 # we just check for egality.
932 if [ "$VERSION" != "$NEW_VERSION" ]; then
933 # Version seems different. Check for major, minor or
934 # revision
935 PKG_MAJOR=`echo $VERSION | cut -f1 -d"."`
936 NEW_MAJOR=`echo $NEW_VERSION | cut -f1 -d"."`
937 PKG_MINOR=`echo $VERSION | cut -f2 -d"."`
938 NEW_MINOR=`echo $NEW_VERSION | cut -f2 -d"."`
939 # Major
940 if [ "$NEW_MAJOR" -gt "$PKG_MAJOR" ]; then
941 RELEASE=major
942 fi
943 if [ "$NEW_MAJOR" -lt "$PKG_MAJOR" ]; then
944 RELEASE=$WARNING
945 FIXE=yes
946 fi
947 # Minor
948 if [ "$NEW_MINOR" -gt "$PKG_MINOR" ]; then
949 RELEASE=minor
950 fi
951 if [ "$NEW_MINOR" -lt "$PKG_MINOR" ]; then
952 RELEASE=$WARNING
953 FIXE=yes
954 fi
955 # Default to revision.
956 if [ -z $RELEASE ]; then
957 RELEASE=revision
958 fi
959 echo -n "$PACKAGE"
960 echo -en "\033[24G $VERSION"
961 echo -en "\033[38G --->"
962 echo -en "\033[48G $NEW_VERSION"
963 echo -en "\033[60G $CATEGORY"
964 echo -e "\033[72G $RELEASE"
965 up=$(($up+1))
966 echo "$PACKAGE" >> upradable-packages.list
967 unset RELEASE
968 fi
969 packages=$(($packages+1))
970 fi
971 fi
972 done
973 rm -f $tmpfile
974 if [ ! "$up" = "" ]; then
975 echo "================================================================================"
976 echo "$packages installed and listed packages to consider, $up to upgrade, $blocked blocked."
977 echo ""
978 else
979 echo "$packages installed and listed packages to consider, 0 to upgrade, $blocked blocked."
980 echo ""
981 exit 0
982 fi
983 # What to do if major or minor version is smaller.
984 if [ "$FIXE" == "yes" ]; then
985 echo -e "$WARNING ---> Installed package seems more recent than the mirrored one."
986 echo "You can block packages using the command : 'tazpkg block package'"
987 echo "Or upgrade package at you own risks."
988 echo ""
989 fi
990 # Ask for upgrade, it can be done an other time.
991 echo -n "Upgrade now (y/N) ? "; read anser
992 if [ ! "$anser" = "y" ]; then
993 echo -e "\nExiting. No package upgraded.\n"
994 exit 0
995 fi
996 # If anser is yes (y). Install all new version.
997 for pkg in `cat upradable-packages.list`
998 do
999 tazpkg get-install $pkg --forced
1000 done
1001 ;;
1002 check)
1003 # check installed packages set.
1005 check_root
1006 cd $INSTALLED
1007 for PACKAGE in `ls`; do
1008 DEPENDS=""
1009 . $PACKAGE/receipt
1010 if [ -s $PACKAGE/modifiers ]; then
1011 echo "The package $PACKAGE $VERSION has been modified by :"
1012 for i in $(cat $PACKAGE/modifiers); do
1013 echo " $i"
1014 done
1015 fi
1016 MSG="Files lost from $PACKAGE $VERSION :\n"
1017 while read file; do
1018 [ -e "$file" ] && continue
1019 if [ -L "$file" ]; then
1020 MSG="$MSG target of symlink"
1021 fi
1022 echo -e "$MSG $file"
1023 MSG=""
1024 done < $PACKAGE/files.list
1025 MSG="Missing dependencies for $PACKAGE $VERSION :\n"
1026 for i in $DEPENDS; do
1027 [ -d $i ] && continue
1028 echo -e "$MSG $i"
1029 MSG=""
1030 done
1031 done
1032 echo "Check completed."
1033 ;;
1034 block)
1035 # Add a pkg name to the list of blocked packages.
1037 check_root
1038 check_for_package_on_cmdline
1039 echo ""
1040 if grep -q "^$PACKAGE" $BLOCKED; then
1041 echo "$PACKAGE is already in the blocked packages list."
1042 echo ""
1043 exit 0
1044 else
1045 echo -n "Add $PACKAGE to : $BLOCKED..."
1046 echo $PACKAGE >> $BLOCKED
1047 status
1048 fi
1049 echo ""
1050 ;;
1051 unblock)
1052 # Remove a pkg name to the list of blocked packages.
1054 check_root
1055 check_for_package_on_cmdline
1056 echo ""
1057 if grep -q "^$PACKAGE" $BLOCKED; then
1058 echo -n "Removing $PACKAGE from : $BLOCKED..."
1059 sed -i s/$PACKAGE/''/ $BLOCKED
1060 sed -i '/^$/d' $BLOCKED
1061 status
1062 else
1063 echo "$PACKAGE is not in the blocked packages list."
1064 echo ""
1065 exit 0
1066 fi
1067 echo ""
1068 ;;
1069 get)
1070 # Downlowd a package with wget.
1072 check_for_package_on_cmdline
1073 check_for_packages_list
1074 check_for_package_in_list
1075 echo ""
1076 download $PACKAGE.tazpkg
1077 echo ""
1078 ;;
1079 get-install)
1080 # Download and install a package.
1082 check_root
1083 check_for_package_on_cmdline
1084 check_for_packages_list
1085 check_for_package_in_list
1086 # Check if forced install.
1087 if [ "$3" = "--forced" ]; then
1088 rm -f $CACHE_DIR/$PACKAGE.tazpkg
1089 else
1090 check_for_installed_package
1091 fi
1092 cd $CACHE_DIR
1093 if [ -f "$PACKAGE.tazpkg" ]; then
1094 echo "$PACKAGE already in the cache : $CACHE_DIR"
1095 else
1096 echo ""
1097 download $PACKAGE.tazpkg
1098 fi
1099 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
1100 install_package
1101 check_for_deps
1102 if [ ! "$MISSING_PACKAGE" = "" ]; then
1103 install_deps
1104 fi
1105 ;;
1106 clean-cache)
1107 # Remove all downloaded packages.
1109 check_root
1110 files=`ls -1 $CACHE_DIR | wc -l`
1111 echo ""
1112 echo -e "\033[1mCleaning cache directory :\033[0m $CACHE_DIR"
1113 echo "================================================================================"
1114 rm -rf $CACHE_DIR/*
1115 echo "$files file(s) removed from cache."
1116 echo ""
1117 ;;
1118 setup-mirror)
1119 # Change mirror URL.
1121 check_root
1122 # Backup old list.
1123 if [ -f "$LOCALSTATE/mirror" ]; then
1124 cp -f $LOCALSTATE/mirror $LOCALSTATE/mirror.bak
1125 fi
1126 echo ""
1127 echo -e "\033[1mCurrent mirror(s)\033[0m"
1128 echo "================================================================================"
1129 echo " `cat $MIRROR`"
1130 echo "
1131 Please enter URL of the new mirror (http or ftp). You must specify the complet
1132 address to the directory of the packages and packages.list file."
1133 echo ""
1134 echo -n "New mirror URL : "
1135 read NEW_MIRROR_URL
1136 if [ "$NEW_MIRROR_URL" = "" ]; then
1137 echo "Nothing as been change."
1138 else
1139 echo "Setting mirror(s) to : $NEW_MIRROR_URL"
1140 echo "$NEW_MIRROR_URL" > $LOCALSTATE/mirror
1141 fi
1142 echo ""
1143 ;;
1144 usage|*)
1145 # Print a short help or give usage for an unknow or empty command.
1147 usage
1148 ;;
1149 esac
1151 exit 0