tazpkg view tazpkg @ rev 273

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