tazpkg view tazpkg @ rev 338

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