tazpkg view tazpkg @ rev 325

output pkgname if filename is given in search: tazpkg search libnss
author Rohit Joshi <jozee@slitaz.org>
date Fri Feb 26 12:48:18 2010 +0000 (2010-02-26)
parents 9a3121405428
children 76f60dfef4f1
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 2>/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 $0 search-pkgname $2;;
1508 esac ;;
1509 search-file)
1510 # Search for a file by pattern or name in all files.list.
1512 if [ -z "$2" ]; then
1513 echo -e "\nPlease specify a pattern or file name to search for."
1514 echo -e "Example : 'tazpkg search-file libnss'. \n"
1515 exit 0
1516 fi
1517 echo ""
1518 echo -e "\033[1mSearch result for file :\033[0m $2"
1519 echo "================================================================================"
1521 if [ "$3" == "--mirror" ]; then
1523 match=0
1524 for i in $LOCALSTATE/files.list.lzma \
1525 $LOCALSTATE/undigest/*/files.list.lzma; do
1526 [ -f $i ] || continue
1527 unlzma -c $i | grep -- ".*:.*$2" | awk '
1528 BEGIN { last="" }
1530 pkg=substr($0,0,index($0,":")-1);
1531 file=substr($0,index($0,":")+2);
1532 if (last != pkg) {
1533 last = pkg;
1534 printf("\n%c[1mPackage %s :%c[0m\n",27,pkg,27);
1536 printf("%s\n",file);
1537 }'
1538 match=$(($match + `unlzma -c $i | grep -- ".*:.*$2" | wc -l`))
1539 done
1541 else
1543 # Check all pkg files.list in search match with specify the package
1544 # name and the full path to the file(s).
1545 for pkg in $INSTALLED/*
1546 do
1547 if grep -qs "$2" $pkg/files.list; then
1548 . $pkg/receipt
1549 echo ""
1550 echo -e "\033[1mPackage $PACKAGE :\033[0m"
1551 grep "$2" $pkg/files.list
1552 files=`grep $2 $pkg/files.list | wc -l`
1553 match=$(($match+$files))
1554 fi
1555 done
1557 fi
1559 if [ "$match" = "" ]; then
1560 echo "0 file found for : $2"
1561 echo ""
1562 else
1563 echo ""
1564 echo "================================================================================"
1565 echo "$match file(s) found for : $2"
1566 echo ""
1567 fi ;;
1568 search-pkgname)
1570 if [ -z "$2" ]; then
1571 echo -e "\nPlease specify a pattern or file name to search for."
1572 echo -e "Example : 'tazpkg search-pkgname libnss'. \n"
1573 exit 0
1574 fi
1575 echo ""
1576 echo -e "\033[1mSearch result for file :\033[0m $2"
1577 echo "================================================================================"
1579 # Search for a file on mirror and output only the package name
1580 match=0
1581 for i in $LOCALSTATE/files.list.lzma \
1582 $LOCALSTATE/undigest/*/files.list.lzma; do
1583 [ -f $i ] || continue
1584 unlzma -c $i | grep -- ".*:.*$2" | cut -d: -f1 | uniq | awk '{ print $1 }'
1585 match=$(($match + `unlzma -c $i | grep -- ".*:.*$2" | cut -d: -f1 | uniq | wc -l`))
1586 done
1588 if [ "$match" = "" ]; then
1589 echo "0 file found for : $2"
1590 echo ""
1591 else
1592 echo ""
1593 echo "================================================================================"
1594 echo "$match pkg(s) found with file : $2"
1595 echo ""
1596 fi
1597 ;;
1598 install)
1599 # Install .tazpkg packages.
1601 check_root
1602 check_for_package_on_cmdline
1603 check_for_package_file
1604 # Check if forced install.
1605 DO_CHECK="yes"
1606 ROOT=""
1607 while [ -n "$3" ]; do
1608 case "$3" in
1609 --forced)
1610 DO_CHECK="no"
1611 ;;
1612 --root=*)
1613 ROOT="${3#--root=}"
1614 ;;
1615 --list=*)
1616 INSTALL_LIST="${3#--list=}"
1617 ;;
1618 *) shift 2
1619 echo -e "\nUnknown option $*.\n"
1620 exit 1
1621 ;;
1622 esac
1623 shift
1624 done
1625 if [ "$DO_CHECK" = "yes" ]; then
1626 check_for_installed_package $ROOT
1627 fi
1628 install_package $ROOT ;;
1629 install-list|get-install-list)
1630 # Install a set of packages from a list.
1632 check_root
1633 if [ -z "$2" ]; then
1634 echo -e "
1635 Please change directory (cd) to the packages repository, and specify the
1636 list of packages to install. Example : tazpkg install-list packages.list\n"
1637 exit 0
1638 fi
1639 # Check if the packages list exist.
1640 if [ ! -f "$2" ]; then
1641 echo "Unable to find : $2"
1642 exit 0
1643 else
1644 LIST=`cat $2`
1645 fi
1647 # Remember processed list
1648 export INSTALL_LIST="$2"
1650 # Set $COMMAND and install all packages.
1651 if [ "$1" = "get-install-list" ]; then
1652 COMMAND=get-install
1653 else
1654 COMMAND=install
1655 fi
1656 touch $2-processed
1658 # Upgrade tazpkg first. It may handle new features/formats...
1659 case " $LIST " in
1660 *\ tazpkg\ *) LIST="tazpkg $LIST";;
1661 esac
1663 for pkg in $LIST
1664 do
1665 grep -qs ^$pkg$ $2-processed && continue
1666 tazpkg $COMMAND $pkg --list=$2 "$3" "$4" "$5"
1667 done
1668 rm -f $2-processed ;;
1669 add-flavor)
1670 # Install a set of packages from a flavor.
1672 install_flavor $2 ;;
1673 install-flavor)
1674 # Install a set of packages from a flavor and purge other ones.
1676 install_flavor $2 --purge ;;
1677 set-release)
1678 # Change curent release and upgrade packages.
1680 RELEASE=$2
1681 if [ -z "$RELEASE" ]; then
1682 echo -e "\nPlease specify the release you want on the command line."
1683 echo -e "Example: tazpkg set-release cooking\n"
1684 exit 0
1685 fi
1686 rm /var/lib/tazpkg/mirror
1687 echo "$RELEASE" > /etc/slitaz-release
1688 tazpkg recharge && tazpkg upgrade
1690 # Install missing depends
1691 cd $INSTALLED
1692 for i in * ; do
1693 DEPENDS=""
1694 . $i/receipt
1695 for j in $DEPENDS ; do
1696 [ -d $j ] || tazpkg get-install $j
1697 done
1698 done ;;
1699 remove)
1700 # Remove packages.
1702 check_root
1703 check_for_package_on_cmdline
1704 if [ ! -f "$INSTALLED/$PACKAGE/receipt" ]; then
1705 echo -e "\n$PACKAGE is not installed.\n"
1706 exit 0
1707 else
1708 ALTERED=""
1709 THE_PACKAGE=$PACKAGE # altered by receipt
1710 for i in $(cd $INSTALLED ; ls); do
1711 [ -f $INSTALLED/$i/receipt ] || continue
1712 DEPENDS=""
1713 . $INSTALLED/$i/receipt
1714 case " $(echo $DEPENDS) " in
1715 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
1716 esac
1717 done
1718 EXTRAVERSION=""
1719 . $INSTALLED/$THE_PACKAGE/receipt
1720 fi
1721 echo ""
1722 if [ -n "$ALTERED" ]; then
1723 echo "The following packages depend on $PACKAGE :"
1724 for i in $ALTERED; do
1725 echo " $i"
1726 done
1727 fi
1728 REFRESH=$(cd $INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1729 if [ -n "$REFRESH" ]; then
1730 echo "The following packages have been modified by $PACKAGE :"
1731 for i in $REFRESH; do
1732 echo " ${i%/modifiers}"
1733 done
1734 fi
1735 echo "Remove $PACKAGE ($VERSION$EXTRAVERSION) ?"
1736 echo -n "Please confirm uninstallation (y/N) : "; read anser
1737 if [ "$anser" = "y" ]; then
1738 echo ""
1739 echo -e "\033[1mRemoving :\033[0m $PACKAGE"
1740 echo "================================================================================"
1741 # Pre remove commands.
1742 if grep -q ^pre_remove $INSTALLED/$PACKAGE/receipt; then
1743 pre_remove
1744 fi
1745 echo -n "Removing all files installed..."
1746 if [ -f $INSTALLED/$PACKAGE/modifiers ]; then
1747 for mod in `cat $INSTALLED/$PACKAGE/modifiers`
1748 do
1749 for file in `cat $INSTALLED/$PACKAGE/files.list`
1750 do
1751 [ $(grep ^$file$ $INSTALLED/$mod/files.list | wc -l) -gt 1 ] && continue
1752 remove_with_path $file
1753 done
1754 done
1755 else
1756 for file in `cat $INSTALLED/$PACKAGE/files.list`
1757 do
1758 remove_with_path $file
1759 done
1760 fi
1761 status
1762 if grep -q ^post_remove $INSTALLED/$PACKAGE/receipt; then
1763 post_remove
1764 fi
1765 # Remove package receipt.
1766 echo -n "Removing package receipt..."
1767 rm -rf $INSTALLED/$PACKAGE
1768 status
1769 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION$/d" \
1770 $LOCALSTATE/installed.md5 2> /dev/null
1771 # Log this activity
1772 log Removed
1773 if [ -n "$ALTERED" ]; then
1774 echo -n "Remove packages depending on $PACKAGE"
1775 echo -n " (y/N) ? "; read anser
1776 if [ "$anser" = "y" ]; then
1777 for i in $ALTERED; do
1778 if [ -d "$INSTALLED/$i" ]; then
1779 tazpkg remove $i
1780 fi
1781 done
1782 fi
1783 fi
1784 if [ -n "$REFRESH" ]; then
1785 echo -n "Reinstall packages modified by $PACKAGE"
1786 echo -n " (y/N) ? "; read anser
1787 if [ "$anser" = "y" ]; then
1788 for i in $REFRESH; do
1789 if [ $(wc -l < $INSTALLED/$i) -gt 1 ]; then
1790 echo "Check $INSTALLED/$i for reinstallation"
1791 continue
1792 fi
1793 rm -r $INSTALLED/$i
1794 tazpkg get-install ${i%/modifiers} --forced
1795 done
1796 fi
1797 fi
1798 else
1799 echo ""
1800 echo "Uninstallation of $PACKAGE cancelled."
1801 fi
1802 echo "" ;;
1803 extract)
1804 # Extract .tazpkg cpio archive into a directory.
1806 check_for_package_on_cmdline
1807 check_for_package_file
1808 echo ""
1809 echo -e "\033[1mExtracting :\033[0m $PACKAGE"
1810 echo "================================================================================"
1811 # If no directory destination is found on the cmdline
1812 # we create one in the current dir using the package name.
1813 if [ -n "$TARGET_DIR" ]; then
1814 DESTDIR=$TARGET_DIR/$PACKAGE
1815 else
1816 DESTDIR=$PACKAGE
1817 fi
1818 mkdir -p $DESTDIR
1819 echo -n "Copying original package..."
1820 cp $PACKAGE_FILE $DESTDIR
1821 status
1822 cd $DESTDIR
1823 extract_package
1824 echo "================================================================================"
1825 echo "$PACKAGE is extracted to : $DESTDIR"
1826 echo "" ;;
1827 recompress)
1828 # Recompress .tazpkg cpio archive with lzma.
1830 check_for_package_on_cmdline
1831 check_for_package_file
1832 echo ""
1833 echo -e "\033[1mRecompressing :\033[0m $PACKAGE"
1834 echo "================================================================================"
1835 mkdir -p $TMP_DIR
1836 echo -n "Copying original package..."
1837 cp $PACKAGE_FILE $TMP_DIR
1838 status
1839 cd $TMP_DIR
1840 extract_package
1841 echo -n "Recompressing the fs... "
1842 find fs | cpio -o -H newc 2> /dev/null | lzma e fs.cpio.lzma -si
1843 rm -rf fs
1844 status
1845 echo -n "Creating new package... "
1846 find . -print | cpio -o -H newc > \
1847 $TOP_DIR/$(basename $PACKAGE_FILE).$$ && mv -f \
1848 $TOP_DIR/$(basename $PACKAGE_FILE).$$ \
1849 $TOP_DIR/$(basename $PACKAGE_FILE)
1850 status
1851 cd $TOP_DIR
1852 rm -rf $TMP_DIR ;;
1853 list-config)
1854 # List configuration files installed.
1856 if [ "$2" = "--box" ]; then
1857 mkdir -p $TMP_DIR && cd $TMP_DIR
1858 FILES="$INSTALLED/*/volatile.cpio.gz"
1859 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
1860 for i in $FILES; do
1861 zcat $i | cpio -idm > /dev/null
1862 find * -type f 2>/dev/null | while read file; do
1863 if [ ! -e /$file ]; then
1864 echo -n "|--|--|--|File lost"
1865 else
1866 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
1867 cmp $file /$file > /dev/null 2>&1 || \
1868 echo -n "$(stat -c "%.16y" /$file)"
1869 fi
1870 echo "|/$file"
1871 done
1872 rm -rf *
1873 done
1874 cd $TOP_DIR
1875 rm -rf $TMP_DIR
1876 else
1877 echo ""
1878 echo -e "\033[1mConfiguration files"
1879 echo "================================================================================"
1880 for i in $INSTALLED/*/volatile.cpio.gz; do
1881 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
1882 [ -f "$i" ] || continue
1883 zcat $i | cpio -t | grep -v "[0-9]* blocks"
1884 done | sed 's|^|/|' | sort
1885 echo "================================================================================"
1886 echo ""
1887 fi ;;
1888 repack-config)
1889 # Create SliTaz package archive from configuration files.
1891 mkdir -p $TMP_DIR && cd $TMP_DIR
1892 CONFIG_VERSION=1.0
1893 mkdir config-$CONFIG_VERSION
1894 cd config-$CONFIG_VERSION
1895 for i in $INSTALLED/*/volatile.cpio.gz; do
1896 zcat $i | cpio -t | grep -v "[0-9]* blocks"
1897 done > files.list
1898 mkdir fs
1899 cd fs
1900 ( cd / ; cpio -o -H newc ) < ../files.list | cpio -idm > /dev/null
1901 mkdir -p etc/tazlito
1902 for i in $INSTALLED/*/receipt; do
1903 EXTRAVERSION=""
1904 . $i
1905 echo "$PACKAGE-$VERSION$EXTRAVERSION"
1906 done > etc/tazlito/config-packages.list
1907 cd ..
1908 echo "etc/tazlito/config-packages.list" >> files.list
1909 cat > receipt <<EOT
1910 # SliTaz package receipt.
1912 PACKAGE="config"
1913 VERSION="$CONFIG_VERSION"
1914 CATEGORY="base-system"
1915 SHORT_DESC="User configuration backup on $(date)"
1916 DEPENDS="$(ls $INSTALLED)"
1917 EOT
1918 cd ..
1919 tazpkg pack config-$CONFIG_VERSION
1920 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
1921 cd $TOP_DIR
1922 rm -rf $TMP_DIR
1923 ;;
1924 repack)
1925 # Create SliTaz package archive from an installed package.
1927 check_for_package_on_cmdline
1928 check_for_receipt
1929 EXTRAVERSION=""
1930 . $INSTALLED/$PACKAGE/receipt
1931 echo ""
1932 echo -e "\033[1mRepacking :\033[0m $PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
1933 echo "================================================================================"
1934 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
1935 echo "Can't repack $PACKAGE"
1936 exit 1
1937 fi
1938 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
1939 echo "Can't repack, $PACKAGE files have been modified by:"
1940 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
1941 echo " $i"
1942 done
1943 exit 1
1944 fi
1945 MISSING=""
1946 while read i; do
1947 [ -e "$i" ] && continue
1948 [ -L "$i" ] || MISSING="$MISSING\n $i"
1949 done < $INSTALLED/$PACKAGE/files.list
1950 if [ -n "$MISSING" ]; then
1951 echo -n "Can't repack, the following files are lost:"
1952 echo -e "$MISSING"
1953 exit 1
1954 fi
1955 mkdir -p $TMP_DIR && cd $TMP_DIR
1956 FILES="fs.cpio.lzma\n"
1957 for i in $(ls $INSTALLED/$PACKAGE) ; do
1958 [ "$i" = "volatile.cpio.gz" ] && continue
1959 [ "$i" = "modifiers" ] && continue
1960 cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
1961 done
1962 ln -s / rootfs
1963 mkdir tmp
1964 sed 's/^/rootfs/' < files.list | cpio -o -H newc 2>/dev/null |\
1965 ( cd tmp ; cpio -idm 2>/dev/null )
1966 mv tmp/rootfs fs
1967 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
1968 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
1969 ( cd fs; cpio -idm )
1970 fi
1971 if grep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
1972 . $INSTALLED/$PACKAGE/receipt
1973 repack_cleanup fs
1974 fi
1975 if [ -f $INSTALLED/$PACKAGE/md5sum ]; then
1976 sed 's, , fs,' < $INSTALLED/$PACKAGE/md5sum | \
1977 md5sum -s -c || {
1978 echo "Can't repack, md5sum error."
1979 cd $TOP_DIR
1980 rm -rf $TMP_DIR
1981 exit 1
1983 fi
1984 find fs | cpio -o -H newc 2> /dev/null | lzma e fs.cpio.lzma -si
1985 echo -e "$FILES" | cpio -o -H newc 2> /dev/null > \
1986 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1987 cd $TOP_DIR
1988 \rm -R $TMP_DIR
1989 echo "Package $PACKAGE repacked successfully."
1990 echo "Size : `du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
1991 echo "" ;;
1992 pack)
1993 # Create SliTaz package archive using cpio and gzip.
1995 check_for_package_on_cmdline
1996 cd $PACKAGE
1997 if [ ! -f "receipt" ]; then
1998 echo "Receipt is missing. Please read the documentation."
1999 exit 0
2000 else
2001 echo ""
2002 echo -e "\033[1mPacking :\033[0m $PACKAGE"
2003 echo "================================================================================"
2004 # Create files.list with redirecting find outpout.
2005 echo -n "Creating the list of files..." && cd fs
2006 find . -type f -print > ../files.list
2007 find . -type l -print >> ../files.list
2008 cd .. && sed -i s/'^.'/''/ files.list
2009 status
2010 echo -n "Creating md5sum of files..."
2011 while read file; do
2012 [ -L "fs$file" ] && continue
2013 [ -f "fs$file" ] || continue
2014 case "$file" in
2015 /lib/modules/*/modules.*|*.pyc) continue;;
2016 esac
2017 md5sum "fs$file" | sed 's/ fs/ /'
2018 done < files.list > md5sum
2019 status
2020 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
2021 description.txt 2> /dev/null | awk \
2022 '{ sz=$1 } END { print sz }')
2023 # Build cpio archives.
2024 echo -n "Compressing the fs... "
2025 find fs | cpio -o -H newc | lzma e fs.cpio.lzma -si
2026 rm -rf fs
2027 status
2028 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
2029 md5sum description.txt 2> /dev/null | awk \
2030 '{ sz=$1 } END { print sz }')
2031 echo -n "Undating receipt sizes..."
2032 sed -i s/^PACKED_SIZE.*$// receipt
2033 sed -i s/^UNPACKED_SIZE.*$// receipt
2034 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
2035 status
2036 echo -n "Creating full cpio archive... "
2037 find . -print | cpio -o -H newc > ../$PACKAGE.tazpkg
2038 status
2039 echo -n "Restoring original package tree... "
2040 unlzma -c fs.cpio.lzma | cpio -idm
2041 status
2042 rm fs.cpio.lzma && cd ..
2043 echo "================================================================================"
2044 echo "Package $PACKAGE compressed successfully."
2045 echo "Size : `du -sh $PACKAGE.tazpkg`"
2046 echo ""
2047 fi ;;
2048 recharge)
2049 # Recharge packages.list from a mirror.
2051 check_root
2052 for path in $LOCALSTATE $LOCALSTATE/undigest/*; do
2053 [ -f $path/mirror ] || continue
2054 echo ""
2055 if [ "$path" != "$LOCALSTATE" ]; then
2056 echo "Recharge undigest $(basename $path):"
2057 fi
2058 cd $path
2059 if [ -f "packages.list" ]; then
2060 echo -n "Creating backup of the last packages list..."
2061 mv -f packages.desc packages.desc.bak 2>/dev/null
2062 mv -f packages.md5 packages.md5.txt 2>/dev/null
2063 mv -f packages.txt packages.txt.bak 2>/dev/null
2064 mv -f packages.list packages.list.bak 2>/dev/null
2065 mv -f packages.equiv packages.equiv.bak 2>/dev/null
2066 mv -f files.list.lzma files.list.lzma.bak 2> /dev/null
2067 mv -f mirrors mirrors.bak 2> /dev/null
2068 status
2069 fi
2070 download_from "$(cat mirror)" packages.desc
2071 download_from "$(cat mirror)" packages.md5
2072 download_from "$(cat mirror)" packages.txt
2073 download_from "$(cat mirror)" packages.list
2074 download_from "$(cat mirror)" packages.equiv
2075 download_from "$(cat mirror)" files.list.lzma
2076 download_from "$(sed 's|packages/.*||' < mirror)" mirrors
2077 [ -f mirrors ] || mv mirrors.bak mirrors 2> /dev/null
2078 suffix=$(head -1 mirror)
2079 suffix=packages${suffix#*/packages}
2080 for i in $(cat mirrors 2> /dev/null); do
2081 grep -qs $i mirror || echo $i$suffix >> mirror
2082 done
2083 if [ -f "packages.list.bak" ]; then
2084 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
2085 sed -i s/+// packages.diff
2086 echo ""
2087 echo -e "\033[1mMirrored packages diff\033[0m"
2088 echo "================================================================================"
2089 cat packages.diff
2090 if [ ! "`cat packages.diff | wc -l`" = 0 ]; then
2091 echo "================================================================================"
2092 echo "`cat packages.diff | wc -l` new packages on the mirror."
2093 echo ""
2094 else
2095 echo "`cat packages.diff | wc -l` new packages on the mirror."
2096 echo ""
2097 fi
2098 else
2099 echo -e "
2100 ================================================================================
2101 Last packages.list is ready to use. Note that next time you recharge the list,
2102 a list of differences will be displayed to show new and upgradeable packages.\n"
2103 fi
2104 done ;;
2105 upgradeable)
2106 # Build upgradeable-packages.list quickly.
2108 check_root
2109 cd $LOCALSTATE
2110 while read md5 file ; do
2111 grep -qs "$md5 $file" packages.md5 && continue
2112 for i in 1 2 3 4 5; do
2113 file=${file%-*}
2114 [ -d installed/$file ] || continue
2115 echo $file
2116 break
2117 done
2118 done < installed.md5 > upgradeable-packages.list ;;
2119 upgrade)
2120 # Upgrade all installed packages with the new version from the mirror.
2122 check_root
2123 check_for_packages_list
2124 cd $LOCALSTATE
2125 # Touch the blocked pkgs list to avoid errors and remove any old
2126 # upgrade list.
2127 touch blocked-packages.list
2128 rm -f upgradeable-packages.list
2129 echo ""
2130 echo -e "\033[1mAvailable upgrades\033[0m"
2131 echo "================================================================================"
2132 echo ""
2133 # Some packages must be installed first
2134 FIRST_CLASS_PACKAGE=" glibc-base slitaz-base-files slitaz-boot-scripts "
2135 if [ -n "$PACKAGE_FILE" -a -d "$INSTALLED/$PACKAGE_FILE" ]; then
2136 ALL=$INSTALLED/$PACKAGE_FILE
2137 else
2138 ALL="$(ls -d $INSTALLED/*)"
2139 fi
2140 for pkg in $ALL
2141 do
2142 [ -f $pkg/receipt ] || continue
2143 EXTRAVERSION=""
2144 . $pkg/receipt
2145 # Display package name to show that Tazpkg is working...
2146 echo -en "\\033[0G "
2147 echo -en "\\033[0G$PACKAGE"
2148 # Skip specified pkgs listed in $LOCALSTATE/blocked-packages.list
2149 if grep -qs "^$PACKAGE" $BLOCKED; then
2150 blocked=$(($blocked+1))
2151 else
2152 # Check if the installed package is in the current list (other
2153 # mirror or local).
2154 NEW_PACKAGE=$(get_package_filename $PACKAGE)
2156 if [ -n "$NEW_PACKAGE" ]; then
2157 # Set new pkg and version for future comparison
2158 NEW_VERSION=`echo $NEW_PACKAGE | sed s/$PACKAGE-/''/`
2159 # Change '-' and 'pre' to points.
2160 NEW_VERSION=`echo $NEW_VERSION | sed s/'-'/'.'/`
2161 VERSION=`echo $VERSION | sed s/'-'/'.'/`$EXTRAVERSION
2162 NEW_VERSION=`echo $NEW_VERSION | sed s/'pre'/'.'/`
2163 VERSION=`echo $VERSION | sed s/'pre'/'.'/`
2164 NEW_VERSION=`echo $NEW_VERSION | sed 's/[A-Z]\.//'`
2165 VERSION=`echo $VERSION | sed 's/[A-Z]\.//'`
2166 # Compare version. Upgrades are only available for official
2167 # packages, so we control the mirror and it should be ok if
2168 # we just check for equality.
2169 RELEASE=""
2170 if [ -f installed.md5 -a -f packages.md5 ]; then
2171 current_md5=$(grep -s " $PACKAGE-$VERSION" installed.md5 | awk '{ print $1 }')
2172 new_md5=$(grep -hs " $PACKAGE-$VERSION" packages.md5 undigest/*/packages.md5 | head -1 | awk '{ print $1 }')
2173 [ -n "$current_md5" ] && [ -n "$new_md5" ] &&
2174 [ "$current_md5" != "$new_md5" ] && RELEASE=build
2175 fi
2176 if [ "$VERSION" != "$NEW_VERSION" -o -n "$RELEASE" ]; then
2177 # Version seems different. Check for major, minor or
2178 # revision
2179 PKG_MAJOR=`echo ${VERSION%_*} | cut -f1 -d"."`
2180 NEW_MAJOR=`echo ${NEW_VERSION%_*} | cut -f1 -d"."`
2181 PKG_MINOR=`echo ${VERSION%_*} | cut -f2 -d"."`
2182 NEW_MINOR=`echo ${NEW_VERSION%_*} | cut -f2 -d"."`
2183 # Minor
2184 if [ "$NEW_MINOR" -gt "$PKG_MINOR" ] 2> /dev/null; then
2185 RELEASE=minor
2186 fi
2187 if [ "$NEW_MINOR" -lt "$PKG_MINOR" ] 2> /dev/null; then
2188 RELEASE=$WARNING
2189 FIXE=yes
2190 fi
2191 # Major
2192 if [ "$NEW_MAJOR" -gt "$PKG_MAJOR" ] 2> /dev/null; then
2193 RELEASE=major
2194 FIXE=""
2195 fi
2196 if [ "$NEW_MAJOR" -lt "$PKG_MAJOR" ] 2> /dev/null; then
2197 RELEASE=$WARNING
2198 FIXE=yes
2199 fi
2200 # Default to revision.
2201 if [ -z $RELEASE ]; then
2202 RELEASE=revision
2203 fi
2204 # Pkg name is already displayed by the check process.
2205 echo -en "\033[24G $VERSION"
2206 echo -en "\033[38G --->"
2207 echo -en "\033[43G $NEW_VERSION"
2208 echo -en "\033[58G $CATEGORY"
2209 echo -e "\033[72G $RELEASE"
2210 up=$(($up+1))
2211 echo "$PACKAGE" >> upgradeable-packages.list
2212 case "$FIRST_CLASS_PACKAGE" in
2213 *\ $PACKAGE\ *) echo "$PACKAGE" >> upgradeable-packages.list$$;;
2214 esac
2215 unset RELEASE
2216 fi
2217 packages=$(($packages+1))
2218 fi
2219 fi
2220 done
2221 if [ -z $blocked ]; then
2222 blocked=0
2223 fi
2224 # Clean last checked package and display summary.
2225 if [ ! "$up" = "" ]; then
2226 echo -e "\\033[0G "
2227 echo "================================================================================"
2228 echo "$packages installed and listed packages to consider, $up to upgrade, $blocked blocked."
2229 echo ""
2230 else
2231 echo -e "\\033[0GSystem is up-to-date. "
2232 echo ""
2233 echo "================================================================================"
2234 echo "$packages installed and listed packages to consider, 0 to upgrade, $blocked blocked."
2235 echo ""
2236 exit 0
2237 fi
2238 # What to do if major or minor version is smaller.
2239 if [ "$FIXE" == "yes" ]; then
2240 echo -e "$WARNING ---> Installed package seems more recent than the mirrored one."
2241 echo "You can block packages using the command : 'tazpkg block package'"
2242 echo "Or upgrade packages at your own risk."
2243 echo ""
2244 fi
2245 # Ask for upgrade, it can be done another time.
2246 echo -n "Upgrade now (y/N) ? "; read anser
2247 if [ ! "$anser" = "y" ]; then
2248 echo -e "\nExiting. No package upgraded.\n"
2249 exit 0
2250 fi
2251 # If anser is yes (y). Install all new versions.
2252 cat upgradeable-packages.list >> upgradeable-packages.list$$
2253 mv -f upgradeable-packages.list$$ upgradeable-packages.list
2254 yes y | tazpkg get-install-list upgradeable-packages.list --forced
2255 rm -f upgradeable-packages.list
2256 ;;
2257 bugs)
2258 # Show known bugs in package(s)
2260 cd $INSTALLED
2261 shift
2262 LIST=$@
2263 [ -n "$LIST" ] || LIST=`ls`
2264 MSG="No known bugs."
2265 for PACKAGE in $LIST; do
2266 BUGS=""
2267 EXTRAVERSION=""
2268 . $PACKAGE/receipt
2269 if [ -n "$BUGS" ]; then
2270 MSG="
2271 Bug list completed"
2272 cat <<EOT
2274 Bugs in package $PACKAGE version $VERSION$EXTRAVERSION:
2275 $BUGS
2276 EOT
2277 fi
2278 done
2279 echo "$MSG" ;;
2280 check)
2281 # Check installed packages set.
2283 check_root
2284 cd $INSTALLED
2285 for PACKAGE in `ls`; do
2286 if [ ! -f $PACKAGE/receipt ]; then
2287 echo "The package $PACKAGE installation has not completed"
2288 continue
2289 fi
2290 DEPENDS=""
2291 EXTRAVERSION=""
2292 . $PACKAGE/receipt
2293 if [ -s $PACKAGE/modifiers ]; then
2294 echo "The package $PACKAGE $VERSION$EXTRAVERSION has been modified by :"
2295 for i in $(cat $PACKAGE/modifiers); do
2296 echo " $i"
2297 done
2298 fi
2299 MSG="Files lost from $PACKAGE $VERSION$EXTRAVERSION :\n"
2300 while read file; do
2301 [ -e "$file" ] && continue
2302 if [ -L "$file" ]; then
2303 MSG="$MSG target of symlink"
2304 fi
2305 echo -e "$MSG $file"
2306 MSG=""
2307 done < $PACKAGE/files.list
2308 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n"
2309 for i in $DEPENDS; do
2310 [ -d $i ] && continue
2311 [ -d $(equivalent_pkg $i) ] && continue
2312 echo -e "$MSG $i"
2313 MSG=""
2314 done
2315 MSG="Dependencies loop between $PACKAGE and :\n"
2316 ALL_DEPS=""
2317 check_for_deps_loop $PACKAGE $DEPENDS
2318 done
2319 echo -n "Looking for known bugs... "
2320 tazpkg bugs
2321 if [ "$PACKAGE_FILE" = "--full" ]; then
2322 for file in */md5sum; do
2323 CONFIG_FILES=""
2324 . $(dirname "$file")/receipt
2325 [ -s "$file" ] || continue
2326 while read md5 f; do
2327 [ -f $f ] || continue
2328 for i in $CONFIG_FILES; do
2329 case "$f" in
2330 $i|$i/*) continue 2;;
2331 esac
2332 done
2333 echo "$md5 $f"
2334 done < "$file" | md5sum -c - 2> /dev/null | \
2335 grep -v OK$ | sed 's/FAILED$/MD5SUM MISMATCH/'
2336 done
2337 FILES=" "
2338 for file in $(cat */files.list); do
2339 [ -d "$file" ] && continue
2340 case "$FILES" in *\ $file\ *) continue;; esac
2341 [ $(grep "^$file$" */files.list 2> /dev/null | \
2342 wc -l) -gt 1 ] || continue
2343 FILES="$FILES$file "
2344 echo "The following packages provide $file :"
2345 grep -l "^$file$" */files.list | while read f
2346 do
2347 pkg=${f%/files.list}
2348 echo -n " $pkg"
2349 if [ -f $pkg/modifiers ]; then
2350 echo -n " (overridden by $(echo "$(cat $pkg/modifiers)"))"
2351 fi
2352 echo ""
2353 done
2354 done
2355 MSG="No package has installed the following files:\n"
2356 find /etc /bin /sbin /lib /usr /var/www \
2357 -not -type d 2> /dev/null | while read file; do
2358 case "$file" in *\[*) continue;; esac
2359 grep -q "^$file$" */files.list && continue
2360 echo -e "$MSG $file"
2361 MSG=""
2362 done
2363 fi
2364 echo "Check completed." ;;
2365 block)
2366 # Add a pkg name to the list of blocked packages.
2368 check_root
2369 check_for_package_on_cmdline
2370 echo ""
2371 if grep -qs "^$PACKAGE" $BLOCKED; then
2372 echo "$PACKAGE is already in the blocked packages list."
2373 echo ""
2374 exit 0
2375 else
2376 echo -n "Add $PACKAGE to : $BLOCKED..."
2377 echo $PACKAGE >> $BLOCKED
2378 status
2379 # Log this activity
2380 . $INSTALLED/$PACKAGE/receipt
2381 log Blocked
2382 fi
2383 echo "" ;;
2384 unblock)
2385 # Remove a pkg name from the list of blocked packages.
2387 check_root
2388 check_for_package_on_cmdline
2389 echo ""
2390 if grep -qs "^$PACKAGE" $BLOCKED; then
2391 echo -n "Removing $PACKAGE from : $BLOCKED..."
2392 sed -i s/$PACKAGE/''/ $BLOCKED
2393 sed -i '/^$/d' $BLOCKED
2394 status
2395 # Log this activity
2396 . $INSTALLED/$PACKAGE/receipt
2397 log Unblocked
2398 else
2399 echo "$PACKAGE is not in the blocked packages list."
2400 echo ""
2401 exit 0
2402 fi
2403 echo "" ;;
2404 get)
2405 # Downlowd a package with wget.
2407 check_for_package_on_cmdline
2408 check_for_packages_list
2409 check_for_package_in_list
2410 echo ""
2411 download $PACKAGE.tazpkg
2412 echo "" ;;
2413 get-install)
2414 # Download and install a package.
2416 check_root
2417 check_for_package_on_cmdline
2418 check_for_packages_list
2419 DO_CHECK=""
2420 while [ -n "$3" ]; do
2421 case "$3" in
2422 --forced)
2423 DO_CHECK="no"
2424 ;;
2425 --root=*)
2426 ROOT="${3#--root=}"
2427 ;;
2428 --list=*)
2429 INSTALL_LIST="${3#--list=}"
2430 ;;
2431 *) shift 2
2432 echo -e "\nUnknown option $*.\n"
2433 exit 1
2434 ;;
2435 esac
2436 shift
2437 done
2438 AUTOEXEC="no"
2439 if ! check_for_package_in_list check; then
2440 PACKAGE=get-$PACKAGE
2441 AUTOEXEC=$PACKAGE
2442 check_for_package_in_list
2443 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
2444 $AUTOEXEC $ROOT
2445 exit 0
2446 fi
2447 fi
2448 # Check if forced install.
2449 if [ "$DO_CHECK" = "no" ]; then
2450 rm -f $CACHE_DIR/$PACKAGE.tazpkg
2451 else
2452 check_for_installed_package $ROOT
2453 fi
2454 cd $CACHE_DIR
2455 if [ -f "$PACKAGE.tazpkg" ]; then
2456 echo "$PACKAGE already in the cache : $CACHE_DIR"
2457 # Check package download was finished
2458 tail -c 2k $PACKAGE.tazpkg | grep -q 00000000TRAILER || {
2459 echo "Continue $PACKAGE download"
2460 download $PACKAGE.tazpkg
2462 else
2463 echo ""
2464 download $PACKAGE.tazpkg
2465 fi
2466 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2467 install_package $ROOT
2468 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT ;;
2469 clean-cache)
2470 # Remove all downloaded packages.
2472 check_root
2473 files=`ls -1 $CACHE_DIR | wc -l`
2474 echo ""
2475 echo -e "\033[1mClean cache :\033[0m $CACHE_DIR"
2476 echo "================================================================================"
2477 echo -n "Cleaning cache directory..."
2478 rm -rf $CACHE_DIR/*
2479 status
2480 echo "================================================================================"
2481 echo "$files file(s) removed from cache."
2482 echo "" ;;
2483 list-undigest)
2484 # list undigest URLs.
2486 if [ "$2" = "--box" ]; then
2487 for i in $LOCALSTATE/undigest/*/mirror; do
2488 [ -f $i ] || continue
2489 echo "$(basename $(dirname $i))|$(cat $i)"
2490 done
2491 else
2492 echo ""
2493 echo -e "\033[1mCurrent undigest(s)\033[0m"
2494 echo "================================================================================"
2495 for i in $LOCALSTATE/undigest/*/mirror; do
2496 if [ ! -f $i ]; then
2497 echo "No undigest mirror found."
2498 exit 1
2499 fi
2500 echo "$(basename $(dirname $i)) $(cat $i)"
2501 done
2502 echo ""
2503 fi ;;
2504 remove-undigest)
2505 # remove undigest URL.
2507 check_root
2508 if [ -d $LOCALSTATE/undigest/$2 ]; then
2509 echo -n "Remove $2 undigest (y/N) ? "; read anser
2510 if [ "$anser" = "y" ]; then
2511 echo -n "Removing $2 undigest..."
2512 rm -rf $LOCALSTATE/undigest/$2
2513 status
2514 rmdir $LOCALSTATE/undigest 2> /dev/null
2515 fi
2516 else
2517 echo "Undigest $2 not found"
2518 fi ;;
2519 add-undigest|setup-undigest)
2520 # Add undigest URL.
2522 check_root
2523 undigest=$2
2524 [ -d $LOCALSTATE/undigest ] || mkdir $LOCALSTATE/undigest
2525 if [ -z "$undigest" ]; then
2526 i=1
2527 while [ -d $LOCALSTATE/undigest/$i ]; do
2528 i=$(($i+1))
2529 done
2530 undigest=$i
2531 fi
2532 if [ ! -d $LOCALSTATE/undigest/$undigest ]; then
2533 echo "Creating new undigest $undigest."
2534 mkdir $LOCALSTATE/undigest/$undigest
2535 fi
2536 setup_mirror $LOCALSTATE/undigest/$undigest $3 ;;
2537 setup-mirror)
2538 # Change mirror URL.
2540 check_root
2541 setup_mirror $LOCALSTATE $2 ;;
2542 reconfigure)
2543 # Replay post_install from receipt
2545 check_for_package_on_cmdline
2546 check_root
2547 ROOT=""
2548 while [ -n "$3" ]; do
2549 case "$3" in
2550 --root=*)
2551 ROOT="${3#--root=}/" ;;
2552 *) shift 2
2553 echo -e "\nUnknown option $*.\n"
2554 exit 1 ;;
2555 esac
2556 shift
2557 done
2558 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2559 check_for_receipt $ROOT
2560 # Check for post_install
2561 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2562 . $ROOT$INSTALLED/$PACKAGE/receipt
2563 post_install $ROOT
2564 # Log this activity
2565 [ -n "$ROOT" ] || log Reconfigured
2566 else
2567 echo -e "\nNothing to do for $PACKAGE."
2568 fi
2569 else
2570 echo -e "\npackage $PACKAGE is not installed."
2571 echo -e "Install package with 'tazpkg install' or 'tazpkg get-install'\n"
2572 fi ;;
2573 shell)
2574 # Tazpkg SHell
2576 if test $(id -u) = 0 ; then
2577 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2578 else
2579 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2580 fi
2581 if [ ! "$2" = "--noheader" ]; then
2582 clear
2583 echo ""
2584 echo -e "\033[1mTazpkg SHell.\033[0m"
2585 echo "================================================================================"
2586 echo "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
2587 echo ""
2588 fi
2589 while true
2590 do
2591 echo -en "$PROMPT"; read cmd
2592 case $cmd in
2593 q|quit)
2594 break ;;
2595 shell)
2596 echo "You are already running a Tazpkg SHell." ;;
2597 su)
2598 su -c 'exec tazpkg shell --noheader' && break ;;
2599 "")
2600 continue ;;
2601 *)
2602 tazpkg $cmd ;;
2603 esac
2604 done ;;
2605 depends)
2606 # Display dependencies tree
2607 cd $INSTALLED
2608 ALL_DEPS=""
2609 if [ -f $2/receipt ]; then
2610 dep_scan $2 ""
2611 fi ;;
2612 rdepends)
2613 # Display reverse dependencies tree
2614 cd $INSTALLED
2615 ALL_DEPS=""
2616 if [ -f $2/receipt ]; then
2617 rdep_scan $2
2618 fi ;;
2619 convert)
2620 # convert misc package format to .tazpkg
2621 check_for_package_file
2622 case "$PACKAGE_FILE" in
2623 *.deb|*.udeb)
2624 convert_deb;;
2625 *.rpm)
2626 convert_rpm;;
2627 *.tgz)
2628 convert_tgz;;
2629 *.pkg.tar.gz)
2630 convert_arch;;
2631 *.ipk|*.opk)
2632 convert_ipk;;
2633 *)
2634 echo "Unsupported format";;
2635 esac ;;
2636 link)
2637 # link a package from another slitaz installation
2638 PACKAGE=$2
2639 if [ ! -d "$TARGET_DIR" -o \
2640 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
2641 cat <<EOT
2642 usage: tazpkg link package_name slitaz_root
2643 example: 'tazpkg link openoffice /mnt' will use less than 100k in
2644 your ram running system.
2645 EOT
2646 exit 1
2647 fi
2648 if [ -e "$INSTALLED/$PACKAGE" ]; then
2649 echo "$PACKAGE is already installed."
2650 exit 1
2651 fi
2652 ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
2653 DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
2654 MISSING=""
2655 for i in $DEPENDS; do
2656 [ -e $INSTALLED/$i ] && continue
2657 MISSING="$MISSING$i "
2658 echo "Missing : $i"
2659 done
2660 if [ -n "$MISSING" ]; then
2661 echo ""
2662 echo -n "Link all missing dependencies (y/N) ? "; read answer
2663 echo ""
2664 if [ "$answer" = "y" ]; then
2665 for i in $MISSING; do
2666 tazpkg link $i $TARGET_DIR
2667 done
2668 else
2669 echo -e "\nLeaving dependencies for $PACKAGE unsolved."
2670 echo -e "The package is installed but will probably not work.\n"
2671 fi
2672 fi
2673 . $INSTALLED/$PACKAGE/receipt
2674 if grep -q ^pre_install $INSTALLED/$PACKAGE/receipt; then
2675 pre_install
2676 fi
2677 while read path; do
2678 [ -e $path ] && continue
2679 while true; do
2680 dir=$(dirname $path)
2681 [ -e $dir ] && break
2682 path=$dir
2683 done
2684 ln -s $TARGET_DIR$path $dir
2685 done < $INSTALLED/$PACKAGE/files.list
2686 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
2687 post_install
2688 fi ;;
2689 usage|*)
2690 # Print a short help or give usage for an unknown or empty command.
2691 usage ;;
2692 esac
2694 exit 0