tazpkg view tazpkg @ rev 125

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