tazpkg view tazpkg @ rev 711

tazpkg: 'desc' shows description or short description.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Dec 15 04:00:54 2014 +0200 (2014-12-15)
parents 58f001f8e2bc
children 68b77b7f356c
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
788 if [ -n "$CONFIG_FILES" ] && ! [ "$newconf" ]; then
789 # save 'official' configuration files
790 action 'Saving configuration files...'
791 for i in $CONFIG_FILES; do
792 { cd fs ; find ${i#/} -type f 2> /dev/null; cd ..; }
793 done | { cd fs ; cpio -o -H newc --quiet | gzip -9; cd ..; } > \
794 $ROOT$INSTALLED/$PACKAGE/volatile.cpio.gz
796 # keep user configuration files
797 for i in $CONFIG_FILES; do
798 { cd fs ; find ${i#/} -type f 2> /dev/null; cd ..; }
799 done | while read i; do
800 [ -e $ROOT/$i ] || continue
801 cp -a $ROOT/$i fs/$i
802 done
803 status
804 fi
806 action 'Installing package...'
807 [ "$(busybox ls fs/* 2> /dev/null)" ] && cp -a fs/* $ROOT/
808 status
810 if [ -s files2remove.list ]; then
811 action 'Removing old package...'
812 while read file; do
813 remove_with_path $ROOT$file
814 done < files2remove.list
815 true
816 status
817 fi
819 # Remove the temporary random directory.
820 action "Removing all tmp files..."
821 cd ..; rm -rf $TMP_DIR
822 status
824 # Post install commands.
825 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
826 post_install $ROOT
827 fi
829 # Update-desktop-database if needed.
830 if [ "$(fgrep .desktop $ROOT$INSTALLED/$PACKAGE/files.list | fgrep /usr/share/applications/)" ]; then
831 updatedesktopdb=yes
832 fi
834 # Update-mime-database if needed.
835 if [ "$(fgrep /usr/share/mime $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
836 updatemimedb=yes
837 fi
839 # Update-icon-database
840 if [ "$(fgrep /usr/share/icon/hicolor $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
841 updateicondb=yes
842 fi
844 # Compile glib schemas if needed.
845 if [ "$(fgrep /usr/share/glib-2.0/schemas $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
846 compile_schemas=yes
847 fi
849 # Update depmod list
850 if [ "$(fgrep /lib/modules $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
851 updatedepmod=yes
852 fi
854 # Update installed.info
855 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
856 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
857 II=$PKGS_DB/installed.info
858 sed -i "/^$PACKAGE /d" $II # remove old entry
859 cat >> $II << EOT
860 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS
861 EOT
862 TEMP_FILE=$(mktemp)
863 sort $II > $TEMP_FILE; mv -f $TEMP_FILE $II; chmod a+r $II; unset II
865 cd $TOP_DIR
866 footer "$(_ 'Package "%s" (%s) is installed.' $PACKAGE $VERSION$EXTRAVERSION)"
868 # Log this activity
869 [ -n "$ROOT" ] || log_pkg Installed
870 }
873 # This function may be called by a get script.
875 abort_package()
876 {
877 cd $CUR_DIR
878 rm -rf $TMP_DIR
879 echo "${1:-Abort $PACKAGE.}"
880 exit 1
881 }
884 # This function installs a package from a get script in the rootfs.
886 install_package_from_get_script()
887 {
888 SCRIPT="$1"
889 ROOT="$2"
890 [ -d $ROOT$INSTALLED/$PACKAGE ] && exit 1
892 grep -q no-check-certificate $SCRIPT &&
893 [ ! -d $INSTALLED/wget ] && tazpkg get-install wget
895 mkdir -p $TMP_DIR && cd $TMP_DIR
896 saved=$PACKAGE
897 unset_receipt
898 PACKAGE=$saved
900 set -e
901 . $SCRIPT
902 set +e
903 cd $TMP_DIR
904 [ -d $PACKAGE-$VERSION ] || abort_package \
905 "$(_ 'Could not download "%s" from "%s". Exiting.' ${TARBALL:-$PACKAGE} ${WGET_URL:-$WEB_SITE})"
907 if [ ! -s $PACKAGE-$VERSION/receipt ]; then
908 cat > $PACKAGE-$VERSION/receipt <<EOT
909 # SliTaz package receipt.
911 PACKAGE="$PACKAGE"
912 VERSION="${VERSION:-unknown}"
913 CATEGORY="${CATEGORY:-non-free}"
914 WEB_SITE="$WEB_SITE"
915 SHORT_DESC="${SHORT_DESC:-$PACKAGE}"
916 MAINTAINER="${MAINTAINER:-nobody@slitaz.org}"
917 EOT
918 for i in LICENSE TARBALL WGET_URL CONFIG_FILES SUGGESTED \
919 PROVIDE DEPENDS HOST_ARCH TAGS EXTRA_SOURCE_FILES ; do
920 eval "[ -n \"\$$i\" ] && echo \"$i=\\\"\$$i\\\"\""
921 done >> $PACKAGE-$VERSION/receipt
922 fi
924 DEPENDS="$(unset DEPENDS; . $PACKAGE-$VERSION/receipt ; echo $DEPENDS)"
925 for i in $(find_depends $PACKAGE-$VERSION/fs); do
926 case " $DEPENDS " in
927 *\ $i\ *) continue;;
928 esac
929 grep -q '^DEPENDS="' $PACKAGE-$VERSION/receipt ||
930 echo 'DEPENDS=""' >> $PACKAGE-$VERSION/receipt
931 sed -i "s/^DEPENDS=\"/&$i /" $PACKAGE-$VERSION/receipt
932 done
934 tazpkg pack $PACKAGE-$VERSION
936 # Clean to save RAM memory before installation
937 rm -rf $PACKAGE-$VERSION
939 # Install pseudo package
940 tazpkg install $PACKAGE-$VERSION.tazpkg --root=$ROOT
941 mv $PACKAGE-$VERSION.tazpkg $CACHE_DIR
943 # Clean
944 cd $TOP_DIR
945 rm -rf $TMP_DIR
946 }
949 # Check for loop in deps tree.
951 check_for_deps_loop()
952 {
953 local list
954 local pkg
955 local deps
956 pkg=$1
957 shift
958 [ -n "$1" ] || return
959 list=""
961 # Filter out already processed deps
962 for i in $@; do
963 case " $ALL_DEPS" in
964 *\ $i\ *) ;;
965 *) list="$list $i";;
966 esac
967 done
968 ALL_DEPS="$ALL_DEPS$list "
969 for i in $list; do
970 [ -f $i/receipt ] || continue
971 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
972 case " $deps " in
973 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
974 *) check_for_deps_loop $pkg $deps;;
975 esac
976 done
977 }
980 # Check for missing deps listed in a receipt packages.
982 check_for_deps()
983 {
984 local saved;
985 saved=$PACKAGE
986 mkdir -p $TMP_DIR
987 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
988 . $TMP_DIR/receipt
989 PACKAGE=$saved
990 rm -rf $TMP_DIR
992 num=0
993 for pkgorg in $DEPENDS; do
994 i=$(equivalent_pkg $pkgorg $1)
995 if [ ! -d "$1$INSTALLED/$i" ]; then
996 MISSING_PACKAGE=$i
997 num=$(($num+1))
998 elif [ ! -f "$1$INSTALLED/$i/receipt" ]; then
999 _ 'WARNING! Dependency loop between "%s" and "%s".' $PACKAGE $i
1000 fi
1001 done
1003 if [ -n "$MISSING_PACKAGE" ]; then
1004 title "$(_ 'Tracking dependencies for package "%s"' $PACKAGE)"
1005 for pkgorg in $DEPENDS; do
1006 i=$(equivalent_pkg $pkgorg $1)
1007 if [ ! -d "$1$INSTALLED/$i" ]; then
1008 MISSING_PACKAGE=$i
1009 _ 'Missing package "%s"' $MISSING_PACKAGE
1010 fi
1011 done
1012 footer "$(_p \
1013 '%s missing package to install.' \
1014 '%s missing packages to install.' $num \
1015 $num)"
1016 fi
1020 # Install all missing deps. Auto install or ask user then install all missing
1021 # deps from local dir, cdrom, media or from the mirror. In case we want to
1022 # install packages from local, we need a packages.list to find the version.
1024 install_deps()
1026 local root
1027 root=""
1028 [ -n "$1" ] && root="--root=$1"
1029 if [ "$AUTO_INSTALL_DEPS" == "yes" ]; then
1030 answer=0
1031 else
1032 newline
1033 confirm "$(_ 'Install all missing dependencies? (y/N)')"
1034 answer=$?
1035 newline
1036 fi
1037 if [ $answer = 0 ] && ! [ "$nodeps" ]; then
1038 for pkgorg in $DEPENDS; do
1039 pkg=$(equivalent_pkg $pkgorg $1)
1040 if [ ! -d "$1$INSTALLED/$pkg" ]; then
1041 local list
1042 list="$INSTALL_LIST"
1043 [ -n "$list" ] || list="$TOP_DIR/packages.list"
1044 # We can install packages from a local dir by greping
1045 # the TAZPKG_BASENAME in the local packages.list.
1046 found=0
1047 if [ -f "$list" ]; then
1048 _ 'Checking if package "%s" exists in local list...' $pkg
1049 mkdir $TMP_DIR
1050 for i in $pkg-*.tazpkg; do
1051 [ -f $i ] || continue
1052 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $i
1053 [ "$(. $TMP_DIR/receipt; echo $PACKAGE)" = "$pkg" ] || continue
1054 if grep -q ^$(package_fullname_in_dir $TMP_DIR).tazpkg$ $list
1055 then
1056 found=1
1057 tazpkg install $i $root --list=$list
1058 break
1059 fi
1060 done
1061 rm -rf $TMP_DIR
1062 fi
1063 # Install deps from the mirror.
1064 if [ $found -eq 0 ]; then
1065 if [ ! -f "$PKGS_DB/packages.list" ]; then
1066 tazpkg recharge
1067 fi
1068 tazpkg get-install $pkg $root
1069 fi
1070 fi
1071 done
1072 else
1073 newline
1074 _ 'Leaving dependencies for package "%s" unresolved.' $PACKAGE
1075 _ 'The package is installed but will probably not work.'
1076 newline
1077 fi
1081 # Search pattern in installed packages.
1083 search_in_installed_packages()
1085 _ 'Installed packages'
1086 separator
1087 num=0
1088 for pkg in $(ls -1 $INSTALLED | grep -i "$PATTERN"); do
1089 EXTRAVERSION=""
1090 [ -f $INSTALLED/$pkg/receipt ] || continue
1091 . $INSTALLED/$pkg/receipt
1092 emsg "$PACKAGE<i 24> $VERSION$EXTRAVERSION<i 42> $(_n $CATEGORY)"
1093 num=$(($num+1))
1094 done
1096 footer "$(_p \
1097 '%s installed package found for "%s"' \
1098 '%s installed packages found for "%s"' $num \
1099 $num "$PATTERN")"
1103 # Search in packages.list for available pkgs.
1105 search_in_packages_list()
1107 _ 'Available packages'
1108 separator
1109 num=0
1110 BPATTERN="$(emsg "<b>$PATTERN</b>")"
1111 for i in $PKGS_DB/packages.list $PKGS_DB/undigest/*/packages.list; do
1112 grep -is "$PATTERN" $i | sed "s|$PATTERN|$BPATTERN|"
1113 num=$(($num + `grep -is "$PATTERN" $i | wc -l`))
1114 done
1115 if [ ! -f "$PKGS_DB/packages.list" ]; then
1116 newline
1117 longline "$(_ \
1118 "No \"%s\" found to check for mirrored packages. For more results, please run \
1119 \"%s\" once as root before searching." packages.list 'tazpkg recharge')"
1120 newline
1121 fi
1122 footer "$(_p \
1123 '%s available package found for "%s"' \
1124 '%s available packages found for "%s"' $num \
1125 $num $PATTERN)"
1129 # search --mirror: Search in packages.txt for available pkgs and give more
1130 # info than --list or default.
1132 search_in_packages_txt()
1134 _ 'Matching packages name with version and desc'
1135 separator
1136 num=0
1137 for i in $PKGS_DB/packages.txt $PKGS_DB/undigest/*/packages.txt; do
1138 grep -is -A 2 "^$PATTERN" $i
1139 num=$(($num + `grep -is "^$PATTERN" $i | wc -l`))
1140 done
1141 if [ ! -f "$PKGS_DB/packages.txt" ]; then
1142 newline
1143 longline "$(_ \
1144 "No \"%s\" found to check for mirrored packages. For more results, please run \
1145 \"%s\" once as root before searching." packages.txt 'tazpkg recharge')"
1146 newline
1147 fi
1148 footer "$(_p \
1149 '%s available package found for "%s"' \
1150 '%s available packages found for "%s"' $num \
1151 $num $PATTERN)"
1155 # Install package-list from a flavor
1157 install_flavor()
1159 check_root $@
1161 # Get repositories priority list.
1162 look_for_priority
1164 FLAVOR=$1
1165 ARG=$2
1166 mkdir -p $TMP_DIR
1167 [ -f $FLAVOR.flavor ] && cp $FLAVOR.flavor $TMP_DIR
1168 cd $TMP_DIR
1169 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1170 zcat < $FLAVOR.flavor | cpio --quiet -i >/dev/null
1172 while read file; do
1173 for pkg in $(ls -d $INSTALLED/${file%%-*}*); do
1174 [ -f $pkg/receipt ] || continue
1175 EXTRAVERSION=""
1176 . $pkg/receipt
1177 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && break
1178 done
1179 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && continue
1180 cd $CACHE_DIR
1181 download $file.tazpkg
1182 cd $TMP_DIR
1183 tazpkg install $CACHE_DIR/$file.tazpkg --forced
1184 done < $FLAVOR.pkglist
1186 [ -f $FLAVOR.nonfree ] && while read pkg; do
1187 [ -d $INSTALLED/$pkg ] || continue
1188 [ -d $INSTALLED/get-$pkg ] && tazpkg get-install get-$pkg
1189 get-$pkg
1190 done < $FLAVOR.nonfree
1192 [ "$ARG" == "--purge" ] && for pkg in $(ls $INSTALLED); do
1193 [ -f $INSTALLED/$pkg/receipt ] || continue
1194 EXTRAVERSION=""
1195 . $INSTALLED/$pkg/receipt
1196 grep -q ^$PACKAGE-$VERSION$EXTRAVERSION$ $FLAVOR.pkglist && continue
1197 grep -qs ^$PACKAGE$ $FLAVOR.nonfree && continue
1198 tazpkg remove $PACKAGE
1199 done
1200 else
1201 _ "Can't find flavor \"%s\". Abort." $FLAVOR
1202 fi
1203 cd $TOP_DIR
1204 rm -rf $TMP_DIR
1208 # Update mirror urls
1210 setup_mirror()
1212 # Backup old list.
1213 if [ -f "$1/mirror" ]; then
1214 cp -f $1/mirror $1/mirror.bak
1215 fi
1216 title 'Current mirror(s)'
1217 echo " `cat $1/mirror 2> /dev/null`"
1218 longline "$(_ \
1219 "Please enter URL of the new mirror (http, ftp or local path). You must specify \
1220 the complete address to the directory of the packages and packages.list file.")"
1221 newline
1222 _n 'New mirror(s) URL: '
1223 NEW_MIRROR_URL=$2
1224 if [ -n "$NEW_MIRROR_URL" ]; then
1225 echo $NEW_MIRROR_URL
1226 else
1227 read NEW_MIRROR_URL
1228 fi
1229 if [ "$NEW_MIRROR_URL" = "" ]; then
1230 _ 'Nothing has been changed.'
1231 else
1232 _ 'Setting mirror(s) to: "%s"' $NEW_MIRROR_URL
1233 rm -f $1/mirror
1234 for i in $NEW_MIRROR_URL; do
1235 echo "${i%/}/" >> $1/mirror
1236 done
1237 fi
1238 newline
1242 # recursive dependencies scan
1244 dep_scan()
1246 for i in $1; do
1247 case " $ALL_DEPS " in
1248 *\ $i\ *) continue;;
1249 esac
1250 ALL_DEPS="$ALL_DEPS $i"
1251 [ -n "$2" ] && echo "$2$i ($(fgrep -A 3 $i $PKGS_DB/packages.txt | \
1252 tail -1 | sed 's/.*(\([^ ]*\).*/\1/'))"
1253 [ -f $i/receipt ] || continue
1254 DEPENDS=""
1255 . $i/receipt
1256 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
1257 done
1261 # recursive reverse dependencies scan
1263 rdep_scan()
1265 SEARCH=$1
1267 for i in * ; do
1268 DEPENDS=""
1269 . $i/receipt
1270 echo "$i $(echo $DEPENDS)"
1271 done | busybox awk -v search=$SEARCH '
1272 function show_deps(deps, all_deps, pkg, space)
1274 if (all_deps[pkg] == 1) return
1275 all_deps[pkg] = 1
1276 if (space != "") printf "%s %s\n",space,pkg
1277 for (i = 1, n = split(deps[pkg], mydeps, " "); i <= n; i++) {
1278 show_deps(deps, all_deps, mydeps[i],"==" space)
1283 all_deps[$1] = 0
1284 for (i = 2; i <= NF; i++)
1285 deps[$i] = deps[$i] " " $1
1288 END {
1289 show_deps(deps, all_deps, search, "")
1291 ' | while read spc pkg; do
1292 echo -n $spc | sed 's/=/ /g'
1293 echo -n $pkg
1294 echo -n ' ('
1295 fgrep -A 3 $pkg $PKGS_DB/packages.txt | tail -1 | \
1296 sed 's/.*(\([^ ]*\).*/\1)/'
1297 done
1301 update_desktop_database()
1303 if [ -f $1/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
1304 chroot "$1/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
1305 fi
1309 update_mime_database()
1311 if [ -f $1/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
1312 chroot "$1/" /usr/bin/update-mime-database /usr/share/mime
1313 fi
1317 update_icon_database()
1319 if [ -f $1/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
1320 chroot "$1/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
1321 fi
1325 compile_glib_schemas()
1327 if [ -f $1/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
1328 chroot "$1/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
1329 fi
1333 update_kernel_modules()
1335 if [ -f $1/sbin/depmod ] && [ -n "$updatedepmod" ]; then
1336 chroot "$1/" /sbin/depmod -a
1337 fi
1344 ###################
1345 # TazPKG commands #
1346 ###################
1348 case "$COMMAND" in
1349 list|-l)
1350 # List all installed packages or a specific category.
1351 shift
1352 check_for_installed_info
1354 case $1 in
1355 b|blocked)
1356 # Display the list of blocked packages.
1357 title 'Blocked packages'
1358 if [ -s "$BLOCKED" ];then
1359 cat $BLOCKED
1360 else
1361 _ 'No blocked packages found.'
1362 fi
1363 newline; exit 0
1364 ;;
1365 c|cat|categories)
1366 # Display the list of categories.
1367 title 'Packages categories'
1368 echo "$PKGS_CATEGORIES" | sed 's|[^a-z-]|\n|g; /^$/d' | \
1369 sed 's|\(.*\)|\1'$'\033''[15G \1|' | translate_category
1370 num=$(echo -n "$PKGS_CATEGORIES" | wc -l)
1371 footer "$(_p \
1372 '%s category' \
1373 '%s categories' $num \
1374 $num)"
1375 exit 0
1376 ;;
1377 '')
1378 # By default list all packages and versions.
1379 title 'List of all installed packages'
1380 TMPLIST=$(mktemp)
1381 awk -F$'\t' '{print $1"\033[35G "$2"\033[53G "$3}' \
1382 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
1384 packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST
1385 footer "$(emsg $(_p \
1386 '%s package installed.' \
1387 '%s packages installed.' $packages \
1388 "<c 32>$packages</c>"))"
1389 ;;
1390 *)
1391 # Check for an asked category.
1392 ASKED_CATEGORY_I18N="$@"
1393 ASKED_CATEGORY=$(reverse_translate_category "$ASKED_CATEGORY_I18N")
1394 title 'Installed packages of category "%s"' $ASKED_CATEGORY_I18N
1395 TMPLIST=$(mktemp)
1396 awk -F$'\t' '
1398 if ($3 == "'$ASKED_CATEGORY'")
1399 print $1"\033[35G "$2
1400 }' \
1401 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
1403 packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST
1404 footer "$(emsg $(_p \
1405 '%s package installed of category "%s".' \
1406 '%s packages installed of category "%s".' $packages \
1407 "<c 32>$packages</c>" "<c 34>$ASKED_CATEGORY_I18N</c>"))"
1408 ;;
1409 esac ;;
1411 list-mirror|-lm)
1412 # List all available packages on the mirror. Option --diff displays
1413 # last mirrored packages diff (see recharge).
1414 check_for_packages_list
1415 case $2 in
1416 --diff)
1417 if [ -f "$PKGS_DB/packages.diff" ]; then
1418 title 'Mirrored packages diff'
1419 cat $PKGS_DB/packages.diff
1420 num=$(wc -l < $PKGS_DB/packages.diff)
1421 footer "$(_p \
1422 '%s new package listed on the mirror.' \
1423 '%s new packages listed on the mirror.' $num \
1424 $num)"
1425 else
1426 newline
1427 _ 'Unable to list anything, no packages.diff found.'
1428 _ 'Recharge your current list to create a first diff.'
1429 newline
1430 fi; exit 0 ;;
1431 --text|--txt|--raw|*)
1432 title 'List of available packages on the mirror'
1433 cat $PKGS_DB/packages.txt ;;
1434 esac
1435 pkgs=$(wc -l < $PKGS_DB/packages.list)
1436 footer "$(emsg "$(_p \
1437 '%s package in the last recharged list.' \
1438 '%s packages in the last recharged list.' $pkgs \
1439 "<c 32>$pkgs</c>")")"
1440 ;;
1443 list-files|-lf)
1444 # List files installed with the package.
1445 check_for_package_on_cmdline
1446 check_for_receipt
1447 title 'Installed files by "%s"' $PACKAGE
1448 sort < $INSTALLED/$PACKAGE/files.list
1449 files=$(wc -l < $INSTALLED/$PACKAGE/files.list)
1450 footer "$(emsg "$(_p \
1451 '%s file' '%s files' $files \
1452 "<c 32>$files</c>")")"
1453 ;;
1456 info)
1457 # Information about package.
1458 check_for_package_on_cmdline
1459 check_for_receipt
1460 EXTRAVERSION=""
1461 . $INSTALLED/$PACKAGE/receipt
1462 title 'TazPKG information'
1463 # Display localized short description
1464 for LC in $LANG ${LANG%_*}; do
1465 if [ -e "$PKGS_DB/packages-desc.$LC" ]; then
1466 LOCDESC=$(grep -e "^$PACKAGE " $PKGS_DB/packages-desc.$LC | cut -d' ' -f2)
1467 [ -n "$LOCDESC" ] && SHORT_DESC="$LOCDESC"
1468 fi
1469 done
1470 emsg "$(
1472 _ 'Package : %s' "$PACKAGE"
1473 _ 'Version : %s' "$VERSION$EXTRAVERSION"
1474 _ 'Category : %s' "$(_ $CATEGORY)"
1475 _ 'Short desc : %s' "$SHORT_DESC"
1476 _ 'Maintainer : %s' "$MAINTAINER"
1477 _ 'License : %s' "$LICENSE"
1478 _ 'Depends : %s' "$DEPENDS"
1479 _ 'Suggested : %s' "$SUGGESTED"
1480 _ 'Build deps : %s' "$BUILD_DEPENDS"
1481 _ 'Wanted src : %s' "$WANTED"
1482 _ 'Web site : %s' "$WEB_SITE"
1483 _ 'Tags : %s' "$TAGS"
1484 } | sed '/: $/d; s|^\([^:]*\):|<b>\1:</b>|')"
1485 footer ;;
1488 desc)
1489 # Display package description.txt if available.
1490 if [ -n "$(grep -e "^$PACKAGE " $PKGS_DB/installed.info)" ]; then
1491 title 'Description of package "%s"' $PACKAGE
1492 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
1493 cat $INSTALLED/$PACKAGE/description.txt
1494 else
1495 awk -F$'\t' '{if ($1 == "'$PACKAGE'") print $4}' $PKGS_DB/installed.info
1496 fi
1497 footer
1498 else
1499 _ 'Package "%s" is not installed.' "$PACKAGE"
1500 fi
1501 ;;
1504 activity|log|-a)
1505 # Show activity log
1506 [ "$nb" ] || nb=18
1507 title 'TazPKG Activity'
1508 IFS=" "
1509 tail -n ${nb} ${LOG} | \
1510 while read date hour none action none pkg vers none; do
1511 case $action in
1512 Installed)
1513 action=$(colorize 32 $action) ;;
1514 Removed)
1515 action=$(colorize 31 $action) ;;
1516 *)
1517 action=$(boldify $action) ;;
1518 esac
1519 echo "$date $hour : $action $pkg $vers"
1520 done
1521 unset IFS
1522 footer ;;
1525 search|-s)
1526 # Search for a package by pattern or name.
1527 PATTERN="$2"
1528 if [ -z "$PATTERN" ]; then
1529 newline
1530 _ 'Please specify a pattern or package name to search for.'
1531 echo "$(_ 'Example:') 'tazpkg search paint'"
1532 newline
1533 exit 0
1534 fi
1535 title 'Search result for "%s"' $PATTERN
1536 # Default is to search in installed pkgs and the raw list.
1537 case "$3" in
1538 -i|--installed)
1539 search_in_installed_packages ;;
1540 -l|--list)
1541 search_in_packages_list ;;
1542 -m|--mirror)
1543 search_in_packages_txt ;;
1544 *)
1545 search_in_installed_packages
1546 search_in_packages_list ;;
1547 esac ;;
1550 search-file|-sf)
1551 # Search for a file by pattern or name in all files.list.
1552 if [ -z "$2" ]; then
1553 newline
1554 _ 'Please specify a pattern or file name to search for.'
1555 echo "$(_ 'Example:') 'tazpkg search-file libnss'"
1556 newline
1557 exit 0
1558 fi
1559 title 'Search result for file "%s"' $2
1561 TMPLIST=$(mktemp)
1562 if [ "$3" == "--mirror" ]; then
1564 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1565 [ -f $i ] || continue
1566 lzcat $i | awk -F: -vP="$(gettext 'Package %s:')" -vT=$TMPLIST '
1567 BEGIN { last = "" }
1568 $2 ~ /'$2'/ {
1569 if (last != $1) {
1570 last = $1;
1571 PP = P;
1572 sub(/%s/, $1, PP);
1573 printf("\n\e[1;33m%s\e[0;39m\n", PP);
1575 gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $2);
1576 print $2;
1577 printf "%s" 1 >> T;
1578 }'
1579 done
1581 else
1583 # Check all pkg files.list in search match which specify the package
1584 # name and the full path to the file(s).
1585 for pkg in $INSTALLED/*; do
1586 if grep -qs "$2" $pkg/files.list; then
1587 . $pkg/receipt
1588 newline
1589 emsg "<c 33>$(_ 'Package %s:' $PACKAGE)</c>"
1590 awk -vT=$TMPLIST '
1591 /'$2'/ {
1592 gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $0);
1593 print " "$0;
1594 printf "%s" 1 >> T;
1596 ' $pkg/files.list
1597 fi
1598 done
1600 fi
1602 match=$(wc -m < $TMPLIST)
1603 rm $TMPLIST
1605 footer "$(emsg "$(_p \
1606 '%s file' '%s files' $match \
1607 "<c 32>$match</c>")")"
1608 ;;
1611 search-pkgname)
1612 # Search for a package name
1613 if [ -z "$2" ]; then
1614 newline
1615 _ 'Please specify a pattern or file name to search for.'
1616 echo "$(_ 'Example:') 'tazpkg search-pkgname libnss'"
1617 newline
1618 exit 0
1619 fi
1620 title 'Search result for package "%s"' $2
1622 # Search for a file on mirror and output only the package name
1623 TMPLIST=$(mktemp)
1624 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1625 [ -f $i ] || continue
1626 lzcat $i | awk -F: -vT=$TMPLIST '
1627 BEGIN { P = "" }
1628 $2 ~ /'$2'/ {
1629 if ($1 != P) {
1630 print $1;
1631 printf "%s" 1 >> T;
1632 P = $1
1634 }'
1635 done
1636 match=$(wc -m < $TMPLIST)
1637 rm $TMPLIST
1639 footer "$(emsg "$(_p \
1640 '%s package' '%s packages' $match \
1641 "<c 32>$match</c>")")"
1642 ;;
1645 install|-i)
1646 # Install .tazpkg packages.
1647 check_root $@
1648 check_for_package_on_cmdline
1649 check_for_package_file
1650 check_for_installed_info
1652 if [ -n "$root" ]; then
1653 ROOT="$root";
1654 check_base_dir "$root"
1655 fi
1656 [ "$list" ] && INSTALL_LIST="$list"
1657 if [ "$rootconfig" ]; then
1658 if [ "$root" ]; then
1659 CACHE_DIR=$root/$CACHE_DIR
1660 SAVE_CACHE_DIR=$CACHE_DIR
1661 PKGS_DB=$root/$PKGS_DB
1662 else
1663 echo "rootconfig needs --root= option used." >&2
1664 exit 1
1665 fi
1666 fi
1668 # Get repositories priority list.
1669 look_for_priority
1671 # Check if forced install.
1672 if [ -z "$forced" ]; then
1673 check_for_installed_package $ROOT
1674 fi
1675 install_package $ROOT
1676 update_desktop_database $ROOT
1677 update_mime_database $ROOT
1678 update_icon_database $ROOT
1679 compile_glib_schemas $ROOT
1680 ;;
1683 install-list|get-install-list)
1684 # Install a set of packages from a list.
1685 check_root $@
1686 if [ -z "$2" ]; then
1687 newline
1688 longline "$(_ \
1689 "Please change directory (cd) to the packages repository and specify the \
1690 list of packages to install.")"
1691 echo "$(_ 'Example:') $(emsg '<b>tazpkg install-list</b> <c 33>packages.list</c>')"
1692 exit 0
1693 fi
1695 # Check if the packages list exist.
1696 if [ ! -f "$2" ]; then
1697 _ 'Unable to find list "%s"' "$2"
1698 exit 0
1699 fi
1701 LIST=$(cat $2)
1703 # Remember processed list
1704 export INSTALL_LIST="$2"
1706 # Set $COMMAND and install all packages.
1707 COMMAND=${1%-list}
1709 touch $2-processed
1711 # Upgrade tazpkg first. It may handle new features/formats...
1712 # then upgrade essential packages early
1713 for pkg in busybox-pam busybox gcc-lib-base glibc-base \
1714 slitaz-base-files tazpkg ; do
1715 pkg=$(egrep $pkg-[0-9] $INSTALL_LIST)
1716 [ -z "$pkg" ] && continue
1717 _ 'Adding implicit depends "%s"...' $pkg
1718 LIST="$pkg
1719 $LIST"
1720 done
1722 for pkg in $LIST; do
1723 grep -qs ^$pkg$ $2-processed && continue
1724 [ -d "$root/var/lib/tazpkg/installed" ] && continue
1725 tazpkg $COMMAND $pkg --list="$2" "$3" "$4" "$5"
1726 done
1727 rm -f $2-processed ;;
1730 add-flavor)
1731 # Install a set of packages from a flavor.
1732 install_flavor $2 ;;
1735 install-flavor)
1736 # Install a set of packages from a flavor and purge other ones.
1737 install_flavor $2 --purge ;;
1740 set-release)
1741 # Change current release and upgrade packages.
1742 RELEASE=$2
1743 if [ -z "$RELEASE" ]; then
1744 newline
1745 _ 'Please specify the release you want on the command line.'
1746 echo "$(_ 'Example:') tazpkg set-release cooking"
1747 newline
1748 exit 0
1749 fi
1750 rm $PKGS_DB/mirror
1751 echo "$RELEASE" > /etc/slitaz-release
1752 tazpkg recharge && tazpkg upgrade
1754 # Install missing depends
1755 cd $INSTALLED
1756 for i in * ; do
1757 DEPENDS=""
1758 . $i/receipt
1759 for j in $DEPENDS ; do
1760 [ -d $j ] || tazpkg get-install $j
1761 done
1762 done ;;
1765 remove|-r)
1766 # Remove packages.
1767 check_root $@
1768 check_for_package_on_cmdline
1769 check_for_installed_info
1771 [ -n "$root" ] && ROOT="$root"
1772 if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then
1773 newline
1774 _ 'Package "%s" is not installed.' $PACKAGE
1775 exit 0
1776 else
1777 ALTERED=""
1778 THE_PACKAGE=$PACKAGE # altered by receipt
1779 for i in $(cd $ROOT$INSTALLED ; ls); do
1780 [ -f $ROOT$INSTALLED/$i/receipt ] || continue
1781 DEPENDS=""
1782 . $ROOT$INSTALLED/$i/receipt
1783 case " $(echo $DEPENDS) " in
1784 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
1785 esac
1786 done
1787 EXTRAVERSION=""
1788 . $ROOT$INSTALLED/$THE_PACKAGE/receipt
1789 fi
1790 newline
1791 if [ -n "$ALTERED" ]; then
1792 _ 'The following packages depend on package "%s":' $PACKAGE
1793 for i in $ALTERED; do
1794 echo " $i"
1795 done
1796 fi
1797 REFRESH=$(cd $ROOT$INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1798 if [ -n "$REFRESH" ]; then
1799 _ 'The following packages have been modified by package "%s":' $PACKAGE
1800 for i in $REFRESH; do
1801 echo " ${i%/modifiers}"
1802 done
1803 fi
1804 if [ "$auto" ]; then
1805 answer=0
1806 else
1807 confirm "$(_ 'Remove package "%s" (%s)? (y/N)' $PACKAGE $VERSION$EXTRAVERSION)"
1808 answer=$?
1809 fi
1810 if [ $answer = 0 ]; then
1811 title 'Removing package "%s"' $PACKAGE
1812 # Pre remove commands.
1813 if grep -q ^pre_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1814 pre_remove $ROOT
1815 fi
1816 action "Removing all files installed..."
1817 if [ -f $ROOT$INSTALLED/$PACKAGE/modifiers ]; then
1818 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1819 for mod in $(cat $ROOT$INSTALLED/$PACKAGE/modifiers); do
1820 [ -f $ROOT$INSTALLED/$mod/files.list ] && [ $(grep "^$(echo $file | grepesc)$" $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && continue 2
1821 done
1822 remove_with_path $ROOT$file
1823 done
1824 else
1825 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1826 remove_with_path $ROOT$file
1827 done
1828 fi
1829 status
1830 if grep -q ^post_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1831 post_remove $ROOT
1832 fi
1834 # Remove package receipt.
1835 action "Removing package receipt..."
1836 rm -rf $ROOT$INSTALLED/$PACKAGE
1837 status
1839 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION$/d" \
1840 $PKGS_DB/installed.$SUM 2> /dev/null
1842 # Update installed.info
1843 sed -i "/^$PACKAGE /d" $PKGS_DB/installed.info
1845 # Log this activity
1846 log_pkg Removed
1848 if [ "$ALTERED" ]; then
1849 if [ "$auto" ]; then
1850 answer=0
1851 else
1852 confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' $PACKAGE)"
1853 answer=$?
1854 fi
1855 if [ $answer = 0 ]; then
1856 for i in $ALTERED; do
1857 if [ -d "$ROOT$INSTALLED/$i" ]; then
1858 tazpkg remove $i $ROOTOPTS
1859 fi
1860 done
1861 fi
1862 fi
1863 if [ "$REFRESH" ]; then
1864 if [ "$auto" ]; then
1865 answer=0
1866 else
1867 confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' $PACKAGE)"
1868 answer=$?
1869 fi
1870 if [ $answer = 0 ]; then
1871 for i in $REFRESH; do
1872 if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then
1873 _ 'Check %s for reinstallation' "$INSTALLED/$i"
1874 continue
1875 fi
1876 rm -r $ROOT$INSTALLED/$i
1877 tazpkg get-install ${i%/modifiers} $ROOTOPTS --forced
1878 done
1879 fi
1880 fi
1881 else
1882 newline
1883 _ 'Uninstallation of package "%s" cancelled.' $PACKAGE
1884 fi
1885 newline ;;
1888 extract|-e)
1889 # Extract .tazpkg cpio archive into a directory.
1890 check_for_package_on_cmdline
1891 check_for_package_file
1892 title 'Extracting package "%s"' $PACKAGE
1894 # If no directory destination is found on the cmdline
1895 # we create one in the current dir using the package name.
1896 if [ -n "$TARGET_DIR" ]; then
1897 DESTDIR=$TARGET_DIR/$PACKAGE
1898 else
1899 DESTDIR=$PACKAGE
1900 fi
1901 mkdir -p $DESTDIR
1903 action "Copying original package..."
1904 cp $PACKAGE_FILE $DESTDIR
1905 status
1907 cd $DESTDIR
1908 extract_package
1909 [ -e "receipt" ] && \
1910 footer "$(_ 'Package "%s" is extracted to "%s"') $PACKAGE $DESTDIR"
1911 ;;
1914 recompress)
1915 # Recompress .tazpkg cpio archive with lzma.
1916 check_for_package_on_cmdline
1917 check_for_package_file
1918 title 'Recompressing package "%s"' $PACKAGE
1919 mkdir -p $TMP_DIR
1921 action "Copying original package..."
1922 cp $PACKAGE_FILE $TMP_DIR
1923 status
1925 cd $TMP_DIR
1926 extract_package
1928 action "Recompressing the FS..."
1929 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1930 rm -rf fs
1931 status
1933 action "Creating new package..."
1934 find . -print | cpio -o -H newc --quiet > \
1935 $TOP_DIR/$(basename $PACKAGE_FILE).$$ && mv -f \
1936 $TOP_DIR/$(basename $PACKAGE_FILE).$$ \
1937 $TOP_DIR/$(basename $PACKAGE_FILE)
1938 status
1940 cd $TOP_DIR
1941 rm -rf $TMP_DIR
1942 separator; newline ;;
1945 list-config)
1946 # List configuration files installed.
1947 if [ "$2" = "--box" ]; then
1948 mkdir -p $TMP_DIR; cd $TMP_DIR
1949 FILES="$INSTALLED/*/volatile.cpio.gz"
1950 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
1951 for i in $FILES; do
1952 zcat $i | cpio -idm --quiet > /dev/null
1953 find * -type f 2>/dev/null | while read file; do
1954 if [ ! -e /$file ]; then
1955 echo -n "----------|----|----|$(_n 'File lost')"
1956 else
1957 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
1958 cmp $file /$file > /dev/null 2>&1 || \
1959 echo -n "$(stat -c "%.16y" /$file)"
1960 fi
1961 echo "|/$file"
1962 done
1963 rm -rf *
1964 done
1965 cd $TOP_DIR
1966 rm -rf $TMP_DIR
1967 else
1968 title 'Configuration files'
1969 for i in $INSTALLED/*/volatile.cpio.gz; do
1970 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
1971 [ -f "$i" ] || continue
1972 zcat $i | cpio -t --quiet
1973 done | sed 's|^|/|' | sort
1974 separator
1975 newline
1976 fi ;;
1979 repack-config)
1980 # Create SliTaz package archive from configuration files.
1981 mkdir -p $TMP_DIR; cd $TMP_DIR
1982 CONFIG_VERSION=1.0
1983 mkdir config-$CONFIG_VERSION
1984 cd config-$CONFIG_VERSION
1985 for i in $INSTALLED/*/volatile.cpio.gz; do
1986 zcat $i | cpio -t --quiet
1987 done > files.list
1988 mkdir fs
1989 cd fs
1990 ( cd / ; cpio -o -H newc --quiet ) < ../files.list | cpio -idm --quiet > /dev/null
1991 mkdir -p etc/tazlito
1992 for i in $INSTALLED/*/receipt; do
1993 EXTRAVERSION=""
1994 . $i
1995 echo "$PACKAGE-$VERSION$EXTRAVERSION"
1996 done > etc/tazlito/config-packages.list
1997 cd ..
1998 echo "etc/tazlito/config-packages.list" >> files.list
1999 pkg_date=$(date +"%x %X")
2000 cat > receipt <<EOT
2001 # SliTaz package receipt.
2003 PACKAGE="config"
2004 VERSION="$CONFIG_VERSION"
2005 CATEGORY="base-system"
2006 SHORT_DESC="$(_n 'User configuration backup on date %s' $pkg_date)"
2007 DEPENDS="$(ls $INSTALLED)"
2008 EOT
2009 cd ..
2010 tazpkg pack config-$CONFIG_VERSION
2011 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
2012 cd $TOP_DIR
2013 rm -rf $TMP_DIR
2014 ;;
2017 repack)
2018 # Create SliTaz package archive from an installed package.
2019 check_for_package_on_cmdline
2020 check_for_receipt
2021 EXTRAVERSION=""
2022 . $INSTALLED/$PACKAGE/receipt
2023 title 'Repacking "%s"' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
2025 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
2026 _ "Can't repack package \"%s\"" $PACKAGE
2027 exit 1
2028 fi
2030 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
2031 _ "Can't repack, \"%s\" files have been modified by:" $PACKAGE
2032 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
2033 echo " $i"
2034 done
2035 exit 1
2036 fi
2038 MISSING=""
2039 while read i; do
2040 [ -e "$i" ] && continue
2041 [ -L "$i" ] || MISSING="$MISSING\n $i"
2042 done < $INSTALLED/$PACKAGE/files.list
2043 if [ -n "$MISSING" ]; then
2044 _n "Can't repack, the following files are lost:"
2045 echo -e "$MISSING"
2046 exit 1
2047 fi
2049 mkdir -p $TMP_DIR; cd $TMP_DIR
2050 FILES="fs.cpio.lzma\n"
2051 for i in $(ls $INSTALLED/$PACKAGE); do
2052 case $i in
2053 volatile.cpio.gz|modifiers) ;;
2054 *) cp $INSTALLED/$PACKAGE/$i .; FILES="$FILES$i\n" ;;
2055 esac
2056 done
2058 ln -s / rootfs
2059 mkdir tmp
2060 sed 's/^/rootfs/' < files.list | cpio -o -H newc --quiet | \
2061 { cd tmp ; cpio -idm --quiet >/dev/null; cd ..; }
2062 mv tmp/rootfs fs
2064 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
2065 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
2066 { cd fs; cpio -idm --quiet; cd ..; }
2067 fi
2069 if fgrep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
2070 . $INSTALLED/$PACKAGE/receipt
2071 repack_cleanup fs
2072 fi
2074 if [ -f $INSTALLED/$PACKAGE/$CHECKSUM ]; then
2075 sed 's, , fs,' < $INSTALLED/$PACKAGE/$CHECKSUM | \
2076 $CHECKSUM -s -c || {
2077 _ "Can't repack, %s error." $CHECKSUM
2078 cd $TOP_DIR
2079 rm -rf $TMP_DIR
2080 exit 1
2082 fi
2084 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2085 echo -e "$FILES" | cpio -o -H newc --quiet > \
2086 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
2087 cd $TOP_DIR
2088 \rm -R $TMP_DIR
2089 _ 'Package "%s" repacked successfully.' $PACKAGE
2090 _ 'Size: %s' "$(du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg)"
2091 newline ;;
2094 pack)
2095 # Create SliTaz package archive using cpio and lzma.
2096 # TODO: Cook also pack packages, we should share code in libpkg.sh
2097 check_for_package_on_cmdline
2098 cd $PACKAGE
2099 if [ ! -f "receipt" ]; then
2100 _ 'Receipt is missing. Please read the documentation.'
2101 exit 0
2102 else
2103 title 'Packing package "%s"' $PACKAGE
2104 # Create files.list with redirecting find outpout.
2105 action "Creating the list of files..."
2106 cd fs
2107 find . -type f -print > ../files.list
2108 find . -type l -print >> ../files.list
2109 cd .. && sed -i s/'^.'/''/ files.list
2110 status
2111 action 'Creating %s of files...' $CHECKSUM
2112 while read file; do
2113 [ -L "fs$file" ] && continue
2114 [ -f "fs$file" ] || continue
2115 case "$file" in
2116 /lib/modules/*/modules.*|*.pyc) continue;;
2117 esac
2118 $CHECKSUM "fs$file" | sed 's/ fs/ /'
2119 done < files.list > $CHECKSUM
2120 status
2121 UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
2122 description.txt 2> /dev/null | awk \
2123 '{ sz=$1 } END { print sz }')
2124 # Build cpio archives.
2125 action "Compressing the FS..."
2126 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2127 rm -rf fs
2128 status
2129 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
2130 $CHECKSUM description.txt 2> /dev/null | awk \
2131 '{ sz=$1 } END { print sz }')
2132 action "Updating receipt sizes..."
2133 sed -i s/^PACKED_SIZE.*$// receipt
2134 sed -i s/^UNPACKED_SIZE.*$// receipt
2135 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
2136 status
2137 action "Creating full cpio archive..."
2138 find . -print | cpio -o -H newc --quiet > ../$PACKAGE.tazpkg
2139 status
2140 action "Restoring original package tree..."
2141 unlzma -c fs.cpio.lzma | cpio -idm --quiet
2142 status
2143 rm fs.cpio.lzma && cd ..
2144 footer "$(_ 'Package "%s" compressed successfully.' $PACKAGE)"
2145 pkg_size=$(du -sh $PACKAGE.tazpkg)
2146 _ 'Size: %s' $pkg_size
2147 newline
2148 fi ;;
2151 recharge)
2152 # Recharge packages.list from a mirror.
2154 # WARNING: The 'mirrors' file has all SliTaz mirrors but 'mirror'
2155 # must have only the chosen main mirror.
2157 check_root $@
2159 ARG=$2
2160 if [ "$root" ]; then
2161 PKGS_DB=$root$PKGS_DB
2162 [ "${2#--}" != "$2" ] && ARG=$3
2163 fi
2164 if [ "$ARG" = main ]; then
2165 repository_to_recharge=$PKGS_DB
2166 elif [ "$ARG" ]; then
2167 if [ -d "$PKGS_DB/undigest/$ARG" ]; then
2168 repository_to_recharge=$PKGS_DB/undigest/$ARG
2169 else
2170 repo="$PKGS_DB/undigest/$ARG"
2171 _ "Repository \"%s\" doesn't exist." $repo >&2
2172 exit 1
2173 fi
2174 else
2175 repository_to_recharge="$PKGS_DB $PKGS_DB/undigest/*"
2176 fi
2177 for path in $repository_to_recharge; do
2178 [ -f $path/mirror ] || continue
2179 cd $path
2181 # Quietly check if recharging is needed.
2182 [ -f ID ] && mv ID ID.bak
2183 download_from "$(cat mirror)" ID >/dev/null 2>/dev/null
2184 if [ -f ID ] && fgrep -q $(cat ID.bak 2>/dev/null || echo "null") ID; then
2185 if [ "$path" = "$PKGS_DB" ]; then
2186 repository_name=Main
2187 else
2188 base_path="$(basename $path)"
2189 repository_name="$(_n 'Undigest %s' $base_path)"
2190 fi
2191 _ 'Repository "%s" is up to date.' $repository_name
2192 rm ID.bak
2193 continue
2194 fi
2196 # Don't let ID be a symlink when using local repository.
2197 if [ -f ID ]; then
2198 mv -f ID ID.bak
2199 cat ID.bak > ID
2200 rm ID.bak
2201 fi
2203 newline
2204 if [ "$path" != "$PKGS_DB" ]; then
2205 base_path="$(basename $path)"
2206 _ 'Recharging undigest %s:' $base_path
2207 fi
2209 if [ -f "packages.list" ]; then
2210 action "Creating backup of the last packages list..."
2211 for i in packages.desc packages.$SUM packages.txt \
2212 packages.list packages.equiv files.list.lzma \
2213 extra.list mirrors packages.info
2214 do
2215 mv -f $i $i.bak 2>/dev/null
2216 done
2217 status
2218 fi
2220 for i in desc $SUM txt list equiv; do
2221 download_from "$(cat mirror)" packages.$i
2222 done
2223 download_from "$(cat mirror)" files.list.lzma
2224 download_from "$(cat mirror)" extra.list
2225 download_from "$(sed 's|packages/.*||' mirror)" mirrors
2227 # packages.info
2228 download_from "$(cat mirror)" packages.info.lzma
2229 lzma d packages.info.lzma packages.info
2230 rm packages.info.lzma
2232 if [ -f "packages.list.bak" ]; then
2233 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
2234 [ -f "extra.list.bak" ] &&
2235 diff -u extra.list.bak extra.list | grep ^+[a-z] >> packages.diff
2236 sed -i s/+// packages.diff
2237 title 'Mirrored packages diff'
2238 cat packages.diff
2239 new_pkgs=$(wc -l < packages.diff)
2240 footer "$(emsg "$(_p \
2241 '%s new package on the mirror.' \
2242 '%s new packages on the mirror.' $new_pkgs \
2243 "<c 32>$new_pkgs</c>")")"
2244 else
2245 footer "$(longline "$(_ "Last %s is ready to use. Note that \
2246 next time you recharge the list, a list of differences will be displayed to \
2247 show new and upgradeable packages." packages.list)")"
2248 fi
2249 done ;;
2252 help-up)
2253 # Options available for the command: up
2254 newline; usage_up; newline
2255 exit 1 ;;
2258 up|upgrade)
2259 check_root
2261 # This is the new way to upgrade packages making 'upgrade' and
2262 # upgradeable out-of-date. This new way is much, much more faster!
2263 # Look into installed packages and get data from receipt, it is fast
2264 # and easy to handle vars after using only md5sum to compare packages
2266 for opt in $@; do
2267 case "$opt" in
2268 --recharge|-r) tazpkg recharge ;;
2269 --install|-i) install="y" ;;
2270 --check|-c) install="n" ;;
2271 esac
2272 done
2273 time=$(date +%s)
2274 installed_sum=$PKGS_DB/installed.$SUM
2275 look_for_priority
2276 for repo in $priority; do
2277 pkg_list=$repo/packages.list
2278 mtime=$(find $pkg_list -mtime +7)
2279 if [ "$mtime" ]; then
2280 if [ "$repo" = "$PKGS_DB" ]; then
2281 repo_name=main
2282 else
2283 repo_name="${repo##*/}"
2284 fi
2285 _ 'List "%s" is older than one week... Recharging.' $pkg_list
2286 tazpkg recharge $repo_name
2287 fi
2288 done
2289 emsg "<n>$(_ 'Package')<i 28> $(_ 'Version')<i 48> $(_ 'Status')<->"
2290 cd $INSTALLED
2291 newline > $UP_LIST
2292 blocked_count=0
2293 for pkg in *; do
2294 [ ! -d $pkg ] && continue
2295 unset VERSION EXTRAVERSION
2296 . $pkg/receipt
2297 md5=$(fgrep " $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" \
2298 $installed_sum | awk '{print $1}')
2299 for repo in $priority; do
2300 pkg_desc=$repo/packages.desc
2301 pkg_list=$repo/packages.list
2302 pkg_sum=$repo/packages.$SUM
2304 if ! fgrep -q "$md5 $PACKAGE-" $pkg_sum; then
2305 # Jump to next repository in priority if pkg doesn't exist
2306 # in this one.
2307 grep -q ^$PACKAGE- $pkg_list || continue
2309 emsg -n "$PACKAGE<i 28> $VERSION"
2311 # Skip pkgs listed in $PKGS_DB/blocked-packages.list
2312 if $(grep -qs "^$PACKAGE" $BLOCKED); then
2313 blocked_count=$(($blocked_count + 1))
2314 emsg "<i 48><c 31> $(_ 'Blocked')</c>"
2315 break
2316 fi
2318 new=$(grep "^$PACKAGE |" $pkg_desc | awk '{print $3}')
2320 if [ "$VERSION" == "$new" ]; then
2321 emsg "<i 48><c 34> $(_ 'New build')</c>"
2322 else
2323 emsg "<i 48><c 32> $(_ 'New version %s' $new)</c>"
2324 fi
2325 echo "$PACKAGE" >> $UP_LIST
2326 break
2327 fi
2328 done
2329 done
2330 sed -i /^$/d $UP_LIST
2331 upnb=$(wc -l < $UP_LIST)
2332 pkgs=$(ls | wc -l)
2333 time=$(($(date +%s) - $time))
2334 if [ "$upnb" = 0 ]; then
2335 install="n"
2336 _ 'System is up-to-date...'
2337 fi
2339 footer "$(emsg "$(_p \
2340 '%s installed package scanned in %ds' \
2341 '%s installed packages scanned in %ds' $pkgs \
2342 "<c 32>$pkgs</c>" $time)")"
2344 if [ "$upnb" != 0 ]; then
2345 blocked="$(_p \
2346 '%s blocked' '%s blocked' $blocked_count \
2347 $blocked_count)"
2349 boldify "$(_p \
2350 'You have %s available upgrade (%s)' \
2351 'You have %s available upgrades (%s)' $upnb \
2352 $upnb "$blocked")"
2353 newline
2354 fi
2355 # Pkgs to upgrade ? Skip, let install them all or ask user
2356 [ "$install" == "n" ] && exit 0
2357 if [ "$upnb" -gt 0 ]; then
2358 if [ "$install" == "y" ]; then
2359 continue
2360 else
2361 confirm "$(_ 'Do you wish to install them now? (y/N)')"
2362 answer=$?
2363 fi
2364 case "$answer" in
2365 0)
2366 for pkg in $(cat $UP_LIST); do
2367 echo 'y' | tazpkg get-install $pkg --forced
2368 done
2369 # List is generated each time and must be cleaned so
2370 # tazpkg-notify doesn't find upgrades anymore.
2371 rm $UP_LIST; touch $UP_LIST ;;
2372 *)
2373 _ 'Leaving without any upgrades installed.'
2374 newline
2375 exit 0 ;;
2376 esac
2377 fi
2378 newline ;;
2381 bugs)
2382 # Show known bugs in package(s)
2383 cd $INSTALLED
2384 shift
2385 LIST=$@
2386 [ -n "$LIST" ] || LIST=$(ls)
2387 MSG=$(_n 'No known bugs.')
2388 for PACKAGE in $LIST; do
2389 BUGS=""
2390 EXTRAVERSION=""
2391 . $PACKAGE/receipt
2392 if [ -n "$BUGS" ]; then
2393 MSG=$(_n 'Bug list completed')
2394 newline
2395 _ 'Bugs in package "%s" version %s:' $PACKAGE $VERSION$EXTRAVERSION
2396 cat <<EOT
2397 $BUGS
2398 EOT
2399 fi
2400 done
2401 echo "$MSG" ;;
2404 check)
2405 # Check installed packages set.
2406 check_root $@
2408 # Get repositories priority list.
2409 look_for_priority
2411 cd $INSTALLED
2412 for PACKAGE in $(ls); do
2414 if [ ! -f $PACKAGE/receipt ]; then
2415 _ 'The package "%s" installation has not completed' $PACKAGE
2416 continue
2417 fi
2419 DEPENDS=""
2420 EXTRAVERSION=""
2421 . $PACKAGE/receipt
2422 if [ -s $PACKAGE/modifiers ]; then
2423 _ 'The package "%s" has been modified by:' $PACKAGE-$VERSION$EXTRAVERSION
2424 for i in $(cat $PACKAGE/modifiers); do
2425 echo " $i"
2426 done
2427 fi
2429 MSG="$(_n 'Files lost from package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2430 while read file; do
2431 [ -e "$file" ] && continue
2432 if [ -L "$file" ]; then
2433 MSG="$MSG $(_n 'target of symlink')"
2434 fi
2435 echo -e "$MSG $file"
2436 MSG=""
2437 done < $PACKAGE/files.list
2439 MSG="$(_n 'Missing dependencies for package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2440 for i in $DEPENDS; do
2441 [ -d $i ] && continue
2442 [ -d $(equivalent_pkg $i) ] && continue
2443 echo -e "$MSG $i"
2444 MSG=""
2445 done
2447 MSG="$(_n 'Dependencies loop between "%s" and:' $PACKAGE)\n"
2448 ALL_DEPS=""
2449 check_for_deps_loop $PACKAGE $DEPENDS
2450 done
2452 _ 'Looking for known bugs...'
2453 tazpkg bugs
2455 if [ "$2" == "--full" ]; then
2456 separator
2458 for file in */$CHECKSUM; do
2459 CONFIG_FILES=""
2460 . $(dirname "$file")/receipt
2461 [ -s "$file" ] || continue
2462 while read md5 f; do
2463 [ -f $f ] || continue
2464 for i in $CONFIG_FILES; do
2465 case "$f" in
2466 $i|$i/*) continue 2;;
2467 esac
2468 done
2469 echo "$md5 $f"
2470 done < "$file" | $CHECKSUM -c - 2> /dev/null | \
2471 grep -v OK$ | sed "s/FAILED$/$CHECKSUM MISMATCH/"
2472 done
2474 FILES=" "
2475 for file in $(cat */files.list); do
2476 [ -d "$file" ] && continue
2477 case "$FILES" in *\ $file\ *) continue;; esac
2478 [ $(grep "^$(echo $file | grepesc)$" */files.list 2> /dev/null | \
2479 wc -l) -gt 1 ] || continue
2480 FILES="$FILES$file "
2481 _ 'The following packages provide file "%s":' $file
2482 grep -l "^$(echo $file | grepesc)$" */files.list | \
2483 while read f; do
2484 pkg=${f%/files.list}
2485 if [ -f $pkg/modifiers ]; then
2486 overriders=$(_n '(overridden by %s)' "$(tr '\n' ' ' | sed 's| $||' < $pkg/modifiers)")
2487 else
2488 overriders=''
2489 fi
2490 echo -n " $pkg $overriders"
2491 newline
2492 done
2493 done
2495 MSG="$(_n 'No package has installed the following files:')\n"
2496 find /etc /bin /sbin /lib /usr /var/www -not -type d 2>/dev/null | \
2497 while read file; do
2498 case "$file" in *\[*) continue;; esac
2499 grep -q "^$(echo $file | grepesc)$" */files.list && continue
2500 echo -e "$MSG $file"
2501 MSG=""
2502 done
2503 fi
2504 _ 'Check completed.'; echo ;;
2507 block)
2508 # Add a pkg name to the list of blocked packages.
2509 check_root $@
2510 check_for_package_on_cmdline
2511 newline
2512 if grep -qs "^$PACKAGE" $BLOCKED; then
2513 _ 'Package "%s" is already in the blocked packages list.' $PACKAGE
2514 else
2515 action 'Add package "%s" to: %s...' $PACKAGE $BLOCKED
2516 echo $PACKAGE >> $BLOCKED
2517 status
2518 # Log this activity
2519 . $INSTALLED/$PACKAGE/receipt
2520 log_pkg Blocked
2521 fi
2522 newline ;;
2525 unblock)
2526 # Remove a pkg name from the list of blocked packages.
2527 check_root $@
2528 check_for_package_on_cmdline
2529 newline
2530 if grep -qs "^$PACKAGE" $BLOCKED; then
2531 action 'Removing package "%s" from: %s...' $PACKAGE $BLOCKED
2532 sed -i s/$PACKAGE/''/ $BLOCKED
2533 sed -i '/^$/d' $BLOCKED
2534 status
2535 # Log this activity
2536 . $INSTALLED/$PACKAGE/receipt
2537 log_pkg Unblocked
2538 else
2539 _ 'Package "%s" is not in the blocked packages list.' $PACKAGE
2540 fi
2541 newline ;;
2544 get)
2545 # Download a package with wget.
2546 check_root $@
2547 check_for_package_on_cmdline
2548 check_for_packages_list
2550 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2551 if [ "$rootconfig" ]; then
2552 if [ "$root" ]; then
2553 CACHE_DIR=$root/$CACHE_DIR
2554 SAVE_CACHE_DIR=$CACHE_DIR
2555 PKGS_DB=$root/$PKGS_DB
2556 else
2557 _ 'rootconfig needs --root= option used.' >&2
2558 exit 1
2559 fi
2560 fi
2562 # Get repositories priority list.
2563 look_for_priority
2565 CURRENT_DIR=$PWD
2566 check_for_package_in_list
2567 cd $CACHE_DIR
2568 if [ -f "$PACKAGE.tazpkg" ]; then
2569 _ 'Package "%s" already in the cache' $PACKAGE
2570 # Check package download was finished
2571 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2572 _ 'Continuing package "%s" download' $PACKAGE
2573 download $PACKAGE.tazpkg
2575 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2576 rm -f $PACKAGE.tazpkg
2577 download $PACKAGE.tazpkg
2578 fi
2579 else
2580 download $PACKAGE.tazpkg
2581 fi
2582 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2583 cp -a $PACKAGE_FILE $CURRENT_DIR ;;
2586 get-install|-gi)
2587 # Download and install a package.
2588 check_root $@
2589 check_for_package_on_cmdline
2590 check_for_packages_list
2592 DO_CHECK=""
2593 [ "$forced" ] && DO_CHECK=no
2594 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2595 [ "$list" ] && INSTALL_LIST="$list"
2596 if [ "$rootconfig" ]; then
2597 if [ "$root" ]; then
2598 CACHE_DIR=$root/$CACHE_DIR
2599 SAVE_CACHE_DIR=$CACHE_DIR
2600 PKGS_DB=$root/$PKGS_DB
2601 else
2602 _ 'rootconfig needs --root= option used.' >&2
2603 exit 1
2604 fi
2605 fi
2607 # Get repositories priority list.
2608 look_for_priority
2610 AUTOEXEC="no"
2611 if ! check_for_package_in_list check; then
2612 CACHE_DIR="${CACHE_DIR%/*}/get"
2613 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
2614 if download_get_script $PACKAGE /tmp/$PACKAGE.$$ ; then
2615 install_package_from_get_script /tmp/$PACKAGE.$$ $ROOT
2616 exit 0
2617 else
2618 PACKAGE=get-$PACKAGE
2619 AUTOEXEC=$PACKAGE
2620 check_for_package_in_list
2621 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
2622 $AUTOEXEC $ROOT
2623 exit 0
2624 fi
2625 fi
2626 fi
2627 # Check if forced install.
2628 if ! [ "$forced" ]; then
2629 check_for_installed_package $ROOT
2630 fi
2631 cd $CACHE_DIR
2632 if [ -f "$PACKAGE.tazpkg" ]; then
2633 _ 'Package "%s" already in the cache' $PACKAGE
2634 # Check package download was finished
2635 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2636 _ 'Continuing package "%s" download' $PACKAGE
2637 download $PACKAGE.tazpkg
2639 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2640 rm -f $PACKAGE.tazpkg
2641 download $PACKAGE.tazpkg
2642 fi
2643 else
2644 newline
2645 download $PACKAGE.tazpkg
2646 fi
2647 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2648 [ "$rootconfig" ] && PKGS_DB=${PKGS_DB#$root}
2649 install_package $ROOT
2650 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
2651 update_desktop_database $ROOT
2652 update_mime_database $ROOT ;;
2655 clean-cache|-cc)
2656 # Remove all downloaded packages.
2657 check_root $@
2658 files=$(find $CACHE_DIR -name *.tazpkg | wc -l)
2659 size=$(du -hs $CACHE_DIR | cut -f1 | sed 's|\.0||'); [ $files == "0" ] && size="0K"
2660 title 'Path: %s' $CACHE_DIR
2661 action "Cleaning cache directory..."
2662 rm -rf $CACHE_DIR/*
2663 status
2665 footer "$(_p \
2666 '%s file removed from cache (%s).' \
2667 '%s files removed from cache (%s).' $files \
2668 "$(colorize 32 "$files")" $size)"
2669 ;;
2672 list-undigest)
2673 # list undigest URLs.
2674 if [ "$2" = "--box" ]; then
2675 for i in $PKGS_DB/undigest/*/mirror; do
2676 [ -f $i ] || continue
2677 echo "$(basename $(dirname $i))|$(cat $i)"
2678 done
2679 else
2680 title 'Current undigest(s)'
2681 for i in $PKGS_DB/undigest/*/mirror; do
2682 if [ ! -f $i ]; then
2683 _ 'No undigest mirror found.'
2684 exit 1
2685 fi
2686 echo "$(basename $(dirname $i)) $(cat $i)"
2687 done
2688 newline
2689 fi ;;
2692 remove-undigest)
2693 # remove undigest URL.
2694 check_root $@
2695 undigest="$2"
2696 if [ -d $PKGS_DB/undigest/$2 ]; then
2697 confirm "$(_ 'Remove "%s" undigest? (y/N)' $undigest)"
2698 if [ $? = 0 ]; then
2699 action 'Removing "%s" undigest...' $undigest
2700 rm -rf $PKGS_DB/undigest/$2
2701 status
2702 rmdir $PKGS_DB/undigest 2> /dev/null
2703 fi
2704 else
2705 _ 'Undigest "%s" not found' $undigest
2706 fi ;;
2709 add-undigest|setup-undigest)
2710 # Add undigest URL.
2711 check_root $@
2712 undigest=$2
2713 [ -d $PKGS_DB/undigest ] || mkdir $PKGS_DB/undigest
2714 if [ -z "$undigest" ]; then
2715 i=1
2716 while [ -d $PKGS_DB/undigest/$i ]; do
2717 i=$(($i+1))
2718 done
2719 undigest=$i
2720 fi
2721 if [ ! -d $PKGS_DB/undigest/$undigest ]; then
2722 _ 'Creating new undigest "%s".' $undigest
2723 mkdir $PKGS_DB/undigest/$undigest
2724 fi
2725 setup_mirror $PKGS_DB/undigest/$undigest $3 ;;
2728 setup-mirror|-sm)
2729 # Change mirror URL.
2730 check_root $@
2731 setup_mirror $PKGS_DB $2 ;;
2734 reconfigure)
2735 # Replay post_install from receipt
2736 check_for_package_on_cmdline
2737 check_root $@
2738 ROOT=""
2739 while [ -n "$3" ]; do
2740 case "$3" in
2741 --root=*)
2742 ROOT="${3#--root=}/" ;;
2743 *)
2744 shift 2
2745 u_opt="$*"
2746 newline >&2
2747 _ 'Unknown option "%s".' $u_opt >&2
2748 exit 1 ;;
2749 esac
2750 shift
2751 done
2752 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2753 check_for_receipt $ROOT
2754 # Check for post_install
2755 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2756 . $ROOT$INSTALLED/$PACKAGE/receipt
2757 post_install $ROOT
2758 # Log this activity
2759 [ -n "$ROOT" ] || log_pkg Reconfigured
2760 else
2761 newline
2762 _ 'Nothing to do for package "%s".' $PACKAGE
2763 fi
2764 else
2765 newline
2766 _ 'Package "%s" is not installed.' $PACKAGE
2767 _ 'Install package with "%s" or "%s"' 'tazpkg install' 'tazpkg get-install'
2768 newline
2769 fi ;;
2772 shell)
2773 # TazPKG SHell
2774 if test $(id -u) = 0 ; then
2775 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2776 else
2777 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2778 fi
2779 if [ ! "$2" = "--noheader" ]; then
2780 clear
2781 title 'TazPKG SHell.'
2782 _ "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
2783 newline
2784 fi
2785 while true; do
2786 echo -en "$PROMPT"; read cmd
2787 case $cmd in
2788 q|quit)
2789 break ;;
2790 shell)
2791 _ 'You are already running a TazPKG SHell.' ;;
2792 su)
2793 su -c 'exec tazpkg shell --noheader' && break ;;
2794 "")
2795 continue ;;
2796 *)
2797 tazpkg $cmd ;;
2798 esac
2799 done ;;
2802 depends)
2803 # Display dependencies tree
2804 cd $INSTALLED
2805 ALL_DEPS=""
2806 if [ -f $2/receipt ]; then
2807 dep_scan $2 ""
2808 fi ;;
2811 rdepends)
2812 # Display reverse dependencies tree
2813 cd $INSTALLED
2814 ALL_DEPS=""
2815 if [ -f $2/receipt ]; then
2816 rdep_scan $2
2817 fi ;;
2820 convert|-c)
2821 # convert misc package format to .tazpkg
2822 check_for_package_file
2823 tazpkg-convert $@
2824 ;;
2827 link)
2828 # link a package from another slitaz installation
2829 PACKAGE=$2
2830 if [ ! -d "$TARGET_DIR" -o \
2831 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
2832 _ 'Usage: tazpkg link package_name slitaz_root'
2833 longline "$(
2834 _n 'Example:'
2835 echo -n ' '
2836 _ '"%s" will use less than 100k in your running system RAM.' \
2837 'tazpkg link openoffice /mnt')"
2838 exit 1
2839 fi
2840 if [ -e "$INSTALLED/$PACKAGE" ]; then
2841 _ 'Package "%s" is already installed.' $PACKAGE
2842 exit 1
2843 fi
2844 ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
2845 DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
2846 MISSING=""
2847 for i in $DEPENDS; do
2848 [ -e $INSTALLED/$i ] && continue
2849 MISSING="$MISSING$i "
2850 _ 'Missing: %s' $i
2851 done
2852 if [ -n "$MISSING" ]; then
2853 newline
2854 confirm "$(_ 'Link all missing dependencies? (y/N)')"
2855 answer=$?
2856 newline
2857 if [ $answer = 0 ]; then
2858 for i in $MISSING; do
2859 tazpkg link $i $TARGET_DIR
2860 done
2861 else
2862 newline
2863 _ 'Leaving dependencies unresolved for package "%s"' $PACKAGE
2864 _ 'The package is installed but probably will not work.'
2865 newline
2866 fi
2867 fi
2868 . $INSTALLED/$PACKAGE/receipt
2869 if grep -q ^pre_install $INSTALLED/$PACKAGE/receipt; then
2870 pre_install
2871 fi
2872 while read path; do
2873 [ -e $path ] && continue
2874 while true; do
2875 dir=$(dirname $path)
2876 [ -e $dir ] && break
2877 path=$dir
2878 done
2879 ln -s $TARGET_DIR$path $dir
2880 done < $INSTALLED/$PACKAGE/files.list
2881 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
2882 post_install
2883 fi ;;
2886 usage|*)
2887 # Print a short help or give usage for an unknown or empty command.
2888 usage ;;
2889 esac
2891 exit 0