tazpkg view tazpkg @ rev 163

Check modifiers during remove
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Oct 15 17:27:44 2008 +0000 (2008-10-15)
parents bfbd3b3a28b4
children 47471c0125a2
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 [ -f $i/receipt ] || continue
1058 DEPENDS=""
1059 . $INSTALLED/$i/receipt
1060 case " $(echo $DEPENDS) " in
1061 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
1062 esac
1063 done
1064 EXTRAVERSION=""
1065 . $INSTALLED/$THE_PACKAGE/receipt
1066 fi
1067 echo ""
1068 if [ -n "$ALTERED" ]; then
1069 echo "The following packages depend on $PACKAGE :"
1070 for i in $ALTERED; do
1071 echo " $i"
1072 done
1073 fi
1074 REFRESH=$(cd $INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1075 if [ -n "$REFRESH" ]; then
1076 echo "The following packages have been modified $PACKAGE :"
1077 for i in $REFRESH; do
1078 echo " $i"
1079 done
1080 fi
1081 echo "Remove $PACKAGE ($VERSION$EXTRAVERSION) ?"
1082 echo -n "Please confirm uninstallation (y/N) : "; read anser
1083 if [ "$anser" = "y" ]; then
1084 echo ""
1085 echo -e "\033[1mRemoving :\033[0m $PACKAGE"
1086 echo "================================================================================"
1087 # Pre remove commands.
1088 if grep -q ^pre_remove $INSTALLED/$PACKAGE/receipt; then
1089 pre_remove
1090 fi
1091 echo -n "Removing all files installed..."
1092 for file in `cat $INSTALLED/$PACKAGE/files.list`
1093 do
1094 [ $(grep ^$file$ $INSTALLED/*/files.list | wc -l) -gt 1 ] && continue
1095 rm -rf $file 2>/dev/null
1096 done
1097 status
1098 if grep -q ^post_remove $INSTALLED/$PACKAGE/receipt; then
1099 post_remove
1100 fi
1101 # Remove package receipt.
1102 echo -n "Removing package receipt..."
1103 rm -rf $INSTALLED/$PACKAGE
1104 status
1105 if [ -n "$ALTERED" ]; then
1106 echo -n "Remove packages depending on $PACKAGE"
1107 echo -n " (y/N) ? "; read anser
1108 if [ "$anser" = "y" ]; then
1109 for i in $ALTERED; do
1110 if [ -d "$INSTALLED/$i" ]; then
1111 tazpkg remove $i
1112 fi
1113 done
1114 fi
1115 fi
1116 if [ -n "$REFRESH" ]; then
1117 echo -n "Reinstall packages modified by $PACKAGE"
1118 echo -n " (y/N) ? "; read anser
1119 if [ "$anser" = "y" ]; then
1120 for i in $REFRESH; do
1121 if [ $(wc -l $INSTALLED/$i/modifiers) -gt 1 ]; then
1122 echo "Check $INSTALLED/$i/modifiers for reinstallation"
1123 continue
1124 fi
1125 rm -r $INSTALLED/$i/modifiers
1126 tazpkg get-install $i --forced
1127 done
1128 fi
1129 fi
1130 else
1131 echo ""
1132 echo "Uninstallation of $PACKAGE cancelled."
1133 fi
1134 echo ""
1135 ;;
1136 extract)
1137 # Extract .tazpkg cpio archive into a directory.
1139 check_for_package_on_cmdline
1140 check_for_package_file
1141 echo ""
1142 echo -e "\033[1mExtracting :\033[0m $PACKAGE"
1143 echo "================================================================================"
1144 # If no directory destination is found on the cmdline
1145 # we create one in the current dir using the package name.
1146 if [ -n "$TARGET_DIR" ]; then
1147 DESTDIR=$TARGET_DIR/$PACKAGE
1148 else
1149 DESTDIR=$PACKAGE
1150 fi
1151 mkdir -p $DESTDIR
1152 echo -n "Copying original package..."
1153 cp $PACKAGE_FILE $DESTDIR
1154 status
1155 cd $DESTDIR
1156 extract_package
1157 echo "================================================================================"
1158 echo "$PACKAGE is extracted to : $DESTDIR"
1159 echo ""
1160 ;;
1161 list-config)
1162 # List configuration files installed.
1164 if [ "$2" = "--box" ]; then
1165 mkdir -p $TMP_DIR && cd $TMP_DIR
1166 for i in $INSTALLED/*/volatile.cpio.gz; do
1167 zcat $i | cpio -id > /dev/null
1168 find * -type f | while read file; do
1169 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
1170 cmp $file /$file > /dev/null 2>&1 || \
1171 echo -n "$(stat -c "%.16y" /$file)"
1172 echo "|/$file"
1173 done
1174 rm -rf *
1175 done
1176 cd $TOP_DIR
1177 rm -rf $TMP_DIR
1178 else
1179 echo ""
1180 echo -e "\033[1mConfiguration files"
1181 echo "================================================================================"
1182 for i in $INSTALLED/*/volatile.cpio.gz; do
1183 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
1184 [ -f "$i" ] || continue
1185 zcat $i | cpio -t | grep -v "[0-9]* blocks"
1186 done | sed 's|^|/|' | sort
1187 echo "================================================================================"
1188 echo ""
1189 fi
1190 ;;
1191 repack-config)
1192 # Create SliTaz package archive from configuration files.
1194 mkdir -p $TMP_DIR && cd $TMP_DIR
1195 CONFIG_VERSION=1.0
1196 mkdir config-$CONFIG_VERSION
1197 cd config-$CONFIG_VERSION
1198 for i in $INSTALLED/*/volatile.cpio.gz; do
1199 zcat $i | cpio -t | grep -v "[0-9]* blocks"
1200 done > files.list
1201 mkdir fs
1202 cd fs
1203 ( cd / ; cpio -o -H newc ) < ../files.list | cpio -id > /dev/null
1204 mkdir -p etc/tazlito
1205 for i in $INSTALLED/*/receipt; do
1206 EXTRAVERSION=""
1207 . $i
1208 echo "$PACKAGE-$VERSION$EXTRAVERSION"
1209 done > etc/tazlito/config-packages.list
1210 cd ..
1211 echo "etc/tazlito/config-packages.list" >> files.list
1212 cat > receipt <<EOT
1213 # SliTaz package receipt.
1215 PACKAGE="config"
1216 VERSION="$CONFIG_VERSION"
1217 CATEGORY="base-system"
1218 SHORT_DESC="User configuration backup on $(date)"
1219 DEPENDS="$(ls $INSTALLED)"
1220 EOT
1221 cd ..
1222 tazpkg pack config-$CONFIG_VERSION
1223 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
1224 cd $TOP_DIR
1225 rm -rf $TMP_DIR
1226 ;;
1227 repack)
1228 # Create SliTaz package archive from an installed package.
1230 check_for_package_on_cmdline
1231 check_for_receipt
1232 EXTRAVERSION=""
1233 . $INSTALLED/$PACKAGE/receipt
1234 echo ""
1235 echo -e "\033[1mRepacking :\033[0m $PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
1236 echo "================================================================================"
1237 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
1238 echo "Can't repack $PACKAGE"
1239 exit 1
1240 fi
1241 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
1242 echo "Can't repack, $PACKAGE files have been modified by:"
1243 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
1244 echo " $i"
1245 done
1246 exit 1
1247 fi
1248 MISSING=""
1249 while read i; do
1250 [ -e "$i" ] && continue
1251 [ -L "$i" ] || MISSING="$MISSING\n $i"
1252 done < $INSTALLED/$PACKAGE/files.list
1253 if [ -n "$MISSING" ]; then
1254 echo -n "Can't repack, the following files are lost:"
1255 echo -e "$MISSING"
1256 exit 1
1257 fi
1258 mkdir -p $TMP_DIR && cd $TMP_DIR
1259 FILES="fs.cpio.gz\n"
1260 for i in $(ls $INSTALLED/$PACKAGE) ; do
1261 [ "$i" = "volatile.cpio.gz" ] && continue
1262 [ "$i" = "modifiers" ] && continue
1263 cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
1264 done
1265 ln -s / rootfs
1266 mkdir tmp
1267 sed 's/^/rootfs/' < files.list | cpio -o -H newc 2>/dev/null |\
1268 ( cd tmp ; cpio -id 2>/dev/null )
1269 mv tmp/rootfs fs
1270 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
1271 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
1272 ( cd fs; cpio -id )
1273 fi
1274 if grep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
1275 . $INSTALLED/$PACKAGE/receipt
1276 repack_cleanup fs
1277 fi
1278 if [ -f $INSTALLED/$PACKAGE/md5sum ]; then
1279 sed 's, , fs,' < $INSTALLED/$PACKAGE/md5sum | \
1280 if ! md5sum -s -c; then
1281 echo -n "Can't repack, md5sum error."
1282 cd $TOP_DIR
1283 \rm -R $TMP_DIR
1284 exit 1
1285 fi
1286 fi
1287 find fs | cpio -o -H newc 2> /dev/null | gzip -9 > fs.cpio.gz
1288 echo -e "$FILES" | cpio -o -H newc 2> /dev/null > \
1289 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1290 cd $TOP_DIR
1291 \rm -R $TMP_DIR
1292 echo "Package $PACKAGE repacked successfully."
1293 echo "Size : `du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
1294 echo ""
1295 ;;
1296 pack)
1297 # Create SliTaz package archive using cpio and gzip.
1299 check_for_package_on_cmdline
1300 cd $PACKAGE
1301 if [ ! -f "receipt" ]; then
1302 echo "Receipt is missing. Please read the documentation."
1303 exit 0
1304 else
1305 echo ""
1306 echo -e "\033[1mPacking :\033[0m $PACKAGE"
1307 echo "================================================================================"
1308 # Create files.list with redirecting find outpout.
1309 echo -n "Creating the list of files..." && cd fs
1310 find . -type f -print > ../files.list
1311 find . -type l -print >> ../files.list
1312 cd .. && sed -i s/'^.'/''/ files.list
1313 status
1314 echo -n "Creating md5sum of files..."
1315 while read file; do
1316 [ -L "fs$file" ] && continue
1317 [ -f "fs$file" ] || continue
1318 case "$file" in
1319 /lib/modules/*/modules.*|*.pyc) continue;;
1320 esac
1321 md5sum "fs$file" | sed 's/ fs/ /'
1322 done < files.list > md5sum
1323 status
1324 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
1325 description.txt 2> /dev/null | awk \
1326 '{ sz=$1 } END { print sz }')
1327 # Build cpio archives.
1328 echo -n "Compressing the fs... "
1329 find fs -print | cpio -o -H newc | gzip > fs.cpio.gz
1330 rm -rf fs
1331 status
1332 PACKED_SIZE=$(du -chs fs.cpio.gz receipt files.list \
1333 md5sum description.txt 2> /dev/null | awk \
1334 '{ sz=$1 } END { print sz }')
1335 echo -n "Undating receipt sizes..."
1336 sed -i s/^PACKED_SIZE.*$// receipt
1337 sed -i s/^UNPACKED_SIZE.*$// receipt
1338 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1339 status
1340 echo -n "Creating full cpio archive... "
1341 find . -print | cpio -o -H newc > ../$PACKAGE.tazpkg
1342 status
1343 echo -n "Restoring original package tree... "
1344 zcat fs.cpio.gz | cpio -id
1345 status
1346 rm fs.cpio.gz && cd ..
1347 echo "================================================================================"
1348 echo "Package $PACKAGE compressed successfully."
1349 echo "Size : `du -sh $PACKAGE.tazpkg`"
1350 echo ""
1351 fi
1352 ;;
1353 recharge)
1354 # Recharge packages.list from a mirror.
1356 check_root
1357 cd $LOCALSTATE
1358 echo ""
1359 if [ -f "$LOCALSTATE/packages.list" ]; then
1360 echo -n "Creating backup of the last packages list..."
1361 mv -f packages.desc packages.desc.bak 2>/dev/null
1362 mv -f packages.txt packages.txt.bak 2>/dev/null
1363 mv -f packages.list packages.list.bak 2>/dev/null
1364 mv -f files.list.lzma files.list.lzma.bak 2> /dev/nul
1365 status
1366 fi
1367 download packages.desc
1368 download packages.txt
1369 download packages.list
1370 download files.list.lzma
1371 if [ -f "$LOCALSTATE/packages.list.bak" ]; then
1372 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
1373 sed -i s/+// packages.diff
1374 echo ""
1375 echo -e "\033[1mMirrored packages diff\033[0m"
1376 echo "================================================================================"
1377 cat packages.diff
1378 if [ ! "`cat packages.diff | wc -l`" = 0 ]; then
1379 echo "================================================================================"
1380 echo "`cat packages.diff | wc -l` new packages on the mirror."
1381 echo ""
1382 else
1383 echo "`cat packages.diff | wc -l` new packages on the mirror."
1384 echo ""
1385 fi
1386 else
1387 echo -e "
1388 ================================================================================
1389 Last packages.list is ready to use. Note that next time you recharge the list,
1390 a list of differencies will be displayed to show new and upgradeable packages.\n"
1391 fi
1392 ;;
1393 upgrade)
1394 # Upgrade all installed packages with the new version from the mirror.
1396 check_root
1397 check_for_packages_list
1398 cd $LOCALSTATE
1399 # Touch the blocked pkgs list to avoid errors and remove any old
1400 # upgrade list.
1401 touch blocked-packages.list
1402 rm -f upgradeable-packages.list
1403 echo ""
1404 echo -e "\033[1mAvailable upgrades\033[0m"
1405 echo "================================================================================"
1406 echo ""
1407 # Some packages must be installed first
1408 FIRST_CLASS_PACKAGE=" glibc-base slitaz-base-files slitaz-boot-scripts "
1409 for pkg in $INSTALLED/*
1410 do
1411 [ -f $pkg/receipt ] || continue
1412 EXTRAVERSION=""
1413 . $pkg/receipt
1414 # Display package name to show that Tazpkg is working...
1415 echo -en "\\033[0G "
1416 echo -en "\\033[0G$PACKAGE"
1417 # Skip specified pkgs listed in $LOCALSTATE/blocked-packages.list
1418 if grep -q "^$PACKAGE" $BLOCKED; then
1419 blocked=$(($blocked+1))
1420 else
1421 # Check if the installed package is in the current list (other
1422 # mirror or local).
1423 NEW_PACKAGE=$(grep "^$PACKAGE-[0-9]" packages.list | head -1)
1424 [ -n "$NEW_PACKAGE" ] || NEW_PACKAGE=$(grep "^$PACKAGE-.[\.0-9]" packages.list | head -1)
1426 if [ -n "$NEW_PACKAGE" ]; then
1427 # Set new pkg and version for futur comparaison
1428 NEW_VERSION=`echo $NEW_PACKAGE | sed s/$PACKAGE-/''/`
1429 # Change '-' and 'pre' to points.
1430 NEW_VERSION=`echo $NEW_VERSION | sed s/'-'/'.'/`
1431 VERSION=`echo $VERSION | sed s/'-'/'.'/`$EXTRAVERSION
1432 NEW_VERSION=`echo $NEW_VERSION | sed s/'pre'/'.'/`
1433 VERSION=`echo $VERSION | sed s/'pre'/'.'/`
1434 NEW_VERSION=`echo $NEW_VERSION | sed 's/[A-Z]\.//'`
1435 VERSION=`echo $VERSION | sed 's/[A-Z]\.//'`
1436 # Compare version. Upgrade are only available for official
1437 # packages, so we control de mirror and it should be ok if
1438 # we just check for egality.
1439 if [ "$VERSION" != "$NEW_VERSION" ]; then
1440 # Version seems different. Check for major, minor or
1441 # revision
1442 PKG_MAJOR=`echo ${VERSION%_*} | cut -f1 -d"."`
1443 NEW_MAJOR=`echo ${NEW_VERSION%_*} | cut -f1 -d"."`
1444 PKG_MINOR=`echo ${VERSION%_*} | cut -f2 -d"."`
1445 NEW_MINOR=`echo ${NEW_VERSION%_*} | cut -f2 -d"."`
1446 # Minor
1447 if [ "$NEW_MINOR" -gt "$PKG_MINOR" ]; then
1448 RELEASE=minor
1449 fi
1450 if [ "$NEW_MINOR" -lt "$PKG_MINOR" ]; then
1451 RELEASE=$WARNING
1452 FIXE=yes
1453 fi
1454 # Major
1455 if [ "$NEW_MAJOR" -gt "$PKG_MAJOR" ]; then
1456 RELEASE=major
1457 FIXE=""
1458 fi
1459 if [ "$NEW_MAJOR" -lt "$PKG_MAJOR" ]; then
1460 RELEASE=$WARNING
1461 FIXE=yes
1462 fi
1463 # Default to revision.
1464 if [ -z $RELEASE ]; then
1465 RELEASE=revision
1466 fi
1467 # Pkg name is already displayed by the check process.
1468 echo -en "\033[24G $VERSION"
1469 echo -en "\033[38G --->"
1470 echo -en "\033[43G $NEW_VERSION"
1471 echo -en "\033[58G $CATEGORY"
1472 echo -e "\033[72G $RELEASE"
1473 up=$(($up+1))
1474 echo "$PACKAGE" >> upgradeable-packages.list
1475 case "$FIRST_CLASS_PACKAGE" in
1476 *\ $PACKAGE\ *) echo "$PACKAGE" >> upgradeable-packages.list$$;;
1477 esac
1478 unset RELEASE
1479 fi
1480 packages=$(($packages+1))
1481 fi
1482 fi
1483 done
1484 if [ -z $blocked ]; then
1485 blocked=0
1486 fi
1487 # Clean last checked package and display summary.
1488 if [ ! "$up" = "" ]; then
1489 echo -e "\\033[0G "
1490 echo "================================================================================"
1491 echo "$packages installed and listed packages to consider, $up to upgrade, $blocked blocked."
1492 echo ""
1493 else
1494 echo -e "\\033[0GSystem is up-to-date. "
1495 echo ""
1496 echo "================================================================================"
1497 echo "$packages installed and listed packages to consider, 0 to upgrade, $blocked blocked."
1498 echo ""
1499 exit 0
1500 fi
1501 # What to do if major or minor version is smaller.
1502 if [ "$FIXE" == "yes" ]; then
1503 echo -e "$WARNING ---> Installed package seems more recent than the mirrored one."
1504 echo "You can block packages using the command : 'tazpkg block package'"
1505 echo "Or upgrade package at you own risks."
1506 echo ""
1507 fi
1508 # Ask for upgrade, it can be done another time.
1509 echo -n "Upgrade now (y/N) ? "; read anser
1510 if [ ! "$anser" = "y" ]; then
1511 echo -e "\nExiting. No package upgraded.\n"
1512 exit 0
1513 fi
1514 # If anser is yes (y). Install all new versions.
1515 cat upgradeable-packages.list >> upgradeable-packages.list$$
1516 mv -f upgradeable-packages.list$$ upgradeable-packages.list
1517 yes y | tazpkg get-install-list upgradeable-packages.list
1518 #rm -f upgradeable-packages.list
1519 ;;
1520 bugs)
1521 # Show known bugs in package(s)
1523 cd $INSTALLED
1524 shift
1525 LIST=$@
1526 [ -n "$LIST" ] || LIST=`ls`
1527 MSG="No known bugs."
1528 for PACKAGE in $LIST; do
1529 BUGS=""
1530 EXTRAVERSION=""
1531 . $PACKAGE/receipt
1532 if [ -n "$BUGS" ]; then
1533 MSG="
1534 Bug list completed"
1535 cat <<EOT
1537 Bugs in package $PACKAGE version $VERSION$EXTRAVERSION:
1538 $BUGS
1539 EOT
1540 fi
1541 done
1542 echo "$MSG"
1543 ;;
1544 check)
1545 # Check installed packages set.
1547 check_root
1548 cd $INSTALLED
1549 for PACKAGE in `ls`; do
1550 if [ ! -f $PACKAGE/receipt ]; then
1551 echo "The package $PACKAGE installation is not completed"
1552 continue
1553 fi
1554 DEPENDS=""
1555 EXTRAVERSION=""
1556 . $PACKAGE/receipt
1557 if [ -s $PACKAGE/modifiers ]; then
1558 echo "The package $PACKAGE $VERSION$EXTRAVERSION has been modified by :"
1559 for i in $(cat $PACKAGE/modifiers); do
1560 echo " $i"
1561 done
1562 fi
1563 MSG="Files lost from $PACKAGE $VERSION$EXTRAVERSION :\n"
1564 while read file; do
1565 [ -e "$file" ] && continue
1566 if [ -L "$file" ]; then
1567 MSG="$MSG target of symlink"
1568 fi
1569 echo -e "$MSG $file"
1570 MSG=""
1571 done < $PACKAGE/files.list
1572 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n"
1573 for i in $DEPENDS; do
1574 [ -d $i ] && continue
1575 echo -e "$MSG $i"
1576 MSG=""
1577 done
1578 MSG="Dependencies loop between $PACKAGE and :\n"
1579 ALL_DEPS=""
1580 check_for_deps_loop $PACKAGE $DEPENDS
1581 done
1582 echo -n "Looking for known bugs... "
1583 tazpkg bugs
1584 if [ "$PACKAGE_FILE" = "--full" ]; then
1585 for file in */md5sum; do
1586 [ -s "$file" ] || continue
1587 md5sum -c "$file" 2> /dev/null | grep -v OK$ |\
1588 sed 's/FAILED$/MD5SUM MISMATCH/'
1589 done
1590 FILES=" "
1591 for file in $(cat */files.list); do
1592 [ -d "$file" ] && continue
1593 case "$FILES" in *\ $file\ *) continue;; esac
1594 [ $(grep "^$file$" */files.list 2> /dev/null | \
1595 wc -l) -gt 1 ] || continue
1596 FILES="$FILES$file "
1597 echo "The following packages provide $file :"
1598 grep -l "^$file$" */files.list | while read f
1599 do
1600 pkg=${f%/files.list}
1601 echo -n " $pkg"
1602 if [ -f $pkg/modifiers ]; then
1603 echo -n " (overridden by $(echo "$(cat $pkg/modifiers)"))"
1604 fi
1605 echo ""
1606 done
1607 done
1608 MSG="No package has installed the following files:\n"
1609 find /etc /bin /sbin /lib /usr /var/www \
1610 -not -type d 2> /dev/null | while read file; do
1611 case "$file" in *\[*) continue;; esac
1612 grep -q "^$file$" */files.list && continue
1613 echo -e "$MSG $file"
1614 MSG=""
1615 done
1616 fi
1617 echo "Check completed."
1618 ;;
1619 block)
1620 # Add a pkg name to the list of blocked packages.
1622 check_root
1623 check_for_package_on_cmdline
1624 echo ""
1625 if grep -q "^$PACKAGE" $BLOCKED; then
1626 echo "$PACKAGE is already in the blocked packages list."
1627 echo ""
1628 exit 0
1629 else
1630 echo -n "Add $PACKAGE to : $BLOCKED..."
1631 echo $PACKAGE >> $BLOCKED
1632 status
1633 fi
1634 echo ""
1635 ;;
1636 unblock)
1637 # Remove a pkg name from the list of blocked packages.
1639 check_root
1640 check_for_package_on_cmdline
1641 echo ""
1642 if grep -q "^$PACKAGE" $BLOCKED; then
1643 echo -n "Removing $PACKAGE from : $BLOCKED..."
1644 sed -i s/$PACKAGE/''/ $BLOCKED
1645 sed -i '/^$/d' $BLOCKED
1646 status
1647 else
1648 echo "$PACKAGE is not in the blocked packages list."
1649 echo ""
1650 exit 0
1651 fi
1652 echo ""
1653 ;;
1654 get)
1655 # Downlowd a package with wget.
1657 check_for_package_on_cmdline
1658 check_for_packages_list
1659 check_for_package_in_list
1660 echo ""
1661 download $PACKAGE.tazpkg
1662 echo ""
1663 ;;
1664 get-install)
1665 # Download and install a package.
1667 check_root
1668 check_for_package_on_cmdline
1669 check_for_packages_list
1670 check_for_package_in_list
1671 DO_CHECK=""
1672 while [ -n "$3" ]; do
1673 case "$3" in
1674 --forced)
1675 DO_CHECK="no"
1676 ;;
1677 --root=*)
1678 ROOT="${3#--root=}"
1679 ;;
1680 --list=*)
1681 INSTALL_LIST="${3#--list=}"
1682 ;;
1683 *) shift 2
1684 echo -e "\nUnknown option $*.\n"
1685 exit 1
1686 ;;
1687 esac
1688 shift
1689 done
1690 # Check if forced install.
1691 if [ "$DO_CHECK" = "no" ]; then
1692 rm -f $CACHE_DIR/$PACKAGE.tazpkg
1693 else
1694 check_for_installed_package $ROOT
1695 fi
1696 cd $CACHE_DIR
1697 if [ -f "$PACKAGE.tazpkg" ]; then
1698 echo "$PACKAGE already in the cache : $CACHE_DIR"
1699 # Check package download was finished
1700 tail -c 2k $PACKAGE.tazpkg | grep -q 00000000TRAILER || {
1701 echo "Continue $PACKAGE download"
1702 download $PACKAGE.tazpkg
1704 else
1705 echo ""
1706 download $PACKAGE.tazpkg
1707 fi
1708 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
1709 install_package $ROOT
1710 ;;
1711 clean-cache)
1712 # Remove all downloaded packages.
1714 check_root
1715 files=`ls -1 $CACHE_DIR | wc -l`
1716 echo ""
1717 echo -e "\033[1mClean cache :\033[0m $CACHE_DIR"
1718 echo "================================================================================"
1719 echo -n "Cleaning cache directory..."
1720 rm -rf $CACHE_DIR/*
1721 status
1722 echo "================================================================================"
1723 echo "$files file(s) removed from cache."
1724 echo ""
1725 ;;
1726 setup-mirror)
1727 # Change mirror URL.
1729 check_root
1730 # Backup old list.
1731 if [ -f "$LOCALSTATE/mirror" ]; then
1732 cp -f $LOCALSTATE/mirror $LOCALSTATE/mirror.bak
1733 fi
1734 echo ""
1735 echo -e "\033[1mCurrent mirror(s)\033[0m"
1736 echo "================================================================================"
1737 echo " `cat $MIRROR`"
1738 echo "
1739 Please enter URL of the new mirror (http or ftp). You must specify the complete
1740 address to the directory of the packages and packages.list file."
1741 echo ""
1742 echo -n "New mirror URL : "
1743 read NEW_MIRROR_URL
1744 if [ "$NEW_MIRROR_URL" = "" ]; then
1745 echo "Nothing has been changed."
1746 else
1747 echo "Setting mirror(s) to : $NEW_MIRROR_URL"
1748 echo "$NEW_MIRROR_URL" > $LOCALSTATE/mirror
1749 fi
1750 echo ""
1751 ;;
1752 reconfigure)
1753 # Replay post_install from receipt
1755 check_for_package_on_cmdline
1756 check_root
1757 if [ -d "$INSTALLED/$PACKAGE" ]; then
1758 check_for_receipt
1759 # Check for post_install
1760 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
1761 . $INSTALLED/$PACKAGE/receipt
1762 post_install
1763 else
1764 echo -e "\nNothing to do for $PACKAGE."
1765 fi
1766 else
1767 echo -e "\npackage $PACKAGE is not installed."
1768 echo -e "Install package with 'tazpkg install' or 'tazpkg get-install'\n"
1769 fi
1770 ;;
1771 shell)
1772 # Tazpkg SHell
1774 if test $(id -u) = 0 ; then
1775 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
1776 else
1777 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
1778 fi
1779 if [ ! "$2" = "--noheader" ]; then
1780 clear
1781 echo ""
1782 echo -e "\033[1mTazpkg SHell.\033[0m"
1783 echo "================================================================================"
1784 echo "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
1785 echo ""
1786 fi
1787 while true
1788 do
1789 echo -en "$PROMPT"; read cmd
1790 case $cmd in
1791 q|quit)
1792 break ;;
1793 shell)
1794 echo "You are already running a Tazpkg SHell." ;;
1795 su)
1796 su -c 'exec tazpkg shell --noheader' && break ;;
1797 "")
1798 continue ;;
1799 *)
1800 tazpkg $cmd ;;
1801 esac
1802 done
1803 ;;
1804 usage|*)
1805 # Print a short help or give usage for an unknown or empty command.
1807 usage
1808 ;;
1809 esac
1811 exit 0