tazpkg view tazpkg @ rev 219

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