tazpkg view tazpkg @ rev 251

Speedup tazpkg remove
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Apr 01 11:50:53 2009 +0000 (2009-04-01)
parents 63f4f0e413e1
children 504335627f00
line source
1 #!/bin/sh
2 # Tazpkg - Tiny autonomous 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.6.1
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 BLOCKED=$LOCALSTATE/blocked-packages.list
60 DEFAULT_MIRROR="http://mirror.slitaz.org/packages/`cat /etc/slitaz-release`/"
61 INSTALL_LIST=""
62 LOG=/var/log/tazpkg.log
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 depends Display dependencies tree.
122 rdepends Display reverse dependencies tree.
123 setup-mirror Change the mirror url configuration.
124 list-undigest List undigest mirrors.
125 remove-undigest Remove an undigest mirror.
126 add-undigest Add an undigest mirror.
127 setup-undigest Update an undigest mirror.
128 reconfigure Replay post install script from package."
129 }
131 # Status function with color (supported by Ash).
132 status()
133 {
134 local CHECK=$?
135 echo -en "\\033[70G[ "
136 if [ $CHECK = 0 ]; then
137 echo -en "\\033[1;33mOK"
138 else
139 echo -en "\\033[1;31mFailed"
140 fi
141 echo -e "\\033[0;39m ]"
142 return $CHECK
143 }
145 # Check if user is root to install, or remove packages.
146 check_root()
147 {
148 if test $(id -u) != 0 ; then
149 echo -e "\nYou must be root to run `basename $0` with this option."
150 echo -e "Please use 'su' and root password to become super-user.\n"
151 exit 0
152 fi
153 }
155 # Check for a package name on cmdline.
156 check_for_package_on_cmdline()
157 {
158 if [ -z "$PACKAGE" ]; then
159 echo -e "\nPlease specify a package name on the command line.\n"
160 exit 0
161 fi
162 }
164 # Check if the package (*.tazpkg) exist before installing or extracting.
165 check_for_package_file()
166 {
167 if [ ! -f "$PACKAGE_FILE" ]; then
168 echo -e "
169 Unable to find : $PACKAGE_FILE\n"
170 exit 0
171 fi
172 }
174 # Check for the receipt of an installed package.
175 check_for_receipt()
176 {
177 if [ ! -f "$1$INSTALLED/$PACKAGE/receipt" ]; then
178 echo -e "\nUnable to find the receipt : $1$INSTALLED/$PACKAGE/receipt\n"
179 exit 0
180 fi
181 }
183 # Get package name in a directory
184 package_fullname_in_dir()
185 {
186 [ -f $2$1/receipt ] || return
187 EXTRAVERSION=""
188 . $2$1/receipt
189 echo $PACKAGE-$VERSION$EXTRAVERSION
190 }
192 # Get package name that is already installed.
193 get_installed_package_pathname()
194 {
195 for i in $2$INSTALLED/${1%%-*}*; do
196 [ -d $i ] || continue
197 if [ "$1" = "$(package_fullname_in_dir $i $2)" ]; then
198 echo $i
199 return
200 fi
201 done
202 }
204 # Check if a package is already installed.
205 check_for_installed_package()
206 {
207 if [ -n "$(get_installed_package_pathname $PACKAGE $1)" ]; then
208 echo -e "
209 $PACKAGE is already installed. You can use the --forced option to force
210 installation or remove it and reinstall.\n"
211 exit 0
212 fi
213 }
215 # Check for packages.list to download and install packages.
216 check_for_packages_list()
217 {
218 if [ ! -f "$LOCALSTATE/packages.list" ]; then
219 if test $(id -u) = 0 ; then
220 tazpkg recharge
221 else
222 echo -e "
223 Unable to find the list : $LOCALSTATE/packages.list\n
224 You should probably run 'tazpkg recharge' as root to get the latest list of
225 packages available on the mirror.\n"
226 exit 0
227 fi
228 fi
229 }
231 # get package from packages.equiv
232 equivalent_pkg()
233 {
234 for i in $(grep -hs "^$1=" $LOCALSTATE/packages.equiv \
235 $LOCALSTATE/undigest/*/packages.equiv | sed "s/^$1=//"); do
236 if echo $i | grep -q : ; then
237 # format 'alternative:newname'
238 # if alternative is installed then substitute newname
239 if [ -f $2$INSTALLED/${i%:*}/receipt ]; then
240 # substitute package dependancy
241 echo ${i#*:}
242 return
243 fi
244 else
245 # if alternative is installed then nothing to install
246 if [ -f $2$INSTALLED/$i/receipt ]; then
247 # substitute installed package
248 echo $i
249 return
250 fi
251 fi
252 done
253 # if not found in packages.equiv then no substitution
254 echo $1
255 }
257 # Get package filename available on the mirror
258 get_package_filename()
259 {
260 local pkg
261 pkg=$(grep -A 1 -sh "^$1$" $LOCALSTATE/packages.txt \
262 $LOCALSTATE/undigest/*/packages.txt | tail -1)
263 pkg=$(echo $pkg)
264 [ -n "$pkg" ] && pkg=$(grep -sh "^$1-$pkg" \
265 $LOCALSTATE/packages.list \
266 $LOCALSTATE/undigest/*/packages.list | head -1)
267 [ -n "$pkg" ] || pkg=$(grep -sh "^$1-[0-9]" \
268 $LOCALSTATE/packages.list \
269 $LOCALSTATE/undigest/*/packages.list | head -1)
270 [ -n "$pkg" ] || pkg=$(grep -sh "^$1-.[\.0-9]" \
271 $LOCALSTATE/packages.list \
272 $LOCALSTATE/undigest/*/packages.list | head -1)
273 if [ -z "$pkg" ]; then
274 # Check for vitual package
275 local equiv
276 equiv=$(equivalent_pkg $1 virtual)
277 if [ "$equiv" != "$1" ]; then
278 PACKAGE=$equiv
279 get_package_filename $PACKAGE
280 return
281 fi
282 fi
283 echo $pkg
284 }
286 # Check for a package in packages.list. Used by get and get-install to grep
287 # package basename.
288 check_for_package_in_list()
289 {
290 local filename
291 local check_only
292 check_only="$1"
293 filename=$(get_package_filename $PACKAGE)
294 if [ -n "$filename" ]; then
295 PACKAGE=$filename
296 else
297 echo -e "\nUnable to find : $PACKAGE in the mirrored packages list.\n"
298 [ -n "$check_only" ] && return 1
299 exit 0
300 fi
301 }
303 # Log this activity
304 log()
305 {
306 local extra
307 [ "$1" = "Installed" ] && \
308 extra=" - $(grep $PACKAGE-$VERSION $LOCALSTATE/installed.md5 | awk '{ print $1 }')"
309 [ -e $LOG ] || touch $LOG
310 DATE=`date +'%F %T'`
311 [ -w $LOG ] &&
312 echo "$DATE - $1 - $PACKAGE ($VERSION$EXTRAVERSION)$extra" >> $LOG
313 }
315 # Download a file from this mirror
316 download_from()
317 {
318 local i
319 local mirrors
320 mirrors="$1"
321 shift
322 for i in $mirrors; do
323 case "$i" in
324 http://*|ftp://*) wget -c $i$@ && break;;
325 *) cp $i/$1 . && break;;
326 esac
327 done
328 }
330 # Download a file trying all mirrors
331 download()
332 {
333 local i
334 case "$1" in
335 *.tazpkg)
336 for i in $LOCALSTATE $LOCALSTATE/undigest/* ; do
337 grep "^${1%.tazpkg}$" $i/packages.list || continue
338 download_from "$(cat $i/mirror)" "$@" && return
339 done
340 esac
341 for i in $(cat $MIRROR $LOCALSTATE/undigest/*/mirror 2> /dev/null); do
342 download_from "$i" "$@" && break
343 done
344 }
346 # Extract a package with cpio and gzip.
347 extract_package()
348 {
349 echo -n "Extracting $PACKAGE... "
350 cpio -idm < $PACKAGE.tazpkg && rm -f $PACKAGE.tazpkg
351 echo -n "Extracting the pseudo fs... "
352 zcat fs.cpio.gz | cpio -idm && rm fs.cpio.gz
353 }
355 # This function installs a package in the rootfs.
356 install_package()
357 {
358 ROOT=$1
359 if [ -n "$ROOT" ]; then
360 # Get absolute path
361 ROOT=$(cd $ROOT; pwd)
362 fi
363 (
364 # Create package path early to avoid dependencies loop
365 mkdir -p $TMP_DIR
366 ( cd $TMP_DIR ; cpio -i receipt > /dev/null) < $PACKAGE_FILE
367 . $TMP_DIR/receipt
368 if grep -q ^pre_depends $TMP_DIR/receipt; then
369 pre_depends $ROOT
370 fi
371 # keep modifers list on upgrade
372 cp $ROOT$INSTALLED/$PACKAGE/modifiers $TMP_DIR 2> /dev/null
373 rm -rf $ROOT$INSTALLED/$PACKAGE 2> /dev/null
374 # Make the installed package data dir to store
375 # the receipt and the files list.
376 mkdir -p $ROOT$INSTALLED/$PACKAGE
377 cp $TMP_DIR/modifiers $ROOT$INSTALLED/$PACKAGE 2> /dev/null
378 rm -rf $TMP_DIR 2> /dev/null
379 sed -i "/ $(basename $PACKAGE_FILE)$/d" \
380 $ROOT$LOCALSTATE/installed.md5 2> /dev/null
381 cd $(dirname $PACKAGE_FILE)
382 md5sum $(basename $PACKAGE_FILE) >> $ROOT$LOCALSTATE/installed.md5
383 )
384 # Resolve package deps.
385 check_for_deps $ROOT
386 if [ ! "$MISSING_PACKAGE" = "" ]; then
387 install_deps $ROOT
388 fi
389 mkdir -p $TMP_DIR
390 [ -n "$INSTALL_LIST" ] && echo "$PACKAGE_FILE" >> $INSTALL_LIST-processed
391 echo ""
392 echo -e "\033[1mInstallation of :\033[0m $PACKAGE"
393 echo "================================================================================"
394 echo -n "Copying $PACKAGE... "
395 cp $PACKAGE_FILE $TMP_DIR
396 status
397 cd $TMP_DIR
398 extract_package
399 SELF_INSTALL=0
400 EXTRAVERSION=""
401 CONFIG_FILES=""
402 # Include temporary receipt to get the right variables.
403 . $PWD/receipt
404 if [ $SELF_INSTALL -ne 0 -a -n "$ROOT" ]; then
405 echo -n "Checking post install dependencies... "
406 [ -f $INSTALLED/$PACKAGE/receipt ]
407 if ! status; then
408 echo "Please run 'tazpkg install $PACKAGE_FILE' in / and retry."
409 cd .. && rm -rf $TMP_DIR
410 exit 1
411 fi
412 fi
413 # Remember modified packages
414 for i in $(grep -v '\[' files.list); do
415 [ -e "$ROOT$i" ] || continue
416 [ -d "$ROOT$i" ] && continue
417 for j in $(grep -l "^$i$" $ROOT$INSTALLED/*/files.list); do
418 local dir
419 dir=$(dirname $j)
420 [ "$j" = "$ROOT$INSTALLED/$PACKAGE/files.list" ] && continue
421 if grep -qs ^$(basename $dir)$ \
422 $ROOT$INSTALLED/$PACKAGE/modifiers; then
423 # Do not overload an overloaded file !
424 rm .$i 2> /dev/null
425 continue
426 fi
427 grep -qs ^$PACKAGE$ $dir/modifiers && continue
428 if [ -s "$dir/volatile.cpio.gz" ]; then
429 # We can modify backed up files
430 zcat $dir/volatile.cpio.gz | \
431 cpio -t 2> /dev/null | \
432 grep -q "^${i#/}$" && continue
433 fi
434 echo "$PACKAGE" >> $dir/modifiers
435 done
436 done
437 cp receipt files.list $ROOT$INSTALLED/$PACKAGE
438 # Copy the description if found.
439 if [ -f "description.txt" ]; then
440 cp description.txt $ROOT$INSTALLED/$PACKAGE
441 fi
442 # Copy the md5sum if found.
443 if [ -f "md5sum" ]; then
444 cp md5sum $ROOT$INSTALLED/$PACKAGE
445 fi
446 # Pre install commands.
447 if grep -q ^pre_install $ROOT$INSTALLED/$PACKAGE/receipt; then
448 pre_install $ROOT
449 fi
450 if [ -n "$CONFIG_FILES" ]; then
451 # save 'official' configuration files
452 echo -n "Save configuration files for $PACKAGE... "
453 for i in $CONFIG_FILES; do
454 ( cd fs ; find ${i#/} -type f )
455 done | ( cd fs ; cpio -o -H newc | gzip -9 ) > \
456 $ROOT$INSTALLED/$PACKAGE/volatile.cpio.gz
457 # keep user configuration files
458 for i in $CONFIG_FILES; do
459 ( cd fs ; find ${i#/} -type f )
460 done | while read i; do
461 [ -e $ROOT/$i ] || continue
462 cp -a $ROOT/$i fs/$i
463 done
464 status
465 fi
466 echo -n "Installing $PACKAGE... "
467 cp -a fs/* $ROOT/
468 status
469 # Remove the temporary random directory.
470 echo -n "Removing all tmp files... "
471 cd .. && rm -rf $TMP_DIR
472 status
473 # Post install commands.
474 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
475 post_install $ROOT
476 fi
477 cd $TOP_DIR
478 echo "================================================================================"
479 echo "$PACKAGE ($VERSION$EXTRAVERSION) is installed."
480 echo ""
481 # Log this activity
482 [ -n "$ROOT" ] || log Installed
484 }
486 # Check for loop in deps tree.
487 check_for_deps_loop()
488 {
489 local list
490 local pkg
491 local deps
492 pkg=$1
493 shift
494 [ -n "$1" ] || return
495 list=""
496 # Filter out already processed deps
497 for i in $@; do
498 case " $ALL_DEPS" in
499 *\ $i\ *);;
500 *) list="$list $i";;
501 esac
502 done
503 ALL_DEPS="$ALL_DEPS$list "
504 for i in $list; do
505 [ -f $i/receipt ] || continue
506 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
507 case " $deps " in
508 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
509 *) check_for_deps_loop $pkg $deps;;
510 esac
511 done
512 }
514 # Check for missing deps listed in a receipt packages.
515 check_for_deps()
516 {
517 local saved;
518 saved=$PACKAGE
519 mkdir -p $TMP_DIR
520 ( cd $TMP_DIR ; cpio -i receipt > /dev/null ) < $PACKAGE_FILE
521 . $TMP_DIR/receipt
522 PACKAGE=$saved
523 rm -rf $TMP_DIR
524 for pkgorg in $DEPENDS
525 do
526 i=$(equivalent_pkg $pkgorg $1)
527 if [ ! -d "$1$INSTALLED/$i" ]; then
528 MISSING_PACKAGE=$i
529 deps=$(($deps+1))
530 elif [ ! -f "$1$INSTALLED/$i/receipt" ]; then
531 echo -e "$WARNING Dependency loop between $PACKAGE and $i."
532 fi
533 done
534 if [ ! "$MISSING_PACKAGE" = "" ]; then
535 echo -e "\033[1mTracking dependencies for :\033[0m $PACKAGE"
536 echo "================================================================================"
537 for pkgorg in $DEPENDS
538 do
539 i=$(equivalent_pkg $pkgorg $1)
540 if [ ! -d "$1$INSTALLED/$i" ]; then
541 MISSING_PACKAGE=$i
542 echo "Missing : $MISSING_PACKAGE"
543 fi
544 done
545 echo "================================================================================"
546 echo "$deps missing package(s) to install."
547 fi
548 }
550 # Install all missing deps. First ask user then install all missing deps
551 # from local dir, cdrom, media or from the mirror. In case we want to
552 # install packages from local, we need a packages.list to find the version.
553 install_deps()
554 {
555 local root
556 root=""
557 [ -n "$1" ] && root="--root=$1"
558 echo ""
559 echo -n "Install all missing dependencies (y/N) ? "; read anser
560 echo ""
561 if [ "$anser" = "y" ]; then
562 for pkgorg in $DEPENDS
563 do
564 pkg=$(equivalent_pkg $pkgorg $1)
565 if [ ! -d "$1$INSTALLED/$pkg" ]; then
566 local list
567 list="$INSTALL_LIST"
568 [ -n "$list" ] || list="$TOP_DIR/packages.list"
569 # We can install packages from a local dir by greping
570 # the TAZPKG_BASENAME in the local packages.list.
571 found=0
572 if [ -f "$list" ]; then
573 echo "Checking if $pkg exists in local list... "
574 mkdir $TMP_DIR
575 for i in $pkg-*.tazpkg; do
576 [ -f $i ] || continue
577 ( cd $TMP_DIR ; cpio -i receipt > /dev/null) < $i
578 [ "$(. $TMP_DIR/receipt; echo $PACKAGE)" = "$pkg" ] || continue
579 if grep -q ^$(package_fullname_in_dir $TMP_DIR).tazpkg$ $list
580 then
581 found=1
582 tazpkg install $i $root --list=$list
583 break
584 fi
585 done
586 rm -rf $TMP_DIR
587 fi
588 # Install deps from the mirror.
589 if [ $found -eq 0 ]; then
590 if [ ! -f "$LOCALSTATE/packages.list" ]; then
591 tazpkg recharge
592 fi
593 tazpkg get-install $pkg $root
594 fi
595 fi
596 done
597 else
598 echo -e "\nLeaving dependencies for $PACKAGE unsolved."
599 echo -e "The package is installed but will probably not work.\n"
600 fi
601 }
603 # xHTML packages list header.
604 xhtml_header()
605 {
606 cat > $XHTML_LIST << _EOT_
607 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
608 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
609 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
610 <head>
611 <title>Installed packages list</title>
612 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
613 <meta name="modified" content="$DATE" />
614 <meta name="generator" content="Tazpkg" />
615 <style type="text/css"><!--
616 body { font: 12px sans-serif, vernada, arial; margin: 0; }
617 #header { background: #f0ba08; color: black; height: 50px;
618 border-top: 1px solid black; border-bottom: 1px solid black; }
619 #content { margin: 0px 50px 26px 50px; }
620 #footer { border-top: 1px solid black; padding-top: 10px;}
621 h1 { margin: 14px 0px 0px 16px; }
622 pre { padding-left: 5px; }
623 hr { color: white; background: white; height: 1px; border: 0; }
624 --></style>
625 </head>
626 <body bgcolor="#ffffff">
627 <div id="header">
628 <h1><font color="#3e1220">Installed packages list</font></h1>
629 </div>
630 <hr />
631 <!-- Start content -->
632 <div id="content">
634 <p>
635 _packages_ packages installed - List generated on : $DATE
636 <p>
638 _EOT_
639 }
641 # xHTML content with packages info.
642 xhtml_pkg_info()
643 {
644 cat >> $XHTML_LIST << _EOT_
645 <h3>$PACKAGE</h3>
646 <pre>
647 Version : $VERSION$EXTRAVERSION
648 Short desc : $SHORT_DESC
649 Web site : <a href="$WEB_SITE">$WEB_SITE</a>
650 </pre>
652 _EOT_
653 }
655 # xHTML packages list footer.
656 xhtml_footer()
657 {
658 cat >> $XHTML_LIST << _EOT_
659 <hr />
660 <p id="footer">
661 $packages packages installed - List generated on : $DATE
662 </p>
664 <!-- End content -->
665 </div>
666 </body>
667 </html>
668 _EOT_
669 }
671 # Search pattern in installed packages.
672 search_in_installed_packages()
673 {
674 echo "Installed packages"
675 echo "================================================================================"
676 list=`ls -1 $INSTALLED | grep -i "$PATTERN"`
677 for pkg in $list
678 do
679 EXTRAVERSION=""
680 [ -f $INSTALLED/$pkg/receipt ] || continue
681 . $INSTALLED/$pkg/receipt
682 echo -n "$PACKAGE "
683 echo -en "\033[24G $VERSION$EXTRAVERSION"
684 echo -e "\033[42G $CATEGORY"
685 packages=$(($packages+1))
686 done
687 # Set correct ending messages.
688 if [ "$packages" = "" ]; then
689 echo "0 installed packages found for : $PATTERN"
690 echo ""
691 else
692 echo "================================================================================"
693 echo "$packages installed package(s) found for : $PATTERN"
694 echo ""
695 fi
696 }
698 # Search in packages.list for available pkgs.
699 search_in_packages_list()
700 {
701 echo "Available packages name-version"
702 echo "================================================================================"
703 packages=0
704 for i in $LOCALSTATE/packages.list $LOCALSTATE/undigest/*/packages.list; do
705 grep -is "$PATTERN" $i
706 packages=$(($packages + `grep -is "$PATTERN" $i | wc -l`))
707 done
708 if [ ! -f "$LOCALSTATE/packages.list" ]; then
709 echo -e "
710 No 'packages.list' found to check for mirrored packages. For more results,
711 please run 'tazpkg recharge' once as root before searching.\n"
712 fi
713 if [ "$packages" = "0" ]; then
714 echo "0 available packages found for : $PATTERN"
715 echo ""
716 else
717 echo "================================================================================"
718 echo "$packages available package(s) found for : $PATTERN"
719 echo ""
720 fi
721 }
723 # search --mirror: Search in packages.txt for available pkgs and give more
724 # info than --list or default.
725 search_in_packages_txt()
726 {
727 echo "Matching packages name with version and desc"
728 echo "================================================================================"
729 packages=0
730 for i in $LOCALSTATE/packages.txt $LOCALSTATE/undigest/*/packages.txt; do
731 grep -is -A 2 "^$PATTERN" $i
732 packages=$(($packages + `grep -is "^$PATTERN" $i | wc -l`))
733 done
734 if [ ! -f "$LOCALSTATE/packages.txt" ]; then
735 echo -e "
736 No 'packages.txt' found to check for mirrored packages. For more results,
737 please run 'tazpkg recharge' once as root before searching.\n"
738 fi
739 if [ "$packages" = "0" ]; then
740 echo "0 available packages found for : $PATTERN"
741 echo ""
742 else
743 echo "================================================================================"
744 echo "$packages available package(s) found for : $PATTERN"
745 echo ""
746 fi
747 }
749 # Install package-list from a flavor
750 install_flavor()
751 {
752 check_root
753 FLAVOR=$1
754 ARG=$2
755 mkdir -p $TMP_DIR
756 [ -f $FLAVOR.flavor ] && cp $FLAVOR.flavor $TMP_DIR
757 cd $TMP_DIR
758 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
759 zcat $FLAVOR.flavor | cpio -i 2>/dev/null
760 while read file; do
761 for pkg in $(ls -d $INSTALLED/${file%%-*}*); do
762 [ -f $pkg/receipt ] || continue
763 EXTRAVERSION=""
764 . $pkg/receipt
765 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && break
766 done
767 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && continue
768 cd $CACHE_DIR
769 download $file.tazpkg
770 cd $TMP_DIR
771 tazpkg install $CACHE_DIR/$file.tazpkg --forced
772 done < $FLAVOR.pkglist
773 [ -f $FLAVOR.nonfree ] && while read pkg; do
774 [ -d $INSTALLED/$pkg ] || continue
775 [ -d $INSTALLED/get-$pkg ] && tazpkg get-install get-$pkg
776 get-$pkg
777 done < $FLAVOR.nonfree
778 [ "$ARG" == "--purge" ] && for pkg in $(ls $INSTALLED); do
779 [ -f $INSTALLED/$pkg/receipt ] || continue
780 EXTRAVERSION=""
781 . $INSTALLED/$pkg/receipt
782 grep -q ^$PACKAGE-$VERSION$EXTRAVERSION$ $FLAVOR.pkglist && continue
783 grep -qs ^$PACKAGE$ $FLAVOR.nonfree && continue
784 tazpkg remove $PACKAGE
785 done
786 else
787 echo "Can't find flavor $FLAVOR Abort."
788 fi
789 cd $TOP_DIR
790 rm -rf $TMP_DIR
791 }
793 # Update mirror urls
794 setup_mirror()
795 {
796 # Backup old list.
797 if [ -f "$1/mirror" ]; then
798 cp -f $1/mirror $1/mirror.bak
799 fi
800 echo ""
801 echo -e "\033[1mCurrent mirror(s)\033[0m"
802 echo "================================================================================"
803 echo " `cat $1/mirror 2> /dev/null`"
804 echo "
805 Please enter URL of the new mirror (http, ftp or local path). You must specify
806 the complete address to the directory of the packages and packages.list file."
807 echo ""
808 echo -n "New mirror(s) URL : "
809 NEW_MIRROR_URL=$2
810 if [ -n "$NEW_MIRROR_URL" ]; then
811 echo $NEW_MIRROR_URL
812 else
813 read NEW_MIRROR_URL
814 fi
815 if [ "$NEW_MIRROR_URL" = "" ]; then
816 echo "Nothing has been changed."
817 else
818 echo "Setting mirror(s) to : $NEW_MIRROR_URL"
819 rm -f $1/mirror
820 for i in $NEW_MIRROR_URL; do
821 echo "$i" >> $1/mirror
822 done
823 fi
824 echo ""
825 }
827 # recursive dependencies scan
828 dep_scan()
829 {
830 for i in $1; do
831 case " $ALL_DEPS " in
832 *\ $i\ *) continue;;
833 esac
834 ALL_DEPS="$ALL_DEPS $i"
835 [ -n "$2" ] && echo "$2$i"
836 [ -f $i/receipt ] || continue
837 DEPENDS=""
838 . $i/receipt
839 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
840 done
841 }
843 # recursive reverse dependencies scan
844 rdep_scan()
845 {
846 for i in $1; do
847 case " $ALL_DEPS " in
848 *\ $i\ *) continue;;
849 esac
850 ALL_DEPS="$ALL_DEPS $i"
851 [ -n "$2" ] && echo "$2$i"
852 RDEPENDS=""
853 for j in *; do
854 [ -f $j/receipt ] || continue
855 DEPENDS=""
856 . $j/receipt
857 case " $(echo $DEPENDS) " in
858 *\ $i\ *)
859 RDEPENDS="$RDEPENDS $j";;
860 esac
861 done
862 [ -n "$RDEPENDS" ] && rdep_scan "$RDEPENDS" "$2 "
863 done
864 }
866 ###################
867 # Tazpkg commands #
868 ###################
870 case "$COMMAND" in
871 list)
872 # List all installed packages or a specific category.
873 #
874 if [ "$2" = "blocked" ]; then
875 echo ""
876 echo -e "\033[1mBlocked packages\033[0m"
877 echo "================================================================================"
878 if [ -s "$BLOCKED" ];then
879 cat $BLOCKED
880 echo ""
881 else
882 echo -e "No blocked packages found.\n"
883 fi
884 exit 0
885 fi
886 # Display the list of categories.
887 if [ "$2" = "cat" -o "$2" = "categories" ]; then
888 echo ""
889 echo -e "\033[1mPackages categories :\033[0m"
890 echo "================================================================================"
891 for i in $CATEGORIES
892 do
893 echo $i
894 categories=$(($categories+1))
895 done
896 echo "================================================================================"
897 echo "$categories categories"
898 echo ""
899 exit 0
900 fi
901 # Check for an asked category.
902 if [ -n "$2" ]; then
903 ASKED_CATEGORY=$2
904 echo ""
905 echo -e "\033[1mInstalled packages of category :\033[0m $ASKED_CATEGORY"
906 echo "================================================================================"
907 for pkg in $INSTALLED/*
908 do
909 [ -f $pkg/receipt ] || continue
910 EXTRAVERSION=""
911 . $pkg/receipt
912 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
913 echo -n "$PACKAGE"
914 echo -e "\033[24G $VERSION$EXTRAVERSION"
915 packages=$(($packages+1))
916 fi
917 done
918 echo "================================================================================"
919 echo -e "$packages packages installed of category $ASKED_CATEGORY."
920 echo ""
921 else
922 # By default list all packages and versions.
923 echo ""
924 echo -e "\033[1mList of all installed packages\033[0m"
925 echo "================================================================================"
926 for pkg in $INSTALLED/*
927 do
928 [ -f $pkg/receipt ] || continue
929 EXTRAVERSION=""
930 . $pkg/receipt
931 echo -n "$PACKAGE"
932 echo -en "\033[24G $VERSION$EXTRAVERSION"
933 echo -e "\033[42G $CATEGORY"
934 packages=$(($packages+1))
935 done
936 echo "================================================================================"
937 echo "$packages packages installed."
938 echo ""
939 fi
940 ;;
941 xhtml-list)
942 # Get info in receipts and build list.
943 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
944 if [ -n "$2" ]; then
945 XHTML_LIST=$2
946 else
947 XHTML_LIST=installed-packages.html
948 fi
949 echo ""
950 echo -e "\033[1mCreating xHTML list of installed packages\033[0m"
951 echo "================================================================================"
952 echo -n "Generating xHTML header..."
953 xhtml_header
954 status
955 # Packages
956 echo -n "Creating packages information..."
957 for pkg in $INSTALLED/*
958 do
959 [ -f $pkg/receipt ] || continue
960 EXTRAVERSION=""
961 . $pkg/receipt
962 xhtml_pkg_info
963 packages=$(($packages+1))
964 done
965 status
966 echo -n "Generating xHTML footer..."
967 xhtml_footer
968 status
969 # sed pkgs nb in header.
970 sed -i s/'_packages_'/"$packages"/ $XHTML_LIST
971 echo "================================================================================"
972 echo "$XHTML_LIST created - $packages packages."
973 echo ""
974 ;;
975 list-mirror)
976 # List all available packages on the mirror. Option --diff displays
977 # last mirrored packages diff (see recharge).
978 check_for_packages_list
979 case $2 in
980 --diff)
981 if [ -f "$LOCALSTATE/packages.diff" ]; then
982 echo ""
983 echo -e "\033[1mMirrored packages diff\033[0m"
984 echo "================================================================================"
985 cat $LOCALSTATE/packages.diff
986 echo "================================================================================"
987 pkgs=`cat $LOCALSTATE/packages.diff | wc -l`
988 echo "$pkgs new packages listed on the mirror."
989 echo ""
990 else
991 echo -e "\nUnable to list anything, no packages.diff found."
992 echo -e "Recharge your current list to create a first diff.\n"
993 fi && exit 0 ;;
994 --text|--txt)
995 echo ""
996 echo -e "\033[1mList of available packages on the mirror\033[0m"
997 echo "================================================================================"
998 cat $LOCALSTATE/packages.txt ;;
999 --raw|*)
1000 echo ""
1001 echo -e "\033[1mList of available packages on the mirror\033[0m"
1002 echo "================================================================================"
1003 cat $LOCALSTATE/packages.list ;;
1004 esac
1005 echo "================================================================================"
1006 pkgs=`cat $LOCALSTATE/packages.list | wc -l`
1007 echo "$pkgs packages in the last recharged list."
1008 echo ""
1009 ;;
1010 list-files)
1011 # List files installed with the package.
1013 check_for_package_on_cmdline
1014 check_for_receipt
1015 echo ""
1016 echo -e "\033[1mInstalled files with :\033[0m $PACKAGE"
1017 echo "================================================================================"
1018 cat $INSTALLED/$PACKAGE/files.list | sort
1019 echo "================================================================================"
1020 files=`cat $INSTALLED/$PACKAGE/files.list | wc -l`
1021 echo "$files files installed with $PACKAGE."
1022 echo ""
1023 ;;
1024 info)
1025 # Information about package.
1027 check_for_package_on_cmdline
1028 check_for_receipt
1029 EXTRAVERSION=""
1030 . $INSTALLED/$PACKAGE/receipt
1031 echo ""
1032 echo -e "\033[1mTazpkg information\033[0m
1033 ================================================================================
1034 Package : $PACKAGE
1035 Version : $VERSION$EXTRAVERSION
1036 Category : $CATEGORY
1037 Short desc : $SHORT_DESC
1038 Maintainer : $MAINTAINER"
1039 if [ ! "$DEPENDS" = "" ]; then
1040 echo -e "Depends : $DEPENDS"
1041 fi
1042 if [ ! "$SUGGESTED" = "" ]; then
1043 echo -e "Suggested : $SUGGESTED"
1044 fi
1045 if [ ! "$BUILD_DEPENDS" = "" ]; then
1046 echo -e "Build deps : $BUILD_DEPENDS"
1047 fi
1048 if [ ! "$WANTED" = "" ]; then
1049 echo -e "Wanted src : $WANTED"
1050 fi
1051 if [ ! "$WEB_SITE" = "" ]; then
1052 echo -e "Web site : $WEB_SITE"
1053 fi
1054 echo "================================================================================"
1055 echo ""
1056 ;;
1057 desc)
1058 # Display package description.txt if available.
1059 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
1060 echo ""
1061 echo -e "\033[1mDescription of :\033[0m $PACKAGE"
1062 echo "================================================================================"
1063 cat $INSTALLED/$PACKAGE/description.txt
1064 echo "================================================================================"
1065 echo ""
1066 else
1067 echo -e "\nSorry, no description available for this package.\n"
1068 fi
1069 ;;
1070 search)
1071 # Search for a package by pattern or name.
1073 PATTERN="$2"
1074 if [ -z "$PATTERN" ]; then
1075 echo -e "\nPlease specify a pattern or package name to search for."
1076 echo -e "Example : 'tazpkg search paint'.\n"
1077 exit 0
1078 fi
1079 echo ""
1080 echo -e "\033[1mSearch result for :\033[0m $PATTERN"
1081 echo ""
1082 # Default is to search in installed pkgs and the raw list.
1083 case $3 in
1084 -i|--installed)
1085 search_in_installed_packages ;;
1086 -l|--list)
1087 search_in_packages_list ;;
1088 -m|--mirror)
1089 search_in_packages_txt ;;
1090 *)
1091 search_in_installed_packages
1092 search_in_packages_list ;;
1093 esac
1094 ;;
1095 search-file)
1096 # Search for a file by pattern or name in all files.list.
1098 if [ -z "$2" ]; then
1099 echo -e "\nPlease specify a pattern or file name to search for."
1100 echo -e "Example : 'tazpkg search-file libnss'. \n"
1101 exit 0
1102 fi
1103 echo ""
1104 echo -e "\033[1mSearch result for file :\033[0m $2"
1105 echo "================================================================================"
1107 if [ "$3" == "--mirror" ]; then
1109 match=0
1110 for i in $LOCALSTATE/files.list.lzma \
1111 $LOCALSTATE/undigest/*/files.list.lzma; do
1112 [ -f $i ] || continue
1113 unlzma -c $i | grep -- ".*:.*$2" | awk '
1114 BEGIN { last="" }
1116 pkg=substr($0,0,index($0,":")-1);
1117 file=substr($0,index($0,":")+2);
1118 if (last != pkg) {
1119 last = pkg;
1120 printf("\n%c[1mPackage %s :%c[0m\n",27,pkg,27);
1122 printf("%s\n",file);
1123 }'
1124 match=$(($match + `unlzma -c $i | grep -- ".*:.*$2" | wc -l`))
1125 done
1127 else
1129 # Check all pkg files.list in search match with specify the package
1130 # name and the full path to the file(s).
1131 for pkg in $INSTALLED/*
1132 do
1133 if grep -qs "$2" $pkg/files.list; then
1134 . $pkg/receipt
1135 echo ""
1136 echo -e "\033[1mPackage $PACKAGE :\033[0m"
1137 grep "$2" $pkg/files.list
1138 files=`grep $2 $pkg/files.list | wc -l`
1139 match=$(($match+$files))
1140 fi
1141 done
1143 fi
1145 if [ "$match" = "" ]; then
1146 echo "0 file found for : $2"
1147 echo ""
1148 else
1149 echo ""
1150 echo "================================================================================"
1151 echo "$match file(s) found for : $2"
1152 echo ""
1153 fi
1154 ;;
1155 install)
1156 # Install .tazpkg packages.
1158 check_root
1159 check_for_package_on_cmdline
1160 check_for_package_file
1161 # Check if forced install.
1162 DO_CHECK="yes"
1163 ROOT=""
1164 while [ -n "$3" ]; do
1165 case "$3" in
1166 --forced)
1167 DO_CHECK="no"
1168 ;;
1169 --root=*)
1170 ROOT="${3#--root=}"
1171 ;;
1172 --list=*)
1173 INSTALL_LIST="${3#--list=}"
1174 ;;
1175 *) shift 2
1176 echo -e "\nUnknown option $*.\n"
1177 exit 1
1178 ;;
1179 esac
1180 shift
1181 done
1182 if [ "$DO_CHECK" = "yes" ]; then
1183 check_for_installed_package $ROOT
1184 fi
1185 install_package $ROOT
1186 ;;
1187 install-list|get-install-list)
1188 # Install a set of packages from a list.
1190 check_root
1191 if [ -z "$2" ]; then
1192 echo -e "
1193 Please change directory (cd) to the packages repository, and specify the
1194 list of packages to install. Example : tazpkg install-list packages.list\n"
1195 exit 0
1196 fi
1197 # Check if the packages list exist.
1198 if [ ! -f "$2" ]; then
1199 echo "Unable to find : $2"
1200 exit 0
1201 else
1202 LIST=`cat $2`
1203 fi
1205 # Remember processed list
1206 export INSTALL_LIST="$2"
1208 # Set $COMMAND and install all packages.
1209 if [ "$1" = "get-install-list" ]; then
1210 COMMAND=get-install
1211 else
1212 COMMAND=install
1213 fi
1214 touch $2-processed
1215 for pkg in $LIST
1216 do
1217 grep -qs ^$pkg$ $2-processed && continue
1218 tazpkg $COMMAND $pkg --list=$2 "$3" "$4" "$5"
1219 done
1220 rm -f $2-processed
1221 ;;
1222 add-flavor)
1223 # Install a set of packages from a flavor.
1225 install_flavor $2
1226 ;;
1227 install-flavor)
1228 # Install a set of packages from a flavor and purge other ones.
1230 install_flavor $2 --purge
1231 ;;
1232 set-release)
1233 # Change curent release and upgrade packages.
1235 RELEASE=$2
1236 if [ -z "$RELEASE" ]; then
1237 echo -e "\nPlease specify the release you want on the command line."
1238 echo -e "Example: tazpkg set-release cooking\n"
1239 exit 0
1240 fi
1241 rm /var/lib/tazpkg/mirror
1242 echo "$RELEASE" > /etc/slitaz-release
1243 tazpkg recharge && tazpkg upgrade
1245 # Install missing depends
1246 cd $INSTALLED
1247 for i in * ; do
1248 DEPENDS=""
1249 . $i/receipt
1250 for j in $DEPENDS ; do
1251 [ -d $j ] || tazpkg get-install $j
1252 done
1253 done
1254 ;;
1255 remove)
1256 # Remove packages.
1258 check_root
1259 check_for_package_on_cmdline
1260 if [ ! -f "$INSTALLED/$PACKAGE/receipt" ]; then
1261 echo -e "\n$PACKAGE is not installed.\n"
1262 exit 0
1263 else
1264 ALTERED=""
1265 THE_PACKAGE=$PACKAGE # altered by receipt
1266 for i in $(cd $INSTALLED ; ls); do
1267 [ -f $INSTALLED/$i/receipt ] || continue
1268 DEPENDS=""
1269 . $INSTALLED/$i/receipt
1270 case " $(echo $DEPENDS) " in
1271 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
1272 esac
1273 done
1274 EXTRAVERSION=""
1275 . $INSTALLED/$THE_PACKAGE/receipt
1276 fi
1277 echo ""
1278 if [ -n "$ALTERED" ]; then
1279 echo "The following packages depend on $PACKAGE :"
1280 for i in $ALTERED; do
1281 echo " $i"
1282 done
1283 fi
1284 REFRESH=$(cd $INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1285 if [ -n "$REFRESH" ]; then
1286 echo "The following packages have been modified by $PACKAGE :"
1287 for i in $REFRESH; do
1288 echo " ${i%/modifiers}"
1289 done
1290 fi
1291 echo "Remove $PACKAGE ($VERSION$EXTRAVERSION) ?"
1292 echo -n "Please confirm uninstallation (y/N) : "; read anser
1293 if [ "$anser" = "y" ]; then
1294 echo ""
1295 echo -e "\033[1mRemoving :\033[0m $PACKAGE"
1296 echo "================================================================================"
1297 # Pre remove commands.
1298 if grep -q ^pre_remove $INSTALLED/$PACKAGE/receipt; then
1299 pre_remove
1300 fi
1301 echo -n "Removing all files installed..."
1302 for mod in `cat $INSTALLED/$PACKAGE/modifiers 2> /dev/null`
1303 do
1304 for file in `cat $INSTALLED/$PACKAGE/files.list`
1305 do
1306 [ $(grep ^$file$ $INSTALLED/$mod/files.list | wc -l) -gt 1 ] && continue
1307 rm -f $file 2>/dev/null
1308 dir="$file"
1309 while [ "$dir" != "/" ]; do
1310 dir="$(dirname $dir)"
1311 rmdir $dir 2> /dev/null || break
1312 done
1313 done
1314 done
1315 status
1316 if grep -q ^post_remove $INSTALLED/$PACKAGE/receipt; then
1317 post_remove
1318 fi
1319 # Remove package receipt.
1320 echo -n "Removing package receipt..."
1321 rm -rf $INSTALLED/$PACKAGE
1322 status
1323 # Log this activity
1324 log Removed
1325 if [ -n "$ALTERED" ]; then
1326 echo -n "Remove packages depending on $PACKAGE"
1327 echo -n " (y/N) ? "; read anser
1328 if [ "$anser" = "y" ]; then
1329 for i in $ALTERED; do
1330 if [ -d "$INSTALLED/$i" ]; then
1331 tazpkg remove $i
1332 fi
1333 done
1334 fi
1335 fi
1336 if [ -n "$REFRESH" ]; then
1337 echo -n "Reinstall packages modified by $PACKAGE"
1338 echo -n " (y/N) ? "; read anser
1339 if [ "$anser" = "y" ]; then
1340 for i in $REFRESH; do
1341 if [ $(wc -l < $INSTALLED/$i) -gt 1 ]; then
1342 echo "Check $INSTALLED/$i for reinstallation"
1343 continue
1344 fi
1345 rm -r $INSTALLED/$i
1346 tazpkg get-install ${i%/modifiers} --forced
1347 done
1348 fi
1349 fi
1350 else
1351 echo ""
1352 echo "Uninstallation of $PACKAGE cancelled."
1353 fi
1354 echo ""
1355 ;;
1356 extract)
1357 # Extract .tazpkg cpio archive into a directory.
1359 check_for_package_on_cmdline
1360 check_for_package_file
1361 echo ""
1362 echo -e "\033[1mExtracting :\033[0m $PACKAGE"
1363 echo "================================================================================"
1364 # If no directory destination is found on the cmdline
1365 # we create one in the current dir using the package name.
1366 if [ -n "$TARGET_DIR" ]; then
1367 DESTDIR=$TARGET_DIR/$PACKAGE
1368 else
1369 DESTDIR=$PACKAGE
1370 fi
1371 mkdir -p $DESTDIR
1372 echo -n "Copying original package..."
1373 cp $PACKAGE_FILE $DESTDIR
1374 status
1375 cd $DESTDIR
1376 extract_package
1377 echo "================================================================================"
1378 echo "$PACKAGE is extracted to : $DESTDIR"
1379 echo ""
1380 ;;
1381 list-config)
1382 # List configuration files installed.
1384 if [ "$2" = "--box" ]; then
1385 mkdir -p $TMP_DIR && cd $TMP_DIR
1386 FILES="$INSTALLED/*/volatile.cpio.gz"
1387 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
1388 for i in $FILES; do
1389 zcat $i | cpio -idm > /dev/null
1390 find * -type f 2>/dev/null | while read file; do
1391 if [ ! -e /$file ]; then
1392 echo -n "|--|--|--|File lost"
1393 else
1394 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
1395 cmp $file /$file > /dev/null 2>&1 || \
1396 echo -n "$(stat -c "%.16y" /$file)"
1397 fi
1398 echo "|/$file"
1399 done
1400 rm -rf *
1401 done
1402 cd $TOP_DIR
1403 rm -rf $TMP_DIR
1404 else
1405 echo ""
1406 echo -e "\033[1mConfiguration files"
1407 echo "================================================================================"
1408 for i in $INSTALLED/*/volatile.cpio.gz; do
1409 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
1410 [ -f "$i" ] || continue
1411 zcat $i | cpio -t | grep -v "[0-9]* blocks"
1412 done | sed 's|^|/|' | sort
1413 echo "================================================================================"
1414 echo ""
1415 fi
1416 ;;
1417 repack-config)
1418 # Create SliTaz package archive from configuration files.
1420 mkdir -p $TMP_DIR && cd $TMP_DIR
1421 CONFIG_VERSION=1.0
1422 mkdir config-$CONFIG_VERSION
1423 cd config-$CONFIG_VERSION
1424 for i in $INSTALLED/*/volatile.cpio.gz; do
1425 zcat $i | cpio -t | grep -v "[0-9]* blocks"
1426 done > files.list
1427 mkdir fs
1428 cd fs
1429 ( cd / ; cpio -o -H newc ) < ../files.list | cpio -idm > /dev/null
1430 mkdir -p etc/tazlito
1431 for i in $INSTALLED/*/receipt; do
1432 EXTRAVERSION=""
1433 . $i
1434 echo "$PACKAGE-$VERSION$EXTRAVERSION"
1435 done > etc/tazlito/config-packages.list
1436 cd ..
1437 echo "etc/tazlito/config-packages.list" >> files.list
1438 cat > receipt <<EOT
1439 # SliTaz package receipt.
1441 PACKAGE="config"
1442 VERSION="$CONFIG_VERSION"
1443 CATEGORY="base-system"
1444 SHORT_DESC="User configuration backup on $(date)"
1445 DEPENDS="$(ls $INSTALLED)"
1446 EOT
1447 cd ..
1448 tazpkg pack config-$CONFIG_VERSION
1449 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
1450 cd $TOP_DIR
1451 rm -rf $TMP_DIR
1452 ;;
1453 repack)
1454 # Create SliTaz package archive from an installed package.
1456 check_for_package_on_cmdline
1457 check_for_receipt
1458 EXTRAVERSION=""
1459 . $INSTALLED/$PACKAGE/receipt
1460 echo ""
1461 echo -e "\033[1mRepacking :\033[0m $PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
1462 echo "================================================================================"
1463 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
1464 echo "Can't repack $PACKAGE"
1465 exit 1
1466 fi
1467 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
1468 echo "Can't repack, $PACKAGE files have been modified by:"
1469 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
1470 echo " $i"
1471 done
1472 exit 1
1473 fi
1474 MISSING=""
1475 while read i; do
1476 [ -e "$i" ] && continue
1477 [ -L "$i" ] || MISSING="$MISSING\n $i"
1478 done < $INSTALLED/$PACKAGE/files.list
1479 if [ -n "$MISSING" ]; then
1480 echo -n "Can't repack, the following files are lost:"
1481 echo -e "$MISSING"
1482 exit 1
1483 fi
1484 mkdir -p $TMP_DIR && cd $TMP_DIR
1485 FILES="fs.cpio.gz\n"
1486 for i in $(ls $INSTALLED/$PACKAGE) ; do
1487 [ "$i" = "volatile.cpio.gz" ] && continue
1488 [ "$i" = "modifiers" ] && continue
1489 cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
1490 done
1491 ln -s / rootfs
1492 mkdir tmp
1493 sed 's/^/rootfs/' < files.list | cpio -o -H newc 2>/dev/null |\
1494 ( cd tmp ; cpio -idm 2>/dev/null )
1495 mv tmp/rootfs fs
1496 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
1497 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
1498 ( cd fs; cpio -idm )
1499 fi
1500 if grep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
1501 . $INSTALLED/$PACKAGE/receipt
1502 repack_cleanup fs
1503 fi
1504 if [ -f $INSTALLED/$PACKAGE/md5sum ]; then
1505 sed 's, , fs,' < $INSTALLED/$PACKAGE/md5sum | \
1506 md5sum -s -c || {
1507 echo "Can't repack, md5sum error."
1508 cd $TOP_DIR
1509 rm -rf $TMP_DIR
1510 exit 1
1512 fi
1513 find fs | cpio -o -H newc 2> /dev/null | gzip -9 > fs.cpio.gz
1514 echo -e "$FILES" | cpio -o -H newc 2> /dev/null > \
1515 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1516 cd $TOP_DIR
1517 \rm -R $TMP_DIR
1518 echo "Package $PACKAGE repacked successfully."
1519 echo "Size : `du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
1520 echo ""
1521 ;;
1522 pack)
1523 # Create SliTaz package archive using cpio and gzip.
1525 check_for_package_on_cmdline
1526 cd $PACKAGE
1527 if [ ! -f "receipt" ]; then
1528 echo "Receipt is missing. Please read the documentation."
1529 exit 0
1530 else
1531 echo ""
1532 echo -e "\033[1mPacking :\033[0m $PACKAGE"
1533 echo "================================================================================"
1534 # Create files.list with redirecting find outpout.
1535 echo -n "Creating the list of files..." && cd fs
1536 find . -type f -print > ../files.list
1537 find . -type l -print >> ../files.list
1538 cd .. && sed -i s/'^.'/''/ files.list
1539 status
1540 echo -n "Creating md5sum of files..."
1541 while read file; do
1542 [ -L "fs$file" ] && continue
1543 [ -f "fs$file" ] || continue
1544 case "$file" in
1545 /lib/modules/*/modules.*|*.pyc) continue;;
1546 esac
1547 md5sum "fs$file" | sed 's/ fs/ /'
1548 done < files.list > md5sum
1549 status
1550 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
1551 description.txt 2> /dev/null | awk \
1552 '{ sz=$1 } END { print sz }')
1553 # Build cpio archives.
1554 echo -n "Compressing the fs... "
1555 find fs -print | cpio -o -H newc | gzip > fs.cpio.gz
1556 rm -rf fs
1557 status
1558 PACKED_SIZE=$(du -chs fs.cpio.gz receipt files.list \
1559 md5sum description.txt 2> /dev/null | awk \
1560 '{ sz=$1 } END { print sz }')
1561 echo -n "Undating receipt sizes..."
1562 sed -i s/^PACKED_SIZE.*$// receipt
1563 sed -i s/^UNPACKED_SIZE.*$// receipt
1564 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1565 status
1566 echo -n "Creating full cpio archive... "
1567 find . -print | cpio -o -H newc > ../$PACKAGE.tazpkg
1568 status
1569 echo -n "Restoring original package tree... "
1570 zcat fs.cpio.gz | cpio -idm
1571 status
1572 rm fs.cpio.gz && cd ..
1573 echo "================================================================================"
1574 echo "Package $PACKAGE compressed successfully."
1575 echo "Size : `du -sh $PACKAGE.tazpkg`"
1576 echo ""
1577 fi
1578 ;;
1579 recharge)
1580 # Recharge packages.list from a mirror.
1582 check_root
1583 for path in $LOCALSTATE $LOCALSTATE/undigest/*; do
1584 [ -f $path/mirror ] || continue
1585 echo ""
1586 if [ "$path" != "$LOCALSTATE" ]; then
1587 echo "Recharge undigest $(basename $path):"
1588 fi
1589 cd $path
1590 if [ -f "packages.list" ]; then
1591 echo -n "Creating backup of the last packages list..."
1592 mv -f packages.desc packages.desc.bak 2>/dev/null
1593 mv -f packages.md5 packages.md5.txt 2>/dev/null
1594 mv -f packages.txt packages.txt.bak 2>/dev/null
1595 mv -f packages.list packages.list.bak 2>/dev/null
1596 mv -f packages.equiv packages.equiv.bak 2>/dev/null
1597 mv -f files.list.lzma files.list.lzma.bak 2> /dev/null
1598 mv -f mirrors mirrors.bak 2> /dev/null
1599 status
1600 fi
1601 download_from "$(cat mirror)" packages.desc
1602 download_from "$(cat mirror)" packages.md5
1603 download_from "$(cat mirror)" packages.txt
1604 download_from "$(cat mirror)" packages.list
1605 download_from "$(cat mirror)" packages.equiv
1606 download_from "$(cat mirror)" files.list.lzma
1607 download_from "$(cat mirror)" mirrors
1608 [ -f mirrors ] || mv mirrors.bak mirrors 2> /dev/null
1609 suffix=$(head -1 mirror)
1610 suffix=packages${suffix#*/packages}
1611 for i in $(cat mirrors 2> /dev/null); do
1612 grep -qs $i mirror || echo $i$suffix >> mirror
1613 done
1614 if [ -f "packages.list.bak" ]; then
1615 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
1616 sed -i s/+// packages.diff
1617 echo ""
1618 echo -e "\033[1mMirrored packages diff\033[0m"
1619 echo "================================================================================"
1620 cat packages.diff
1621 if [ ! "`cat packages.diff | wc -l`" = 0 ]; then
1622 echo "================================================================================"
1623 echo "`cat packages.diff | wc -l` new packages on the mirror."
1624 echo ""
1625 else
1626 echo "`cat packages.diff | wc -l` new packages on the mirror."
1627 echo ""
1628 fi
1629 else
1630 echo -e "
1631 ================================================================================
1632 Last packages.list is ready to use. Note that next time you recharge the list,
1633 a list of differencies will be displayed to show new and upgradeable packages.\n"
1634 fi
1635 done
1636 ;;
1637 upgrade)
1638 # Upgrade all installed packages with the new version from the mirror.
1640 check_root
1641 check_for_packages_list
1642 cd $LOCALSTATE
1643 # Touch the blocked pkgs list to avoid errors and remove any old
1644 # upgrade list.
1645 touch blocked-packages.list
1646 rm -f upgradeable-packages.list
1647 echo ""
1648 echo -e "\033[1mAvailable upgrades\033[0m"
1649 echo "================================================================================"
1650 echo ""
1651 # Some packages must be installed first
1652 FIRST_CLASS_PACKAGE=" glibc-base slitaz-base-files slitaz-boot-scripts "
1653 for pkg in $INSTALLED/*
1654 do
1655 [ -f $pkg/receipt ] || continue
1656 EXTRAVERSION=""
1657 . $pkg/receipt
1658 # Display package name to show that Tazpkg is working...
1659 echo -en "\\033[0G "
1660 echo -en "\\033[0G$PACKAGE"
1661 # Skip specified pkgs listed in $LOCALSTATE/blocked-packages.list
1662 if grep -qs "^$PACKAGE" $BLOCKED; then
1663 blocked=$(($blocked+1))
1664 else
1665 # Check if the installed package is in the current list (other
1666 # mirror or local).
1667 NEW_PACKAGE=$(get_package_filename $PACKAGE)
1669 if [ -n "$NEW_PACKAGE" ]; then
1670 # Set new pkg and version for future comparison
1671 NEW_VERSION=`echo $NEW_PACKAGE | sed s/$PACKAGE-/''/`
1672 # Change '-' and 'pre' to points.
1673 NEW_VERSION=`echo $NEW_VERSION | sed s/'-'/'.'/`
1674 VERSION=`echo $VERSION | sed s/'-'/'.'/`$EXTRAVERSION
1675 NEW_VERSION=`echo $NEW_VERSION | sed s/'pre'/'.'/`
1676 VERSION=`echo $VERSION | sed s/'pre'/'.'/`
1677 NEW_VERSION=`echo $NEW_VERSION | sed 's/[A-Z]\.//'`
1678 VERSION=`echo $VERSION | sed 's/[A-Z]\.//'`
1679 # Compare version. Upgrades are only available for official
1680 # packages, so we control the mirror and it should be ok if
1681 # we just check for equality.
1682 RELEASE=""
1683 if [ -f installed.md5 -a -f packages.md5 ]; then
1684 current_md5=$(grep -s " $PACKAGE-$VERSION" installed.md5 | awk '{ print $1 }')
1685 new_md5=$(grep -hs " $PACKAGE-$VERSION" packages.md5 undigest/*/packages.md5 | head -1 | awk '{ print $1 }')
1686 [ -n "$current_md5" ] && [ -n "$new_md5" ] &&
1687 [ "$current_md5" != "$new_md5" ] && RELEASE=build
1688 fi
1689 if [ "$VERSION" != "$NEW_VERSION" -o -n "$RELEASE" ]; then
1690 # Version seems different. Check for major, minor or
1691 # revision
1692 PKG_MAJOR=`echo ${VERSION%_*} | cut -f1 -d"."`
1693 NEW_MAJOR=`echo ${NEW_VERSION%_*} | cut -f1 -d"."`
1694 PKG_MINOR=`echo ${VERSION%_*} | cut -f2 -d"."`
1695 NEW_MINOR=`echo ${NEW_VERSION%_*} | cut -f2 -d"."`
1696 # Minor
1697 if [ "$NEW_MINOR" -gt "$PKG_MINOR" ] 2> /dev/null; then
1698 RELEASE=minor
1699 fi
1700 if [ "$NEW_MINOR" -lt "$PKG_MINOR" ] 2> /dev/null; then
1701 RELEASE=$WARNING
1702 FIXE=yes
1703 fi
1704 # Major
1705 if [ "$NEW_MAJOR" -gt "$PKG_MAJOR" ] 2> /dev/null; then
1706 RELEASE=major
1707 FIXE=""
1708 fi
1709 if [ "$NEW_MAJOR" -lt "$PKG_MAJOR" ] 2> /dev/null; then
1710 RELEASE=$WARNING
1711 FIXE=yes
1712 fi
1713 # Default to revision.
1714 if [ -z $RELEASE ]; then
1715 RELEASE=revision
1716 fi
1717 # Pkg name is already displayed by the check process.
1718 echo -en "\033[24G $VERSION"
1719 echo -en "\033[38G --->"
1720 echo -en "\033[43G $NEW_VERSION"
1721 echo -en "\033[58G $CATEGORY"
1722 echo -e "\033[72G $RELEASE"
1723 up=$(($up+1))
1724 echo "$PACKAGE" >> upgradeable-packages.list
1725 case "$FIRST_CLASS_PACKAGE" in
1726 *\ $PACKAGE\ *) echo "$PACKAGE" >> upgradeable-packages.list$$;;
1727 esac
1728 unset RELEASE
1729 fi
1730 packages=$(($packages+1))
1731 fi
1732 fi
1733 done
1734 if [ -z $blocked ]; then
1735 blocked=0
1736 fi
1737 # Clean last checked package and display summary.
1738 if [ ! "$up" = "" ]; then
1739 echo -e "\\033[0G "
1740 echo "================================================================================"
1741 echo "$packages installed and listed packages to consider, $up to upgrade, $blocked blocked."
1742 echo ""
1743 else
1744 echo -e "\\033[0GSystem is up-to-date. "
1745 echo ""
1746 echo "================================================================================"
1747 echo "$packages installed and listed packages to consider, 0 to upgrade, $blocked blocked."
1748 echo ""
1749 exit 0
1750 fi
1751 # What to do if major or minor version is smaller.
1752 if [ "$FIXE" == "yes" ]; then
1753 echo -e "$WARNING ---> Installed package seems more recent than the mirrored one."
1754 echo "You can block packages using the command : 'tazpkg block package'"
1755 echo "Or upgrade packages at your own risk."
1756 echo ""
1757 fi
1758 # Ask for upgrade, it can be done another time.
1759 echo -n "Upgrade now (y/N) ? "; read anser
1760 if [ ! "$anser" = "y" ]; then
1761 echo -e "\nExiting. No package upgraded.\n"
1762 exit 0
1763 fi
1764 # If anser is yes (y). Install all new versions.
1765 cat upgradeable-packages.list >> upgradeable-packages.list$$
1766 mv -f upgradeable-packages.list$$ upgradeable-packages.list
1767 yes y | tazpkg get-install-list upgradeable-packages.list --forced
1768 rm -f upgradeable-packages.list
1769 ;;
1770 bugs)
1771 # Show known bugs in package(s)
1773 cd $INSTALLED
1774 shift
1775 LIST=$@
1776 [ -n "$LIST" ] || LIST=`ls`
1777 MSG="No known bugs."
1778 for PACKAGE in $LIST; do
1779 BUGS=""
1780 EXTRAVERSION=""
1781 . $PACKAGE/receipt
1782 if [ -n "$BUGS" ]; then
1783 MSG="
1784 Bug list completed"
1785 cat <<EOT
1787 Bugs in package $PACKAGE version $VERSION$EXTRAVERSION:
1788 $BUGS
1789 EOT
1790 fi
1791 done
1792 echo "$MSG"
1793 ;;
1794 check)
1795 # Check installed packages set.
1797 check_root
1798 cd $INSTALLED
1799 for PACKAGE in `ls`; do
1800 if [ ! -f $PACKAGE/receipt ]; then
1801 echo "The package $PACKAGE installation is not completed"
1802 continue
1803 fi
1804 DEPENDS=""
1805 EXTRAVERSION=""
1806 . $PACKAGE/receipt
1807 if [ -s $PACKAGE/modifiers ]; then
1808 echo "The package $PACKAGE $VERSION$EXTRAVERSION has been modified by :"
1809 for i in $(cat $PACKAGE/modifiers); do
1810 echo " $i"
1811 done
1812 fi
1813 MSG="Files lost from $PACKAGE $VERSION$EXTRAVERSION :\n"
1814 while read file; do
1815 [ -e "$file" ] && continue
1816 if [ -L "$file" ]; then
1817 MSG="$MSG target of symlink"
1818 fi
1819 echo -e "$MSG $file"
1820 MSG=""
1821 done < $PACKAGE/files.list
1822 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n"
1823 for i in $DEPENDS; do
1824 [ -d $i ] && continue
1825 echo -e "$MSG $i"
1826 MSG=""
1827 done
1828 MSG="Dependencies loop between $PACKAGE and :\n"
1829 ALL_DEPS=""
1830 check_for_deps_loop $PACKAGE $DEPENDS
1831 done
1832 echo -n "Looking for known bugs... "
1833 tazpkg bugs
1834 if [ "$PACKAGE_FILE" = "--full" ]; then
1835 for file in */md5sum; do
1836 CONFIG_FILES=""
1837 . $(dirname "$file")/receipt
1838 [ -s "$file" ] || continue
1839 while read md5 f; do
1840 [ -f $f ] || continue
1841 for i in $CONFIG_FILES; do
1842 case "$f" in
1843 $i|$i/*) continue 2;;
1844 esac
1845 done
1846 echo "$md5 $f"
1847 done < "$file" | md5sum -c - 2> /dev/null | \
1848 grep -v OK$ | sed 's/FAILED$/MD5SUM MISMATCH/'
1849 done
1850 FILES=" "
1851 for file in $(cat */files.list); do
1852 [ -d "$file" ] && continue
1853 case "$FILES" in *\ $file\ *) continue;; esac
1854 [ $(grep "^$file$" */files.list 2> /dev/null | \
1855 wc -l) -gt 1 ] || continue
1856 FILES="$FILES$file "
1857 echo "The following packages provide $file :"
1858 grep -l "^$file$" */files.list | while read f
1859 do
1860 pkg=${f%/files.list}
1861 echo -n " $pkg"
1862 if [ -f $pkg/modifiers ]; then
1863 echo -n " (overridden by $(echo "$(cat $pkg/modifiers)"))"
1864 fi
1865 echo ""
1866 done
1867 done
1868 MSG="No package has installed the following files:\n"
1869 find /etc /bin /sbin /lib /usr /var/www \
1870 -not -type d 2> /dev/null | while read file; do
1871 case "$file" in *\[*) continue;; esac
1872 grep -q "^$file$" */files.list && continue
1873 echo -e "$MSG $file"
1874 MSG=""
1875 done
1876 fi
1877 echo "Check completed."
1878 ;;
1879 block)
1880 # Add a pkg name to the list of blocked packages.
1882 check_root
1883 check_for_package_on_cmdline
1884 echo ""
1885 if grep -qs "^$PACKAGE" $BLOCKED; then
1886 echo "$PACKAGE is already in the blocked packages list."
1887 echo ""
1888 exit 0
1889 else
1890 echo -n "Add $PACKAGE to : $BLOCKED..."
1891 echo $PACKAGE >> $BLOCKED
1892 status
1893 # Log this activity
1894 . $INSTALLED/$PACKAGE/receipt
1895 log Blocked
1896 fi
1897 echo ""
1898 ;;
1899 unblock)
1900 # Remove a pkg name from the list of blocked packages.
1902 check_root
1903 check_for_package_on_cmdline
1904 echo ""
1905 if grep -qs "^$PACKAGE" $BLOCKED; then
1906 echo -n "Removing $PACKAGE from : $BLOCKED..."
1907 sed -i s/$PACKAGE/''/ $BLOCKED
1908 sed -i '/^$/d' $BLOCKED
1909 status
1910 # Log this activity
1911 . $INSTALLED/$PACKAGE/receipt
1912 log Unblocked
1913 else
1914 echo "$PACKAGE is not in the blocked packages list."
1915 echo ""
1916 exit 0
1917 fi
1918 echo ""
1919 ;;
1920 get)
1921 # Downlowd a package with wget.
1923 check_for_package_on_cmdline
1924 check_for_packages_list
1925 check_for_package_in_list
1926 echo ""
1927 download $PACKAGE.tazpkg
1928 echo ""
1929 ;;
1930 get-install)
1931 # Download and install a package.
1933 check_root
1934 check_for_package_on_cmdline
1935 check_for_packages_list
1936 DO_CHECK=""
1937 while [ -n "$3" ]; do
1938 case "$3" in
1939 --forced)
1940 DO_CHECK="no"
1941 ;;
1942 --root=*)
1943 ROOT="${3#--root=}"
1944 ;;
1945 --list=*)
1946 INSTALL_LIST="${3#--list=}"
1947 ;;
1948 *) shift 2
1949 echo -e "\nUnknown option $*.\n"
1950 exit 1
1951 ;;
1952 esac
1953 shift
1954 done
1955 AUTOEXEC="no"
1956 if ! check_for_package_in_list check; then
1957 PACKAGE=get-$PACKAGE
1958 AUTOEXEC=$PACKAGE
1959 check_for_package_in_list
1960 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
1961 $AUTOEXEC $ROOT
1962 exit 0
1963 fi
1964 fi
1965 # Check if forced install.
1966 if [ "$DO_CHECK" = "no" ]; then
1967 rm -f $CACHE_DIR/$PACKAGE.tazpkg
1968 else
1969 check_for_installed_package $ROOT
1970 fi
1971 cd $CACHE_DIR
1972 if [ -f "$PACKAGE.tazpkg" ]; then
1973 echo "$PACKAGE already in the cache : $CACHE_DIR"
1974 # Check package download was finished
1975 tail -c 2k $PACKAGE.tazpkg | grep -q 00000000TRAILER || {
1976 echo "Continue $PACKAGE download"
1977 download $PACKAGE.tazpkg
1979 else
1980 echo ""
1981 download $PACKAGE.tazpkg
1982 fi
1983 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
1984 install_package $ROOT
1985 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
1986 ;;
1987 clean-cache)
1988 # Remove all downloaded packages.
1990 check_root
1991 files=`ls -1 $CACHE_DIR | wc -l`
1992 echo ""
1993 echo -e "\033[1mClean cache :\033[0m $CACHE_DIR"
1994 echo "================================================================================"
1995 echo -n "Cleaning cache directory..."
1996 rm -rf $CACHE_DIR/*
1997 status
1998 echo "================================================================================"
1999 echo "$files file(s) removed from cache."
2000 echo ""
2001 ;;
2002 list-undigest)
2003 # list undigest URLs.
2005 if [ "$2" = "--box" ]; then
2006 for i in $LOCALSTATE/undigest/*/mirror; do
2007 [ -f $i ] || continue
2008 echo "$(basename $(dirname $i))|$(cat $i)"
2009 done
2010 else
2011 echo ""
2012 echo -e "\033[1mCurrent undigest(s)\033[0m"
2013 echo "================================================================================"
2014 for i in $LOCALSTATE/undigest/*/mirror; do
2015 if [ ! -f $i ]; then
2016 echo "No undigest mirror found."
2017 exit 1
2018 fi
2019 echo "$(basename $(dirname $i)) $(cat $i)"
2020 done
2021 echo ""
2022 fi
2023 ;;
2024 remove-undigest)
2025 # remove undigest URL.
2027 check_root
2028 if [ -d $LOCALSTATE/undigest/$2 ]; then
2029 echo -n "Remove $2 undigest (y/N) ? "; read anser
2030 if [ "$anser" = "y" ]; then
2031 echo -n "Removing $2 undigest..."
2032 rm -rf $LOCALSTATE/undigest/$2
2033 status
2034 rmdir $LOCALSTATE/undigest 2> /dev/null
2035 fi
2036 else
2037 echo "Undigest $2 not found"
2038 fi
2039 ;;
2040 add-undigest|setup-undigest)
2041 # Add undigest URL.
2043 check_root
2044 undigest=$2
2045 [ -d $LOCALSTATE/undigest ] || mkdir $LOCALSTATE/undigest
2046 if [ -z "$undigest" ]; then
2047 i=1
2048 while [ -d $LOCALSTATE/undigest/$i ]; do
2049 i=$(($i+1))
2050 done
2051 undigest=$i
2052 fi
2053 if [ ! -d $LOCALSTATE/undigest/$undigest ]; then
2054 echo "Creating new undigest $undigest."
2055 mkdir $LOCALSTATE/undigest/$undigest
2056 fi
2057 setup_mirror $LOCALSTATE/undigest/$undigest $3
2058 ;;
2059 setup-mirror)
2060 # Change mirror URL.
2062 check_root
2063 setup_mirror $LOCALSTATE $2
2064 ;;
2065 reconfigure)
2066 # Replay post_install from receipt
2068 check_for_package_on_cmdline
2069 check_root
2070 ROOT=""
2071 while [ -n "$3" ]; do
2072 case "$3" in
2073 --root=*)
2074 ROOT="${3#--root=}/"
2075 ;;
2076 *) shift 2
2077 echo -e "\nUnknown option $*.\n"
2078 exit 1
2079 ;;
2080 esac
2081 shift
2082 done
2083 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2084 check_for_receipt $ROOT
2085 # Check for post_install
2086 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2087 . $ROOT$INSTALLED/$PACKAGE/receipt
2088 post_install $ROOT
2089 # Log this activity
2090 [ -n "$ROOT" ] || log Reconfigured
2091 else
2092 echo -e "\nNothing to do for $PACKAGE."
2093 fi
2094 else
2095 echo -e "\npackage $PACKAGE is not installed."
2096 echo -e "Install package with 'tazpkg install' or 'tazpkg get-install'\n"
2097 fi
2098 ;;
2099 shell)
2100 # Tazpkg SHell
2102 if test $(id -u) = 0 ; then
2103 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2104 else
2105 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2106 fi
2107 if [ ! "$2" = "--noheader" ]; then
2108 clear
2109 echo ""
2110 echo -e "\033[1mTazpkg SHell.\033[0m"
2111 echo "================================================================================"
2112 echo "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
2113 echo ""
2114 fi
2115 while true
2116 do
2117 echo -en "$PROMPT"; read cmd
2118 case $cmd in
2119 q|quit)
2120 break ;;
2121 shell)
2122 echo "You are already running a Tazpkg SHell." ;;
2123 su)
2124 su -c 'exec tazpkg shell --noheader' && break ;;
2125 "")
2126 continue ;;
2127 *)
2128 tazpkg $cmd ;;
2129 esac
2130 done
2131 ;;
2132 depends)
2133 # Display dependencies tree
2134 cd $INSTALLED
2135 ALL_DEPS=""
2136 if [ -f $2/receipt ]; then
2137 dep_scan $2 ""
2138 fi
2139 ;;
2140 rdepends)
2141 # Display reverse dependencies tree
2142 cd $INSTALLED
2143 ALL_DEPS=""
2144 if [ -f $2/receipt ]; then
2145 rdep_scan $2 ""
2146 fi
2147 ;;
2148 usage|*)
2149 # Print a short help or give usage for an unknown or empty command.
2151 usage
2152 ;;
2153 esac
2155 exit 0