tazpkg view tazpkg @ rev 801

tazpkg convert: fix args
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu May 07 11:42:03 2015 +0200 (2015-05-07)
parents cc0ec9f7b111
children f07e0fd1175e
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 {
253 if ! [ -d "$1" ]; then
254 action 'Creating folder "%s"...' "$1"
255 mkdir -p "$1"
256 status
257 return 1
258 fi
259 }
262 # Check if the directories and files used by TazPKG
263 # exist. If not and user is root we create them.
265 check_base_dir()
266 {
267 if [ "$(id -u)" = "0" ]; then
268 check_dir $1$CACHE_DIR
269 check_dir $1$INSTALLED
270 check_dir $1$SLITAZ_LOGS
271 if [ ! -f "$1$PKGS_DB/mirror" ]; then
272 echo "${DEFAULT_MIRROR%/}/" > $1$PKGS_DB/mirror
273 [ -n "$1" ] && cp $PKGS_DB/packages.* $1$PKGS_DB/
274 fi
275 fi
276 }
277 check_base_dir
280 # Check for a package name on cmdline.
282 check_for_package_on_cmdline()
283 {
284 if [ -z "$PACKAGE" ]; then
285 newline
286 _ 'Please specify a package name on the command line.'
287 newline
288 exit 1
289 fi
290 }
293 # Check if the package (*.tazpkg) exists before installing or extracting.
295 check_for_package_file()
296 {
297 if [ ! -f "$PACKAGE_FILE" ]; then
298 newline
299 _ 'Unable to find file "%s"' $PACKAGE_FILE
300 newline
301 exit 1
302 fi
303 }
306 # Check for the receipt of an installed package.
308 check_for_receipt()
309 {
310 if [ ! -f "$1$INSTALLED/$PACKAGE/receipt" ]; then
311 newline
312 _ 'Unable to find the receipt "%s"' "$1$INSTALLED/$PACKAGE/receipt"
313 newline
314 exit 1
315 fi
316 }
319 # Get repositories priority using $PKGS_DB/priority.
320 # In this files, undigest are called by their name and main mirror
321 # by main. Sort order: priority
323 look_for_priority()
324 {
325 [ -s $PKGS_DB/priority ] && priority=$(cat $PKGS_DB/priority)
326 for rep in main $(ls $PKGS_DB/undigest 2>/dev/null); do
327 if [ ! -s $PKGS_DB/priority ] || \
328 ! grep -q ^$rep$ $PKGS_DB/priority; then
329 priority=$(echo -e "$priority\n$rep")
330 fi
331 done
332 priority=$(echo "$priority" | sed '/^$/d' | \
333 while read line; do
334 if [ "$line" = main ]; then
335 echo $PKGS_DB
336 else
337 echo $PKGS_DB/undigest/$line
338 fi
339 done)
340 }
343 # Get package name in a directory
345 package_fullname_in_dir()
346 {
347 [ -f $1/receipt ] || return
348 EXTRAVERSION=""
349 . $1/receipt
350 echo $PACKAGE-$VERSION$EXTRAVERSION
351 }
354 # Get package name that is already installed.
356 get_installed_package_pathname()
357 {
358 for i in $2$INSTALLED/${1%%-*}*; do
359 [ -d $i ] || continue
360 if [ "$1" = "$(package_fullname_in_dir $i)" ]; then
361 echo $i
362 return
363 fi
364 done
365 }
368 # Check if a package is already installed.
370 check_for_installed_package()
371 {
372 if [ -n "$(get_installed_package_pathname $PACKAGE $1)" ]; then
373 newline
374 _ '"%s" package is already installed.' $(colorize 34 $PACKAGE)
375 longline "$(_ 'You can use the --forced option to force installation.')"
376 newline
377 exit 0
378 fi
379 }
382 # Check for packages.list to download and install packages.
384 check_for_packages_list()
385 {
386 list_path="$PKGS_DB/packages.list"
387 if [ ! -f "$list_path" ]; then
388 if test $(id -u) = 0 ; then
389 tazpkg recharge
390 else
391 newline
392 _ 'Unable to find the list "%s"' $list_path
393 _ \
394 "You must probably run 'tazpkg recharge' as root to get the latest list of
395 packages available on the mirror."
396 newline
397 exit 0
398 fi
399 fi
400 }
403 # Check for installed.info - local file with format of packages.info
404 # "installed.info" is absent on not clean installs; check it and re-generate if needed.
406 check_for_installed_info()
407 {
408 info_path="$ROOT$PKGS_DB/installed.info"
409 if [ ! -f "$info_path" ]; then
410 if [ "$(id -u)" == "0" ]; then
411 _ 'File "%s" generated. Please wait...' installed.info
412 for pkg in $ROOT$PKGS_DB/installed/*/receipt; do
413 unset_receipt
414 . $pkg
415 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
416 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
417 cat >> $info_path << EOT
418 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS
419 EOT
420 done
421 else
422 _ 'Unable to find file "%s"' installed.info
423 _ 'Please run tazpkg as root.'
424 exit 1
425 fi
426 fi
427 }
430 get_cache_dir()
431 {
432 echo $rep > $tmp/rep
433 if [ "$rep" = "$PKGS_DB" ]; then
434 CACHE_DIR="$SAVE_CACHE_DIR/$SLITAZ_RELEASE/packages"
435 elif [ "${rep%-incoming}" = "$rep" ]; then
436 CACHE_DIR="$SAVE_CACHE_DIR/${rep##*/}/packages"
437 else
438 rep="${rep%-incoming}"
439 CACHE_DIR="$SAVE_CACHE_DIR/${rep##*/}/packages-incoming"
440 fi
441 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
442 echo $CACHE_DIR > $tmp/cachedir
443 }
446 # get an already installed package from packages.equiv
448 equivalent_pkg()
449 {
450 for i in $(grep -hs "^$1=" $PKGS_DB/packages.equiv \
451 $PKGS_DB/undigest/*/packages.equiv | sed "s/^$1=//"); do
452 if echo $i | fgrep -q : ; then
453 # format 'alternative:newname'
454 # if alternative is installed then substitute newname
455 if [ -f $2$INSTALLED/${i%:*}/receipt ]; then
456 # substitute package dependency
457 echo ${i#*:}
458 return
459 fi
460 else
461 # if alternative is installed then nothing to install
462 if [ -f $2$INSTALLED/$i/receipt ]; then
463 # substitute installed package
464 echo $i
465 return
466 fi
467 fi
468 done
469 # if not found in packages.equiv then no substitution
470 echo $1
471 }
474 # get a virtual package from packages.equiv
476 virtual_pkg()
477 {
478 for i in $(for rep in $priority; do
479 grep -hs "^$1=" $rep/packages.equiv
480 done | sed "s/^$1=//"); do
481 if echo $i | fgrep -q : ; then
482 # format 'alternative:newname'
483 # if alternative is installed then substitute newname
484 if [ -f $2$INSTALLED/${i%:*}/receipt ]; then
485 # substitute package dependency
486 echo ${i#*:}
487 return
488 fi
489 else
490 # unconditional substitution
491 echo $i
492 return
493 fi
494 done
495 }
498 # Get package filename available on the mirror
500 get_package_filename()
501 {
502 local pkg
503 for rep in $priority; do
504 pkg=$(grep -A 1 -sh "^$1$" $rep/packages.txt | tail -1 | sed 's/^ *//')
505 [ "$pkg" ] && pkg=$(grep -sh "^$1-$pkg" $rep/packages.list | head -1)
507 # Allow user to call a package with his version number.
508 [ "$pkg" ] || pkg=$(grep -sh "^$1$" $rep/packages.list | head -1)
510 [ "$pkg" ] || pkg=$(grep -sh "^$1-[0-9]" $rep/packages.list | head -1)
511 [ "$pkg" ] || pkg=$(grep -sh "^$1-.[\.0-9]" $rep/packages.list | head -1)
512 [ "$pkg" ] && get_cache_dir && break
513 done
514 if [ -z "$pkg" ]; then
515 # Check for virtual package
516 local equiv
517 equiv=$(virtual_pkg $1)
518 if [ "$equiv" != "$1" ]; then
519 PACKAGE=$equiv
520 get_package_filename $PACKAGE
521 return
522 fi
523 fi
524 echo $pkg
525 }
528 # Check for a package in packages.list. Used by get and get-install to grep
529 # package basename.
531 check_for_package_in_list()
532 {
533 local filename
534 local check_only
535 check_only="$1"
536 filename=$(get_package_filename $PACKAGE)
537 if [ "$filename" ]; then
538 PACKAGE=$filename
539 CACHE_DIR=$(cat $tmp/cachedir)
540 rep=$(cat $tmp/rep)
541 rm -f $tmp/rep $tmp/cachedir
542 else
543 newline
544 _ 'Unable to find package "%s" in the mirrored packages list.' $PACKAGE
545 newline
546 [ -n "$check_only" ] && return 1
547 exit 0
548 fi
549 }
552 # Log this activity
553 # (there log_pkg because we have log() in libtaz.sh)
555 log_pkg()
556 {
557 local extra
559 [ "$1" = "Installed" ] && \
560 extra=" - $(fgrep $PACKAGE-$VERSION $PKGS_DB/installed.$SUM | awk '{ print $1 }')"
562 [ -e $LOG ] || touch $LOG
564 [ -w $LOG ] &&
565 echo "$(date +'%F %T') - $1 - $PACKAGE ($VERSION$EXTRAVERSION)$extra" >> $LOG
566 }
569 # Download a get-package script from this mirror
571 download_get_script()
572 {
573 local p
574 for p in $priority ; do
575 local i
576 for i in $(cat $p/mirror) ; do
577 case "$i" in
578 http://*|ftp://*)
579 wget -O $2 ${i%packages/*}packages/get/$1 && return 0 ;;
580 esac
581 done
582 done
583 return 1
584 }
587 # Download a file from this mirror
589 download_from()
590 {
591 local i
592 local mirrors
593 mirrors="$1"
594 shift
595 for i in $mirrors; do
596 case "$i" in
597 # Mirror URL can have a trailing slash or not.
598 http://*|ftp://*)
599 busybox wget -c ${i%/}/$@ && break ;;
600 https://*)
601 echo 'Sorry, https not supported' ;;
602 *)
603 ln -sf $i/$1 . && break ;;
604 esac
605 done
606 }
609 # Download a file trying all mirrors
611 download()
612 {
613 local i
614 case "$1" in
615 *.tazpkg)
616 for i in $priority ; do
617 grep -q "^${1%.tazpkg}$" $i/packages.list 2>/dev/null || continue
618 download_from "$(cat $i/mirror)" "$@" && return
619 done
620 esac
621 for i in $(cat $(for rep in $priority; do echo $rep/mirror; done) 2>/dev/null); do
622 download_from "$i" "$@" && break
623 done
624 }
627 # Extract a package with cpio and gzip/lzma.
629 extract_package()
630 {
631 action 'Extracting package...'
632 cpio -idm --quiet < ${PACKAGE_FILE##*/} && rm -f ${PACKAGE_FILE##*/}
633 status
634 if [ -f fs.cpio.lzma ]; then
635 unlzma -c fs.cpio.lzma | cpio -idm --quiet && rm fs.cpio.lzma
636 elif [ -f fs.cpio.gz ]; then
637 zcat fs.cpio.gz | cpio -idm --quiet && rm fs.cpio.gz
638 fi
639 }
642 remove_with_path()
643 {
644 # Avoid dirname errors by checking for argument.
645 [ "$1" ] || return
647 local dir
648 rm -f $1 2>/dev/null
649 dir="$1"
650 while [ "$dir" != "/" ]; do
651 dir="$(dirname $dir)"
652 rmdir $dir 2> /dev/null || break
653 done
654 }
657 grepesc()
658 {
659 sed 's/\[/\\[/g'
660 }
663 # Print short package description
664 print_short_description() {
665 local short_desc=''
666 for LC in $LANG ${LANG%_*}; do
667 if [ -e "$PKGS_DB/packages-desc.$LC" ]; then
668 short_desc=$(grep -e "^$1 " $PKGS_DB/packages-desc.$LC | cut -d' ' -f2)
669 fi
670 done
671 [ -z "$short_desc" -a -s $PKGS_DB/packages.info ] &&
672 short_desc="$(awk -F$'\t' -vp="$PACKAGE" '{if($1==p){print $4;exit}}' $PKGS_DB/packages.info)"
673 longline "$short_desc"
674 }
677 # This function installs a package in the rootfs.
679 install_package()
680 {
681 ROOT=$1
682 if [ -n "$ROOT" ]; then
683 # Get absolute path
684 ROOT=$(realpath $ROOT)
685 fi
686 {
687 # Create package path early to avoid dependencies loop
688 mkdir -p $TMP_DIR
689 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
690 . $TMP_DIR/receipt
691 # FIXME: legacy?
692 if grep -q ^pre_depends $TMP_DIR/receipt; then
693 pre_depends $ROOT
694 fi
696 # Keep modifiers and file list on upgrade
697 cp $ROOT$INSTALLED/$PACKAGE/modifiers \
698 $ROOT$INSTALLED/$PACKAGE/files.list $TMP_DIR 2> /dev/null
699 rm -rf $ROOT$INSTALLED/$PACKAGE 2> /dev/null
701 # Make the installed package data dir to store
702 # the receipt and the files list.
703 mkdir -p $ROOT$INSTALLED/$PACKAGE
704 cp $TMP_DIR/modifiers $ROOT$INSTALLED/$PACKAGE 2> /dev/null
705 cp $TMP_DIR/files.list $ROOT$INSTALLED/$PACKAGE 2> /dev/null
706 rm -rf $TMP_DIR 2> /dev/null
707 sed -i "/ $(basename $PACKAGE_FILE)$/d" \
708 $ROOT$PKGS_DB/installed.$SUM 2> /dev/null
709 cd $(dirname $PACKAGE_FILE)
710 $CHECKSUM $(basename $PACKAGE_FILE) >> $ROOT$PKGS_DB/installed.$SUM
711 }
713 # Resolve package deps.
714 check_for_deps $ROOT
715 if [ -n "$MISSING_PACKAGE" ]; then
716 install_deps $ROOT
717 fi
718 mkdir -p $TMP_DIR
719 [ -n "$INSTALL_LIST" ] && echo "$PACKAGE_FILE" >> $ROOT$PKGS_DB/$INSTALL_LIST-processed
721 title 'Installation of package "%s"' $PACKAGE
723 print_short_description $PACKAGE
724 separator '-'
726 action 'Copying package...'
727 cp $PACKAGE_FILE $TMP_DIR
728 status
730 cd $TMP_DIR
731 extract_package
732 SELF_INSTALL=0
733 EXTRAVERSION=""
734 CONFIG_FILES=""
736 # Include temporary receipt to get the right variables.
737 . $PWD/receipt
738 cd $ROOT$INSTALLED
740 # FIXME: legacy?
741 if [ $SELF_INSTALL -ne 0 -a -n "$ROOT" ]; then
742 action "Checking post install dependencies..."
743 [ -f $INSTALLED/$PACKAGE/receipt ]
744 if ! status; then
745 _ 'Please run "%s" in / and retry.' "tazpkg install $PACKAGE_FILE"
746 rm -rf $TMP_DIR
747 exit 1
748 fi
749 fi
751 # Get files to remove if upgrading
752 if [ -f $PACKAGE/files.list ]; then
753 while read file; do
754 grep -q "^$(echo $file | grepesc)$" $TMP_DIR/files.list && continue
755 for i in $(cat $PACKAGE/modifiers 2> /dev/null ;
756 fgrep -sl $PACKAGE */modifiers | cut -d/ -f1 ); do
757 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
758 done
759 echo $file
760 done < $PACKAGE/files.list > $TMP_DIR/files2remove.list
761 fi
763 # Remember modified packages
764 {
765 check=false
766 for i in $(fgrep -v [ $TMP_DIR/files.list); do
767 [ -e "$ROOT$i" ] || continue
768 [ -d "$ROOT$i" ] && continue
769 echo "- $i"
770 check=true
771 done ;
772 $check && \
773 for i in *; do
774 [ "$i" == "$PACKAGE" ] && continue
775 [ -s $i/files.list ] || continue
776 awk "{ printf \"$i %s\\n\",\$1 }" < $i/files.list
777 done;
778 } | awk '
779 {
780 if ($1 == "-" || file[$2] != "") {
781 file[$2] = file[$2] " " $1
782 if ($1 != "-") {
783 if (pkg[$1] == "") all = all " " $1
784 pkg[$1] = pkg[$1] " " $2
785 }
786 }
787 }
788 END {
789 for (i = split(all, p, " "); i > 0; i--)
790 for (j = split(pkg[p[i]], f, " "); j > 0; j--)
791 printf "%s %s\n",p[i],f[j];
792 }
793 ' | while read dir file; do
794 if grep -qs ^$dir$ $PACKAGE/modifiers; then
795 # Do not overload an overloaded file !
796 rm $TMP_DIR$file 2> /dev/null
797 continue
798 fi
799 grep -qs ^$PACKAGE$ $dir/modifiers && continue
800 if [ -s "$dir/volatile.cpio.gz" ]; then
801 # We can modify backed up files without notice
802 zcat $dir/volatile.cpio.gz | cpio -t --quiet | \
803 grep -q "^${file#/}$" && continue
804 fi
805 echo "$PACKAGE" >> $dir/modifiers
806 done
808 cd $TMP_DIR
809 cp receipt files.list $ROOT$INSTALLED/$PACKAGE
811 # Copy the description if found.
812 if [ -f "description.txt" ]; then
813 cp description.txt $ROOT$INSTALLED/$PACKAGE
814 fi
816 # Copy the md5sum if found.
817 if [ -f "$CHECKSUM" ]; then
818 cp $CHECKSUM $ROOT$INSTALLED/$PACKAGE
819 fi
821 # Pre install commands.
822 if grep -q ^pre_install $ROOT$INSTALLED/$PACKAGE/receipt; then
823 pre_install $ROOT
824 fi
826 if [ -n "$CONFIG_FILES" ]; then
827 # save 'official' configuration files
828 action 'Saving configuration files...'
829 for i in $CONFIG_FILES; do
830 { cd fs ; find ${i#/} -type f 2> /dev/null; cd ..; }
831 done | { cd fs ; cpio -o -H newc --quiet | gzip -9; cd ..; } > \
832 $ROOT$INSTALLED/$PACKAGE/volatile.cpio.gz
834 if [ -z "$newconf" ]; then
835 # keep user configuration files
836 for i in $CONFIG_FILES; do
837 { cd fs ; find ${i#/} -type f 2> /dev/null; cd ..; }
838 done | while read i; do
839 [ -e $ROOT/$i ] || continue
840 cp -a $ROOT/$i fs/$i
841 done
842 fi
843 status
844 fi
846 action 'Installing package...'
847 [ "$(busybox ls fs/* 2>/dev/null)" ] && cp -af fs/* $ROOT/
848 status
850 if [ -s files2remove.list ]; then
851 action 'Removing old package...'
852 while read file; do
853 remove_with_path $ROOT$file
854 done < files2remove.list
855 true
856 status
857 fi
859 # Remove the temporary random directory.
860 action "Removing all tmp files..."
861 cd ..; rm -rf $TMP_DIR
862 status
864 # Post install commands.
865 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
866 action "Execute post-install commands..."
867 post_install $ROOT
868 status
869 fi
871 # Update-desktop-database if needed.
872 if [ "$(fgrep .desktop $ROOT$INSTALLED/$PACKAGE/files.list | fgrep /usr/share/applications/)" ]; then
873 updatedesktopdb=yes
874 fi
876 # Update-mime-database if needed.
877 if [ "$(fgrep /usr/share/mime $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
878 updatemimedb=yes
879 fi
881 # Update-icon-database
882 if [ "$(fgrep /usr/share/icon/hicolor $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
883 updateicondb=yes
884 fi
886 # Compile glib schemas if needed.
887 if [ "$(fgrep /usr/share/glib-2.0/schemas $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
888 compile_schemas=yes
889 fi
891 # Update depmod list
892 if [ "$(fgrep /lib/modules $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
893 updatedepmod=yes
894 fi
896 # Update installed.info
897 check_for_installed_info
898 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
899 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
900 II=$ROOT$PKGS_DB/installed.info
901 sed -i "/^$PACKAGE /d" $II # remove old entry
902 cat >> $II << EOT
903 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS
904 EOT
905 TEMP_FILE=$(mktemp)
906 sort $II > $TEMP_FILE; mv -f $TEMP_FILE $II; chmod a+r $II; unset II
908 cd $TOP_DIR
909 footer "$(_ 'Package "%s" (%s) is installed.' $PACKAGE $VERSION$EXTRAVERSION)"
911 # Log this activity
912 [ -n "$ROOT" ] || log_pkg Installed
914 # Remove package from upgrade list
915 [ -s $UP_LIST ] && sed -i "/^$PACKAGE\$/d" $UP_LIST
916 }
919 # This function may be called by a get script.
921 abort_package()
922 {
923 cd $CUR_DIR
924 rm -rf $TMP_DIR
925 echo "${1:-Abort $PACKAGE.}"
926 exit 1
927 }
930 # This function installs a package from a get script in the rootfs.
932 install_package_from_get_script()
933 {
934 SCRIPT="$1"
935 ROOT="$2"
936 [ -d $ROOT$INSTALLED/$PACKAGE ] && exit 1
938 grep -q no-check-certificate $SCRIPT &&
939 [ ! -d $INSTALLED/wget ] && tazpkg get-install wget
941 mkdir -p $TMP_DIR && cd $TMP_DIR
942 saved=$PACKAGE
943 unset_receipt
944 PACKAGE=$saved
946 set -e
947 . $SCRIPT
948 set +e
949 [ -d $PACKAGE-$VERSION ] || cd $TMP_DIR
950 [ -d $PACKAGE-$VERSION ] || abort_package \
951 "$(_ 'Could not download "%s" from "%s". Exiting.' ${TARBALL:-$PACKAGE} ${WGET_URL:-$WEB_SITE})"
953 if [ ! -s $PACKAGE-$VERSION/receipt ]; then
954 cat > $PACKAGE-$VERSION/receipt <<EOT
955 # SliTaz package receipt.
957 PACKAGE="$PACKAGE"
958 VERSION="${VERSION:-unknown}"
959 CATEGORY="${CATEGORY:-non-free}"
960 WEB_SITE="$WEB_SITE"
961 SHORT_DESC="${SHORT_DESC:-$PACKAGE}"
962 MAINTAINER="${MAINTAINER:-nobody@slitaz.org}"
963 EOT
964 for i in LICENSE TARBALL WGET_URL CONFIG_FILES SUGGESTED \
965 PROVIDE DEPENDS HOST_ARCH TAGS EXTRA_SOURCE_FILES ; do
966 eval "[ -n \"\$$i\" ] && echo \"$i=\\\"\$$i\\\"\""
967 done >> $PACKAGE-$VERSION/receipt
968 fi
970 DEPENDS="$(unset DEPENDS; . $PACKAGE-$VERSION/receipt ; echo $DEPENDS)"
971 for i in $(find_depends $PACKAGE-$VERSION/fs); do
972 case " $DEPENDS " in
973 *\ $i\ *) continue;;
974 esac
975 grep -q '^DEPENDS="' $PACKAGE-$VERSION/receipt ||
976 echo 'DEPENDS=""' >> $PACKAGE-$VERSION/receipt
977 sed -i "s/^DEPENDS=\"/&$i /" $PACKAGE-$VERSION/receipt
978 done
980 tazpkg pack $PACKAGE-$VERSION
982 # Clean to save RAM memory before installation
983 rm -rf $PACKAGE-$VERSION
985 if [ "$3" == "--get" ]; then
986 mv $PACKAGE-$VERSION.tazpkg $TOP_DIR
987 else
988 # Install pseudo package
989 tazpkg install $PACKAGE-$VERSION.tazpkg --root=$ROOT
990 mv $PACKAGE-$VERSION.tazpkg $CACHE_DIR
991 fi
993 # Clean
994 cd $TOP_DIR
995 rm -rf $TMP_DIR
996 }
999 # Check for loop in deps tree.
1001 check_for_deps_loop()
1003 local list
1004 local pkg
1005 local deps
1006 pkg=$1
1007 shift
1008 [ -n "$1" ] || return
1009 list=""
1011 # Filter out already processed deps
1012 for i in $@; do
1013 case " $ALL_DEPS" in
1014 *\ $i\ *) ;;
1015 *) list="$list $i";;
1016 esac
1017 done
1018 ALL_DEPS="$ALL_DEPS$list "
1019 for i in $list; do
1020 [ -f $i/receipt ] || continue
1021 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
1022 case " $deps " in
1023 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
1024 *) check_for_deps_loop $pkg $deps;;
1025 esac
1026 done
1030 # Check for missing deps listed in a receipt packages.
1032 check_for_deps()
1034 local saved;
1035 saved=$PACKAGE
1036 mkdir -p $TMP_DIR
1037 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
1038 . $TMP_DIR/receipt
1039 PACKAGE=$saved
1040 rm -rf $TMP_DIR
1042 num=0
1043 for pkgorg in $DEPENDS; do
1044 i=$(equivalent_pkg $pkgorg $1)
1045 if [ ! -d "$1$INSTALLED/$i" ]; then
1046 MISSING_PACKAGE=$i
1047 num=$(($num+1))
1048 elif [ ! -f "$1$INSTALLED/$i/receipt" ]; then
1049 _ 'WARNING! Dependency loop between "%s" and "%s".' $PACKAGE $i
1050 fi
1051 done
1053 if [ -n "$MISSING_PACKAGE" ]; then
1054 title "$(_ 'Tracking dependencies for package "%s"' $PACKAGE)"
1055 for pkgorg in $DEPENDS; do
1056 i=$(equivalent_pkg $pkgorg $1)
1057 if [ ! -d "$1$INSTALLED/$i" ]; then
1058 MISSING_PACKAGE=$i
1059 _ 'Missing package "%s"' $MISSING_PACKAGE
1060 fi
1061 done
1062 footer "$(_p \
1063 '%s missing package to install.' \
1064 '%s missing packages to install.' $num \
1065 $num)"
1066 fi
1070 # Install all missing deps. Auto install or ask user then install all missing
1071 # deps from local dir, cdrom, media or from the mirror. In case we want to
1072 # install packages from local, we need a packages.list to find the version.
1074 install_deps()
1076 local root
1077 root=""
1078 [ -n "$1" ] && root="--root=$1"
1079 if [ "$AUTO_INSTALL_DEPS" == "yes" ]; then
1080 answer=0
1081 else
1082 newline
1083 confirm "$(_ 'Install all missing dependencies? (y/N)')"
1084 answer=$?
1085 newline
1086 fi
1087 if [ $answer = 0 ] && ! [ "$nodeps" ]; then
1088 for pkgorg in $DEPENDS; do
1089 pkg=$(equivalent_pkg $pkgorg $1)
1090 if [ ! -d "$1$INSTALLED/$pkg" ]; then
1091 local list
1092 list="$INSTALL_LIST"
1093 [ -n "$list" ] || list="$TOP_DIR/packages.list"
1094 # We can install packages from a local dir by greping
1095 # the TAZPKG_BASENAME in the local packages.list.
1096 found=0
1097 if [ -f "$list" ]; then
1098 _ 'Checking if package "%s" exists in local list...' $pkg
1099 mkdir $TMP_DIR
1100 for i in $pkg-*.tazpkg; do
1101 [ -f $i ] || continue
1102 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $i
1103 [ "$(. $TMP_DIR/receipt; echo $PACKAGE)" = "$pkg" ] || continue
1104 if grep -q ^$(package_fullname_in_dir $TMP_DIR).tazpkg$ $list
1105 then
1106 found=1
1107 tazpkg install $i $root --list=$list
1108 break
1109 fi
1110 done
1111 rm -rf $TMP_DIR
1112 fi
1113 # Install deps from the mirror.
1114 if [ $found -eq 0 ]; then
1115 if [ ! -f "$PKGS_DB/packages.list" ]; then
1116 tazpkg recharge
1117 fi
1118 tazpkg get-install $pkg $root
1119 fi
1120 fi
1121 done
1122 else
1123 newline
1124 _ 'Leaving dependencies for package "%s" unresolved.' $PACKAGE
1125 _ 'The package is installed but will probably not work.'
1126 newline
1127 fi
1131 # Search pattern in installed packages.
1133 search_in_installed_packages()
1135 _ 'Installed packages'
1136 separator
1137 num=0
1138 for pkg in $(ls -1 $INSTALLED | grep -i "$PATTERN"); do
1139 EXTRAVERSION=""
1140 [ -f $INSTALLED/$pkg/receipt ] || continue
1141 . $INSTALLED/$pkg/receipt
1142 emsg "$PACKAGE<i 24> $VERSION$EXTRAVERSION<i 42> $(_n $CATEGORY)"
1143 num=$(($num+1))
1144 done
1146 footer "$(_p \
1147 '%s installed package found for "%s"' \
1148 '%s installed packages found for "%s"' $num \
1149 $num "$PATTERN")"
1153 # Search in packages.list for available pkgs.
1155 search_in_packages_list()
1157 _ 'Available packages'
1158 separator
1159 num=0
1160 BPATTERN="$(emsg "<b>$PATTERN</b>")"
1161 for i in $PKGS_DB/packages.list $PKGS_DB/undigest/*/packages.list \
1162 $PKGS_DB/extra.list $PKGS_DB/undigest/*/extra.list ; do
1163 grep -is "$PATTERN" $i | sed "s|$PATTERN|$BPATTERN|"
1164 num=$(($num + `grep -is "$PATTERN" $i | wc -l`))
1165 done
1166 if [ ! -f "$PKGS_DB/packages.list" ]; then
1167 newline
1168 longline "$(_ \
1169 "No \"%s\" found to check for mirrored packages. For more results, please run \
1170 \"%s\" once as root before searching." packages.list 'tazpkg recharge')"
1171 newline
1172 fi
1173 footer "$(_p \
1174 '%s available package found for "%s"' \
1175 '%s available packages found for "%s"' $num \
1176 $num $PATTERN)"
1180 # search --mirror: Search in packages.txt for available pkgs and give more
1181 # info than --list or default.
1183 search_in_packages_txt()
1185 _ 'Matching packages name with version and desc'
1186 separator
1187 num=0
1188 for i in $PKGS_DB/packages.txt $PKGS_DB/undigest/*/packages.txt; do
1189 grep -is -A 2 "^$PATTERN" $i
1190 num=$(($num + `grep -is "^$PATTERN" $i | wc -l`))
1191 done
1192 if [ ! -f "$PKGS_DB/packages.txt" ]; then
1193 newline
1194 longline "$(_ \
1195 "No \"%s\" found to check for mirrored packages. For more results, please run \
1196 \"%s\" once as root before searching." packages.txt 'tazpkg recharge')"
1197 newline
1198 fi
1199 footer "$(_p \
1200 '%s available package found for "%s"' \
1201 '%s available packages found for "%s"' $num \
1202 $num $PATTERN)"
1206 # Install package-list from a flavor
1208 install_flavor()
1210 check_root $@
1212 # Get repositories priority list.
1213 look_for_priority
1215 FLAVOR=$1
1216 ARG=$2
1217 mkdir -p $TMP_DIR
1218 [ -f $FLAVOR.flavor ] && cp $FLAVOR.flavor $TMP_DIR
1219 cd $TMP_DIR
1220 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1221 zcat < $FLAVOR.flavor | cpio --quiet -i >/dev/null
1223 while read file; do
1224 for pkg in $(ls -d $INSTALLED/${file%%-*}*); do
1225 [ -f $pkg/receipt ] || continue
1226 EXTRAVERSION=""
1227 . $pkg/receipt
1228 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && break
1229 done
1230 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && continue
1231 cd $CACHE_DIR
1232 download $file.tazpkg
1233 cd $TMP_DIR
1234 tazpkg install $CACHE_DIR/$file.tazpkg --forced
1235 done < $FLAVOR.pkglist
1237 [ -f $FLAVOR.nonfree ] && while read pkg; do
1238 [ -d $INSTALLED/$pkg ] || continue
1239 [ -d $INSTALLED/get-$pkg ] && tazpkg get-install get-$pkg
1240 get-$pkg
1241 done < $FLAVOR.nonfree
1243 [ "$ARG" == "--purge" ] && for pkg in $(ls $INSTALLED); do
1244 [ -f $INSTALLED/$pkg/receipt ] || continue
1245 EXTRAVERSION=""
1246 . $INSTALLED/$pkg/receipt
1247 grep -q ^$PACKAGE-$VERSION$EXTRAVERSION$ $FLAVOR.pkglist && continue
1248 grep -qs ^$PACKAGE$ $FLAVOR.nonfree && continue
1249 tazpkg remove $PACKAGE
1250 done
1251 else
1252 _ "Can't find flavor \"%s\". Abort." $FLAVOR
1253 fi
1254 cd $TOP_DIR
1255 rm -rf $TMP_DIR
1259 # Update mirror urls
1261 setup_mirror()
1263 # Backup old list.
1264 if [ -f "$1/mirror" ]; then
1265 cp -f $1/mirror $1/mirror.bak
1266 fi
1267 title 'Current mirror(s)'
1268 echo " `cat $1/mirror 2> /dev/null`"
1269 longline "$(_ \
1270 "Please enter URL of the new mirror (http, ftp or local path). You must specify \
1271 the complete address to the directory of the packages and packages.list file.")"
1272 newline
1273 _n 'New mirror(s) URL: '
1274 NEW_MIRROR_URL=$2
1275 if [ -n "$NEW_MIRROR_URL" ]; then
1276 echo $NEW_MIRROR_URL
1277 else
1278 read NEW_MIRROR_URL
1279 fi
1280 if [ "$NEW_MIRROR_URL" = "" ]; then
1281 _ 'Nothing has been changed.'
1282 else
1283 _ 'Setting mirror(s) to: "%s"' $NEW_MIRROR_URL
1284 rm -f $1/mirror
1285 for i in $NEW_MIRROR_URL; do
1286 echo "${i%/}/" >> $1/mirror
1287 done
1288 fi
1289 newline
1293 # recursive dependencies scan
1295 dep_scan()
1297 for i in $1; do
1298 case " $ALL_DEPS " in
1299 *\ $i\ *) continue;;
1300 esac
1301 ALL_DEPS="$ALL_DEPS $i"
1302 [ -n "$2" ] && echo "$2$i ($(fgrep -A 3 $i $PKGS_DB/packages.txt | \
1303 tail -1 | sed 's/.*(\([^ ]*\).*/\1/'))"
1304 [ -f $i/receipt ] || continue
1305 DEPENDS=""
1306 . $i/receipt
1307 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
1308 done
1312 # recursive reverse dependencies scan
1314 rdep_scan()
1316 SEARCH=$1
1318 for i in * ; do
1319 DEPENDS=""
1320 . $i/receipt
1321 echo "$i $(echo $DEPENDS)"
1322 done | busybox awk -v search=$SEARCH '
1323 function show_deps(deps, all_deps, pkg, space)
1325 if (all_deps[pkg] == 1) return
1326 all_deps[pkg] = 1
1327 if (space != "") printf "%s %s\n",space,pkg
1328 for (i = 1, n = split(deps[pkg], mydeps, " "); i <= n; i++) {
1329 show_deps(deps, all_deps, mydeps[i],"==" space)
1334 all_deps[$1] = 0
1335 for (i = 2; i <= NF; i++)
1336 deps[$i] = deps[$i] " " $1
1339 END {
1340 show_deps(deps, all_deps, search, "")
1342 ' | while read spc pkg; do
1343 echo -n $spc | sed 's/=/ /g'
1344 echo -n $pkg
1345 echo -n ' ('
1346 fgrep -A 3 $pkg $PKGS_DB/packages.txt | tail -1 | \
1347 sed 's/.*(\([^ ]*\).*/\1)/'
1348 done
1352 update_desktop_database()
1354 if [ -f $1/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
1355 chroot "$1/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
1356 fi
1360 update_mime_database()
1362 if [ -f $1/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
1363 chroot "$1/" /usr/bin/update-mime-database /usr/share/mime
1364 fi
1368 update_icon_database()
1370 if [ -f $1/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
1371 chroot "$1/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
1372 fi
1376 compile_glib_schemas()
1378 if [ -f $1/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
1379 chroot "$1/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
1380 fi
1384 update_kernel_modules()
1386 if [ -f $1/sbin/depmod ] && [ -n "$updatedepmod" ]; then
1387 chroot "$1/" /sbin/depmod -a
1388 fi
1395 ###################
1396 # TazPKG commands #
1397 ###################
1399 case "$COMMAND" in
1400 list|-l)
1401 # List all installed packages or a specific category.
1402 shift
1403 check_for_installed_info
1405 case $1 in
1406 b|blocked)
1407 # Display the list of blocked packages.
1408 title 'Blocked packages'
1409 if [ -s "$BLOCKED" ];then
1410 cat $BLOCKED
1411 else
1412 _ 'No blocked packages found.'
1413 fi
1414 newline; exit 0
1415 ;;
1416 c|cat|categories)
1417 # Display the list of categories.
1418 title 'Packages categories'
1420 echo "$PKGS_CATEGORIES" | sed 's|[^a-z-]|\n|g; /^$/d' | \
1421 sed 's|\(.*\)|\1\t\1|' | translate_category | awk -F$'\t' '{
1422 if ($1==$2) print $1; else print $1"\033[15G "$2}'
1424 num=$(echo -n "$PKGS_CATEGORIES" | wc -l)
1425 footer "$(_p \
1426 '%s category' \
1427 '%s categories' $num \
1428 $num)"
1429 exit 0
1430 ;;
1431 '')
1432 # By default list all packages and versions.
1433 title 'List of all installed packages'
1434 TMPLIST=$(mktemp)
1435 awk -F$'\t' '{print $1"\033[35G "$2"\033[53G "$3}' \
1436 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
1438 packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST
1439 footer "$(emsg $(_p \
1440 '%s package installed.' \
1441 '%s packages installed.' $packages \
1442 "<c 32>$packages</c>"))"
1443 ;;
1444 *)
1445 # Check for an asked category.
1446 ASKED_CATEGORY_I18N="$@"
1447 ASKED_CATEGORY=$(reverse_translate_category "$ASKED_CATEGORY_I18N")
1448 title 'Installed packages of category "%s"' $ASKED_CATEGORY_I18N
1449 TMPLIST=$(mktemp)
1450 awk -F$'\t' '
1452 if ($3 == "'$ASKED_CATEGORY'")
1453 print $1"\033[35G "$2
1454 }' \
1455 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
1457 packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST
1458 footer "$(emsg $(_p \
1459 '%s package installed of category "%s".' \
1460 '%s packages installed of category "%s".' $packages \
1461 "<c 32>$packages</c>" "<c 34>$ASKED_CATEGORY_I18N</c>"))"
1462 ;;
1463 esac ;;
1465 list-mirror|-lm)
1466 # List all available packages on the mirror. Option --diff displays
1467 # last mirrored packages diff (see recharge).
1468 check_for_packages_list
1469 case $2 in
1470 --diff)
1471 if [ -f "$PKGS_DB/packages.diff" ]; then
1472 title 'Mirrored packages diff'
1473 cat $PKGS_DB/packages.diff
1474 num=$(wc -l < $PKGS_DB/packages.diff)
1475 footer "$(_p \
1476 '%s new package listed on the mirror.' \
1477 '%s new packages listed on the mirror.' $num \
1478 $num)"
1479 else
1480 newline
1481 _ 'Unable to list anything, no packages.diff found.'
1482 _ 'Recharge your current list to create a first diff.'
1483 newline
1484 fi; exit 0 ;;
1485 --text|--txt|--raw|*)
1486 title 'List of available packages on the mirror'
1487 cat $PKGS_DB/packages.txt ;;
1488 esac
1489 pkgs=$(wc -l < $PKGS_DB/packages.list)
1490 footer "$(emsg "$(_p \
1491 '%s package in the last recharged list.' \
1492 '%s packages in the last recharged list.' $pkgs \
1493 "<c 32>$pkgs</c>")")"
1494 ;;
1497 list-files|-lf)
1498 # List files installed with the package.
1499 check_for_package_on_cmdline
1500 check_for_receipt
1501 title 'Installed files by "%s"' $PACKAGE
1502 sort < $INSTALLED/$PACKAGE/files.list
1503 files=$(wc -l < $INSTALLED/$PACKAGE/files.list)
1504 footer "$(emsg "$(_p \
1505 '%s file' '%s files' $files \
1506 "<c 32>$files</c>")")"
1507 ;;
1510 info)
1511 # Information about package.
1512 check_for_package_on_cmdline
1513 check_for_receipt
1514 EXTRAVERSION=""
1515 . $INSTALLED/$PACKAGE/receipt
1516 im && title 'TazPKG information'
1517 # Display localized short description
1518 for LC in $LANG ${LANG%_*}; do
1519 if [ -e "$PKGS_DB/packages-desc.$LC" ]; then
1520 LOCDESC=$(grep -e "^$PACKAGE " $PKGS_DB/packages-desc.$LC | cut -d' ' -f2)
1521 [ -n "$LOCDESC" ] && SHORT_DESC="$LOCDESC"
1522 fi
1523 done
1524 SIZES=$(echo $PACKED_SIZE/$UNPACKED_SIZE | sed 's|\.0||g' | sed 's|^/$||')
1526 emsg "$(
1528 _ 'Package : %s' "$PACKAGE"
1529 _ 'Version : %s' "$VERSION$EXTRAVERSION"
1530 _ 'Category : %s' "$(_ $CATEGORY)"
1531 _ 'Short desc : %s' "$SHORT_DESC"
1532 _ 'Maintainer : %s' "$MAINTAINER"
1533 _ 'License : %s' "$LICENSE"
1534 _ 'Depends : %s' "$DEPENDS"
1535 _ 'Suggested : %s' "$SUGGESTED"
1536 _ 'Build deps : %s' "$BUILD_DEPENDS"
1537 _ 'Wanted src : %s' "$WANTED"
1538 _ 'Web site : %s' "$WEB_SITE"
1539 _ 'Size : %s' "$SIZES"
1540 _ 'Tags : %s' "$TAGS"
1541 } | sed '/: $/d; s|^\([^:]*\):|<b>\1:</b>|')"
1542 im && footer
1543 ;;
1546 desc)
1547 # Display package description
1548 if [ -n "$(grep -e "^$PACKAGE " $PKGS_DB/installed.info)" ]; then
1549 im && title 'Description of package "%s"' $PACKAGE
1550 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
1551 cat $INSTALLED/$PACKAGE/description.txt
1552 else
1553 im && awk -F$'\t' '{if ($1 == "'$PACKAGE'") print $4}' $PKGS_DB/installed.info
1554 fi
1555 im && footer
1556 else
1557 im && _ 'Package "%s" is not installed.' "$PACKAGE"
1558 fi
1559 ;;
1562 activity|log|-a)
1563 # Show activity log
1564 [ "$nb" ] || nb=18
1565 title 'TazPKG Activity'
1566 IFS=" "
1567 tail -n ${nb} ${LOG} | \
1568 while read date hour none action none pkg vers none; do
1569 case $action in
1570 Installed)
1571 action=$(colorize 32 $action) ;;
1572 Removed)
1573 action=$(colorize 31 $action) ;;
1574 *)
1575 action=$(boldify $action) ;;
1576 esac
1577 echo "$date $hour : $action $pkg $vers"
1578 done
1579 unset IFS
1580 footer ;;
1583 search|-s)
1584 # Search for a package by pattern or name.
1585 PATTERN="$2"
1586 if [ -z "$PATTERN" ]; then
1587 newline
1588 _ 'Please specify a pattern or package name to search for.'
1589 echo "$(_ 'Example:') 'tazpkg search paint'"
1590 newline
1591 exit 0
1592 fi
1593 title 'Search result for "%s"' $PATTERN
1594 # Default is to search in installed pkgs and the raw list.
1595 case "$3" in
1596 -i|--installed)
1597 search_in_installed_packages ;;
1598 -l|--list)
1599 search_in_packages_list ;;
1600 -m|--mirror)
1601 search_in_packages_txt ;;
1602 *)
1603 search_in_installed_packages
1604 search_in_packages_list ;;
1605 esac ;;
1608 search-file|-sf)
1609 # Search for a file by pattern or name in all files.list.
1610 if [ -z "$2" ]; then
1611 newline
1612 _ 'Please specify a pattern or file name to search for.'
1613 echo "$(_ 'Example:') 'tazpkg search-file libnss'"
1614 newline
1615 exit 0
1616 fi
1617 title 'Search result for file "%s"' $2
1619 TMPLIST=$(mktemp)
1620 if [ "$3" == "--mirror" ]; then
1622 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1623 [ -f $i ] || continue
1624 lzcat $i | awk -F: -vP="$(gettext 'Package %s:')" -vT=$TMPLIST '
1625 BEGIN { last = "" }
1626 $2 ~ /'$2'/ {
1627 if (last != $1) {
1628 last = $1;
1629 PP = P;
1630 sub(/%s/, $1, PP);
1631 printf("\n\e[1;33m%s\e[0;39m\n", PP);
1633 gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $2);
1634 print $2;
1635 printf "%s" 1 >> T;
1636 }'
1637 done
1639 else
1641 # Check all pkg files.list in search match which specify the package
1642 # name and the full path to the file(s).
1643 for pkg in $INSTALLED/*; do
1644 if grep -qs "$2" $pkg/files.list; then
1645 . $pkg/receipt
1646 newline
1647 emsg "<c 33>$(_ 'Package %s:' $PACKAGE)</c>"
1648 awk -vT=$TMPLIST '
1649 /'$2'/ {
1650 gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $0);
1651 print " "$0;
1652 printf "%s" 1 >> T;
1654 ' $pkg/files.list
1655 fi
1656 done
1658 fi
1660 match=$(wc -m < $TMPLIST)
1661 rm $TMPLIST
1663 footer "$(emsg "$(_p \
1664 '%s file' '%s files' $match \
1665 "<c 32>$match</c>")")"
1666 ;;
1669 search-pkgname)
1670 # Search for a package name
1671 if [ -z "$2" ]; then
1672 newline
1673 _ 'Please specify a pattern or file name to search for.'
1674 echo "$(_ 'Example:') 'tazpkg search-pkgname libnss'"
1675 newline
1676 exit 0
1677 fi
1678 title 'Search result for package "%s"' $2
1680 # Search for a file on mirror and output only the package name
1681 TMPLIST=$(mktemp)
1682 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1683 [ -f $i ] || continue
1684 lzcat $i | awk -F: -vT=$TMPLIST '
1685 BEGIN { P = "" }
1686 $2 ~ /'$2'/ {
1687 if ($1 != P) {
1688 print $1;
1689 printf "%s" 1 >> T;
1690 P = $1
1692 }'
1693 done
1694 match=$(wc -m < $TMPLIST)
1695 rm $TMPLIST
1697 footer "$(emsg "$(_p \
1698 '%s package' '%s packages' $match \
1699 "<c 32>$match</c>")")"
1700 ;;
1703 install|-i)
1704 # Install .tazpkg packages.
1705 check_root $@
1706 check_for_package_on_cmdline
1707 check_for_package_file
1708 check_for_installed_info
1710 if [ -n "$root" ]; then
1711 ROOT="$root";
1712 check_base_dir "$root"
1713 fi
1714 [ "$list" ] && INSTALL_LIST="$list"
1715 if [ "$rootconfig" ]; then
1716 if [ "$root" ]; then
1717 CACHE_DIR=$root/$CACHE_DIR
1718 SAVE_CACHE_DIR=$CACHE_DIR
1719 PKGS_DB=$root/$PKGS_DB
1720 else
1721 echo "rootconfig needs --root= option used." >&2
1722 exit 1
1723 fi
1724 fi
1726 # Get repositories priority list.
1727 look_for_priority
1729 # Check if forced install.
1730 if [ -z "$forced" ]; then
1731 check_for_installed_package $ROOT
1732 fi
1733 install_package $ROOT
1734 update_desktop_database $ROOT
1735 update_mime_database $ROOT
1736 update_icon_database $ROOT
1737 compile_glib_schemas $ROOT
1738 ;;
1741 install-list|get-install-list)
1742 # Install a set of packages from a list.
1743 check_root $@
1744 if [ -z "$2" ]; then
1745 newline
1746 longline "$(_ \
1747 "Please change directory (cd) to the packages repository and specify the \
1748 list of packages to install.")"
1749 echo "$(_ 'Example:') $(emsg '<b>tazpkg install-list</b> <c 33>packages.list</c>')"
1750 exit 0
1751 fi
1753 # Check if the packages list exist.
1754 if [ ! -f "$2" ]; then
1755 _ 'Unable to find list "%s"' "$2"
1756 exit 0
1757 fi
1759 LIST=$(cat $2)
1761 # Remember processed list
1762 export INSTALL_LIST="$2"
1764 # Set $COMMAND and install all packages.
1765 COMMAND=${1%-list}
1767 touch $2-processed
1769 # Upgrade tazpkg first. It may handle new features/formats...
1770 # then upgrade essential packages early
1771 for pkg in busybox-pam busybox gcc-lib-base glibc-base \
1772 slitaz-base-files tazpkg ; do
1773 pkg=$(egrep $pkg-[0-9] $INSTALL_LIST)
1774 [ -z "$pkg" ] && continue
1775 _ 'Adding implicit depends "%s"...' $pkg
1776 LIST="$pkg
1777 $LIST"
1778 done
1780 for pkg in $LIST; do
1781 grep -qs ^$pkg$ $2-processed && continue
1782 [ -d "$root/var/lib/tazpkg/installed" ] &&
1783 tazpkg $COMMAND $pkg --list="$2" "$3" "$4" "$5"
1784 done
1785 rm -f $2-processed ;;
1788 add-flavor)
1789 # Install a set of packages from a flavor.
1790 install_flavor $2 ;;
1793 install-flavor)
1794 # Install a set of packages from a flavor and purge other ones.
1795 install_flavor $2 --purge ;;
1798 set-release)
1799 # Change current release and upgrade packages.
1800 RELEASE=$2
1801 if [ -z "$RELEASE" ]; then
1802 newline
1803 _ 'Please specify the release you want on the command line.'
1804 echo "$(_ 'Example:') tazpkg set-release cooking"
1805 newline
1806 exit 0
1807 fi
1808 rm $PKGS_DB/mirror
1809 echo "$RELEASE" > /etc/slitaz-release
1810 tazpkg recharge && tazpkg upgrade
1812 # Install missing depends
1813 cd $INSTALLED
1814 for i in * ; do
1815 DEPENDS=""
1816 . $i/receipt
1817 for j in $DEPENDS ; do
1818 [ -d $j ] || tazpkg get-install $j
1819 done
1820 done ;;
1823 remove|-r)
1824 # Remove packages.
1825 check_root $@
1826 check_for_package_on_cmdline
1827 check_for_installed_info
1829 [ -n "$root" ] && ROOT="$root"
1831 if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then
1832 newline; _ 'Package "%s" is not installed.' $PACKAGE
1833 exit 0
1834 fi
1836 . $ROOT$INSTALLED/$PACKAGE/receipt
1838 # Info #1: dependent packages (to be processed later)
1839 ALTERED="$(awk -F$'\t' -vp=" $PACKAGE " '
1840 index(" " $8 " ", p) { printf " %s\n", $1 }
1841 ' $ROOT/$PKGS_DB/installed.info)"
1843 if [ -n "$ALTERED" ]; then
1844 _ 'The following packages depend on package "%s":' $PACKAGE
1845 echo "$ALTERED"
1846 fi
1848 # Info #2: changed packages (to be processed later)
1849 REFRESH=$(cd $ROOT$INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1851 if [ -n "$REFRESH" ]; then
1852 _ 'The following packages have been modified by package "%s":' $PACKAGE
1853 for i in $REFRESH; do
1854 echo " ${i%/modifiers}"
1855 done
1856 fi
1858 # Confirmation
1859 if im && [ -z "$auto" ]; then
1860 confirm "$(_ 'Remove package "%s" (%s)? (y/N)' $PACKAGE $VERSION$EXTRAVERSION)"
1861 if [ $? != 0 ]; then
1862 newline; _ 'Uninstallation of package "%s" cancelled.' $PACKAGE
1863 exit 0
1864 fi
1865 fi
1866 # We are here: non-interactive mode, or --auto, or answer 'y'
1868 # Removing package
1869 title 'Removing package "%s"' $PACKAGE
1871 # [1/4] Pre-remove commands
1872 if grep -q ^pre_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1873 action "Execution of pre-remove commands..."
1874 pre_remove $ROOT
1875 status
1876 fi
1878 # [2/4] Removing files
1879 action "Removing all files installed..."
1880 if [ -f $ROOT$INSTALLED/$PACKAGE/modifiers ]; then
1881 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1882 for mod in $(cat $ROOT$INSTALLED/$PACKAGE/modifiers); do
1883 [ -f $ROOT$INSTALLED/$mod/files.list ] && \
1884 [ $(grep "^$(echo $file | grepesc)$" $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && \
1885 continue 2
1886 done
1887 remove_with_path $ROOT$file
1888 done
1889 else
1890 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1891 remove_with_path $ROOT$file
1892 done
1893 fi
1894 status
1896 # [3/4] Post-remove commands
1897 if grep -q ^post_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1898 action "Execution of post-remove commands..."
1899 post_remove $ROOT
1900 status
1901 fi
1903 # [4/4] Remove package receipt and remove it from databases
1904 action "Removing package receipt..."
1905 rm -rf $ROOT$INSTALLED/$PACKAGE
1906 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg$/d" $PKGS_DB/installed.$SUM
1907 sed -i "/^$PACKAGE /d" $PKGS_DB/installed.info
1908 status
1910 footer "$(_ 'Package "%s" (%s) removed.' $PACKAGE $VERSION$EXTRAVERSION)"
1912 # Log this activity
1913 log_pkg Removed
1915 # Stop if non-interactive mode and no --auto option
1916 if ! im && [ -z "$auto" ]; then exit 0; fi
1918 # Process dependent packages
1919 if [ -n "$ALTERED" ]; then
1920 if [ "$auto" ]; then
1921 answer=0
1922 else
1923 confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' $PACKAGE)"
1924 answer=$?
1925 fi
1926 if [ $answer = 0 ]; then
1927 for i in $ALTERED; do
1928 if [ -d "$ROOT$INSTALLED/$i" ]; then
1929 echo "tazpkg remove $i $ROOTOPTS"
1930 fi
1931 done
1932 fi
1933 fi
1935 # Process changed packages
1936 if [ -n "$REFRESH" ]; then
1937 if [ "$auto" ]; then
1938 answer=0
1939 else
1940 confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' $PACKAGE)"
1941 answer=$?
1942 fi
1943 if [ $answer = 0 ]; then
1944 for i in $REFRESH; do
1945 if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then
1946 _ 'Check %s for reinstallation' "$INSTALLED/$i"
1947 continue
1948 fi
1949 echo "rm -r $ROOT$INSTALLED/$i"
1950 echo "tazpkg get-install ${i%/modifiers} $ROOTOPTS --forced"
1951 done
1952 fi
1953 fi
1955 ;;
1958 extract|-e)
1959 # Extract .tazpkg cpio archive into a directory.
1960 check_for_package_on_cmdline
1961 check_for_package_file
1962 title 'Extracting package "%s"' $PACKAGE
1964 # If no directory destination is found on the cmdline
1965 # we create one in the current dir using the package name.
1966 if [ -n "$TARGET_DIR" ]; then
1967 DESTDIR=$TARGET_DIR/$PACKAGE
1968 else
1969 DESTDIR=$PACKAGE
1970 fi
1971 mkdir -p $DESTDIR
1973 action "Copying original package..."
1974 cp $PACKAGE_FILE $DESTDIR
1975 status
1977 cd $DESTDIR
1978 extract_package
1979 [ -e "receipt" ] && \
1980 footer "$(_ 'Package "%s" is extracted to "%s"' $PACKAGE $DESTDIR)"
1981 ;;
1984 recompress)
1985 # Recompress .tazpkg cpio archive with lzma.
1986 check_for_package_on_cmdline
1987 check_for_package_file
1988 title 'Recompressing package "%s"' $PACKAGE
1989 mkdir -p $TMP_DIR
1991 action "Copying original package..."
1992 cp $PACKAGE_FILE $TMP_DIR
1993 status
1995 cd $TMP_DIR
1996 extract_package
1998 action "Recompressing the FS..."
1999 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2000 rm -rf fs
2001 status
2003 action "Creating new package..."
2004 find . -print | cpio -o -H newc --quiet > \
2005 $TOP_DIR/$(basename $PACKAGE_FILE).$$ && mv -f \
2006 $TOP_DIR/$(basename $PACKAGE_FILE).$$ \
2007 $TOP_DIR/$(basename $PACKAGE_FILE)
2008 status
2010 cd $TOP_DIR
2011 rm -rf $TMP_DIR
2012 separator; newline ;;
2015 list-config)
2016 # List configuration files installed.
2017 if [ -n "$box" ]; then
2018 mkdir -p $TMP_DIR; cd $TMP_DIR
2019 FILES="$INSTALLED/*/volatile.cpio.gz"
2020 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
2021 for i in $FILES; do
2022 zcat $i | cpio -idm --quiet > /dev/null
2023 find * -type f 2>/dev/null | while read file; do
2024 if [ ! -e /$file ]; then
2025 echo -n "----------|----|----|$(_n 'File lost')"
2026 else
2027 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
2028 cmp $file /$file > /dev/null 2>&1 || \
2029 echo -n "$(stat -c "%.16y" /$file)"
2030 fi
2031 echo "|/$file"
2032 done
2033 rm -rf *
2034 done
2035 cd $TOP_DIR
2036 rm -rf $TMP_DIR
2037 else
2038 im && title 'Configuration files'
2039 for i in $INSTALLED/*/volatile.cpio.gz; do
2040 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
2041 [ -f "$i" ] || continue
2042 zcat $i | cpio -t --quiet
2043 done | sed 's|^|/|' | sort
2044 im && footer
2045 fi ;;
2048 repack-config)
2049 # Create SliTaz package archive from configuration files.
2050 mkdir -p $TMP_DIR; cd $TMP_DIR
2051 CONFIG_VERSION=1.0
2052 mkdir config-$CONFIG_VERSION
2053 cd config-$CONFIG_VERSION
2054 for i in $INSTALLED/*/volatile.cpio.gz; do
2055 zcat $i | cpio -t --quiet
2056 done > files.list
2057 mkdir fs
2058 cd fs
2059 ( cd / ; cpio -o -H newc --quiet ) < ../files.list | cpio -idm --quiet > /dev/null
2060 mkdir -p etc/tazlito
2061 for i in $INSTALLED/*/receipt; do
2062 EXTRAVERSION=""
2063 . $i
2064 echo "$PACKAGE-$VERSION$EXTRAVERSION"
2065 done > etc/tazlito/config-packages.list
2066 cd ..
2067 echo "etc/tazlito/config-packages.list" >> files.list
2068 pkg_date=$(date +"%x %X")
2069 cat > receipt <<EOT
2070 # SliTaz package receipt.
2072 PACKAGE="config"
2073 VERSION="$CONFIG_VERSION"
2074 CATEGORY="base-system"
2075 SHORT_DESC="$(_n 'User configuration backup on date %s' $pkg_date)"
2076 DEPENDS="$(ls $INSTALLED)"
2077 EOT
2078 cd ..
2079 tazpkg pack config-$CONFIG_VERSION
2080 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
2081 cd $TOP_DIR
2082 rm -rf $TMP_DIR
2083 ;;
2086 repack)
2087 # Create SliTaz package archive from an installed package.
2088 check_for_package_on_cmdline
2089 check_for_receipt
2090 EXTRAVERSION=""
2091 . $INSTALLED/$PACKAGE/receipt
2092 title 'Repacking "%s"' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
2094 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
2095 _ "Can't repack package \"%s\"" $PACKAGE
2096 exit 1
2097 fi
2099 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
2100 _ "Can't repack, \"%s\" files have been modified by:" $PACKAGE
2101 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
2102 echo " $i"
2103 done
2104 exit 1
2105 fi
2107 MISSING=""
2108 while read i; do
2109 [ -e "$i" ] && continue
2110 [ -L "$i" ] || MISSING="$MISSING\n $i"
2111 done < $INSTALLED/$PACKAGE/files.list
2112 if [ -n "$MISSING" ]; then
2113 _n "Can't repack, the following files are lost:"
2114 echo -e "$MISSING"
2115 exit 1
2116 fi
2118 mkdir -p $TMP_DIR; cd $TMP_DIR
2119 FILES="fs.cpio.lzma\n"
2120 for i in $(ls $INSTALLED/$PACKAGE); do
2121 case $i in
2122 volatile.cpio.gz|modifiers) ;;
2123 *) cp $INSTALLED/$PACKAGE/$i .; FILES="$FILES$i\n" ;;
2124 esac
2125 done
2127 ln -s / rootfs
2128 mkdir tmp
2129 sed 's/^/rootfs/' < files.list | cpio -o -H newc --quiet | \
2130 { cd tmp ; cpio -idm --quiet >/dev/null; cd ..; }
2131 mv tmp/rootfs fs
2133 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
2134 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
2135 { cd fs; cpio -idm --quiet; cd ..; }
2136 fi
2138 if fgrep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
2139 . $INSTALLED/$PACKAGE/receipt
2140 repack_cleanup fs
2141 fi
2143 if [ -f $INSTALLED/$PACKAGE/$CHECKSUM ]; then
2144 sed 's, , fs,' < $INSTALLED/$PACKAGE/$CHECKSUM | \
2145 $CHECKSUM -s -c || {
2146 _ "Can't repack, %s error." $CHECKSUM
2147 cd $TOP_DIR
2148 rm -rf $TMP_DIR
2149 exit 1
2151 fi
2153 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2154 echo -e "$FILES" | cpio -o -H newc --quiet > \
2155 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
2156 cd $TOP_DIR
2157 \rm -R $TMP_DIR
2158 _ 'Package "%s" repacked successfully.' $PACKAGE
2159 _ 'Size: %s' "$(du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg)"
2160 newline ;;
2163 pack)
2164 # Create SliTaz package archive using cpio and lzma.
2165 # TODO: Cook also pack packages, we should share code in libpkg.sh
2166 check_for_package_on_cmdline
2167 cd $PACKAGE
2168 if [ ! -f "receipt" ]; then
2169 _ 'Receipt is missing. Please read the documentation.'
2170 exit 0
2171 fi
2173 title 'Packing package "%s"' $PACKAGE
2174 # Create files.list with redirecting find outpout.
2176 action "Creating the list of files..."
2177 cd fs
2178 find . -type f -print > ../files.list
2179 find . -type l -print >> ../files.list
2180 cd .. && sed -i s/'^.'/''/ files.list
2181 status
2183 action 'Creating %s of files...' $CHECKSUM
2184 while read file; do
2185 [ -L "fs$file" ] && continue
2186 [ -f "fs$file" ] || continue
2187 case "$file" in
2188 /lib/modules/*/modules.*|*.pyc) continue;;
2189 esac
2190 $CHECKSUM "fs$file" | sed 's/ fs/ /'
2191 done < files.list > $CHECKSUM
2192 status
2194 UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
2195 description.txt 2> /dev/null | awk \
2196 '{ sz=$1 } END { print sz }')
2197 # Build cpio archives.
2199 action "Compressing the FS..."
2200 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2201 rm -rf fs
2202 status
2204 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
2205 $CHECKSUM description.txt 2> /dev/null | awk \
2206 '{ sz=$1 } END { print sz }')
2208 action "Updating receipt sizes..."
2209 sed -i s/^PACKED_SIZE.*$// receipt
2210 sed -i s/^UNPACKED_SIZE.*$// receipt
2211 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
2212 status
2214 action "Creating full cpio archive..."
2215 find . -print | cpio -o -H newc --quiet > ../$PACKAGE.tazpkg
2216 status
2218 action "Restoring original package tree..."
2219 unlzma -c fs.cpio.lzma | cpio -idm --quiet
2220 status
2222 rm fs.cpio.lzma && cd ..
2223 footer "$(_ 'Package "%s" compressed successfully.' $PACKAGE)"
2224 _ 'Size: %s' "$(ls -lh $PACKAGE.tazpkg | awk '{print $5}')"
2225 ;;
2228 recharge)
2229 # Recharge packages.list from a mirror.
2231 # WARNING: The 'mirrors' file has all SliTaz mirrors but 'mirror'
2232 # must have only the chosen main mirror.
2234 check_root $@
2236 ARG=$2
2237 if [ "$root" ]; then
2238 PKGS_DB=$root$PKGS_DB
2239 [ "${2#--}" != "$2" ] && ARG=$3
2240 fi
2241 if [ "$ARG" = main ]; then
2242 repository_to_recharge=$PKGS_DB
2243 elif [ "$ARG" ]; then
2244 if [ -d "$PKGS_DB/undigest/$ARG" ]; then
2245 repository_to_recharge=$PKGS_DB/undigest/$ARG
2246 else
2247 repo="$PKGS_DB/undigest/$ARG"
2248 _ "Repository \"%s\" doesn't exist." $repo >&2
2249 exit 1
2250 fi
2251 else
2252 repository_to_recharge="$PKGS_DB $PKGS_DB/undigest/*"
2253 fi
2254 for path in $repository_to_recharge; do
2255 [ -f $path/mirror ] || continue
2256 cd $path
2258 # Quietly check if recharging is needed.
2259 [ -f ID ] && mv ID ID.bak
2260 download_from "$(cat mirror)" ID >/dev/null 2>/dev/null
2261 if [ -f ID ] && fgrep -q $(cat ID.bak 2>/dev/null || echo "null") ID; then
2262 if [ "$path" = "$PKGS_DB" ]; then
2263 repository_name=Main
2264 else
2265 base_path="$(basename $path)"
2266 repository_name="$(_n 'Undigest %s' $base_path)"
2267 fi
2268 _ 'Repository "%s" is up to date.' "$repository_name"
2269 rm ID.bak
2270 continue
2271 fi
2273 # Don't let ID be a symlink when using local repository.
2274 if [ -f ID ]; then
2275 mv -f ID ID.bak
2276 cat ID.bak > ID
2277 rm ID.bak
2278 fi
2280 newline
2281 if [ "$path" != "$PKGS_DB" ]; then
2282 base_path="$(basename $path)"
2283 _ 'Recharging undigest %s:' $base_path
2284 fi
2286 if [ -f "packages.list" ]; then
2287 action "Creating backup of the last packages list..."
2288 for i in packages.desc packages.$SUM packages.txt \
2289 packages.list packages.equiv files.list.lzma \
2290 extra.list mirrors packages.info
2291 do
2292 mv -f $i $i.bak 2>/dev/null
2293 done
2294 status
2295 fi
2297 for i in desc $SUM txt list equiv; do
2298 download_from "$(cat mirror)" packages.$i
2299 done
2300 download_from "$(cat mirror)" files.list.lzma
2301 download_from "$(cat mirror)" extra.list
2302 download_from "$(sed 's|packages/.*||' mirror)" mirrors
2304 # packages.info
2305 download_from "$(cat mirror)" packages.info.lzma
2306 lzma d packages.info.lzma packages.info
2307 rm packages.info.lzma
2309 if [ -f "packages.list.bak" ]; then
2310 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
2311 [ -f "extra.list.bak" ] &&
2312 diff -u extra.list.bak extra.list | grep ^+[a-z] >> packages.diff
2313 sed -i s/+// packages.diff
2314 title 'Mirrored packages diff'
2315 cat packages.diff
2316 new_pkgs=$(wc -l < packages.diff)
2317 footer "$(emsg "$(_p \
2318 '%s new package on the mirror.' \
2319 '%s new packages on the mirror.' $new_pkgs \
2320 "<c 32>$new_pkgs</c>")")"
2321 else
2322 footer "$(longline "$(_ "Last %s is ready to use. Note that \
2323 next time you recharge the list, a list of differences will be displayed to \
2324 show new and upgradeable packages." packages.list)")"
2325 fi
2326 done ;;
2329 help-up)
2330 # Options available for the command: up
2331 newline; usage_up; newline
2332 exit 1 ;;
2335 up|upgrade)
2336 check_root
2338 # This is the new way to upgrade packages making 'upgrade' and
2339 # upgradeable out-of-date. This new way is much, much more faster!
2340 # Look into installed packages and get data from receipt, it is fast
2341 # and easy to handle vars after using only md5sum to compare packages
2343 for opt in $@; do
2344 case "$opt" in
2345 --recharge|-r) tazpkg recharge ;;
2346 --install|-i) install="y" ;;
2347 --check|-c) install="n" ;;
2348 esac
2349 done
2350 time=$(date +%s)
2352 look_for_priority
2353 for repo in $priority; do
2354 pkg_list=$repo/packages.list
2355 mtime=$(find $pkg_list -mtime +7)
2356 if [ "$mtime" ]; then
2357 if [ "$repo" == "$PKGS_DB" ]; then
2358 repo_name=main
2359 else
2360 repo_name="${repo##*/}"
2361 fi
2362 _ 'List "%s" is older than one week... Recharging.' $pkg_list
2363 tazpkg recharge $repo_name
2364 fi
2365 done
2367 emsg "<n>$(_ 'Package')<i 28> $(_ 'Version')<i 48> $(_ 'Status')<->"
2369 cd $INSTALLED
2370 echo -n > $UP_LIST
2371 blocked_count=0
2372 installed_sum=$PKGS_DB/installed.$SUM
2374 for pkg in *; do
2375 [ ! -d $pkg ] && continue
2376 unset VERSION EXTRAVERSION
2377 . $pkg/receipt
2378 md5=$(fgrep " $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" \
2379 $installed_sum | awk '{print $1}')
2380 for repo in $priority; do
2381 pkg_desc=$repo/packages.desc
2382 pkg_list=$repo/packages.list
2383 pkg_sum=$repo/packages.$SUM
2385 if ! fgrep -q "$md5 $PACKAGE-" $pkg_sum; then
2386 # Jump to next repository in priority if pkg doesn't exist
2387 # in this one.
2388 grep -q ^$PACKAGE- $pkg_list || continue
2390 emsg -n "$PACKAGE<i 28> $VERSION"
2392 # Skip pkgs listed in $PKGS_DB/blocked-packages.list
2393 if $(grep -qs "^$PACKAGE" $BLOCKED); then
2394 blocked_count=$(($blocked_count + 1))
2395 emsg "<i 48><c 31> $(_ 'Blocked')</c>"
2396 break
2397 fi
2399 new=$(grep "^$PACKAGE |" $pkg_desc | awk '{print $3}')
2401 if [ "$VERSION" == "$new" ]; then
2402 emsg "<i 48><c 34> $(_ 'New build')</c>"
2403 else
2404 emsg "<i 48><c 32> $(_ 'New version %s' $new)</c>"
2405 fi
2406 echo "$PACKAGE" >> $UP_LIST
2407 break
2408 fi
2409 done
2410 done
2411 sed -i /^$/d $UP_LIST
2412 upnb=$(wc -l < $UP_LIST)
2413 pkgs=$(ls | wc -l)
2414 time=$(($(date +%s) - $time))
2415 if [ "$upnb" == 0 ]; then
2416 install="n"
2417 _ 'System is up-to-date...'
2418 fi
2420 footer "$(emsg "$(_p \
2421 '%s installed package scanned in %ds' \
2422 '%s installed packages scanned in %ds' $pkgs \
2423 "<c 32>$pkgs</c>" $time)")"
2425 if [ "$upnb" != 0 ]; then
2426 blocked="$(_p \
2427 '%s blocked' \
2428 '%s blocked' $blocked_count \
2429 $blocked_count)"
2431 boldify "$(_p \
2432 'You have %s available upgrade (%s)' \
2433 'You have %s available upgrades (%s)' $upnb \
2434 $upnb "$blocked")"
2435 newline
2436 fi
2437 # Pkgs to upgrade ? Skip, let install them all or ask user
2438 [ "$install" == "n" ] && exit 0
2439 if [ "$upnb" -gt 0 ]; then
2440 if [ "$install" == "y" ]; then
2441 answer=0
2442 else
2443 confirm "$(_ 'Do you wish to install them now? (y/N)')"
2444 answer=$?
2445 fi
2446 case "$answer" in
2447 0)
2448 for pkg in $(cat $UP_LIST); do
2449 echo 'y' | tazpkg get-install $pkg --forced
2450 done
2451 # List is generated each time and must be cleaned so
2452 # tazpkg-notify doesn't find upgrades anymore.
2453 rm $UP_LIST; touch $UP_LIST ;;
2454 *)
2455 _ 'Leaving without any upgrades installed.'
2456 newline
2457 exit 0 ;;
2458 esac
2459 fi
2460 newline ;;
2463 bugs)
2464 # Show known bugs in package(s)
2465 cd $INSTALLED
2466 shift
2467 LIST=$@
2468 [ -n "$LIST" ] || LIST=$(ls)
2469 MSG=$(_n 'No known bugs.')
2470 for PACKAGE in $LIST; do
2471 BUGS=""
2472 EXTRAVERSION=""
2473 . $PACKAGE/receipt
2474 if [ -n "$BUGS" ]; then
2475 MSG=$(_n 'Bug list completed')
2476 newline
2477 _ 'Bugs in package "%s" version %s:' $PACKAGE $VERSION$EXTRAVERSION
2478 cat <<EOT
2479 $BUGS
2480 EOT
2481 fi
2482 done
2483 echo "$MSG" ;;
2486 check)
2487 # Check installed packages set.
2488 check_root $@
2490 # Get repositories priority list.
2491 look_for_priority
2493 cd $INSTALLED
2494 for PACKAGE in $(ls); do
2496 if [ ! -f $PACKAGE/receipt ]; then
2497 _ 'The package "%s" installation has not completed' $PACKAGE
2498 continue
2499 fi
2501 DEPENDS=""
2502 EXTRAVERSION=""
2503 . $PACKAGE/receipt
2504 if [ -s $PACKAGE/modifiers ]; then
2505 _ 'The package "%s" has been modified by:' $PACKAGE-$VERSION$EXTRAVERSION
2506 for i in $(cat $PACKAGE/modifiers); do
2507 echo " $i"
2508 done
2509 fi
2511 MSG="$(_n 'Files lost from package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2512 while read file; do
2513 [ -e "$file" ] && continue
2514 if [ -L "$file" ]; then
2515 MSG="$MSG $(_n 'target of symlink')"
2516 fi
2517 echo -e "$MSG $file"
2518 MSG=""
2519 done < $PACKAGE/files.list
2521 MSG="$(_n 'Missing dependencies for package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2522 for i in $DEPENDS; do
2523 [ -d $i ] && continue
2524 [ -d $(equivalent_pkg $i) ] && continue
2525 echo -e "$MSG $i"
2526 MSG=""
2527 done
2529 MSG="$(_n 'Dependencies loop between "%s" and:' $PACKAGE)\n"
2530 ALL_DEPS=""
2531 check_for_deps_loop $PACKAGE $DEPENDS
2532 done
2534 _ 'Looking for known bugs...'
2535 tazpkg bugs
2537 if [ "$2" == "--full" ]; then
2538 separator
2540 for file in */$CHECKSUM; do
2541 CONFIG_FILES=""
2542 . $(dirname "$file")/receipt
2543 [ -s "$file" ] || continue
2544 while read md5 f; do
2545 [ -f $f ] || continue
2546 for i in $CONFIG_FILES; do
2547 case "$f" in
2548 $i|$i/*) continue 2;;
2549 esac
2550 done
2551 echo "$md5 $f"
2552 done < "$file" | busybox $CHECKSUM -c - 2> /dev/null | \
2553 grep -v OK$ | sed "s/FAILED$/$CHECKSUM MISMATCH/"
2554 done
2556 FILES=" "
2557 for file in $(cat */files.list); do
2558 [ -d "$file" ] && continue
2559 case "$FILES" in *\ $file\ *) continue;; esac
2560 [ $(grep "^$(echo $file | grepesc)$" */files.list 2> /dev/null | \
2561 wc -l) -gt 1 ] || continue
2562 FILES="$FILES$file "
2563 _ 'The following packages provide file "%s":' $file
2564 grep -l "^$(echo $file | grepesc)$" */files.list | \
2565 while read f; do
2566 pkg=${f%/files.list}
2567 if [ -f $pkg/modifiers ]; then
2568 overriders=$(_n '(overridden by %s)' "$(tr '\n' ' ' | sed 's| $||' < $pkg/modifiers)")
2569 else
2570 overriders=''
2571 fi
2572 echo -n " $pkg $overriders"
2573 newline
2574 done
2575 done
2577 MSG="$(_n 'No package has installed the following files:')\n"
2578 find /etc /bin /sbin /lib /usr /var/www -not -type d 2>/dev/null | \
2579 while read file; do
2580 case "$file" in *\[*) continue;; esac
2581 grep -q "^$(echo $file | grepesc)$" */files.list && continue
2582 echo -e "$MSG $file"
2583 MSG=""
2584 done
2585 fi
2586 _ 'Check completed.'; echo ;;
2589 block|-b)
2590 # Add a pkg name to the list of blocked packages.
2591 check_root $@
2592 check_for_package_on_cmdline
2593 newline
2594 if [ ! -d $INSTALLED/$PACKAGE ]; then
2595 _ 'Package "%s" is not installed.' $PACKAGE; exit
2596 fi
2597 if grep -qs "^$PACKAGE" $BLOCKED; then
2598 _ 'Package "%s" is already blocked.' $PACKAGE
2599 else
2600 echo $PACKAGE >> $BLOCKED
2601 # Log this activity
2602 . $INSTALLED/$PACKAGE/receipt; log_pkg Blocked
2603 _ 'Package "%s" blocked.' $PACKAGE
2604 fi
2605 newline ;;
2608 unblock|-u)
2609 # Remove a pkg name from the list of blocked packages.
2610 check_root $@
2611 check_for_package_on_cmdline
2612 newline
2613 if [ ! -d $INSTALLED/$PACKAGE ]; then
2614 _ 'Package "%s" is not installed.' $PACKAGE; exit
2615 fi
2616 if grep -qs "^$PACKAGE" $BLOCKED; then
2617 sed -i "/^$PACKAGE\$/d" $BLOCKED
2618 # Log this activity
2619 . $INSTALLED/$PACKAGE/receipt; log_pkg Unblocked
2620 _ 'Package "%s" unblocked.' $PACKAGE
2621 else
2622 _ 'Package "%s" is not blocked.' $PACKAGE
2623 fi
2624 newline ;;
2627 chblock)
2628 # Change package's blocked status.
2629 check_root $@
2630 check_for_package_on_cmdline
2631 newline
2632 if [ ! -d $INSTALLED/$PACKAGE ]; then
2633 _ 'Package "%s" is not installed.' $PACKAGE; exit
2634 fi
2635 if grep -qs "^$PACKAGE" $BLOCKED; then
2636 sed -i "/^$PACKAGE\$/d" $BLOCKED
2637 # Log this activity
2638 . $INSTALLED/$PACKAGE/receipt; log_pkg Unblocked
2639 _ 'Package "%s" unblocked.' $PACKAGE
2640 else
2641 echo $PACKAGE >> $BLOCKED
2642 # Log this activity
2643 . $INSTALLED/$PACKAGE/receipt; log_pkg Blocked
2644 _ 'Package "%s" blocked.' $PACKAGE
2645 fi
2646 newline ;;
2649 get|-g)
2650 # Download a package with wget.
2651 check_root $@
2652 check_for_package_on_cmdline
2653 check_for_packages_list
2655 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2656 if [ "$rootconfig" ]; then
2657 if [ "$root" ]; then
2658 CACHE_DIR=$root/$CACHE_DIR
2659 SAVE_CACHE_DIR=$CACHE_DIR
2660 PKGS_DB=$root/$PKGS_DB
2661 else
2662 _ 'rootconfig needs --root= option used.' >&2
2663 exit 1
2664 fi
2665 fi
2667 # Get repositories priority list.
2668 look_for_priority
2670 CURRENT_DIR=$PWD
2671 cd $CACHE_DIR
2672 if check_for_package_in_list check ; then
2673 if [ -f "$PACKAGE.tazpkg" ]; then
2674 _ 'Package "%s" already in the cache' $PACKAGE
2675 # Check package download was finished
2676 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2677 _ 'Continuing package "%s" download' $PACKAGE
2678 download $PACKAGE.tazpkg
2680 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2681 rm -f $PACKAGE.tazpkg
2682 download $PACKAGE.tazpkg
2683 fi
2684 else
2685 download $PACKAGE.tazpkg
2686 fi
2687 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2688 elif download_get_script $PACKAGE /tmp/$PACKAGE.$$ ; then
2689 install_package_from_get_script /tmp/$PACKAGE.$$ "$ROOT" --get
2690 PACKAGE_FILE=$(ls $PWD/$PACKAGE-*.tazpkg)
2691 fi
2692 [ "$PWD" != "$CURRENT_DIR" ] &&
2693 cp -a $PACKAGE_FILE $CURRENT_DIR ;;
2696 get-install|-gi)
2697 # Download and install a package.
2698 check_root $@
2699 check_for_package_on_cmdline
2700 check_for_packages_list
2702 DO_CHECK=""
2703 [ "$forced" ] && DO_CHECK=no
2704 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2705 [ "$list" ] && INSTALL_LIST="$list"
2706 if [ "$rootconfig" ]; then
2707 if [ "$root" ]; then
2708 CACHE_DIR=$root/$CACHE_DIR
2709 SAVE_CACHE_DIR=$CACHE_DIR
2710 PKGS_DB=$root/$PKGS_DB
2711 else
2712 _ 'rootconfig needs --root= option used.' >&2
2713 exit 1
2714 fi
2715 fi
2717 # Get repositories priority list.
2718 look_for_priority
2720 AUTOEXEC="no"
2721 if ! check_for_package_in_list check; then
2722 CACHE_DIR="${CACHE_DIR%/*}/get"
2723 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
2724 if download_get_script $PACKAGE /tmp/$PACKAGE.$$ ; then
2725 install_package_from_get_script /tmp/$PACKAGE.$$ $ROOT
2726 exit 0
2727 else
2728 PACKAGE=get-$PACKAGE
2729 AUTOEXEC=$PACKAGE
2730 check_for_package_in_list
2731 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
2732 $AUTOEXEC $ROOT
2733 exit 0
2734 fi
2735 fi
2736 fi
2737 # Check if forced install.
2738 if ! [ "$forced" ]; then
2739 check_for_installed_package $ROOT
2740 fi
2741 cd $CACHE_DIR
2742 if [ -f "$PACKAGE.tazpkg" ]; then
2743 _ 'Package "%s" already in the cache' $PACKAGE
2744 # Check package download was finished
2745 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2746 _ 'Continuing package "%s" download' $PACKAGE
2747 download $PACKAGE.tazpkg
2749 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2750 rm -f $PACKAGE.tazpkg
2751 download $PACKAGE.tazpkg
2752 fi
2753 else
2754 newline
2755 download $PACKAGE.tazpkg
2756 fi
2757 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2758 [ "$rootconfig" ] && PKGS_DB=${PKGS_DB#$root}
2759 install_package $ROOT
2760 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
2761 update_desktop_database $ROOT
2762 update_mime_database $ROOT ;;
2765 clean-cache|-cc)
2766 # Remove all downloaded packages.
2767 check_root $@
2768 files=$(find $CACHE_DIR -name *.tazpkg | wc -l)
2769 size=$(du -hs $CACHE_DIR | cut -f1 | sed 's|\.0||'); [ $files == "0" ] && size="0K"
2770 title 'Path: %s' $CACHE_DIR
2771 action "Cleaning cache directory..."
2772 rm -rf $CACHE_DIR/*
2773 status
2775 footer "$(_p \
2776 '%s file removed from cache (%s).' \
2777 '%s files removed from cache (%s).' $files \
2778 "$(colorize 32 "$files")" $size)"
2779 ;;
2782 list-undigest)
2783 # list undigest URLs.
2784 if [ "$2" = "--box" ]; then
2785 for i in $PKGS_DB/undigest/*/mirror; do
2786 [ -f $i ] || continue
2787 echo "$(basename $(dirname $i))|$(cat $i)"
2788 done
2789 else
2790 title 'Current undigest(s)'
2791 for i in $PKGS_DB/undigest/*/mirror; do
2792 if [ ! -f $i ]; then
2793 _ 'No undigest mirror found.'
2794 exit 1
2795 fi
2796 echo "$(basename $(dirname $i)) $(cat $i)"
2797 done
2798 newline
2799 fi ;;
2802 remove-undigest)
2803 # remove undigest URL.
2804 check_root $@
2805 undigest="$2"
2806 if [ -d $PKGS_DB/undigest/$2 ]; then
2807 confirm "$(_ 'Remove "%s" undigest? (y/N)' $undigest)"
2808 if [ $? = 0 ]; then
2809 action 'Removing "%s" undigest...' $undigest
2810 rm -rf $PKGS_DB/undigest/$2
2811 status
2812 rmdir $PKGS_DB/undigest 2> /dev/null
2813 fi
2814 else
2815 _ 'Undigest "%s" not found' $undigest
2816 fi ;;
2819 add-undigest|setup-undigest)
2820 # Add undigest URL.
2821 check_root $@
2822 undigest=$2
2823 [ -d $PKGS_DB/undigest ] || mkdir $PKGS_DB/undigest
2824 if [ -z "$undigest" ]; then
2825 i=1
2826 while [ -d $PKGS_DB/undigest/$i ]; do
2827 i=$(($i+1))
2828 done
2829 undigest=$i
2830 fi
2831 if [ ! -d $PKGS_DB/undigest/$undigest ]; then
2832 _ 'Creating new undigest "%s".' $undigest
2833 mkdir $PKGS_DB/undigest/$undigest
2834 fi
2835 setup_mirror $PKGS_DB/undigest/$undigest $3 ;;
2838 setup-mirror|-sm)
2839 # Change mirror URL.
2840 check_root $@
2841 setup_mirror $PKGS_DB $2 ;;
2844 reconfigure)
2845 # Replay post_install from receipt
2846 check_for_package_on_cmdline
2847 check_root $@
2848 ROOT=""
2849 while [ -n "$3" ]; do
2850 case "$3" in
2851 --root=*)
2852 ROOT="${3#--root=}/" ;;
2853 *)
2854 shift 2
2855 u_opt="$*"
2856 newline >&2
2857 _ 'Unknown option "%s".' $u_opt >&2
2858 exit 1 ;;
2859 esac
2860 shift
2861 done
2862 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2863 check_for_receipt $ROOT
2864 # Check for post_install
2865 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2866 . $ROOT$INSTALLED/$PACKAGE/receipt
2867 post_install $ROOT
2868 # Log this activity
2869 [ -n "$ROOT" ] || log_pkg Reconfigured
2870 else
2871 newline
2872 _ 'Nothing to do for package "%s".' $PACKAGE
2873 fi
2874 else
2875 newline
2876 _ 'Package "%s" is not installed.' $PACKAGE
2877 _ 'Install package with "%s" or "%s"' 'tazpkg install' 'tazpkg get-install'
2878 newline
2879 fi ;;
2882 shell)
2883 # TazPKG SHell
2884 if test $(id -u) = 0 ; then
2885 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2886 else
2887 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2888 fi
2889 if [ ! "$2" = "--noheader" ]; then
2890 clear
2891 title 'TazPKG SHell.'
2892 _ "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
2893 newline
2894 fi
2895 while true; do
2896 echo -en "$PROMPT"; read cmd
2897 case $cmd in
2898 q|quit)
2899 break ;;
2900 shell)
2901 _ 'You are already running a TazPKG SHell.' ;;
2902 su)
2903 su -c 'exec tazpkg shell --noheader' && break ;;
2904 "")
2905 continue ;;
2906 *)
2907 tazpkg $cmd ;;
2908 esac
2909 done ;;
2912 depends)
2913 # Display dependencies tree
2914 cd $INSTALLED
2915 ALL_DEPS=""
2916 if [ -f $2/receipt ]; then
2917 dep_scan $2 ""
2918 fi ;;
2921 rdepends)
2922 # Display reverse dependencies tree
2923 cd $INSTALLED
2924 ALL_DEPS=""
2925 if [ -f $2/receipt ]; then
2926 rdep_scan $2
2927 fi ;;
2930 list-suggested)
2931 for i in $(ls -d $INSTALLED/*); do
2932 . $i/receipt
2933 if [ "$SUGGESTED" ]; then
2934 if [ -z "$all" ]; then
2935 for s in $SUGGESTED; do
2936 [ -d $INSTALLED/$s ] && \
2937 SUGGESTED=$(echo -n $SUGGESTED | sed "s/$s//")
2938 done
2939 fi
2940 cat <<EOT
2941 $(boldify $(echo $PACKAGE):) $SUGGESTED
2942 EOT
2943 fi
2944 SUGGESTED=""
2945 done ;;
2948 convert|-c)
2949 # convert misc package format to .tazpkg
2950 check_for_package_file
2951 shift
2952 tazpkg-convert $@
2953 ;;
2956 link)
2957 # link a package from another slitaz installation
2958 PACKAGE=$2
2959 if [ ! -d "$TARGET_DIR" -o \
2960 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
2961 _ 'Usage: tazpkg link package_name slitaz_root'
2962 longline "$(
2963 _n 'Example:'
2964 echo -n ' '
2965 _ '"%s" will use less than 100k in your running system RAM.' \
2966 'tazpkg link openoffice /mnt')"
2967 exit 1
2968 fi
2969 if [ -e "$INSTALLED/$PACKAGE" ]; then
2970 _ 'Package "%s" is already installed.' $PACKAGE
2971 exit 1
2972 fi
2973 ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
2974 DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
2975 MISSING=""
2976 for i in $DEPENDS; do
2977 [ -e $INSTALLED/$i ] && continue
2978 MISSING="$MISSING$i "
2979 _ 'Missing: %s' $i
2980 done
2981 if [ -n "$MISSING" ]; then
2982 newline
2983 confirm "$(_ 'Link all missing dependencies? (y/N)')"
2984 answer=$?
2985 newline
2986 if [ $answer = 0 ]; then
2987 for i in $MISSING; do
2988 tazpkg link $i $TARGET_DIR
2989 done
2990 else
2991 newline
2992 _ 'Leaving dependencies unresolved for package "%s"' $PACKAGE
2993 _ 'The package is installed but probably will not work.'
2994 newline
2995 fi
2996 fi
2997 . $INSTALLED/$PACKAGE/receipt
2998 if grep -q ^pre_install $INSTALLED/$PACKAGE/receipt; then
2999 pre_install
3000 fi
3001 while read path; do
3002 [ -e $path ] && continue
3003 while true; do
3004 dir=$(dirname $path)
3005 [ -e $dir ] && break
3006 path=$dir
3007 done
3008 ln -s $TARGET_DIR$path $dir
3009 done < $INSTALLED/$PACKAGE/files.list
3010 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
3011 post_install
3012 fi ;;
3015 usage|*)
3016 # Print a short help or give usage for an unknown or empty command.
3017 usage ;;
3018 esac
3020 exit 0