tazpkg view tazpkg @ rev 144

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