tazpkg view tazpkg @ rev 162

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