tazpkg view tazpkg @ rev 341

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