tazpkg view tazpkg @ rev 71

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