tazpkg view tazpkg @ rev 272

Tiny edits
author Paul Issott <paul@slitaz.org>
date Mon Jun 15 17:29:49 2009 +0000 (2009-06-15)
parents 920ebc92d5b0
children f2fd7d0fb885
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 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 # Check for ELF file
899 is_elf()
900 {
901 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
902 }
904 # Print shared library dependencies
905 ldd()
906 {
907 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
908 }
910 # search dependencies for files in $TMP_DIR/$file/fs
911 find_depends()
912 {
913 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
915 [ -f /var/lib/tazpkg/files.list.lzma ] || tazpkg recharge
916 for i in /var/lib/tazpkg/files.list.lzma \
917 /var/lib/tazpkg/undigest/*/files.list.lzma ; do
918 [ -f $i ] && lzma d $i -so >> $TMP_DIR/files.list
919 done
920 find $TMP_DIR/$file/fs -type f | while read file ; do
921 is_elf $file || continue
922 case "$file" in
923 *.o|*.ko|*.ko.gz) continue;;
924 esac
925 ldd $file | while read lib rem; do
926 case "$lib" in
927 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
928 continue;;
929 esac
930 for dep in $(grep $lib files.list | cut -d: -f1); do
931 case " $DEFAULT_DEPENDS $ALL_DEPENDS " in
932 *\ $dep\ *) continue 2;;
933 esac
934 done
935 ALL_DEPENDS="$ALL_DEPENDS $dep"
936 if [ -n "$dep" ]; then
937 echo -n " $dep"
938 else
939 echo "$lib" >> $TMP_DIR/unresolved
940 fi
941 done
942 done
943 }
945 show_unresolved_lib()
946 {
947 if [ -s $TMP_DIR/unresolved ]; then
948 echo "BUGS=\"No dependency for $(cat $TMP_DIR/unresolved)\"" >> $1
949 for lib in $(cat $TMP_DIR/unresolved) ; do
950 echo -e "$WARNING: unknown dependency for $lib"
951 done
952 fi
953 }
955 # convert a .deb package to .tazpkg
956 convert_deb()
957 {
958 mkdir -p $TMP_DIR
959 dpkg-deb -e $PACKAGE_FILE $TMP_DIR
960 package=$(grep '^ *Package' $TMP_DIR/control)
961 package=$(echo ${package##*:})
962 version=$(grep '^ *Version' $TMP_DIR/control)
963 version=$(echo ${version##*:})
964 descrip=$(grep '^ *Description' $TMP_DIR/control)
965 descrip=$(echo ${descrip##*:})
966 file="$package-$version"
967 mkdir -p $TMP_DIR/$file/fs/
968 dpkg-deb -x $PACKAGE_FILE $TMP_DIR/$file/fs
969 cd $TMP_DIR
970 cat > $file/receipt <<EOT
971 # SliTaz package receipt.
972 # generated by tazpkg from debian package $(basename $PACKAGE_FILE)
973 PACKAGE="$package"
974 VERSION="$version"
975 CATEGORY="misc"
976 SHORT_DESC="$descrip"
977 WEB_SITE="http://packages.debian.org/search?keywords=$package"
978 MAINTAINER="nobody@slitaz.org"
979 DEPENDS="$(find_depends)"
980 EOT
981 show_unresolved_lib $file/receipt
982 awk '
983 {
984 if (/^ / && show) print substr($0,2);
985 else show=0;
986 if (/^Description/) show=1;
987 }' < $TMP_DIR/control > $file/description.txt
988 sed -i 's/^\.$//' $file/description.txt
989 tazpkg pack $file
990 mv $file.tazpkg $TOP_DIR
991 cd $TOP_DIR
992 rm -rf $TMP_DIR
993 }
995 # convert a .rpm package to .tazpkg
996 convert_rpm()
997 {
998 mkdir -p $TMP_DIR
999 cp $PACKAGE_FILE $TMP_DIR
1000 PACKAGE_FILE=$TMP_DIR/$(basename $PACKAGE_FILE)
1001 rpm -qip $PACKAGE_FILE | awk -v pkg=$(basename $PACKAGE_FILE) '
1002 BEGIN {
1003 goturl=0;
1004 printf "# Taz package receipt.\n";
1005 printf "# generated by tazpkg from rpm package %s\n",pkg;
1008 if (/^Name/) { name=$3; printf "PACKAGE=\"%s\"\n",$3; }
1009 if (/^Version/) printf "VERSION=\"%s-",$3;
1010 if (/^Release/) printf "%s\"\n",$3;
1011 if (/^Summary/) printf "SHORT_DESC=\"%s\"\n",substr($0,15);
1012 if (/^URL/) { goturl=1; printf "WEB_SITE=\"%s\"\n",$3; }
1014 END {
1015 if (goturl == 0)
1016 printf "WEB_SITE=\"http://rpmfind.net/linux/rpm2html/search.php?query=%s\"\n",name;
1017 printf "CATEGORY=\"misc\"\n";
1018 printf "MAINTAINER=\"nobody@slitaz.org\"\n";
1020 ' > $TMP_DIR/receipt
1021 . $TMP_DIR/receipt
1022 file=$PACKAGE-$VERSION
1023 mkdir -p $TMP_DIR/$file/fs/
1024 mv $TMP_DIR/receipt $TMP_DIR/$file
1025 rpm -qip $PACKAGE_FILE | awk '
1026 DEGIN { show=0 }
1028 if (show) print;
1029 if (/^Description/) show=1;
1031 ' > $TMP_DIR/$file/description.txt
1032 cd $TMP_DIR/$file/fs/
1033 rpm2cpio $PACKAGE_FILE | cpio -idm
1034 cd ../..
1035 echo "DEPENDS=\"$(find_depends)\"" >> $TMP_DIR/$file/receipt
1036 show_unresolved_lib $TMP_DIR/$file/receipt
1037 tazpkg pack $file
1038 mv $file.tazpkg $TOP_DIR
1039 cd $TOP_DIR
1040 rm -rf $TMP_DIR
1043 ###################
1044 # Tazpkg commands #
1045 ###################
1047 case "$COMMAND" in
1048 list)
1049 # List all installed packages or a specific category.
1051 if [ "$2" = "blocked" ]; then
1052 echo ""
1053 echo -e "\033[1mBlocked packages\033[0m"
1054 echo "================================================================================"
1055 if [ -s "$BLOCKED" ];then
1056 cat $BLOCKED
1057 echo ""
1058 else
1059 echo -e "No blocked packages found.\n"
1060 fi
1061 exit 0
1062 fi
1063 # Display the list of categories.
1064 if [ "$2" = "cat" -o "$2" = "categories" ]; then
1065 echo ""
1066 echo -e "\033[1mPackages categories :\033[0m"
1067 echo "================================================================================"
1068 for i in $CATEGORIES
1069 do
1070 echo $i
1071 categories=$(($categories+1))
1072 done
1073 echo "================================================================================"
1074 echo "$categories categories"
1075 echo ""
1076 exit 0
1077 fi
1078 # Check for an asked category.
1079 if [ -n "$2" ]; then
1080 ASKED_CATEGORY=$2
1081 echo ""
1082 echo -e "\033[1mInstalled packages of category :\033[0m $ASKED_CATEGORY"
1083 echo "================================================================================"
1084 for pkg in $INSTALLED/*
1085 do
1086 [ -f $pkg/receipt ] || continue
1087 EXTRAVERSION=""
1088 . $pkg/receipt
1089 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
1090 echo -n "$PACKAGE"
1091 echo -e "\033[24G $VERSION$EXTRAVERSION"
1092 packages=$(($packages+1))
1093 fi
1094 done
1095 echo "================================================================================"
1096 echo -e "$packages packages installed of category $ASKED_CATEGORY."
1097 echo ""
1098 else
1099 # By default list all packages and versions.
1100 echo ""
1101 echo -e "\033[1mList of all installed packages\033[0m"
1102 echo "================================================================================"
1103 for pkg in $INSTALLED/*
1104 do
1105 [ -f $pkg/receipt ] || continue
1106 EXTRAVERSION=""
1107 . $pkg/receipt
1108 echo -n "$PACKAGE"
1109 echo -en "\033[24G $VERSION$EXTRAVERSION"
1110 echo -e "\033[42G $CATEGORY"
1111 packages=$(($packages+1))
1112 done
1113 echo "================================================================================"
1114 echo "$packages packages installed."
1115 echo ""
1116 fi
1117 ;;
1118 xhtml-list)
1119 # Get info in receipts and build list.
1120 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
1121 if [ -n "$2" ]; then
1122 XHTML_LIST=$2
1123 else
1124 XHTML_LIST=installed-packages.html
1125 fi
1126 echo ""
1127 echo -e "\033[1mCreating xHTML list of installed packages\033[0m"
1128 echo "================================================================================"
1129 echo -n "Generating xHTML header..."
1130 xhtml_header
1131 status
1132 # Packages
1133 echo -n "Creating packages information..."
1134 for pkg in $INSTALLED/*
1135 do
1136 [ -f $pkg/receipt ] || continue
1137 EXTRAVERSION=""
1138 . $pkg/receipt
1139 xhtml_pkg_info
1140 packages=$(($packages+1))
1141 done
1142 status
1143 echo -n "Generating xHTML footer..."
1144 xhtml_footer
1145 status
1146 # sed pkgs nb in header.
1147 sed -i s/'_packages_'/"$packages"/ $XHTML_LIST
1148 echo "================================================================================"
1149 echo "$XHTML_LIST created - $packages packages."
1150 echo ""
1151 ;;
1152 list-mirror)
1153 # List all available packages on the mirror. Option --diff displays
1154 # last mirrored packages diff (see recharge).
1155 check_for_packages_list
1156 case $2 in
1157 --diff)
1158 if [ -f "$LOCALSTATE/packages.diff" ]; then
1159 echo ""
1160 echo -e "\033[1mMirrored packages diff\033[0m"
1161 echo "================================================================================"
1162 cat $LOCALSTATE/packages.diff
1163 echo "================================================================================"
1164 pkgs=`cat $LOCALSTATE/packages.diff | wc -l`
1165 echo "$pkgs new packages listed on the mirror."
1166 echo ""
1167 else
1168 echo -e "\nUnable to list anything, no packages.diff found."
1169 echo -e "Recharge your current list to create a first diff.\n"
1170 fi && exit 0 ;;
1171 --text|--txt)
1172 echo ""
1173 echo -e "\033[1mList of available packages on the mirror\033[0m"
1174 echo "================================================================================"
1175 cat $LOCALSTATE/packages.txt ;;
1176 --raw|*)
1177 echo ""
1178 echo -e "\033[1mList of available packages on the mirror\033[0m"
1179 echo "================================================================================"
1180 cat $LOCALSTATE/packages.list ;;
1181 esac
1182 echo "================================================================================"
1183 pkgs=`cat $LOCALSTATE/packages.list | wc -l`
1184 echo "$pkgs packages in the last recharged list."
1185 echo ""
1186 ;;
1187 list-files)
1188 # List files installed with the package.
1190 check_for_package_on_cmdline
1191 check_for_receipt
1192 echo ""
1193 echo -e "\033[1mInstalled files with :\033[0m $PACKAGE"
1194 echo "================================================================================"
1195 cat $INSTALLED/$PACKAGE/files.list | sort
1196 echo "================================================================================"
1197 files=`cat $INSTALLED/$PACKAGE/files.list | wc -l`
1198 echo "$files files installed with $PACKAGE."
1199 echo ""
1200 ;;
1201 info)
1202 # Information about package.
1204 check_for_package_on_cmdline
1205 check_for_receipt
1206 EXTRAVERSION=""
1207 . $INSTALLED/$PACKAGE/receipt
1208 echo ""
1209 echo -e "\033[1mTazpkg information\033[0m
1210 ================================================================================
1211 Package : $PACKAGE
1212 Version : $VERSION$EXTRAVERSION
1213 Category : $CATEGORY
1214 Short desc : $SHORT_DESC
1215 Maintainer : $MAINTAINER"
1216 if [ ! "$DEPENDS" = "" ]; then
1217 echo -e "Depends : $DEPENDS"
1218 fi
1219 if [ ! "$SUGGESTED" = "" ]; then
1220 echo -e "Suggested : $SUGGESTED"
1221 fi
1222 if [ ! "$BUILD_DEPENDS" = "" ]; then
1223 echo -e "Build deps : $BUILD_DEPENDS"
1224 fi
1225 if [ ! "$WANTED" = "" ]; then
1226 echo -e "Wanted src : $WANTED"
1227 fi
1228 if [ ! "$WEB_SITE" = "" ]; then
1229 echo -e "Web site : $WEB_SITE"
1230 fi
1231 echo "================================================================================"
1232 echo ""
1233 ;;
1234 desc)
1235 # Display package description.txt if available.
1236 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
1237 echo ""
1238 echo -e "\033[1mDescription of :\033[0m $PACKAGE"
1239 echo "================================================================================"
1240 cat $INSTALLED/$PACKAGE/description.txt
1241 echo "================================================================================"
1242 echo ""
1243 else
1244 echo -e "\nSorry, no description available for this package.\n"
1245 fi
1246 ;;
1247 search)
1248 # Search for a package by pattern or name.
1250 PATTERN="$2"
1251 if [ -z "$PATTERN" ]; then
1252 echo -e "\nPlease specify a pattern or package name to search for."
1253 echo -e "Example : 'tazpkg search paint'.\n"
1254 exit 0
1255 fi
1256 echo ""
1257 echo -e "\033[1mSearch result for :\033[0m $PATTERN"
1258 echo ""
1259 # Default is to search in installed pkgs and the raw list.
1260 case $3 in
1261 -i|--installed)
1262 search_in_installed_packages ;;
1263 -l|--list)
1264 search_in_packages_list ;;
1265 -m|--mirror)
1266 search_in_packages_txt ;;
1267 *)
1268 search_in_installed_packages
1269 search_in_packages_list ;;
1270 esac
1271 ;;
1272 search-file)
1273 # Search for a file by pattern or name in all files.list.
1275 if [ -z "$2" ]; then
1276 echo -e "\nPlease specify a pattern or file name to search for."
1277 echo -e "Example : 'tazpkg search-file libnss'. \n"
1278 exit 0
1279 fi
1280 echo ""
1281 echo -e "\033[1mSearch result for file :\033[0m $2"
1282 echo "================================================================================"
1284 if [ "$3" == "--mirror" ]; then
1286 match=0
1287 for i in $LOCALSTATE/files.list.lzma \
1288 $LOCALSTATE/undigest/*/files.list.lzma; do
1289 [ -f $i ] || continue
1290 unlzma -c $i | grep -- ".*:.*$2" | awk '
1291 BEGIN { last="" }
1293 pkg=substr($0,0,index($0,":")-1);
1294 file=substr($0,index($0,":")+2);
1295 if (last != pkg) {
1296 last = pkg;
1297 printf("\n%c[1mPackage %s :%c[0m\n",27,pkg,27);
1299 printf("%s\n",file);
1300 }'
1301 match=$(($match + `unlzma -c $i | grep -- ".*:.*$2" | wc -l`))
1302 done
1304 else
1306 # Check all pkg files.list in search match with specify the package
1307 # name and the full path to the file(s).
1308 for pkg in $INSTALLED/*
1309 do
1310 if grep -qs "$2" $pkg/files.list; then
1311 . $pkg/receipt
1312 echo ""
1313 echo -e "\033[1mPackage $PACKAGE :\033[0m"
1314 grep "$2" $pkg/files.list
1315 files=`grep $2 $pkg/files.list | wc -l`
1316 match=$(($match+$files))
1317 fi
1318 done
1320 fi
1322 if [ "$match" = "" ]; then
1323 echo "0 file found for : $2"
1324 echo ""
1325 else
1326 echo ""
1327 echo "================================================================================"
1328 echo "$match file(s) found for : $2"
1329 echo ""
1330 fi
1331 ;;
1332 install)
1333 # Install .tazpkg packages.
1335 check_root
1336 check_for_package_on_cmdline
1337 check_for_package_file
1338 # Check if forced install.
1339 DO_CHECK="yes"
1340 ROOT=""
1341 while [ -n "$3" ]; do
1342 case "$3" in
1343 --forced)
1344 DO_CHECK="no"
1345 ;;
1346 --root=*)
1347 ROOT="${3#--root=}"
1348 ;;
1349 --list=*)
1350 INSTALL_LIST="${3#--list=}"
1351 ;;
1352 *) shift 2
1353 echo -e "\nUnknown option $*.\n"
1354 exit 1
1355 ;;
1356 esac
1357 shift
1358 done
1359 if [ "$DO_CHECK" = "yes" ]; then
1360 check_for_installed_package $ROOT
1361 fi
1362 install_package $ROOT
1363 ;;
1364 install-list|get-install-list)
1365 # Install a set of packages from a list.
1367 check_root
1368 if [ -z "$2" ]; then
1369 echo -e "
1370 Please change directory (cd) to the packages repository, and specify the
1371 list of packages to install. Example : tazpkg install-list packages.list\n"
1372 exit 0
1373 fi
1374 # Check if the packages list exist.
1375 if [ ! -f "$2" ]; then
1376 echo "Unable to find : $2"
1377 exit 0
1378 else
1379 LIST=`cat $2`
1380 fi
1382 # Remember processed list
1383 export INSTALL_LIST="$2"
1385 # Set $COMMAND and install all packages.
1386 if [ "$1" = "get-install-list" ]; then
1387 COMMAND=get-install
1388 else
1389 COMMAND=install
1390 fi
1391 touch $2-processed
1392 for pkg in $LIST
1393 do
1394 grep -qs ^$pkg$ $2-processed && continue
1395 tazpkg $COMMAND $pkg --list=$2 "$3" "$4" "$5"
1396 done
1397 rm -f $2-processed
1398 ;;
1399 add-flavor)
1400 # Install a set of packages from a flavor.
1402 install_flavor $2
1403 ;;
1404 install-flavor)
1405 # Install a set of packages from a flavor and purge other ones.
1407 install_flavor $2 --purge
1408 ;;
1409 set-release)
1410 # Change curent release and upgrade packages.
1412 RELEASE=$2
1413 if [ -z "$RELEASE" ]; then
1414 echo -e "\nPlease specify the release you want on the command line."
1415 echo -e "Example: tazpkg set-release cooking\n"
1416 exit 0
1417 fi
1418 rm /var/lib/tazpkg/mirror
1419 echo "$RELEASE" > /etc/slitaz-release
1420 tazpkg recharge && tazpkg upgrade
1422 # Install missing depends
1423 cd $INSTALLED
1424 for i in * ; do
1425 DEPENDS=""
1426 . $i/receipt
1427 for j in $DEPENDS ; do
1428 [ -d $j ] || tazpkg get-install $j
1429 done
1430 done
1431 ;;
1432 remove)
1433 # Remove packages.
1435 check_root
1436 check_for_package_on_cmdline
1437 if [ ! -f "$INSTALLED/$PACKAGE/receipt" ]; then
1438 echo -e "\n$PACKAGE is not installed.\n"
1439 exit 0
1440 else
1441 ALTERED=""
1442 THE_PACKAGE=$PACKAGE # altered by receipt
1443 for i in $(cd $INSTALLED ; ls); do
1444 [ -f $INSTALLED/$i/receipt ] || continue
1445 DEPENDS=""
1446 . $INSTALLED/$i/receipt
1447 case " $(echo $DEPENDS) " in
1448 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
1449 esac
1450 done
1451 EXTRAVERSION=""
1452 . $INSTALLED/$THE_PACKAGE/receipt
1453 fi
1454 echo ""
1455 if [ -n "$ALTERED" ]; then
1456 echo "The following packages depend on $PACKAGE :"
1457 for i in $ALTERED; do
1458 echo " $i"
1459 done
1460 fi
1461 REFRESH=$(cd $INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1462 if [ -n "$REFRESH" ]; then
1463 echo "The following packages have been modified by $PACKAGE :"
1464 for i in $REFRESH; do
1465 echo " ${i%/modifiers}"
1466 done
1467 fi
1468 echo "Remove $PACKAGE ($VERSION$EXTRAVERSION) ?"
1469 echo -n "Please confirm uninstallation (y/N) : "; read anser
1470 if [ "$anser" = "y" ]; then
1471 echo ""
1472 echo -e "\033[1mRemoving :\033[0m $PACKAGE"
1473 echo "================================================================================"
1474 # Pre remove commands.
1475 if grep -q ^pre_remove $INSTALLED/$PACKAGE/receipt; then
1476 pre_remove
1477 fi
1478 echo -n "Removing all files installed..."
1479 if [ -f $INSTALLED/$PACKAGE/modifiers ]; then
1480 for mod in `cat $INSTALLED/$PACKAGE/modifiers`
1481 do
1482 for file in `cat $INSTALLED/$PACKAGE/files.list`
1483 do
1484 [ $(grep ^$file$ $INSTALLED/$mod/files.list | wc -l) -gt 1 ] && continue
1485 rm -f $file 2>/dev/null
1486 dir="$file"
1487 while [ "$dir" != "/" ]; do
1488 dir="$(dirname $dir)"
1489 rmdir $dir 2> /dev/null || break
1490 done
1491 done
1492 done
1493 else
1494 for file in `cat $INSTALLED/$PACKAGE/files.list`
1495 do
1496 rm -f $file 2>/dev/null
1497 dir="$file"
1498 while [ "$dir" != "/" ]; do
1499 dir="$(dirname $dir)"
1500 rmdir $dir 2> /dev/null || break
1501 done
1502 done
1503 fi
1504 status
1505 if grep -q ^post_remove $INSTALLED/$PACKAGE/receipt; then
1506 post_remove
1507 fi
1508 # Remove package receipt.
1509 echo -n "Removing package receipt..."
1510 rm -rf $INSTALLED/$PACKAGE
1511 status
1512 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION$/d" \
1513 $LOCALSTATE/installed.md5 2> /dev/null
1514 # Log this activity
1515 log Removed
1516 if [ -n "$ALTERED" ]; then
1517 echo -n "Remove packages depending on $PACKAGE"
1518 echo -n " (y/N) ? "; read anser
1519 if [ "$anser" = "y" ]; then
1520 for i in $ALTERED; do
1521 if [ -d "$INSTALLED/$i" ]; then
1522 tazpkg remove $i
1523 fi
1524 done
1525 fi
1526 fi
1527 if [ -n "$REFRESH" ]; then
1528 echo -n "Reinstall packages modified by $PACKAGE"
1529 echo -n " (y/N) ? "; read anser
1530 if [ "$anser" = "y" ]; then
1531 for i in $REFRESH; do
1532 if [ $(wc -l < $INSTALLED/$i) -gt 1 ]; then
1533 echo "Check $INSTALLED/$i for reinstallation"
1534 continue
1535 fi
1536 rm -r $INSTALLED/$i
1537 tazpkg get-install ${i%/modifiers} --forced
1538 done
1539 fi
1540 fi
1541 else
1542 echo ""
1543 echo "Uninstallation of $PACKAGE cancelled."
1544 fi
1545 echo ""
1546 ;;
1547 extract)
1548 # Extract .tazpkg cpio archive into a directory.
1550 check_for_package_on_cmdline
1551 check_for_package_file
1552 echo ""
1553 echo -e "\033[1mExtracting :\033[0m $PACKAGE"
1554 echo "================================================================================"
1555 # If no directory destination is found on the cmdline
1556 # we create one in the current dir using the package name.
1557 if [ -n "$TARGET_DIR" ]; then
1558 DESTDIR=$TARGET_DIR/$PACKAGE
1559 else
1560 DESTDIR=$PACKAGE
1561 fi
1562 mkdir -p $DESTDIR
1563 echo -n "Copying original package..."
1564 cp $PACKAGE_FILE $DESTDIR
1565 status
1566 cd $DESTDIR
1567 extract_package
1568 echo "================================================================================"
1569 echo "$PACKAGE is extracted to : $DESTDIR"
1570 echo ""
1571 ;;
1572 list-config)
1573 # List configuration files installed.
1575 if [ "$2" = "--box" ]; then
1576 mkdir -p $TMP_DIR && cd $TMP_DIR
1577 FILES="$INSTALLED/*/volatile.cpio.gz"
1578 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
1579 for i in $FILES; do
1580 zcat $i | cpio -idm > /dev/null
1581 find * -type f 2>/dev/null | while read file; do
1582 if [ ! -e /$file ]; then
1583 echo -n "|--|--|--|File lost"
1584 else
1585 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
1586 cmp $file /$file > /dev/null 2>&1 || \
1587 echo -n "$(stat -c "%.16y" /$file)"
1588 fi
1589 echo "|/$file"
1590 done
1591 rm -rf *
1592 done
1593 cd $TOP_DIR
1594 rm -rf $TMP_DIR
1595 else
1596 echo ""
1597 echo -e "\033[1mConfiguration files"
1598 echo "================================================================================"
1599 for i in $INSTALLED/*/volatile.cpio.gz; do
1600 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
1601 [ -f "$i" ] || continue
1602 zcat $i | cpio -t | grep -v "[0-9]* blocks"
1603 done | sed 's|^|/|' | sort
1604 echo "================================================================================"
1605 echo ""
1606 fi
1607 ;;
1608 repack-config)
1609 # Create SliTaz package archive from configuration files.
1611 mkdir -p $TMP_DIR && cd $TMP_DIR
1612 CONFIG_VERSION=1.0
1613 mkdir config-$CONFIG_VERSION
1614 cd config-$CONFIG_VERSION
1615 for i in $INSTALLED/*/volatile.cpio.gz; do
1616 zcat $i | cpio -t | grep -v "[0-9]* blocks"
1617 done > files.list
1618 mkdir fs
1619 cd fs
1620 ( cd / ; cpio -o -H newc ) < ../files.list | cpio -idm > /dev/null
1621 mkdir -p etc/tazlito
1622 for i in $INSTALLED/*/receipt; do
1623 EXTRAVERSION=""
1624 . $i
1625 echo "$PACKAGE-$VERSION$EXTRAVERSION"
1626 done > etc/tazlito/config-packages.list
1627 cd ..
1628 echo "etc/tazlito/config-packages.list" >> files.list
1629 cat > receipt <<EOT
1630 # SliTaz package receipt.
1632 PACKAGE="config"
1633 VERSION="$CONFIG_VERSION"
1634 CATEGORY="base-system"
1635 SHORT_DESC="User configuration backup on $(date)"
1636 DEPENDS="$(ls $INSTALLED)"
1637 EOT
1638 cd ..
1639 tazpkg pack config-$CONFIG_VERSION
1640 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
1641 cd $TOP_DIR
1642 rm -rf $TMP_DIR
1643 ;;
1644 repack)
1645 # Create SliTaz package archive from an installed package.
1647 check_for_package_on_cmdline
1648 check_for_receipt
1649 EXTRAVERSION=""
1650 . $INSTALLED/$PACKAGE/receipt
1651 echo ""
1652 echo -e "\033[1mRepacking :\033[0m $PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
1653 echo "================================================================================"
1654 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
1655 echo "Can't repack $PACKAGE"
1656 exit 1
1657 fi
1658 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
1659 echo "Can't repack, $PACKAGE files have been modified by:"
1660 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
1661 echo " $i"
1662 done
1663 exit 1
1664 fi
1665 MISSING=""
1666 while read i; do
1667 [ -e "$i" ] && continue
1668 [ -L "$i" ] || MISSING="$MISSING\n $i"
1669 done < $INSTALLED/$PACKAGE/files.list
1670 if [ -n "$MISSING" ]; then
1671 echo -n "Can't repack, the following files are lost:"
1672 echo -e "$MISSING"
1673 exit 1
1674 fi
1675 mkdir -p $TMP_DIR && cd $TMP_DIR
1676 FILES="fs.cpio.gz\n"
1677 for i in $(ls $INSTALLED/$PACKAGE) ; do
1678 [ "$i" = "volatile.cpio.gz" ] && continue
1679 [ "$i" = "modifiers" ] && continue
1680 cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
1681 done
1682 ln -s / rootfs
1683 mkdir tmp
1684 sed 's/^/rootfs/' < files.list | cpio -o -H newc 2>/dev/null |\
1685 ( cd tmp ; cpio -idm 2>/dev/null )
1686 mv tmp/rootfs fs
1687 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
1688 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
1689 ( cd fs; cpio -idm )
1690 fi
1691 if grep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
1692 . $INSTALLED/$PACKAGE/receipt
1693 repack_cleanup fs
1694 fi
1695 if [ -f $INSTALLED/$PACKAGE/md5sum ]; then
1696 sed 's, , fs,' < $INSTALLED/$PACKAGE/md5sum | \
1697 md5sum -s -c || {
1698 echo "Can't repack, md5sum error."
1699 cd $TOP_DIR
1700 rm -rf $TMP_DIR
1701 exit 1
1703 fi
1704 find fs | cpio -o -H newc 2> /dev/null | gzip -9 > fs.cpio.gz
1705 echo -e "$FILES" | cpio -o -H newc 2> /dev/null > \
1706 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1707 cd $TOP_DIR
1708 \rm -R $TMP_DIR
1709 echo "Package $PACKAGE repacked successfully."
1710 echo "Size : `du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
1711 echo ""
1712 ;;
1713 pack)
1714 # Create SliTaz package archive using cpio and gzip.
1716 check_for_package_on_cmdline
1717 cd $PACKAGE
1718 if [ ! -f "receipt" ]; then
1719 echo "Receipt is missing. Please read the documentation."
1720 exit 0
1721 else
1722 echo ""
1723 echo -e "\033[1mPacking :\033[0m $PACKAGE"
1724 echo "================================================================================"
1725 # Create files.list with redirecting find outpout.
1726 echo -n "Creating the list of files..." && cd fs
1727 find . -type f -print > ../files.list
1728 find . -type l -print >> ../files.list
1729 cd .. && sed -i s/'^.'/''/ files.list
1730 status
1731 echo -n "Creating md5sum of files..."
1732 while read file; do
1733 [ -L "fs$file" ] && continue
1734 [ -f "fs$file" ] || continue
1735 case "$file" in
1736 /lib/modules/*/modules.*|*.pyc) continue;;
1737 esac
1738 md5sum "fs$file" | sed 's/ fs/ /'
1739 done < files.list > md5sum
1740 status
1741 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
1742 description.txt 2> /dev/null | awk \
1743 '{ sz=$1 } END { print sz }')
1744 # Build cpio archives.
1745 echo -n "Compressing the fs... "
1746 find fs -print | cpio -o -H newc | gzip > fs.cpio.gz
1747 rm -rf fs
1748 status
1749 PACKED_SIZE=$(du -chs fs.cpio.gz receipt files.list \
1750 md5sum description.txt 2> /dev/null | awk \
1751 '{ sz=$1 } END { print sz }')
1752 echo -n "Undating receipt sizes..."
1753 sed -i s/^PACKED_SIZE.*$// receipt
1754 sed -i s/^UNPACKED_SIZE.*$// receipt
1755 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1756 status
1757 echo -n "Creating full cpio archive... "
1758 find . -print | cpio -o -H newc > ../$PACKAGE.tazpkg
1759 status
1760 echo -n "Restoring original package tree... "
1761 zcat fs.cpio.gz | cpio -idm
1762 status
1763 rm fs.cpio.gz && cd ..
1764 echo "================================================================================"
1765 echo "Package $PACKAGE compressed successfully."
1766 echo "Size : `du -sh $PACKAGE.tazpkg`"
1767 echo ""
1768 fi
1769 ;;
1770 recharge)
1771 # Recharge packages.list from a mirror.
1773 check_root
1774 for path in $LOCALSTATE $LOCALSTATE/undigest/*; do
1775 [ -f $path/mirror ] || continue
1776 echo ""
1777 if [ "$path" != "$LOCALSTATE" ]; then
1778 echo "Recharge undigest $(basename $path):"
1779 fi
1780 cd $path
1781 if [ -f "packages.list" ]; then
1782 echo -n "Creating backup of the last packages list..."
1783 mv -f packages.desc packages.desc.bak 2>/dev/null
1784 mv -f packages.md5 packages.md5.txt 2>/dev/null
1785 mv -f packages.txt packages.txt.bak 2>/dev/null
1786 mv -f packages.list packages.list.bak 2>/dev/null
1787 mv -f packages.equiv packages.equiv.bak 2>/dev/null
1788 mv -f files.list.lzma files.list.lzma.bak 2> /dev/null
1789 mv -f mirrors mirrors.bak 2> /dev/null
1790 status
1791 fi
1792 download_from "$(cat mirror)" packages.desc
1793 download_from "$(cat mirror)" packages.md5
1794 download_from "$(cat mirror)" packages.txt
1795 download_from "$(cat mirror)" packages.list
1796 download_from "$(cat mirror)" packages.equiv
1797 download_from "$(cat mirror)" files.list.lzma
1798 download_from "$(cat mirror)" mirrors
1799 [ -f mirrors ] || mv mirrors.bak mirrors 2> /dev/null
1800 suffix=$(head -1 mirror)
1801 suffix=packages${suffix#*/packages}
1802 for i in $(cat mirrors 2> /dev/null); do
1803 grep -qs $i mirror || echo $i$suffix >> mirror
1804 done
1805 if [ -f "packages.list.bak" ]; then
1806 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
1807 sed -i s/+// packages.diff
1808 echo ""
1809 echo -e "\033[1mMirrored packages diff\033[0m"
1810 echo "================================================================================"
1811 cat packages.diff
1812 if [ ! "`cat packages.diff | wc -l`" = 0 ]; then
1813 echo "================================================================================"
1814 echo "`cat packages.diff | wc -l` new packages on the mirror."
1815 echo ""
1816 else
1817 echo "`cat packages.diff | wc -l` new packages on the mirror."
1818 echo ""
1819 fi
1820 else
1821 echo -e "
1822 ================================================================================
1823 Last packages.list is ready to use. Note that next time you recharge the list,
1824 a list of differences will be displayed to show new and upgradeable packages.\n"
1825 fi
1826 done
1827 ;;
1828 upgrade)
1829 # Upgrade all installed packages with the new version from the mirror.
1831 check_root
1832 check_for_packages_list
1833 cd $LOCALSTATE
1834 # Touch the blocked pkgs list to avoid errors and remove any old
1835 # upgrade list.
1836 touch blocked-packages.list
1837 rm -f upgradeable-packages.list
1838 echo ""
1839 echo -e "\033[1mAvailable upgrades\033[0m"
1840 echo "================================================================================"
1841 echo ""
1842 # Some packages must be installed first
1843 FIRST_CLASS_PACKAGE=" glibc-base slitaz-base-files slitaz-boot-scripts "
1844 if [ -n "$PACKAGE_FILE" -a -d "$INSTALLED/$PACKAGE_FILE" ]; then
1845 ALL=$INSTALLED/$PACKAGE_FILE
1846 else
1847 ALL="$(ls -d $INSTALLED/*)"
1848 fi
1849 for pkg in $ALL
1850 do
1851 [ -f $pkg/receipt ] || continue
1852 EXTRAVERSION=""
1853 . $pkg/receipt
1854 # Display package name to show that Tazpkg is working...
1855 echo -en "\\033[0G "
1856 echo -en "\\033[0G$PACKAGE"
1857 # Skip specified pkgs listed in $LOCALSTATE/blocked-packages.list
1858 if grep -qs "^$PACKAGE" $BLOCKED; then
1859 blocked=$(($blocked+1))
1860 else
1861 # Check if the installed package is in the current list (other
1862 # mirror or local).
1863 NEW_PACKAGE=$(get_package_filename $PACKAGE)
1865 if [ -n "$NEW_PACKAGE" ]; then
1866 # Set new pkg and version for future comparison
1867 NEW_VERSION=`echo $NEW_PACKAGE | sed s/$PACKAGE-/''/`
1868 # Change '-' and 'pre' to points.
1869 NEW_VERSION=`echo $NEW_VERSION | sed s/'-'/'.'/`
1870 VERSION=`echo $VERSION | sed s/'-'/'.'/`$EXTRAVERSION
1871 NEW_VERSION=`echo $NEW_VERSION | sed s/'pre'/'.'/`
1872 VERSION=`echo $VERSION | sed s/'pre'/'.'/`
1873 NEW_VERSION=`echo $NEW_VERSION | sed 's/[A-Z]\.//'`
1874 VERSION=`echo $VERSION | sed 's/[A-Z]\.//'`
1875 # Compare version. Upgrades are only available for official
1876 # packages, so we control the mirror and it should be ok if
1877 # we just check for equality.
1878 RELEASE=""
1879 if [ -f installed.md5 -a -f packages.md5 ]; then
1880 current_md5=$(grep -s " $PACKAGE-$VERSION" installed.md5 | awk '{ print $1 }')
1881 new_md5=$(grep -hs " $PACKAGE-$VERSION" packages.md5 undigest/*/packages.md5 | head -1 | awk '{ print $1 }')
1882 [ -n "$current_md5" ] && [ -n "$new_md5" ] &&
1883 [ "$current_md5" != "$new_md5" ] && RELEASE=build
1884 fi
1885 if [ "$VERSION" != "$NEW_VERSION" -o -n "$RELEASE" ]; then
1886 # Version seems different. Check for major, minor or
1887 # revision
1888 PKG_MAJOR=`echo ${VERSION%_*} | cut -f1 -d"."`
1889 NEW_MAJOR=`echo ${NEW_VERSION%_*} | cut -f1 -d"."`
1890 PKG_MINOR=`echo ${VERSION%_*} | cut -f2 -d"."`
1891 NEW_MINOR=`echo ${NEW_VERSION%_*} | cut -f2 -d"."`
1892 # Minor
1893 if [ "$NEW_MINOR" -gt "$PKG_MINOR" ] 2> /dev/null; then
1894 RELEASE=minor
1895 fi
1896 if [ "$NEW_MINOR" -lt "$PKG_MINOR" ] 2> /dev/null; then
1897 RELEASE=$WARNING
1898 FIXE=yes
1899 fi
1900 # Major
1901 if [ "$NEW_MAJOR" -gt "$PKG_MAJOR" ] 2> /dev/null; then
1902 RELEASE=major
1903 FIXE=""
1904 fi
1905 if [ "$NEW_MAJOR" -lt "$PKG_MAJOR" ] 2> /dev/null; then
1906 RELEASE=$WARNING
1907 FIXE=yes
1908 fi
1909 # Default to revision.
1910 if [ -z $RELEASE ]; then
1911 RELEASE=revision
1912 fi
1913 # Pkg name is already displayed by the check process.
1914 echo -en "\033[24G $VERSION"
1915 echo -en "\033[38G --->"
1916 echo -en "\033[43G $NEW_VERSION"
1917 echo -en "\033[58G $CATEGORY"
1918 echo -e "\033[72G $RELEASE"
1919 up=$(($up+1))
1920 echo "$PACKAGE" >> upgradeable-packages.list
1921 case "$FIRST_CLASS_PACKAGE" in
1922 *\ $PACKAGE\ *) echo "$PACKAGE" >> upgradeable-packages.list$$;;
1923 esac
1924 unset RELEASE
1925 fi
1926 packages=$(($packages+1))
1927 fi
1928 fi
1929 done
1930 if [ -z $blocked ]; then
1931 blocked=0
1932 fi
1933 # Clean last checked package and display summary.
1934 if [ ! "$up" = "" ]; then
1935 echo -e "\\033[0G "
1936 echo "================================================================================"
1937 echo "$packages installed and listed packages to consider, $up to upgrade, $blocked blocked."
1938 echo ""
1939 else
1940 echo -e "\\033[0GSystem is up-to-date. "
1941 echo ""
1942 echo "================================================================================"
1943 echo "$packages installed and listed packages to consider, 0 to upgrade, $blocked blocked."
1944 echo ""
1945 exit 0
1946 fi
1947 # What to do if major or minor version is smaller.
1948 if [ "$FIXE" == "yes" ]; then
1949 echo -e "$WARNING ---> Installed package seems more recent than the mirrored one."
1950 echo "You can block packages using the command : 'tazpkg block package'"
1951 echo "Or upgrade packages at your own risk."
1952 echo ""
1953 fi
1954 # Ask for upgrade, it can be done another time.
1955 echo -n "Upgrade now (y/N) ? "; read anser
1956 if [ ! "$anser" = "y" ]; then
1957 echo -e "\nExiting. No package upgraded.\n"
1958 exit 0
1959 fi
1960 # If anser is yes (y). Install all new versions.
1961 cat upgradeable-packages.list >> upgradeable-packages.list$$
1962 mv -f upgradeable-packages.list$$ upgradeable-packages.list
1963 yes y | tazpkg get-install-list upgradeable-packages.list --forced
1964 rm -f upgradeable-packages.list
1965 ;;
1966 bugs)
1967 # Show known bugs in package(s)
1969 cd $INSTALLED
1970 shift
1971 LIST=$@
1972 [ -n "$LIST" ] || LIST=`ls`
1973 MSG="No known bugs."
1974 for PACKAGE in $LIST; do
1975 BUGS=""
1976 EXTRAVERSION=""
1977 . $PACKAGE/receipt
1978 if [ -n "$BUGS" ]; then
1979 MSG="
1980 Bug list completed"
1981 cat <<EOT
1983 Bugs in package $PACKAGE version $VERSION$EXTRAVERSION:
1984 $BUGS
1985 EOT
1986 fi
1987 done
1988 echo "$MSG"
1989 ;;
1990 check)
1991 # Check installed packages set.
1993 check_root
1994 cd $INSTALLED
1995 for PACKAGE in `ls`; do
1996 if [ ! -f $PACKAGE/receipt ]; then
1997 echo "The package $PACKAGE installation is not completed"
1998 continue
1999 fi
2000 DEPENDS=""
2001 EXTRAVERSION=""
2002 . $PACKAGE/receipt
2003 if [ -s $PACKAGE/modifiers ]; then
2004 echo "The package $PACKAGE $VERSION$EXTRAVERSION has been modified by :"
2005 for i in $(cat $PACKAGE/modifiers); do
2006 echo " $i"
2007 done
2008 fi
2009 MSG="Files lost from $PACKAGE $VERSION$EXTRAVERSION :\n"
2010 while read file; do
2011 [ -e "$file" ] && continue
2012 if [ -L "$file" ]; then
2013 MSG="$MSG target of symlink"
2014 fi
2015 echo -e "$MSG $file"
2016 MSG=""
2017 done < $PACKAGE/files.list
2018 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n"
2019 for i in $DEPENDS; do
2020 [ -d $i ] && continue
2021 echo -e "$MSG $i"
2022 MSG=""
2023 done
2024 MSG="Dependencies loop between $PACKAGE and :\n"
2025 ALL_DEPS=""
2026 check_for_deps_loop $PACKAGE $DEPENDS
2027 done
2028 echo -n "Looking for known bugs... "
2029 tazpkg bugs
2030 if [ "$PACKAGE_FILE" = "--full" ]; then
2031 for file in */md5sum; do
2032 CONFIG_FILES=""
2033 . $(dirname "$file")/receipt
2034 [ -s "$file" ] || continue
2035 while read md5 f; do
2036 [ -f $f ] || continue
2037 for i in $CONFIG_FILES; do
2038 case "$f" in
2039 $i|$i/*) continue 2;;
2040 esac
2041 done
2042 echo "$md5 $f"
2043 done < "$file" | md5sum -c - 2> /dev/null | \
2044 grep -v OK$ | sed 's/FAILED$/MD5SUM MISMATCH/'
2045 done
2046 FILES=" "
2047 for file in $(cat */files.list); do
2048 [ -d "$file" ] && continue
2049 case "$FILES" in *\ $file\ *) continue;; esac
2050 [ $(grep "^$file$" */files.list 2> /dev/null | \
2051 wc -l) -gt 1 ] || continue
2052 FILES="$FILES$file "
2053 echo "The following packages provide $file :"
2054 grep -l "^$file$" */files.list | while read f
2055 do
2056 pkg=${f%/files.list}
2057 echo -n " $pkg"
2058 if [ -f $pkg/modifiers ]; then
2059 echo -n " (overridden by $(echo "$(cat $pkg/modifiers)"))"
2060 fi
2061 echo ""
2062 done
2063 done
2064 MSG="No package has installed the following files:\n"
2065 find /etc /bin /sbin /lib /usr /var/www \
2066 -not -type d 2> /dev/null | while read file; do
2067 case "$file" in *\[*) continue;; esac
2068 grep -q "^$file$" */files.list && continue
2069 echo -e "$MSG $file"
2070 MSG=""
2071 done
2072 fi
2073 echo "Check completed."
2074 ;;
2075 block)
2076 # Add a pkg name to the list of blocked packages.
2078 check_root
2079 check_for_package_on_cmdline
2080 echo ""
2081 if grep -qs "^$PACKAGE" $BLOCKED; then
2082 echo "$PACKAGE is already in the blocked packages list."
2083 echo ""
2084 exit 0
2085 else
2086 echo -n "Add $PACKAGE to : $BLOCKED..."
2087 echo $PACKAGE >> $BLOCKED
2088 status
2089 # Log this activity
2090 . $INSTALLED/$PACKAGE/receipt
2091 log Blocked
2092 fi
2093 echo ""
2094 ;;
2095 unblock)
2096 # Remove a pkg name from the list of blocked packages.
2098 check_root
2099 check_for_package_on_cmdline
2100 echo ""
2101 if grep -qs "^$PACKAGE" $BLOCKED; then
2102 echo -n "Removing $PACKAGE from : $BLOCKED..."
2103 sed -i s/$PACKAGE/''/ $BLOCKED
2104 sed -i '/^$/d' $BLOCKED
2105 status
2106 # Log this activity
2107 . $INSTALLED/$PACKAGE/receipt
2108 log Unblocked
2109 else
2110 echo "$PACKAGE is not in the blocked packages list."
2111 echo ""
2112 exit 0
2113 fi
2114 echo ""
2115 ;;
2116 get)
2117 # Downlowd a package with wget.
2119 check_for_package_on_cmdline
2120 check_for_packages_list
2121 check_for_package_in_list
2122 echo ""
2123 download $PACKAGE.tazpkg
2124 echo ""
2125 ;;
2126 get-install)
2127 # Download and install a package.
2129 check_root
2130 check_for_package_on_cmdline
2131 check_for_packages_list
2132 DO_CHECK=""
2133 while [ -n "$3" ]; do
2134 case "$3" in
2135 --forced)
2136 DO_CHECK="no"
2137 ;;
2138 --root=*)
2139 ROOT="${3#--root=}"
2140 ;;
2141 --list=*)
2142 INSTALL_LIST="${3#--list=}"
2143 ;;
2144 *) shift 2
2145 echo -e "\nUnknown option $*.\n"
2146 exit 1
2147 ;;
2148 esac
2149 shift
2150 done
2151 AUTOEXEC="no"
2152 if ! check_for_package_in_list check; then
2153 PACKAGE=get-$PACKAGE
2154 AUTOEXEC=$PACKAGE
2155 check_for_package_in_list
2156 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
2157 $AUTOEXEC $ROOT
2158 exit 0
2159 fi
2160 fi
2161 # Check if forced install.
2162 if [ "$DO_CHECK" = "no" ]; then
2163 rm -f $CACHE_DIR/$PACKAGE.tazpkg
2164 else
2165 check_for_installed_package $ROOT
2166 fi
2167 cd $CACHE_DIR
2168 if [ -f "$PACKAGE.tazpkg" ]; then
2169 echo "$PACKAGE already in the cache : $CACHE_DIR"
2170 # Check package download was finished
2171 tail -c 2k $PACKAGE.tazpkg | grep -q 00000000TRAILER || {
2172 echo "Continue $PACKAGE download"
2173 download $PACKAGE.tazpkg
2175 else
2176 echo ""
2177 download $PACKAGE.tazpkg
2178 fi
2179 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2180 install_package $ROOT
2181 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
2182 ;;
2183 clean-cache)
2184 # Remove all downloaded packages.
2186 check_root
2187 files=`ls -1 $CACHE_DIR | wc -l`
2188 echo ""
2189 echo -e "\033[1mClean cache :\033[0m $CACHE_DIR"
2190 echo "================================================================================"
2191 echo -n "Cleaning cache directory..."
2192 rm -rf $CACHE_DIR/*
2193 status
2194 echo "================================================================================"
2195 echo "$files file(s) removed from cache."
2196 echo ""
2197 ;;
2198 list-undigest)
2199 # list undigest URLs.
2201 if [ "$2" = "--box" ]; then
2202 for i in $LOCALSTATE/undigest/*/mirror; do
2203 [ -f $i ] || continue
2204 echo "$(basename $(dirname $i))|$(cat $i)"
2205 done
2206 else
2207 echo ""
2208 echo -e "\033[1mCurrent undigest(s)\033[0m"
2209 echo "================================================================================"
2210 for i in $LOCALSTATE/undigest/*/mirror; do
2211 if [ ! -f $i ]; then
2212 echo "No undigest mirror found."
2213 exit 1
2214 fi
2215 echo "$(basename $(dirname $i)) $(cat $i)"
2216 done
2217 echo ""
2218 fi
2219 ;;
2220 remove-undigest)
2221 # remove undigest URL.
2223 check_root
2224 if [ -d $LOCALSTATE/undigest/$2 ]; then
2225 echo -n "Remove $2 undigest (y/N) ? "; read anser
2226 if [ "$anser" = "y" ]; then
2227 echo -n "Removing $2 undigest..."
2228 rm -rf $LOCALSTATE/undigest/$2
2229 status
2230 rmdir $LOCALSTATE/undigest 2> /dev/null
2231 fi
2232 else
2233 echo "Undigest $2 not found"
2234 fi
2235 ;;
2236 add-undigest|setup-undigest)
2237 # Add undigest URL.
2239 check_root
2240 undigest=$2
2241 [ -d $LOCALSTATE/undigest ] || mkdir $LOCALSTATE/undigest
2242 if [ -z "$undigest" ]; then
2243 i=1
2244 while [ -d $LOCALSTATE/undigest/$i ]; do
2245 i=$(($i+1))
2246 done
2247 undigest=$i
2248 fi
2249 if [ ! -d $LOCALSTATE/undigest/$undigest ]; then
2250 echo "Creating new undigest $undigest."
2251 mkdir $LOCALSTATE/undigest/$undigest
2252 fi
2253 setup_mirror $LOCALSTATE/undigest/$undigest $3
2254 ;;
2255 setup-mirror)
2256 # Change mirror URL.
2258 check_root
2259 setup_mirror $LOCALSTATE $2
2260 ;;
2261 reconfigure)
2262 # Replay post_install from receipt
2264 check_for_package_on_cmdline
2265 check_root
2266 ROOT=""
2267 while [ -n "$3" ]; do
2268 case "$3" in
2269 --root=*)
2270 ROOT="${3#--root=}/"
2271 ;;
2272 *) shift 2
2273 echo -e "\nUnknown option $*.\n"
2274 exit 1
2275 ;;
2276 esac
2277 shift
2278 done
2279 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2280 check_for_receipt $ROOT
2281 # Check for post_install
2282 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2283 . $ROOT$INSTALLED/$PACKAGE/receipt
2284 post_install $ROOT
2285 # Log this activity
2286 [ -n "$ROOT" ] || log Reconfigured
2287 else
2288 echo -e "\nNothing to do for $PACKAGE."
2289 fi
2290 else
2291 echo -e "\npackage $PACKAGE is not installed."
2292 echo -e "Install package with 'tazpkg install' or 'tazpkg get-install'\n"
2293 fi
2294 ;;
2295 shell)
2296 # Tazpkg SHell
2298 if test $(id -u) = 0 ; then
2299 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2300 else
2301 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2302 fi
2303 if [ ! "$2" = "--noheader" ]; then
2304 clear
2305 echo ""
2306 echo -e "\033[1mTazpkg SHell.\033[0m"
2307 echo "================================================================================"
2308 echo "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
2309 echo ""
2310 fi
2311 while true
2312 do
2313 echo -en "$PROMPT"; read cmd
2314 case $cmd in
2315 q|quit)
2316 break ;;
2317 shell)
2318 echo "You are already running a Tazpkg SHell." ;;
2319 su)
2320 su -c 'exec tazpkg shell --noheader' && break ;;
2321 "")
2322 continue ;;
2323 *)
2324 tazpkg $cmd ;;
2325 esac
2326 done
2327 ;;
2328 depends)
2329 # Display dependencies tree
2330 cd $INSTALLED
2331 ALL_DEPS=""
2332 if [ -f $2/receipt ]; then
2333 dep_scan $2 ""
2334 fi
2335 ;;
2336 rdepends)
2337 # Display reverse dependencies tree
2338 cd $INSTALLED
2339 ALL_DEPS=""
2340 if [ -f $2/receipt ]; then
2341 rdep_scan $2
2342 fi
2343 ;;
2344 convert)
2345 # convert misc package format to .tazpkg
2346 check_for_package_file
2347 case "$PACKAGE_FILE" in
2348 *.deb|*.udeb)
2349 convert_deb;;
2350 *.rpm)
2351 convert_rpm;;
2352 *)
2353 echo "Unsupported format";;
2354 esac
2355 ;;
2356 link)
2357 # link a package from another slitaz installation
2358 PACKAGE=$2
2359 if [ ! -d "$TARGET_DIR" -o \
2360 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
2361 cat <<EOT
2362 usage: tazpkg link package_name slitaz_root
2363 example: 'tazpkg link openoffice /mnt' will use less than 100k in
2364 your ram running system.
2365 EOT
2366 exit 1
2367 fi
2368 if [ -e "$INSTALLED/$PACKAGE" ]; then
2369 echo "$PACKAGE is already installed."
2370 exit 1
2371 fi
2372 ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
2373 DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
2374 MISSING=""
2375 for i in $DEPENDS; do
2376 [ -e $INSTALLED/$i ] && continue
2377 MISSING="$MISSING$i "
2378 echo "Missing : $i"
2379 done
2380 if [ -n "$MISSING" ]; then
2381 echo ""
2382 echo -n "Link all missing dependencies (y/N) ? "; read answer
2383 echo ""
2384 if [ "$answer" = "y" ]; then
2385 for i in $MISSING; do
2386 tazpkg link $i $TARGET_DIR
2387 done
2388 else
2389 echo -e "\nLeaving dependencies for $PACKAGE unsolved."
2390 echo -e "The package is installed but will probably not work.\n"
2391 fi
2392 fi
2393 . $INSTALLED/$PACKAGE/receipt
2394 if grep -q ^pre_install $INSTALLED/$PACKAGE/receipt; then
2395 pre_install
2396 fi
2397 while read path; do
2398 [ -e $path ] && continue
2399 while true; do
2400 dir=$(dirname $path)
2401 [ -e $dir ] && break
2402 path=$dir
2403 done
2404 ln -s $TARGET_DIR$path $dir
2405 done < $INSTALLED/$PACKAGE/files.list
2406 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
2407 post_install
2408 fi
2409 ;;
2410 usage|*)
2411 # Print a short help or give usage for an unknown or empty command.
2413 usage
2414 ;;
2415 esac
2417 exit 0