tazpkg view tazpkg @ rev 211

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