tazpkg view tazpkg @ rev 115

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