tazpkg view tazpkg @ rev 265

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