tazpkg view tazpkg @ rev 752

Change VERSION
author Eric Joseph-Alexandre <erjo@slitaz.org>
date Mon Mar 23 01:18:38 2015 +0100 (2015-03-23)
parents 82842f95d47c
children 0dd5c5995b4f
line source
1 #!/bin/sh
2 #
3 # TazPKG - Tiny autonomous zone packages manager.
4 #
5 # This is a lightweight packages manager for *.tazpkg files written in SHell
6 # script. It works well with Busybox ash shell and bash. TazPKG lets you
7 # list, install, remove, download or get information about a package. You
8 # can use 'tazpkg usage' to get a list of commands with short descriptions.
9 # TazPKG also resolves dependencies and can upgrade packages from a mirror.
10 #
11 # (C) 2007-2014 SliTaz - GNU General Public License v3.
12 #
13 # Authors: See the AUTHORS files
14 #
16 ####################
17 # Script variables #
18 ####################
20 # TazPKG version
21 VERSION=5.3.4
23 . /etc/slitaz/slitaz.conf
24 . /etc/slitaz/tazpkg.conf
26 . /lib/libtaz.sh
27 . /usr/lib/slitaz/libpkg.sh
28 . /usr/lib/tazpkg/tazpkg-find-depends
30 # Internationalization.
31 export TEXTDOMAIN='tazpkg'
32 _() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; echo; }
33 _n() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; }
34 _p() {
35 local S="$1" P="$2" N="$3"; shift; shift; shift;
36 printf "$(ngettext "$S" "$P" "$N")" "$@"; }
39 #
40 # Functions set for translate categories
41 #
44 # Make array of pre-translated categories
46 cat_i18n=""
47 for c in "base-system" "x-window" "utilities" "network" "graphics" \
48 "multimedia" "office" "development" "system-tools" "security" "games" \
49 "misc" "meta" "non-free"; do
50 cat_i18n="$cat_i18n
51 $(gettext "$c") $c"
52 done
55 # Translate category names (must be last in line)
57 translate_category()
58 {
59 sed "s|base-system$|$(_ base-system)|g; s|x-window$|$(_ x-window)|g;
60 s|utilities$|$(_ utilities)|g; s|network$|$(_ network)|g;
61 s|graphics$|$(_ graphics)|g; s|multimedia$|$(_ multimedia)|g;
62 s|office$|$(_ office)|g; s|development$|$(_ development)|g;
63 s|system-tools$|$(_ system-tools)|g; s|security$|$(_ security)|g;
64 s|games$|$(_ games)|g; s|misc$|$(_ misc)|g; s|meta$|$(_ meta)|g;
65 s|non-free$|$(_ non-free)|g"
66 }
69 # If category is not one of those translated in native language, keep it
70 # untranslated. This allows both native and english language support.
71 # This also supports custom categories.
72 # And now we support spaces in translated categories
74 reverse_translate_category()
75 {
76 echo "$cat_i18n" | awk "BEGIN{FS=\" \"}{if (/^$@ /) a=\$2}END{if (a==\"\") a=\"$@\"; print a}"
77 }
81 #
82 # TazPKG output functions
83 #
86 # Print localized title
88 title() { newline; boldify "$(_ "$@")"; separator; }
91 # Print footer
93 footer() { separator; echo "$1"; [ -n "$1" ] && newline; }
96 # Print current action in brown color (separate from any other msgs)
98 action() {
99 case $output in
100 raw|gtk|html) _n "$@" ;;
101 *) echo -ne "\033[0;33m"$(_ "$@")"\033[0m" ;;
102 esac
103 }
106 # Initialize some variables to use words rather than numbers for functions
107 # and actions.
108 COMMAND=$1
109 PACKAGE=${2%/}
110 PACKAGE_DIR="$(cd $(dirname $PACKAGE 2>/dev/null) 2>/dev/null; pwd)"
111 [ -n "$PACKAGE" ] && PACKAGE_FILE="$PACKAGE_DIR/${PACKAGE##*/}"
112 if [ -f "$PACKAGE" ]; then
113 # Set pkg basename for install, extract
114 PACKAGE=$(basename $PACKAGE .tazpkg 2>/dev/null)
115 else
116 # Pkg name for remove, search and all other cmds
117 PACKAGE=${PACKAGE%.tazpkg}
118 fi
119 TARGET_DIR=$3
120 TOP_DIR=$(pwd)
121 TMP_DIR=/tmp/$RANDOM
122 INSTALL_LIST=""
123 SAVE_CACHE_DIR="$CACHE_DIR"
125 # Path to tazpkg used dir and configuration files
126 MIRROR=$PKGS_DB/mirror
127 BLOCKED=$PKGS_DB/blocked-packages.list
128 UP_LIST=$PKGS_DB/packages.up
129 DEFAULT_MIRROR="$ONLINE_PKGS"
134 ####################
135 # Script functions #
136 ####################
139 # Interactive mode
141 im() { tty -s; }
144 # Print the usage.
146 usage () {
147 cat << EOT
149 $(_ 'SliTaz package manager - Version: %s' $(colorize 34 $VERSION))
151 $(boldify "$(_ 'Usage:')")
152 $(_ 'tazpkg [command] [package|dir|pattern|list|cat|--opt] [dir|--opt]')
154 $(boldify "$(_ 'SHell:')") tazpkg shell
156 $(boldify "$(_ 'Commands:')")
157 $(optlist "\
158 usage $(_ 'Print this short usage')
159 bugs $(_ 'Show known bugs in packages')
160 -a activity $(_ 'Show TazPkg activity log')
161 -l list $(_ 'List installed packages on the system')
162 -lm list-mirror $(_ 'List all available packages on the mirror')
163 info $(_ 'Print information about a package')
164 desc $(_ 'Print description of a package')
165 -lf list-files $(_ 'List the files installed with a package')
166 list-config $(_ 'List the configuration files')
168 -s search $(_ 'Search for a package by pattern or name')
169 search-pkgname $(_ 'Search on mirror for package having a particular file')
170 -sf search-file $(_ 'Search for file in all installed packages files')
172 get $(_ 'Download a package into the current directory')
173 -gi get-install $(_ 'Download and install a package from the mirror')
174 get-install-list $(_ 'Download and install a list of packages from the mirror')
175 -i install $(_ 'Install a local package')
176 install-list $(_ 'Install all packages from a list of packages')
177 -r remove $(_ 'Remove the specified package and all installed files')
178 -e extract $(_ 'Extract a (*.tazpkg) package into a directory')
179 pack $(_ 'Pack an unpacked or prepared package tree')
181 recharge $(_ 'Recharge your packages.list from the mirror')
182 up|help-up $(_ 'Check packages %s to list and install latest upgrades' $CHECKSUM)
184 repack $(_ 'Create a package archive from an installed package')
185 repack-config $(_ 'Create a package archive with configuration files')
186 recompress $(_ 'Rebuild a package with a better compression ratio')
187 block|unblock $(_ 'Block an installed package version or unblock it for upgrade')
188 check $(_ 'Verify consistency of installed packages')
190 add-flavor $(_ 'Install the flavor list of packages')
191 install-flavor $(_ 'Install the flavor list of packages and remove other ones')
193 set-release $(_ 'Change release and update packages')
194 -cc clean-cache $(_ 'Clean all packages downloaded in cache directory')
196 depends $(_ 'Display dependencies tree')
197 rdepends $(_ 'Display reverse dependencies tree')
199 convert $(_ 'Convert alien package to tazpkg')
200 link $(_ 'Link a package from another slitaz installation')
202 -sm setup-mirror $(_ 'Change the mirror url configuration')
203 list-undigest $(_ 'List undigest mirrors')
204 remove-undigest $(_ 'Remove an undigest mirror')
205 add-undigest $(_ 'Add an undigest mirror')
206 setup-undigest $(_ 'Update an undigest mirror')
208 reconfigure $(_ 'Replay post install script from package')
209 ")
210 EOT
211 }
214 usage_up() {
215 cat << EOT
216 $(emsg "<b>$(_ 'Usage for command up:')</b>") tazpkg up [$(_ 'option')]
218 * $(longline "$(_ 'Without options run in interactive mode and ask before install')")
220 $(boldify "$(_ 'Where options are:')")
221 $(optlist "\
222 -c --check $(_ 'Check only for available upgrades')
223 -r --recharge $(_ 'Force recharge of packages list and check')
224 -i --install $(_ 'Check for upgrades and install them all')
225 ")
227 $(boldify "$(_ 'Example:')")
228 tazpkg up --recharge --install
229 tazpkg up -c -r
230 EOT
231 }
234 # Check if dir exists
236 check_dir()
237 {
238 if ! [ -d "$1" ]; then
239 action 'Creating folder "%s"...' "$1"
240 mkdir -p "$1"
241 status
242 return 1
243 fi
244 }
247 # Check if the directories and files used by TazPKG
248 # exist. If not and user is root we create them.
250 check_base_dir()
251 {
252 if [ "$(id -u)" = "0" ]; then
253 check_dir $1$CACHE_DIR
254 check_dir $1$INSTALLED
255 check_dir $1$SLITAZ_LOGS
256 if [ ! -f "$1$PKGS_DB/mirror" ]; then
257 echo "${DEFAULT_MIRROR%/}/" > $1$PKGS_DB/mirror
258 [ -n "$1" ] && cp $PKGS_DB/packages.* $1$PKGS_DB/
259 fi
260 fi
261 }
262 check_base_dir
265 # Check for a package name on cmdline.
267 check_for_package_on_cmdline()
268 {
269 if [ -z "$PACKAGE" ]; then
270 newline
271 _ 'Please specify a package name on the command line.'
272 newline
273 exit 1
274 fi
275 }
278 # Check if the package (*.tazpkg) exists before installing or extracting.
280 check_for_package_file()
281 {
282 if [ ! -f "$PACKAGE_FILE" ]; then
283 newline
284 _ 'Unable to find file "%s"' $PACKAGE_FILE
285 newline
286 exit 1
287 fi
288 }
291 # Check for the receipt of an installed package.
293 check_for_receipt()
294 {
295 if [ ! -f "$1$INSTALLED/$PACKAGE/receipt" ]; then
296 newline
297 _ 'Unable to find the receipt "%s"' "$1$INSTALLED/$PACKAGE/receipt"
298 newline
299 exit 1
300 fi
301 }
304 # Get repositories priority using $PKGS_DB/priority.
305 # In this files, undigest are called by their name and main mirror
306 # by main. Sort order: priority
308 look_for_priority()
309 {
310 [ -s $PKGS_DB/priority ] && priority=$(cat $PKGS_DB/priority)
311 for rep in main $(ls $PKGS_DB/undigest 2>/dev/null); do
312 if [ ! -s $PKGS_DB/priority ] || \
313 ! grep -q ^$rep$ $PKGS_DB/priority; then
314 priority=$(echo -e "$priority\n$rep")
315 fi
316 done
317 priority=$(echo "$priority" | sed '/^$/d' | \
318 while read line; do
319 if [ "$line" = main ]; then
320 echo $PKGS_DB
321 else
322 echo $PKGS_DB/undigest/$line
323 fi
324 done)
325 }
328 # Get package name in a directory
330 package_fullname_in_dir()
331 {
332 [ -f $1/receipt ] || return
333 EXTRAVERSION=""
334 . $1/receipt
335 echo $PACKAGE-$VERSION$EXTRAVERSION
336 }
339 # Get package name that is already installed.
341 get_installed_package_pathname()
342 {
343 for i in $2$INSTALLED/${1%%-*}*; do
344 [ -d $i ] || continue
345 if [ "$1" = "$(package_fullname_in_dir $i)" ]; then
346 echo $i
347 return
348 fi
349 done
350 }
353 # Check if a package is already installed.
355 check_for_installed_package()
356 {
357 if [ -n "$(get_installed_package_pathname $PACKAGE $1)" ]; then
358 newline
359 _ '"%s" package is already installed.' $(colorize 34 $PACKAGE)
360 longline "$(_ 'You can use the --forced option to force installation.')"
361 newline
362 exit 0
363 fi
364 }
367 # Check for packages.list to download and install packages.
369 check_for_packages_list()
370 {
371 list_path="$PKGS_DB/packages.list"
372 if [ ! -f "$list_path" ]; then
373 if test $(id -u) = 0 ; then
374 tazpkg recharge
375 else
376 newline
377 _ 'Unable to find the list "%s"' $list_path
378 _ \
379 "You must probably run 'tazpkg recharge' as root to get the latest list of
380 packages available on the mirror."
381 newline
382 exit 0
383 fi
384 fi
385 }
388 # Check for installed.info - local file with format of packages.info
389 # "installed.info" is absent on not clean installs; check it and re-generate if needed.
391 check_for_installed_info()
392 {
393 info_path="$PKGS_DB/installed.info"
394 if [ ! -f "$info_path" ]; then
395 if [ "$(id -u)" == "0" ]; then
396 _ 'File "%s" generated. Please wait...' installed.info
397 for pkg in $PKGS_DB/installed/*/receipt; do
398 unset_receipt
399 . $pkg
400 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
401 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
402 cat >> $info_path << EOT
403 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS
404 EOT
405 done
406 else
407 _ 'Unable to find file "%s"' installed.info
408 _ 'Please run tazpkg as root.'
409 exit 1
410 fi
411 fi
412 }
415 get_cache_dir()
416 {
417 echo $rep > $tmp/rep
418 if [ "$rep" = "$PKGS_DB" ]; then
419 CACHE_DIR="$SAVE_CACHE_DIR/$SLITAZ_RELEASE/packages"
420 elif [ "${rep%-incoming}" = "$rep" ]; then
421 CACHE_DIR="$SAVE_CACHE_DIR/${rep##*/}/packages"
422 else
423 rep="${rep%-incoming}"
424 CACHE_DIR="$SAVE_CACHE_DIR/${rep##*/}/packages-incoming"
425 fi
426 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
427 echo $CACHE_DIR > $tmp/cachedir
428 }
431 # get an already installed package from packages.equiv
433 equivalent_pkg()
434 {
435 for i in $(grep -hs "^$1=" $PKGS_DB/packages.equiv \
436 $PKGS_DB/undigest/*/packages.equiv | sed "s/^$1=//"); do
437 if echo $i | fgrep -q : ; then
438 # format 'alternative:newname'
439 # if alternative is installed then substitute newname
440 if [ -f $2$INSTALLED/${i%:*}/receipt ]; then
441 # substitute package dependency
442 echo ${i#*:}
443 return
444 fi
445 else
446 # if alternative is installed then nothing to install
447 if [ -f $2$INSTALLED/$i/receipt ]; then
448 # substitute installed package
449 echo $i
450 return
451 fi
452 fi
453 done
454 # if not found in packages.equiv then no substitution
455 echo $1
456 }
459 # get a virtual package from packages.equiv
461 virtual_pkg()
462 {
463 for i in $(for rep in $priority; do
464 grep -hs "^$1=" $rep/packages.equiv
465 done | sed "s/^$1=//"); do
466 if echo $i | fgrep -q : ; then
467 # format 'alternative:newname'
468 # if alternative is installed then substitute newname
469 if [ -f $2$INSTALLED/${i%:*}/receipt ]; then
470 # substitute package dependency
471 echo ${i#*:}
472 return
473 fi
474 else
475 # unconditional substitution
476 echo $i
477 return
478 fi
479 done
480 }
483 # Get package filename available on the mirror
485 get_package_filename()
486 {
487 local pkg
488 for rep in $priority; do
489 pkg=$(grep -A 1 -sh "^$1$" $rep/packages.txt | tail -1 | sed 's/^ *//')
490 [ "$pkg" ] && pkg=$(grep -sh "^$1-$pkg" $rep/packages.list | head -1)
492 # Allow user to call a package with his version number.
493 [ "$pkg" ] || pkg=$(grep -sh "^$1$" $rep/packages.list | head -1)
495 [ "$pkg" ] || pkg=$(grep -sh "^$1-[0-9]" $rep/packages.list | head -1)
496 [ "$pkg" ] || pkg=$(grep -sh "^$1-.[\.0-9]" $rep/packages.list | head -1)
497 [ "$pkg" ] && get_cache_dir && break
498 done
499 if [ -z "$pkg" ]; then
500 # Check for virtual package
501 local equiv
502 equiv=$(virtual_pkg $1)
503 if [ "$equiv" != "$1" ]; then
504 PACKAGE=$equiv
505 get_package_filename $PACKAGE
506 return
507 fi
508 fi
509 echo $pkg
510 }
513 # Check for a package in packages.list. Used by get and get-install to grep
514 # package basename.
516 check_for_package_in_list()
517 {
518 local filename
519 local check_only
520 check_only="$1"
521 filename=$(get_package_filename $PACKAGE)
522 if [ "$filename" ]; then
523 PACKAGE=$filename
524 CACHE_DIR=$(cat $tmp/cachedir)
525 rep=$(cat $tmp/rep)
526 rm -f $tmp/rep $tmp/cachedir
527 else
528 newline
529 _ 'Unable to find package "%s" in the mirrored packages list.' $PACKAGE
530 newline
531 [ -n "$check_only" ] && return 1
532 exit 0
533 fi
534 }
537 # Log this activity
538 # (there log_pkg because we have log() in libtaz.sh)
540 log_pkg()
541 {
542 local extra
544 [ "$1" = "Installed" ] && \
545 extra=" - $(fgrep $PACKAGE-$VERSION $PKGS_DB/installed.$SUM | awk '{ print $1 }')"
547 [ -e $LOG ] || touch $LOG
549 [ -w $LOG ] &&
550 echo "$(date +'%F %T') - $1 - $PACKAGE ($VERSION$EXTRAVERSION)$extra" >> $LOG
551 }
554 # Download a get-package script from this mirror
556 download_get_script()
557 {
558 local p
559 for p in $priority ; do
560 local i
561 for i in $(cat $p/mirror) ; do
562 case "$i" in
563 http://*|ftp://*)
564 wget -O $2 ${i%packages/*}packages/get/$1 && return 0 ;;
565 esac
566 done
567 done
568 return 1
569 }
572 # Download a file from this mirror
574 download_from()
575 {
576 local i
577 local mirrors
578 mirrors="$1"
579 shift
580 for i in $mirrors; do
581 case "$i" in
582 # Mirror URL can have a trailing slash or not.
583 http://*|ftp://*)
584 busybox wget -c ${i%/}/$@ && break ;;
585 https://*)
586 echo 'Sorry, https not supported' ;;
587 *)
588 ln -sf $i/$1 . && break ;;
589 esac
590 done
591 }
594 # Download a file trying all mirrors
596 download()
597 {
598 local i
599 case "$1" in
600 *.tazpkg)
601 for i in $priority ; do
602 grep -q "^${1%.tazpkg}$" $i/packages.list 2>/dev/null || continue
603 download_from "$(cat $i/mirror)" "$@" && return
604 done
605 esac
606 for i in $(cat $(for rep in $priority; do echo $rep/mirror; done) 2>/dev/null); do
607 download_from "$i" "$@" && break
608 done
609 }
612 # Extract a package with cpio and gzip/lzma.
614 extract_package()
615 {
616 action 'Extracting package...'
617 cpio -idm --quiet < ${PACKAGE_FILE##*/} && rm -f ${PACKAGE_FILE##*/}
618 status
619 if [ -f fs.cpio.lzma ]; then
620 unlzma -c fs.cpio.lzma | cpio -idm --quiet && rm fs.cpio.lzma
621 elif [ -f fs.cpio.gz ]; then
622 zcat fs.cpio.gz | cpio -idm --quiet && rm fs.cpio.gz
623 fi
624 }
627 remove_with_path()
628 {
629 # Avoid dirname errors by checking for argument.
630 [ "$1" ] || return
632 local dir
633 rm -f $1 2>/dev/null
634 dir="$1"
635 while [ "$dir" != "/" ]; do
636 dir="$(dirname $dir)"
637 rmdir $dir 2> /dev/null || break
638 done
639 }
642 grepesc()
643 {
644 sed 's/\[/\\[/g'
645 }
648 # This function installs a package in the rootfs.
650 install_package()
651 {
652 ROOT=$1
653 if [ -n "$ROOT" ]; then
654 # Get absolute path
655 ROOT=$(realpath $ROOT)
656 fi
657 {
658 # Create package path early to avoid dependencies loop
659 mkdir -p $TMP_DIR
660 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
661 . $TMP_DIR/receipt
662 # FIXME: legacy?
663 if grep -q ^pre_depends $TMP_DIR/receipt; then
664 pre_depends $ROOT
665 fi
667 # Keep modifiers and file list on upgrade
668 cp $ROOT$INSTALLED/$PACKAGE/modifiers \
669 $ROOT$INSTALLED/$PACKAGE/files.list $TMP_DIR 2> /dev/null
670 rm -rf $ROOT$INSTALLED/$PACKAGE 2> /dev/null
672 # Make the installed package data dir to store
673 # the receipt and the files list.
674 mkdir -p $ROOT$INSTALLED/$PACKAGE
675 cp $TMP_DIR/modifiers $ROOT$INSTALLED/$PACKAGE 2> /dev/null
676 cp $TMP_DIR/files.list $ROOT$INSTALLED/$PACKAGE 2> /dev/null
677 rm -rf $TMP_DIR 2> /dev/null
678 sed -i "/ $(basename $PACKAGE_FILE)$/d" \
679 $ROOT$PKGS_DB/installed.$SUM 2> /dev/null
680 cd $(dirname $PACKAGE_FILE)
681 $CHECKSUM $(basename $PACKAGE_FILE) >> $ROOT$PKGS_DB/installed.$SUM
682 }
684 # Resolve package deps.
685 check_for_deps $ROOT
686 if [ -n "$MISSING_PACKAGE" ]; then
687 install_deps $ROOT
688 fi
689 mkdir -p $TMP_DIR
690 [ -n "$INSTALL_LIST" ] && echo "$PACKAGE_FILE" >> $ROOT$PKGS_DB/$INSTALL_LIST-processed
692 title 'Installation of package "%s"' $PACKAGE
694 action 'Copying package...'
695 cp $PACKAGE_FILE $TMP_DIR
696 status
698 cd $TMP_DIR
699 extract_package
700 SELF_INSTALL=0
701 EXTRAVERSION=""
702 CONFIG_FILES=""
704 # Include temporary receipt to get the right variables.
705 . $PWD/receipt
706 cd $ROOT$INSTALLED
708 # FIXME: legacy?
709 if [ $SELF_INSTALL -ne 0 -a -n "$ROOT" ]; then
710 action "Checking post install dependencies..."
711 [ -f $INSTALLED/$PACKAGE/receipt ]
712 if ! status; then
713 _ 'Please run "%s" in / and retry.' "tazpkg install $PACKAGE_FILE"
714 rm -rf $TMP_DIR
715 exit 1
716 fi
717 fi
719 # Get files to remove if upgrading
720 if [ -f $PACKAGE/files.list ]; then
721 while read file; do
722 grep -q "^$(echo $file | grepesc)$" $TMP_DIR/files.list && continue
723 for i in $(cat $PACKAGE/modifiers 2> /dev/null ;
724 fgrep -sl $PACKAGE */modifiers | cut -d/ -f1 ); do
725 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
726 done
727 echo $file
728 done < $PACKAGE/files.list > $TMP_DIR/files2remove.list
729 fi
731 # Remember modified packages
732 {
733 check=false
734 for i in $(fgrep -v [ $TMP_DIR/files.list); do
735 [ -e "$ROOT$i" ] || continue
736 [ -d "$ROOT$i" ] && continue
737 echo "- $i"
738 check=true
739 done ;
740 $check && \
741 for i in *; do
742 [ "$i" == "$PACKAGE" ] && continue
743 [ -s $i/files.list ] || continue
744 awk "{ printf \"$i %s\\n\",\$1 }" < $i/files.list
745 done;
746 } | awk '
747 {
748 if ($1 == "-" || file[$2] != "") {
749 file[$2] = file[$2] " " $1
750 if ($1 != "-") {
751 if (pkg[$1] == "") all = all " " $1
752 pkg[$1] = pkg[$1] " " $2
753 }
754 }
755 }
756 END {
757 for (i = split(all, p, " "); i > 0; i--)
758 for (j = split(pkg[p[i]], f, " "); j > 0; j--)
759 printf "%s %s\n",p[i],f[j];
760 }
761 ' | while read dir file; do
762 if grep -qs ^$dir$ $PACKAGE/modifiers; then
763 # Do not overload an overloaded file !
764 rm $TMP_DIR$file 2> /dev/null
765 continue
766 fi
767 grep -qs ^$PACKAGE$ $dir/modifiers && continue
768 if [ -s "$dir/volatile.cpio.gz" ]; then
769 # We can modify backed up files without notice
770 zcat $dir/volatile.cpio.gz | cpio -t --quiet | \
771 grep -q "^${file#/}$" && continue
772 fi
773 echo "$PACKAGE" >> $dir/modifiers
774 done
776 cd $TMP_DIR
777 cp receipt files.list $ROOT$INSTALLED/$PACKAGE
779 # Copy the description if found.
780 if [ -f "description.txt" ]; then
781 cp description.txt $ROOT$INSTALLED/$PACKAGE
782 fi
784 # Copy the md5sum if found.
785 if [ -f "$CHECKSUM" ]; then
786 cp $CHECKSUM $ROOT$INSTALLED/$PACKAGE
787 fi
789 # Pre install commands.
790 if grep -q ^pre_install $ROOT$INSTALLED/$PACKAGE/receipt; then
791 pre_install $ROOT
792 fi
794 if [ -n "$CONFIG_FILES" ]; then
795 # save 'official' configuration files
796 action 'Saving configuration files...'
797 for i in $CONFIG_FILES; do
798 { cd fs ; find ${i#/} -type f 2> /dev/null; cd ..; }
799 done | { cd fs ; cpio -o -H newc --quiet | gzip -9; cd ..; } > \
800 $ROOT$INSTALLED/$PACKAGE/volatile.cpio.gz
802 if [ -z "$newconf" ]; then
803 # keep user configuration files
804 for i in $CONFIG_FILES; do
805 { cd fs ; find ${i#/} -type f 2> /dev/null; cd ..; }
806 done | while read i; do
807 [ -e $ROOT/$i ] || continue
808 cp -a $ROOT/$i fs/$i
809 done
810 fi
811 status
812 fi
814 action 'Installing package...'
815 [ "$(busybox ls fs/* 2> /dev/null)" ] && cp -af fs/* $ROOT/
816 status
818 if [ -s files2remove.list ]; then
819 action 'Removing old package...'
820 while read file; do
821 remove_with_path $ROOT$file
822 done < files2remove.list
823 true
824 status
825 fi
827 # Remove the temporary random directory.
828 action "Removing all tmp files..."
829 cd ..; rm -rf $TMP_DIR
830 status
832 # Post install commands.
833 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
834 post_install $ROOT
835 fi
837 # Update-desktop-database if needed.
838 if [ "$(fgrep .desktop $ROOT$INSTALLED/$PACKAGE/files.list | fgrep /usr/share/applications/)" ]; then
839 updatedesktopdb=yes
840 fi
842 # Update-mime-database if needed.
843 if [ "$(fgrep /usr/share/mime $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
844 updatemimedb=yes
845 fi
847 # Update-icon-database
848 if [ "$(fgrep /usr/share/icon/hicolor $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
849 updateicondb=yes
850 fi
852 # Compile glib schemas if needed.
853 if [ "$(fgrep /usr/share/glib-2.0/schemas $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
854 compile_schemas=yes
855 fi
857 # Update depmod list
858 if [ "$(fgrep /lib/modules $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
859 updatedepmod=yes
860 fi
862 # Update installed.info
863 check_for_installed_info
864 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
865 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
866 II=$PKGS_DB/installed.info
867 sed -i "/^$PACKAGE /d" $II # remove old entry
868 cat >> $II << EOT
869 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS
870 EOT
871 TEMP_FILE=$(mktemp)
872 sort $II > $TEMP_FILE; mv -f $TEMP_FILE $II; chmod a+r $II; unset II
874 cd $TOP_DIR
875 footer "$(_ 'Package "%s" (%s) is installed.' $PACKAGE $VERSION$EXTRAVERSION)"
877 # Log this activity
878 [ -n "$ROOT" ] || log_pkg Installed
879 }
882 # This function may be called by a get script.
884 abort_package()
885 {
886 cd $CUR_DIR
887 rm -rf $TMP_DIR
888 echo "${1:-Abort $PACKAGE.}"
889 exit 1
890 }
893 # This function installs a package from a get script in the rootfs.
895 install_package_from_get_script()
896 {
897 SCRIPT="$1"
898 ROOT="$2"
899 [ -d $ROOT$INSTALLED/$PACKAGE ] && exit 1
901 grep -q no-check-certificate $SCRIPT &&
902 [ ! -d $INSTALLED/wget ] && tazpkg get-install wget
904 mkdir -p $TMP_DIR && cd $TMP_DIR
905 saved=$PACKAGE
906 unset_receipt
907 PACKAGE=$saved
909 set -e
910 . $SCRIPT
911 set +e
912 cd $TMP_DIR
913 [ -d $PACKAGE-$VERSION ] || abort_package \
914 "$(_ 'Could not download "%s" from "%s". Exiting.' ${TARBALL:-$PACKAGE} ${WGET_URL:-$WEB_SITE})"
916 if [ ! -s $PACKAGE-$VERSION/receipt ]; then
917 cat > $PACKAGE-$VERSION/receipt <<EOT
918 # SliTaz package receipt.
920 PACKAGE="$PACKAGE"
921 VERSION="${VERSION:-unknown}"
922 CATEGORY="${CATEGORY:-non-free}"
923 WEB_SITE="$WEB_SITE"
924 SHORT_DESC="${SHORT_DESC:-$PACKAGE}"
925 MAINTAINER="${MAINTAINER:-nobody@slitaz.org}"
926 EOT
927 for i in LICENSE TARBALL WGET_URL CONFIG_FILES SUGGESTED \
928 PROVIDE DEPENDS HOST_ARCH TAGS EXTRA_SOURCE_FILES ; do
929 eval "[ -n \"\$$i\" ] && echo \"$i=\\\"\$$i\\\"\""
930 done >> $PACKAGE-$VERSION/receipt
931 fi
933 DEPENDS="$(unset DEPENDS; . $PACKAGE-$VERSION/receipt ; echo $DEPENDS)"
934 for i in $(find_depends $PACKAGE-$VERSION/fs); do
935 case " $DEPENDS " in
936 *\ $i\ *) continue;;
937 esac
938 grep -q '^DEPENDS="' $PACKAGE-$VERSION/receipt ||
939 echo 'DEPENDS=""' >> $PACKAGE-$VERSION/receipt
940 sed -i "s/^DEPENDS=\"/&$i /" $PACKAGE-$VERSION/receipt
941 done
943 tazpkg pack $PACKAGE-$VERSION
945 # Clean to save RAM memory before installation
946 rm -rf $PACKAGE-$VERSION
948 # Install pseudo package
949 tazpkg install $PACKAGE-$VERSION.tazpkg --root=$ROOT
950 mv $PACKAGE-$VERSION.tazpkg $CACHE_DIR
952 # Clean
953 cd $TOP_DIR
954 rm -rf $TMP_DIR
955 }
958 # Check for loop in deps tree.
960 check_for_deps_loop()
961 {
962 local list
963 local pkg
964 local deps
965 pkg=$1
966 shift
967 [ -n "$1" ] || return
968 list=""
970 # Filter out already processed deps
971 for i in $@; do
972 case " $ALL_DEPS" in
973 *\ $i\ *) ;;
974 *) list="$list $i";;
975 esac
976 done
977 ALL_DEPS="$ALL_DEPS$list "
978 for i in $list; do
979 [ -f $i/receipt ] || continue
980 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
981 case " $deps " in
982 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
983 *) check_for_deps_loop $pkg $deps;;
984 esac
985 done
986 }
989 # Check for missing deps listed in a receipt packages.
991 check_for_deps()
992 {
993 local saved;
994 saved=$PACKAGE
995 mkdir -p $TMP_DIR
996 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
997 . $TMP_DIR/receipt
998 PACKAGE=$saved
999 rm -rf $TMP_DIR
1001 num=0
1002 for pkgorg in $DEPENDS; do
1003 i=$(equivalent_pkg $pkgorg $1)
1004 if [ ! -d "$1$INSTALLED/$i" ]; then
1005 MISSING_PACKAGE=$i
1006 num=$(($num+1))
1007 elif [ ! -f "$1$INSTALLED/$i/receipt" ]; then
1008 _ 'WARNING! Dependency loop between "%s" and "%s".' $PACKAGE $i
1009 fi
1010 done
1012 if [ -n "$MISSING_PACKAGE" ]; then
1013 title "$(_ 'Tracking dependencies for package "%s"' $PACKAGE)"
1014 for pkgorg in $DEPENDS; do
1015 i=$(equivalent_pkg $pkgorg $1)
1016 if [ ! -d "$1$INSTALLED/$i" ]; then
1017 MISSING_PACKAGE=$i
1018 _ 'Missing package "%s"' $MISSING_PACKAGE
1019 fi
1020 done
1021 footer "$(_p \
1022 '%s missing package to install.' \
1023 '%s missing packages to install.' $num \
1024 $num)"
1025 fi
1029 # Install all missing deps. Auto install or ask user then install all missing
1030 # deps from local dir, cdrom, media or from the mirror. In case we want to
1031 # install packages from local, we need a packages.list to find the version.
1033 install_deps()
1035 local root
1036 root=""
1037 [ -n "$1" ] && root="--root=$1"
1038 if [ "$AUTO_INSTALL_DEPS" == "yes" ]; then
1039 answer=0
1040 else
1041 newline
1042 confirm "$(_ 'Install all missing dependencies? (y/N)')"
1043 answer=$?
1044 newline
1045 fi
1046 if [ $answer = 0 ] && ! [ "$nodeps" ]; then
1047 for pkgorg in $DEPENDS; do
1048 pkg=$(equivalent_pkg $pkgorg $1)
1049 if [ ! -d "$1$INSTALLED/$pkg" ]; then
1050 local list
1051 list="$INSTALL_LIST"
1052 [ -n "$list" ] || list="$TOP_DIR/packages.list"
1053 # We can install packages from a local dir by greping
1054 # the TAZPKG_BASENAME in the local packages.list.
1055 found=0
1056 if [ -f "$list" ]; then
1057 _ 'Checking if package "%s" exists in local list...' $pkg
1058 mkdir $TMP_DIR
1059 for i in $pkg-*.tazpkg; do
1060 [ -f $i ] || continue
1061 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $i
1062 [ "$(. $TMP_DIR/receipt; echo $PACKAGE)" = "$pkg" ] || continue
1063 if grep -q ^$(package_fullname_in_dir $TMP_DIR).tazpkg$ $list
1064 then
1065 found=1
1066 tazpkg install $i $root --list=$list
1067 break
1068 fi
1069 done
1070 rm -rf $TMP_DIR
1071 fi
1072 # Install deps from the mirror.
1073 if [ $found -eq 0 ]; then
1074 if [ ! -f "$PKGS_DB/packages.list" ]; then
1075 tazpkg recharge
1076 fi
1077 tazpkg get-install $pkg $root
1078 fi
1079 fi
1080 done
1081 else
1082 newline
1083 _ 'Leaving dependencies for package "%s" unresolved.' $PACKAGE
1084 _ 'The package is installed but will probably not work.'
1085 newline
1086 fi
1090 # Search pattern in installed packages.
1092 search_in_installed_packages()
1094 _ 'Installed packages'
1095 separator
1096 num=0
1097 for pkg in $(ls -1 $INSTALLED | grep -i "$PATTERN"); do
1098 EXTRAVERSION=""
1099 [ -f $INSTALLED/$pkg/receipt ] || continue
1100 . $INSTALLED/$pkg/receipt
1101 emsg "$PACKAGE<i 24> $VERSION$EXTRAVERSION<i 42> $(_n $CATEGORY)"
1102 num=$(($num+1))
1103 done
1105 footer "$(_p \
1106 '%s installed package found for "%s"' \
1107 '%s installed packages found for "%s"' $num \
1108 $num "$PATTERN")"
1112 # Search in packages.list for available pkgs.
1114 search_in_packages_list()
1116 _ 'Available packages'
1117 separator
1118 num=0
1119 BPATTERN="$(emsg "<b>$PATTERN</b>")"
1120 for i in $PKGS_DB/packages.list $PKGS_DB/undigest/*/packages.list; do
1121 grep -is "$PATTERN" $i | sed "s|$PATTERN|$BPATTERN|"
1122 num=$(($num + `grep -is "$PATTERN" $i | wc -l`))
1123 done
1124 if [ ! -f "$PKGS_DB/packages.list" ]; then
1125 newline
1126 longline "$(_ \
1127 "No \"%s\" found to check for mirrored packages. For more results, please run \
1128 \"%s\" once as root before searching." packages.list 'tazpkg recharge')"
1129 newline
1130 fi
1131 footer "$(_p \
1132 '%s available package found for "%s"' \
1133 '%s available packages found for "%s"' $num \
1134 $num $PATTERN)"
1138 # search --mirror: Search in packages.txt for available pkgs and give more
1139 # info than --list or default.
1141 search_in_packages_txt()
1143 _ 'Matching packages name with version and desc'
1144 separator
1145 num=0
1146 for i in $PKGS_DB/packages.txt $PKGS_DB/undigest/*/packages.txt; do
1147 grep -is -A 2 "^$PATTERN" $i
1148 num=$(($num + `grep -is "^$PATTERN" $i | wc -l`))
1149 done
1150 if [ ! -f "$PKGS_DB/packages.txt" ]; then
1151 newline
1152 longline "$(_ \
1153 "No \"%s\" found to check for mirrored packages. For more results, please run \
1154 \"%s\" once as root before searching." packages.txt 'tazpkg recharge')"
1155 newline
1156 fi
1157 footer "$(_p \
1158 '%s available package found for "%s"' \
1159 '%s available packages found for "%s"' $num \
1160 $num $PATTERN)"
1164 # Install package-list from a flavor
1166 install_flavor()
1168 check_root $@
1170 # Get repositories priority list.
1171 look_for_priority
1173 FLAVOR=$1
1174 ARG=$2
1175 mkdir -p $TMP_DIR
1176 [ -f $FLAVOR.flavor ] && cp $FLAVOR.flavor $TMP_DIR
1177 cd $TMP_DIR
1178 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1179 zcat < $FLAVOR.flavor | cpio --quiet -i >/dev/null
1181 while read file; do
1182 for pkg in $(ls -d $INSTALLED/${file%%-*}*); do
1183 [ -f $pkg/receipt ] || continue
1184 EXTRAVERSION=""
1185 . $pkg/receipt
1186 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && break
1187 done
1188 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && continue
1189 cd $CACHE_DIR
1190 download $file.tazpkg
1191 cd $TMP_DIR
1192 tazpkg install $CACHE_DIR/$file.tazpkg --forced
1193 done < $FLAVOR.pkglist
1195 [ -f $FLAVOR.nonfree ] && while read pkg; do
1196 [ -d $INSTALLED/$pkg ] || continue
1197 [ -d $INSTALLED/get-$pkg ] && tazpkg get-install get-$pkg
1198 get-$pkg
1199 done < $FLAVOR.nonfree
1201 [ "$ARG" == "--purge" ] && for pkg in $(ls $INSTALLED); do
1202 [ -f $INSTALLED/$pkg/receipt ] || continue
1203 EXTRAVERSION=""
1204 . $INSTALLED/$pkg/receipt
1205 grep -q ^$PACKAGE-$VERSION$EXTRAVERSION$ $FLAVOR.pkglist && continue
1206 grep -qs ^$PACKAGE$ $FLAVOR.nonfree && continue
1207 tazpkg remove $PACKAGE
1208 done
1209 else
1210 _ "Can't find flavor \"%s\". Abort." $FLAVOR
1211 fi
1212 cd $TOP_DIR
1213 rm -rf $TMP_DIR
1217 # Update mirror urls
1219 setup_mirror()
1221 # Backup old list.
1222 if [ -f "$1/mirror" ]; then
1223 cp -f $1/mirror $1/mirror.bak
1224 fi
1225 title 'Current mirror(s)'
1226 echo " `cat $1/mirror 2> /dev/null`"
1227 longline "$(_ \
1228 "Please enter URL of the new mirror (http, ftp or local path). You must specify \
1229 the complete address to the directory of the packages and packages.list file.")"
1230 newline
1231 _n 'New mirror(s) URL: '
1232 NEW_MIRROR_URL=$2
1233 if [ -n "$NEW_MIRROR_URL" ]; then
1234 echo $NEW_MIRROR_URL
1235 else
1236 read NEW_MIRROR_URL
1237 fi
1238 if [ "$NEW_MIRROR_URL" = "" ]; then
1239 _ 'Nothing has been changed.'
1240 else
1241 _ 'Setting mirror(s) to: "%s"' $NEW_MIRROR_URL
1242 rm -f $1/mirror
1243 for i in $NEW_MIRROR_URL; do
1244 echo "${i%/}/" >> $1/mirror
1245 done
1246 fi
1247 newline
1251 # recursive dependencies scan
1253 dep_scan()
1255 for i in $1; do
1256 case " $ALL_DEPS " in
1257 *\ $i\ *) continue;;
1258 esac
1259 ALL_DEPS="$ALL_DEPS $i"
1260 [ -n "$2" ] && echo "$2$i ($(fgrep -A 3 $i $PKGS_DB/packages.txt | \
1261 tail -1 | sed 's/.*(\([^ ]*\).*/\1/'))"
1262 [ -f $i/receipt ] || continue
1263 DEPENDS=""
1264 . $i/receipt
1265 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
1266 done
1270 # recursive reverse dependencies scan
1272 rdep_scan()
1274 SEARCH=$1
1276 for i in * ; do
1277 DEPENDS=""
1278 . $i/receipt
1279 echo "$i $(echo $DEPENDS)"
1280 done | busybox awk -v search=$SEARCH '
1281 function show_deps(deps, all_deps, pkg, space)
1283 if (all_deps[pkg] == 1) return
1284 all_deps[pkg] = 1
1285 if (space != "") printf "%s %s\n",space,pkg
1286 for (i = 1, n = split(deps[pkg], mydeps, " "); i <= n; i++) {
1287 show_deps(deps, all_deps, mydeps[i],"==" space)
1292 all_deps[$1] = 0
1293 for (i = 2; i <= NF; i++)
1294 deps[$i] = deps[$i] " " $1
1297 END {
1298 show_deps(deps, all_deps, search, "")
1300 ' | while read spc pkg; do
1301 echo -n $spc | sed 's/=/ /g'
1302 echo -n $pkg
1303 echo -n ' ('
1304 fgrep -A 3 $pkg $PKGS_DB/packages.txt | tail -1 | \
1305 sed 's/.*(\([^ ]*\).*/\1)/'
1306 done
1310 update_desktop_database()
1312 if [ -f $1/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
1313 chroot "$1/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
1314 fi
1318 update_mime_database()
1320 if [ -f $1/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
1321 chroot "$1/" /usr/bin/update-mime-database /usr/share/mime
1322 fi
1326 update_icon_database()
1328 if [ -f $1/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
1329 chroot "$1/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
1330 fi
1334 compile_glib_schemas()
1336 if [ -f $1/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
1337 chroot "$1/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
1338 fi
1342 update_kernel_modules()
1344 if [ -f $1/sbin/depmod ] && [ -n "$updatedepmod" ]; then
1345 chroot "$1/" /sbin/depmod -a
1346 fi
1353 ###################
1354 # TazPKG commands #
1355 ###################
1357 case "$COMMAND" in
1358 list|-l)
1359 # List all installed packages or a specific category.
1360 shift
1361 check_for_installed_info
1363 case $1 in
1364 b|blocked)
1365 # Display the list of blocked packages.
1366 title 'Blocked packages'
1367 if [ -s "$BLOCKED" ];then
1368 cat $BLOCKED
1369 else
1370 _ 'No blocked packages found.'
1371 fi
1372 newline; exit 0
1373 ;;
1374 c|cat|categories)
1375 # Display the list of categories.
1376 title 'Packages categories'
1377 echo "$PKGS_CATEGORIES" | sed 's|[^a-z-]|\n|g; /^$/d' | \
1378 sed 's|\(.*\)|\1'$'\033''[15G \1|' | translate_category
1379 num=$(echo -n "$PKGS_CATEGORIES" | wc -l)
1380 footer "$(_p \
1381 '%s category' \
1382 '%s categories' $num \
1383 $num)"
1384 exit 0
1385 ;;
1386 '')
1387 # By default list all packages and versions.
1388 title 'List of all installed packages'
1389 TMPLIST=$(mktemp)
1390 awk -F$'\t' '{print $1"\033[35G "$2"\033[53G "$3}' \
1391 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
1393 packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST
1394 footer "$(emsg $(_p \
1395 '%s package installed.' \
1396 '%s packages installed.' $packages \
1397 "<c 32>$packages</c>"))"
1398 ;;
1399 *)
1400 # Check for an asked category.
1401 ASKED_CATEGORY_I18N="$@"
1402 ASKED_CATEGORY=$(reverse_translate_category "$ASKED_CATEGORY_I18N")
1403 title 'Installed packages of category "%s"' $ASKED_CATEGORY_I18N
1404 TMPLIST=$(mktemp)
1405 awk -F$'\t' '
1407 if ($3 == "'$ASKED_CATEGORY'")
1408 print $1"\033[35G "$2
1409 }' \
1410 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
1412 packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST
1413 footer "$(emsg $(_p \
1414 '%s package installed of category "%s".' \
1415 '%s packages installed of category "%s".' $packages \
1416 "<c 32>$packages</c>" "<c 34>$ASKED_CATEGORY_I18N</c>"))"
1417 ;;
1418 esac ;;
1420 list-mirror|-lm)
1421 # List all available packages on the mirror. Option --diff displays
1422 # last mirrored packages diff (see recharge).
1423 check_for_packages_list
1424 case $2 in
1425 --diff)
1426 if [ -f "$PKGS_DB/packages.diff" ]; then
1427 title 'Mirrored packages diff'
1428 cat $PKGS_DB/packages.diff
1429 num=$(wc -l < $PKGS_DB/packages.diff)
1430 footer "$(_p \
1431 '%s new package listed on the mirror.' \
1432 '%s new packages listed on the mirror.' $num \
1433 $num)"
1434 else
1435 newline
1436 _ 'Unable to list anything, no packages.diff found.'
1437 _ 'Recharge your current list to create a first diff.'
1438 newline
1439 fi; exit 0 ;;
1440 --text|--txt|--raw|*)
1441 title 'List of available packages on the mirror'
1442 cat $PKGS_DB/packages.txt ;;
1443 esac
1444 pkgs=$(wc -l < $PKGS_DB/packages.list)
1445 footer "$(emsg "$(_p \
1446 '%s package in the last recharged list.' \
1447 '%s packages in the last recharged list.' $pkgs \
1448 "<c 32>$pkgs</c>")")"
1449 ;;
1452 list-files|-lf)
1453 # List files installed with the package.
1454 check_for_package_on_cmdline
1455 check_for_receipt
1456 title 'Installed files by "%s"' $PACKAGE
1457 sort < $INSTALLED/$PACKAGE/files.list
1458 files=$(wc -l < $INSTALLED/$PACKAGE/files.list)
1459 footer "$(emsg "$(_p \
1460 '%s file' '%s files' $files \
1461 "<c 32>$files</c>")")"
1462 ;;
1465 info)
1466 # Information about package.
1467 check_for_package_on_cmdline
1468 check_for_receipt
1469 EXTRAVERSION=""
1470 . $INSTALLED/$PACKAGE/receipt
1471 im && title 'TazPKG information'
1472 # Display localized short description
1473 for LC in $LANG ${LANG%_*}; do
1474 if [ -e "$PKGS_DB/packages-desc.$LC" ]; then
1475 LOCDESC=$(grep -e "^$PACKAGE " $PKGS_DB/packages-desc.$LC | cut -d' ' -f2)
1476 [ -n "$LOCDESC" ] && SHORT_DESC="$LOCDESC"
1477 fi
1478 done
1479 emsg "$(
1481 _ 'Package : %s' "$PACKAGE"
1482 _ 'Version : %s' "$VERSION$EXTRAVERSION"
1483 _ 'Category : %s' "$(_ $CATEGORY)"
1484 _ 'Short desc : %s' "$SHORT_DESC"
1485 _ 'Maintainer : %s' "$MAINTAINER"
1486 _ 'License : %s' "$LICENSE"
1487 _ 'Depends : %s' "$DEPENDS"
1488 _ 'Suggested : %s' "$SUGGESTED"
1489 _ 'Build deps : %s' "$BUILD_DEPENDS"
1490 _ 'Wanted src : %s' "$WANTED"
1491 _ 'Web site : %s' "$WEB_SITE"
1492 _ 'Tags : %s' "$TAGS"
1493 } | sed '/: $/d; s|^\([^:]*\):|<b>\1:</b>|')"
1494 im && footer
1495 ;;
1498 desc)
1499 # Display package description
1500 if [ -n "$(grep -e "^$PACKAGE " $PKGS_DB/installed.info)" ]; then
1501 im && title 'Description of package "%s"' $PACKAGE
1502 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
1503 cat $INSTALLED/$PACKAGE/description.txt
1504 else
1505 im && awk -F$'\t' '{if ($1 == "'$PACKAGE'") print $4}' $PKGS_DB/installed.info
1506 fi
1507 im && footer
1508 else
1509 im && _ 'Package "%s" is not installed.' "$PACKAGE"
1510 fi
1511 ;;
1514 activity|log|-a)
1515 # Show activity log
1516 [ "$nb" ] || nb=18
1517 title 'TazPKG Activity'
1518 IFS=" "
1519 tail -n ${nb} ${LOG} | \
1520 while read date hour none action none pkg vers none; do
1521 case $action in
1522 Installed)
1523 action=$(colorize 32 $action) ;;
1524 Removed)
1525 action=$(colorize 31 $action) ;;
1526 *)
1527 action=$(boldify $action) ;;
1528 esac
1529 echo "$date $hour : $action $pkg $vers"
1530 done
1531 unset IFS
1532 footer ;;
1535 search|-s)
1536 # Search for a package by pattern or name.
1537 PATTERN="$2"
1538 if [ -z "$PATTERN" ]; then
1539 newline
1540 _ 'Please specify a pattern or package name to search for.'
1541 echo "$(_ 'Example:') 'tazpkg search paint'"
1542 newline
1543 exit 0
1544 fi
1545 title 'Search result for "%s"' $PATTERN
1546 # Default is to search in installed pkgs and the raw list.
1547 case "$3" in
1548 -i|--installed)
1549 search_in_installed_packages ;;
1550 -l|--list)
1551 search_in_packages_list ;;
1552 -m|--mirror)
1553 search_in_packages_txt ;;
1554 *)
1555 search_in_installed_packages
1556 search_in_packages_list ;;
1557 esac ;;
1560 search-file|-sf)
1561 # Search for a file by pattern or name in all files.list.
1562 if [ -z "$2" ]; then
1563 newline
1564 _ 'Please specify a pattern or file name to search for.'
1565 echo "$(_ 'Example:') 'tazpkg search-file libnss'"
1566 newline
1567 exit 0
1568 fi
1569 title 'Search result for file "%s"' $2
1571 TMPLIST=$(mktemp)
1572 if [ "$3" == "--mirror" ]; then
1574 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1575 [ -f $i ] || continue
1576 lzcat $i | awk -F: -vP="$(gettext 'Package %s:')" -vT=$TMPLIST '
1577 BEGIN { last = "" }
1578 $2 ~ /'$2'/ {
1579 if (last != $1) {
1580 last = $1;
1581 PP = P;
1582 sub(/%s/, $1, PP);
1583 printf("\n\e[1;33m%s\e[0;39m\n", PP);
1585 gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $2);
1586 print $2;
1587 printf "%s" 1 >> T;
1588 }'
1589 done
1591 else
1593 # Check all pkg files.list in search match which specify the package
1594 # name and the full path to the file(s).
1595 for pkg in $INSTALLED/*; do
1596 if grep -qs "$2" $pkg/files.list; then
1597 . $pkg/receipt
1598 newline
1599 emsg "<c 33>$(_ 'Package %s:' $PACKAGE)</c>"
1600 awk -vT=$TMPLIST '
1601 /'$2'/ {
1602 gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $0);
1603 print " "$0;
1604 printf "%s" 1 >> T;
1606 ' $pkg/files.list
1607 fi
1608 done
1610 fi
1612 match=$(wc -m < $TMPLIST)
1613 rm $TMPLIST
1615 footer "$(emsg "$(_p \
1616 '%s file' '%s files' $match \
1617 "<c 32>$match</c>")")"
1618 ;;
1621 search-pkgname)
1622 # Search for a package name
1623 if [ -z "$2" ]; then
1624 newline
1625 _ 'Please specify a pattern or file name to search for.'
1626 echo "$(_ 'Example:') 'tazpkg search-pkgname libnss'"
1627 newline
1628 exit 0
1629 fi
1630 title 'Search result for package "%s"' $2
1632 # Search for a file on mirror and output only the package name
1633 TMPLIST=$(mktemp)
1634 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1635 [ -f $i ] || continue
1636 lzcat $i | awk -F: -vT=$TMPLIST '
1637 BEGIN { P = "" }
1638 $2 ~ /'$2'/ {
1639 if ($1 != P) {
1640 print $1;
1641 printf "%s" 1 >> T;
1642 P = $1
1644 }'
1645 done
1646 match=$(wc -m < $TMPLIST)
1647 rm $TMPLIST
1649 footer "$(emsg "$(_p \
1650 '%s package' '%s packages' $match \
1651 "<c 32>$match</c>")")"
1652 ;;
1655 install|-i)
1656 # Install .tazpkg packages.
1657 check_root $@
1658 check_for_package_on_cmdline
1659 check_for_package_file
1660 check_for_installed_info
1662 if [ -n "$root" ]; then
1663 ROOT="$root";
1664 check_base_dir "$root"
1665 fi
1666 [ "$list" ] && INSTALL_LIST="$list"
1667 if [ "$rootconfig" ]; then
1668 if [ "$root" ]; then
1669 CACHE_DIR=$root/$CACHE_DIR
1670 SAVE_CACHE_DIR=$CACHE_DIR
1671 PKGS_DB=$root/$PKGS_DB
1672 else
1673 echo "rootconfig needs --root= option used." >&2
1674 exit 1
1675 fi
1676 fi
1678 # Get repositories priority list.
1679 look_for_priority
1681 # Check if forced install.
1682 if [ -z "$forced" ]; then
1683 check_for_installed_package $ROOT
1684 fi
1685 install_package $ROOT
1686 update_desktop_database $ROOT
1687 update_mime_database $ROOT
1688 update_icon_database $ROOT
1689 compile_glib_schemas $ROOT
1690 ;;
1693 install-list|get-install-list)
1694 # Install a set of packages from a list.
1695 check_root $@
1696 if [ -z "$2" ]; then
1697 newline
1698 longline "$(_ \
1699 "Please change directory (cd) to the packages repository and specify the \
1700 list of packages to install.")"
1701 echo "$(_ 'Example:') $(emsg '<b>tazpkg install-list</b> <c 33>packages.list</c>')"
1702 exit 0
1703 fi
1705 # Check if the packages list exist.
1706 if [ ! -f "$2" ]; then
1707 _ 'Unable to find list "%s"' "$2"
1708 exit 0
1709 fi
1711 LIST=$(cat $2)
1713 # Remember processed list
1714 export INSTALL_LIST="$2"
1716 # Set $COMMAND and install all packages.
1717 COMMAND=${1%-list}
1719 touch $2-processed
1721 # Upgrade tazpkg first. It may handle new features/formats...
1722 # then upgrade essential packages early
1723 for pkg in busybox-pam busybox gcc-lib-base glibc-base \
1724 slitaz-base-files tazpkg ; do
1725 pkg=$(egrep $pkg-[0-9] $INSTALL_LIST)
1726 [ -z "$pkg" ] && continue
1727 _ 'Adding implicit depends "%s"...' $pkg
1728 LIST="$pkg
1729 $LIST"
1730 done
1732 for pkg in $LIST; do
1733 grep -qs ^$pkg$ $2-processed && continue
1734 [ -d "$root/var/lib/tazpkg/installed" ] &&
1735 tazpkg $COMMAND $pkg --list="$2" "$3" "$4" "$5"
1736 done
1737 rm -f $2-processed ;;
1740 add-flavor)
1741 # Install a set of packages from a flavor.
1742 install_flavor $2 ;;
1745 install-flavor)
1746 # Install a set of packages from a flavor and purge other ones.
1747 install_flavor $2 --purge ;;
1750 set-release)
1751 # Change current release and upgrade packages.
1752 RELEASE=$2
1753 if [ -z "$RELEASE" ]; then
1754 newline
1755 _ 'Please specify the release you want on the command line.'
1756 echo "$(_ 'Example:') tazpkg set-release cooking"
1757 newline
1758 exit 0
1759 fi
1760 rm $PKGS_DB/mirror
1761 echo "$RELEASE" > /etc/slitaz-release
1762 tazpkg recharge && tazpkg upgrade
1764 # Install missing depends
1765 cd $INSTALLED
1766 for i in * ; do
1767 DEPENDS=""
1768 . $i/receipt
1769 for j in $DEPENDS ; do
1770 [ -d $j ] || tazpkg get-install $j
1771 done
1772 done ;;
1775 remove|-r)
1776 # Remove packages.
1777 check_root $@
1778 check_for_package_on_cmdline
1779 check_for_installed_info
1781 [ -n "$root" ] && ROOT="$root"
1782 if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then
1783 newline
1784 _ 'Package "%s" is not installed.' $PACKAGE
1785 exit 0
1786 else
1787 ALTERED=""
1788 THE_PACKAGE=$PACKAGE # altered by receipt
1789 for i in $(cd $ROOT$INSTALLED ; ls); do
1790 [ -f $ROOT$INSTALLED/$i/receipt ] || continue
1791 DEPENDS=""
1792 . $ROOT$INSTALLED/$i/receipt
1793 case " $(echo $DEPENDS) " in
1794 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
1795 esac
1796 done
1797 EXTRAVERSION=""
1798 . $ROOT$INSTALLED/$THE_PACKAGE/receipt
1799 fi
1800 newline
1801 if [ -n "$ALTERED" ]; then
1802 _ 'The following packages depend on package "%s":' $PACKAGE
1803 for i in $ALTERED; do
1804 echo " $i"
1805 done
1806 fi
1807 REFRESH=$(cd $ROOT$INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1808 if [ -n "$REFRESH" ]; then
1809 _ 'The following packages have been modified by package "%s":' $PACKAGE
1810 for i in $REFRESH; do
1811 echo " ${i%/modifiers}"
1812 done
1813 fi
1814 if [ "$auto" ]; then
1815 answer=0
1816 else
1817 confirm "$(_ 'Remove package "%s" (%s)? (y/N)' $PACKAGE $VERSION$EXTRAVERSION)"
1818 answer=$?
1819 fi
1820 if [ $answer = 0 ]; then
1821 title 'Removing package "%s"' $PACKAGE
1822 # Pre remove commands.
1823 if grep -q ^pre_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1824 pre_remove $ROOT
1825 fi
1826 action "Removing all files installed..."
1827 if [ -f $ROOT$INSTALLED/$PACKAGE/modifiers ]; then
1828 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1829 for mod in $(cat $ROOT$INSTALLED/$PACKAGE/modifiers); do
1830 [ -f $ROOT$INSTALLED/$mod/files.list ] && [ $(grep "^$(echo $file | grepesc)$" $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && continue 2
1831 done
1832 remove_with_path $ROOT$file
1833 done
1834 else
1835 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1836 remove_with_path $ROOT$file
1837 done
1838 fi
1839 status
1840 if grep -q ^post_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1841 post_remove $ROOT
1842 fi
1844 # Remove package receipt.
1845 action "Removing package receipt..."
1846 rm -rf $ROOT$INSTALLED/$PACKAGE
1847 status
1849 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION$/d" \
1850 $PKGS_DB/installed.$SUM 2> /dev/null
1852 # Update installed.info
1853 sed -i "/^$PACKAGE /d" $PKGS_DB/installed.info
1855 # Log this activity
1856 log_pkg Removed
1858 if [ "$ALTERED" ]; then
1859 if [ "$auto" ]; then
1860 answer=0
1861 else
1862 confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' $PACKAGE)"
1863 answer=$?
1864 fi
1865 if [ $answer = 0 ]; then
1866 for i in $ALTERED; do
1867 if [ -d "$ROOT$INSTALLED/$i" ]; then
1868 tazpkg remove $i $ROOTOPTS
1869 fi
1870 done
1871 fi
1872 fi
1873 if [ "$REFRESH" ]; then
1874 if [ "$auto" ]; then
1875 answer=0
1876 else
1877 confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' $PACKAGE)"
1878 answer=$?
1879 fi
1880 if [ $answer = 0 ]; then
1881 for i in $REFRESH; do
1882 if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then
1883 _ 'Check %s for reinstallation' "$INSTALLED/$i"
1884 continue
1885 fi
1886 rm -r $ROOT$INSTALLED/$i
1887 tazpkg get-install ${i%/modifiers} $ROOTOPTS --forced
1888 done
1889 fi
1890 fi
1891 else
1892 newline
1893 _ 'Uninstallation of package "%s" cancelled.' $PACKAGE
1894 fi
1895 newline ;;
1898 extract|-e)
1899 # Extract .tazpkg cpio archive into a directory.
1900 check_for_package_on_cmdline
1901 check_for_package_file
1902 title 'Extracting package "%s"' $PACKAGE
1904 # If no directory destination is found on the cmdline
1905 # we create one in the current dir using the package name.
1906 if [ -n "$TARGET_DIR" ]; then
1907 DESTDIR=$TARGET_DIR/$PACKAGE
1908 else
1909 DESTDIR=$PACKAGE
1910 fi
1911 mkdir -p $DESTDIR
1913 action "Copying original package..."
1914 cp $PACKAGE_FILE $DESTDIR
1915 status
1917 cd $DESTDIR
1918 extract_package
1919 [ -e "receipt" ] && \
1920 footer "$(_ 'Package "%s" is extracted to "%s"') $PACKAGE $DESTDIR"
1921 ;;
1924 recompress)
1925 # Recompress .tazpkg cpio archive with lzma.
1926 check_for_package_on_cmdline
1927 check_for_package_file
1928 title 'Recompressing package "%s"' $PACKAGE
1929 mkdir -p $TMP_DIR
1931 action "Copying original package..."
1932 cp $PACKAGE_FILE $TMP_DIR
1933 status
1935 cd $TMP_DIR
1936 extract_package
1938 action "Recompressing the FS..."
1939 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1940 rm -rf fs
1941 status
1943 action "Creating new package..."
1944 find . -print | cpio -o -H newc --quiet > \
1945 $TOP_DIR/$(basename $PACKAGE_FILE).$$ && mv -f \
1946 $TOP_DIR/$(basename $PACKAGE_FILE).$$ \
1947 $TOP_DIR/$(basename $PACKAGE_FILE)
1948 status
1950 cd $TOP_DIR
1951 rm -rf $TMP_DIR
1952 separator; newline ;;
1955 list-config)
1956 # List configuration files installed.
1957 if [ -n "$box" ]; then
1958 mkdir -p $TMP_DIR; cd $TMP_DIR
1959 FILES="$INSTALLED/*/volatile.cpio.gz"
1960 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
1961 for i in $FILES; do
1962 zcat $i | cpio -idm --quiet > /dev/null
1963 find * -type f 2>/dev/null | while read file; do
1964 if [ ! -e /$file ]; then
1965 echo -n "----------|----|----|$(_n 'File lost')"
1966 else
1967 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
1968 cmp $file /$file > /dev/null 2>&1 || \
1969 echo -n "$(stat -c "%.16y" /$file)"
1970 fi
1971 echo "|/$file"
1972 done
1973 rm -rf *
1974 done
1975 cd $TOP_DIR
1976 rm -rf $TMP_DIR
1977 else
1978 im && title 'Configuration files'
1979 for i in $INSTALLED/*/volatile.cpio.gz; do
1980 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
1981 [ -f "$i" ] || continue
1982 zcat $i | cpio -t --quiet
1983 done | sed 's|^|/|' | sort
1984 im && footer
1985 fi ;;
1988 repack-config)
1989 # Create SliTaz package archive from configuration files.
1990 mkdir -p $TMP_DIR; cd $TMP_DIR
1991 CONFIG_VERSION=1.0
1992 mkdir config-$CONFIG_VERSION
1993 cd config-$CONFIG_VERSION
1994 for i in $INSTALLED/*/volatile.cpio.gz; do
1995 zcat $i | cpio -t --quiet
1996 done > files.list
1997 mkdir fs
1998 cd fs
1999 ( cd / ; cpio -o -H newc --quiet ) < ../files.list | cpio -idm --quiet > /dev/null
2000 mkdir -p etc/tazlito
2001 for i in $INSTALLED/*/receipt; do
2002 EXTRAVERSION=""
2003 . $i
2004 echo "$PACKAGE-$VERSION$EXTRAVERSION"
2005 done > etc/tazlito/config-packages.list
2006 cd ..
2007 echo "etc/tazlito/config-packages.list" >> files.list
2008 pkg_date=$(date +"%x %X")
2009 cat > receipt <<EOT
2010 # SliTaz package receipt.
2012 PACKAGE="config"
2013 VERSION="$CONFIG_VERSION"
2014 CATEGORY="base-system"
2015 SHORT_DESC="$(_n 'User configuration backup on date %s' $pkg_date)"
2016 DEPENDS="$(ls $INSTALLED)"
2017 EOT
2018 cd ..
2019 tazpkg pack config-$CONFIG_VERSION
2020 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
2021 cd $TOP_DIR
2022 rm -rf $TMP_DIR
2023 ;;
2026 repack)
2027 # Create SliTaz package archive from an installed package.
2028 check_for_package_on_cmdline
2029 check_for_receipt
2030 EXTRAVERSION=""
2031 . $INSTALLED/$PACKAGE/receipt
2032 title 'Repacking "%s"' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
2034 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
2035 _ "Can't repack package \"%s\"" $PACKAGE
2036 exit 1
2037 fi
2039 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
2040 _ "Can't repack, \"%s\" files have been modified by:" $PACKAGE
2041 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
2042 echo " $i"
2043 done
2044 exit 1
2045 fi
2047 MISSING=""
2048 while read i; do
2049 [ -e "$i" ] && continue
2050 [ -L "$i" ] || MISSING="$MISSING\n $i"
2051 done < $INSTALLED/$PACKAGE/files.list
2052 if [ -n "$MISSING" ]; then
2053 _n "Can't repack, the following files are lost:"
2054 echo -e "$MISSING"
2055 exit 1
2056 fi
2058 mkdir -p $TMP_DIR; cd $TMP_DIR
2059 FILES="fs.cpio.lzma\n"
2060 for i in $(ls $INSTALLED/$PACKAGE); do
2061 case $i in
2062 volatile.cpio.gz|modifiers) ;;
2063 *) cp $INSTALLED/$PACKAGE/$i .; FILES="$FILES$i\n" ;;
2064 esac
2065 done
2067 ln -s / rootfs
2068 mkdir tmp
2069 sed 's/^/rootfs/' < files.list | cpio -o -H newc --quiet | \
2070 { cd tmp ; cpio -idm --quiet >/dev/null; cd ..; }
2071 mv tmp/rootfs fs
2073 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
2074 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
2075 { cd fs; cpio -idm --quiet; cd ..; }
2076 fi
2078 if fgrep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
2079 . $INSTALLED/$PACKAGE/receipt
2080 repack_cleanup fs
2081 fi
2083 if [ -f $INSTALLED/$PACKAGE/$CHECKSUM ]; then
2084 sed 's, , fs,' < $INSTALLED/$PACKAGE/$CHECKSUM | \
2085 $CHECKSUM -s -c || {
2086 _ "Can't repack, %s error." $CHECKSUM
2087 cd $TOP_DIR
2088 rm -rf $TMP_DIR
2089 exit 1
2091 fi
2093 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2094 echo -e "$FILES" | cpio -o -H newc --quiet > \
2095 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
2096 cd $TOP_DIR
2097 \rm -R $TMP_DIR
2098 _ 'Package "%s" repacked successfully.' $PACKAGE
2099 _ 'Size: %s' "$(du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg)"
2100 newline ;;
2103 pack)
2104 # Create SliTaz package archive using cpio and lzma.
2105 # TODO: Cook also pack packages, we should share code in libpkg.sh
2106 check_for_package_on_cmdline
2107 cd $PACKAGE
2108 if [ ! -f "receipt" ]; then
2109 _ 'Receipt is missing. Please read the documentation.'
2110 exit 0
2111 fi
2113 title 'Packing package "%s"' $PACKAGE
2114 # Create files.list with redirecting find outpout.
2116 action "Creating the list of files..."
2117 cd fs
2118 find . -type f -print > ../files.list
2119 find . -type l -print >> ../files.list
2120 cd .. && sed -i s/'^.'/''/ files.list
2121 status
2123 action 'Creating %s of files...' $CHECKSUM
2124 while read file; do
2125 [ -L "fs$file" ] && continue
2126 [ -f "fs$file" ] || continue
2127 case "$file" in
2128 /lib/modules/*/modules.*|*.pyc) continue;;
2129 esac
2130 $CHECKSUM "fs$file" | sed 's/ fs/ /'
2131 done < files.list > $CHECKSUM
2132 status
2134 UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
2135 description.txt 2> /dev/null | awk \
2136 '{ sz=$1 } END { print sz }')
2137 # Build cpio archives.
2139 action "Compressing the FS..."
2140 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2141 rm -rf fs
2142 status
2144 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
2145 $CHECKSUM description.txt 2> /dev/null | awk \
2146 '{ sz=$1 } END { print sz }')
2148 action "Updating receipt sizes..."
2149 sed -i s/^PACKED_SIZE.*$// receipt
2150 sed -i s/^UNPACKED_SIZE.*$// receipt
2151 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
2152 status
2154 action "Creating full cpio archive..."
2155 find . -print | cpio -o -H newc --quiet > ../$PACKAGE.tazpkg
2156 status
2158 action "Restoring original package tree..."
2159 unlzma -c fs.cpio.lzma | cpio -idm --quiet
2160 status
2162 rm fs.cpio.lzma && cd ..
2163 footer "$(_ 'Package "%s" compressed successfully.' $PACKAGE)"
2164 _ 'Size: %s' "$(ls -lh $PACKAGE.tazpkg | awk '{print $5}')"
2165 ;;
2168 recharge)
2169 # Recharge packages.list from a mirror.
2171 # WARNING: The 'mirrors' file has all SliTaz mirrors but 'mirror'
2172 # must have only the chosen main mirror.
2174 check_root $@
2176 ARG=$2
2177 if [ "$root" ]; then
2178 PKGS_DB=$root$PKGS_DB
2179 [ "${2#--}" != "$2" ] && ARG=$3
2180 fi
2181 if [ "$ARG" = main ]; then
2182 repository_to_recharge=$PKGS_DB
2183 elif [ "$ARG" ]; then
2184 if [ -d "$PKGS_DB/undigest/$ARG" ]; then
2185 repository_to_recharge=$PKGS_DB/undigest/$ARG
2186 else
2187 repo="$PKGS_DB/undigest/$ARG"
2188 _ "Repository \"%s\" doesn't exist." $repo >&2
2189 exit 1
2190 fi
2191 else
2192 repository_to_recharge="$PKGS_DB $PKGS_DB/undigest/*"
2193 fi
2194 for path in $repository_to_recharge; do
2195 [ -f $path/mirror ] || continue
2196 cd $path
2198 # Quietly check if recharging is needed.
2199 [ -f ID ] && mv ID ID.bak
2200 download_from "$(cat mirror)" ID >/dev/null 2>/dev/null
2201 if [ -f ID ] && fgrep -q $(cat ID.bak 2>/dev/null || echo "null") ID; then
2202 if [ "$path" = "$PKGS_DB" ]; then
2203 repository_name=Main
2204 else
2205 base_path="$(basename $path)"
2206 repository_name="$(_n 'Undigest %s' $base_path)"
2207 fi
2208 _ 'Repository "%s" is up to date.' "$repository_name"
2209 rm ID.bak
2210 continue
2211 fi
2213 # Don't let ID be a symlink when using local repository.
2214 if [ -f ID ]; then
2215 mv -f ID ID.bak
2216 cat ID.bak > ID
2217 rm ID.bak
2218 fi
2220 newline
2221 if [ "$path" != "$PKGS_DB" ]; then
2222 base_path="$(basename $path)"
2223 _ 'Recharging undigest %s:' $base_path
2224 fi
2226 if [ -f "packages.list" ]; then
2227 action "Creating backup of the last packages list..."
2228 for i in packages.desc packages.$SUM packages.txt \
2229 packages.list packages.equiv files.list.lzma \
2230 extra.list mirrors packages.info
2231 do
2232 mv -f $i $i.bak 2>/dev/null
2233 done
2234 status
2235 fi
2237 for i in desc $SUM txt list equiv; do
2238 download_from "$(cat mirror)" packages.$i
2239 done
2240 download_from "$(cat mirror)" files.list.lzma
2241 download_from "$(cat mirror)" extra.list
2242 download_from "$(sed 's|packages/.*||' mirror)" mirrors
2244 # packages.info
2245 download_from "$(cat mirror)" packages.info.lzma
2246 lzma d packages.info.lzma packages.info
2247 rm packages.info.lzma
2249 if [ -f "packages.list.bak" ]; then
2250 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
2251 [ -f "extra.list.bak" ] &&
2252 diff -u extra.list.bak extra.list | grep ^+[a-z] >> packages.diff
2253 sed -i s/+// packages.diff
2254 title 'Mirrored packages diff'
2255 cat packages.diff
2256 new_pkgs=$(wc -l < packages.diff)
2257 footer "$(emsg "$(_p \
2258 '%s new package on the mirror.' \
2259 '%s new packages on the mirror.' $new_pkgs \
2260 "<c 32>$new_pkgs</c>")")"
2261 else
2262 footer "$(longline "$(_ "Last %s is ready to use. Note that \
2263 next time you recharge the list, a list of differences will be displayed to \
2264 show new and upgradeable packages." packages.list)")"
2265 fi
2266 done ;;
2269 help-up)
2270 # Options available for the command: up
2271 newline; usage_up; newline
2272 exit 1 ;;
2275 up|upgrade)
2276 check_root
2278 # This is the new way to upgrade packages making 'upgrade' and
2279 # upgradeable out-of-date. This new way is much, much more faster!
2280 # Look into installed packages and get data from receipt, it is fast
2281 # and easy to handle vars after using only md5sum to compare packages
2283 for opt in $@; do
2284 case "$opt" in
2285 --recharge|-r) tazpkg recharge ;;
2286 --install|-i) install="y" ;;
2287 --check|-c) install="n" ;;
2288 esac
2289 done
2290 time=$(date +%s)
2292 look_for_priority
2293 for repo in $priority; do
2294 pkg_list=$repo/packages.list
2295 mtime=$(find $pkg_list -mtime +7)
2296 if [ "$mtime" ]; then
2297 if [ "$repo" == "$PKGS_DB" ]; then
2298 repo_name=main
2299 else
2300 repo_name="${repo##*/}"
2301 fi
2302 _ 'List "%s" is older than one week... Recharging.' $pkg_list
2303 tazpkg recharge $repo_name
2304 fi
2305 done
2307 emsg "<n>$(_ 'Package')<i 28> $(_ 'Version')<i 48> $(_ 'Status')<->"
2309 cd $INSTALLED
2310 echo -n > $UP_LIST
2311 blocked_count=0
2312 installed_sum=$PKGS_DB/installed.$SUM
2314 for pkg in *; do
2315 [ ! -d $pkg ] && continue
2316 unset VERSION EXTRAVERSION
2317 . $pkg/receipt
2318 md5=$(fgrep " $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" \
2319 $installed_sum | awk '{print $1}')
2320 for repo in $priority; do
2321 pkg_desc=$repo/packages.desc
2322 pkg_list=$repo/packages.list
2323 pkg_sum=$repo/packages.$SUM
2325 if ! fgrep -q "$md5 $PACKAGE-" $pkg_sum; then
2326 # Jump to next repository in priority if pkg doesn't exist
2327 # in this one.
2328 grep -q ^$PACKAGE- $pkg_list || continue
2330 emsg -n "$PACKAGE<i 28> $VERSION"
2332 # Skip pkgs listed in $PKGS_DB/blocked-packages.list
2333 if $(grep -qs "^$PACKAGE" $BLOCKED); then
2334 blocked_count=$(($blocked_count + 1))
2335 emsg "<i 48><c 31> $(_ 'Blocked')</c>"
2336 break
2337 fi
2339 new=$(grep "^$PACKAGE |" $pkg_desc | awk '{print $3}')
2341 if [ "$VERSION" == "$new" ]; then
2342 emsg "<i 48><c 34> $(_ 'New build')</c>"
2343 else
2344 emsg "<i 48><c 32> $(_ 'New version %s' $new)</c>"
2345 fi
2346 echo "$PACKAGE" >> $UP_LIST
2347 break
2348 fi
2349 done
2350 done
2351 sed -i /^$/d $UP_LIST
2352 upnb=$(wc -l < $UP_LIST)
2353 pkgs=$(ls | wc -l)
2354 time=$(($(date +%s) - $time))
2355 if [ "$upnb" == 0 ]; then
2356 install="n"
2357 _ 'System is up-to-date...'
2358 fi
2360 footer "$(emsg "$(_p \
2361 '%s installed package scanned in %ds' \
2362 '%s installed packages scanned in %ds' $pkgs \
2363 "<c 32>$pkgs</c>" $time)")"
2365 if [ "$upnb" != 0 ]; then
2366 blocked="$(_p \
2367 '%s blocked' \
2368 '%s blocked' $blocked_count \
2369 $blocked_count)"
2371 boldify "$(_p \
2372 'You have %s available upgrade (%s)' \
2373 'You have %s available upgrades (%s)' $upnb \
2374 $upnb "$blocked")"
2375 newline
2376 fi
2377 # Pkgs to upgrade ? Skip, let install them all or ask user
2378 [ "$install" == "n" ] && exit 0
2379 if [ "$upnb" -gt 0 ]; then
2380 if [ "$install" == "y" ]; then
2381 continue
2382 else
2383 confirm "$(_ 'Do you wish to install them now? (y/N)')"
2384 answer=$?
2385 fi
2386 case "$answer" in
2387 0)
2388 for pkg in $(cat $UP_LIST); do
2389 echo 'y' | tazpkg get-install $pkg --forced
2390 done
2391 # List is generated each time and must be cleaned so
2392 # tazpkg-notify doesn't find upgrades anymore.
2393 rm $UP_LIST; touch $UP_LIST ;;
2394 *)
2395 _ 'Leaving without any upgrades installed.'
2396 newline
2397 exit 0 ;;
2398 esac
2399 fi
2400 newline ;;
2403 bugs)
2404 # Show known bugs in package(s)
2405 cd $INSTALLED
2406 shift
2407 LIST=$@
2408 [ -n "$LIST" ] || LIST=$(ls)
2409 MSG=$(_n 'No known bugs.')
2410 for PACKAGE in $LIST; do
2411 BUGS=""
2412 EXTRAVERSION=""
2413 . $PACKAGE/receipt
2414 if [ -n "$BUGS" ]; then
2415 MSG=$(_n 'Bug list completed')
2416 newline
2417 _ 'Bugs in package "%s" version %s:' $PACKAGE $VERSION$EXTRAVERSION
2418 cat <<EOT
2419 $BUGS
2420 EOT
2421 fi
2422 done
2423 echo "$MSG" ;;
2426 check)
2427 # Check installed packages set.
2428 check_root $@
2430 # Get repositories priority list.
2431 look_for_priority
2433 cd $INSTALLED
2434 for PACKAGE in $(ls); do
2436 if [ ! -f $PACKAGE/receipt ]; then
2437 _ 'The package "%s" installation has not completed' $PACKAGE
2438 continue
2439 fi
2441 DEPENDS=""
2442 EXTRAVERSION=""
2443 . $PACKAGE/receipt
2444 if [ -s $PACKAGE/modifiers ]; then
2445 _ 'The package "%s" has been modified by:' $PACKAGE-$VERSION$EXTRAVERSION
2446 for i in $(cat $PACKAGE/modifiers); do
2447 echo " $i"
2448 done
2449 fi
2451 MSG="$(_n 'Files lost from package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2452 while read file; do
2453 [ -e "$file" ] && continue
2454 if [ -L "$file" ]; then
2455 MSG="$MSG $(_n 'target of symlink')"
2456 fi
2457 echo -e "$MSG $file"
2458 MSG=""
2459 done < $PACKAGE/files.list
2461 MSG="$(_n 'Missing dependencies for package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2462 for i in $DEPENDS; do
2463 [ -d $i ] && continue
2464 [ -d $(equivalent_pkg $i) ] && continue
2465 echo -e "$MSG $i"
2466 MSG=""
2467 done
2469 MSG="$(_n 'Dependencies loop between "%s" and:' $PACKAGE)\n"
2470 ALL_DEPS=""
2471 check_for_deps_loop $PACKAGE $DEPENDS
2472 done
2474 _ 'Looking for known bugs...'
2475 tazpkg bugs
2477 if [ "$2" == "--full" ]; then
2478 separator
2480 for file in */$CHECKSUM; do
2481 CONFIG_FILES=""
2482 . $(dirname "$file")/receipt
2483 [ -s "$file" ] || continue
2484 while read md5 f; do
2485 [ -f $f ] || continue
2486 for i in $CONFIG_FILES; do
2487 case "$f" in
2488 $i|$i/*) continue 2;;
2489 esac
2490 done
2491 echo "$md5 $f"
2492 done < "$file" | busybox $CHECKSUM -c - 2> /dev/null | \
2493 grep -v OK$ | sed "s/FAILED$/$CHECKSUM MISMATCH/"
2494 done
2496 FILES=" "
2497 for file in $(cat */files.list); do
2498 [ -d "$file" ] && continue
2499 case "$FILES" in *\ $file\ *) continue;; esac
2500 [ $(grep "^$(echo $file | grepesc)$" */files.list 2> /dev/null | \
2501 wc -l) -gt 1 ] || continue
2502 FILES="$FILES$file "
2503 _ 'The following packages provide file "%s":' $file
2504 grep -l "^$(echo $file | grepesc)$" */files.list | \
2505 while read f; do
2506 pkg=${f%/files.list}
2507 if [ -f $pkg/modifiers ]; then
2508 overriders=$(_n '(overridden by %s)' "$(tr '\n' ' ' | sed 's| $||' < $pkg/modifiers)")
2509 else
2510 overriders=''
2511 fi
2512 echo -n " $pkg $overriders"
2513 newline
2514 done
2515 done
2517 MSG="$(_n 'No package has installed the following files:')\n"
2518 find /etc /bin /sbin /lib /usr /var/www -not -type d 2>/dev/null | \
2519 while read file; do
2520 case "$file" in *\[*) continue;; esac
2521 grep -q "^$(echo $file | grepesc)$" */files.list && continue
2522 echo -e "$MSG $file"
2523 MSG=""
2524 done
2525 fi
2526 _ 'Check completed.'; echo ;;
2529 block)
2530 # Add a pkg name to the list of blocked packages.
2531 check_root $@
2532 check_for_package_on_cmdline
2533 newline
2534 if grep -qs "^$PACKAGE" $BLOCKED; then
2535 _ 'Package "%s" is already in the blocked packages list.' $PACKAGE
2536 else
2537 action 'Add package "%s" to: %s...' $PACKAGE $BLOCKED
2538 echo $PACKAGE >> $BLOCKED
2539 status
2540 # Log this activity
2541 . $INSTALLED/$PACKAGE/receipt
2542 log_pkg Blocked
2543 fi
2544 newline ;;
2547 unblock)
2548 # Remove a pkg name from the list of blocked packages.
2549 check_root $@
2550 check_for_package_on_cmdline
2551 newline
2552 if grep -qs "^$PACKAGE" $BLOCKED; then
2553 action 'Removing package "%s" from: %s...' $PACKAGE $BLOCKED
2554 sed -i s/$PACKAGE/''/ $BLOCKED
2555 sed -i '/^$/d' $BLOCKED
2556 status
2557 # Log this activity
2558 . $INSTALLED/$PACKAGE/receipt
2559 log_pkg Unblocked
2560 else
2561 _ 'Package "%s" is not in the blocked packages list.' $PACKAGE
2562 fi
2563 newline ;;
2566 get)
2567 # Download a package with wget.
2568 check_root $@
2569 check_for_package_on_cmdline
2570 check_for_packages_list
2572 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2573 if [ "$rootconfig" ]; then
2574 if [ "$root" ]; then
2575 CACHE_DIR=$root/$CACHE_DIR
2576 SAVE_CACHE_DIR=$CACHE_DIR
2577 PKGS_DB=$root/$PKGS_DB
2578 else
2579 _ 'rootconfig needs --root= option used.' >&2
2580 exit 1
2581 fi
2582 fi
2584 # Get repositories priority list.
2585 look_for_priority
2587 CURRENT_DIR=$PWD
2588 check_for_package_in_list
2589 cd $CACHE_DIR
2590 if [ -f "$PACKAGE.tazpkg" ]; then
2591 _ 'Package "%s" already in the cache' $PACKAGE
2592 # Check package download was finished
2593 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2594 _ 'Continuing package "%s" download' $PACKAGE
2595 download $PACKAGE.tazpkg
2597 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2598 rm -f $PACKAGE.tazpkg
2599 download $PACKAGE.tazpkg
2600 fi
2601 else
2602 download $PACKAGE.tazpkg
2603 fi
2604 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2605 cp -a $PACKAGE_FILE $CURRENT_DIR ;;
2608 get-install|-gi)
2609 # Download and install a package.
2610 check_root $@
2611 check_for_package_on_cmdline
2612 check_for_packages_list
2614 DO_CHECK=""
2615 [ "$forced" ] && DO_CHECK=no
2616 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2617 [ "$list" ] && INSTALL_LIST="$list"
2618 if [ "$rootconfig" ]; then
2619 if [ "$root" ]; then
2620 CACHE_DIR=$root/$CACHE_DIR
2621 SAVE_CACHE_DIR=$CACHE_DIR
2622 PKGS_DB=$root/$PKGS_DB
2623 else
2624 _ 'rootconfig needs --root= option used.' >&2
2625 exit 1
2626 fi
2627 fi
2629 # Get repositories priority list.
2630 look_for_priority
2632 AUTOEXEC="no"
2633 if ! check_for_package_in_list check; then
2634 CACHE_DIR="${CACHE_DIR%/*}/get"
2635 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
2636 if download_get_script $PACKAGE /tmp/$PACKAGE.$$ ; then
2637 install_package_from_get_script /tmp/$PACKAGE.$$ $ROOT
2638 exit 0
2639 else
2640 PACKAGE=get-$PACKAGE
2641 AUTOEXEC=$PACKAGE
2642 check_for_package_in_list
2643 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
2644 $AUTOEXEC $ROOT
2645 exit 0
2646 fi
2647 fi
2648 fi
2649 # Check if forced install.
2650 if ! [ "$forced" ]; then
2651 check_for_installed_package $ROOT
2652 fi
2653 cd $CACHE_DIR
2654 if [ -f "$PACKAGE.tazpkg" ]; then
2655 _ 'Package "%s" already in the cache' $PACKAGE
2656 # Check package download was finished
2657 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2658 _ 'Continuing package "%s" download' $PACKAGE
2659 download $PACKAGE.tazpkg
2661 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2662 rm -f $PACKAGE.tazpkg
2663 download $PACKAGE.tazpkg
2664 fi
2665 else
2666 newline
2667 download $PACKAGE.tazpkg
2668 fi
2669 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2670 [ "$rootconfig" ] && PKGS_DB=${PKGS_DB#$root}
2671 install_package $ROOT
2672 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
2673 update_desktop_database $ROOT
2674 update_mime_database $ROOT ;;
2677 clean-cache|-cc)
2678 # Remove all downloaded packages.
2679 check_root $@
2680 files=$(find $CACHE_DIR -name *.tazpkg | wc -l)
2681 size=$(du -hs $CACHE_DIR | cut -f1 | sed 's|\.0||'); [ $files == "0" ] && size="0K"
2682 title 'Path: %s' $CACHE_DIR
2683 action "Cleaning cache directory..."
2684 rm -rf $CACHE_DIR/*
2685 status
2687 footer "$(_p \
2688 '%s file removed from cache (%s).' \
2689 '%s files removed from cache (%s).' $files \
2690 "$(colorize 32 "$files")" $size)"
2691 ;;
2694 list-undigest)
2695 # list undigest URLs.
2696 if [ "$2" = "--box" ]; then
2697 for i in $PKGS_DB/undigest/*/mirror; do
2698 [ -f $i ] || continue
2699 echo "$(basename $(dirname $i))|$(cat $i)"
2700 done
2701 else
2702 title 'Current undigest(s)'
2703 for i in $PKGS_DB/undigest/*/mirror; do
2704 if [ ! -f $i ]; then
2705 _ 'No undigest mirror found.'
2706 exit 1
2707 fi
2708 echo "$(basename $(dirname $i)) $(cat $i)"
2709 done
2710 newline
2711 fi ;;
2714 remove-undigest)
2715 # remove undigest URL.
2716 check_root $@
2717 undigest="$2"
2718 if [ -d $PKGS_DB/undigest/$2 ]; then
2719 confirm "$(_ 'Remove "%s" undigest? (y/N)' $undigest)"
2720 if [ $? = 0 ]; then
2721 action 'Removing "%s" undigest...' $undigest
2722 rm -rf $PKGS_DB/undigest/$2
2723 status
2724 rmdir $PKGS_DB/undigest 2> /dev/null
2725 fi
2726 else
2727 _ 'Undigest "%s" not found' $undigest
2728 fi ;;
2731 add-undigest|setup-undigest)
2732 # Add undigest URL.
2733 check_root $@
2734 undigest=$2
2735 [ -d $PKGS_DB/undigest ] || mkdir $PKGS_DB/undigest
2736 if [ -z "$undigest" ]; then
2737 i=1
2738 while [ -d $PKGS_DB/undigest/$i ]; do
2739 i=$(($i+1))
2740 done
2741 undigest=$i
2742 fi
2743 if [ ! -d $PKGS_DB/undigest/$undigest ]; then
2744 _ 'Creating new undigest "%s".' $undigest
2745 mkdir $PKGS_DB/undigest/$undigest
2746 fi
2747 setup_mirror $PKGS_DB/undigest/$undigest $3 ;;
2750 setup-mirror|-sm)
2751 # Change mirror URL.
2752 check_root $@
2753 setup_mirror $PKGS_DB $2 ;;
2756 reconfigure)
2757 # Replay post_install from receipt
2758 check_for_package_on_cmdline
2759 check_root $@
2760 ROOT=""
2761 while [ -n "$3" ]; do
2762 case "$3" in
2763 --root=*)
2764 ROOT="${3#--root=}/" ;;
2765 *)
2766 shift 2
2767 u_opt="$*"
2768 newline >&2
2769 _ 'Unknown option "%s".' $u_opt >&2
2770 exit 1 ;;
2771 esac
2772 shift
2773 done
2774 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2775 check_for_receipt $ROOT
2776 # Check for post_install
2777 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2778 . $ROOT$INSTALLED/$PACKAGE/receipt
2779 post_install $ROOT
2780 # Log this activity
2781 [ -n "$ROOT" ] || log_pkg Reconfigured
2782 else
2783 newline
2784 _ 'Nothing to do for package "%s".' $PACKAGE
2785 fi
2786 else
2787 newline
2788 _ 'Package "%s" is not installed.' $PACKAGE
2789 _ 'Install package with "%s" or "%s"' 'tazpkg install' 'tazpkg get-install'
2790 newline
2791 fi ;;
2794 shell)
2795 # TazPKG SHell
2796 if test $(id -u) = 0 ; then
2797 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2798 else
2799 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2800 fi
2801 if [ ! "$2" = "--noheader" ]; then
2802 clear
2803 title 'TazPKG SHell.'
2804 _ "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
2805 newline
2806 fi
2807 while true; do
2808 echo -en "$PROMPT"; read cmd
2809 case $cmd in
2810 q|quit)
2811 break ;;
2812 shell)
2813 _ 'You are already running a TazPKG SHell.' ;;
2814 su)
2815 su -c 'exec tazpkg shell --noheader' && break ;;
2816 "")
2817 continue ;;
2818 *)
2819 tazpkg $cmd ;;
2820 esac
2821 done ;;
2824 depends)
2825 # Display dependencies tree
2826 cd $INSTALLED
2827 ALL_DEPS=""
2828 if [ -f $2/receipt ]; then
2829 dep_scan $2 ""
2830 fi ;;
2833 rdepends)
2834 # Display reverse dependencies tree
2835 cd $INSTALLED
2836 ALL_DEPS=""
2837 if [ -f $2/receipt ]; then
2838 rdep_scan $2
2839 fi ;;
2842 list-suggested)
2843 for i in $(ls -d $INSTALLED/*); do
2844 . $i/receipt
2845 if [ "$SUGGESTED" ]; then
2846 if [ -z "$all" ]; then
2847 for s in $SUGGESTED; do
2848 [ -d $INSTALLED/$s ] && \
2849 SUGGESTED=$(echo -n $SUGGESTED | sed "s/$s//")
2850 done
2851 fi
2852 cat << EOT
2853 $(boldify $(echo $PACKAGE):) $SUGGESTED
2854 EOT
2855 fi
2856 SUGGESTED=""
2857 done ;;
2860 convert|-c)
2861 # convert misc package format to .tazpkg
2862 check_for_package_file
2863 tazpkg-convert $@
2864 ;;
2867 link)
2868 # link a package from another slitaz installation
2869 PACKAGE=$2
2870 if [ ! -d "$TARGET_DIR" -o \
2871 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
2872 _ 'Usage: tazpkg link package_name slitaz_root'
2873 longline "$(
2874 _n 'Example:'
2875 echo -n ' '
2876 _ '"%s" will use less than 100k in your running system RAM.' \
2877 'tazpkg link openoffice /mnt')"
2878 exit 1
2879 fi
2880 if [ -e "$INSTALLED/$PACKAGE" ]; then
2881 _ 'Package "%s" is already installed.' $PACKAGE
2882 exit 1
2883 fi
2884 ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
2885 DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
2886 MISSING=""
2887 for i in $DEPENDS; do
2888 [ -e $INSTALLED/$i ] && continue
2889 MISSING="$MISSING$i "
2890 _ 'Missing: %s' $i
2891 done
2892 if [ -n "$MISSING" ]; then
2893 newline
2894 confirm "$(_ 'Link all missing dependencies? (y/N)')"
2895 answer=$?
2896 newline
2897 if [ $answer = 0 ]; then
2898 for i in $MISSING; do
2899 tazpkg link $i $TARGET_DIR
2900 done
2901 else
2902 newline
2903 _ 'Leaving dependencies unresolved for package "%s"' $PACKAGE
2904 _ 'The package is installed but probably will not work.'
2905 newline
2906 fi
2907 fi
2908 . $INSTALLED/$PACKAGE/receipt
2909 if grep -q ^pre_install $INSTALLED/$PACKAGE/receipt; then
2910 pre_install
2911 fi
2912 while read path; do
2913 [ -e $path ] && continue
2914 while true; do
2915 dir=$(dirname $path)
2916 [ -e $dir ] && break
2917 path=$dir
2918 done
2919 ln -s $TARGET_DIR$path $dir
2920 done < $INSTALLED/$PACKAGE/files.list
2921 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
2922 post_install
2923 fi ;;
2926 usage|*)
2927 # Print a short help or give usage for an unknown or empty command.
2928 usage ;;
2929 esac
2931 exit 0