tazpkg view tazpkg @ rev 803

tazpkg: fast recharge (also coming soon for Undigest repo, fails now); update pot and complete Russian translations.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sun May 10 13:33:16 2015 +0300 (2015-05-10)
parents 3dbd29398250
children e5c261e450c7
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-2015 SliTaz - GNU General Public License v3.
12 #
13 # Authors: See the AUTHORS files
14 #
17 ####################
18 # Script variables #
19 ####################
21 # TazPkg version
22 VERSION=5.3.4
24 . /etc/slitaz/slitaz.conf
25 . /etc/slitaz/tazpkg.conf
27 . /lib/libtaz.sh
28 . /usr/lib/slitaz/libpkg.sh
29 . /usr/lib/tazpkg/tazpkg-find-depends
31 # Internationalization.
32 export TEXTDOMAIN='tazpkg'
33 _() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; echo; }
34 _n() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; }
35 _p() {
36 local S="$1" P="$2" N="$3"; shift; shift; shift;
37 printf "$(ngettext "$S" "$P" "$N")" "$@"; }
40 #
41 # Functions set for translate categories
42 #
45 # Make array of pre-translated categories
47 cat_i18n=""
48 for c in "base-system" "x-window" "utilities" "network" "graphics" \
49 "multimedia" "office" "development" "system-tools" "security" "games" \
50 "misc" "meta" "non-free"; do
51 cat_i18n="$cat_i18n
52 $(gettext "$c") $c"
53 done
56 # Translate category names (must be last in line)
58 translate_category()
59 {
60 sed "s|base-system$|$(_ base-system)|g; s|x-window$|$(_ x-window)|g;
61 s|utilities$|$(_ utilities)|g; s|network$|$(_ network)|g;
62 s|graphics$|$(_ graphics)|g; s|multimedia$|$(_ multimedia)|g;
63 s|office$|$(_ office)|g; s|development$|$(_ development)|g;
64 s|system-tools$|$(_ system-tools)|g; s|security$|$(_ security)|g;
65 s|games$|$(_ games)|g; s|misc$|$(_ misc)|g; s|meta$|$(_ meta)|g;
66 s|non-free$|$(_ non-free)|g"
67 }
70 # If category is not one of those translated in native language, keep it
71 # untranslated. This allows both native and English language support.
72 # This also supports custom categories.
73 # And now we support spaces in translated categories
75 reverse_translate_category()
76 {
77 echo "$cat_i18n" | awk "BEGIN{FS=\" \"}{if (/^$@ /) a=\$2}END{if (a==\"\") a=\"$@\"; print a}"
78 }
82 #
83 # TazPkg output functions
84 #
87 # Print localized title
89 title() {
90 case $output in
91 html)
92 echo "<section><header>$(_ "$@")</header><pre class=\"scroll\">";;
93 *)
94 newline; boldify "$(_ "$@")"; separator;;
95 esac
96 }
99 # Print footer
101 footer() {
102 case $output in
103 html)
104 echo "</pre><footer>$1</header></section>";;
105 *)
106 separator; echo "$1"; [ -n "$1" ] && newline;;
107 esac
108 }
111 # Print current action in brown color (separate from any other msgs)
113 action() {
114 case $output in
115 raw|gtk|html) _n "$@" ;;
116 *) echo -ne "\033[0;33m"$(_ "$@")"\033[0m" ;;
117 esac
118 }
121 # Initialize some variables to use words rather than numbers for functions
122 # and actions.
123 COMMAND=$1
124 PACKAGE=${2%/}
125 PACKAGE_DIR="$(cd $(dirname $PACKAGE 2>/dev/null) 2>/dev/null; pwd)"
126 [ -n "$PACKAGE" ] && PACKAGE_FILE="$PACKAGE_DIR/${PACKAGE##*/}"
127 if [ -f "$PACKAGE" ]; then
128 # Set pkg basename for install, extract
129 PACKAGE=$(basename $PACKAGE .tazpkg 2>/dev/null)
130 else
131 # Pkg name for remove, search and all other cmds
132 PACKAGE=${PACKAGE%.tazpkg}
133 fi
134 TARGET_DIR=$3
135 TOP_DIR=$(pwd)
136 TMP_DIR=/tmp/$RANDOM
137 INSTALL_LIST=""
138 SAVE_CACHE_DIR="$CACHE_DIR"
140 # Path to tazpkg used dir and configuration files
141 MIRROR=$PKGS_DB/mirror
142 BLOCKED=$PKGS_DB/blocked-packages.list
143 UP_LIST=$PKGS_DB/packages.up
144 DEFAULT_MIRROR="$ONLINE_PKGS"
149 ####################
150 # Script functions #
151 ####################
154 # Interactive mode
156 im() { tty -s; }
159 # Print the usage.
161 usage () {
162 cat <<EOT
164 $(_ 'SliTaz package manager - Version: %s' $(colorize 34 $VERSION))
166 $(boldify "$(_ 'Usage:')")
167 $(_ 'tazpkg [command] [package|dir|pattern|list|cat|--opt] [dir|--opt]')
169 $(boldify "$(_ 'SHell:')") tazpkg shell
171 $(boldify "$(_ 'Commands:')")
172 $(optlist "\
173 usage $(_ 'Print this short usage')
174 bugs $(_ 'Show known bugs in packages')
175 -a activity $(_ 'Show TazPkg activity log')
176 -l list $(_ 'List installed packages on the system')
177 -lm list-mirror $(_ 'List all available packages on the mirror')
178 info $(_ 'Print information about a package')
179 desc $(_ 'Print description of a package')
180 -lf list-files $(_ 'List the files installed with a package')
181 list-config $(_ 'List the configuration files')
183 -s search $(_ 'Search for a package by pattern or name')
184 search-pkgname $(_ 'Search on mirror for package having a particular file')
185 -sf search-file $(_ 'Search for file in all installed packages files')
187 -g get $(_ 'Download a package into the current directory')
188 -gi get-install $(_ 'Download and install a package from the mirror')
189 get-install-list $(_ 'Download and install a list of packages from the mirror')
190 -i install $(_ 'Install a local package')
191 install-list $(_ 'Install all packages from a list of packages')
192 -r remove $(_ 'Remove the specified package and all installed files')
193 -e extract $(_ 'Extract a (*.tazpkg) package into a directory')
194 pack $(_ 'Pack an unpacked or prepared package tree')
196 recharge $(_ 'Recharge your packages.list from the mirror')
197 up|help-up $(_ 'Check packages %s to list and install latest upgrades' $CHECKSUM)
199 repack $(_ 'Create a package archive from an installed package')
200 repack-config $(_ 'Create a package archive with configuration files')
201 recompress $(_ 'Rebuild a package with a better compression ratio')
202 -b|u block|unblock $(_ 'Block an installed package version or unblock it for upgrade')
203 check $(_ 'Verify consistency of installed packages')
205 add-flavor $(_ 'Install the flavor list of packages')
206 install-flavor $(_ 'Install the flavor list of packages and remove other ones')
208 set-release $(_ 'Change release and update packages')
209 -cc clean-cache $(_ 'Clean all packages downloaded in cache directory')
211 depends $(_ 'Display dependencies tree')
212 rdepends $(_ 'Display reverse dependencies tree')
214 convert $(_ 'Convert alien package to tazpkg')
215 link $(_ 'Link a package from another slitaz installation')
217 -sm setup-mirror $(_ 'Change the mirror url configuration')
218 list-undigest $(_ 'List undigest mirrors')
219 remove-undigest $(_ 'Remove an undigest mirror')
220 add-undigest $(_ 'Add an undigest mirror')
221 setup-undigest $(_ 'Update an undigest mirror')
223 reconfigure $(_ 'Replay post install script from package')
224 ")
225 EOT
226 }
229 usage_up() {
230 cat <<EOT
231 $(emsg "<b>$(_ 'Usage for command up:')</b>") tazpkg up [$(_ 'option')]
233 * $(longline "$(_ 'Without options run in interactive mode and ask before install')")
235 $(boldify "$(_ 'Where options are:')")
236 $(optlist "\
237 -c --check $(_ 'Check only for available upgrades')
238 -r --recharge $(_ 'Force recharge of packages list and check')
239 -i --install $(_ 'Check for upgrades and install them all')
240 ")
242 $(boldify "$(_ 'Example:')")
243 tazpkg up --recharge --install
244 tazpkg up -c -r
245 EOT
246 }
249 # Check if dir exists
251 check_dir() {
252 if ! [ -d "$1" ]; then
253 action 'Creating folder "%s"...' "$1"
254 mkdir -p "$1"
255 status
256 return 1
257 fi
258 }
261 # Check if the directories and files used by TazPkg exist.
262 # If not and user is root we create them.
264 check_base_dir() {
265 if [ "$(id -u)" = "0" ]; then
266 check_dir $1$CACHE_DIR
267 check_dir $1$INSTALLED
268 check_dir $1$SLITAZ_LOGS
269 if [ ! -f "$1$PKGS_DB/mirror" ]; then
270 echo "${DEFAULT_MIRROR%/}/" > $1$PKGS_DB/mirror
271 [ -n "$1" ] && cp $PKGS_DB/packages.* $1$PKGS_DB/
272 fi
273 fi
274 }
275 check_base_dir
278 # Check for a package name on cmdline.
280 check_for_package_on_cmdline() {
281 if [ -z "$PACKAGE" ]; then
282 newline
283 _ 'Please specify a package name on the command line.'
284 newline
285 exit 1
286 fi
287 }
290 # Check if the package (*.tazpkg) exists before installing or extracting.
292 check_for_package_file() {
293 if [ ! -f "$PACKAGE_FILE" ]; then
294 newline
295 _ 'Unable to find file "%s"' $PACKAGE_FILE
296 newline
297 exit 1
298 fi
299 }
302 # Check for the receipt of an installed package.
304 check_for_receipt() {
305 if [ ! -f "$1$INSTALLED/$PACKAGE/receipt" ]; then
306 newline
307 _ 'Unable to find the receipt "%s"' "$1$INSTALLED/$PACKAGE/receipt"
308 newline
309 exit 1
310 fi
311 }
314 # Get repositories priority using $PKGS_DB/priority.
315 # In this files, undigest are called by their name and main mirror
316 # by main. Sort order: priority
318 look_for_priority() {
319 [ -s $PKGS_DB/priority ] && priority=$(cat $PKGS_DB/priority)
320 for rep in main $(ls $PKGS_DB/undigest 2>/dev/null); do
321 if [ ! -s $PKGS_DB/priority ] || \
322 ! grep -q ^$rep$ $PKGS_DB/priority; then
323 priority=$(echo -e "$priority\n$rep")
324 fi
325 done
326 priority=$(echo "$priority" | sed '/^$/d' | \
327 while read line; do
328 if [ "$line" = main ]; then
329 echo $PKGS_DB
330 else
331 echo $PKGS_DB/undigest/$line
332 fi
333 done)
334 }
337 # Get package name in a directory
339 package_fullname_in_dir() {
340 [ -f $1/receipt ] || return
341 EXTRAVERSION=""
342 . $1/receipt
343 echo $PACKAGE-$VERSION$EXTRAVERSION
344 }
347 # Get package name that is already installed.
349 get_installed_package_pathname() {
350 for i in $2$INSTALLED/${1%%-*}*; do
351 [ -d $i ] || continue
352 if [ "$1" = "$(package_fullname_in_dir $i)" ]; then
353 echo $i
354 return
355 fi
356 done
357 }
360 # Check if a package is already installed.
362 check_for_installed_package() {
363 if [ -n "$(get_installed_package_pathname $PACKAGE $1)" ]; then
364 newline
365 _ '"%s" package is already installed.' $(colorize 34 $PACKAGE)
366 longline "$(_ 'You can use the --forced option to force installation.')"
367 newline
368 exit 0
369 fi
370 }
373 # Check for packages.list to download and install packages.
375 check_for_packages_list() {
376 list_path="$PKGS_DB/packages.list"
377 if [ ! -f "$list_path" ]; then
378 if test $(id -u) = 0 ; then
379 tazpkg recharge
380 else
381 newline
382 _ 'Unable to find the list "%s"' $list_path
383 _ \
384 "You must probably run 'tazpkg recharge' as root to get the latest list of
385 packages available on the mirror."
386 newline
387 exit 0
388 fi
389 fi
390 }
393 # Check for installed.info - local file with format of packages.info
394 # "installed.info" is absent on not clean installs; check it and re-generate if needed.
396 check_for_installed_info() {
397 info_path="$ROOT$PKGS_DB/installed.info"
398 if [ ! -f "$info_path" ]; then
399 if [ "$(id -u)" == "0" ]; then
400 _ 'File "%s" generated. Please wait...' installed.info
401 for pkg in $ROOT$PKGS_DB/installed/*/receipt; do
402 unset_receipt
403 . $pkg
404 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
405 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
406 cat >> $info_path << EOT
407 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS
408 EOT
409 done
410 else
411 _ 'Unable to find file "%s"' installed.info
412 _ 'Please run tazpkg as root.'
413 exit 1
414 fi
415 fi
416 }
419 get_cache_dir() {
420 echo $rep > $tmp/rep
421 if [ "$rep" = "$PKGS_DB" ]; then
422 CACHE_DIR="$SAVE_CACHE_DIR/$SLITAZ_RELEASE/packages"
423 elif [ "${rep%-incoming}" = "$rep" ]; then
424 CACHE_DIR="$SAVE_CACHE_DIR/${rep##*/}/packages"
425 else
426 rep="${rep%-incoming}"
427 CACHE_DIR="$SAVE_CACHE_DIR/${rep##*/}/packages-incoming"
428 fi
429 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
430 echo $CACHE_DIR > $tmp/cachedir
431 }
434 # get an already installed package from packages.equiv
436 equivalent_pkg() {
437 for i in $(grep -hs "^$1=" $PKGS_DB/packages.equiv \
438 $PKGS_DB/undigest/*/packages.equiv | sed "s/^$1=//"); do
439 if echo $i | fgrep -q : ; then
440 # format 'alternative:newname'
441 # if alternative is installed then substitute newname
442 if [ -f $2$INSTALLED/${i%:*}/receipt ]; then
443 # substitute package dependency
444 echo ${i#*:}
445 return
446 fi
447 else
448 # if alternative is installed then nothing to install
449 if [ -f $2$INSTALLED/$i/receipt ]; then
450 # substitute installed package
451 echo $i
452 return
453 fi
454 fi
455 done
456 # if not found in packages.equiv then no substitution
457 echo $1
458 }
461 # get a virtual package from packages.equiv
463 virtual_pkg() {
464 for i in $(for rep in $priority; do
465 grep -hs "^$1=" $rep/packages.equiv
466 done | sed "s/^$1=//"); do
467 if echo $i | fgrep -q : ; then
468 # format 'alternative:newname'
469 # if alternative is installed then substitute newname
470 if [ -f $2$INSTALLED/${i%:*}/receipt ]; then
471 # substitute package dependency
472 echo ${i#*:}
473 return
474 fi
475 else
476 # unconditional substitution
477 echo $i
478 return
479 fi
480 done
481 }
484 # Get package filename available on the mirror
486 get_package_filename() {
487 local pkg
488 for rep in $priority; do
489 pkg=$(grep -A 1 -sh "^$1$" $rep/packages.txt | tail -1 | sed 's/^ *//')
490 [ "$pkg" ] && pkg=$(grep -sh "^$1-$pkg" $rep/packages.list | head -1)
492 # Allow user to call a package with his version number.
493 [ "$pkg" ] || pkg=$(grep -sh "^$1$" $rep/packages.list | head -1)
495 [ "$pkg" ] || pkg=$(grep -sh "^$1-[0-9]" $rep/packages.list | head -1)
496 [ "$pkg" ] || pkg=$(grep -sh "^$1-.[\.0-9]" $rep/packages.list | head -1)
497 [ "$pkg" ] && get_cache_dir && break
498 done
499 if [ -z "$pkg" ]; then
500 # Check for virtual package
501 local equiv
502 equiv=$(virtual_pkg $1)
503 if [ "$equiv" != "$1" ]; then
504 PACKAGE=$equiv
505 get_package_filename $PACKAGE
506 return
507 fi
508 fi
509 echo $pkg
510 }
513 # Check for a package in packages.list. Used by get and get-install to grep
514 # package basename.
516 check_for_package_in_list() {
517 local filename
518 local check_only
519 check_only="$1"
520 filename=$(get_package_filename $PACKAGE)
521 if [ "$filename" ]; then
522 PACKAGE=$filename
523 CACHE_DIR=$(cat $tmp/cachedir)
524 rep=$(cat $tmp/rep)
525 rm -f $tmp/rep $tmp/cachedir
526 else
527 newline
528 _ 'Unable to find package "%s" in the mirrored packages list.' $PACKAGE
529 newline
530 [ -n "$check_only" ] && return 1
531 exit 0
532 fi
533 }
536 # Log this activity
537 # (there log_pkg because we have log() in libtaz.sh)
539 log_pkg() {
540 local extra
542 [ "$1" = "Installed" ] && \
543 extra=" - $(fgrep $PACKAGE-$VERSION $PKGS_DB/installed.$SUM | awk '{ print $1 }')"
545 [ -e $LOG ] || touch $LOG
547 [ -w $LOG ] &&
548 echo "$(date +'%F %T') - $1 - $PACKAGE ($VERSION$EXTRAVERSION)$extra" >> $LOG
549 }
552 # Download a get-package script from this mirror
554 download_get_script() {
555 local p
556 for p in $priority ; do
557 local i
558 for i in $(cat $p/mirror) ; do
559 case "$i" in
560 http://*|ftp://*)
561 wget -O $2 ${i%packages/*}packages/get/$1 && return 0 ;;
562 esac
563 done
564 done
565 return 1
566 }
569 # Download a file from this mirror
571 download_from() {
572 local i mirrors="$1"; shift
573 for i in $mirrors; do
574 case "$i" in
575 # Mirror URL can have a trailing slash or not.
576 http://*|https://*|ftp://*)
577 busybox wget -c -q -T 30 -U TazPkg ${i%/}/$@ 2>/dev/null && break ;;
578 *)
579 ln -sf ${i%/}/$1 . && break ;;
580 esac
581 done
582 }
585 # Download a file trying all mirrors
587 download() {
588 local i
589 case "$1" in
590 *.tazpkg)
591 for i in $priority ; do
592 grep -q "^${1%.tazpkg}$" $i/packages.list 2>/dev/null || continue
593 download_from "$(cat $i/mirror)" "$@" && return
594 done
595 esac
596 for i in $(cat $(for rep in $priority; do echo $rep/mirror; done) 2>/dev/null); do
597 download_from "$i" "$@" && break
598 done
599 }
602 # Extract a package with cpio and gzip/lzma.
604 extract_package() {
605 action 'Extracting package...'
606 cpio -idm --quiet < ${PACKAGE_FILE##*/} && rm -f ${PACKAGE_FILE##*/}
607 status
608 if [ -f fs.cpio.lzma ]; then
609 unlzma -c fs.cpio.lzma | cpio -idm --quiet && rm fs.cpio.lzma
610 elif [ -f fs.cpio.gz ]; then
611 zcat fs.cpio.gz | cpio -idm --quiet && rm fs.cpio.gz
612 fi
613 }
616 remove_with_path() {
617 # Avoid dirname errors by checking for argument.
618 [ "$1" ] || return
620 local dir
621 rm -f $1 2>/dev/null
622 dir="$1"
623 while [ "$dir" != "/" ]; do
624 dir="$(dirname $dir)"
625 rmdir $dir 2> /dev/null || break
626 done
627 }
630 grepesc() {
631 sed 's/\[/\\[/g'
632 }
635 # Print short package description
636 print_short_description() {
637 local short_desc=''
638 for LC in $LANG ${LANG%_*}; do
639 if [ -e "$PKGS_DB/packages-desc.$LC" ]; then
640 short_desc=$(grep -e "^$1 " $PKGS_DB/packages-desc.$LC | cut -d' ' -f2)
641 fi
642 done
643 [ -z "$short_desc" -a -s $PKGS_DB/packages.info ] &&
644 short_desc="$(awk -F$'\t' -vp="$PACKAGE" '{if($1==p){print $4;exit}}' $PKGS_DB/packages.info)"
645 longline "$short_desc"
646 }
649 # This function installs a package in the rootfs.
651 install_package() {
652 ROOT=$1
653 if [ -n "$ROOT" ]; then
654 # Get absolute path
655 ROOT=$(realpath $ROOT)
656 fi
657 {
658 # Create package path early to avoid dependencies loop
659 mkdir -p $TMP_DIR
660 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
661 . $TMP_DIR/receipt
662 # FIXME: legacy?
663 if grep -q ^pre_depends $TMP_DIR/receipt; then
664 pre_depends $ROOT
665 fi
667 # Keep modifiers and file list on upgrade
668 cp $ROOT$INSTALLED/$PACKAGE/modifiers \
669 $ROOT$INSTALLED/$PACKAGE/files.list $TMP_DIR 2> /dev/null
670 rm -rf $ROOT$INSTALLED/$PACKAGE 2> /dev/null
672 # Make the installed package data dir to store
673 # the receipt and the files list.
674 mkdir -p $ROOT$INSTALLED/$PACKAGE
675 cp $TMP_DIR/modifiers $ROOT$INSTALLED/$PACKAGE 2> /dev/null
676 cp $TMP_DIR/files.list $ROOT$INSTALLED/$PACKAGE 2> /dev/null
677 rm -rf $TMP_DIR 2> /dev/null
678 sed -i "/ $(basename $PACKAGE_FILE)$/d" \
679 $ROOT$PKGS_DB/installed.$SUM 2> /dev/null
680 cd $(dirname $PACKAGE_FILE)
681 $CHECKSUM $(basename $PACKAGE_FILE) >> $ROOT$PKGS_DB/installed.$SUM
682 }
684 # Resolve package deps.
685 check_for_deps $ROOT
686 if [ -n "$MISSING_PACKAGE" ]; then
687 install_deps $ROOT
688 fi
689 mkdir -p $TMP_DIR
690 [ -n "$INSTALL_LIST" ] && echo "$PACKAGE_FILE" >> $ROOT$PKGS_DB/$INSTALL_LIST-processed
692 title 'Installation of package "%s"' $PACKAGE
694 print_short_description $PACKAGE
695 separator '-'
697 action 'Copying package...'
698 cp $PACKAGE_FILE $TMP_DIR
699 status
701 cd $TMP_DIR
702 extract_package
703 SELF_INSTALL=0
704 EXTRAVERSION=""
705 CONFIG_FILES=""
707 # Include temporary receipt to get the right variables.
708 . $PWD/receipt
709 cd $ROOT$INSTALLED
711 # FIXME: legacy?
712 if [ $SELF_INSTALL -ne 0 -a -n "$ROOT" ]; then
713 action "Checking post install dependencies..."
714 [ -f $INSTALLED/$PACKAGE/receipt ]
715 if ! status; then
716 _ 'Please run "%s" in / and retry.' "tazpkg install $PACKAGE_FILE"
717 rm -rf $TMP_DIR
718 exit 1
719 fi
720 fi
722 # Get files to remove if upgrading
723 if [ -f $PACKAGE/files.list ]; then
724 while read file; do
725 grep -q "^$(echo $file | grepesc)$" $TMP_DIR/files.list && continue
726 for i in $(cat $PACKAGE/modifiers 2> /dev/null ;
727 fgrep -sl $PACKAGE */modifiers | cut -d/ -f1 ); do
728 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
729 done
730 echo $file
731 done < $PACKAGE/files.list > $TMP_DIR/files2remove.list
732 fi
734 # Remember modified packages
735 {
736 check=false
737 for i in $(fgrep -v [ $TMP_DIR/files.list); do
738 [ -e "$ROOT$i" ] || continue
739 [ -d "$ROOT$i" ] && continue
740 echo "- $i"
741 check=true
742 done ;
743 $check && \
744 for i in *; do
745 [ "$i" == "$PACKAGE" ] && continue
746 [ -s $i/files.list ] || continue
747 awk "{ printf \"$i %s\\n\",\$1 }" < $i/files.list
748 done;
749 } | awk '
750 {
751 if ($1 == "-" || file[$2] != "") {
752 file[$2] = file[$2] " " $1
753 if ($1 != "-") {
754 if (pkg[$1] == "") all = all " " $1
755 pkg[$1] = pkg[$1] " " $2
756 }
757 }
758 }
759 END {
760 for (i = split(all, p, " "); i > 0; i--)
761 for (j = split(pkg[p[i]], f, " "); j > 0; j--)
762 printf "%s %s\n",p[i],f[j];
763 }
764 ' | while read dir file; do
765 if grep -qs ^$dir$ $PACKAGE/modifiers; then
766 # Do not overload an overloaded file !
767 rm $TMP_DIR$file 2> /dev/null
768 continue
769 fi
770 grep -qs ^$PACKAGE$ $dir/modifiers && continue
771 if [ -s "$dir/volatile.cpio.gz" ]; then
772 # We can modify backed up files without notice
773 zcat $dir/volatile.cpio.gz | cpio -t --quiet | \
774 grep -q "^${file#/}$" && continue
775 fi
776 echo "$PACKAGE" >> $dir/modifiers
777 done
779 cd $TMP_DIR
780 cp receipt files.list $ROOT$INSTALLED/$PACKAGE
782 # Copy the description if found.
783 if [ -f "description.txt" ]; then
784 cp description.txt $ROOT$INSTALLED/$PACKAGE
785 fi
787 # Copy the md5sum if found.
788 if [ -f "$CHECKSUM" ]; then
789 cp $CHECKSUM $ROOT$INSTALLED/$PACKAGE
790 fi
792 # Pre install commands.
793 if grep -q ^pre_install $ROOT$INSTALLED/$PACKAGE/receipt; then
794 pre_install $ROOT
795 fi
797 if [ -n "$CONFIG_FILES" ]; then
798 # save 'official' configuration files
799 action 'Saving configuration files...'
800 for i in $CONFIG_FILES; do
801 { cd fs ; find ${i#/} -type f 2> /dev/null; cd ..; }
802 done | { cd fs ; cpio -o -H newc --quiet | gzip -9; cd ..; } > \
803 $ROOT$INSTALLED/$PACKAGE/volatile.cpio.gz
805 if [ -z "$newconf" ]; then
806 # keep user configuration files
807 for i in $CONFIG_FILES; do
808 { cd fs ; find ${i#/} -type f 2> /dev/null; cd ..; }
809 done | while read i; do
810 [ -e $ROOT/$i ] || continue
811 cp -a $ROOT/$i fs/$i
812 done
813 fi
814 status
815 fi
817 action 'Installing package...'
818 [ "$(busybox ls fs/* 2>/dev/null)" ] && cp -af fs/* $ROOT/
819 status
821 if [ -s files2remove.list ]; then
822 action 'Removing old package...'
823 while read file; do
824 remove_with_path $ROOT$file
825 done < files2remove.list
826 true
827 status
828 fi
830 # Remove the temporary random directory.
831 action "Removing all tmp files..."
832 cd ..; rm -rf $TMP_DIR
833 status
835 # Post install commands.
836 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
837 action "Execute post-install commands..."
838 post_install $ROOT
839 status
840 fi
842 # Update-desktop-database if needed.
843 if [ "$(fgrep .desktop $ROOT$INSTALLED/$PACKAGE/files.list | fgrep /usr/share/applications/)" ]; then
844 updatedesktopdb=yes
845 fi
847 # Update-mime-database if needed.
848 if [ "$(fgrep /usr/share/mime $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
849 updatemimedb=yes
850 fi
852 # Update-icon-database
853 if [ "$(fgrep /usr/share/icon/hicolor $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
854 updateicondb=yes
855 fi
857 # Compile glib schemas if needed.
858 if [ "$(fgrep /usr/share/glib-2.0/schemas $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
859 compile_schemas=yes
860 fi
862 # Update depmod list
863 if [ "$(fgrep /lib/modules $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
864 updatedepmod=yes
865 fi
867 # Update installed.info
868 check_for_installed_info
869 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
870 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
871 II=$ROOT$PKGS_DB/installed.info
872 sed -i "/^$PACKAGE /d" $II # remove old entry
873 cat >> $II << EOT
874 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS
875 EOT
876 TEMP_FILE=$(mktemp)
877 sort $II > $TEMP_FILE; mv -f $TEMP_FILE $II; chmod a+r $II; unset II
879 cd $TOP_DIR
880 footer "$(_ 'Package "%s" (%s) is installed.' $PACKAGE $VERSION$EXTRAVERSION)"
882 # Log this activity
883 [ -n "$ROOT" ] || log_pkg Installed
885 # Remove package from upgrade list
886 [ -s $UP_LIST ] && sed -i "/^$PACKAGE\$/d" $UP_LIST
887 }
890 # This function may be called by a get script.
892 abort_package() {
893 cd $CUR_DIR
894 rm -rf $TMP_DIR
895 echo "${1:-Abort $PACKAGE.}"
896 exit 1
897 }
900 # This function installs a package from a get script in the rootfs.
902 install_package_from_get_script() {
903 SCRIPT="$1"
904 ROOT="$2"
905 [ -d $ROOT$INSTALLED/$PACKAGE ] && exit 1
907 grep -q no-check-certificate $SCRIPT &&
908 [ ! -d $INSTALLED/wget ] && tazpkg get-install wget
910 mkdir -p $TMP_DIR && cd $TMP_DIR
911 saved=$PACKAGE
912 unset_receipt
913 PACKAGE=$saved
915 set -e
916 . $SCRIPT
917 set +e
918 [ -d $PACKAGE-$VERSION ] || cd $TMP_DIR
919 [ -d $PACKAGE-$VERSION ] || abort_package \
920 "$(_ 'Could not download "%s" from "%s". Exiting.' ${TARBALL:-$PACKAGE} ${WGET_URL:-$WEB_SITE})"
922 if [ ! -s $PACKAGE-$VERSION/receipt ]; then
923 cat > $PACKAGE-$VERSION/receipt <<EOT
924 # SliTaz package receipt.
926 PACKAGE="$PACKAGE"
927 VERSION="${VERSION:-unknown}"
928 CATEGORY="${CATEGORY:-non-free}"
929 WEB_SITE="$WEB_SITE"
930 SHORT_DESC="${SHORT_DESC:-$PACKAGE}"
931 MAINTAINER="${MAINTAINER:-nobody@slitaz.org}"
932 EOT
933 for i in LICENSE TARBALL WGET_URL CONFIG_FILES SUGGESTED \
934 PROVIDE DEPENDS HOST_ARCH TAGS EXTRA_SOURCE_FILES ; do
935 eval "[ -n \"\$$i\" ] && echo \"$i=\\\"\$$i\\\"\""
936 done >> $PACKAGE-$VERSION/receipt
937 fi
939 DEPENDS="$(unset DEPENDS; . $PACKAGE-$VERSION/receipt ; echo $DEPENDS)"
940 for i in $(find_depends $PACKAGE-$VERSION/fs); do
941 case " $DEPENDS " in
942 *\ $i\ *) continue;;
943 esac
944 grep -q '^DEPENDS="' $PACKAGE-$VERSION/receipt ||
945 echo 'DEPENDS=""' >> $PACKAGE-$VERSION/receipt
946 sed -i "s/^DEPENDS=\"/&$i /" $PACKAGE-$VERSION/receipt
947 done
949 tazpkg pack $PACKAGE-$VERSION
951 # Clean to save RAM memory before installation
952 rm -rf $PACKAGE-$VERSION
954 if [ "$3" == "--get" ]; then
955 mv $PACKAGE-$VERSION.tazpkg $TOP_DIR
956 else
957 # Install pseudo package
958 tazpkg install $PACKAGE-$VERSION.tazpkg --root=$ROOT
959 mv $PACKAGE-$VERSION.tazpkg $CACHE_DIR
960 fi
962 # Clean
963 cd $TOP_DIR
964 rm -rf $TMP_DIR
965 }
968 # Check for loop in deps tree.
970 check_for_deps_loop() {
971 local list
972 local pkg
973 local deps
974 pkg=$1
975 shift
976 [ -n "$1" ] || return
977 list=""
979 # Filter out already processed deps
980 for i in $@; do
981 case " $ALL_DEPS" in
982 *\ $i\ *) ;;
983 *) list="$list $i";;
984 esac
985 done
986 ALL_DEPS="$ALL_DEPS$list "
987 for i in $list; do
988 [ -f $i/receipt ] || continue
989 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
990 case " $deps " in
991 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
992 *) check_for_deps_loop $pkg $deps;;
993 esac
994 done
995 }
998 # Check for missing deps listed in a receipt packages.
1000 check_for_deps() {
1001 local saved;
1002 saved=$PACKAGE
1003 mkdir -p $TMP_DIR
1004 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
1005 . $TMP_DIR/receipt
1006 PACKAGE=$saved
1007 rm -rf $TMP_DIR
1009 num=0
1010 for pkgorg in $DEPENDS; do
1011 i=$(equivalent_pkg $pkgorg $1)
1012 if [ ! -d "$1$INSTALLED/$i" ]; then
1013 MISSING_PACKAGE=$i
1014 num=$(($num+1))
1015 elif [ ! -f "$1$INSTALLED/$i/receipt" ]; then
1016 _ 'WARNING! Dependency loop between "%s" and "%s".' $PACKAGE $i
1017 fi
1018 done
1020 if [ -n "$MISSING_PACKAGE" ]; then
1021 title "$(_ 'Tracking dependencies for package "%s"' $PACKAGE)"
1022 for pkgorg in $DEPENDS; do
1023 i=$(equivalent_pkg $pkgorg $1)
1024 if [ ! -d "$1$INSTALLED/$i" ]; then
1025 MISSING_PACKAGE=$i
1026 _ 'Missing package "%s"' $MISSING_PACKAGE
1027 fi
1028 done
1029 footer "$(_p \
1030 '%s missing package to install.' \
1031 '%s missing packages to install.' $num \
1032 $num)"
1033 fi
1037 # Install all missing deps. Auto install or ask user then install all missing
1038 # deps from local dir, cdrom, media or from the mirror. In case we want to
1039 # install packages from local, we need a packages.list to find the version.
1041 install_deps() {
1042 local root
1043 root=""
1044 [ -n "$1" ] && root="--root=$1"
1045 if [ "$AUTO_INSTALL_DEPS" == "yes" ]; then
1046 answer=0
1047 else
1048 newline
1049 confirm "$(_ 'Install all missing dependencies? (y/N)')"
1050 answer=$?
1051 newline
1052 fi
1053 if [ $answer == 0 ] && ! [ "$nodeps" ]; then
1054 for pkgorg in $DEPENDS; do
1055 pkg=$(equivalent_pkg $pkgorg $1)
1056 if [ ! -d "$1$INSTALLED/$pkg" ]; then
1057 local list
1058 list="$INSTALL_LIST"
1059 [ -n "$list" ] || list="$TOP_DIR/packages.list"
1060 # We can install packages from a local dir by greping
1061 # the TAZPKG_BASENAME in the local packages.list.
1062 found=0
1063 if [ -f "$list" ]; then
1064 _ 'Checking if package "%s" exists in local list...' $pkg
1065 mkdir $TMP_DIR
1066 for i in $pkg-*.tazpkg; do
1067 [ -f $i ] || continue
1068 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $i
1069 [ "$(. $TMP_DIR/receipt; echo $PACKAGE)" = "$pkg" ] || continue
1070 if grep -q ^$(package_fullname_in_dir $TMP_DIR).tazpkg$ $list
1071 then
1072 found=1
1073 tazpkg install $i $root --list=$list
1074 break
1075 fi
1076 done
1077 rm -rf $TMP_DIR
1078 fi
1079 # Install deps from the mirror.
1080 if [ $found -eq 0 ]; then
1081 if [ ! -f "$PKGS_DB/packages.list" ]; then
1082 tazpkg recharge
1083 fi
1084 tazpkg get-install $pkg $root
1085 fi
1086 fi
1087 done
1088 else
1089 newline
1090 _ 'Leaving dependencies for package "%s" unresolved.' $PACKAGE
1091 _ 'The package is installed but will probably not work.'
1092 newline
1093 fi
1097 # Search pattern in installed packages.
1099 search_in_installed_packages() {
1100 _ 'Installed packages'
1101 separator
1102 num=0
1103 for pkg in $(ls -1 $INSTALLED | grep -i "$PATTERN"); do
1104 EXTRAVERSION=""
1105 [ -f $INSTALLED/$pkg/receipt ] || continue
1106 . $INSTALLED/$pkg/receipt
1107 emsg "$PACKAGE<i 24> $VERSION$EXTRAVERSION<i 42> $(_n $CATEGORY)"
1108 num=$(($num+1))
1109 done
1111 footer "$(_p \
1112 '%s installed package found for "%s"' \
1113 '%s installed packages found for "%s"' $num \
1114 $num "$PATTERN")"
1118 # Search in packages.list for available pkgs.
1120 search_in_packages_list() {
1121 _ 'Available packages'
1122 separator
1123 num=0
1124 BPATTERN="$(emsg "<b>$PATTERN</b>")"
1125 for i in $PKGS_DB/packages.list $PKGS_DB/undigest/*/packages.list \
1126 $PKGS_DB/extra.list $PKGS_DB/undigest/*/extra.list ; do
1127 grep -is "$PATTERN" $i | sed "s|$PATTERN|$BPATTERN|"
1128 num=$(($num + `grep -is "$PATTERN" $i | wc -l`))
1129 done
1130 if [ ! -f "$PKGS_DB/packages.list" ]; then
1131 newline
1132 longline "$(_ \
1133 "No \"%s\" found to check for mirrored packages. For more results, please run \
1134 \"%s\" once as root before searching." packages.list 'tazpkg recharge')"
1135 newline
1136 fi
1137 footer "$(_p \
1138 '%s available package found for "%s"' \
1139 '%s available packages found for "%s"' $num \
1140 $num $PATTERN)"
1144 # search --mirror: Search in packages.txt for available pkgs and give more
1145 # info than --list or default.
1147 search_in_packages_txt() {
1148 _ 'Matching packages name with version and desc'
1149 separator
1150 num=0
1151 for i in $PKGS_DB/packages.txt $PKGS_DB/undigest/*/packages.txt; do
1152 grep -is -A 2 "^$PATTERN" $i
1153 num=$(($num + `grep -is "^$PATTERN" $i | wc -l`))
1154 done
1155 if [ ! -f "$PKGS_DB/packages.txt" ]; then
1156 newline
1157 longline "$(_ \
1158 "No \"%s\" found to check for mirrored packages. For more results, please run \
1159 \"%s\" once as root before searching." packages.txt 'tazpkg recharge')"
1160 newline
1161 fi
1162 footer "$(_p \
1163 '%s available package found for "%s"' \
1164 '%s available packages found for "%s"' $num \
1165 $num $PATTERN)"
1169 # Install package-list from a flavor
1171 install_flavor() {
1172 check_root $@
1174 # Get repositories priority list.
1175 look_for_priority
1177 FLAVOR=$1
1178 ARG=$2
1179 mkdir -p $TMP_DIR
1180 [ -f $FLAVOR.flavor ] && cp $FLAVOR.flavor $TMP_DIR
1181 cd $TMP_DIR
1182 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1183 zcat < $FLAVOR.flavor | cpio --quiet -i >/dev/null
1185 while read file; do
1186 for pkg in $(ls -d $INSTALLED/${file%%-*}*); do
1187 [ -f $pkg/receipt ] || continue
1188 EXTRAVERSION=""
1189 . $pkg/receipt
1190 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && break
1191 done
1192 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && continue
1193 cd $CACHE_DIR
1194 download $file.tazpkg
1195 cd $TMP_DIR
1196 tazpkg install $CACHE_DIR/$file.tazpkg --forced
1197 done < $FLAVOR.pkglist
1199 [ -f $FLAVOR.nonfree ] && while read pkg; do
1200 [ -d $INSTALLED/$pkg ] || continue
1201 [ -d $INSTALLED/get-$pkg ] && tazpkg get-install get-$pkg
1202 get-$pkg
1203 done < $FLAVOR.nonfree
1205 [ "$ARG" == "--purge" ] && for pkg in $(ls $INSTALLED); do
1206 [ -f $INSTALLED/$pkg/receipt ] || continue
1207 EXTRAVERSION=""
1208 . $INSTALLED/$pkg/receipt
1209 grep -q ^$PACKAGE-$VERSION$EXTRAVERSION$ $FLAVOR.pkglist && continue
1210 grep -qs ^$PACKAGE$ $FLAVOR.nonfree && continue
1211 tazpkg remove $PACKAGE
1212 done
1213 else
1214 _ "Can't find flavor \"%s\". Abort." $FLAVOR
1215 fi
1216 cd $TOP_DIR
1217 rm -rf $TMP_DIR
1221 # Update mirror urls
1223 setup_mirror() {
1224 # Backup old list.
1225 if [ -f "$1/mirror" ]; then
1226 cp -f $1/mirror $1/mirror.bak
1227 fi
1228 title 'Current mirror(s)'
1229 echo " `cat $1/mirror 2> /dev/null`"
1230 longline "$(_ \
1231 "Please enter URL of the new mirror (http, ftp or local path). You must specify \
1232 the complete address to the directory of the packages and packages.list file.")"
1233 newline
1234 _n 'New mirror(s) URL: '
1235 NEW_MIRROR_URL=$2
1236 if [ -n "$NEW_MIRROR_URL" ]; then
1237 echo $NEW_MIRROR_URL
1238 else
1239 read NEW_MIRROR_URL
1240 fi
1241 if [ "$NEW_MIRROR_URL" = "" ]; then
1242 _ 'Nothing has been changed.'
1243 else
1244 _ 'Setting mirror(s) to: "%s"' $NEW_MIRROR_URL
1245 rm -f $1/mirror
1246 for i in $NEW_MIRROR_URL; do
1247 echo "${i%/}/" >> $1/mirror
1248 done
1249 fi
1250 newline
1254 # recursive dependencies scan
1256 dep_scan() {
1257 for i in $1; do
1258 case " $ALL_DEPS " in
1259 *\ $i\ *) continue;;
1260 esac
1261 ALL_DEPS="$ALL_DEPS $i"
1262 [ -n "$2" ] && echo "$2$i ($(fgrep -A 3 $i $PKGS_DB/packages.txt | \
1263 tail -1 | sed 's/.*(\([^ ]*\).*/\1/'))"
1264 [ -f $i/receipt ] || continue
1265 DEPENDS=""
1266 . $i/receipt
1267 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
1268 done
1272 # recursive reverse dependencies scan
1274 rdep_scan() {
1275 SEARCH=$1
1277 for i in * ; do
1278 DEPENDS=""
1279 . $i/receipt
1280 echo "$i $(echo $DEPENDS)"
1281 done | busybox awk -v search=$SEARCH '
1282 function show_deps(deps, all_deps, pkg, space)
1284 if (all_deps[pkg] == 1) return
1285 all_deps[pkg] = 1
1286 if (space != "") printf "%s %s\n",space,pkg
1287 for (i = 1, n = split(deps[pkg], mydeps, " "); i <= n; i++) {
1288 show_deps(deps, all_deps, mydeps[i],"==" space)
1293 all_deps[$1] = 0
1294 for (i = 2; i <= NF; i++)
1295 deps[$i] = deps[$i] " " $1
1298 END {
1299 show_deps(deps, all_deps, search, "")
1301 ' | while read spc pkg; do
1302 echo -n $spc | sed 's/=/ /g'
1303 echo -n $pkg
1304 echo -n ' ('
1305 fgrep -A 3 $pkg $PKGS_DB/packages.txt | tail -1 | \
1306 sed 's/.*(\([^ ]*\).*/\1)/'
1307 done
1311 update_desktop_database() {
1312 if [ -f $1/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
1313 chroot "$1/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
1314 fi
1318 update_mime_database() {
1319 if [ -f $1/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
1320 chroot "$1/" /usr/bin/update-mime-database /usr/share/mime
1321 fi
1325 update_icon_database() {
1326 if [ -f $1/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
1327 chroot "$1/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
1328 fi
1332 compile_glib_schemas() {
1333 if [ -f $1/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
1334 chroot "$1/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
1335 fi
1339 update_kernel_modules() {
1340 if [ -f $1/sbin/depmod ] && [ -n "$updatedepmod" ]; then
1341 chroot "$1/" /sbin/depmod -a
1342 fi
1346 # When recharging errors occurs
1348 recharging_failed() {
1349 colorize 31 "$(_ 'Recharging failed')"
1351 # Restore database from bak files
1352 action 'Restoring database files...'
1353 [ -e 'ID' -a ! -e 'ID.bak' ] && rm ID
1354 [ -e 'IDs' -a ! -e 'IDs.bak' ] && rm IDs
1355 for file in $(ls $1/*.bak); do
1356 mv -f $file ${file%.bak}
1357 done
1358 status
1364 ###################
1365 # TazPkg commands #
1366 ###################
1368 case "$COMMAND" in
1369 list|-l)
1370 # List all installed packages or a specific category.
1371 shift
1372 check_for_installed_info
1374 case $1 in
1375 b|blocked)
1376 # Display the list of blocked packages.
1377 title 'Blocked packages'
1378 if [ -s "$BLOCKED" ];then
1379 cat $BLOCKED
1380 else
1381 _ 'No blocked packages found.'
1382 fi
1383 newline; exit 0
1384 ;;
1386 c|cat|categories)
1387 # Display the list of categories.
1388 title 'Packages categories'
1390 echo "$PKGS_CATEGORIES" | sed 's|[^a-z-]|\n|g; /^$/d' | \
1391 sed 's|\(.*\)|\1\t\1|' | translate_category | awk -F$'\t' '{
1392 if ($1==$2) print $1; else print $1"\033[15G "$2}'
1394 num=$(echo -n "$PKGS_CATEGORIES" | wc -l)
1395 footer "$(_p \
1396 '%s category' \
1397 '%s categories' $num \
1398 $num)"
1399 exit 0
1400 ;;
1402 '')
1403 # By default list all packages and versions.
1404 title 'List of all installed packages'
1405 TMPLIST=$(mktemp)
1406 awk -F$'\t' '{print $1"\033[35G "$2"\033[53G "$3}' \
1407 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
1409 packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST
1410 footer "$(emsg $(_p \
1411 '%s package installed.' \
1412 '%s packages installed.' $packages \
1413 "<c 32>$packages</c>"))"
1414 ;;
1416 *)
1417 # Check for an asked category.
1418 ASKED_CATEGORY_I18N="$@"
1419 ASKED_CATEGORY=$(reverse_translate_category "$ASKED_CATEGORY_I18N")
1420 title 'Installed packages of category "%s"' $ASKED_CATEGORY_I18N
1421 TMPLIST=$(mktemp)
1422 awk -F$'\t' '
1424 if ($3 == "'$ASKED_CATEGORY'")
1425 print $1"\033[35G "$2
1426 }' \
1427 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
1429 packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST
1430 footer "$(emsg $(_p \
1431 '%s package installed of category "%s".' \
1432 '%s packages installed of category "%s".' $packages \
1433 "<c 32>$packages</c>" "<c 34>$ASKED_CATEGORY_I18N</c>"))"
1434 ;;
1435 esac ;;
1438 list-mirror|-lm)
1439 # List all available packages on the mirror. Option --diff displays
1440 # last mirrored packages diff (see recharge).
1441 check_for_packages_list
1442 case $2 in
1443 --diff)
1444 if [ -f "$PKGS_DB/packages.diff" ]; then
1445 title 'Mirrored packages diff'
1446 cat $PKGS_DB/packages.diff
1447 num=$(wc -l < $PKGS_DB/packages.diff)
1448 footer "$(_p \
1449 '%s new package listed on the mirror.' \
1450 '%s new packages listed on the mirror.' $num \
1451 $num)"
1452 else
1453 newline
1454 _ 'Unable to list anything, no packages.diff found.'
1455 _ 'Recharge your current list to create a first diff.'
1456 newline
1457 fi; exit 0 ;;
1458 --text|--txt|--raw|*)
1459 title 'List of available packages on the mirror'
1460 cat $PKGS_DB/packages.txt ;;
1461 esac
1462 pkgs=$(wc -l < $PKGS_DB/packages.list)
1463 footer "$(emsg "$(_p \
1464 '%s package in the last recharged list.' \
1465 '%s packages in the last recharged list.' $pkgs \
1466 "<c 32>$pkgs</c>")")"
1467 ;;
1470 list-files|-lf)
1471 # List files installed with the package.
1472 check_for_package_on_cmdline
1473 check_for_receipt
1474 title 'Installed files by "%s"' $PACKAGE
1475 sort < $INSTALLED/$PACKAGE/files.list
1476 files=$(wc -l < $INSTALLED/$PACKAGE/files.list)
1477 footer "$(emsg "$(_p \
1478 '%s file' '%s files' $files \
1479 "<c 32>$files</c>")")"
1480 ;;
1483 info)
1484 # Information about package.
1485 check_for_package_on_cmdline
1486 check_for_receipt
1487 EXTRAVERSION=""
1488 . $INSTALLED/$PACKAGE/receipt
1489 im && title 'TazPKG information'
1490 # Display localized short description
1491 for LC in $LANG ${LANG%_*}; do
1492 if [ -e "$PKGS_DB/packages-desc.$LC" ]; then
1493 LOCDESC=$(grep -e "^$PACKAGE " $PKGS_DB/packages-desc.$LC | cut -d' ' -f2)
1494 [ -n "$LOCDESC" ] && SHORT_DESC="$LOCDESC"
1495 fi
1496 done
1497 SIZES=$(echo $PACKED_SIZE/$UNPACKED_SIZE | sed 's|\.0||g' | sed 's|^/$||')
1499 emsg "$(
1501 _ 'Package : %s' "$PACKAGE"
1502 _ 'Version : %s' "$VERSION$EXTRAVERSION"
1503 _ 'Category : %s' "$(_ $CATEGORY)"
1504 _ 'Short desc : %s' "$SHORT_DESC"
1505 _ 'Maintainer : %s' "$MAINTAINER"
1506 _ 'License : %s' "$LICENSE"
1507 _ 'Depends : %s' "$DEPENDS"
1508 _ 'Suggested : %s' "$SUGGESTED"
1509 _ 'Build deps : %s' "$BUILD_DEPENDS"
1510 _ 'Wanted src : %s' "$WANTED"
1511 _ 'Web site : %s' "$WEB_SITE"
1512 _ 'Size : %s' "$SIZES"
1513 _ 'Tags : %s' "$TAGS"
1514 } | sed '/: $/d; s|^\([^:]*\):|<b>\1:</b>|')"
1515 im && footer
1516 ;;
1519 desc)
1520 # Display package description
1521 if [ -n "$(grep -e "^$PACKAGE " $PKGS_DB/installed.info)" ]; then
1522 im && title 'Description of package "%s"' $PACKAGE
1523 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
1524 cat $INSTALLED/$PACKAGE/description.txt
1525 else
1526 im && awk -F$'\t' '{if ($1 == "'$PACKAGE'") print $4}' $PKGS_DB/installed.info
1527 fi
1528 im && footer
1529 else
1530 im && _ 'Package "%s" is not installed.' "$PACKAGE"
1531 fi
1532 ;;
1535 activity|log|-a)
1536 # Show activity log
1537 [ "$nb" ] || nb=18
1538 title 'TazPKG Activity'
1539 IFS=" "
1540 tail -n ${nb} ${LOG} | \
1541 while read date hour none action none pkg vers none; do
1542 case $action in
1543 Installed)
1544 action=$(colorize 32 $action) ;;
1545 Removed)
1546 action=$(colorize 31 $action) ;;
1547 *)
1548 action=$(boldify $action) ;;
1549 esac
1550 echo "$date $hour : $action $pkg $vers"
1551 done
1552 unset IFS
1553 footer ;;
1556 search|-s)
1557 # Search for a package by pattern or name.
1558 PATTERN="$2"
1559 if [ -z "$PATTERN" ]; then
1560 newline
1561 _ 'Please specify a pattern or package name to search for.'
1562 echo "$(_ 'Example:') 'tazpkg search paint'"
1563 newline
1564 exit 0
1565 fi
1566 title 'Search result for "%s"' $PATTERN
1567 # Default is to search in installed pkgs and the raw list.
1568 case "$3" in
1569 -i|--installed) search_in_installed_packages ;;
1570 -l|--list) search_in_packages_list ;;
1571 -m|--mirror) search_in_packages_txt ;;
1572 *)
1573 search_in_installed_packages
1574 search_in_packages_list ;;
1575 esac ;;
1578 search-file|-sf)
1579 # Search for a file by pattern or name in all files.list.
1580 if [ -z "$2" ]; then
1581 newline
1582 _ 'Please specify a pattern or file name to search for.'
1583 echo "$(_ 'Example:') 'tazpkg search-file libnss'"
1584 newline
1585 exit 0
1586 fi
1587 title 'Search result for file "%s"' $2
1589 TMPLIST=$(mktemp)
1590 if [ "$3" == "--mirror" ]; then
1592 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1593 [ -f $i ] || continue
1594 lzcat $i | awk -F: -vP="$(gettext 'Package %s:')" -vT=$TMPLIST '
1595 BEGIN { last = "" }
1596 $2 ~ /'$2'/ {
1597 if (last != $1) {
1598 last = $1;
1599 PP = P;
1600 sub(/%s/, $1, PP);
1601 printf("\n\e[1;33m%s\e[0;39m\n", PP);
1603 gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $2);
1604 print $2;
1605 printf "%s" 1 >> T;
1606 }'
1607 done
1609 else
1611 # Check all pkg files.list in search match which specify the package
1612 # name and the full path to the file(s).
1613 for pkg in $INSTALLED/*; do
1614 if grep -qs "$2" $pkg/files.list; then
1615 . $pkg/receipt
1616 newline
1617 emsg "<c 33>$(_ 'Package %s:' $PACKAGE)</c>"
1618 awk -vT=$TMPLIST '
1619 /'$2'/ {
1620 gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $0);
1621 print " "$0;
1622 printf "%s" 1 >> T;
1624 ' $pkg/files.list
1625 fi
1626 done
1628 fi
1630 match=$(wc -m < $TMPLIST)
1631 rm $TMPLIST
1633 footer "$(emsg "$(_p \
1634 '%s file' '%s files' $match \
1635 "<c 32>$match</c>")")"
1636 ;;
1639 search-pkgname)
1640 # Search for a package name
1641 if [ -z "$2" ]; then
1642 newline
1643 _ 'Please specify a pattern or file name to search for.'
1644 echo "$(_ 'Example:') 'tazpkg search-pkgname libnss'"
1645 newline
1646 exit 0
1647 fi
1648 title 'Search result for package "%s"' $2
1650 # Search for a file on mirror and output only the package name
1651 TMPLIST=$(mktemp)
1652 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1653 [ -f $i ] || continue
1654 lzcat $i | awk -F: -vT=$TMPLIST '
1655 BEGIN { P = "" }
1656 $2 ~ /'$2'/ {
1657 if ($1 != P) {
1658 print $1;
1659 printf "%s" 1 >> T;
1660 P = $1
1662 }'
1663 done
1664 match=$(wc -m < $TMPLIST)
1665 rm $TMPLIST
1667 footer "$(emsg "$(_p \
1668 '%s package' '%s packages' $match \
1669 "<c 32>$match</c>")")"
1670 ;;
1673 install|-i)
1674 # Install .tazpkg packages.
1675 check_root $@
1676 check_for_package_on_cmdline
1677 check_for_package_file
1678 check_for_installed_info
1680 if [ -n "$root" ]; then
1681 ROOT="$root";
1682 check_base_dir "$root"
1683 fi
1684 [ "$list" ] && INSTALL_LIST="$list"
1685 if [ "$rootconfig" ]; then
1686 if [ "$root" ]; then
1687 CACHE_DIR=$root/$CACHE_DIR
1688 SAVE_CACHE_DIR=$CACHE_DIR
1689 PKGS_DB=$root/$PKGS_DB
1690 else
1691 echo "rootconfig needs --root= option used." >&2
1692 exit 1
1693 fi
1694 fi
1696 # Get repositories priority list.
1697 look_for_priority
1699 # Check if forced install.
1700 if [ -z "$forced" ]; then
1701 check_for_installed_package $ROOT
1702 fi
1703 install_package $ROOT
1704 update_desktop_database $ROOT
1705 update_mime_database $ROOT
1706 update_icon_database $ROOT
1707 compile_glib_schemas $ROOT
1708 ;;
1711 install-list|get-install-list)
1712 # Install a set of packages from a list.
1713 check_root $@
1714 if [ -z "$2" ]; then
1715 newline
1716 longline "$(_ \
1717 "Please change directory (cd) to the packages repository and specify the \
1718 list of packages to install.")"
1719 echo "$(_ 'Example:') $(emsg '<b>tazpkg install-list</b> <c 33>packages.list</c>')"
1720 exit 0
1721 fi
1723 # Check if the packages list exist.
1724 if [ ! -f "$2" ]; then
1725 _ 'Unable to find list "%s"' "$2"
1726 exit 0
1727 fi
1729 LIST=$(cat $2)
1731 # Remember processed list
1732 export INSTALL_LIST="$2"
1734 # Set $COMMAND and install all packages.
1735 COMMAND=${1%-list}
1737 touch $2-processed
1739 # Upgrade tazpkg first. It may handle new features/formats...
1740 # then upgrade essential packages early
1741 for pkg in busybox-pam busybox gcc-lib-base glibc-base \
1742 slitaz-base-files tazpkg ; do
1743 pkg=$(egrep $pkg-[0-9] $INSTALL_LIST)
1744 [ -z "$pkg" ] && continue
1745 _ 'Adding implicit depends "%s"...' $pkg
1746 LIST="$pkg
1747 $LIST"
1748 done
1750 for pkg in $LIST; do
1751 grep -qs ^$pkg$ $2-processed && continue
1752 [ -d "$root/var/lib/tazpkg/installed" ] &&
1753 tazpkg $COMMAND $pkg --list="$2" "$3" "$4" "$5"
1754 done
1755 rm -f $2-processed ;;
1758 add-flavor)
1759 # Install a set of packages from a flavor.
1760 install_flavor $2 ;;
1763 install-flavor)
1764 # Install a set of packages from a flavor and purge other ones.
1765 install_flavor $2 --purge ;;
1768 set-release)
1769 # Change current release and upgrade packages.
1770 RELEASE=$2
1771 if [ -z "$RELEASE" ]; then
1772 newline
1773 _ 'Please specify the release you want on the command line.'
1774 echo "$(_ 'Example:') tazpkg set-release cooking"
1775 newline
1776 exit 0
1777 fi
1778 rm $PKGS_DB/mirror
1779 echo "$RELEASE" > /etc/slitaz-release
1780 tazpkg recharge && tazpkg upgrade
1782 # Install missing depends
1783 cd $INSTALLED
1784 for i in * ; do
1785 DEPENDS=""
1786 . $i/receipt
1787 for j in $DEPENDS ; do
1788 [ -d $j ] || tazpkg get-install $j
1789 done
1790 done ;;
1793 remove|-r)
1794 # Remove packages.
1795 check_root $@
1796 check_for_package_on_cmdline
1797 check_for_installed_info
1799 [ -n "$root" ] && ROOT="$root"
1801 if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then
1802 newline; _ 'Package "%s" is not installed.' $PACKAGE
1803 exit 0
1804 fi
1806 . $ROOT$INSTALLED/$PACKAGE/receipt
1808 # Info #1: dependent packages (to be processed later)
1809 ALTERED="$(awk -F$'\t' -vp=" $PACKAGE " '
1810 index(" " $8 " ", p) { printf " %s\n", $1 }
1811 ' $ROOT/$PKGS_DB/installed.info)"
1813 if [ -n "$ALTERED" ]; then
1814 _ 'The following packages depend on package "%s":' $PACKAGE
1815 echo "$ALTERED"
1816 fi
1818 # Info #2: changed packages (to be processed later)
1819 REFRESH=$(cd $ROOT$INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1821 if [ -n "$REFRESH" ]; then
1822 _ 'The following packages have been modified by package "%s":' $PACKAGE
1823 for i in $REFRESH; do
1824 echo " ${i%/modifiers}"
1825 done
1826 fi
1828 # Confirmation
1829 if im && [ -z "$auto" ]; then
1830 confirm "$(_ 'Remove package "%s" (%s)? (y/N)' $PACKAGE $VERSION$EXTRAVERSION)"
1831 if [ $? != 0 ]; then
1832 newline; _ 'Uninstallation of package "%s" cancelled.' $PACKAGE
1833 exit 0
1834 fi
1835 fi
1836 # We are here: non-interactive mode, or --auto, or answer 'y'
1838 # Removing package
1839 title 'Removing package "%s"' $PACKAGE
1841 # [1/4] Pre-remove commands
1842 if grep -q ^pre_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1843 action "Execution of pre-remove commands..."
1844 pre_remove $ROOT
1845 status
1846 fi
1848 # [2/4] Removing files
1849 action "Removing all files installed..."
1850 if [ -f $ROOT$INSTALLED/$PACKAGE/modifiers ]; then
1851 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1852 for mod in $(cat $ROOT$INSTALLED/$PACKAGE/modifiers); do
1853 [ -f $ROOT$INSTALLED/$mod/files.list ] && \
1854 [ $(grep "^$(echo $file | grepesc)$" $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && \
1855 continue 2
1856 done
1857 remove_with_path $ROOT$file
1858 done
1859 else
1860 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1861 remove_with_path $ROOT$file
1862 done
1863 fi
1864 status
1866 # [3/4] Post-remove commands
1867 if grep -q ^post_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1868 action "Execution of post-remove commands..."
1869 post_remove $ROOT
1870 status
1871 fi
1873 # [4/4] Remove package receipt and remove it from databases
1874 action "Removing package receipt..."
1875 rm -rf $ROOT$INSTALLED/$PACKAGE
1876 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg$/d" $PKGS_DB/installed.$SUM
1877 sed -i "/^$PACKAGE /d" $PKGS_DB/installed.info
1878 status
1880 footer "$(_ 'Package "%s" (%s) removed.' $PACKAGE $VERSION$EXTRAVERSION)"
1882 # Log this activity
1883 log_pkg Removed
1885 # Stop if non-interactive mode and no --auto option
1886 if ! im && [ -z "$auto" ]; then exit 0; fi
1888 # Process dependent packages
1889 if [ -n "$ALTERED" ]; then
1890 if [ "$auto" ]; then
1891 answer=0
1892 else
1893 confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' $PACKAGE)"
1894 answer=$?
1895 fi
1896 if [ $answer = 0 ]; then
1897 for i in $ALTERED; do
1898 if [ -d "$ROOT$INSTALLED/$i" ]; then
1899 echo "tazpkg remove $i $ROOTOPTS"
1900 fi
1901 done
1902 fi
1903 fi
1905 # Process changed packages
1906 if [ -n "$REFRESH" ]; then
1907 if [ "$auto" ]; then
1908 answer=0
1909 else
1910 confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' $PACKAGE)"
1911 answer=$?
1912 fi
1913 if [ $answer = 0 ]; then
1914 for i in $REFRESH; do
1915 if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then
1916 _ 'Check %s for reinstallation' "$INSTALLED/$i"
1917 continue
1918 fi
1919 echo "rm -r $ROOT$INSTALLED/$i"
1920 echo "tazpkg get-install ${i%/modifiers} $ROOTOPTS --forced"
1921 done
1922 fi
1923 fi
1925 ;;
1928 extract|-e)
1929 # Extract .tazpkg cpio archive into a directory.
1930 check_for_package_on_cmdline
1931 check_for_package_file
1932 title 'Extracting package "%s"' $PACKAGE
1934 # If no directory destination is found on the cmdline
1935 # we create one in the current dir using the package name.
1936 if [ -n "$TARGET_DIR" ]; then
1937 DESTDIR=$TARGET_DIR/$PACKAGE
1938 else
1939 DESTDIR=$PACKAGE
1940 fi
1941 mkdir -p $DESTDIR
1943 action "Copying original package..."
1944 cp $PACKAGE_FILE $DESTDIR
1945 status
1947 cd $DESTDIR
1948 extract_package
1949 [ -e "receipt" ] && \
1950 footer "$(_ 'Package "%s" is extracted to "%s"' $PACKAGE $DESTDIR)"
1951 ;;
1954 recompress)
1955 # Recompress .tazpkg cpio archive with lzma.
1956 check_for_package_on_cmdline
1957 check_for_package_file
1958 title 'Recompressing package "%s"' $PACKAGE
1959 mkdir -p $TMP_DIR
1961 action "Copying original package..."
1962 cp $PACKAGE_FILE $TMP_DIR
1963 status
1965 cd $TMP_DIR
1966 extract_package
1968 action "Recompressing the FS..."
1969 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1970 rm -rf fs
1971 status
1973 action "Creating new package..."
1974 find . -print | cpio -o -H newc --quiet > \
1975 $TOP_DIR/$(basename $PACKAGE_FILE).$$ && mv -f \
1976 $TOP_DIR/$(basename $PACKAGE_FILE).$$ \
1977 $TOP_DIR/$(basename $PACKAGE_FILE)
1978 status
1980 cd $TOP_DIR
1981 rm -rf $TMP_DIR
1982 separator; newline ;;
1985 list-config)
1986 # List configuration files installed.
1987 if [ -n "$box" ]; then
1988 mkdir -p $TMP_DIR; cd $TMP_DIR
1989 FILES="$INSTALLED/*/volatile.cpio.gz"
1990 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
1991 for i in $FILES; do
1992 zcat $i | cpio -idm --quiet > /dev/null
1993 find * -type f 2>/dev/null | while read file; do
1994 if [ ! -e /$file ]; then
1995 echo -n "----------|----|----|$(_n 'File lost')"
1996 else
1997 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
1998 cmp $file /$file > /dev/null 2>&1 || \
1999 echo -n "$(stat -c "%.16y" /$file)"
2000 fi
2001 echo "|/$file"
2002 done
2003 rm -rf *
2004 done
2005 cd $TOP_DIR
2006 rm -rf $TMP_DIR
2007 else
2008 im && title 'Configuration files'
2009 for i in $INSTALLED/*/volatile.cpio.gz; do
2010 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
2011 [ -f "$i" ] || continue
2012 zcat $i | cpio -t --quiet
2013 done | sed 's|^|/|' | sort
2014 im && footer
2015 fi ;;
2018 repack-config)
2019 # Create SliTaz package archive from configuration files.
2020 mkdir -p $TMP_DIR; cd $TMP_DIR
2021 CONFIG_VERSION=1.0
2022 mkdir config-$CONFIG_VERSION
2023 cd config-$CONFIG_VERSION
2024 for i in $INSTALLED/*/volatile.cpio.gz; do
2025 zcat $i | cpio -t --quiet
2026 done > files.list
2027 mkdir fs
2028 cd fs
2029 ( cd / ; cpio -o -H newc --quiet ) < ../files.list | cpio -idm --quiet > /dev/null
2030 mkdir -p etc/tazlito
2031 for i in $INSTALLED/*/receipt; do
2032 EXTRAVERSION=""
2033 . $i
2034 echo "$PACKAGE-$VERSION$EXTRAVERSION"
2035 done > etc/tazlito/config-packages.list
2036 cd ..
2037 echo "etc/tazlito/config-packages.list" >> files.list
2038 pkg_date=$(date +"%x %X")
2039 cat > receipt <<EOT
2040 # SliTaz package receipt.
2042 PACKAGE="config"
2043 VERSION="$CONFIG_VERSION"
2044 CATEGORY="base-system"
2045 SHORT_DESC="$(_n 'User configuration backup on date %s' $pkg_date)"
2046 DEPENDS="$(ls $INSTALLED)"
2047 EOT
2048 cd ..
2049 tazpkg pack config-$CONFIG_VERSION
2050 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
2051 cd $TOP_DIR
2052 rm -rf $TMP_DIR
2053 ;;
2056 repack)
2057 # Create SliTaz package archive from an installed package.
2058 check_for_package_on_cmdline
2059 check_for_receipt
2060 EXTRAVERSION=""
2061 . $INSTALLED/$PACKAGE/receipt
2062 title 'Repacking "%s"' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
2064 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
2065 _ "Can't repack package \"%s\"" $PACKAGE
2066 exit 1
2067 fi
2069 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
2070 _ "Can't repack, \"%s\" files have been modified by:" $PACKAGE
2071 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
2072 echo " $i"
2073 done
2074 exit 1
2075 fi
2077 MISSING=""
2078 while read i; do
2079 [ -e "$i" ] && continue
2080 [ -L "$i" ] || MISSING="$MISSING\n $i"
2081 done < $INSTALLED/$PACKAGE/files.list
2082 if [ -n "$MISSING" ]; then
2083 _n "Can't repack, the following files are lost:"
2084 echo -e "$MISSING"
2085 exit 1
2086 fi
2088 mkdir -p $TMP_DIR; cd $TMP_DIR
2089 FILES="fs.cpio.lzma\n"
2090 for i in $(ls $INSTALLED/$PACKAGE); do
2091 case $i in
2092 volatile.cpio.gz|modifiers) ;;
2093 *) cp $INSTALLED/$PACKAGE/$i .; FILES="$FILES$i\n" ;;
2094 esac
2095 done
2097 ln -s / rootfs
2098 mkdir tmp
2099 sed 's/^/rootfs/' < files.list | cpio -o -H newc --quiet | \
2100 { cd tmp ; cpio -idm --quiet >/dev/null; cd ..; }
2101 mv tmp/rootfs fs
2103 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
2104 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
2105 { cd fs; cpio -idm --quiet; cd ..; }
2106 fi
2108 if fgrep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
2109 . $INSTALLED/$PACKAGE/receipt
2110 repack_cleanup fs
2111 fi
2113 if [ -f $INSTALLED/$PACKAGE/$CHECKSUM ]; then
2114 sed 's, , fs,' < $INSTALLED/$PACKAGE/$CHECKSUM | \
2115 $CHECKSUM -s -c || {
2116 _ "Can't repack, %s error." $CHECKSUM
2117 cd $TOP_DIR
2118 rm -rf $TMP_DIR
2119 exit 1
2121 fi
2123 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2124 echo -e "$FILES" | cpio -o -H newc --quiet > \
2125 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
2126 cd $TOP_DIR
2127 \rm -R $TMP_DIR
2128 _ 'Package "%s" repacked successfully.' $PACKAGE
2129 _ 'Size: %s' "$(du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg)"
2130 newline ;;
2133 pack)
2134 # Create SliTaz package archive using cpio and lzma.
2135 # TODO: Cook also pack packages, we should share code in libpkg.sh
2136 check_for_package_on_cmdline
2137 cd $PACKAGE
2138 if [ ! -f "receipt" ]; then
2139 _ 'Receipt is missing. Please read the documentation.'
2140 exit 0
2141 fi
2143 title 'Packing package "%s"' $PACKAGE
2144 # Create files.list with redirecting find outpout.
2146 action "Creating the list of files..."
2147 cd fs
2148 find . -type f -print > ../files.list
2149 find . -type l -print >> ../files.list
2150 cd .. && sed -i s/'^.'/''/ files.list
2151 status
2153 action 'Creating %s of files...' $CHECKSUM
2154 while read file; do
2155 [ -L "fs$file" ] && continue
2156 [ -f "fs$file" ] || continue
2157 case "$file" in
2158 /lib/modules/*/modules.*|*.pyc) continue;;
2159 esac
2160 $CHECKSUM "fs$file" | sed 's/ fs/ /'
2161 done < files.list > $CHECKSUM
2162 status
2164 UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
2165 description.txt 2> /dev/null | awk \
2166 '{ sz=$1 } END { print sz }')
2167 # Build cpio archives.
2169 action "Compressing the FS..."
2170 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2171 rm -rf fs
2172 status
2174 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
2175 $CHECKSUM description.txt 2> /dev/null | awk \
2176 '{ sz=$1 } END { print sz }')
2178 action "Updating receipt sizes..."
2179 sed -i s/^PACKED_SIZE.*$// receipt
2180 sed -i s/^UNPACKED_SIZE.*$// receipt
2181 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
2182 status
2184 action "Creating full cpio archive..."
2185 find . -print | cpio -o -H newc --quiet > ../$PACKAGE.tazpkg
2186 status
2188 action "Restoring original package tree..."
2189 unlzma -c fs.cpio.lzma | cpio -idm --quiet
2190 status
2192 rm fs.cpio.lzma && cd ..
2193 footer "$(_ 'Package "%s" compressed successfully.' $PACKAGE)"
2194 _ 'Size: %s' "$(ls -lh $PACKAGE.tazpkg | awk '{print $5}')"
2195 ;;
2198 recharge)
2199 # Recharge packages databases from a mirror.
2201 # WARNING: The 'mirrors' file has all SliTaz mirrors but 'mirror'
2202 # must have only the chosen main mirror.
2204 check_root $@
2206 # usage: tazpkg recharge [--root=path] [main|<repository>]
2208 ARG="$2"
2209 if [ -n "$root" ]; then
2210 PKGS_DB="$root$PKGS_DB"
2211 [ "${2#--}" != "$2" ] && ARG="$3"
2212 fi
2214 case "$ARG" in
2215 main) repo_to_recharge="$PKGS_DB";;
2216 '') repo_to_recharge="$PKGS_DB $PKGS_DB/undigest/*";;
2217 *) repo_to_recharge="$PKGS_DB/undigest/$ARG"
2218 if [ ! -d "$repo_to_recharge" ]; then
2219 _ "Repository \"%s\" doesn't exist." "$repo_to_recharge" >&2
2220 exit 1
2221 fi
2222 ;;
2223 esac
2225 for path in $repo_to_recharge; do
2226 [ ! -f $path/mirror ] && continue # skip
2227 cd $path
2228 mirror="$(cat mirror)"
2230 # Repository name
2231 if [ "$path" == "$PKGS_DB" ]; then
2232 repo_name='Main'
2233 else
2234 repo_name="$(_n 'Undigest %s' "$(basename $path)")"
2235 fi
2237 # Don't let ID be a symlink when using local repository.
2238 if [ -h ID ]; then mv -f ID ID.lnk; cat ID.lnk > ID; rm ID.lnk; fi
2239 if [ -h IDs ]; then mv -f IDs IDs.lnk; cat IDs.lnk > IDs; rm IDs.lnk; fi
2241 [ -f ID ] && mv ID ID.bak # Compatibility with "old" ID
2242 [ -f IDs ] && mv IDs IDs.bak
2243 download_from "$mirror" IDs
2244 [ -e 'IDs' ] && awk '{print $1}' IDs > ID # Compatibility with "old" ID
2246 # Check if recharging is needed
2247 if [ -f 'IDs' ] && cmp -s IDs IDs.bak; then
2248 _ 'Repository "%s" is up to date.' "$repo_name"
2249 rm IDs.bak ID.bak
2250 continue
2251 fi
2253 title 'Recharging repository "%s"' "$repo_name"
2254 [ -e 'IDs' ] && _ 'Database timestamp: %s' "$(date -d "@$(awk '{print $2}' IDs)" "+%x %R")"
2256 action 'Creating backup of the last packages list...'
2257 for i in packages.desc packages.$SUM packages.txt packages.list \
2258 packages.equiv files.list.lzma extra.list mirrors packages.info; do
2259 [ -f "$i" ] && mv -f $i $i.bak 2>/dev/null
2260 done
2261 status
2263 # Download and extract bundle: extra.list, mirrors, files-list.md5,
2264 # packages.{info,desc,md5,txt,list,equiv}
2265 bundle='bundle.tar.lzma'
2266 action 'Getting "%s"...' $bundle
2267 download_from "$mirror" $bundle
2268 status
2269 if [ -f "$bundle" ]; then
2270 busybox tar -xaf $bundle; rm $bundle
2271 else
2272 recharging_failed $path; continue
2273 fi
2275 # Download files.list.lzma
2276 files_local='files.list.lzma'; files_remote='files-list.lzma'
2277 if [ -e "$files_local.bak" ]; then
2278 md5sum $files_local.bak | awk '{printf $1}' > files-list.md5.bak
2279 if cmp -s files-list.md5 files-list.md5.bak; then
2280 mv $files_local.bak $files_remote
2281 else
2282 action 'Getting "%s"...' $files_remote
2283 download_from "$mirror" $files_remote
2284 status
2285 fi
2286 else
2287 action 'Getting "%s"...' $files_remote
2288 download_from "$mirror" $files_remote
2289 status
2290 fi
2292 if [ ! -e "$files_remote" ]; then
2293 recharging_failed $path; continue
2294 fi
2295 mv -f $files_remote $files_local
2297 # Remove old database files (but packages.list.bak, extra.list.bak)
2298 for i in packages.desc packages.$SUM packages.txt packages.equiv \
2299 files.list.lzma mirrors packages.info files-list.md5; do
2300 [ -f "$i.bak" ] && rm $i.bak 2>/dev/null
2301 done
2303 footer "$(_ 'Last database is ready to use.')"
2305 # Check diff
2306 if [ -f 'packages.list.bak' ]; then
2307 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
2308 rm packages.list.bak
2309 if [ -f 'extra.list.bak' ]; then
2310 if [ -f 'extra.list' ]; then
2311 diff -u extra.list.bak extra.list | grep ^+[a-z] >> packages.diff
2312 rm extra.list.bak
2313 else
2314 mv extra.list.bak extra.list
2315 fi
2316 fi
2317 sed -i s/+// packages.diff
2319 new_pkgs=$(wc -l < packages.diff)
2320 if [ "$new_pkgs" -gt 0 ]; then
2321 title 'Mirrored packages diff'
2322 cat packages.diff
2323 footer "$(emsg "$(_p \
2324 '%s new package on the mirror.' \
2325 '%s new packages on the mirror.' $new_pkgs \
2326 "<c 32>$new_pkgs</c>")")"
2327 fi
2328 else
2329 longline "$(_ "Note that next time you recharge the \
2330 list, a list of differences will be displayed to show new and upgradeable \
2331 packages.")"
2332 fi
2333 done ;;
2336 help-up)
2337 # Options available for the command: up
2338 newline; usage_up; newline
2339 exit 1 ;;
2342 up|upgrade)
2343 check_root
2345 # This is the new way to upgrade packages making 'upgrade' and
2346 # upgradeable out-of-date. This new way is much, much more faster!
2347 # Look into installed packages and get data from receipt, it is fast
2348 # and easy to handle vars after using only md5sum to compare packages
2350 for opt in $@; do
2351 case "$opt" in
2352 --recharge|-r) tazpkg recharge ;;
2353 --install|-i) install="y" ;;
2354 --check|-c) install="n" ;;
2355 esac
2356 done
2357 time=$(date +%s)
2359 look_for_priority
2360 for repo in $priority; do
2361 pkg_list=$repo/packages.list
2362 mtime=$(find $pkg_list -mtime +7)
2363 if [ "$mtime" ]; then
2364 if [ "$repo" == "$PKGS_DB" ]; then
2365 repo_name=main
2366 else
2367 repo_name="${repo##*/}"
2368 fi
2369 _ 'List "%s" is older than one week... Recharging.' $pkg_list
2370 tazpkg recharge $repo_name
2371 fi
2372 done
2374 emsg "<n>$(_ 'Package')<i 28> $(_ 'Version')<i 48> $(_ 'Status')<->"
2376 cd $INSTALLED
2377 echo -n > $UP_LIST
2378 blocked_count=0
2379 installed_sum=$PKGS_DB/installed.$SUM
2381 for pkg in *; do
2382 [ ! -d $pkg ] && continue
2383 unset VERSION EXTRAVERSION
2384 . $pkg/receipt
2385 md5=$(fgrep " $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" \
2386 $installed_sum | awk '{print $1}')
2387 for repo in $priority; do
2388 pkg_desc=$repo/packages.desc
2389 pkg_list=$repo/packages.list
2390 pkg_sum=$repo/packages.$SUM
2392 if ! fgrep -q "$md5 $PACKAGE-" $pkg_sum; then
2393 # Jump to next repository in priority if pkg doesn't exist
2394 # in this one.
2395 grep -q ^$PACKAGE- $pkg_list || continue
2397 emsg -n "$PACKAGE<i 28> $VERSION"
2399 # Skip pkgs listed in $PKGS_DB/blocked-packages.list
2400 if $(grep -qs "^$PACKAGE" $BLOCKED); then
2401 blocked_count=$(($blocked_count + 1))
2402 emsg "<i 48><c 31> $(_ 'Blocked')</c>"
2403 break
2404 fi
2406 new=$(grep "^$PACKAGE |" $pkg_desc | awk '{print $3}')
2408 if [ "$VERSION" == "$new" ]; then
2409 emsg "<i 48><c 34> $(_ 'New build')</c>"
2410 else
2411 emsg "<i 48><c 32> $(_ 'New version %s' $new)</c>"
2412 fi
2413 echo "$PACKAGE" >> $UP_LIST
2414 break
2415 fi
2416 done
2417 done
2418 sed -i /^$/d $UP_LIST
2419 upnb=$(wc -l < $UP_LIST)
2420 pkgs=$(ls | wc -l)
2421 time=$(($(date +%s) - $time))
2422 if [ "$upnb" == 0 ]; then
2423 install="n"
2424 _ 'System is up-to-date...'
2425 fi
2427 footer "$(emsg "$(_p \
2428 '%s installed package scanned in %ds' \
2429 '%s installed packages scanned in %ds' $pkgs \
2430 "<c 32>$pkgs</c>" $time)")"
2432 if [ "$upnb" != 0 ]; then
2433 blocked="$(_p \
2434 '%s blocked' \
2435 '%s blocked' $blocked_count \
2436 $blocked_count)"
2438 boldify "$(_p \
2439 'You have %s available upgrade (%s)' \
2440 'You have %s available upgrades (%s)' $upnb \
2441 $upnb "$blocked")"
2442 newline
2443 fi
2444 # Pkgs to upgrade ? Skip, let install them all or ask user
2445 [ "$install" == "n" ] && exit 0
2446 if [ "$upnb" -gt 0 ]; then
2447 if [ "$install" == "y" ]; then
2448 answer=0
2449 else
2450 confirm "$(_ 'Do you wish to install them now? (y/N)')"
2451 answer=$?
2452 fi
2453 case "$answer" in
2454 0)
2455 for pkg in $(cat $UP_LIST); do
2456 echo 'y' | tazpkg get-install $pkg --forced
2457 done
2458 # List is generated each time and must be cleaned so
2459 # tazpkg-notify doesn't find upgrades anymore.
2460 rm $UP_LIST; touch $UP_LIST ;;
2461 *)
2462 _ 'Leaving without any upgrades installed.'
2463 newline
2464 exit 0 ;;
2465 esac
2466 fi
2467 newline ;;
2470 bugs)
2471 # Show known bugs in package(s)
2472 cd $INSTALLED
2473 shift
2474 LIST=$@
2475 [ -n "$LIST" ] || LIST=$(ls)
2476 MSG=$(_n 'No known bugs.')
2477 for PACKAGE in $LIST; do
2478 BUGS=""
2479 EXTRAVERSION=""
2480 . $PACKAGE/receipt
2481 if [ -n "$BUGS" ]; then
2482 MSG=$(_n 'Bug list completed')
2483 newline
2484 _ 'Bugs in package "%s" version %s:' $PACKAGE $VERSION$EXTRAVERSION
2485 cat <<EOT
2486 $BUGS
2487 EOT
2488 fi
2489 done
2490 echo "$MSG" ;;
2493 check)
2494 # Check installed packages set.
2495 check_root $@
2497 # Get repositories priority list.
2498 look_for_priority
2500 cd $INSTALLED
2501 for PACKAGE in $(ls); do
2503 if [ ! -f $PACKAGE/receipt ]; then
2504 _ 'The package "%s" installation has not completed' $PACKAGE
2505 continue
2506 fi
2508 DEPENDS=""
2509 EXTRAVERSION=""
2510 . $PACKAGE/receipt
2511 if [ -s $PACKAGE/modifiers ]; then
2512 _ 'The package "%s" has been modified by:' $PACKAGE-$VERSION$EXTRAVERSION
2513 for i in $(cat $PACKAGE/modifiers); do
2514 echo " $i"
2515 done
2516 fi
2518 MSG="$(_n 'Files lost from package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2519 while read file; do
2520 [ -e "$file" ] && continue
2521 if [ -L "$file" ]; then
2522 MSG="$MSG $(_n 'target of symlink')"
2523 fi
2524 echo -e "$MSG $file"
2525 MSG=""
2526 done < $PACKAGE/files.list
2528 MSG="$(_n 'Missing dependencies for package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2529 for i in $DEPENDS; do
2530 [ -d $i ] && continue
2531 [ -d $(equivalent_pkg $i) ] && continue
2532 echo -e "$MSG $i"
2533 MSG=""
2534 done
2536 MSG="$(_n 'Dependencies loop between "%s" and:' $PACKAGE)\n"
2537 ALL_DEPS=""
2538 check_for_deps_loop $PACKAGE $DEPENDS
2539 done
2541 _ 'Looking for known bugs...'
2542 tazpkg bugs
2544 if [ "$2" == "--full" ]; then
2545 separator
2547 for file in */$CHECKSUM; do
2548 CONFIG_FILES=""
2549 . $(dirname "$file")/receipt
2550 [ -s "$file" ] || continue
2551 while read md5 f; do
2552 [ -f $f ] || continue
2553 for i in $CONFIG_FILES; do
2554 case "$f" in
2555 $i|$i/*) continue 2;;
2556 esac
2557 done
2558 echo "$md5 $f"
2559 done < "$file" | busybox $CHECKSUM -c - 2> /dev/null | \
2560 grep -v OK$ | sed "s/FAILED$/$CHECKSUM MISMATCH/"
2561 done
2563 FILES=" "
2564 for file in $(cat */files.list); do
2565 [ -d "$file" ] && continue
2566 case "$FILES" in *\ $file\ *) continue;; esac
2567 [ $(grep "^$(echo $file | grepesc)$" */files.list 2> /dev/null | \
2568 wc -l) -gt 1 ] || continue
2569 FILES="$FILES$file "
2570 _ 'The following packages provide file "%s":' $file
2571 grep -l "^$(echo $file | grepesc)$" */files.list | \
2572 while read f; do
2573 pkg=${f%/files.list}
2574 if [ -f $pkg/modifiers ]; then
2575 overriders=$(_n '(overridden by %s)' "$(tr '\n' ' ' | sed 's| $||' < $pkg/modifiers)")
2576 else
2577 overriders=''
2578 fi
2579 echo -n " $pkg $overriders"
2580 newline
2581 done
2582 done
2584 MSG="$(_n 'No package has installed the following files:')\n"
2585 find /etc /bin /sbin /lib /usr /var/www -not -type d 2>/dev/null | \
2586 while read file; do
2587 case "$file" in *\[*) continue;; esac
2588 grep -q "^$(echo $file | grepesc)$" */files.list && continue
2589 echo -e "$MSG $file"
2590 MSG=""
2591 done
2592 fi
2593 _ 'Check completed.'; echo ;;
2596 block|-b)
2597 # Add a pkg name to the list of blocked packages.
2598 check_root $@
2599 check_for_package_on_cmdline
2600 newline
2601 if [ ! -d $INSTALLED/$PACKAGE ]; then
2602 _ 'Package "%s" is not installed.' $PACKAGE; exit
2603 fi
2604 if grep -qs "^$PACKAGE" $BLOCKED; then
2605 _ 'Package "%s" is already blocked.' $PACKAGE
2606 else
2607 echo $PACKAGE >> $BLOCKED
2608 # Log this activity
2609 . $INSTALLED/$PACKAGE/receipt; log_pkg Blocked
2610 _ 'Package "%s" blocked.' $PACKAGE
2611 fi
2612 newline ;;
2615 unblock|-u)
2616 # Remove a pkg name from the list of blocked packages.
2617 check_root $@
2618 check_for_package_on_cmdline
2619 newline
2620 if [ ! -d $INSTALLED/$PACKAGE ]; then
2621 _ 'Package "%s" is not installed.' $PACKAGE; exit
2622 fi
2623 if grep -qs "^$PACKAGE" $BLOCKED; then
2624 sed -i "/^$PACKAGE\$/d" $BLOCKED
2625 # Log this activity
2626 . $INSTALLED/$PACKAGE/receipt; log_pkg Unblocked
2627 _ 'Package "%s" unblocked.' $PACKAGE
2628 else
2629 _ 'Package "%s" is not blocked.' $PACKAGE
2630 fi
2631 newline ;;
2634 chblock)
2635 # Change package's blocked status.
2636 check_root $@
2637 check_for_package_on_cmdline
2638 newline
2639 if [ ! -d $INSTALLED/$PACKAGE ]; then
2640 _ 'Package "%s" is not installed.' $PACKAGE; exit
2641 fi
2642 if grep -qs "^$PACKAGE" $BLOCKED; then
2643 sed -i "/^$PACKAGE\$/d" $BLOCKED
2644 # Log this activity
2645 . $INSTALLED/$PACKAGE/receipt; log_pkg Unblocked
2646 _ 'Package "%s" unblocked.' $PACKAGE
2647 else
2648 echo $PACKAGE >> $BLOCKED
2649 # Log this activity
2650 . $INSTALLED/$PACKAGE/receipt; log_pkg Blocked
2651 _ 'Package "%s" blocked.' $PACKAGE
2652 fi
2653 newline ;;
2656 get|-g)
2657 # Download a package with wget.
2658 check_root $@
2659 check_for_package_on_cmdline
2660 check_for_packages_list
2662 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2663 if [ "$rootconfig" ]; then
2664 if [ "$root" ]; then
2665 CACHE_DIR=$root/$CACHE_DIR
2666 SAVE_CACHE_DIR=$CACHE_DIR
2667 PKGS_DB=$root/$PKGS_DB
2668 else
2669 _ 'rootconfig needs --root= option used.' >&2
2670 exit 1
2671 fi
2672 fi
2674 # Get repositories priority list.
2675 look_for_priority
2677 CURRENT_DIR=$PWD
2678 cd $CACHE_DIR
2679 if check_for_package_in_list check ; then
2680 if [ -f "$PACKAGE.tazpkg" ]; then
2681 _ 'Package "%s" already in the cache' $PACKAGE
2682 # Check package download was finished
2683 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2684 _ 'Continuing package "%s" download' $PACKAGE
2685 download $PACKAGE.tazpkg
2687 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2688 rm -f $PACKAGE.tazpkg
2689 download $PACKAGE.tazpkg
2690 fi
2691 else
2692 download $PACKAGE.tazpkg
2693 fi
2694 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2695 elif download_get_script $PACKAGE /tmp/$PACKAGE.$$ ; then
2696 install_package_from_get_script /tmp/$PACKAGE.$$ "$ROOT" --get
2697 PACKAGE_FILE=$(ls $PWD/$PACKAGE-*.tazpkg)
2698 fi
2699 [ "$PWD" != "$CURRENT_DIR" ] &&
2700 cp -a $PACKAGE_FILE $CURRENT_DIR ;;
2703 get-install|-gi)
2704 # Download and install a package.
2705 check_root $@
2706 check_for_package_on_cmdline
2707 check_for_packages_list
2709 DO_CHECK=""
2710 [ "$forced" ] && DO_CHECK=no
2711 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2712 [ "$list" ] && INSTALL_LIST="$list"
2713 if [ "$rootconfig" ]; then
2714 if [ "$root" ]; then
2715 CACHE_DIR=$root/$CACHE_DIR
2716 SAVE_CACHE_DIR=$CACHE_DIR
2717 PKGS_DB=$root/$PKGS_DB
2718 else
2719 _ 'rootconfig needs --root= option used.' >&2
2720 exit 1
2721 fi
2722 fi
2724 # Get repositories priority list.
2725 look_for_priority
2727 AUTOEXEC="no"
2728 if ! check_for_package_in_list check; then
2729 CACHE_DIR="${CACHE_DIR%/*}/get"
2730 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
2731 if download_get_script $PACKAGE /tmp/$PACKAGE.$$ ; then
2732 install_package_from_get_script /tmp/$PACKAGE.$$ $ROOT
2733 exit 0
2734 else
2735 PACKAGE=get-$PACKAGE
2736 AUTOEXEC=$PACKAGE
2737 check_for_package_in_list
2738 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
2739 $AUTOEXEC $ROOT
2740 exit 0
2741 fi
2742 fi
2743 fi
2744 # Check if forced install.
2745 if ! [ "$forced" ]; then
2746 check_for_installed_package $ROOT
2747 fi
2748 cd $CACHE_DIR
2749 if [ -f "$PACKAGE.tazpkg" ]; then
2750 _ 'Package "%s" already in the cache' $PACKAGE
2751 # Check package download was finished
2752 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2753 _ 'Continuing package "%s" download' $PACKAGE
2754 download $PACKAGE.tazpkg
2756 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2757 rm -f $PACKAGE.tazpkg
2758 download $PACKAGE.tazpkg
2759 fi
2760 else
2761 newline
2762 download $PACKAGE.tazpkg
2763 fi
2764 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2765 [ "$rootconfig" ] && PKGS_DB=${PKGS_DB#$root}
2766 install_package $ROOT
2767 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
2768 update_desktop_database $ROOT
2769 update_mime_database $ROOT ;;
2772 clean-cache|-cc)
2773 # Remove all downloaded packages.
2774 check_root $@
2775 files=$(find $CACHE_DIR -name *.tazpkg | wc -l)
2776 size=$(du -hs $CACHE_DIR | cut -f1 | sed 's|\.0||'); [ $files == "0" ] && size="0K"
2777 title 'Path: %s' $CACHE_DIR
2778 action "Cleaning cache directory..."
2779 rm -rf $CACHE_DIR/*
2780 status
2782 footer "$(_p \
2783 '%s file removed from cache (%s).' \
2784 '%s files removed from cache (%s).' $files \
2785 "$(colorize 32 "$files")" $size)"
2786 ;;
2789 list-undigest)
2790 # list undigest URLs.
2791 if [ "$2" = "--box" ]; then
2792 for i in $PKGS_DB/undigest/*/mirror; do
2793 [ -f $i ] || continue
2794 echo "$(basename $(dirname $i))|$(cat $i)"
2795 done
2796 else
2797 title 'Current undigest(s)'
2798 for i in $PKGS_DB/undigest/*/mirror; do
2799 if [ ! -f $i ]; then
2800 _ 'No undigest mirror found.'
2801 exit 1
2802 fi
2803 echo "$(basename $(dirname $i)) $(cat $i)"
2804 done
2805 newline
2806 fi ;;
2809 remove-undigest)
2810 # remove undigest URL.
2811 check_root $@
2812 undigest="$2"
2813 if [ -d $PKGS_DB/undigest/$2 ]; then
2814 confirm "$(_ 'Remove "%s" undigest? (y/N)' $undigest)"
2815 if [ $? = 0 ]; then
2816 action 'Removing "%s" undigest...' $undigest
2817 rm -rf $PKGS_DB/undigest/$2
2818 status
2819 rmdir $PKGS_DB/undigest 2> /dev/null
2820 fi
2821 else
2822 _ 'Undigest "%s" not found' $undigest
2823 fi ;;
2826 add-undigest|setup-undigest)
2827 # Add undigest URL.
2828 check_root $@
2829 undigest=$2
2830 [ -d $PKGS_DB/undigest ] || mkdir $PKGS_DB/undigest
2831 if [ -z "$undigest" ]; then
2832 i=1
2833 while [ -d $PKGS_DB/undigest/$i ]; do
2834 i=$(($i+1))
2835 done
2836 undigest=$i
2837 fi
2838 if [ ! -d $PKGS_DB/undigest/$undigest ]; then
2839 _ 'Creating new undigest "%s".' $undigest
2840 mkdir $PKGS_DB/undigest/$undigest
2841 fi
2842 setup_mirror $PKGS_DB/undigest/$undigest $3 ;;
2845 setup-mirror|-sm)
2846 # Change mirror URL.
2847 check_root $@
2848 setup_mirror $PKGS_DB $2 ;;
2851 reconfigure)
2852 # Replay post_install from receipt
2853 check_for_package_on_cmdline
2854 check_root $@
2855 ROOT=""
2856 while [ -n "$3" ]; do
2857 case "$3" in
2858 --root=*)
2859 ROOT="${3#--root=}/" ;;
2860 *)
2861 shift 2
2862 u_opt="$*"
2863 newline >&2
2864 _ 'Unknown option "%s".' $u_opt >&2
2865 exit 1 ;;
2866 esac
2867 shift
2868 done
2869 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2870 check_for_receipt $ROOT
2871 # Check for post_install
2872 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2873 . $ROOT$INSTALLED/$PACKAGE/receipt
2874 post_install $ROOT
2875 # Log this activity
2876 [ -n "$ROOT" ] || log_pkg Reconfigured
2877 else
2878 newline
2879 _ 'Nothing to do for package "%s".' $PACKAGE
2880 fi
2881 else
2882 newline
2883 _ 'Package "%s" is not installed.' $PACKAGE
2884 _ 'Install package with "%s" or "%s"' 'tazpkg install' 'tazpkg get-install'
2885 newline
2886 fi ;;
2889 shell)
2890 # TazPKG SHell
2891 if test $(id -u) = 0 ; then
2892 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2893 else
2894 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2895 fi
2896 if [ ! "$2" = "--noheader" ]; then
2897 clear
2898 title 'TazPKG SHell.'
2899 _ "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
2900 newline
2901 fi
2902 while true; do
2903 echo -en "$PROMPT"; read cmd
2904 case $cmd in
2905 q|quit)
2906 break ;;
2907 shell)
2908 _ 'You are already running a TazPKG SHell.' ;;
2909 su)
2910 su -c 'exec tazpkg shell --noheader' && break ;;
2911 "")
2912 continue ;;
2913 *)
2914 tazpkg $cmd ;;
2915 esac
2916 done ;;
2919 depends)
2920 # Display dependencies tree
2921 cd $INSTALLED
2922 ALL_DEPS=""
2923 if [ -f $2/receipt ]; then
2924 dep_scan $2 ""
2925 fi ;;
2928 rdepends)
2929 # Display reverse dependencies tree
2930 cd $INSTALLED
2931 ALL_DEPS=""
2932 if [ -f $2/receipt ]; then
2933 rdep_scan $2
2934 fi ;;
2937 list-suggested)
2938 for i in $(ls -d $INSTALLED/*); do
2939 . $i/receipt
2940 if [ "$SUGGESTED" ]; then
2941 if [ -z "$all" ]; then
2942 for s in $SUGGESTED; do
2943 [ -d $INSTALLED/$s ] && \
2944 SUGGESTED=$(echo -n $SUGGESTED | sed "s/$s//")
2945 done
2946 fi
2947 cat <<EOT
2948 $(boldify $(echo $PACKAGE):) $SUGGESTED
2949 EOT
2950 fi
2951 SUGGESTED=""
2952 done ;;
2955 convert|-c)
2956 # convert misc package format to .tazpkg
2957 check_for_package_file
2958 shift
2959 tazpkg-convert $@
2960 ;;
2963 link)
2964 # link a package from another slitaz installation
2965 PACKAGE=$2
2966 if [ ! -d "$TARGET_DIR" -o \
2967 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
2968 _ 'Usage: tazpkg link package_name slitaz_root'
2969 longline "$(
2970 _n 'Example:'
2971 echo -n ' '
2972 _ '"%s" will use less than 100k in your running system RAM.' \
2973 'tazpkg link openoffice /mnt')"
2974 exit 1
2975 fi
2976 if [ -e "$INSTALLED/$PACKAGE" ]; then
2977 _ 'Package "%s" is already installed.' $PACKAGE
2978 exit 1
2979 fi
2980 ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
2981 DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
2982 MISSING=""
2983 for i in $DEPENDS; do
2984 [ -e $INSTALLED/$i ] && continue
2985 MISSING="$MISSING$i "
2986 _ 'Missing: %s' $i
2987 done
2988 if [ -n "$MISSING" ]; then
2989 newline
2990 confirm "$(_ 'Link all missing dependencies? (y/N)')"
2991 answer=$?
2992 newline
2993 if [ $answer = 0 ]; then
2994 for i in $MISSING; do
2995 tazpkg link $i $TARGET_DIR
2996 done
2997 else
2998 newline
2999 _ 'Leaving dependencies unresolved for package "%s"' $PACKAGE
3000 _ 'The package is installed but probably will not work.'
3001 newline
3002 fi
3003 fi
3004 . $INSTALLED/$PACKAGE/receipt
3005 if grep -q ^pre_install $INSTALLED/$PACKAGE/receipt; then
3006 pre_install
3007 fi
3008 while read path; do
3009 [ -e $path ] && continue
3010 while true; do
3011 dir=$(dirname $path)
3012 [ -e $dir ] && break
3013 path=$dir
3014 done
3015 ln -s $TARGET_DIR$path $dir
3016 done < $INSTALLED/$PACKAGE/files.list
3017 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
3018 post_install
3019 fi ;;
3022 usage|*)
3023 # Print a short help or give usage for an unknown or empty command.
3024 usage ;;
3025 esac
3027 exit 0