tazpkg view tazpkg @ rev 155

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