tazpkg view tazpkg @ rev 715

add "tazpkg list-suggested"
author Xander Ziiryanoff <psychomaniak@xakep.ru>
date Tue Dec 16 15:10:58 2014 +0000 (2014-12-16)
parents 5cfba8b15016
children 1dea2235808c
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.3
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 # Print the usage.
141 usage () {
142 cat << EOT
144 $(_ 'SliTaz package manager - Version: %s' $(colorize 34 $VERSION))
146 $(boldify "$(_ 'Usage:')")
147 $(_ 'tazpkg [command] [package|dir|pattern|list|cat|--opt] [dir|--opt]')
149 $(boldify "$(_ 'SHell:')") tazpkg shell
151 $(boldify "$(_ 'Commands:')")
152 $(optlist "\
153 usage $(_ 'Print this short usage')
154 bugs $(_ 'Show known bugs in packages')
155 -a activity $(_ 'Show TazPkg activity log')
156 -l list $(_ 'List installed packages on the system')
157 -lm list-mirror $(_ 'List all available packages on the mirror')
158 info $(_ 'Print information about a package')
159 desc $(_ 'Print description of a package')
160 -lf list-files $(_ 'List the files installed with a package')
161 list-config $(_ 'List the configuration files')
163 -s search $(_ 'Search for a package by pattern or name')
164 search-pkgname $(_ 'Search on mirror for package having a particular file')
165 -sf search-file $(_ 'Search for file in all installed packages files')
167 get $(_ 'Download a package into the current directory')
168 -gi get-install $(_ 'Download and install a package from the mirror')
169 get-install-list $(_ 'Download and install a list of packages from the mirror')
170 -i install $(_ 'Install a local package')
171 install-list $(_ 'Install all packages from a list of packages')
172 -r remove $(_ 'Remove the specified package and all installed files')
173 -e extract $(_ 'Extract a (*.tazpkg) package into a directory')
174 pack $(_ 'Pack an unpacked or prepared package tree')
176 recharge $(_ 'Recharge your packages.list from the mirror')
177 up|help-up $(_ 'Check packages %s to list and install latest upgrades' $CHECKSUM)
179 repack $(_ 'Create a package archive from an installed package')
180 repack-config $(_ 'Create a package archive with configuration files')
181 recompress $(_ 'Rebuild a package with a better compression ratio')
182 block|unblock $(_ 'Block an installed package version or unblock it for upgrade')
183 check $(_ 'Verify consistency of installed packages')
185 add-flavor $(_ 'Install the flavor list of packages')
186 install-flavor $(_ 'Install the flavor list of packages and remove other ones')
188 set-release $(_ 'Change release and update packages')
189 -cc clean-cache $(_ 'Clean all packages downloaded in cache directory')
191 depends $(_ 'Display dependencies tree')
192 rdepends $(_ 'Display reverse dependencies tree')
194 convert $(_ 'Convert alien package to tazpkg')
195 link $(_ 'Link a package from another slitaz installation')
197 -sm setup-mirror $(_ 'Change the mirror url configuration')
198 list-undigest $(_ 'List undigest mirrors')
199 remove-undigest $(_ 'Remove an undigest mirror')
200 add-undigest $(_ 'Add an undigest mirror')
201 setup-undigest $(_ 'Update an undigest mirror')
203 reconfigure $(_ 'Replay post install script from package')
204 ")
205 EOT
206 }
209 usage_up() {
210 cat << EOT
211 $(emsg "<b>$(_ 'Usage for command up:')</b>") tazpkg up [$(_ 'option')]
213 * $(longline "$(_ 'Without options run in interactive mode and ask before install')")
215 $(boldify "$(_ 'Where options are:')")
216 $(optlist "\
217 -c --check $(_ 'Check only for available upgrades')
218 -r --recharge $(_ 'Force recharge of packages list and check')
219 -i --install $(_ 'Check for upgrades and install them all')
220 ")
222 $(boldify "$(_ 'Example:')")
223 tazpkg up --recharge --install
224 tazpkg up -c -r
225 EOT
226 }
229 # Check if dir exists
231 check_dir()
232 {
233 if ! [ -d "$1" ]; then
234 action 'Creating folder "%s"...' "$1"
235 mkdir -p "$1"
236 status
237 return 1
238 fi
239 }
242 # Check if the directories and files used by TazPKG
243 # exist. If not and user is root we create them.
245 check_base_dir()
246 {
247 if [ "$(id -u)" = "0" ]; then
248 check_dir $1$CACHE_DIR
249 check_dir $1$INSTALLED
250 check_dir $1$SLITAZ_LOGS
251 if [ ! -f "$1$PKGS_DB/mirror" ]; then
252 echo "${DEFAULT_MIRROR%/}/" > $1$PKGS_DB/mirror
253 [ -n "$1" ] && cp $PKGS_DB/packages.* $1$PKGS_DB/
254 fi
255 fi
256 }
257 check_base_dir
260 # Check for a package name on cmdline.
262 check_for_package_on_cmdline()
263 {
264 if [ -z "$PACKAGE" ]; then
265 newline
266 _ 'Please specify a package name on the command line.'
267 newline
268 exit 1
269 fi
270 }
273 # Check if the package (*.tazpkg) exists before installing or extracting.
275 check_for_package_file()
276 {
277 if [ ! -f "$PACKAGE_FILE" ]; then
278 newline
279 _ 'Unable to find file "%s"' $PACKAGE_FILE
280 newline
281 exit 1
282 fi
283 }
286 # Check for the receipt of an installed package.
288 check_for_receipt()
289 {
290 if [ ! -f "$1$INSTALLED/$PACKAGE/receipt" ]; then
291 newline
292 _ 'Unable to find the receipt "%s"' "$1$INSTALLED/$PACKAGE/receipt"
293 newline
294 exit 1
295 fi
296 }
299 # Get repositories priority using $PKGS_DB/priority.
300 # In this files, undigest are called by their name and main mirror
301 # by main. Sort order: priority
303 look_for_priority()
304 {
305 [ -s $PKGS_DB/priority ] && priority=$(cat $PKGS_DB/priority)
306 for rep in main $(ls $PKGS_DB/undigest 2>/dev/null); do
307 if [ ! -s $PKGS_DB/priority ] || \
308 ! grep -q ^$rep$ $PKGS_DB/priority; then
309 priority=$(echo -e "$priority\n$rep")
310 fi
311 done
312 priority=$(echo "$priority" | sed '/^$/d' | \
313 while read line; do
314 if [ "$line" = main ]; then
315 echo $PKGS_DB
316 else
317 echo $PKGS_DB/undigest/$line
318 fi
319 done)
320 }
323 # Get package name in a directory
325 package_fullname_in_dir()
326 {
327 [ -f $1/receipt ] || return
328 EXTRAVERSION=""
329 . $1/receipt
330 echo $PACKAGE-$VERSION$EXTRAVERSION
331 }
334 # Get package name that is already installed.
336 get_installed_package_pathname()
337 {
338 for i in $2$INSTALLED/${1%%-*}*; do
339 [ -d $i ] || continue
340 if [ "$1" = "$(package_fullname_in_dir $i)" ]; then
341 echo $i
342 return
343 fi
344 done
345 }
348 # Check if a package is already installed.
350 check_for_installed_package()
351 {
352 if [ -n "$(get_installed_package_pathname $PACKAGE $1)" ]; then
353 newline
354 _ '"%s" package is already installed.' $(colorize 34 $PACKAGE)
355 longline "$(_ 'You can use the --forced option to force installation.')"
356 newline
357 exit 0
358 fi
359 }
362 # Check for packages.list to download and install packages.
364 check_for_packages_list()
365 {
366 list_path="$PKGS_DB/packages.list"
367 if [ ! -f "$list_path" ]; then
368 if test $(id -u) = 0 ; then
369 tazpkg recharge
370 else
371 newline
372 _ 'Unable to find the list "%s"' $list_path
373 _ \
374 "You must probably run 'tazpkg recharge' as root to get the latest list of
375 packages available on the mirror."
376 newline
377 exit 0
378 fi
379 fi
380 }
383 # Check for installed.info - local file with format of packages.info
384 # "installed.info" is absent on not clean installs; check it and re-generate if needed.
386 check_for_installed_info()
387 {
388 info_path="$PKGS_DB/installed.info"
389 if [ ! -f "$info_path" ]; then
390 if [ "$(id -u)" == "0" ]; then
391 _ 'File "%s" generated. Please wait...' installed.info
392 for pkg in $PKGS_DB/installed/*/receipt; do
393 unset_receipt
394 . $pkg
395 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
396 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
397 cat >> $info_path << EOT
398 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS
399 EOT
400 done
401 else
402 _ 'Unable to find file "%s"' installed.info
403 _ 'Please run tazpkg as root.'
404 exit 1
405 fi
406 fi
407 }
410 get_cache_dir()
411 {
412 echo $rep > $tmp/rep
413 if [ "$rep" = "$PKGS_DB" ]; then
414 CACHE_DIR="$SAVE_CACHE_DIR/$SLITAZ_RELEASE/packages"
415 elif [ "${rep%-incoming}" = "$rep" ]; then
416 CACHE_DIR="$SAVE_CACHE_DIR/${rep##*/}/packages"
417 else
418 rep="${rep%-incoming}"
419 CACHE_DIR="$SAVE_CACHE_DIR/${rep##*/}/packages-incoming"
420 fi
421 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
422 echo $CACHE_DIR > $tmp/cachedir
423 }
426 # get an already installed package from packages.equiv
428 equivalent_pkg()
429 {
430 for i in $(grep -hs "^$1=" $PKGS_DB/packages.equiv \
431 $PKGS_DB/undigest/*/packages.equiv | sed "s/^$1=//"); do
432 if echo $i | fgrep -q : ; then
433 # format 'alternative:newname'
434 # if alternative is installed then substitute newname
435 if [ -f $2$INSTALLED/${i%:*}/receipt ]; then
436 # substitute package dependency
437 echo ${i#*:}
438 return
439 fi
440 else
441 # if alternative is installed then nothing to install
442 if [ -f $2$INSTALLED/$i/receipt ]; then
443 # substitute installed package
444 echo $i
445 return
446 fi
447 fi
448 done
449 # if not found in packages.equiv then no substitution
450 echo $1
451 }
454 # get a virtual package from packages.equiv
456 virtual_pkg()
457 {
458 for i in $(for rep in $priority; do
459 grep -hs "^$1=" $rep/packages.equiv
460 done | sed "s/^$1=//"); do
461 if echo $i | fgrep -q : ; then
462 # format 'alternative:newname'
463 # if alternative is installed then substitute newname
464 if [ -f $2$INSTALLED/${i%:*}/receipt ]; then
465 # substitute package dependency
466 echo ${i#*:}
467 return
468 fi
469 else
470 # unconditional substitution
471 echo $i
472 return
473 fi
474 done
475 }
478 # Get package filename available on the mirror
480 get_package_filename()
481 {
482 local pkg
483 for rep in $priority; do
484 pkg=$(grep -A 1 -sh "^$1$" $rep/packages.txt | tail -1 | sed 's/^ *//')
485 [ "$pkg" ] && pkg=$(grep -sh "^$1-$pkg" $rep/packages.list | head -1)
487 # Allow user to call a package with his version number.
488 [ "$pkg" ] || pkg=$(grep -sh "^$1$" $rep/packages.list | head -1)
490 [ "$pkg" ] || pkg=$(grep -sh "^$1-[0-9]" $rep/packages.list | head -1)
491 [ "$pkg" ] || pkg=$(grep -sh "^$1-.[\.0-9]" $rep/packages.list | head -1)
492 [ "$pkg" ] && get_cache_dir && break
493 done
494 if [ -z "$pkg" ]; then
495 # Check for virtual package
496 local equiv
497 equiv=$(virtual_pkg $1)
498 if [ "$equiv" != "$1" ]; then
499 PACKAGE=$equiv
500 get_package_filename $PACKAGE
501 return
502 fi
503 fi
504 echo $pkg
505 }
508 # Check for a package in packages.list. Used by get and get-install to grep
509 # package basename.
511 check_for_package_in_list()
512 {
513 local filename
514 local check_only
515 check_only="$1"
516 filename=$(get_package_filename $PACKAGE)
517 if [ "$filename" ]; then
518 PACKAGE=$filename
519 CACHE_DIR=$(cat $tmp/cachedir)
520 rep=$(cat $tmp/rep)
521 rm -f $tmp/rep $tmp/cachedir
522 else
523 newline
524 _ 'Unable to find package "%s" in the mirrored packages list.' $PACKAGE
525 newline
526 [ -n "$check_only" ] && return 1
527 exit 0
528 fi
529 }
532 # Log this activity
533 # (there log_pkg because we have log() in libtaz.sh)
535 log_pkg()
536 {
537 local extra
539 [ "$1" = "Installed" ] && \
540 extra=" - $(fgrep $PACKAGE-$VERSION $PKGS_DB/installed.$SUM | awk '{ print $1 }')"
542 [ -e $LOG ] || touch $LOG
544 [ -w $LOG ] &&
545 echo "$(date +'%F %T') - $1 - $PACKAGE ($VERSION$EXTRAVERSION)$extra" >> $LOG
546 }
549 # Download a get-package script from this mirror
551 download_get_script()
552 {
553 local p
554 for p in $priority ; do
555 local i
556 for i in $(cat $p/mirror) ; do
557 case "$i" in
558 http://*|ftp://*)
559 wget -O $2 ${i%packages/*}packages/get/$1 && return 0 ;;
560 esac
561 done
562 done
563 return 1
564 }
567 # Download a file from this mirror
569 download_from()
570 {
571 local i
572 local mirrors
573 mirrors="$1"
574 shift
575 for i in $mirrors; do
576 case "$i" in
577 # Mirror URL can have a trailing slash or not.
578 http://*|ftp://*)
579 busybox wget -c ${i%/}/$@ && break ;;
580 https://*)
581 echo 'Sorry, https not supported' ;;
582 *)
583 ln -sf $i/$1 . && break ;;
584 esac
585 done
586 }
589 # Download a file trying all mirrors
591 download()
592 {
593 local i
594 case "$1" in
595 *.tazpkg)
596 for i in $priority ; do
597 grep -q "^${1%.tazpkg}$" $i/packages.list 2>/dev/null || continue
598 download_from "$(cat $i/mirror)" "$@" && return
599 done
600 esac
601 for i in $(cat $(for rep in $priority; do echo $rep/mirror; done) 2>/dev/null); do
602 download_from "$i" "$@" && break
603 done
604 }
607 # Extract a package with cpio and gzip/lzma.
609 extract_package()
610 {
611 action 'Extracting package...'
612 cpio -idm --quiet < ${PACKAGE_FILE##*/} && rm -f ${PACKAGE_FILE##*/}
613 status
614 if [ -f fs.cpio.lzma ]; then
615 unlzma -c fs.cpio.lzma | cpio -idm --quiet && rm fs.cpio.lzma
616 elif [ -f fs.cpio.gz ]; then
617 zcat fs.cpio.gz | cpio -idm --quiet && rm fs.cpio.gz
618 fi
619 }
622 remove_with_path()
623 {
624 # Avoid dirname errors by checking for argument.
625 [ "$1" ] || return
627 local dir
628 rm -f $1 2>/dev/null
629 dir="$1"
630 while [ "$dir" != "/" ]; do
631 dir="$(dirname $dir)"
632 rmdir $dir 2> /dev/null || break
633 done
634 }
637 grepesc()
638 {
639 sed 's/\[/\\[/g'
640 }
643 # This function installs a package in the rootfs.
645 install_package()
646 {
647 ROOT=$1
648 if [ -n "$ROOT" ]; then
649 # Get absolute path
650 ROOT=$(realpath $ROOT)
651 fi
652 {
653 # Create package path early to avoid dependencies loop
654 mkdir -p $TMP_DIR
655 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
656 . $TMP_DIR/receipt
657 # FIXME: legacy?
658 if grep -q ^pre_depends $TMP_DIR/receipt; then
659 pre_depends $ROOT
660 fi
662 # Keep modifiers and file list on upgrade
663 cp $ROOT$INSTALLED/$PACKAGE/modifiers \
664 $ROOT$INSTALLED/$PACKAGE/files.list $TMP_DIR 2> /dev/null
665 rm -rf $ROOT$INSTALLED/$PACKAGE 2> /dev/null
667 # Make the installed package data dir to store
668 # the receipt and the files list.
669 mkdir -p $ROOT$INSTALLED/$PACKAGE
670 cp $TMP_DIR/modifiers $ROOT$INSTALLED/$PACKAGE 2> /dev/null
671 cp $TMP_DIR/files.list $ROOT$INSTALLED/$PACKAGE 2> /dev/null
672 rm -rf $TMP_DIR 2> /dev/null
673 sed -i "/ $(basename $PACKAGE_FILE)$/d" \
674 $ROOT$PKGS_DB/installed.$SUM 2> /dev/null
675 cd $(dirname $PACKAGE_FILE)
676 $CHECKSUM $(basename $PACKAGE_FILE) >> $ROOT$PKGS_DB/installed.$SUM
677 }
679 # Resolve package deps.
680 check_for_deps $ROOT
681 if [ -n "$MISSING_PACKAGE" ]; then
682 install_deps $ROOT
683 fi
684 mkdir -p $TMP_DIR
685 [ -n "$INSTALL_LIST" ] && echo "$PACKAGE_FILE" >> $ROOT$PKGS_DB/$INSTALL_LIST-processed
687 title 'Installation of package "%s"' $PACKAGE
689 action 'Copying package...'
690 cp $PACKAGE_FILE $TMP_DIR
691 status
693 cd $TMP_DIR
694 extract_package
695 SELF_INSTALL=0
696 EXTRAVERSION=""
697 CONFIG_FILES=""
699 # Include temporary receipt to get the right variables.
700 . $PWD/receipt
701 cd $ROOT$INSTALLED
703 # FIXME: legacy?
704 if [ $SELF_INSTALL -ne 0 -a -n "$ROOT" ]; then
705 action "Checking post install dependencies..."
706 [ -f $INSTALLED/$PACKAGE/receipt ]
707 if ! status; then
708 _ 'Please run "%s" in / and retry.' "tazpkg install $PACKAGE_FILE"
709 rm -rf $TMP_DIR
710 exit 1
711 fi
712 fi
714 # Get files to remove if upgrading
715 if [ -f $PACKAGE/files.list ]; then
716 while read file; do
717 grep -q "^$(echo $file | grepesc)$" $TMP_DIR/files.list && continue
718 for i in $(cat $PACKAGE/modifiers 2> /dev/null ;
719 fgrep -sl $PACKAGE */modifiers | cut -d/ -f1 ); do
720 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
721 done
722 echo $file
723 done < $PACKAGE/files.list > $TMP_DIR/files2remove.list
724 fi
726 # Remember modified packages
727 {
728 check=false
729 for i in $(fgrep -v [ $TMP_DIR/files.list); do
730 [ -e "$ROOT$i" ] || continue
731 [ -d "$ROOT$i" ] && continue
732 echo "- $i"
733 check=true
734 done ;
735 $check && \
736 for i in *; do
737 [ "$i" == "$PACKAGE" ] && continue
738 [ -s $i/files.list ] || continue
739 awk "{ printf \"$i %s\\n\",\$1 }" < $i/files.list
740 done;
741 } | awk '
742 {
743 if ($1 == "-" || file[$2] != "") {
744 file[$2] = file[$2] " " $1
745 if ($1 != "-") {
746 if (pkg[$1] == "") all = all " " $1
747 pkg[$1] = pkg[$1] " " $2
748 }
749 }
750 }
751 END {
752 for (i = split(all, p, " "); i > 0; i--)
753 for (j = split(pkg[p[i]], f, " "); j > 0; j--)
754 printf "%s %s\n",p[i],f[j];
755 }
756 ' | while read dir file; do
757 if grep -qs ^$dir$ $PACKAGE/modifiers; then
758 # Do not overload an overloaded file !
759 rm $TMP_DIR$file 2> /dev/null
760 continue
761 fi
762 grep -qs ^$PACKAGE$ $dir/modifiers && continue
763 if [ -s "$dir/volatile.cpio.gz" ]; then
764 # We can modify backed up files without notice
765 zcat $dir/volatile.cpio.gz | cpio -t --quiet | \
766 grep -q "^${file#/}$" && continue
767 fi
768 echo "$PACKAGE" >> $dir/modifiers
769 done
771 cd $TMP_DIR
772 cp receipt files.list $ROOT$INSTALLED/$PACKAGE
774 # Copy the description if found.
775 if [ -f "description.txt" ]; then
776 cp description.txt $ROOT$INSTALLED/$PACKAGE
777 fi
779 # Copy the md5sum if found.
780 if [ -f "$CHECKSUM" ]; then
781 cp $CHECKSUM $ROOT$INSTALLED/$PACKAGE
782 fi
784 # Pre install commands.
785 if grep -q ^pre_install $ROOT$INSTALLED/$PACKAGE/receipt; then
786 pre_install $ROOT
787 fi
789 if [ -n "$CONFIG_FILES" ]; then
790 # save 'official' configuration files
791 action 'Saving configuration files...'
792 for i in $CONFIG_FILES; do
793 { cd fs ; find ${i#/} -type f 2> /dev/null; cd ..; }
794 done | { cd fs ; cpio -o -H newc --quiet | gzip -9; cd ..; } > \
795 $ROOT$INSTALLED/$PACKAGE/volatile.cpio.gz
797 if [ -z "$newconf" ]; then
798 # keep user configuration files
799 for i in $CONFIG_FILES; do
800 { cd fs ; find ${i#/} -type f 2> /dev/null; cd ..; }
801 done | while read i; do
802 [ -e $ROOT/$i ] || continue
803 cp -a $ROOT/$i fs/$i
804 done
805 fi
806 status
807 fi
809 action 'Installing package...'
810 [ "$(busybox ls fs/* 2> /dev/null)" ] && cp -a fs/* $ROOT/
811 status
813 if [ -s files2remove.list ]; then
814 action 'Removing old package...'
815 while read file; do
816 remove_with_path $ROOT$file
817 done < files2remove.list
818 true
819 status
820 fi
822 # Remove the temporary random directory.
823 action "Removing all tmp files..."
824 cd ..; rm -rf $TMP_DIR
825 status
827 # Post install commands.
828 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
829 post_install $ROOT
830 fi
832 # Update-desktop-database if needed.
833 if [ "$(fgrep .desktop $ROOT$INSTALLED/$PACKAGE/files.list | fgrep /usr/share/applications/)" ]; then
834 updatedesktopdb=yes
835 fi
837 # Update-mime-database if needed.
838 if [ "$(fgrep /usr/share/mime $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
839 updatemimedb=yes
840 fi
842 # Update-icon-database
843 if [ "$(fgrep /usr/share/icon/hicolor $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
844 updateicondb=yes
845 fi
847 # Compile glib schemas if needed.
848 if [ "$(fgrep /usr/share/glib-2.0/schemas $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
849 compile_schemas=yes
850 fi
852 # Update depmod list
853 if [ "$(fgrep /lib/modules $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
854 updatedepmod=yes
855 fi
857 # Update installed.info
858 check_for_installed_info
859 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
860 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
861 II=$PKGS_DB/installed.info
862 sed -i "/^$PACKAGE /d" $II # remove old entry
863 cat >> $II << EOT
864 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS
865 EOT
866 TEMP_FILE=$(mktemp)
867 sort $II > $TEMP_FILE; mv -f $TEMP_FILE $II; chmod a+r $II; unset II
869 cd $TOP_DIR
870 footer "$(_ 'Package "%s" (%s) is installed.' $PACKAGE $VERSION$EXTRAVERSION)"
872 # Log this activity
873 [ -n "$ROOT" ] || log_pkg Installed
874 }
877 # This function may be called by a get script.
879 abort_package()
880 {
881 cd $CUR_DIR
882 rm -rf $TMP_DIR
883 echo "${1:-Abort $PACKAGE.}"
884 exit 1
885 }
888 # This function installs a package from a get script in the rootfs.
890 install_package_from_get_script()
891 {
892 SCRIPT="$1"
893 ROOT="$2"
894 [ -d $ROOT$INSTALLED/$PACKAGE ] && exit 1
896 grep -q no-check-certificate $SCRIPT &&
897 [ ! -d $INSTALLED/wget ] && tazpkg get-install wget
899 mkdir -p $TMP_DIR && cd $TMP_DIR
900 saved=$PACKAGE
901 unset_receipt
902 PACKAGE=$saved
904 set -e
905 . $SCRIPT
906 set +e
907 cd $TMP_DIR
908 [ -d $PACKAGE-$VERSION ] || abort_package \
909 "$(_ 'Could not download "%s" from "%s". Exiting.' ${TARBALL:-$PACKAGE} ${WGET_URL:-$WEB_SITE})"
911 if [ ! -s $PACKAGE-$VERSION/receipt ]; then
912 cat > $PACKAGE-$VERSION/receipt <<EOT
913 # SliTaz package receipt.
915 PACKAGE="$PACKAGE"
916 VERSION="${VERSION:-unknown}"
917 CATEGORY="${CATEGORY:-non-free}"
918 WEB_SITE="$WEB_SITE"
919 SHORT_DESC="${SHORT_DESC:-$PACKAGE}"
920 MAINTAINER="${MAINTAINER:-nobody@slitaz.org}"
921 EOT
922 for i in LICENSE TARBALL WGET_URL CONFIG_FILES SUGGESTED \
923 PROVIDE DEPENDS HOST_ARCH TAGS EXTRA_SOURCE_FILES ; do
924 eval "[ -n \"\$$i\" ] && echo \"$i=\\\"\$$i\\\"\""
925 done >> $PACKAGE-$VERSION/receipt
926 fi
928 DEPENDS="$(unset DEPENDS; . $PACKAGE-$VERSION/receipt ; echo $DEPENDS)"
929 for i in $(find_depends $PACKAGE-$VERSION/fs); do
930 case " $DEPENDS " in
931 *\ $i\ *) continue;;
932 esac
933 grep -q '^DEPENDS="' $PACKAGE-$VERSION/receipt ||
934 echo 'DEPENDS=""' >> $PACKAGE-$VERSION/receipt
935 sed -i "s/^DEPENDS=\"/&$i /" $PACKAGE-$VERSION/receipt
936 done
938 tazpkg pack $PACKAGE-$VERSION
940 # Clean to save RAM memory before installation
941 rm -rf $PACKAGE-$VERSION
943 # Install pseudo package
944 tazpkg install $PACKAGE-$VERSION.tazpkg --root=$ROOT
945 mv $PACKAGE-$VERSION.tazpkg $CACHE_DIR
947 # Clean
948 cd $TOP_DIR
949 rm -rf $TMP_DIR
950 }
953 # Check for loop in deps tree.
955 check_for_deps_loop()
956 {
957 local list
958 local pkg
959 local deps
960 pkg=$1
961 shift
962 [ -n "$1" ] || return
963 list=""
965 # Filter out already processed deps
966 for i in $@; do
967 case " $ALL_DEPS" in
968 *\ $i\ *) ;;
969 *) list="$list $i";;
970 esac
971 done
972 ALL_DEPS="$ALL_DEPS$list "
973 for i in $list; do
974 [ -f $i/receipt ] || continue
975 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
976 case " $deps " in
977 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
978 *) check_for_deps_loop $pkg $deps;;
979 esac
980 done
981 }
984 # Check for missing deps listed in a receipt packages.
986 check_for_deps()
987 {
988 local saved;
989 saved=$PACKAGE
990 mkdir -p $TMP_DIR
991 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
992 . $TMP_DIR/receipt
993 PACKAGE=$saved
994 rm -rf $TMP_DIR
996 num=0
997 for pkgorg in $DEPENDS; do
998 i=$(equivalent_pkg $pkgorg $1)
999 if [ ! -d "$1$INSTALLED/$i" ]; then
1000 MISSING_PACKAGE=$i
1001 num=$(($num+1))
1002 elif [ ! -f "$1$INSTALLED/$i/receipt" ]; then
1003 _ 'WARNING! Dependency loop between "%s" and "%s".' $PACKAGE $i
1004 fi
1005 done
1007 if [ -n "$MISSING_PACKAGE" ]; then
1008 title "$(_ 'Tracking dependencies for package "%s"' $PACKAGE)"
1009 for pkgorg in $DEPENDS; do
1010 i=$(equivalent_pkg $pkgorg $1)
1011 if [ ! -d "$1$INSTALLED/$i" ]; then
1012 MISSING_PACKAGE=$i
1013 _ 'Missing package "%s"' $MISSING_PACKAGE
1014 fi
1015 done
1016 footer "$(_p \
1017 '%s missing package to install.' \
1018 '%s missing packages to install.' $num \
1019 $num)"
1020 fi
1024 # Install all missing deps. Auto install or ask user then install all missing
1025 # deps from local dir, cdrom, media or from the mirror. In case we want to
1026 # install packages from local, we need a packages.list to find the version.
1028 install_deps()
1030 local root
1031 root=""
1032 [ -n "$1" ] && root="--root=$1"
1033 if [ "$AUTO_INSTALL_DEPS" == "yes" ]; then
1034 answer=0
1035 else
1036 newline
1037 confirm "$(_ 'Install all missing dependencies? (y/N)')"
1038 answer=$?
1039 newline
1040 fi
1041 if [ $answer = 0 ] && ! [ "$nodeps" ]; then
1042 for pkgorg in $DEPENDS; do
1043 pkg=$(equivalent_pkg $pkgorg $1)
1044 if [ ! -d "$1$INSTALLED/$pkg" ]; then
1045 local list
1046 list="$INSTALL_LIST"
1047 [ -n "$list" ] || list="$TOP_DIR/packages.list"
1048 # We can install packages from a local dir by greping
1049 # the TAZPKG_BASENAME in the local packages.list.
1050 found=0
1051 if [ -f "$list" ]; then
1052 _ 'Checking if package "%s" exists in local list...' $pkg
1053 mkdir $TMP_DIR
1054 for i in $pkg-*.tazpkg; do
1055 [ -f $i ] || continue
1056 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $i
1057 [ "$(. $TMP_DIR/receipt; echo $PACKAGE)" = "$pkg" ] || continue
1058 if grep -q ^$(package_fullname_in_dir $TMP_DIR).tazpkg$ $list
1059 then
1060 found=1
1061 tazpkg install $i $root --list=$list
1062 break
1063 fi
1064 done
1065 rm -rf $TMP_DIR
1066 fi
1067 # Install deps from the mirror.
1068 if [ $found -eq 0 ]; then
1069 if [ ! -f "$PKGS_DB/packages.list" ]; then
1070 tazpkg recharge
1071 fi
1072 tazpkg get-install $pkg $root
1073 fi
1074 fi
1075 done
1076 else
1077 newline
1078 _ 'Leaving dependencies for package "%s" unresolved.' $PACKAGE
1079 _ 'The package is installed but will probably not work.'
1080 newline
1081 fi
1085 # Search pattern in installed packages.
1087 search_in_installed_packages()
1089 _ 'Installed packages'
1090 separator
1091 num=0
1092 for pkg in $(ls -1 $INSTALLED | grep -i "$PATTERN"); do
1093 EXTRAVERSION=""
1094 [ -f $INSTALLED/$pkg/receipt ] || continue
1095 . $INSTALLED/$pkg/receipt
1096 emsg "$PACKAGE<i 24> $VERSION$EXTRAVERSION<i 42> $(_n $CATEGORY)"
1097 num=$(($num+1))
1098 done
1100 footer "$(_p \
1101 '%s installed package found for "%s"' \
1102 '%s installed packages found for "%s"' $num \
1103 $num "$PATTERN")"
1107 # Search in packages.list for available pkgs.
1109 search_in_packages_list()
1111 _ 'Available packages'
1112 separator
1113 num=0
1114 BPATTERN="$(emsg "<b>$PATTERN</b>")"
1115 for i in $PKGS_DB/packages.list $PKGS_DB/undigest/*/packages.list; do
1116 grep -is "$PATTERN" $i | sed "s|$PATTERN|$BPATTERN|"
1117 num=$(($num + `grep -is "$PATTERN" $i | wc -l`))
1118 done
1119 if [ ! -f "$PKGS_DB/packages.list" ]; then
1120 newline
1121 longline "$(_ \
1122 "No \"%s\" found to check for mirrored packages. For more results, please run \
1123 \"%s\" once as root before searching." packages.list 'tazpkg recharge')"
1124 newline
1125 fi
1126 footer "$(_p \
1127 '%s available package found for "%s"' \
1128 '%s available packages found for "%s"' $num \
1129 $num $PATTERN)"
1133 # search --mirror: Search in packages.txt for available pkgs and give more
1134 # info than --list or default.
1136 search_in_packages_txt()
1138 _ 'Matching packages name with version and desc'
1139 separator
1140 num=0
1141 for i in $PKGS_DB/packages.txt $PKGS_DB/undigest/*/packages.txt; do
1142 grep -is -A 2 "^$PATTERN" $i
1143 num=$(($num + `grep -is "^$PATTERN" $i | wc -l`))
1144 done
1145 if [ ! -f "$PKGS_DB/packages.txt" ]; then
1146 newline
1147 longline "$(_ \
1148 "No \"%s\" found to check for mirrored packages. For more results, please run \
1149 \"%s\" once as root before searching." packages.txt 'tazpkg recharge')"
1150 newline
1151 fi
1152 footer "$(_p \
1153 '%s available package found for "%s"' \
1154 '%s available packages found for "%s"' $num \
1155 $num $PATTERN)"
1159 # Install package-list from a flavor
1161 install_flavor()
1163 check_root $@
1165 # Get repositories priority list.
1166 look_for_priority
1168 FLAVOR=$1
1169 ARG=$2
1170 mkdir -p $TMP_DIR
1171 [ -f $FLAVOR.flavor ] && cp $FLAVOR.flavor $TMP_DIR
1172 cd $TMP_DIR
1173 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1174 zcat < $FLAVOR.flavor | cpio --quiet -i >/dev/null
1176 while read file; do
1177 for pkg in $(ls -d $INSTALLED/${file%%-*}*); do
1178 [ -f $pkg/receipt ] || continue
1179 EXTRAVERSION=""
1180 . $pkg/receipt
1181 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && break
1182 done
1183 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && continue
1184 cd $CACHE_DIR
1185 download $file.tazpkg
1186 cd $TMP_DIR
1187 tazpkg install $CACHE_DIR/$file.tazpkg --forced
1188 done < $FLAVOR.pkglist
1190 [ -f $FLAVOR.nonfree ] && while read pkg; do
1191 [ -d $INSTALLED/$pkg ] || continue
1192 [ -d $INSTALLED/get-$pkg ] && tazpkg get-install get-$pkg
1193 get-$pkg
1194 done < $FLAVOR.nonfree
1196 [ "$ARG" == "--purge" ] && for pkg in $(ls $INSTALLED); do
1197 [ -f $INSTALLED/$pkg/receipt ] || continue
1198 EXTRAVERSION=""
1199 . $INSTALLED/$pkg/receipt
1200 grep -q ^$PACKAGE-$VERSION$EXTRAVERSION$ $FLAVOR.pkglist && continue
1201 grep -qs ^$PACKAGE$ $FLAVOR.nonfree && continue
1202 tazpkg remove $PACKAGE
1203 done
1204 else
1205 _ "Can't find flavor \"%s\". Abort." $FLAVOR
1206 fi
1207 cd $TOP_DIR
1208 rm -rf $TMP_DIR
1212 # Update mirror urls
1214 setup_mirror()
1216 # Backup old list.
1217 if [ -f "$1/mirror" ]; then
1218 cp -f $1/mirror $1/mirror.bak
1219 fi
1220 title 'Current mirror(s)'
1221 echo " `cat $1/mirror 2> /dev/null`"
1222 longline "$(_ \
1223 "Please enter URL of the new mirror (http, ftp or local path). You must specify \
1224 the complete address to the directory of the packages and packages.list file.")"
1225 newline
1226 _n 'New mirror(s) URL: '
1227 NEW_MIRROR_URL=$2
1228 if [ -n "$NEW_MIRROR_URL" ]; then
1229 echo $NEW_MIRROR_URL
1230 else
1231 read NEW_MIRROR_URL
1232 fi
1233 if [ "$NEW_MIRROR_URL" = "" ]; then
1234 _ 'Nothing has been changed.'
1235 else
1236 _ 'Setting mirror(s) to: "%s"' $NEW_MIRROR_URL
1237 rm -f $1/mirror
1238 for i in $NEW_MIRROR_URL; do
1239 echo "${i%/}/" >> $1/mirror
1240 done
1241 fi
1242 newline
1246 # recursive dependencies scan
1248 dep_scan()
1250 for i in $1; do
1251 case " $ALL_DEPS " in
1252 *\ $i\ *) continue;;
1253 esac
1254 ALL_DEPS="$ALL_DEPS $i"
1255 [ -n "$2" ] && echo "$2$i ($(fgrep -A 3 $i $PKGS_DB/packages.txt | \
1256 tail -1 | sed 's/.*(\([^ ]*\).*/\1/'))"
1257 [ -f $i/receipt ] || continue
1258 DEPENDS=""
1259 . $i/receipt
1260 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
1261 done
1265 # recursive reverse dependencies scan
1267 rdep_scan()
1269 SEARCH=$1
1271 for i in * ; do
1272 DEPENDS=""
1273 . $i/receipt
1274 echo "$i $(echo $DEPENDS)"
1275 done | busybox awk -v search=$SEARCH '
1276 function show_deps(deps, all_deps, pkg, space)
1278 if (all_deps[pkg] == 1) return
1279 all_deps[pkg] = 1
1280 if (space != "") printf "%s %s\n",space,pkg
1281 for (i = 1, n = split(deps[pkg], mydeps, " "); i <= n; i++) {
1282 show_deps(deps, all_deps, mydeps[i],"==" space)
1287 all_deps[$1] = 0
1288 for (i = 2; i <= NF; i++)
1289 deps[$i] = deps[$i] " " $1
1292 END {
1293 show_deps(deps, all_deps, search, "")
1295 ' | while read spc pkg; do
1296 echo -n $spc | sed 's/=/ /g'
1297 echo -n $pkg
1298 echo -n ' ('
1299 fgrep -A 3 $pkg $PKGS_DB/packages.txt | tail -1 | \
1300 sed 's/.*(\([^ ]*\).*/\1)/'
1301 done
1305 update_desktop_database()
1307 if [ -f $1/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
1308 chroot "$1/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
1309 fi
1313 update_mime_database()
1315 if [ -f $1/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
1316 chroot "$1/" /usr/bin/update-mime-database /usr/share/mime
1317 fi
1321 update_icon_database()
1323 if [ -f $1/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
1324 chroot "$1/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
1325 fi
1329 compile_glib_schemas()
1331 if [ -f $1/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
1332 chroot "$1/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
1333 fi
1337 update_kernel_modules()
1339 if [ -f $1/sbin/depmod ] && [ -n "$updatedepmod" ]; then
1340 chroot "$1/" /sbin/depmod -a
1341 fi
1348 ###################
1349 # TazPKG commands #
1350 ###################
1352 case "$COMMAND" in
1353 list|-l)
1354 # List all installed packages or a specific category.
1355 shift
1356 check_for_installed_info
1358 case $1 in
1359 b|blocked)
1360 # Display the list of blocked packages.
1361 title 'Blocked packages'
1362 if [ -s "$BLOCKED" ];then
1363 cat $BLOCKED
1364 else
1365 _ 'No blocked packages found.'
1366 fi
1367 newline; exit 0
1368 ;;
1369 c|cat|categories)
1370 # Display the list of categories.
1371 title 'Packages categories'
1372 echo "$PKGS_CATEGORIES" | sed 's|[^a-z-]|\n|g; /^$/d' | \
1373 sed 's|\(.*\)|\1'$'\033''[15G \1|' | translate_category
1374 num=$(echo -n "$PKGS_CATEGORIES" | wc -l)
1375 footer "$(_p \
1376 '%s category' \
1377 '%s categories' $num \
1378 $num)"
1379 exit 0
1380 ;;
1381 '')
1382 # By default list all packages and versions.
1383 title 'List of all installed packages'
1384 TMPLIST=$(mktemp)
1385 awk -F$'\t' '{print $1"\033[35G "$2"\033[53G "$3}' \
1386 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
1388 packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST
1389 footer "$(emsg $(_p \
1390 '%s package installed.' \
1391 '%s packages installed.' $packages \
1392 "<c 32>$packages</c>"))"
1393 ;;
1394 *)
1395 # Check for an asked category.
1396 ASKED_CATEGORY_I18N="$@"
1397 ASKED_CATEGORY=$(reverse_translate_category "$ASKED_CATEGORY_I18N")
1398 title 'Installed packages of category "%s"' $ASKED_CATEGORY_I18N
1399 TMPLIST=$(mktemp)
1400 awk -F$'\t' '
1402 if ($3 == "'$ASKED_CATEGORY'")
1403 print $1"\033[35G "$2
1404 }' \
1405 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
1407 packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST
1408 footer "$(emsg $(_p \
1409 '%s package installed of category "%s".' \
1410 '%s packages installed of category "%s".' $packages \
1411 "<c 32>$packages</c>" "<c 34>$ASKED_CATEGORY_I18N</c>"))"
1412 ;;
1413 esac ;;
1415 list-mirror|-lm)
1416 # List all available packages on the mirror. Option --diff displays
1417 # last mirrored packages diff (see recharge).
1418 check_for_packages_list
1419 case $2 in
1420 --diff)
1421 if [ -f "$PKGS_DB/packages.diff" ]; then
1422 title 'Mirrored packages diff'
1423 cat $PKGS_DB/packages.diff
1424 num=$(wc -l < $PKGS_DB/packages.diff)
1425 footer "$(_p \
1426 '%s new package listed on the mirror.' \
1427 '%s new packages listed on the mirror.' $num \
1428 $num)"
1429 else
1430 newline
1431 _ 'Unable to list anything, no packages.diff found.'
1432 _ 'Recharge your current list to create a first diff.'
1433 newline
1434 fi; exit 0 ;;
1435 --text|--txt|--raw|*)
1436 title 'List of available packages on the mirror'
1437 cat $PKGS_DB/packages.txt ;;
1438 esac
1439 pkgs=$(wc -l < $PKGS_DB/packages.list)
1440 footer "$(emsg "$(_p \
1441 '%s package in the last recharged list.' \
1442 '%s packages in the last recharged list.' $pkgs \
1443 "<c 32>$pkgs</c>")")"
1444 ;;
1447 list-files|-lf)
1448 # List files installed with the package.
1449 check_for_package_on_cmdline
1450 check_for_receipt
1451 title 'Installed files by "%s"' $PACKAGE
1452 sort < $INSTALLED/$PACKAGE/files.list
1453 files=$(wc -l < $INSTALLED/$PACKAGE/files.list)
1454 footer "$(emsg "$(_p \
1455 '%s file' '%s files' $files \
1456 "<c 32>$files</c>")")"
1457 ;;
1460 info)
1461 # Information about package.
1462 check_for_package_on_cmdline
1463 check_for_receipt
1464 EXTRAVERSION=""
1465 . $INSTALLED/$PACKAGE/receipt
1466 title 'TazPKG information'
1467 # Display localized short description
1468 for LC in $LANG ${LANG%_*}; do
1469 if [ -e "$PKGS_DB/packages-desc.$LC" ]; then
1470 LOCDESC=$(grep -e "^$PACKAGE " $PKGS_DB/packages-desc.$LC | cut -d' ' -f2)
1471 [ -n "$LOCDESC" ] && SHORT_DESC="$LOCDESC"
1472 fi
1473 done
1474 emsg "$(
1476 _ 'Package : %s' "$PACKAGE"
1477 _ 'Version : %s' "$VERSION$EXTRAVERSION"
1478 _ 'Category : %s' "$(_ $CATEGORY)"
1479 _ 'Short desc : %s' "$SHORT_DESC"
1480 _ 'Maintainer : %s' "$MAINTAINER"
1481 _ 'License : %s' "$LICENSE"
1482 _ 'Depends : %s' "$DEPENDS"
1483 _ 'Suggested : %s' "$SUGGESTED"
1484 _ 'Build deps : %s' "$BUILD_DEPENDS"
1485 _ 'Wanted src : %s' "$WANTED"
1486 _ 'Web site : %s' "$WEB_SITE"
1487 _ 'Tags : %s' "$TAGS"
1488 } | sed '/: $/d; s|^\([^:]*\):|<b>\1:</b>|')"
1489 footer ;;
1492 desc)
1493 # Display package description.txt if available.
1494 if [ -n "$(grep -e "^$PACKAGE " $PKGS_DB/installed.info)" ]; then
1495 title 'Description of package "%s"' $PACKAGE
1496 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
1497 cat $INSTALLED/$PACKAGE/description.txt
1498 else
1499 awk -F$'\t' '{if ($1 == "'$PACKAGE'") print $4}' $PKGS_DB/installed.info
1500 fi
1501 footer
1502 else
1503 _ 'Package "%s" is not installed.' "$PACKAGE"
1504 fi
1505 ;;
1508 activity|log|-a)
1509 # Show activity log
1510 [ "$nb" ] || nb=18
1511 title 'TazPKG Activity'
1512 IFS=" "
1513 tail -n ${nb} ${LOG} | \
1514 while read date hour none action none pkg vers none; do
1515 case $action in
1516 Installed)
1517 action=$(colorize 32 $action) ;;
1518 Removed)
1519 action=$(colorize 31 $action) ;;
1520 *)
1521 action=$(boldify $action) ;;
1522 esac
1523 echo "$date $hour : $action $pkg $vers"
1524 done
1525 unset IFS
1526 footer ;;
1529 search|-s)
1530 # Search for a package by pattern or name.
1531 PATTERN="$2"
1532 if [ -z "$PATTERN" ]; then
1533 newline
1534 _ 'Please specify a pattern or package name to search for.'
1535 echo "$(_ 'Example:') 'tazpkg search paint'"
1536 newline
1537 exit 0
1538 fi
1539 title 'Search result for "%s"' $PATTERN
1540 # Default is to search in installed pkgs and the raw list.
1541 case "$3" in
1542 -i|--installed)
1543 search_in_installed_packages ;;
1544 -l|--list)
1545 search_in_packages_list ;;
1546 -m|--mirror)
1547 search_in_packages_txt ;;
1548 *)
1549 search_in_installed_packages
1550 search_in_packages_list ;;
1551 esac ;;
1554 search-file|-sf)
1555 # Search for a file by pattern or name in all files.list.
1556 if [ -z "$2" ]; then
1557 newline
1558 _ 'Please specify a pattern or file name to search for.'
1559 echo "$(_ 'Example:') 'tazpkg search-file libnss'"
1560 newline
1561 exit 0
1562 fi
1563 title 'Search result for file "%s"' $2
1565 TMPLIST=$(mktemp)
1566 if [ "$3" == "--mirror" ]; then
1568 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1569 [ -f $i ] || continue
1570 lzcat $i | awk -F: -vP="$(gettext 'Package %s:')" -vT=$TMPLIST '
1571 BEGIN { last = "" }
1572 $2 ~ /'$2'/ {
1573 if (last != $1) {
1574 last = $1;
1575 PP = P;
1576 sub(/%s/, $1, PP);
1577 printf("\n\e[1;33m%s\e[0;39m\n", PP);
1579 gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $2);
1580 print $2;
1581 printf "%s" 1 >> T;
1582 }'
1583 done
1585 else
1587 # Check all pkg files.list in search match which specify the package
1588 # name and the full path to the file(s).
1589 for pkg in $INSTALLED/*; do
1590 if grep -qs "$2" $pkg/files.list; then
1591 . $pkg/receipt
1592 newline
1593 emsg "<c 33>$(_ 'Package %s:' $PACKAGE)</c>"
1594 awk -vT=$TMPLIST '
1595 /'$2'/ {
1596 gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $0);
1597 print " "$0;
1598 printf "%s" 1 >> T;
1600 ' $pkg/files.list
1601 fi
1602 done
1604 fi
1606 match=$(wc -m < $TMPLIST)
1607 rm $TMPLIST
1609 footer "$(emsg "$(_p \
1610 '%s file' '%s files' $match \
1611 "<c 32>$match</c>")")"
1612 ;;
1615 search-pkgname)
1616 # Search for a package name
1617 if [ -z "$2" ]; then
1618 newline
1619 _ 'Please specify a pattern or file name to search for.'
1620 echo "$(_ 'Example:') 'tazpkg search-pkgname libnss'"
1621 newline
1622 exit 0
1623 fi
1624 title 'Search result for package "%s"' $2
1626 # Search for a file on mirror and output only the package name
1627 TMPLIST=$(mktemp)
1628 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1629 [ -f $i ] || continue
1630 lzcat $i | awk -F: -vT=$TMPLIST '
1631 BEGIN { P = "" }
1632 $2 ~ /'$2'/ {
1633 if ($1 != P) {
1634 print $1;
1635 printf "%s" 1 >> T;
1636 P = $1
1638 }'
1639 done
1640 match=$(wc -m < $TMPLIST)
1641 rm $TMPLIST
1643 footer "$(emsg "$(_p \
1644 '%s package' '%s packages' $match \
1645 "<c 32>$match</c>")")"
1646 ;;
1649 install|-i)
1650 # Install .tazpkg packages.
1651 check_root $@
1652 check_for_package_on_cmdline
1653 check_for_package_file
1654 check_for_installed_info
1656 if [ -n "$root" ]; then
1657 ROOT="$root";
1658 check_base_dir "$root"
1659 fi
1660 [ "$list" ] && INSTALL_LIST="$list"
1661 if [ "$rootconfig" ]; then
1662 if [ "$root" ]; then
1663 CACHE_DIR=$root/$CACHE_DIR
1664 SAVE_CACHE_DIR=$CACHE_DIR
1665 PKGS_DB=$root/$PKGS_DB
1666 else
1667 echo "rootconfig needs --root= option used." >&2
1668 exit 1
1669 fi
1670 fi
1672 # Get repositories priority list.
1673 look_for_priority
1675 # Check if forced install.
1676 if [ -z "$forced" ]; then
1677 check_for_installed_package $ROOT
1678 fi
1679 install_package $ROOT
1680 update_desktop_database $ROOT
1681 update_mime_database $ROOT
1682 update_icon_database $ROOT
1683 compile_glib_schemas $ROOT
1684 ;;
1687 install-list|get-install-list)
1688 # Install a set of packages from a list.
1689 check_root $@
1690 if [ -z "$2" ]; then
1691 newline
1692 longline "$(_ \
1693 "Please change directory (cd) to the packages repository and specify the \
1694 list of packages to install.")"
1695 echo "$(_ 'Example:') $(emsg '<b>tazpkg install-list</b> <c 33>packages.list</c>')"
1696 exit 0
1697 fi
1699 # Check if the packages list exist.
1700 if [ ! -f "$2" ]; then
1701 _ 'Unable to find list "%s"' "$2"
1702 exit 0
1703 fi
1705 LIST=$(cat $2)
1707 # Remember processed list
1708 export INSTALL_LIST="$2"
1710 # Set $COMMAND and install all packages.
1711 COMMAND=${1%-list}
1713 touch $2-processed
1715 # Upgrade tazpkg first. It may handle new features/formats...
1716 # then upgrade essential packages early
1717 for pkg in busybox-pam busybox gcc-lib-base glibc-base \
1718 slitaz-base-files tazpkg ; do
1719 pkg=$(egrep $pkg-[0-9] $INSTALL_LIST)
1720 [ -z "$pkg" ] && continue
1721 _ 'Adding implicit depends "%s"...' $pkg
1722 LIST="$pkg
1723 $LIST"
1724 done
1726 for pkg in $LIST; do
1727 grep -qs ^$pkg$ $2-processed && continue
1728 [ -d "$root/var/lib/tazpkg/installed" ] && continue
1729 tazpkg $COMMAND $pkg --list="$2" "$3" "$4" "$5"
1730 done
1731 rm -f $2-processed ;;
1734 add-flavor)
1735 # Install a set of packages from a flavor.
1736 install_flavor $2 ;;
1739 install-flavor)
1740 # Install a set of packages from a flavor and purge other ones.
1741 install_flavor $2 --purge ;;
1744 set-release)
1745 # Change current release and upgrade packages.
1746 RELEASE=$2
1747 if [ -z "$RELEASE" ]; then
1748 newline
1749 _ 'Please specify the release you want on the command line.'
1750 echo "$(_ 'Example:') tazpkg set-release cooking"
1751 newline
1752 exit 0
1753 fi
1754 rm $PKGS_DB/mirror
1755 echo "$RELEASE" > /etc/slitaz-release
1756 tazpkg recharge && tazpkg upgrade
1758 # Install missing depends
1759 cd $INSTALLED
1760 for i in * ; do
1761 DEPENDS=""
1762 . $i/receipt
1763 for j in $DEPENDS ; do
1764 [ -d $j ] || tazpkg get-install $j
1765 done
1766 done ;;
1769 remove|-r)
1770 # Remove packages.
1771 check_root $@
1772 check_for_package_on_cmdline
1773 check_for_installed_info
1775 [ -n "$root" ] && ROOT="$root"
1776 if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then
1777 newline
1778 _ 'Package "%s" is not installed.' $PACKAGE
1779 exit 0
1780 else
1781 ALTERED=""
1782 THE_PACKAGE=$PACKAGE # altered by receipt
1783 for i in $(cd $ROOT$INSTALLED ; ls); do
1784 [ -f $ROOT$INSTALLED/$i/receipt ] || continue
1785 DEPENDS=""
1786 . $ROOT$INSTALLED/$i/receipt
1787 case " $(echo $DEPENDS) " in
1788 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
1789 esac
1790 done
1791 EXTRAVERSION=""
1792 . $ROOT$INSTALLED/$THE_PACKAGE/receipt
1793 fi
1794 newline
1795 if [ -n "$ALTERED" ]; then
1796 _ 'The following packages depend on package "%s":' $PACKAGE
1797 for i in $ALTERED; do
1798 echo " $i"
1799 done
1800 fi
1801 REFRESH=$(cd $ROOT$INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1802 if [ -n "$REFRESH" ]; then
1803 _ 'The following packages have been modified by package "%s":' $PACKAGE
1804 for i in $REFRESH; do
1805 echo " ${i%/modifiers}"
1806 done
1807 fi
1808 if [ "$auto" ]; then
1809 answer=0
1810 else
1811 confirm "$(_ 'Remove package "%s" (%s)? (y/N)' $PACKAGE $VERSION$EXTRAVERSION)"
1812 answer=$?
1813 fi
1814 if [ $answer = 0 ]; then
1815 title 'Removing package "%s"' $PACKAGE
1816 # Pre remove commands.
1817 if grep -q ^pre_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1818 pre_remove $ROOT
1819 fi
1820 action "Removing all files installed..."
1821 if [ -f $ROOT$INSTALLED/$PACKAGE/modifiers ]; then
1822 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1823 for mod in $(cat $ROOT$INSTALLED/$PACKAGE/modifiers); do
1824 [ -f $ROOT$INSTALLED/$mod/files.list ] && [ $(grep "^$(echo $file | grepesc)$" $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && continue 2
1825 done
1826 remove_with_path $ROOT$file
1827 done
1828 else
1829 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1830 remove_with_path $ROOT$file
1831 done
1832 fi
1833 status
1834 if grep -q ^post_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1835 post_remove $ROOT
1836 fi
1838 # Remove package receipt.
1839 action "Removing package receipt..."
1840 rm -rf $ROOT$INSTALLED/$PACKAGE
1841 status
1843 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION$/d" \
1844 $PKGS_DB/installed.$SUM 2> /dev/null
1846 # Update installed.info
1847 sed -i "/^$PACKAGE /d" $PKGS_DB/installed.info
1849 # Log this activity
1850 log_pkg Removed
1852 if [ "$ALTERED" ]; then
1853 if [ "$auto" ]; then
1854 answer=0
1855 else
1856 confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' $PACKAGE)"
1857 answer=$?
1858 fi
1859 if [ $answer = 0 ]; then
1860 for i in $ALTERED; do
1861 if [ -d "$ROOT$INSTALLED/$i" ]; then
1862 tazpkg remove $i $ROOTOPTS
1863 fi
1864 done
1865 fi
1866 fi
1867 if [ "$REFRESH" ]; then
1868 if [ "$auto" ]; then
1869 answer=0
1870 else
1871 confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' $PACKAGE)"
1872 answer=$?
1873 fi
1874 if [ $answer = 0 ]; then
1875 for i in $REFRESH; do
1876 if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then
1877 _ 'Check %s for reinstallation' "$INSTALLED/$i"
1878 continue
1879 fi
1880 rm -r $ROOT$INSTALLED/$i
1881 tazpkg get-install ${i%/modifiers} $ROOTOPTS --forced
1882 done
1883 fi
1884 fi
1885 else
1886 newline
1887 _ 'Uninstallation of package "%s" cancelled.' $PACKAGE
1888 fi
1889 newline ;;
1892 extract|-e)
1893 # Extract .tazpkg cpio archive into a directory.
1894 check_for_package_on_cmdline
1895 check_for_package_file
1896 title 'Extracting package "%s"' $PACKAGE
1898 # If no directory destination is found on the cmdline
1899 # we create one in the current dir using the package name.
1900 if [ -n "$TARGET_DIR" ]; then
1901 DESTDIR=$TARGET_DIR/$PACKAGE
1902 else
1903 DESTDIR=$PACKAGE
1904 fi
1905 mkdir -p $DESTDIR
1907 action "Copying original package..."
1908 cp $PACKAGE_FILE $DESTDIR
1909 status
1911 cd $DESTDIR
1912 extract_package
1913 [ -e "receipt" ] && \
1914 footer "$(_ 'Package "%s" is extracted to "%s"') $PACKAGE $DESTDIR"
1915 ;;
1918 recompress)
1919 # Recompress .tazpkg cpio archive with lzma.
1920 check_for_package_on_cmdline
1921 check_for_package_file
1922 title 'Recompressing package "%s"' $PACKAGE
1923 mkdir -p $TMP_DIR
1925 action "Copying original package..."
1926 cp $PACKAGE_FILE $TMP_DIR
1927 status
1929 cd $TMP_DIR
1930 extract_package
1932 action "Recompressing the FS..."
1933 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1934 rm -rf fs
1935 status
1937 action "Creating new package..."
1938 find . -print | cpio -o -H newc --quiet > \
1939 $TOP_DIR/$(basename $PACKAGE_FILE).$$ && mv -f \
1940 $TOP_DIR/$(basename $PACKAGE_FILE).$$ \
1941 $TOP_DIR/$(basename $PACKAGE_FILE)
1942 status
1944 cd $TOP_DIR
1945 rm -rf $TMP_DIR
1946 separator; newline ;;
1949 list-config)
1950 # List configuration files installed.
1951 if [ "$2" = "--box" ]; then
1952 mkdir -p $TMP_DIR; cd $TMP_DIR
1953 FILES="$INSTALLED/*/volatile.cpio.gz"
1954 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
1955 for i in $FILES; do
1956 zcat $i | cpio -idm --quiet > /dev/null
1957 find * -type f 2>/dev/null | while read file; do
1958 if [ ! -e /$file ]; then
1959 echo -n "----------|----|----|$(_n 'File lost')"
1960 else
1961 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
1962 cmp $file /$file > /dev/null 2>&1 || \
1963 echo -n "$(stat -c "%.16y" /$file)"
1964 fi
1965 echo "|/$file"
1966 done
1967 rm -rf *
1968 done
1969 cd $TOP_DIR
1970 rm -rf $TMP_DIR
1971 else
1972 title 'Configuration files'
1973 for i in $INSTALLED/*/volatile.cpio.gz; do
1974 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
1975 [ -f "$i" ] || continue
1976 zcat $i | cpio -t --quiet
1977 done | sed 's|^|/|' | sort
1978 separator
1979 newline
1980 fi ;;
1983 repack-config)
1984 # Create SliTaz package archive from configuration files.
1985 mkdir -p $TMP_DIR; cd $TMP_DIR
1986 CONFIG_VERSION=1.0
1987 mkdir config-$CONFIG_VERSION
1988 cd config-$CONFIG_VERSION
1989 for i in $INSTALLED/*/volatile.cpio.gz; do
1990 zcat $i | cpio -t --quiet
1991 done > files.list
1992 mkdir fs
1993 cd fs
1994 ( cd / ; cpio -o -H newc --quiet ) < ../files.list | cpio -idm --quiet > /dev/null
1995 mkdir -p etc/tazlito
1996 for i in $INSTALLED/*/receipt; do
1997 EXTRAVERSION=""
1998 . $i
1999 echo "$PACKAGE-$VERSION$EXTRAVERSION"
2000 done > etc/tazlito/config-packages.list
2001 cd ..
2002 echo "etc/tazlito/config-packages.list" >> files.list
2003 pkg_date=$(date +"%x %X")
2004 cat > receipt <<EOT
2005 # SliTaz package receipt.
2007 PACKAGE="config"
2008 VERSION="$CONFIG_VERSION"
2009 CATEGORY="base-system"
2010 SHORT_DESC="$(_n 'User configuration backup on date %s' $pkg_date)"
2011 DEPENDS="$(ls $INSTALLED)"
2012 EOT
2013 cd ..
2014 tazpkg pack config-$CONFIG_VERSION
2015 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
2016 cd $TOP_DIR
2017 rm -rf $TMP_DIR
2018 ;;
2021 repack)
2022 # Create SliTaz package archive from an installed package.
2023 check_for_package_on_cmdline
2024 check_for_receipt
2025 EXTRAVERSION=""
2026 . $INSTALLED/$PACKAGE/receipt
2027 title 'Repacking "%s"' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
2029 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
2030 _ "Can't repack package \"%s\"" $PACKAGE
2031 exit 1
2032 fi
2034 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
2035 _ "Can't repack, \"%s\" files have been modified by:" $PACKAGE
2036 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
2037 echo " $i"
2038 done
2039 exit 1
2040 fi
2042 MISSING=""
2043 while read i; do
2044 [ -e "$i" ] && continue
2045 [ -L "$i" ] || MISSING="$MISSING\n $i"
2046 done < $INSTALLED/$PACKAGE/files.list
2047 if [ -n "$MISSING" ]; then
2048 _n "Can't repack, the following files are lost:"
2049 echo -e "$MISSING"
2050 exit 1
2051 fi
2053 mkdir -p $TMP_DIR; cd $TMP_DIR
2054 FILES="fs.cpio.lzma\n"
2055 for i in $(ls $INSTALLED/$PACKAGE); do
2056 case $i in
2057 volatile.cpio.gz|modifiers) ;;
2058 *) cp $INSTALLED/$PACKAGE/$i .; FILES="$FILES$i\n" ;;
2059 esac
2060 done
2062 ln -s / rootfs
2063 mkdir tmp
2064 sed 's/^/rootfs/' < files.list | cpio -o -H newc --quiet | \
2065 { cd tmp ; cpio -idm --quiet >/dev/null; cd ..; }
2066 mv tmp/rootfs fs
2068 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
2069 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
2070 { cd fs; cpio -idm --quiet; cd ..; }
2071 fi
2073 if fgrep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
2074 . $INSTALLED/$PACKAGE/receipt
2075 repack_cleanup fs
2076 fi
2078 if [ -f $INSTALLED/$PACKAGE/$CHECKSUM ]; then
2079 sed 's, , fs,' < $INSTALLED/$PACKAGE/$CHECKSUM | \
2080 $CHECKSUM -s -c || {
2081 _ "Can't repack, %s error." $CHECKSUM
2082 cd $TOP_DIR
2083 rm -rf $TMP_DIR
2084 exit 1
2086 fi
2088 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2089 echo -e "$FILES" | cpio -o -H newc --quiet > \
2090 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
2091 cd $TOP_DIR
2092 \rm -R $TMP_DIR
2093 _ 'Package "%s" repacked successfully.' $PACKAGE
2094 _ 'Size: %s' "$(du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg)"
2095 newline ;;
2098 pack)
2099 # Create SliTaz package archive using cpio and lzma.
2100 # TODO: Cook also pack packages, we should share code in libpkg.sh
2101 check_for_package_on_cmdline
2102 cd $PACKAGE
2103 if [ ! -f "receipt" ]; then
2104 _ 'Receipt is missing. Please read the documentation.'
2105 exit 0
2106 else
2107 title 'Packing package "%s"' $PACKAGE
2108 # Create files.list with redirecting find outpout.
2109 action "Creating the list of files..."
2110 cd fs
2111 find . -type f -print > ../files.list
2112 find . -type l -print >> ../files.list
2113 cd .. && sed -i s/'^.'/''/ files.list
2114 status
2115 action 'Creating %s of files...' $CHECKSUM
2116 while read file; do
2117 [ -L "fs$file" ] && continue
2118 [ -f "fs$file" ] || continue
2119 case "$file" in
2120 /lib/modules/*/modules.*|*.pyc) continue;;
2121 esac
2122 $CHECKSUM "fs$file" | sed 's/ fs/ /'
2123 done < files.list > $CHECKSUM
2124 status
2125 UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
2126 description.txt 2> /dev/null | awk \
2127 '{ sz=$1 } END { print sz }')
2128 # Build cpio archives.
2129 action "Compressing the FS..."
2130 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2131 rm -rf fs
2132 status
2133 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
2134 $CHECKSUM description.txt 2> /dev/null | awk \
2135 '{ sz=$1 } END { print sz }')
2136 action "Updating receipt sizes..."
2137 sed -i s/^PACKED_SIZE.*$// receipt
2138 sed -i s/^UNPACKED_SIZE.*$// receipt
2139 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
2140 status
2141 action "Creating full cpio archive..."
2142 find . -print | cpio -o -H newc --quiet > ../$PACKAGE.tazpkg
2143 status
2144 action "Restoring original package tree..."
2145 unlzma -c fs.cpio.lzma | cpio -idm --quiet
2146 status
2147 rm fs.cpio.lzma && cd ..
2148 footer "$(_ 'Package "%s" compressed successfully.' $PACKAGE)"
2149 pkg_size=$(du -sh $PACKAGE.tazpkg)
2150 _ 'Size: %s' $pkg_size
2151 newline
2152 fi ;;
2155 recharge)
2156 # Recharge packages.list from a mirror.
2158 # WARNING: The 'mirrors' file has all SliTaz mirrors but 'mirror'
2159 # must have only the chosen main mirror.
2161 check_root $@
2163 ARG=$2
2164 if [ "$root" ]; then
2165 PKGS_DB=$root$PKGS_DB
2166 [ "${2#--}" != "$2" ] && ARG=$3
2167 fi
2168 if [ "$ARG" = main ]; then
2169 repository_to_recharge=$PKGS_DB
2170 elif [ "$ARG" ]; then
2171 if [ -d "$PKGS_DB/undigest/$ARG" ]; then
2172 repository_to_recharge=$PKGS_DB/undigest/$ARG
2173 else
2174 repo="$PKGS_DB/undigest/$ARG"
2175 _ "Repository \"%s\" doesn't exist." $repo >&2
2176 exit 1
2177 fi
2178 else
2179 repository_to_recharge="$PKGS_DB $PKGS_DB/undigest/*"
2180 fi
2181 for path in $repository_to_recharge; do
2182 [ -f $path/mirror ] || continue
2183 cd $path
2185 # Quietly check if recharging is needed.
2186 [ -f ID ] && mv ID ID.bak
2187 download_from "$(cat mirror)" ID >/dev/null 2>/dev/null
2188 if [ -f ID ] && fgrep -q $(cat ID.bak 2>/dev/null || echo "null") ID; then
2189 if [ "$path" = "$PKGS_DB" ]; then
2190 repository_name=Main
2191 else
2192 base_path="$(basename $path)"
2193 repository_name="$(_n 'Undigest %s' $base_path)"
2194 fi
2195 _ 'Repository "%s" is up to date.' $repository_name
2196 rm ID.bak
2197 continue
2198 fi
2200 # Don't let ID be a symlink when using local repository.
2201 if [ -f ID ]; then
2202 mv -f ID ID.bak
2203 cat ID.bak > ID
2204 rm ID.bak
2205 fi
2207 newline
2208 if [ "$path" != "$PKGS_DB" ]; then
2209 base_path="$(basename $path)"
2210 _ 'Recharging undigest %s:' $base_path
2211 fi
2213 if [ -f "packages.list" ]; then
2214 action "Creating backup of the last packages list..."
2215 for i in packages.desc packages.$SUM packages.txt \
2216 packages.list packages.equiv files.list.lzma \
2217 extra.list mirrors packages.info
2218 do
2219 mv -f $i $i.bak 2>/dev/null
2220 done
2221 status
2222 fi
2224 for i in desc $SUM txt list equiv; do
2225 download_from "$(cat mirror)" packages.$i
2226 done
2227 download_from "$(cat mirror)" files.list.lzma
2228 download_from "$(cat mirror)" extra.list
2229 download_from "$(sed 's|packages/.*||' mirror)" mirrors
2231 # packages.info
2232 download_from "$(cat mirror)" packages.info.lzma
2233 lzma d packages.info.lzma packages.info
2234 rm packages.info.lzma
2236 if [ -f "packages.list.bak" ]; then
2237 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
2238 [ -f "extra.list.bak" ] &&
2239 diff -u extra.list.bak extra.list | grep ^+[a-z] >> packages.diff
2240 sed -i s/+// packages.diff
2241 title 'Mirrored packages diff'
2242 cat packages.diff
2243 new_pkgs=$(wc -l < packages.diff)
2244 footer "$(emsg "$(_p \
2245 '%s new package on the mirror.' \
2246 '%s new packages on the mirror.' $new_pkgs \
2247 "<c 32>$new_pkgs</c>")")"
2248 else
2249 footer "$(longline "$(_ "Last %s is ready to use. Note that \
2250 next time you recharge the list, a list of differences will be displayed to \
2251 show new and upgradeable packages." packages.list)")"
2252 fi
2253 done ;;
2256 help-up)
2257 # Options available for the command: up
2258 newline; usage_up; newline
2259 exit 1 ;;
2262 up|upgrade)
2263 check_root
2265 # This is the new way to upgrade packages making 'upgrade' and
2266 # upgradeable out-of-date. This new way is much, much more faster!
2267 # Look into installed packages and get data from receipt, it is fast
2268 # and easy to handle vars after using only md5sum to compare packages
2270 for opt in $@; do
2271 case "$opt" in
2272 --recharge|-r) tazpkg recharge ;;
2273 --install|-i) install="y" ;;
2274 --check|-c) install="n" ;;
2275 esac
2276 done
2277 time=$(date +%s)
2278 installed_sum=$PKGS_DB/installed.$SUM
2279 look_for_priority
2280 for repo in $priority; do
2281 pkg_list=$repo/packages.list
2282 mtime=$(find $pkg_list -mtime +7)
2283 if [ "$mtime" ]; then
2284 if [ "$repo" = "$PKGS_DB" ]; then
2285 repo_name=main
2286 else
2287 repo_name="${repo##*/}"
2288 fi
2289 _ 'List "%s" is older than one week... Recharging.' $pkg_list
2290 tazpkg recharge $repo_name
2291 fi
2292 done
2293 emsg "<n>$(_ 'Package')<i 28> $(_ 'Version')<i 48> $(_ 'Status')<->"
2294 cd $INSTALLED
2295 newline > $UP_LIST
2296 blocked_count=0
2297 for pkg in *; do
2298 [ ! -d $pkg ] && continue
2299 unset VERSION EXTRAVERSION
2300 . $pkg/receipt
2301 md5=$(fgrep " $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" \
2302 $installed_sum | awk '{print $1}')
2303 for repo in $priority; do
2304 pkg_desc=$repo/packages.desc
2305 pkg_list=$repo/packages.list
2306 pkg_sum=$repo/packages.$SUM
2308 if ! fgrep -q "$md5 $PACKAGE-" $pkg_sum; then
2309 # Jump to next repository in priority if pkg doesn't exist
2310 # in this one.
2311 grep -q ^$PACKAGE- $pkg_list || continue
2313 emsg -n "$PACKAGE<i 28> $VERSION"
2315 # Skip pkgs listed in $PKGS_DB/blocked-packages.list
2316 if $(grep -qs "^$PACKAGE" $BLOCKED); then
2317 blocked_count=$(($blocked_count + 1))
2318 emsg "<i 48><c 31> $(_ 'Blocked')</c>"
2319 break
2320 fi
2322 new=$(grep "^$PACKAGE |" $pkg_desc | awk '{print $3}')
2324 if [ "$VERSION" == "$new" ]; then
2325 emsg "<i 48><c 34> $(_ 'New build')</c>"
2326 else
2327 emsg "<i 48><c 32> $(_ 'New version %s' $new)</c>"
2328 fi
2329 echo "$PACKAGE" >> $UP_LIST
2330 break
2331 fi
2332 done
2333 done
2334 sed -i /^$/d $UP_LIST
2335 upnb=$(wc -l < $UP_LIST)
2336 pkgs=$(ls | wc -l)
2337 time=$(($(date +%s) - $time))
2338 if [ "$upnb" = 0 ]; then
2339 install="n"
2340 _ 'System is up-to-date...'
2341 fi
2343 footer "$(emsg "$(_p \
2344 '%s installed package scanned in %ds' \
2345 '%s installed packages scanned in %ds' $pkgs \
2346 "<c 32>$pkgs</c>" $time)")"
2348 if [ "$upnb" != 0 ]; then
2349 blocked="$(_p \
2350 '%s blocked' '%s blocked' $blocked_count \
2351 $blocked_count)"
2353 boldify "$(_p \
2354 'You have %s available upgrade (%s)' \
2355 'You have %s available upgrades (%s)' $upnb \
2356 $upnb "$blocked")"
2357 newline
2358 fi
2359 # Pkgs to upgrade ? Skip, let install them all or ask user
2360 [ "$install" == "n" ] && exit 0
2361 if [ "$upnb" -gt 0 ]; then
2362 if [ "$install" == "y" ]; then
2363 continue
2364 else
2365 confirm "$(_ 'Do you wish to install them now? (y/N)')"
2366 answer=$?
2367 fi
2368 case "$answer" in
2369 0)
2370 for pkg in $(cat $UP_LIST); do
2371 echo 'y' | tazpkg get-install $pkg --forced
2372 done
2373 # List is generated each time and must be cleaned so
2374 # tazpkg-notify doesn't find upgrades anymore.
2375 rm $UP_LIST; touch $UP_LIST ;;
2376 *)
2377 _ 'Leaving without any upgrades installed.'
2378 newline
2379 exit 0 ;;
2380 esac
2381 fi
2382 newline ;;
2385 bugs)
2386 # Show known bugs in package(s)
2387 cd $INSTALLED
2388 shift
2389 LIST=$@
2390 [ -n "$LIST" ] || LIST=$(ls)
2391 MSG=$(_n 'No known bugs.')
2392 for PACKAGE in $LIST; do
2393 BUGS=""
2394 EXTRAVERSION=""
2395 . $PACKAGE/receipt
2396 if [ -n "$BUGS" ]; then
2397 MSG=$(_n 'Bug list completed')
2398 newline
2399 _ 'Bugs in package "%s" version %s:' $PACKAGE $VERSION$EXTRAVERSION
2400 cat <<EOT
2401 $BUGS
2402 EOT
2403 fi
2404 done
2405 echo "$MSG" ;;
2408 check)
2409 # Check installed packages set.
2410 check_root $@
2412 # Get repositories priority list.
2413 look_for_priority
2415 cd $INSTALLED
2416 for PACKAGE in $(ls); do
2418 if [ ! -f $PACKAGE/receipt ]; then
2419 _ 'The package "%s" installation has not completed' $PACKAGE
2420 continue
2421 fi
2423 DEPENDS=""
2424 EXTRAVERSION=""
2425 . $PACKAGE/receipt
2426 if [ -s $PACKAGE/modifiers ]; then
2427 _ 'The package "%s" has been modified by:' $PACKAGE-$VERSION$EXTRAVERSION
2428 for i in $(cat $PACKAGE/modifiers); do
2429 echo " $i"
2430 done
2431 fi
2433 MSG="$(_n 'Files lost from package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2434 while read file; do
2435 [ -e "$file" ] && continue
2436 if [ -L "$file" ]; then
2437 MSG="$MSG $(_n 'target of symlink')"
2438 fi
2439 echo -e "$MSG $file"
2440 MSG=""
2441 done < $PACKAGE/files.list
2443 MSG="$(_n 'Missing dependencies for package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2444 for i in $DEPENDS; do
2445 [ -d $i ] && continue
2446 [ -d $(equivalent_pkg $i) ] && continue
2447 echo -e "$MSG $i"
2448 MSG=""
2449 done
2451 MSG="$(_n 'Dependencies loop between "%s" and:' $PACKAGE)\n"
2452 ALL_DEPS=""
2453 check_for_deps_loop $PACKAGE $DEPENDS
2454 done
2456 _ 'Looking for known bugs...'
2457 tazpkg bugs
2459 if [ "$2" == "--full" ]; then
2460 separator
2462 for file in */$CHECKSUM; do
2463 CONFIG_FILES=""
2464 . $(dirname "$file")/receipt
2465 [ -s "$file" ] || continue
2466 while read md5 f; do
2467 [ -f $f ] || continue
2468 for i in $CONFIG_FILES; do
2469 case "$f" in
2470 $i|$i/*) continue 2;;
2471 esac
2472 done
2473 echo "$md5 $f"
2474 done < "$file" | $CHECKSUM -c - 2> /dev/null | \
2475 grep -v OK$ | sed "s/FAILED$/$CHECKSUM MISMATCH/"
2476 done
2478 FILES=" "
2479 for file in $(cat */files.list); do
2480 [ -d "$file" ] && continue
2481 case "$FILES" in *\ $file\ *) continue;; esac
2482 [ $(grep "^$(echo $file | grepesc)$" */files.list 2> /dev/null | \
2483 wc -l) -gt 1 ] || continue
2484 FILES="$FILES$file "
2485 _ 'The following packages provide file "%s":' $file
2486 grep -l "^$(echo $file | grepesc)$" */files.list | \
2487 while read f; do
2488 pkg=${f%/files.list}
2489 if [ -f $pkg/modifiers ]; then
2490 overriders=$(_n '(overridden by %s)' "$(tr '\n' ' ' | sed 's| $||' < $pkg/modifiers)")
2491 else
2492 overriders=''
2493 fi
2494 echo -n " $pkg $overriders"
2495 newline
2496 done
2497 done
2499 MSG="$(_n 'No package has installed the following files:')\n"
2500 find /etc /bin /sbin /lib /usr /var/www -not -type d 2>/dev/null | \
2501 while read file; do
2502 case "$file" in *\[*) continue;; esac
2503 grep -q "^$(echo $file | grepesc)$" */files.list && continue
2504 echo -e "$MSG $file"
2505 MSG=""
2506 done
2507 fi
2508 _ 'Check completed.'; echo ;;
2511 block)
2512 # Add a pkg name to the list of blocked packages.
2513 check_root $@
2514 check_for_package_on_cmdline
2515 newline
2516 if grep -qs "^$PACKAGE" $BLOCKED; then
2517 _ 'Package "%s" is already in the blocked packages list.' $PACKAGE
2518 else
2519 action 'Add package "%s" to: %s...' $PACKAGE $BLOCKED
2520 echo $PACKAGE >> $BLOCKED
2521 status
2522 # Log this activity
2523 . $INSTALLED/$PACKAGE/receipt
2524 log_pkg Blocked
2525 fi
2526 newline ;;
2529 unblock)
2530 # Remove a pkg name from the list of blocked packages.
2531 check_root $@
2532 check_for_package_on_cmdline
2533 newline
2534 if grep -qs "^$PACKAGE" $BLOCKED; then
2535 action 'Removing package "%s" from: %s...' $PACKAGE $BLOCKED
2536 sed -i s/$PACKAGE/''/ $BLOCKED
2537 sed -i '/^$/d' $BLOCKED
2538 status
2539 # Log this activity
2540 . $INSTALLED/$PACKAGE/receipt
2541 log_pkg Unblocked
2542 else
2543 _ 'Package "%s" is not in the blocked packages list.' $PACKAGE
2544 fi
2545 newline ;;
2548 get)
2549 # Download a package with wget.
2550 check_root $@
2551 check_for_package_on_cmdline
2552 check_for_packages_list
2554 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2555 if [ "$rootconfig" ]; then
2556 if [ "$root" ]; then
2557 CACHE_DIR=$root/$CACHE_DIR
2558 SAVE_CACHE_DIR=$CACHE_DIR
2559 PKGS_DB=$root/$PKGS_DB
2560 else
2561 _ 'rootconfig needs --root= option used.' >&2
2562 exit 1
2563 fi
2564 fi
2566 # Get repositories priority list.
2567 look_for_priority
2569 CURRENT_DIR=$PWD
2570 check_for_package_in_list
2571 cd $CACHE_DIR
2572 if [ -f "$PACKAGE.tazpkg" ]; then
2573 _ 'Package "%s" already in the cache' $PACKAGE
2574 # Check package download was finished
2575 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2576 _ 'Continuing package "%s" download' $PACKAGE
2577 download $PACKAGE.tazpkg
2579 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2580 rm -f $PACKAGE.tazpkg
2581 download $PACKAGE.tazpkg
2582 fi
2583 else
2584 download $PACKAGE.tazpkg
2585 fi
2586 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2587 cp -a $PACKAGE_FILE $CURRENT_DIR ;;
2590 get-install|-gi)
2591 # Download and install a package.
2592 check_root $@
2593 check_for_package_on_cmdline
2594 check_for_packages_list
2596 DO_CHECK=""
2597 [ "$forced" ] && DO_CHECK=no
2598 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2599 [ "$list" ] && INSTALL_LIST="$list"
2600 if [ "$rootconfig" ]; then
2601 if [ "$root" ]; then
2602 CACHE_DIR=$root/$CACHE_DIR
2603 SAVE_CACHE_DIR=$CACHE_DIR
2604 PKGS_DB=$root/$PKGS_DB
2605 else
2606 _ 'rootconfig needs --root= option used.' >&2
2607 exit 1
2608 fi
2609 fi
2611 # Get repositories priority list.
2612 look_for_priority
2614 AUTOEXEC="no"
2615 if ! check_for_package_in_list check; then
2616 CACHE_DIR="${CACHE_DIR%/*}/get"
2617 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
2618 if download_get_script $PACKAGE /tmp/$PACKAGE.$$ ; then
2619 install_package_from_get_script /tmp/$PACKAGE.$$ $ROOT
2620 exit 0
2621 else
2622 PACKAGE=get-$PACKAGE
2623 AUTOEXEC=$PACKAGE
2624 check_for_package_in_list
2625 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
2626 $AUTOEXEC $ROOT
2627 exit 0
2628 fi
2629 fi
2630 fi
2631 # Check if forced install.
2632 if ! [ "$forced" ]; then
2633 check_for_installed_package $ROOT
2634 fi
2635 cd $CACHE_DIR
2636 if [ -f "$PACKAGE.tazpkg" ]; then
2637 _ 'Package "%s" already in the cache' $PACKAGE
2638 # Check package download was finished
2639 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2640 _ 'Continuing package "%s" download' $PACKAGE
2641 download $PACKAGE.tazpkg
2643 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2644 rm -f $PACKAGE.tazpkg
2645 download $PACKAGE.tazpkg
2646 fi
2647 else
2648 newline
2649 download $PACKAGE.tazpkg
2650 fi
2651 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2652 [ "$rootconfig" ] && PKGS_DB=${PKGS_DB#$root}
2653 install_package $ROOT
2654 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
2655 update_desktop_database $ROOT
2656 update_mime_database $ROOT ;;
2659 clean-cache|-cc)
2660 # Remove all downloaded packages.
2661 check_root $@
2662 files=$(find $CACHE_DIR -name *.tazpkg | wc -l)
2663 size=$(du -hs $CACHE_DIR | cut -f1 | sed 's|\.0||'); [ $files == "0" ] && size="0K"
2664 title 'Path: %s' $CACHE_DIR
2665 action "Cleaning cache directory..."
2666 rm -rf $CACHE_DIR/*
2667 status
2669 footer "$(_p \
2670 '%s file removed from cache (%s).' \
2671 '%s files removed from cache (%s).' $files \
2672 "$(colorize 32 "$files")" $size)"
2673 ;;
2676 list-undigest)
2677 # list undigest URLs.
2678 if [ "$2" = "--box" ]; then
2679 for i in $PKGS_DB/undigest/*/mirror; do
2680 [ -f $i ] || continue
2681 echo "$(basename $(dirname $i))|$(cat $i)"
2682 done
2683 else
2684 title 'Current undigest(s)'
2685 for i in $PKGS_DB/undigest/*/mirror; do
2686 if [ ! -f $i ]; then
2687 _ 'No undigest mirror found.'
2688 exit 1
2689 fi
2690 echo "$(basename $(dirname $i)) $(cat $i)"
2691 done
2692 newline
2693 fi ;;
2696 remove-undigest)
2697 # remove undigest URL.
2698 check_root $@
2699 undigest="$2"
2700 if [ -d $PKGS_DB/undigest/$2 ]; then
2701 confirm "$(_ 'Remove "%s" undigest? (y/N)' $undigest)"
2702 if [ $? = 0 ]; then
2703 action 'Removing "%s" undigest...' $undigest
2704 rm -rf $PKGS_DB/undigest/$2
2705 status
2706 rmdir $PKGS_DB/undigest 2> /dev/null
2707 fi
2708 else
2709 _ 'Undigest "%s" not found' $undigest
2710 fi ;;
2713 add-undigest|setup-undigest)
2714 # Add undigest URL.
2715 check_root $@
2716 undigest=$2
2717 [ -d $PKGS_DB/undigest ] || mkdir $PKGS_DB/undigest
2718 if [ -z "$undigest" ]; then
2719 i=1
2720 while [ -d $PKGS_DB/undigest/$i ]; do
2721 i=$(($i+1))
2722 done
2723 undigest=$i
2724 fi
2725 if [ ! -d $PKGS_DB/undigest/$undigest ]; then
2726 _ 'Creating new undigest "%s".' $undigest
2727 mkdir $PKGS_DB/undigest/$undigest
2728 fi
2729 setup_mirror $PKGS_DB/undigest/$undigest $3 ;;
2732 setup-mirror|-sm)
2733 # Change mirror URL.
2734 check_root $@
2735 setup_mirror $PKGS_DB $2 ;;
2738 reconfigure)
2739 # Replay post_install from receipt
2740 check_for_package_on_cmdline
2741 check_root $@
2742 ROOT=""
2743 while [ -n "$3" ]; do
2744 case "$3" in
2745 --root=*)
2746 ROOT="${3#--root=}/" ;;
2747 *)
2748 shift 2
2749 u_opt="$*"
2750 newline >&2
2751 _ 'Unknown option "%s".' $u_opt >&2
2752 exit 1 ;;
2753 esac
2754 shift
2755 done
2756 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2757 check_for_receipt $ROOT
2758 # Check for post_install
2759 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2760 . $ROOT$INSTALLED/$PACKAGE/receipt
2761 post_install $ROOT
2762 # Log this activity
2763 [ -n "$ROOT" ] || log_pkg Reconfigured
2764 else
2765 newline
2766 _ 'Nothing to do for package "%s".' $PACKAGE
2767 fi
2768 else
2769 newline
2770 _ 'Package "%s" is not installed.' $PACKAGE
2771 _ 'Install package with "%s" or "%s"' 'tazpkg install' 'tazpkg get-install'
2772 newline
2773 fi ;;
2776 shell)
2777 # TazPKG SHell
2778 if test $(id -u) = 0 ; then
2779 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2780 else
2781 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2782 fi
2783 if [ ! "$2" = "--noheader" ]; then
2784 clear
2785 title 'TazPKG SHell.'
2786 _ "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
2787 newline
2788 fi
2789 while true; do
2790 echo -en "$PROMPT"; read cmd
2791 case $cmd in
2792 q|quit)
2793 break ;;
2794 shell)
2795 _ 'You are already running a TazPKG SHell.' ;;
2796 su)
2797 su -c 'exec tazpkg shell --noheader' && break ;;
2798 "")
2799 continue ;;
2800 *)
2801 tazpkg $cmd ;;
2802 esac
2803 done ;;
2806 depends)
2807 # Display dependencies tree
2808 cd $INSTALLED
2809 ALL_DEPS=""
2810 if [ -f $2/receipt ]; then
2811 dep_scan $2 ""
2812 fi ;;
2815 rdepends)
2816 # Display reverse dependencies tree
2817 cd $INSTALLED
2818 ALL_DEPS=""
2819 if [ -f $2/receipt ]; then
2820 rdep_scan $2
2821 fi ;;
2824 list-suggested)
2825 for i in $(ls -d $INSTALLED/*); do
2826 . $i/receipt
2827 if [ "$SUGGESTED" ]; then
2828 if [ -z "$all" ]; then
2829 for s in $SUGGESTED; do
2830 [ -d $INSTALLED/$s ] && \
2831 SUGGESTED=$(echo -n $SUGGESTED | sed "s/$s//")
2832 done
2833 fi
2834 cat << EOT
2835 $(boldify $(echo $PACKAGE):) $SUGGESTED
2836 EOT
2837 fi
2838 SUGGESTED=""
2839 done ;;
2842 convert|-c)
2843 # convert misc package format to .tazpkg
2844 check_for_package_file
2845 tazpkg-convert $@
2846 ;;
2849 link)
2850 # link a package from another slitaz installation
2851 PACKAGE=$2
2852 if [ ! -d "$TARGET_DIR" -o \
2853 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
2854 _ 'Usage: tazpkg link package_name slitaz_root'
2855 longline "$(
2856 _n 'Example:'
2857 echo -n ' '
2858 _ '"%s" will use less than 100k in your running system RAM.' \
2859 'tazpkg link openoffice /mnt')"
2860 exit 1
2861 fi
2862 if [ -e "$INSTALLED/$PACKAGE" ]; then
2863 _ 'Package "%s" is already installed.' $PACKAGE
2864 exit 1
2865 fi
2866 ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
2867 DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
2868 MISSING=""
2869 for i in $DEPENDS; do
2870 [ -e $INSTALLED/$i ] && continue
2871 MISSING="$MISSING$i "
2872 _ 'Missing: %s' $i
2873 done
2874 if [ -n "$MISSING" ]; then
2875 newline
2876 confirm "$(_ 'Link all missing dependencies? (y/N)')"
2877 answer=$?
2878 newline
2879 if [ $answer = 0 ]; then
2880 for i in $MISSING; do
2881 tazpkg link $i $TARGET_DIR
2882 done
2883 else
2884 newline
2885 _ 'Leaving dependencies unresolved for package "%s"' $PACKAGE
2886 _ 'The package is installed but probably will not work.'
2887 newline
2888 fi
2889 fi
2890 . $INSTALLED/$PACKAGE/receipt
2891 if grep -q ^pre_install $INSTALLED/$PACKAGE/receipt; then
2892 pre_install
2893 fi
2894 while read path; do
2895 [ -e $path ] && continue
2896 while true; do
2897 dir=$(dirname $path)
2898 [ -e $dir ] && break
2899 path=$dir
2900 done
2901 ln -s $TARGET_DIR$path $dir
2902 done < $INSTALLED/$PACKAGE/files.list
2903 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
2904 post_install
2905 fi ;;
2908 usage|*)
2909 # Print a short help or give usage for an unknown or empty command.
2910 usage ;;
2911 esac
2913 exit 0