tazpkg view tazpkg @ rev 279

Prepa for release
author Christophe Lincoln <pankso@slitaz.org>
date Wed Aug 05 23:20:25 2009 +0200 (2009-08-05)
parents 1695ed3d9011
children 9e858955ddba
line source
1 #!/bin/sh
2 # Tazpkg - Tiny autonomous zone packages manager.
3 #
4 # This is a lightwight packages manager for *.tazpkg files, all written in
5 # SHell script. It works well with Busybox ash shell and bash. Tazpkg lets you
6 # list, install, remove, download or get information about a package. You can
7 # use 'tazpkg usage' to get a list of commands with short descriptions. Tazpkg
8 # also resolves dependencies and can upgrade packages from a mirror.
9 #
10 # (C) 2007-2008 SliTaz - GNU General Public License v3.
11 #
12 # Authors : Christophe Lincoln <pankso@slitaz.org>
13 # Pascal Bellard <pascal.bellard@slitaz.org>
14 # Eric Joseph-Alexandre <erjo@slitaz.org>
15 # Paul Issott <paul@slitaz.org>
16 #
17 VERSION=3.0
19 ####################
20 # Script variables #
21 ####################
23 # Packages categories.
24 CATEGORIES="
25 base-system
26 x-window
27 utilities
28 network
29 graphics
30 multimedia
31 office
32 development
33 system-tools
34 security
35 games
36 misc
37 meta
38 non-free"
40 # Initialize some variables to use words
41 # rather than numbers for functions and actions.
42 COMMAND=$1
43 if [ -f "$2" ]; then
44 # Set pkg basename for install, extract
45 PACKAGE=$(basename ${2%.tazpkg} 2>/dev/null)
46 else
47 # Pkg name for remove, search and all other cmds
48 PACKAGE=${2%.tazpkg}
49 fi
50 PACKAGE_FILE=$2
51 TARGET_DIR=$3
52 TOP_DIR=`pwd`
53 TMP_DIR=/tmp/tazpkg-$$-$RANDOM
55 # Path to tazpkg used dir and configuration files
56 LOCALSTATE=/var/lib/tazpkg
57 INSTALLED=$LOCALSTATE/installed
58 CACHE_DIR=/var/cache/tazpkg
59 MIRROR=$LOCALSTATE/mirror
60 BLOCKED=$LOCALSTATE/blocked-packages.list
61 DEFAULT_MIRROR="http://mirror.slitaz.org/packages/`cat /etc/slitaz-release`/"
62 INSTALL_LIST=""
63 LOG=/var/log/tazpkg.log
65 # Messages language setting --> line 230.
66 case $LANG in
67 fr*)
68 #. /usr/share/slitaz/messages/fr/tazpkg.msg
69 # Bold red warning for upgrade.
70 WARNING="\\033[1;31mATTENTION\\033[0;39m"
71 CHECK_FOR_PACKAGE_FILE_MSG="Impossible de trouver"
72 CHECK_FOR_RECEIPT_MSG="Impossible de trouver la receipt"
73 CHECK_FOR_INSTALLED_PACKAGE_MSG="\
74 $PACKAGE est déjà installé. Vous pouvez utiliser l'option --forced pour
75 forcer l'installation ou supprimer le paquet et le réinstaller." ;;
76 *)
77 #. /usr/share/slitaz/messages/en/tazpkg.msg
78 # Bold red warning for upgrade.
79 WARNING="\\033[1;31mWARNING\\033[0;39m"
80 CHECK_FOR_PACKAGE_FILE_MSG="Unable to find"
81 CHECK_FOR_RECEIPT_MSG="Unable to find the receipt"
82 CHECK_FOR_INSTALLED_PACKAGE_MSG="\
83 $PACKAGE is already installed. You can use the --forced option to force
84 installation or remove it and reinstall." ;;
85 esac
87 # Check if the directories and files used by Tazpkg
88 # exist. If not and user is root we create them.
89 if test $(id -u) = 0 ; then
90 if [ ! -d "$CACHE_DIR" ]; then
91 mkdir -p $CACHE_DIR
92 fi
93 if [ ! -d "$INSTALLED" ]; then
94 mkdir -p $INSTALLED
95 fi
96 if [ ! -f "$LOCALSTATE/mirror" ]; then
97 echo "$DEFAULT_MIRROR" > $LOCALSTATE/mirror
98 fi
99 fi
101 ####################
102 # Script functions #
103 ####################
105 # Print the usage.
106 usage ()
107 {
108 echo -e "SliTaz package manager - Version: $VERSION\n
109 \033[1mUsage:\033[0m tazpkg [command] [package|dir|pattern|list|cat|--opt] [dir|--opt]
110 tazpkg shell\n
111 \033[1mCommands: \033[0m
112 usage Print this short usage.
113 bugs Show known bugs in packages.
114 list List installed packages on the system by category or all.
115 xhtml-list Create a xHTML list of installed packages.
116 list-mirror List all available packages on the mirror (--diff for new).
117 info Print information about a package.
118 desc Print description of a package (if it exists).
119 list-files List the files installed with a package.
120 list-config List the configuration files.
121 search Search for a package by pattern or name (options: -i|-l|-m).
122 search-file Search for file(s) in all installed packages files.
123 install Install a local (*.tazpkg) package (--forced to force).
124 install-list Install all packages from a list of packages.
125 remove Remove the specified package and all installed files.
126 extract Extract a (*.tazpkg) package into a directory.
127 pack Pack an unpacked or prepared package tree.
128 recharge Recharge your packages.list from the mirror.
129 repack Create a package archive from an installed package.
130 repack-config Create a package archive with configuration files.
131 upgrade Upgrade one or all installed and listed packages on the mirror.
132 block|unblock Block an installed package version or unblock it for upgrade.
133 get Download a package into the current directory.
134 get-install Download and install a package from the mirror.
135 get-install-list Download and install a list of packages from the mirror.
136 check Verify consistency of installed packages.
137 add-flavor Install the flavor list of packages.
138 install-flavor Install the flavor list of packages and remove other ones.
139 set-release Change release and update packages.
140 clean-cache Clean all packages downloaded in cache directory.
141 depends Display dependencies tree.
142 rdepends Display reverse dependencies tree.
143 convert Convert a deb/rpm/tgz package to a slitaz package (.tazpkg).
144 link Link a package from another slitaz installation.
145 setup-mirror Change the mirror url configuration.
146 list-undigest List undigest mirrors.
147 remove-undigest Remove an undigest mirror.
148 add-undigest Add an undigest mirror.
149 setup-undigest Update an undigest mirror.
150 reconfigure Replay post install script from package."
151 }
153 # Status function with color (supported by Ash).
154 status()
155 {
156 local CHECK=$?
157 echo -en "\\033[70G[ "
158 if [ $CHECK = 0 ]; then
159 echo -en "\\033[1;33mOK"
160 else
161 echo -en "\\033[1;31mFailed"
162 fi
163 echo -e "\\033[0;39m ]"
164 return $CHECK
165 }
167 # Check if user is root to install, or remove packages.
168 check_root()
169 {
170 if test $(id -u) != 0 ; then
171 echo -e "\nYou must be root to run `basename $0` with this option."
172 echo -e "Please use 'su' and root password to become super-user.\n"
173 exit 0
174 fi
175 }
177 # Check for a package name on cmdline.
178 check_for_package_on_cmdline()
179 {
180 if [ -z "$PACKAGE" ]; then
181 echo -e "\nPlease specify a package name on the command line.\n"
182 exit 0
183 fi
184 }
186 # Check if the package (*.tazpkg) exist before installing or extracting.
187 check_for_package_file()
188 {
189 if [ ! -f "$PACKAGE_FILE" ]; then
190 echo -e "
191 $CHECK_FOR_PACKAGE_FILE_MSG : $PACKAGE_FILE\n"
192 exit 0
193 fi
194 }
196 # Check for the receipt of an installed package.
197 check_for_receipt()
198 {
199 if [ ! -f "$1$INSTALLED/$PACKAGE/receipt" ]; then
200 echo -e "\n$CHECK_FOR_RECEIPT_MSG : $1$INSTALLED/$PACKAGE/receipt\n"
201 exit 0
202 fi
203 }
205 # Get package name in a directory
206 package_fullname_in_dir()
207 {
208 [ -f $2$1/receipt ] || return
209 EXTRAVERSION=""
210 . $2$1/receipt
211 echo $PACKAGE-$VERSION$EXTRAVERSION
212 }
214 # Get package name that is already installed.
215 get_installed_package_pathname()
216 {
217 for i in $2$INSTALLED/${1%%-*}*; do
218 [ -d $i ] || continue
219 if [ "$1" = "$(package_fullname_in_dir $i $2)" ]; then
220 echo $i
221 return
222 fi
223 done
224 }
226 # Check if a package is already installed.
227 check_for_installed_package()
228 {
229 if [ -n "$(get_installed_package_pathname $PACKAGE $1)" ]; then
230 echo -e "\n$CHECK_FOR_INSTALLED_PACKAGE_MSG\n"
231 exit 0
232 fi
233 }
235 # Check for packages.list to download and install packages.
236 check_for_packages_list()
237 {
238 if [ ! -f "$LOCALSTATE/packages.list" ]; then
239 if test $(id -u) = 0 ; then
240 tazpkg recharge
241 else
242 echo -e "\nUnable to find the list : $LOCALSTATE/packages.list\n
243 You should probably run 'tazpkg recharge' as root to get the latest list of
244 packages available on the mirror.\n"
245 exit 0
246 fi
247 fi
248 }
250 # get an already installed package from packages.equiv
251 equivalent_pkg()
252 {
253 for i in $(grep -hs "^$1=" $LOCALSTATE/packages.equiv \
254 $LOCALSTATE/undigest/*/packages.equiv | sed "s/^$1=//"); do
255 if echo $i | grep -q : ; then
256 # format 'alternative:newname'
257 # if alternative is installed then substitute newname
258 if [ -f $2$INSTALLED/${i%:*}/receipt ]; then
259 # substitute package dependancy
260 echo ${i#*:}
261 return
262 fi
263 else
264 # if alternative is installed then nothing to install
265 if [ -f $2$INSTALLED/$i/receipt ]; then
266 # substitute installed package
267 echo $i
268 return
269 fi
270 fi
271 done
272 # if not found in packages.equiv then no substitution
273 echo $1
274 }
276 # get a virtual package from packages.equiv
277 virtual_pkg()
278 {
279 for i in $(grep -hs "^$1=" $LOCALSTATE/packages.equiv \
280 $LOCALSTATE/undigest/*/packages.equiv | sed "s/^$1=//"); do
281 if echo $i | grep -q : ; then
282 # format 'alternative:newname'
283 # if alternative is installed then substitute newname
284 if [ -f $2$INSTALLED/${i%:*}/receipt ]; then
285 # substitute package dependancy
286 echo ${i#*:}
287 return
288 fi
289 else
290 # unconditional substitution
291 echo $i
292 return
293 fi
294 done
295 }
297 # Get package filename available on the mirror
298 get_package_filename()
299 {
300 local pkg
301 pkg=$(grep -A 1 -sh "^$1$" $LOCALSTATE/packages.txt \
302 $LOCALSTATE/undigest/*/packages.txt | tail -1)
303 pkg=$(echo $pkg)
304 [ -n "$pkg" ] && pkg=$(grep -sh "^$1-$pkg" \
305 $LOCALSTATE/packages.list \
306 $LOCALSTATE/undigest/*/packages.list | head -1)
307 [ -n "$pkg" ] || pkg=$(grep -sh "^$1-[0-9]" \
308 $LOCALSTATE/packages.list \
309 $LOCALSTATE/undigest/*/packages.list | head -1)
310 [ -n "$pkg" ] || pkg=$(grep -sh "^$1-.[\.0-9]" \
311 $LOCALSTATE/packages.list \
312 $LOCALSTATE/undigest/*/packages.list | head -1)
313 if [ -z "$pkg" ]; then
314 # Check for vitual package
315 local equiv
316 equiv=$(virtual_pkg $1)
317 if [ "$equiv" != "$1" ]; then
318 PACKAGE=$equiv
319 get_package_filename $PACKAGE
320 return
321 fi
322 fi
323 echo $pkg
324 }
326 # Check for a package in packages.list. Used by get and get-install to grep
327 # package basename.
328 check_for_package_in_list()
329 {
330 local filename
331 local check_only
332 check_only="$1"
333 filename=$(get_package_filename $PACKAGE)
334 if [ -n "$filename" ]; then
335 PACKAGE=$filename
336 else
337 echo -e "\nUnable to find : $PACKAGE in the mirrored packages list.\n"
338 [ -n "$check_only" ] && return 1
339 exit 0
340 fi
341 }
343 # Log this activity
344 log()
345 {
346 local extra
347 [ "$1" = "Installed" ] && \
348 extra=" - $(grep $PACKAGE-$VERSION $LOCALSTATE/installed.md5 | awk '{ print $1 }')"
349 [ -e $LOG ] || touch $LOG
350 DATE=`date +'%F %T'`
351 [ -w $LOG ] &&
352 echo "$DATE - $1 - $PACKAGE ($VERSION$EXTRAVERSION)$extra" >> $LOG
353 }
355 # Download a file from this mirror
356 download_from()
357 {
358 local i
359 local mirrors
360 mirrors="$1"
361 shift
362 for i in $mirrors; do
363 case "$i" in
364 http://*|ftp://*) wget -c $i$@ && break;;
365 *) cp $i/$1 . && break;;
366 esac
367 done
368 }
370 # Download a file trying all mirrors
371 download()
372 {
373 local i
374 case "$1" in
375 *.tazpkg)
376 for i in $LOCALSTATE $LOCALSTATE/undigest/* ; do
377 grep "^${1%.tazpkg}$" $i/packages.list || continue
378 download_from "$(cat $i/mirror)" "$@" && return
379 done
380 esac
381 for i in $(cat $MIRROR $LOCALSTATE/undigest/*/mirror 2> /dev/null); do
382 download_from "$i" "$@" && break
383 done
384 }
386 # Extract a package with cpio and gzip.
387 extract_package()
388 {
389 echo -n "Extracting $PACKAGE... "
390 cpio -idm < $PACKAGE.tazpkg && rm -f $PACKAGE.tazpkg
391 echo -n "Extracting the pseudo fs... "
392 zcat fs.cpio.gz | cpio -idm && rm fs.cpio.gz
393 }
395 # This function installs a package in the rootfs.
396 install_package()
397 {
398 ROOT=$1
399 if [ -n "$ROOT" ]; then
400 # Get absolute path
401 ROOT=$(cd $ROOT; pwd)
402 fi
403 (
404 # Create package path early to avoid dependencies loop
405 mkdir -p $TMP_DIR
406 ( cd $TMP_DIR ; cpio -i receipt > /dev/null) < $PACKAGE_FILE
407 . $TMP_DIR/receipt
408 if grep -q ^pre_depends $TMP_DIR/receipt; then
409 pre_depends $ROOT
410 fi
411 # keep modifers and file list on upgrade
412 cp $ROOT$INSTALLED/$PACKAGE/modifiers \
413 $ROOT$INSTALLED/$PACKAGE/files.list $TMP_DIR 2> /dev/null
414 rm -rf $ROOT$INSTALLED/$PACKAGE 2> /dev/null
415 # Make the installed package data dir to store
416 # the receipt and the files list.
417 mkdir -p $ROOT$INSTALLED/$PACKAGE
418 cp $TMP_DIR/modifiers $ROOT$INSTALLED/$PACKAGE 2> /dev/null
419 cp $TMP_DIR/files.list $ROOT$INSTALLED/$PACKAGE 2> /dev/null
420 rm -rf $TMP_DIR 2> /dev/null
421 sed -i "/ $(basename $PACKAGE_FILE)$/d" \
422 $ROOT$LOCALSTATE/installed.md5 2> /dev/null
423 cd $(dirname $PACKAGE_FILE)
424 md5sum $(basename $PACKAGE_FILE) >> $ROOT$LOCALSTATE/installed.md5
425 )
426 # Resolve package deps.
427 check_for_deps $ROOT
428 if [ ! "$MISSING_PACKAGE" = "" ]; then
429 install_deps $ROOT
430 fi
431 mkdir -p $TMP_DIR
432 [ -n "$INSTALL_LIST" ] && echo "$PACKAGE_FILE" >> $INSTALL_LIST-processed
433 echo ""
434 echo -e "\033[1mInstallation of :\033[0m $PACKAGE"
435 echo "================================================================================"
436 echo -n "Copying $PACKAGE... "
437 cp $PACKAGE_FILE $TMP_DIR
438 status
439 cd $TMP_DIR
440 extract_package
441 SELF_INSTALL=0
442 EXTRAVERSION=""
443 CONFIG_FILES=""
444 # Include temporary receipt to get the right variables.
445 . $PWD/receipt
446 cd $ROOT$INSTALLED
447 if [ $SELF_INSTALL -ne 0 -a -n "$ROOT" ]; then
448 echo -n "Checking post install dependencies... "
449 [ -f $INSTALLED/$PACKAGE/receipt ]
450 if ! status; then
451 echo "Please run 'tazpkg install $PACKAGE_FILE' in / and retry."
452 rm -rf $TMP_DIR
453 exit 1
454 fi
455 fi
456 # Get files to remove if upgrading
457 if [ -f $PACKAGE/files.list ]; then
458 while read file; do
459 grep -q "^$file$" $TMP_DIR/files.list && continue
460 for i in $(cat $PACKAGE/modifiers 2> /dev/null ;
461 grep -sl $PACKAGE */modifiers | cut -d/ -f1 ); do
462 grep -q "^$file$" $i/files.list && continue 2
463 done
464 echo $file
465 done < $PACKAGE/files.list > $TMP_DIR/files2remove.list
466 fi
467 # Remember modified packages
468 for i in $(grep -v '\[' files.list); do
469 [ -e "$ROOT$i" ] || continue
470 [ -d "$ROOT$i" ] && continue
471 for j in $(grep -l "^$i$" */files.list); do
472 local dir
473 dir=$(dirname $j)
474 [ "$j" = "$PACKAGE/files.list" ] && continue
475 if grep -qs ^$dir$ $PACKAGE/modifiers; then
476 # Do not overload an overloaded file !
477 rm $TMP_DIR$i 2> /dev/null
478 continue
479 fi
480 grep -qs ^$PACKAGE$ $dir/modifiers && continue
481 if [ -s "$dir/volatile.cpio.gz" ]; then
482 # We can modify backed up files
483 zcat $dir/volatile.cpio.gz | \
484 cpio -t 2> /dev/null | \
485 grep -q "^${i#/}$" && continue
486 fi
487 echo "$PACKAGE" >> $dir/modifiers
488 done
489 done
490 cd $TMP_DIR
491 cp receipt files.list $ROOT$INSTALLED/$PACKAGE
492 # Copy the description if found.
493 if [ -f "description.txt" ]; then
494 cp description.txt $ROOT$INSTALLED/$PACKAGE
495 fi
496 # Copy the md5sum if found.
497 if [ -f "md5sum" ]; then
498 cp md5sum $ROOT$INSTALLED/$PACKAGE
499 fi
500 # Pre install commands.
501 if grep -q ^pre_install $ROOT$INSTALLED/$PACKAGE/receipt; then
502 pre_install $ROOT
503 fi
504 if [ -n "$CONFIG_FILES" ]; then
505 # save 'official' configuration files
506 echo -n "Save configuration files for $PACKAGE... "
507 for i in $CONFIG_FILES; do
508 ( cd fs ; find ${i#/} -type f )
509 done | ( cd fs ; cpio -o -H newc | gzip -9 ) > \
510 $ROOT$INSTALLED/$PACKAGE/volatile.cpio.gz
511 # keep user configuration files
512 for i in $CONFIG_FILES; do
513 ( cd fs ; find ${i#/} -type f )
514 done | while read i; do
515 [ -e $ROOT/$i ] || continue
516 cp -a $ROOT/$i fs/$i
517 done
518 status
519 fi
520 echo -n "Installing $PACKAGE... "
521 cp -a fs/* $ROOT/
522 status
523 if [ -s files2remove.list ]; then
524 echo -n "Removing old $PACKAGE... "
525 while read file; do
526 rm -f $ROOT$file
527 dir=$(dirname $ROOT$file)
528 while true; do
529 rmdir $dir 2> /dev/null || { true; break; }
530 dir=$(dirname $dir)
531 done
532 done < files2remove.list
533 status
534 fi
535 # Remove the temporary random directory.
536 echo -n "Removing all tmp files... "
537 cd .. && rm -rf $TMP_DIR
538 status
539 # Post install commands.
540 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
541 post_install $ROOT
542 fi
543 cd $TOP_DIR
544 echo "================================================================================"
545 echo "$PACKAGE ($VERSION$EXTRAVERSION) is installed."
546 echo ""
547 # Log this activity
548 [ -n "$ROOT" ] || log Installed
549 }
551 # Check for loop in deps tree.
552 check_for_deps_loop()
553 {
554 local list
555 local pkg
556 local deps
557 pkg=$1
558 shift
559 [ -n "$1" ] || return
560 list=""
561 # Filter out already processed deps
562 for i in $@; do
563 case " $ALL_DEPS" in
564 *\ $i\ *);;
565 *) list="$list $i";;
566 esac
567 done
568 ALL_DEPS="$ALL_DEPS$list "
569 for i in $list; do
570 [ -f $i/receipt ] || continue
571 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
572 case " $deps " in
573 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
574 *) check_for_deps_loop $pkg $deps;;
575 esac
576 done
577 }
579 # Check for missing deps listed in a receipt packages.
580 check_for_deps()
581 {
582 local saved;
583 saved=$PACKAGE
584 mkdir -p $TMP_DIR
585 ( cd $TMP_DIR ; cpio -i receipt > /dev/null ) < $PACKAGE_FILE
586 . $TMP_DIR/receipt
587 PACKAGE=$saved
588 rm -rf $TMP_DIR
589 for pkgorg in $DEPENDS
590 do
591 i=$(equivalent_pkg $pkgorg $1)
592 if [ ! -d "$1$INSTALLED/$i" ]; then
593 MISSING_PACKAGE=$i
594 deps=$(($deps+1))
595 elif [ ! -f "$1$INSTALLED/$i/receipt" ]; then
596 echo -e "$WARNING Dependency loop between $PACKAGE and $i."
597 fi
598 done
599 if [ ! "$MISSING_PACKAGE" = "" ]; then
600 echo -e "\033[1mTracking dependencies for :\033[0m $PACKAGE"
601 echo "================================================================================"
602 for pkgorg in $DEPENDS
603 do
604 i=$(equivalent_pkg $pkgorg $1)
605 if [ ! -d "$1$INSTALLED/$i" ]; then
606 MISSING_PACKAGE=$i
607 echo "Missing : $MISSING_PACKAGE"
608 fi
609 done
610 echo "================================================================================"
611 echo "$deps missing package(s) to install."
612 fi
613 }
615 # Install all missing deps. First ask user then install all missing deps
616 # from local dir, cdrom, media or from the mirror. In case we want to
617 # install packages from local, we need a packages.list to find the version.
618 install_deps()
619 {
620 local root
621 root=""
622 [ -n "$1" ] && root="--root=$1"
623 echo ""
624 echo -n "Install all missing dependencies (y/N) ? "; read anser
625 echo ""
626 if [ "$anser" = "y" ]; then
627 for pkgorg in $DEPENDS
628 do
629 pkg=$(equivalent_pkg $pkgorg $1)
630 if [ ! -d "$1$INSTALLED/$pkg" ]; then
631 local list
632 list="$INSTALL_LIST"
633 [ -n "$list" ] || list="$TOP_DIR/packages.list"
634 # We can install packages from a local dir by greping
635 # the TAZPKG_BASENAME in the local packages.list.
636 found=0
637 if [ -f "$list" ]; then
638 echo "Checking if $pkg exists in local list... "
639 mkdir $TMP_DIR
640 for i in $pkg-*.tazpkg; do
641 [ -f $i ] || continue
642 ( cd $TMP_DIR ; cpio -i receipt > /dev/null) < $i
643 [ "$(. $TMP_DIR/receipt; echo $PACKAGE)" = "$pkg" ] || continue
644 if grep -q ^$(package_fullname_in_dir $TMP_DIR).tazpkg$ $list
645 then
646 found=1
647 tazpkg install $i $root --list=$list
648 break
649 fi
650 done
651 rm -rf $TMP_DIR
652 fi
653 # Install deps from the mirror.
654 if [ $found -eq 0 ]; then
655 if [ ! -f "$LOCALSTATE/packages.list" ]; then
656 tazpkg recharge
657 fi
658 tazpkg get-install $pkg $root
659 fi
660 fi
661 done
662 else
663 echo -e "\nLeaving dependencies for $PACKAGE unsolved."
664 echo -e "The package is installed but will probably not work.\n"
665 fi
666 }
668 # xHTML packages list header.
669 xhtml_header()
670 {
671 cat > $XHTML_LIST << _EOT_
672 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
673 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
674 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
675 <head>
676 <title>Installed packages list</title>
677 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
678 <meta name="modified" content="$DATE" />
679 <meta name="generator" content="Tazpkg" />
680 <style type="text/css"><!--
681 body { font: 12px sans-serif, vernada, arial; margin: 0; }
682 #header { background: #f0ba08; color: black; height: 50px;
683 border-top: 1px solid black; border-bottom: 1px solid black; }
684 #content { margin: 0px 50px 26px 50px; }
685 #footer { border-top: 1px solid black; padding-top: 10px;}
686 h1 { margin: 14px 0px 0px 16px; }
687 pre { padding-left: 5px; }
688 hr { color: white; background: white; height: 1px; border: 0; }
689 --></style>
690 </head>
691 <body bgcolor="#ffffff">
692 <div id="header">
693 <h1><font color="#3e1220">Installed packages list</font></h1>
694 </div>
695 <hr />
696 <!-- Start content -->
697 <div id="content">
699 <p>
700 _packages_ packages installed - List generated on : $DATE
701 <p>
703 _EOT_
704 }
706 # xHTML content with packages info.
707 xhtml_pkg_info()
708 {
709 cat >> $XHTML_LIST << _EOT_
710 <h3>$PACKAGE</h3>
711 <pre>
712 Version : $VERSION$EXTRAVERSION
713 Short desc : $SHORT_DESC
714 Web site : <a href="$WEB_SITE">$WEB_SITE</a>
715 </pre>
717 _EOT_
718 }
720 # xHTML packages list footer.
721 xhtml_footer()
722 {
723 cat >> $XHTML_LIST << _EOT_
724 <hr />
725 <p id="footer">
726 $packages packages installed - List generated on : $DATE
727 </p>
729 <!-- End content -->
730 </div>
731 </body>
732 </html>
733 _EOT_
734 }
736 # Search pattern in installed packages.
737 search_in_installed_packages()
738 {
739 echo "Installed packages"
740 echo "================================================================================"
741 list=`ls -1 $INSTALLED | grep -i "$PATTERN"`
742 for pkg in $list
743 do
744 EXTRAVERSION=""
745 [ -f $INSTALLED/$pkg/receipt ] || continue
746 . $INSTALLED/$pkg/receipt
747 echo -n "$PACKAGE "
748 echo -en "\033[24G $VERSION$EXTRAVERSION"
749 echo -e "\033[42G $CATEGORY"
750 packages=$(($packages+1))
751 done
752 # Set correct ending messages.
753 if [ "$packages" = "" ]; then
754 echo "0 installed packages found for : $PATTERN"
755 echo ""
756 else
757 echo "================================================================================"
758 echo "$packages installed package(s) found for : $PATTERN"
759 echo ""
760 fi
761 }
763 # Search in packages.list for available pkgs.
764 search_in_packages_list()
765 {
766 echo "Available packages name-version"
767 echo "================================================================================"
768 packages=0
769 for i in $LOCALSTATE/packages.list $LOCALSTATE/undigest/*/packages.list; do
770 grep -is "$PATTERN" $i
771 packages=$(($packages + `grep -is "$PATTERN" $i | wc -l`))
772 done
773 if [ ! -f "$LOCALSTATE/packages.list" ]; then
774 echo -e "
775 No 'packages.list' found to check for mirrored packages. For more results,
776 please run 'tazpkg recharge' once as root before searching.\n"
777 fi
778 if [ "$packages" = "0" ]; then
779 echo "0 available packages found for : $PATTERN"
780 echo ""
781 else
782 echo "================================================================================"
783 echo "$packages available package(s) found for : $PATTERN"
784 echo ""
785 fi
786 }
788 # search --mirror: Search in packages.txt for available pkgs and give more
789 # info than --list or default.
790 search_in_packages_txt()
791 {
792 echo "Matching packages name with version and desc"
793 echo "================================================================================"
794 packages=0
795 for i in $LOCALSTATE/packages.txt $LOCALSTATE/undigest/*/packages.txt; do
796 grep -is -A 2 "^$PATTERN" $i
797 packages=$(($packages + `grep -is "^$PATTERN" $i | wc -l`))
798 done
799 if [ ! -f "$LOCALSTATE/packages.txt" ]; then
800 echo -e "
801 No 'packages.txt' found to check for mirrored packages. For more results,
802 please run 'tazpkg recharge' once as root before searching.\n"
803 fi
804 if [ "$packages" = "0" ]; then
805 echo "0 available packages found for : $PATTERN"
806 echo ""
807 else
808 echo "================================================================================"
809 echo "$packages available package(s) found for : $PATTERN"
810 echo ""
811 fi
812 }
814 # Install package-list from a flavor
815 install_flavor()
816 {
817 check_root
818 FLAVOR=$1
819 ARG=$2
820 mkdir -p $TMP_DIR
821 [ -f $FLAVOR.flavor ] && cp $FLAVOR.flavor $TMP_DIR
822 cd $TMP_DIR
823 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
824 zcat $FLAVOR.flavor | cpio -i 2>/dev/null
825 while read file; do
826 for pkg in $(ls -d $INSTALLED/${file%%-*}*); do
827 [ -f $pkg/receipt ] || continue
828 EXTRAVERSION=""
829 . $pkg/receipt
830 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && break
831 done
832 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && continue
833 cd $CACHE_DIR
834 download $file.tazpkg
835 cd $TMP_DIR
836 tazpkg install $CACHE_DIR/$file.tazpkg --forced
837 done < $FLAVOR.pkglist
838 [ -f $FLAVOR.nonfree ] && while read pkg; do
839 [ -d $INSTALLED/$pkg ] || continue
840 [ -d $INSTALLED/get-$pkg ] && tazpkg get-install get-$pkg
841 get-$pkg
842 done < $FLAVOR.nonfree
843 [ "$ARG" == "--purge" ] && for pkg in $(ls $INSTALLED); do
844 [ -f $INSTALLED/$pkg/receipt ] || continue
845 EXTRAVERSION=""
846 . $INSTALLED/$pkg/receipt
847 grep -q ^$PACKAGE-$VERSION$EXTRAVERSION$ $FLAVOR.pkglist && continue
848 grep -qs ^$PACKAGE$ $FLAVOR.nonfree && continue
849 tazpkg remove $PACKAGE
850 done
851 else
852 echo "Can't find flavor $FLAVOR Abort."
853 fi
854 cd $TOP_DIR
855 rm -rf $TMP_DIR
856 }
858 # Update mirror urls
859 setup_mirror()
860 {
861 # Backup old list.
862 if [ -f "$1/mirror" ]; then
863 cp -f $1/mirror $1/mirror.bak
864 fi
865 echo ""
866 echo -e "\033[1mCurrent mirror(s)\033[0m"
867 echo "================================================================================"
868 echo " `cat $1/mirror 2> /dev/null`"
869 echo "
870 Please enter URL of the new mirror (http, ftp or local path). You must specify
871 the complete address to the directory of the packages and packages.list file."
872 echo ""
873 echo -n "New mirror(s) URL : "
874 NEW_MIRROR_URL=$2
875 if [ -n "$NEW_MIRROR_URL" ]; then
876 echo $NEW_MIRROR_URL
877 else
878 read NEW_MIRROR_URL
879 fi
880 if [ "$NEW_MIRROR_URL" = "" ]; then
881 echo "Nothing has been changed."
882 else
883 echo "Setting mirror(s) to : $NEW_MIRROR_URL"
884 rm -f $1/mirror
885 for i in $NEW_MIRROR_URL; do
886 echo "$i" >> $1/mirror
887 done
888 fi
889 echo ""
890 }
892 # recursive dependencies scan
893 dep_scan()
894 {
895 for i in $1; do
896 case " $ALL_DEPS " in
897 *\ $i\ *) continue;;
898 esac
899 ALL_DEPS="$ALL_DEPS $i"
900 [ -n "$2" ] && echo "$2$i"
901 [ -f $i/receipt ] || continue
902 DEPENDS=""
903 . $i/receipt
904 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
905 done
906 }
908 # recursive reverse dependencies scan
909 rdep_scan()
910 {
911 SEARCH=$1
913 for i in * ; do
914 DEPENDS=""
915 . $i/receipt
916 echo "$i $(echo $DEPENDS)"
917 done | awk -v search=$SEARCH '
918 function show_deps(deps, all_deps, pkg, space)
919 {
920 if (all_deps[pkg] == 1) return
921 all_deps[pkg] = 1
922 if (space != "") printf "%s%s\n",space,pkg
923 for (i = 1; i <= split(deps[pkg], mydeps, " "); i++) {
924 show_deps(deps, all_deps, mydeps[i]," " space)
925 }
926 }
928 {
929 all_deps[$1] = 0
930 for (i = 2; i <= NF; i++)
931 deps[$i] = deps[$i] " " $1
932 }
934 END {
935 show_deps(deps, all_deps, search, "")
936 }
937 '
938 }
940 # Check for ELF file
941 is_elf()
942 {
943 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
944 }
946 # Print shared library dependencies
947 ldd()
948 {
949 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
950 }
952 # search dependencies for files in $TMP_DIR/$file/fs
953 find_depends()
954 {
955 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
957 [ -f /var/lib/tazpkg/files.list.lzma ] || tazpkg recharge
958 for i in /var/lib/tazpkg/files.list.lzma \
959 /var/lib/tazpkg/undigest/*/files.list.lzma ; do
960 [ -f $i ] && lzma d $i -so >> $TMP_DIR/files.list
961 done
962 find $TMP_DIR/$file/fs -type f | while read file ; do
963 is_elf $file || continue
964 case "$file" in
965 *.o|*.ko|*.ko.gz) continue;;
966 esac
967 ldd $file | while read lib rem; do
968 case "$lib" in
969 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
970 continue;;
971 esac
972 for dep in $(grep $lib files.list | cut -d: -f1); do
973 case " $DEFAULT_DEPENDS $ALL_DEPENDS " in
974 *\ $dep\ *) continue 2;;
975 esac
976 done
977 ALL_DEPENDS="$ALL_DEPENDS $dep"
978 if [ -n "$dep" ]; then
979 echo -n " $dep"
980 else
981 echo "$lib" >> $TMP_DIR/unresolved
982 fi
983 done
984 done
985 }
987 show_unresolved_lib()
988 {
989 if [ -s $TMP_DIR/unresolved ]; then
990 echo "BUGS=\"No dependency for $(cat $TMP_DIR/unresolved)\"" >> $1
991 for lib in $(cat $TMP_DIR/unresolved) ; do
992 echo -e "$WARNING: unknown dependency for $lib"
993 done
994 fi
995 }
997 # convert a .tgz package to .tazpkg
998 convert_tgz()
999 {
1000 package=$(basename $PACKAGE_FILE)
1001 IFS='-'
1002 set -- $package
1003 unset IFS
1004 package=$1
1005 version=$2
1006 file="$package-$version"
1007 mkdir -p $TMP_DIR/$file/fs
1008 tar xzf $PACKAGE_FILE -C $TMP_DIR/$file/fs
1009 cd $TMP_DIR
1010 if [ -d $file/fs/install ]; then
1011 descrip=$(grep ^$package $file/fs/install/slack-desc | \
1012 head -1 | sed 's/.*(\(.*\)).*/\1/')
1013 cat > $file/receipt <<EOT
1014 # SliTaz package receipt.
1015 # generated by tazpkg from slackware package $(basename $PACKAGE_FILE)
1016 PACKAGE="$package"
1017 VERSION="$version"
1018 CATEGORY="misc"
1019 SHORT_DESC="$descrip"
1020 WEB_SITE="http://www.slackware.com/packages/"
1021 MAINTAINER="nobody@slitaz.org"
1022 DEPENDS="$(find_depends)"
1023 EOT
1024 show_unresolved_lib $file/receipt
1025 [ -f $file/fs/install/doinst.sh ] && cat >> $file/receipt <<EOM
1027 post_install()
1029 chroot \$1/ sh - << EOT
1030 cd /
1031 $(cat $file/fs/install/doinst.sh | sed -e 's/\\/\\\\/g' | sed -e 's/\$/\\$/g')
1032 EOT
1034 EOM
1035 grep ^$package $file/fs/install/slack-desc | \
1036 sed "s/^$package://" > $file/description.txt
1037 rm -rf $file/fs/install
1038 tazpkg pack $file
1039 mv $file.tazpkg $TOP_DIR
1040 else
1041 echo "$PACKAGE_FILE does not look like a Slackware package !"
1042 fi
1043 cd $TOP_DIR
1044 rm -rf $TMP_DIR
1047 # convert a .deb package to .tazpkg
1048 convert_deb()
1050 mkdir -p $TMP_DIR
1051 dpkg-deb -e $PACKAGE_FILE $TMP_DIR
1052 package=$(grep '^ *Package' $TMP_DIR/control)
1053 package=$(echo ${package##*:})
1054 version=$(grep '^ *Version' $TMP_DIR/control)
1055 version=$(echo ${version##*:})
1056 descrip=$(grep '^ *Description' $TMP_DIR/control)
1057 descrip=$(echo ${descrip##*:})
1058 file="$package-$version"
1059 mkdir -p $TMP_DIR/$file/fs/
1060 dpkg-deb -x $PACKAGE_FILE $TMP_DIR/$file/fs
1061 cd $TMP_DIR
1062 cat > $file/receipt <<EOT
1063 # SliTaz package receipt.
1064 # generated by tazpkg from debian package $(basename $PACKAGE_FILE)
1065 PACKAGE="$package"
1066 VERSION="$version"
1067 CATEGORY="misc"
1068 SHORT_DESC="$descrip"
1069 WEB_SITE="http://packages.debian.org/search?keywords=$package"
1070 MAINTAINER="nobody@slitaz.org"
1071 DEPENDS="$(find_depends)"
1072 EOT
1073 show_unresolved_lib $file/receipt
1074 awk '
1076 if (/^ / && show) print substr($0,2);
1077 else show=0;
1078 if (/^Description/) show=1;
1079 }' < $TMP_DIR/control > $file/description.txt
1080 sed -i 's/^\.$//' $file/description.txt
1081 tazpkg pack $file
1082 mv $file.tazpkg $TOP_DIR
1083 cd $TOP_DIR
1084 rm -rf $TMP_DIR
1087 # convert a .rpm package to .tazpkg
1088 convert_rpm()
1090 mkdir -p $TMP_DIR
1091 cp $PACKAGE_FILE $TMP_DIR
1092 PACKAGE_FILE=$TMP_DIR/$(basename $PACKAGE_FILE)
1093 rpm -qip $PACKAGE_FILE | awk -v pkg=$(basename $PACKAGE_FILE) '
1094 BEGIN {
1095 goturl=0;
1096 printf "# Taz package receipt.\n";
1097 printf "# generated by tazpkg from rpm package %s\n",pkg;
1100 if (/^Name/) { name=$3; printf "PACKAGE=\"%s\"\n",$3; }
1101 if (/^Version/) printf "VERSION=\"%s-",$3;
1102 if (/^Release/) printf "%s\"\n",$3;
1103 if (/^Summary/) printf "SHORT_DESC=\"%s\"\n",substr($0,15);
1104 if (/^URL/) { goturl=1; printf "WEB_SITE=\"%s\"\n",$3; }
1106 END {
1107 if (goturl == 0)
1108 printf "WEB_SITE=\"http://rpmfind.net/linux/rpm2html/search.php?query=%s\"\n",name;
1109 printf "CATEGORY=\"misc\"\n";
1110 printf "MAINTAINER=\"nobody@slitaz.org\"\n";
1112 ' > $TMP_DIR/receipt
1113 . $TMP_DIR/receipt
1114 file=$PACKAGE-$VERSION
1115 mkdir -p $TMP_DIR/$file/fs/
1116 mv $TMP_DIR/receipt $TMP_DIR/$file
1117 rpm -qip $PACKAGE_FILE | awk '
1118 DEGIN { show=0 }
1120 if (show) print;
1121 if (/^Description/) show=1;
1123 ' > $TMP_DIR/$file/description.txt
1124 cd $TMP_DIR/$file/fs/
1125 rpm2cpio $PACKAGE_FILE | cpio -idm
1126 cd ../..
1127 echo "DEPENDS=\"$(find_depends)\"" >> $TMP_DIR/$file/receipt
1128 show_unresolved_lib $TMP_DIR/$file/receipt
1129 tazpkg pack $file
1130 mv $file.tazpkg $TOP_DIR
1131 cd $TOP_DIR
1132 rm -rf $TMP_DIR
1135 ###################
1136 # Tazpkg commands #
1137 ###################
1139 case "$COMMAND" in
1140 list)
1141 # List all installed packages or a specific category.
1143 if [ "$2" = "blocked" ]; then
1144 echo ""
1145 echo -e "\033[1mBlocked packages\033[0m"
1146 echo "================================================================================"
1147 if [ -s "$BLOCKED" ];then
1148 cat $BLOCKED
1149 echo ""
1150 else
1151 echo -e "No blocked packages found.\n"
1152 fi
1153 exit 0
1154 fi
1155 # Display the list of categories.
1156 if [ "$2" = "cat" -o "$2" = "categories" ]; then
1157 echo ""
1158 echo -e "\033[1mPackages categories :\033[0m"
1159 echo "================================================================================"
1160 for i in $CATEGORIES
1161 do
1162 echo $i
1163 categories=$(($categories+1))
1164 done
1165 echo "================================================================================"
1166 echo "$categories categories"
1167 echo ""
1168 exit 0
1169 fi
1170 # Check for an asked category.
1171 if [ -n "$2" ]; then
1172 ASKED_CATEGORY=$2
1173 echo ""
1174 echo -e "\033[1mInstalled packages of category :\033[0m $ASKED_CATEGORY"
1175 echo "================================================================================"
1176 for pkg in $INSTALLED/*
1177 do
1178 [ -f $pkg/receipt ] || continue
1179 EXTRAVERSION=""
1180 . $pkg/receipt
1181 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
1182 echo -n "$PACKAGE"
1183 echo -e "\033[24G $VERSION$EXTRAVERSION"
1184 packages=$(($packages+1))
1185 fi
1186 done
1187 echo "================================================================================"
1188 echo -e "$packages packages installed of category $ASKED_CATEGORY."
1189 echo ""
1190 else
1191 # By default list all packages and versions.
1192 echo ""
1193 echo -e "\033[1mList of all installed packages\033[0m"
1194 echo "================================================================================"
1195 for pkg in $INSTALLED/*
1196 do
1197 [ -f $pkg/receipt ] || continue
1198 EXTRAVERSION=""
1199 . $pkg/receipt
1200 echo -n "$PACKAGE"
1201 echo -en "\033[24G $VERSION$EXTRAVERSION"
1202 echo -e "\033[42G $CATEGORY"
1203 packages=$(($packages+1))
1204 done
1205 echo "================================================================================"
1206 echo "$packages packages installed."
1207 echo ""
1208 fi
1209 ;;
1210 xhtml-list)
1211 # Get info in receipts and build list.
1212 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
1213 if [ -n "$2" ]; then
1214 XHTML_LIST=$2
1215 else
1216 XHTML_LIST=installed-packages.html
1217 fi
1218 echo ""
1219 echo -e "\033[1mCreating xHTML list of installed packages\033[0m"
1220 echo "================================================================================"
1221 echo -n "Generating xHTML header..."
1222 xhtml_header
1223 status
1224 # Packages
1225 echo -n "Creating packages information..."
1226 for pkg in $INSTALLED/*
1227 do
1228 [ -f $pkg/receipt ] || continue
1229 EXTRAVERSION=""
1230 . $pkg/receipt
1231 xhtml_pkg_info
1232 packages=$(($packages+1))
1233 done
1234 status
1235 echo -n "Generating xHTML footer..."
1236 xhtml_footer
1237 status
1238 # sed pkgs nb in header.
1239 sed -i s/'_packages_'/"$packages"/ $XHTML_LIST
1240 echo "================================================================================"
1241 echo "$XHTML_LIST created - $packages packages."
1242 echo ""
1243 ;;
1244 list-mirror)
1245 # List all available packages on the mirror. Option --diff displays
1246 # last mirrored packages diff (see recharge).
1247 check_for_packages_list
1248 case $2 in
1249 --diff)
1250 if [ -f "$LOCALSTATE/packages.diff" ]; then
1251 echo ""
1252 echo -e "\033[1mMirrored packages diff\033[0m"
1253 echo "================================================================================"
1254 cat $LOCALSTATE/packages.diff
1255 echo "================================================================================"
1256 pkgs=`cat $LOCALSTATE/packages.diff | wc -l`
1257 echo "$pkgs new packages listed on the mirror."
1258 echo ""
1259 else
1260 echo -e "\nUnable to list anything, no packages.diff found."
1261 echo -e "Recharge your current list to create a first diff.\n"
1262 fi && exit 0 ;;
1263 --text|--txt)
1264 echo ""
1265 echo -e "\033[1mList of available packages on the mirror\033[0m"
1266 echo "================================================================================"
1267 cat $LOCALSTATE/packages.txt ;;
1268 --raw|*)
1269 echo ""
1270 echo -e "\033[1mList of available packages on the mirror\033[0m"
1271 echo "================================================================================"
1272 cat $LOCALSTATE/packages.list ;;
1273 esac
1274 echo "================================================================================"
1275 pkgs=`cat $LOCALSTATE/packages.list | wc -l`
1276 echo "$pkgs packages in the last recharged list."
1277 echo ""
1278 ;;
1279 list-files)
1280 # List files installed with the package.
1282 check_for_package_on_cmdline
1283 check_for_receipt
1284 echo ""
1285 echo -e "\033[1mInstalled files with :\033[0m $PACKAGE"
1286 echo "================================================================================"
1287 cat $INSTALLED/$PACKAGE/files.list | sort
1288 echo "================================================================================"
1289 files=`cat $INSTALLED/$PACKAGE/files.list | wc -l`
1290 echo "$files files installed with $PACKAGE."
1291 echo ""
1292 ;;
1293 info)
1294 # Information about package.
1296 check_for_package_on_cmdline
1297 check_for_receipt
1298 EXTRAVERSION=""
1299 . $INSTALLED/$PACKAGE/receipt
1300 echo ""
1301 echo -e "\033[1mTazpkg information\033[0m
1302 ================================================================================
1303 Package : $PACKAGE
1304 Version : $VERSION$EXTRAVERSION
1305 Category : $CATEGORY
1306 Short desc : $SHORT_DESC
1307 Maintainer : $MAINTAINER"
1308 if [ ! "$DEPENDS" = "" ]; then
1309 echo -e "Depends : $DEPENDS"
1310 fi
1311 if [ ! "$SUGGESTED" = "" ]; then
1312 echo -e "Suggested : $SUGGESTED"
1313 fi
1314 if [ ! "$BUILD_DEPENDS" = "" ]; then
1315 echo -e "Build deps : $BUILD_DEPENDS"
1316 fi
1317 if [ ! "$WANTED" = "" ]; then
1318 echo -e "Wanted src : $WANTED"
1319 fi
1320 if [ ! "$WEB_SITE" = "" ]; then
1321 echo -e "Web site : $WEB_SITE"
1322 fi
1323 echo "================================================================================"
1324 echo ""
1325 ;;
1326 desc)
1327 # Display package description.txt if available.
1328 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
1329 echo ""
1330 echo -e "\033[1mDescription of :\033[0m $PACKAGE"
1331 echo "================================================================================"
1332 cat $INSTALLED/$PACKAGE/description.txt
1333 echo "================================================================================"
1334 echo ""
1335 else
1336 echo -e "\nSorry, no description available for this package.\n"
1337 fi
1338 ;;
1339 search)
1340 # Search for a package by pattern or name.
1342 PATTERN="$2"
1343 if [ -z "$PATTERN" ]; then
1344 echo -e "\nPlease specify a pattern or package name to search for."
1345 echo -e "Example : 'tazpkg search paint'.\n"
1346 exit 0
1347 fi
1348 echo ""
1349 echo -e "\033[1mSearch result for :\033[0m $PATTERN"
1350 echo ""
1351 # Default is to search in installed pkgs and the raw list.
1352 case $3 in
1353 -i|--installed)
1354 search_in_installed_packages ;;
1355 -l|--list)
1356 search_in_packages_list ;;
1357 -m|--mirror)
1358 search_in_packages_txt ;;
1359 *)
1360 search_in_installed_packages
1361 search_in_packages_list ;;
1362 esac
1363 ;;
1364 search-file)
1365 # Search for a file by pattern or name in all files.list.
1367 if [ -z "$2" ]; then
1368 echo -e "\nPlease specify a pattern or file name to search for."
1369 echo -e "Example : 'tazpkg search-file libnss'. \n"
1370 exit 0
1371 fi
1372 echo ""
1373 echo -e "\033[1mSearch result for file :\033[0m $2"
1374 echo "================================================================================"
1376 if [ "$3" == "--mirror" ]; then
1378 match=0
1379 for i in $LOCALSTATE/files.list.lzma \
1380 $LOCALSTATE/undigest/*/files.list.lzma; do
1381 [ -f $i ] || continue
1382 unlzma -c $i | grep -- ".*:.*$2" | awk '
1383 BEGIN { last="" }
1385 pkg=substr($0,0,index($0,":")-1);
1386 file=substr($0,index($0,":")+2);
1387 if (last != pkg) {
1388 last = pkg;
1389 printf("\n%c[1mPackage %s :%c[0m\n",27,pkg,27);
1391 printf("%s\n",file);
1392 }'
1393 match=$(($match + `unlzma -c $i | grep -- ".*:.*$2" | wc -l`))
1394 done
1396 else
1398 # Check all pkg files.list in search match with specify the package
1399 # name and the full path to the file(s).
1400 for pkg in $INSTALLED/*
1401 do
1402 if grep -qs "$2" $pkg/files.list; then
1403 . $pkg/receipt
1404 echo ""
1405 echo -e "\033[1mPackage $PACKAGE :\033[0m"
1406 grep "$2" $pkg/files.list
1407 files=`grep $2 $pkg/files.list | wc -l`
1408 match=$(($match+$files))
1409 fi
1410 done
1412 fi
1414 if [ "$match" = "" ]; then
1415 echo "0 file found for : $2"
1416 echo ""
1417 else
1418 echo ""
1419 echo "================================================================================"
1420 echo "$match file(s) found for : $2"
1421 echo ""
1422 fi
1423 ;;
1424 install)
1425 # Install .tazpkg packages.
1427 check_root
1428 check_for_package_on_cmdline
1429 check_for_package_file
1430 # Check if forced install.
1431 DO_CHECK="yes"
1432 ROOT=""
1433 while [ -n "$3" ]; do
1434 case "$3" in
1435 --forced)
1436 DO_CHECK="no"
1437 ;;
1438 --root=*)
1439 ROOT="${3#--root=}"
1440 ;;
1441 --list=*)
1442 INSTALL_LIST="${3#--list=}"
1443 ;;
1444 *) shift 2
1445 echo -e "\nUnknown option $*.\n"
1446 exit 1
1447 ;;
1448 esac
1449 shift
1450 done
1451 if [ "$DO_CHECK" = "yes" ]; then
1452 check_for_installed_package $ROOT
1453 fi
1454 install_package $ROOT
1455 ;;
1456 install-list|get-install-list)
1457 # Install a set of packages from a list.
1459 check_root
1460 if [ -z "$2" ]; then
1461 echo -e "
1462 Please change directory (cd) to the packages repository, and specify the
1463 list of packages to install. Example : tazpkg install-list packages.list\n"
1464 exit 0
1465 fi
1466 # Check if the packages list exist.
1467 if [ ! -f "$2" ]; then
1468 echo "Unable to find : $2"
1469 exit 0
1470 else
1471 LIST=`cat $2`
1472 fi
1474 # Remember processed list
1475 export INSTALL_LIST="$2"
1477 # Set $COMMAND and install all packages.
1478 if [ "$1" = "get-install-list" ]; then
1479 COMMAND=get-install
1480 else
1481 COMMAND=install
1482 fi
1483 touch $2-processed
1484 for pkg in $LIST
1485 do
1486 grep -qs ^$pkg$ $2-processed && continue
1487 tazpkg $COMMAND $pkg --list=$2 "$3" "$4" "$5"
1488 done
1489 rm -f $2-processed
1490 ;;
1491 add-flavor)
1492 # Install a set of packages from a flavor.
1494 install_flavor $2
1495 ;;
1496 install-flavor)
1497 # Install a set of packages from a flavor and purge other ones.
1499 install_flavor $2 --purge
1500 ;;
1501 set-release)
1502 # Change curent release and upgrade packages.
1504 RELEASE=$2
1505 if [ -z "$RELEASE" ]; then
1506 echo -e "\nPlease specify the release you want on the command line."
1507 echo -e "Example: tazpkg set-release cooking\n"
1508 exit 0
1509 fi
1510 rm /var/lib/tazpkg/mirror
1511 echo "$RELEASE" > /etc/slitaz-release
1512 tazpkg recharge && tazpkg upgrade
1514 # Install missing depends
1515 cd $INSTALLED
1516 for i in * ; do
1517 DEPENDS=""
1518 . $i/receipt
1519 for j in $DEPENDS ; do
1520 [ -d $j ] || tazpkg get-install $j
1521 done
1522 done
1523 ;;
1524 remove)
1525 # Remove packages.
1527 check_root
1528 check_for_package_on_cmdline
1529 if [ ! -f "$INSTALLED/$PACKAGE/receipt" ]; then
1530 echo -e "\n$PACKAGE is not installed.\n"
1531 exit 0
1532 else
1533 ALTERED=""
1534 THE_PACKAGE=$PACKAGE # altered by receipt
1535 for i in $(cd $INSTALLED ; ls); do
1536 [ -f $INSTALLED/$i/receipt ] || continue
1537 DEPENDS=""
1538 . $INSTALLED/$i/receipt
1539 case " $(echo $DEPENDS) " in
1540 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
1541 esac
1542 done
1543 EXTRAVERSION=""
1544 . $INSTALLED/$THE_PACKAGE/receipt
1545 fi
1546 echo ""
1547 if [ -n "$ALTERED" ]; then
1548 echo "The following packages depend on $PACKAGE :"
1549 for i in $ALTERED; do
1550 echo " $i"
1551 done
1552 fi
1553 REFRESH=$(cd $INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1554 if [ -n "$REFRESH" ]; then
1555 echo "The following packages have been modified by $PACKAGE :"
1556 for i in $REFRESH; do
1557 echo " ${i%/modifiers}"
1558 done
1559 fi
1560 echo "Remove $PACKAGE ($VERSION$EXTRAVERSION) ?"
1561 echo -n "Please confirm uninstallation (y/N) : "; read anser
1562 if [ "$anser" = "y" ]; then
1563 echo ""
1564 echo -e "\033[1mRemoving :\033[0m $PACKAGE"
1565 echo "================================================================================"
1566 # Pre remove commands.
1567 if grep -q ^pre_remove $INSTALLED/$PACKAGE/receipt; then
1568 pre_remove
1569 fi
1570 echo -n "Removing all files installed..."
1571 if [ -f $INSTALLED/$PACKAGE/modifiers ]; then
1572 for mod in `cat $INSTALLED/$PACKAGE/modifiers`
1573 do
1574 for file in `cat $INSTALLED/$PACKAGE/files.list`
1575 do
1576 [ $(grep ^$file$ $INSTALLED/$mod/files.list | wc -l) -gt 1 ] && continue
1577 rm -f $file 2>/dev/null
1578 dir="$file"
1579 while [ "$dir" != "/" ]; do
1580 dir="$(dirname $dir)"
1581 rmdir $dir 2> /dev/null || break
1582 done
1583 done
1584 done
1585 else
1586 for file in `cat $INSTALLED/$PACKAGE/files.list`
1587 do
1588 rm -f $file 2>/dev/null
1589 dir="$file"
1590 while [ "$dir" != "/" ]; do
1591 dir="$(dirname $dir)"
1592 rmdir $dir 2> /dev/null || break
1593 done
1594 done
1595 fi
1596 status
1597 if grep -q ^post_remove $INSTALLED/$PACKAGE/receipt; then
1598 post_remove
1599 fi
1600 # Remove package receipt.
1601 echo -n "Removing package receipt..."
1602 rm -rf $INSTALLED/$PACKAGE
1603 status
1604 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION$/d" \
1605 $LOCALSTATE/installed.md5 2> /dev/null
1606 # Log this activity
1607 log Removed
1608 if [ -n "$ALTERED" ]; then
1609 echo -n "Remove packages depending on $PACKAGE"
1610 echo -n " (y/N) ? "; read anser
1611 if [ "$anser" = "y" ]; then
1612 for i in $ALTERED; do
1613 if [ -d "$INSTALLED/$i" ]; then
1614 tazpkg remove $i
1615 fi
1616 done
1617 fi
1618 fi
1619 if [ -n "$REFRESH" ]; then
1620 echo -n "Reinstall packages modified by $PACKAGE"
1621 echo -n " (y/N) ? "; read anser
1622 if [ "$anser" = "y" ]; then
1623 for i in $REFRESH; do
1624 if [ $(wc -l < $INSTALLED/$i) -gt 1 ]; then
1625 echo "Check $INSTALLED/$i for reinstallation"
1626 continue
1627 fi
1628 rm -r $INSTALLED/$i
1629 tazpkg get-install ${i%/modifiers} --forced
1630 done
1631 fi
1632 fi
1633 else
1634 echo ""
1635 echo "Uninstallation of $PACKAGE cancelled."
1636 fi
1637 echo ""
1638 ;;
1639 extract)
1640 # Extract .tazpkg cpio archive into a directory.
1642 check_for_package_on_cmdline
1643 check_for_package_file
1644 echo ""
1645 echo -e "\033[1mExtracting :\033[0m $PACKAGE"
1646 echo "================================================================================"
1647 # If no directory destination is found on the cmdline
1648 # we create one in the current dir using the package name.
1649 if [ -n "$TARGET_DIR" ]; then
1650 DESTDIR=$TARGET_DIR/$PACKAGE
1651 else
1652 DESTDIR=$PACKAGE
1653 fi
1654 mkdir -p $DESTDIR
1655 echo -n "Copying original package..."
1656 cp $PACKAGE_FILE $DESTDIR
1657 status
1658 cd $DESTDIR
1659 extract_package
1660 echo "================================================================================"
1661 echo "$PACKAGE is extracted to : $DESTDIR"
1662 echo ""
1663 ;;
1664 list-config)
1665 # List configuration files installed.
1667 if [ "$2" = "--box" ]; then
1668 mkdir -p $TMP_DIR && cd $TMP_DIR
1669 FILES="$INSTALLED/*/volatile.cpio.gz"
1670 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
1671 for i in $FILES; do
1672 zcat $i | cpio -idm > /dev/null
1673 find * -type f 2>/dev/null | while read file; do
1674 if [ ! -e /$file ]; then
1675 echo -n "|--|--|--|File lost"
1676 else
1677 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
1678 cmp $file /$file > /dev/null 2>&1 || \
1679 echo -n "$(stat -c "%.16y" /$file)"
1680 fi
1681 echo "|/$file"
1682 done
1683 rm -rf *
1684 done
1685 cd $TOP_DIR
1686 rm -rf $TMP_DIR
1687 else
1688 echo ""
1689 echo -e "\033[1mConfiguration files"
1690 echo "================================================================================"
1691 for i in $INSTALLED/*/volatile.cpio.gz; do
1692 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
1693 [ -f "$i" ] || continue
1694 zcat $i | cpio -t | grep -v "[0-9]* blocks"
1695 done | sed 's|^|/|' | sort
1696 echo "================================================================================"
1697 echo ""
1698 fi
1699 ;;
1700 repack-config)
1701 # Create SliTaz package archive from configuration files.
1703 mkdir -p $TMP_DIR && cd $TMP_DIR
1704 CONFIG_VERSION=1.0
1705 mkdir config-$CONFIG_VERSION
1706 cd config-$CONFIG_VERSION
1707 for i in $INSTALLED/*/volatile.cpio.gz; do
1708 zcat $i | cpio -t | grep -v "[0-9]* blocks"
1709 done > files.list
1710 mkdir fs
1711 cd fs
1712 ( cd / ; cpio -o -H newc ) < ../files.list | cpio -idm > /dev/null
1713 mkdir -p etc/tazlito
1714 for i in $INSTALLED/*/receipt; do
1715 EXTRAVERSION=""
1716 . $i
1717 echo "$PACKAGE-$VERSION$EXTRAVERSION"
1718 done > etc/tazlito/config-packages.list
1719 cd ..
1720 echo "etc/tazlito/config-packages.list" >> files.list
1721 cat > receipt <<EOT
1722 # SliTaz package receipt.
1724 PACKAGE="config"
1725 VERSION="$CONFIG_VERSION"
1726 CATEGORY="base-system"
1727 SHORT_DESC="User configuration backup on $(date)"
1728 DEPENDS="$(ls $INSTALLED)"
1729 EOT
1730 cd ..
1731 tazpkg pack config-$CONFIG_VERSION
1732 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
1733 cd $TOP_DIR
1734 rm -rf $TMP_DIR
1735 ;;
1736 repack)
1737 # Create SliTaz package archive from an installed package.
1739 check_for_package_on_cmdline
1740 check_for_receipt
1741 EXTRAVERSION=""
1742 . $INSTALLED/$PACKAGE/receipt
1743 echo ""
1744 echo -e "\033[1mRepacking :\033[0m $PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
1745 echo "================================================================================"
1746 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
1747 echo "Can't repack $PACKAGE"
1748 exit 1
1749 fi
1750 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
1751 echo "Can't repack, $PACKAGE files have been modified by:"
1752 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
1753 echo " $i"
1754 done
1755 exit 1
1756 fi
1757 MISSING=""
1758 while read i; do
1759 [ -e "$i" ] && continue
1760 [ -L "$i" ] || MISSING="$MISSING\n $i"
1761 done < $INSTALLED/$PACKAGE/files.list
1762 if [ -n "$MISSING" ]; then
1763 echo -n "Can't repack, the following files are lost:"
1764 echo -e "$MISSING"
1765 exit 1
1766 fi
1767 mkdir -p $TMP_DIR && cd $TMP_DIR
1768 FILES="fs.cpio.gz\n"
1769 for i in $(ls $INSTALLED/$PACKAGE) ; do
1770 [ "$i" = "volatile.cpio.gz" ] && continue
1771 [ "$i" = "modifiers" ] && continue
1772 cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
1773 done
1774 ln -s / rootfs
1775 mkdir tmp
1776 sed 's/^/rootfs/' < files.list | cpio -o -H newc 2>/dev/null |\
1777 ( cd tmp ; cpio -idm 2>/dev/null )
1778 mv tmp/rootfs fs
1779 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
1780 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
1781 ( cd fs; cpio -idm )
1782 fi
1783 if grep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
1784 . $INSTALLED/$PACKAGE/receipt
1785 repack_cleanup fs
1786 fi
1787 if [ -f $INSTALLED/$PACKAGE/md5sum ]; then
1788 sed 's, , fs,' < $INSTALLED/$PACKAGE/md5sum | \
1789 md5sum -s -c || {
1790 echo "Can't repack, md5sum error."
1791 cd $TOP_DIR
1792 rm -rf $TMP_DIR
1793 exit 1
1795 fi
1796 find fs | cpio -o -H newc 2> /dev/null | gzip -9 > fs.cpio.gz
1797 echo -e "$FILES" | cpio -o -H newc 2> /dev/null > \
1798 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1799 cd $TOP_DIR
1800 \rm -R $TMP_DIR
1801 echo "Package $PACKAGE repacked successfully."
1802 echo "Size : `du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
1803 echo ""
1804 ;;
1805 pack)
1806 # Create SliTaz package archive using cpio and gzip.
1808 check_for_package_on_cmdline
1809 cd $PACKAGE
1810 if [ ! -f "receipt" ]; then
1811 echo "Receipt is missing. Please read the documentation."
1812 exit 0
1813 else
1814 echo ""
1815 echo -e "\033[1mPacking :\033[0m $PACKAGE"
1816 echo "================================================================================"
1817 # Create files.list with redirecting find outpout.
1818 echo -n "Creating the list of files..." && cd fs
1819 find . -type f -print > ../files.list
1820 find . -type l -print >> ../files.list
1821 cd .. && sed -i s/'^.'/''/ files.list
1822 status
1823 echo -n "Creating md5sum of files..."
1824 while read file; do
1825 [ -L "fs$file" ] && continue
1826 [ -f "fs$file" ] || continue
1827 case "$file" in
1828 /lib/modules/*/modules.*|*.pyc) continue;;
1829 esac
1830 md5sum "fs$file" | sed 's/ fs/ /'
1831 done < files.list > md5sum
1832 status
1833 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
1834 description.txt 2> /dev/null | awk \
1835 '{ sz=$1 } END { print sz }')
1836 # Build cpio archives.
1837 echo -n "Compressing the fs... "
1838 find fs -print | cpio -o -H newc | gzip > fs.cpio.gz
1839 rm -rf fs
1840 status
1841 PACKED_SIZE=$(du -chs fs.cpio.gz receipt files.list \
1842 md5sum description.txt 2> /dev/null | awk \
1843 '{ sz=$1 } END { print sz }')
1844 echo -n "Undating receipt sizes..."
1845 sed -i s/^PACKED_SIZE.*$// receipt
1846 sed -i s/^UNPACKED_SIZE.*$// receipt
1847 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1848 status
1849 echo -n "Creating full cpio archive... "
1850 find . -print | cpio -o -H newc > ../$PACKAGE.tazpkg
1851 status
1852 echo -n "Restoring original package tree... "
1853 zcat fs.cpio.gz | cpio -idm
1854 status
1855 rm fs.cpio.gz && cd ..
1856 echo "================================================================================"
1857 echo "Package $PACKAGE compressed successfully."
1858 echo "Size : `du -sh $PACKAGE.tazpkg`"
1859 echo ""
1860 fi
1861 ;;
1862 recharge)
1863 # Recharge packages.list from a mirror.
1865 check_root
1866 for path in $LOCALSTATE $LOCALSTATE/undigest/*; do
1867 [ -f $path/mirror ] || continue
1868 echo ""
1869 if [ "$path" != "$LOCALSTATE" ]; then
1870 echo "Recharge undigest $(basename $path):"
1871 fi
1872 cd $path
1873 if [ -f "packages.list" ]; then
1874 echo -n "Creating backup of the last packages list..."
1875 mv -f packages.desc packages.desc.bak 2>/dev/null
1876 mv -f packages.md5 packages.md5.txt 2>/dev/null
1877 mv -f packages.txt packages.txt.bak 2>/dev/null
1878 mv -f packages.list packages.list.bak 2>/dev/null
1879 mv -f packages.equiv packages.equiv.bak 2>/dev/null
1880 mv -f files.list.lzma files.list.lzma.bak 2> /dev/null
1881 mv -f mirrors mirrors.bak 2> /dev/null
1882 status
1883 fi
1884 download_from "$(cat mirror)" packages.desc
1885 download_from "$(cat mirror)" packages.md5
1886 download_from "$(cat mirror)" packages.txt
1887 download_from "$(cat mirror)" packages.list
1888 download_from "$(cat mirror)" packages.equiv
1889 download_from "$(cat mirror)" files.list.lzma
1890 download_from "$(cat mirror)" mirrors
1891 [ -f mirrors ] || mv mirrors.bak mirrors 2> /dev/null
1892 suffix=$(head -1 mirror)
1893 suffix=packages${suffix#*/packages}
1894 for i in $(cat mirrors 2> /dev/null); do
1895 grep -qs $i mirror || echo $i$suffix >> mirror
1896 done
1897 if [ -f "packages.list.bak" ]; then
1898 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
1899 sed -i s/+// packages.diff
1900 echo ""
1901 echo -e "\033[1mMirrored packages diff\033[0m"
1902 echo "================================================================================"
1903 cat packages.diff
1904 if [ ! "`cat packages.diff | wc -l`" = 0 ]; then
1905 echo "================================================================================"
1906 echo "`cat packages.diff | wc -l` new packages on the mirror."
1907 echo ""
1908 else
1909 echo "`cat packages.diff | wc -l` new packages on the mirror."
1910 echo ""
1911 fi
1912 else
1913 echo -e "
1914 ================================================================================
1915 Last packages.list is ready to use. Note that next time you recharge the list,
1916 a list of differences will be displayed to show new and upgradeable packages.\n"
1917 fi
1918 done
1919 ;;
1920 upgrade)
1921 # Upgrade all installed packages with the new version from the mirror.
1923 check_root
1924 check_for_packages_list
1925 cd $LOCALSTATE
1926 # Touch the blocked pkgs list to avoid errors and remove any old
1927 # upgrade list.
1928 touch blocked-packages.list
1929 rm -f upgradeable-packages.list
1930 echo ""
1931 echo -e "\033[1mAvailable upgrades\033[0m"
1932 echo "================================================================================"
1933 echo ""
1934 # Some packages must be installed first
1935 FIRST_CLASS_PACKAGE=" glibc-base slitaz-base-files slitaz-boot-scripts "
1936 if [ -n "$PACKAGE_FILE" -a -d "$INSTALLED/$PACKAGE_FILE" ]; then
1937 ALL=$INSTALLED/$PACKAGE_FILE
1938 else
1939 ALL="$(ls -d $INSTALLED/*)"
1940 fi
1941 for pkg in $ALL
1942 do
1943 [ -f $pkg/receipt ] || continue
1944 EXTRAVERSION=""
1945 . $pkg/receipt
1946 # Display package name to show that Tazpkg is working...
1947 echo -en "\\033[0G "
1948 echo -en "\\033[0G$PACKAGE"
1949 # Skip specified pkgs listed in $LOCALSTATE/blocked-packages.list
1950 if grep -qs "^$PACKAGE" $BLOCKED; then
1951 blocked=$(($blocked+1))
1952 else
1953 # Check if the installed package is in the current list (other
1954 # mirror or local).
1955 NEW_PACKAGE=$(get_package_filename $PACKAGE)
1957 if [ -n "$NEW_PACKAGE" ]; then
1958 # Set new pkg and version for future comparison
1959 NEW_VERSION=`echo $NEW_PACKAGE | sed s/$PACKAGE-/''/`
1960 # Change '-' and 'pre' to points.
1961 NEW_VERSION=`echo $NEW_VERSION | sed s/'-'/'.'/`
1962 VERSION=`echo $VERSION | sed s/'-'/'.'/`$EXTRAVERSION
1963 NEW_VERSION=`echo $NEW_VERSION | sed s/'pre'/'.'/`
1964 VERSION=`echo $VERSION | sed s/'pre'/'.'/`
1965 NEW_VERSION=`echo $NEW_VERSION | sed 's/[A-Z]\.//'`
1966 VERSION=`echo $VERSION | sed 's/[A-Z]\.//'`
1967 # Compare version. Upgrades are only available for official
1968 # packages, so we control the mirror and it should be ok if
1969 # we just check for equality.
1970 RELEASE=""
1971 if [ -f installed.md5 -a -f packages.md5 ]; then
1972 current_md5=$(grep -s " $PACKAGE-$VERSION" installed.md5 | awk '{ print $1 }')
1973 new_md5=$(grep -hs " $PACKAGE-$VERSION" packages.md5 undigest/*/packages.md5 | head -1 | awk '{ print $1 }')
1974 [ -n "$current_md5" ] && [ -n "$new_md5" ] &&
1975 [ "$current_md5" != "$new_md5" ] && RELEASE=build
1976 fi
1977 if [ "$VERSION" != "$NEW_VERSION" -o -n "$RELEASE" ]; then
1978 # Version seems different. Check for major, minor or
1979 # revision
1980 PKG_MAJOR=`echo ${VERSION%_*} | cut -f1 -d"."`
1981 NEW_MAJOR=`echo ${NEW_VERSION%_*} | cut -f1 -d"."`
1982 PKG_MINOR=`echo ${VERSION%_*} | cut -f2 -d"."`
1983 NEW_MINOR=`echo ${NEW_VERSION%_*} | cut -f2 -d"."`
1984 # Minor
1985 if [ "$NEW_MINOR" -gt "$PKG_MINOR" ] 2> /dev/null; then
1986 RELEASE=minor
1987 fi
1988 if [ "$NEW_MINOR" -lt "$PKG_MINOR" ] 2> /dev/null; then
1989 RELEASE=$WARNING
1990 FIXE=yes
1991 fi
1992 # Major
1993 if [ "$NEW_MAJOR" -gt "$PKG_MAJOR" ] 2> /dev/null; then
1994 RELEASE=major
1995 FIXE=""
1996 fi
1997 if [ "$NEW_MAJOR" -lt "$PKG_MAJOR" ] 2> /dev/null; then
1998 RELEASE=$WARNING
1999 FIXE=yes
2000 fi
2001 # Default to revision.
2002 if [ -z $RELEASE ]; then
2003 RELEASE=revision
2004 fi
2005 # Pkg name is already displayed by the check process.
2006 echo -en "\033[24G $VERSION"
2007 echo -en "\033[38G --->"
2008 echo -en "\033[43G $NEW_VERSION"
2009 echo -en "\033[58G $CATEGORY"
2010 echo -e "\033[72G $RELEASE"
2011 up=$(($up+1))
2012 echo "$PACKAGE" >> upgradeable-packages.list
2013 case "$FIRST_CLASS_PACKAGE" in
2014 *\ $PACKAGE\ *) echo "$PACKAGE" >> upgradeable-packages.list$$;;
2015 esac
2016 unset RELEASE
2017 fi
2018 packages=$(($packages+1))
2019 fi
2020 fi
2021 done
2022 if [ -z $blocked ]; then
2023 blocked=0
2024 fi
2025 # Clean last checked package and display summary.
2026 if [ ! "$up" = "" ]; then
2027 echo -e "\\033[0G "
2028 echo "================================================================================"
2029 echo "$packages installed and listed packages to consider, $up to upgrade, $blocked blocked."
2030 echo ""
2031 else
2032 echo -e "\\033[0GSystem is up-to-date. "
2033 echo ""
2034 echo "================================================================================"
2035 echo "$packages installed and listed packages to consider, 0 to upgrade, $blocked blocked."
2036 echo ""
2037 exit 0
2038 fi
2039 # What to do if major or minor version is smaller.
2040 if [ "$FIXE" == "yes" ]; then
2041 echo -e "$WARNING ---> Installed package seems more recent than the mirrored one."
2042 echo "You can block packages using the command : 'tazpkg block package'"
2043 echo "Or upgrade packages at your own risk."
2044 echo ""
2045 fi
2046 # Ask for upgrade, it can be done another time.
2047 echo -n "Upgrade now (y/N) ? "; read anser
2048 if [ ! "$anser" = "y" ]; then
2049 echo -e "\nExiting. No package upgraded.\n"
2050 exit 0
2051 fi
2052 # If anser is yes (y). Install all new versions.
2053 cat upgradeable-packages.list >> upgradeable-packages.list$$
2054 mv -f upgradeable-packages.list$$ upgradeable-packages.list
2055 yes y | tazpkg get-install-list upgradeable-packages.list --forced
2056 rm -f upgradeable-packages.list
2057 ;;
2058 bugs)
2059 # Show known bugs in package(s)
2061 cd $INSTALLED
2062 shift
2063 LIST=$@
2064 [ -n "$LIST" ] || LIST=`ls`
2065 MSG="No known bugs."
2066 for PACKAGE in $LIST; do
2067 BUGS=""
2068 EXTRAVERSION=""
2069 . $PACKAGE/receipt
2070 if [ -n "$BUGS" ]; then
2071 MSG="
2072 Bug list completed"
2073 cat <<EOT
2075 Bugs in package $PACKAGE version $VERSION$EXTRAVERSION:
2076 $BUGS
2077 EOT
2078 fi
2079 done
2080 echo "$MSG"
2081 ;;
2082 check)
2083 # Check installed packages set.
2085 check_root
2086 cd $INSTALLED
2087 for PACKAGE in `ls`; do
2088 if [ ! -f $PACKAGE/receipt ]; then
2089 echo "The package $PACKAGE installation is not completed"
2090 continue
2091 fi
2092 DEPENDS=""
2093 EXTRAVERSION=""
2094 . $PACKAGE/receipt
2095 if [ -s $PACKAGE/modifiers ]; then
2096 echo "The package $PACKAGE $VERSION$EXTRAVERSION has been modified by :"
2097 for i in $(cat $PACKAGE/modifiers); do
2098 echo " $i"
2099 done
2100 fi
2101 MSG="Files lost from $PACKAGE $VERSION$EXTRAVERSION :\n"
2102 while read file; do
2103 [ -e "$file" ] && continue
2104 if [ -L "$file" ]; then
2105 MSG="$MSG target of symlink"
2106 fi
2107 echo -e "$MSG $file"
2108 MSG=""
2109 done < $PACKAGE/files.list
2110 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n"
2111 for i in $DEPENDS; do
2112 [ -d $i ] && continue
2113 echo -e "$MSG $i"
2114 MSG=""
2115 done
2116 MSG="Dependencies loop between $PACKAGE and :\n"
2117 ALL_DEPS=""
2118 check_for_deps_loop $PACKAGE $DEPENDS
2119 done
2120 echo -n "Looking for known bugs... "
2121 tazpkg bugs
2122 if [ "$PACKAGE_FILE" = "--full" ]; then
2123 for file in */md5sum; do
2124 CONFIG_FILES=""
2125 . $(dirname "$file")/receipt
2126 [ -s "$file" ] || continue
2127 while read md5 f; do
2128 [ -f $f ] || continue
2129 for i in $CONFIG_FILES; do
2130 case "$f" in
2131 $i|$i/*) continue 2;;
2132 esac
2133 done
2134 echo "$md5 $f"
2135 done < "$file" | md5sum -c - 2> /dev/null | \
2136 grep -v OK$ | sed 's/FAILED$/MD5SUM MISMATCH/'
2137 done
2138 FILES=" "
2139 for file in $(cat */files.list); do
2140 [ -d "$file" ] && continue
2141 case "$FILES" in *\ $file\ *) continue;; esac
2142 [ $(grep "^$file$" */files.list 2> /dev/null | \
2143 wc -l) -gt 1 ] || continue
2144 FILES="$FILES$file "
2145 echo "The following packages provide $file :"
2146 grep -l "^$file$" */files.list | while read f
2147 do
2148 pkg=${f%/files.list}
2149 echo -n " $pkg"
2150 if [ -f $pkg/modifiers ]; then
2151 echo -n " (overridden by $(echo "$(cat $pkg/modifiers)"))"
2152 fi
2153 echo ""
2154 done
2155 done
2156 MSG="No package has installed the following files:\n"
2157 find /etc /bin /sbin /lib /usr /var/www \
2158 -not -type d 2> /dev/null | while read file; do
2159 case "$file" in *\[*) continue;; esac
2160 grep -q "^$file$" */files.list && continue
2161 echo -e "$MSG $file"
2162 MSG=""
2163 done
2164 fi
2165 echo "Check completed."
2166 ;;
2167 block)
2168 # Add a pkg name to the list of blocked packages.
2170 check_root
2171 check_for_package_on_cmdline
2172 echo ""
2173 if grep -qs "^$PACKAGE" $BLOCKED; then
2174 echo "$PACKAGE is already in the blocked packages list."
2175 echo ""
2176 exit 0
2177 else
2178 echo -n "Add $PACKAGE to : $BLOCKED..."
2179 echo $PACKAGE >> $BLOCKED
2180 status
2181 # Log this activity
2182 . $INSTALLED/$PACKAGE/receipt
2183 log Blocked
2184 fi
2185 echo ""
2186 ;;
2187 unblock)
2188 # Remove a pkg name from the list of blocked packages.
2190 check_root
2191 check_for_package_on_cmdline
2192 echo ""
2193 if grep -qs "^$PACKAGE" $BLOCKED; then
2194 echo -n "Removing $PACKAGE from : $BLOCKED..."
2195 sed -i s/$PACKAGE/''/ $BLOCKED
2196 sed -i '/^$/d' $BLOCKED
2197 status
2198 # Log this activity
2199 . $INSTALLED/$PACKAGE/receipt
2200 log Unblocked
2201 else
2202 echo "$PACKAGE is not in the blocked packages list."
2203 echo ""
2204 exit 0
2205 fi
2206 echo ""
2207 ;;
2208 get)
2209 # Downlowd a package with wget.
2211 check_for_package_on_cmdline
2212 check_for_packages_list
2213 check_for_package_in_list
2214 echo ""
2215 download $PACKAGE.tazpkg
2216 echo ""
2217 ;;
2218 get-install)
2219 # Download and install a package.
2221 check_root
2222 check_for_package_on_cmdline
2223 check_for_packages_list
2224 DO_CHECK=""
2225 while [ -n "$3" ]; do
2226 case "$3" in
2227 --forced)
2228 DO_CHECK="no"
2229 ;;
2230 --root=*)
2231 ROOT="${3#--root=}"
2232 ;;
2233 --list=*)
2234 INSTALL_LIST="${3#--list=}"
2235 ;;
2236 *) shift 2
2237 echo -e "\nUnknown option $*.\n"
2238 exit 1
2239 ;;
2240 esac
2241 shift
2242 done
2243 AUTOEXEC="no"
2244 if ! check_for_package_in_list check; then
2245 PACKAGE=get-$PACKAGE
2246 AUTOEXEC=$PACKAGE
2247 check_for_package_in_list
2248 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
2249 $AUTOEXEC $ROOT
2250 exit 0
2251 fi
2252 fi
2253 # Check if forced install.
2254 if [ "$DO_CHECK" = "no" ]; then
2255 rm -f $CACHE_DIR/$PACKAGE.tazpkg
2256 else
2257 check_for_installed_package $ROOT
2258 fi
2259 cd $CACHE_DIR
2260 if [ -f "$PACKAGE.tazpkg" ]; then
2261 echo "$PACKAGE already in the cache : $CACHE_DIR"
2262 # Check package download was finished
2263 tail -c 2k $PACKAGE.tazpkg | grep -q 00000000TRAILER || {
2264 echo "Continue $PACKAGE download"
2265 download $PACKAGE.tazpkg
2267 else
2268 echo ""
2269 download $PACKAGE.tazpkg
2270 fi
2271 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2272 install_package $ROOT
2273 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
2274 ;;
2275 clean-cache)
2276 # Remove all downloaded packages.
2278 check_root
2279 files=`ls -1 $CACHE_DIR | wc -l`
2280 echo ""
2281 echo -e "\033[1mClean cache :\033[0m $CACHE_DIR"
2282 echo "================================================================================"
2283 echo -n "Cleaning cache directory..."
2284 rm -rf $CACHE_DIR/*
2285 status
2286 echo "================================================================================"
2287 echo "$files file(s) removed from cache."
2288 echo ""
2289 ;;
2290 list-undigest)
2291 # list undigest URLs.
2293 if [ "$2" = "--box" ]; then
2294 for i in $LOCALSTATE/undigest/*/mirror; do
2295 [ -f $i ] || continue
2296 echo "$(basename $(dirname $i))|$(cat $i)"
2297 done
2298 else
2299 echo ""
2300 echo -e "\033[1mCurrent undigest(s)\033[0m"
2301 echo "================================================================================"
2302 for i in $LOCALSTATE/undigest/*/mirror; do
2303 if [ ! -f $i ]; then
2304 echo "No undigest mirror found."
2305 exit 1
2306 fi
2307 echo "$(basename $(dirname $i)) $(cat $i)"
2308 done
2309 echo ""
2310 fi
2311 ;;
2312 remove-undigest)
2313 # remove undigest URL.
2315 check_root
2316 if [ -d $LOCALSTATE/undigest/$2 ]; then
2317 echo -n "Remove $2 undigest (y/N) ? "; read anser
2318 if [ "$anser" = "y" ]; then
2319 echo -n "Removing $2 undigest..."
2320 rm -rf $LOCALSTATE/undigest/$2
2321 status
2322 rmdir $LOCALSTATE/undigest 2> /dev/null
2323 fi
2324 else
2325 echo "Undigest $2 not found"
2326 fi
2327 ;;
2328 add-undigest|setup-undigest)
2329 # Add undigest URL.
2331 check_root
2332 undigest=$2
2333 [ -d $LOCALSTATE/undigest ] || mkdir $LOCALSTATE/undigest
2334 if [ -z "$undigest" ]; then
2335 i=1
2336 while [ -d $LOCALSTATE/undigest/$i ]; do
2337 i=$(($i+1))
2338 done
2339 undigest=$i
2340 fi
2341 if [ ! -d $LOCALSTATE/undigest/$undigest ]; then
2342 echo "Creating new undigest $undigest."
2343 mkdir $LOCALSTATE/undigest/$undigest
2344 fi
2345 setup_mirror $LOCALSTATE/undigest/$undigest $3
2346 ;;
2347 setup-mirror)
2348 # Change mirror URL.
2350 check_root
2351 setup_mirror $LOCALSTATE $2
2352 ;;
2353 reconfigure)
2354 # Replay post_install from receipt
2356 check_for_package_on_cmdline
2357 check_root
2358 ROOT=""
2359 while [ -n "$3" ]; do
2360 case "$3" in
2361 --root=*)
2362 ROOT="${3#--root=}/"
2363 ;;
2364 *) shift 2
2365 echo -e "\nUnknown option $*.\n"
2366 exit 1
2367 ;;
2368 esac
2369 shift
2370 done
2371 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2372 check_for_receipt $ROOT
2373 # Check for post_install
2374 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2375 . $ROOT$INSTALLED/$PACKAGE/receipt
2376 post_install $ROOT
2377 # Log this activity
2378 [ -n "$ROOT" ] || log Reconfigured
2379 else
2380 echo -e "\nNothing to do for $PACKAGE."
2381 fi
2382 else
2383 echo -e "\npackage $PACKAGE is not installed."
2384 echo -e "Install package with 'tazpkg install' or 'tazpkg get-install'\n"
2385 fi
2386 ;;
2387 shell)
2388 # Tazpkg SHell
2390 if test $(id -u) = 0 ; then
2391 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2392 else
2393 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2394 fi
2395 if [ ! "$2" = "--noheader" ]; then
2396 clear
2397 echo ""
2398 echo -e "\033[1mTazpkg SHell.\033[0m"
2399 echo "================================================================================"
2400 echo "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
2401 echo ""
2402 fi
2403 while true
2404 do
2405 echo -en "$PROMPT"; read cmd
2406 case $cmd in
2407 q|quit)
2408 break ;;
2409 shell)
2410 echo "You are already running a Tazpkg SHell." ;;
2411 su)
2412 su -c 'exec tazpkg shell --noheader' && break ;;
2413 "")
2414 continue ;;
2415 *)
2416 tazpkg $cmd ;;
2417 esac
2418 done
2419 ;;
2420 depends)
2421 # Display dependencies tree
2422 cd $INSTALLED
2423 ALL_DEPS=""
2424 if [ -f $2/receipt ]; then
2425 dep_scan $2 ""
2426 fi
2427 ;;
2428 rdepends)
2429 # Display reverse dependencies tree
2430 cd $INSTALLED
2431 ALL_DEPS=""
2432 if [ -f $2/receipt ]; then
2433 rdep_scan $2
2434 fi
2435 ;;
2436 convert)
2437 # convert misc package format to .tazpkg
2438 check_for_package_file
2439 case "$PACKAGE_FILE" in
2440 *.deb|*.udeb)
2441 convert_deb;;
2442 *.rpm)
2443 convert_rpm;;
2444 *.tgz)
2445 convert_tgz;;
2446 *)
2447 echo "Unsupported format";;
2448 esac
2449 ;;
2450 link)
2451 # link a package from another slitaz installation
2452 PACKAGE=$2
2453 if [ ! -d "$TARGET_DIR" -o \
2454 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
2455 cat <<EOT
2456 usage: tazpkg link package_name slitaz_root
2457 example: 'tazpkg link openoffice /mnt' will use less than 100k in
2458 your ram running system.
2459 EOT
2460 exit 1
2461 fi
2462 if [ -e "$INSTALLED/$PACKAGE" ]; then
2463 echo "$PACKAGE is already installed."
2464 exit 1
2465 fi
2466 ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
2467 DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
2468 MISSING=""
2469 for i in $DEPENDS; do
2470 [ -e $INSTALLED/$i ] && continue
2471 MISSING="$MISSING$i "
2472 echo "Missing : $i"
2473 done
2474 if [ -n "$MISSING" ]; then
2475 echo ""
2476 echo -n "Link all missing dependencies (y/N) ? "; read answer
2477 echo ""
2478 if [ "$answer" = "y" ]; then
2479 for i in $MISSING; do
2480 tazpkg link $i $TARGET_DIR
2481 done
2482 else
2483 echo -e "\nLeaving dependencies for $PACKAGE unsolved."
2484 echo -e "The package is installed but will probably not work.\n"
2485 fi
2486 fi
2487 . $INSTALLED/$PACKAGE/receipt
2488 if grep -q ^pre_install $INSTALLED/$PACKAGE/receipt; then
2489 pre_install
2490 fi
2491 while read path; do
2492 [ -e $path ] && continue
2493 while true; do
2494 dir=$(dirname $path)
2495 [ -e $dir ] && break
2496 path=$dir
2497 done
2498 ln -s $TARGET_DIR$path $dir
2499 done < $INSTALLED/$PACKAGE/files.list
2500 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
2501 post_install
2502 fi
2503 ;;
2504 usage|*)
2505 # Print a short help or give usage for an unknown or empty command.
2506 usage ;;
2507 esac
2509 exit 0