tazpkg view tazpkg @ rev 148

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