tazpkg view tazpkg @ rev 795

pkgs.cgi: change look of "do=command" page; tazpkg: rework "remove" command.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu Apr 30 02:21:14 2015 +0300 (2015-04-30)
parents afe32a913bc4
children 547d8bdde963
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" ] && \
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
913 }
916 # This function may be called by a get script.
918 abort_package()
919 {
920 cd $CUR_DIR
921 rm -rf $TMP_DIR
922 echo "${1:-Abort $PACKAGE.}"
923 exit 1
924 }
927 # This function installs a package from a get script in the rootfs.
929 install_package_from_get_script()
930 {
931 SCRIPT="$1"
932 ROOT="$2"
933 [ -d $ROOT$INSTALLED/$PACKAGE ] && exit 1
935 grep -q no-check-certificate $SCRIPT &&
936 [ ! -d $INSTALLED/wget ] && tazpkg get-install wget
938 mkdir -p $TMP_DIR && cd $TMP_DIR
939 saved=$PACKAGE
940 unset_receipt
941 PACKAGE=$saved
943 set -e
944 . $SCRIPT
945 set +e
946 [ -d $PACKAGE-$VERSION ] || cd $TMP_DIR
947 [ -d $PACKAGE-$VERSION ] || abort_package \
948 "$(_ 'Could not download "%s" from "%s". Exiting.' ${TARBALL:-$PACKAGE} ${WGET_URL:-$WEB_SITE})"
950 if [ ! -s $PACKAGE-$VERSION/receipt ]; then
951 cat > $PACKAGE-$VERSION/receipt <<EOT
952 # SliTaz package receipt.
954 PACKAGE="$PACKAGE"
955 VERSION="${VERSION:-unknown}"
956 CATEGORY="${CATEGORY:-non-free}"
957 WEB_SITE="$WEB_SITE"
958 SHORT_DESC="${SHORT_DESC:-$PACKAGE}"
959 MAINTAINER="${MAINTAINER:-nobody@slitaz.org}"
960 EOT
961 for i in LICENSE TARBALL WGET_URL CONFIG_FILES SUGGESTED \
962 PROVIDE DEPENDS HOST_ARCH TAGS EXTRA_SOURCE_FILES ; do
963 eval "[ -n \"\$$i\" ] && echo \"$i=\\\"\$$i\\\"\""
964 done >> $PACKAGE-$VERSION/receipt
965 fi
967 DEPENDS="$(unset DEPENDS; . $PACKAGE-$VERSION/receipt ; echo $DEPENDS)"
968 for i in $(find_depends $PACKAGE-$VERSION/fs); do
969 case " $DEPENDS " in
970 *\ $i\ *) continue;;
971 esac
972 grep -q '^DEPENDS="' $PACKAGE-$VERSION/receipt ||
973 echo 'DEPENDS=""' >> $PACKAGE-$VERSION/receipt
974 sed -i "s/^DEPENDS=\"/&$i /" $PACKAGE-$VERSION/receipt
975 done
977 tazpkg pack $PACKAGE-$VERSION
979 # Clean to save RAM memory before installation
980 rm -rf $PACKAGE-$VERSION
982 if [ "$3" == "--get" ]; then
983 mv $PACKAGE-$VERSION.tazpkg $TOP_DIR
984 else
985 # Install pseudo package
986 tazpkg install $PACKAGE-$VERSION.tazpkg --root=$ROOT
987 mv $PACKAGE-$VERSION.tazpkg $CACHE_DIR
988 fi
990 # Clean
991 cd $TOP_DIR
992 rm -rf $TMP_DIR
993 }
996 # Check for loop in deps tree.
998 check_for_deps_loop()
999 {
1000 local list
1001 local pkg
1002 local deps
1003 pkg=$1
1004 shift
1005 [ -n "$1" ] || return
1006 list=""
1008 # Filter out already processed deps
1009 for i in $@; do
1010 case " $ALL_DEPS" in
1011 *\ $i\ *) ;;
1012 *) list="$list $i";;
1013 esac
1014 done
1015 ALL_DEPS="$ALL_DEPS$list "
1016 for i in $list; do
1017 [ -f $i/receipt ] || continue
1018 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
1019 case " $deps " in
1020 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
1021 *) check_for_deps_loop $pkg $deps;;
1022 esac
1023 done
1027 # Check for missing deps listed in a receipt packages.
1029 check_for_deps()
1031 local saved;
1032 saved=$PACKAGE
1033 mkdir -p $TMP_DIR
1034 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
1035 . $TMP_DIR/receipt
1036 PACKAGE=$saved
1037 rm -rf $TMP_DIR
1039 num=0
1040 for pkgorg in $DEPENDS; do
1041 i=$(equivalent_pkg $pkgorg $1)
1042 if [ ! -d "$1$INSTALLED/$i" ]; then
1043 MISSING_PACKAGE=$i
1044 num=$(($num+1))
1045 elif [ ! -f "$1$INSTALLED/$i/receipt" ]; then
1046 _ 'WARNING! Dependency loop between "%s" and "%s".' $PACKAGE $i
1047 fi
1048 done
1050 if [ -n "$MISSING_PACKAGE" ]; then
1051 title "$(_ 'Tracking dependencies for package "%s"' $PACKAGE)"
1052 for pkgorg in $DEPENDS; do
1053 i=$(equivalent_pkg $pkgorg $1)
1054 if [ ! -d "$1$INSTALLED/$i" ]; then
1055 MISSING_PACKAGE=$i
1056 _ 'Missing package "%s"' $MISSING_PACKAGE
1057 fi
1058 done
1059 footer "$(_p \
1060 '%s missing package to install.' \
1061 '%s missing packages to install.' $num \
1062 $num)"
1063 fi
1067 # Install all missing deps. Auto install or ask user then install all missing
1068 # deps from local dir, cdrom, media or from the mirror. In case we want to
1069 # install packages from local, we need a packages.list to find the version.
1071 install_deps()
1073 local root
1074 root=""
1075 [ -n "$1" ] && root="--root=$1"
1076 if [ "$AUTO_INSTALL_DEPS" == "yes" ]; then
1077 answer=0
1078 else
1079 newline
1080 confirm "$(_ 'Install all missing dependencies? (y/N)')"
1081 answer=$?
1082 newline
1083 fi
1084 if [ $answer = 0 ] && ! [ "$nodeps" ]; then
1085 for pkgorg in $DEPENDS; do
1086 pkg=$(equivalent_pkg $pkgorg $1)
1087 if [ ! -d "$1$INSTALLED/$pkg" ]; then
1088 local list
1089 list="$INSTALL_LIST"
1090 [ -n "$list" ] || list="$TOP_DIR/packages.list"
1091 # We can install packages from a local dir by greping
1092 # the TAZPKG_BASENAME in the local packages.list.
1093 found=0
1094 if [ -f "$list" ]; then
1095 _ 'Checking if package "%s" exists in local list...' $pkg
1096 mkdir $TMP_DIR
1097 for i in $pkg-*.tazpkg; do
1098 [ -f $i ] || continue
1099 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $i
1100 [ "$(. $TMP_DIR/receipt; echo $PACKAGE)" = "$pkg" ] || continue
1101 if grep -q ^$(package_fullname_in_dir $TMP_DIR).tazpkg$ $list
1102 then
1103 found=1
1104 tazpkg install $i $root --list=$list
1105 break
1106 fi
1107 done
1108 rm -rf $TMP_DIR
1109 fi
1110 # Install deps from the mirror.
1111 if [ $found -eq 0 ]; then
1112 if [ ! -f "$PKGS_DB/packages.list" ]; then
1113 tazpkg recharge
1114 fi
1115 tazpkg get-install $pkg $root
1116 fi
1117 fi
1118 done
1119 else
1120 newline
1121 _ 'Leaving dependencies for package "%s" unresolved.' $PACKAGE
1122 _ 'The package is installed but will probably not work.'
1123 newline
1124 fi
1128 # Search pattern in installed packages.
1130 search_in_installed_packages()
1132 _ 'Installed packages'
1133 separator
1134 num=0
1135 for pkg in $(ls -1 $INSTALLED | grep -i "$PATTERN"); do
1136 EXTRAVERSION=""
1137 [ -f $INSTALLED/$pkg/receipt ] || continue
1138 . $INSTALLED/$pkg/receipt
1139 emsg "$PACKAGE<i 24> $VERSION$EXTRAVERSION<i 42> $(_n $CATEGORY)"
1140 num=$(($num+1))
1141 done
1143 footer "$(_p \
1144 '%s installed package found for "%s"' \
1145 '%s installed packages found for "%s"' $num \
1146 $num "$PATTERN")"
1150 # Search in packages.list for available pkgs.
1152 search_in_packages_list()
1154 _ 'Available packages'
1155 separator
1156 num=0
1157 BPATTERN="$(emsg "<b>$PATTERN</b>")"
1158 for i in $PKGS_DB/packages.list $PKGS_DB/undigest/*/packages.list \
1159 $PKGS_DB/extra.list $PKGS_DB/undigest/*/extra.list ; do
1160 grep -is "$PATTERN" $i | sed "s|$PATTERN|$BPATTERN|"
1161 num=$(($num + `grep -is "$PATTERN" $i | wc -l`))
1162 done
1163 if [ ! -f "$PKGS_DB/packages.list" ]; then
1164 newline
1165 longline "$(_ \
1166 "No \"%s\" found to check for mirrored packages. For more results, please run \
1167 \"%s\" once as root before searching." packages.list 'tazpkg recharge')"
1168 newline
1169 fi
1170 footer "$(_p \
1171 '%s available package found for "%s"' \
1172 '%s available packages found for "%s"' $num \
1173 $num $PATTERN)"
1177 # search --mirror: Search in packages.txt for available pkgs and give more
1178 # info than --list or default.
1180 search_in_packages_txt()
1182 _ 'Matching packages name with version and desc'
1183 separator
1184 num=0
1185 for i in $PKGS_DB/packages.txt $PKGS_DB/undigest/*/packages.txt; do
1186 grep -is -A 2 "^$PATTERN" $i
1187 num=$(($num + `grep -is "^$PATTERN" $i | wc -l`))
1188 done
1189 if [ ! -f "$PKGS_DB/packages.txt" ]; then
1190 newline
1191 longline "$(_ \
1192 "No \"%s\" found to check for mirrored packages. For more results, please run \
1193 \"%s\" once as root before searching." packages.txt 'tazpkg recharge')"
1194 newline
1195 fi
1196 footer "$(_p \
1197 '%s available package found for "%s"' \
1198 '%s available packages found for "%s"' $num \
1199 $num $PATTERN)"
1203 # Install package-list from a flavor
1205 install_flavor()
1207 check_root $@
1209 # Get repositories priority list.
1210 look_for_priority
1212 FLAVOR=$1
1213 ARG=$2
1214 mkdir -p $TMP_DIR
1215 [ -f $FLAVOR.flavor ] && cp $FLAVOR.flavor $TMP_DIR
1216 cd $TMP_DIR
1217 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1218 zcat < $FLAVOR.flavor | cpio --quiet -i >/dev/null
1220 while read file; do
1221 for pkg in $(ls -d $INSTALLED/${file%%-*}*); do
1222 [ -f $pkg/receipt ] || continue
1223 EXTRAVERSION=""
1224 . $pkg/receipt
1225 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && break
1226 done
1227 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && continue
1228 cd $CACHE_DIR
1229 download $file.tazpkg
1230 cd $TMP_DIR
1231 tazpkg install $CACHE_DIR/$file.tazpkg --forced
1232 done < $FLAVOR.pkglist
1234 [ -f $FLAVOR.nonfree ] && while read pkg; do
1235 [ -d $INSTALLED/$pkg ] || continue
1236 [ -d $INSTALLED/get-$pkg ] && tazpkg get-install get-$pkg
1237 get-$pkg
1238 done < $FLAVOR.nonfree
1240 [ "$ARG" == "--purge" ] && for pkg in $(ls $INSTALLED); do
1241 [ -f $INSTALLED/$pkg/receipt ] || continue
1242 EXTRAVERSION=""
1243 . $INSTALLED/$pkg/receipt
1244 grep -q ^$PACKAGE-$VERSION$EXTRAVERSION$ $FLAVOR.pkglist && continue
1245 grep -qs ^$PACKAGE$ $FLAVOR.nonfree && continue
1246 tazpkg remove $PACKAGE
1247 done
1248 else
1249 _ "Can't find flavor \"%s\". Abort." $FLAVOR
1250 fi
1251 cd $TOP_DIR
1252 rm -rf $TMP_DIR
1256 # Update mirror urls
1258 setup_mirror()
1260 # Backup old list.
1261 if [ -f "$1/mirror" ]; then
1262 cp -f $1/mirror $1/mirror.bak
1263 fi
1264 title 'Current mirror(s)'
1265 echo " `cat $1/mirror 2> /dev/null`"
1266 longline "$(_ \
1267 "Please enter URL of the new mirror (http, ftp or local path). You must specify \
1268 the complete address to the directory of the packages and packages.list file.")"
1269 newline
1270 _n 'New mirror(s) URL: '
1271 NEW_MIRROR_URL=$2
1272 if [ -n "$NEW_MIRROR_URL" ]; then
1273 echo $NEW_MIRROR_URL
1274 else
1275 read NEW_MIRROR_URL
1276 fi
1277 if [ "$NEW_MIRROR_URL" = "" ]; then
1278 _ 'Nothing has been changed.'
1279 else
1280 _ 'Setting mirror(s) to: "%s"' $NEW_MIRROR_URL
1281 rm -f $1/mirror
1282 for i in $NEW_MIRROR_URL; do
1283 echo "${i%/}/" >> $1/mirror
1284 done
1285 fi
1286 newline
1290 # recursive dependencies scan
1292 dep_scan()
1294 for i in $1; do
1295 case " $ALL_DEPS " in
1296 *\ $i\ *) continue;;
1297 esac
1298 ALL_DEPS="$ALL_DEPS $i"
1299 [ -n "$2" ] && echo "$2$i ($(fgrep -A 3 $i $PKGS_DB/packages.txt | \
1300 tail -1 | sed 's/.*(\([^ ]*\).*/\1/'))"
1301 [ -f $i/receipt ] || continue
1302 DEPENDS=""
1303 . $i/receipt
1304 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
1305 done
1309 # recursive reverse dependencies scan
1311 rdep_scan()
1313 SEARCH=$1
1315 for i in * ; do
1316 DEPENDS=""
1317 . $i/receipt
1318 echo "$i $(echo $DEPENDS)"
1319 done | busybox awk -v search=$SEARCH '
1320 function show_deps(deps, all_deps, pkg, space)
1322 if (all_deps[pkg] == 1) return
1323 all_deps[pkg] = 1
1324 if (space != "") printf "%s %s\n",space,pkg
1325 for (i = 1, n = split(deps[pkg], mydeps, " "); i <= n; i++) {
1326 show_deps(deps, all_deps, mydeps[i],"==" space)
1331 all_deps[$1] = 0
1332 for (i = 2; i <= NF; i++)
1333 deps[$i] = deps[$i] " " $1
1336 END {
1337 show_deps(deps, all_deps, search, "")
1339 ' | while read spc pkg; do
1340 echo -n $spc | sed 's/=/ /g'
1341 echo -n $pkg
1342 echo -n ' ('
1343 fgrep -A 3 $pkg $PKGS_DB/packages.txt | tail -1 | \
1344 sed 's/.*(\([^ ]*\).*/\1)/'
1345 done
1349 update_desktop_database()
1351 if [ -f $1/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
1352 chroot "$1/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
1353 fi
1357 update_mime_database()
1359 if [ -f $1/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
1360 chroot "$1/" /usr/bin/update-mime-database /usr/share/mime
1361 fi
1365 update_icon_database()
1367 if [ -f $1/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
1368 chroot "$1/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
1369 fi
1373 compile_glib_schemas()
1375 if [ -f $1/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
1376 chroot "$1/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
1377 fi
1381 update_kernel_modules()
1383 if [ -f $1/sbin/depmod ] && [ -n "$updatedepmod" ]; then
1384 chroot "$1/" /sbin/depmod -a
1385 fi
1392 ###################
1393 # TazPKG commands #
1394 ###################
1396 case "$COMMAND" in
1397 list|-l)
1398 # List all installed packages or a specific category.
1399 shift
1400 check_for_installed_info
1402 case $1 in
1403 b|blocked)
1404 # Display the list of blocked packages.
1405 title 'Blocked packages'
1406 if [ -s "$BLOCKED" ];then
1407 cat $BLOCKED
1408 else
1409 _ 'No blocked packages found.'
1410 fi
1411 newline; exit 0
1412 ;;
1413 c|cat|categories)
1414 # Display the list of categories.
1415 title 'Packages categories'
1417 echo "$PKGS_CATEGORIES" | sed 's|[^a-z-]|\n|g; /^$/d' | \
1418 sed 's|\(.*\)|\1\t\1|' | translate_category | awk -F$'\t' '{
1419 if ($1==$2) print $1; else print $1"\033[15G "$2}'
1421 num=$(echo -n "$PKGS_CATEGORIES" | wc -l)
1422 footer "$(_p \
1423 '%s category' \
1424 '%s categories' $num \
1425 $num)"
1426 exit 0
1427 ;;
1428 '')
1429 # By default list all packages and versions.
1430 title 'List of all installed packages'
1431 TMPLIST=$(mktemp)
1432 awk -F$'\t' '{print $1"\033[35G "$2"\033[53G "$3}' \
1433 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
1435 packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST
1436 footer "$(emsg $(_p \
1437 '%s package installed.' \
1438 '%s packages installed.' $packages \
1439 "<c 32>$packages</c>"))"
1440 ;;
1441 *)
1442 # Check for an asked category.
1443 ASKED_CATEGORY_I18N="$@"
1444 ASKED_CATEGORY=$(reverse_translate_category "$ASKED_CATEGORY_I18N")
1445 title 'Installed packages of category "%s"' $ASKED_CATEGORY_I18N
1446 TMPLIST=$(mktemp)
1447 awk -F$'\t' '
1449 if ($3 == "'$ASKED_CATEGORY'")
1450 print $1"\033[35G "$2
1451 }' \
1452 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
1454 packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST
1455 footer "$(emsg $(_p \
1456 '%s package installed of category "%s".' \
1457 '%s packages installed of category "%s".' $packages \
1458 "<c 32>$packages</c>" "<c 34>$ASKED_CATEGORY_I18N</c>"))"
1459 ;;
1460 esac ;;
1462 list-mirror|-lm)
1463 # List all available packages on the mirror. Option --diff displays
1464 # last mirrored packages diff (see recharge).
1465 check_for_packages_list
1466 case $2 in
1467 --diff)
1468 if [ -f "$PKGS_DB/packages.diff" ]; then
1469 title 'Mirrored packages diff'
1470 cat $PKGS_DB/packages.diff
1471 num=$(wc -l < $PKGS_DB/packages.diff)
1472 footer "$(_p \
1473 '%s new package listed on the mirror.' \
1474 '%s new packages listed on the mirror.' $num \
1475 $num)"
1476 else
1477 newline
1478 _ 'Unable to list anything, no packages.diff found.'
1479 _ 'Recharge your current list to create a first diff.'
1480 newline
1481 fi; exit 0 ;;
1482 --text|--txt|--raw|*)
1483 title 'List of available packages on the mirror'
1484 cat $PKGS_DB/packages.txt ;;
1485 esac
1486 pkgs=$(wc -l < $PKGS_DB/packages.list)
1487 footer "$(emsg "$(_p \
1488 '%s package in the last recharged list.' \
1489 '%s packages in the last recharged list.' $pkgs \
1490 "<c 32>$pkgs</c>")")"
1491 ;;
1494 list-files|-lf)
1495 # List files installed with the package.
1496 check_for_package_on_cmdline
1497 check_for_receipt
1498 title 'Installed files by "%s"' $PACKAGE
1499 sort < $INSTALLED/$PACKAGE/files.list
1500 files=$(wc -l < $INSTALLED/$PACKAGE/files.list)
1501 footer "$(emsg "$(_p \
1502 '%s file' '%s files' $files \
1503 "<c 32>$files</c>")")"
1504 ;;
1507 info)
1508 # Information about package.
1509 check_for_package_on_cmdline
1510 check_for_receipt
1511 EXTRAVERSION=""
1512 . $INSTALLED/$PACKAGE/receipt
1513 im && title 'TazPKG information'
1514 # Display localized short description
1515 for LC in $LANG ${LANG%_*}; do
1516 if [ -e "$PKGS_DB/packages-desc.$LC" ]; then
1517 LOCDESC=$(grep -e "^$PACKAGE " $PKGS_DB/packages-desc.$LC | cut -d' ' -f2)
1518 [ -n "$LOCDESC" ] && SHORT_DESC="$LOCDESC"
1519 fi
1520 done
1521 SIZES=$(echo $PACKED_SIZE/$UNPACKED_SIZE | sed 's|\.0||g' | sed 's|^/$||')
1523 emsg "$(
1525 _ 'Package : %s' "$PACKAGE"
1526 _ 'Version : %s' "$VERSION$EXTRAVERSION"
1527 _ 'Category : %s' "$(_ $CATEGORY)"
1528 _ 'Short desc : %s' "$SHORT_DESC"
1529 _ 'Maintainer : %s' "$MAINTAINER"
1530 _ 'License : %s' "$LICENSE"
1531 _ 'Depends : %s' "$DEPENDS"
1532 _ 'Suggested : %s' "$SUGGESTED"
1533 _ 'Build deps : %s' "$BUILD_DEPENDS"
1534 _ 'Wanted src : %s' "$WANTED"
1535 _ 'Web site : %s' "$WEB_SITE"
1536 _ 'Size : %s' "$SIZES"
1537 _ 'Tags : %s' "$TAGS"
1538 } | sed '/: $/d; s|^\([^:]*\):|<b>\1:</b>|')"
1539 im && footer
1540 ;;
1543 desc)
1544 # Display package description
1545 if [ -n "$(grep -e "^$PACKAGE " $PKGS_DB/installed.info)" ]; then
1546 im && title 'Description of package "%s"' $PACKAGE
1547 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
1548 cat $INSTALLED/$PACKAGE/description.txt
1549 else
1550 im && awk -F$'\t' '{if ($1 == "'$PACKAGE'") print $4}' $PKGS_DB/installed.info
1551 fi
1552 im && footer
1553 else
1554 im && _ 'Package "%s" is not installed.' "$PACKAGE"
1555 fi
1556 ;;
1559 activity|log|-a)
1560 # Show activity log
1561 [ "$nb" ] || nb=18
1562 title 'TazPKG Activity'
1563 IFS=" "
1564 tail -n ${nb} ${LOG} | \
1565 while read date hour none action none pkg vers none; do
1566 case $action in
1567 Installed)
1568 action=$(colorize 32 $action) ;;
1569 Removed)
1570 action=$(colorize 31 $action) ;;
1571 *)
1572 action=$(boldify $action) ;;
1573 esac
1574 echo "$date $hour : $action $pkg $vers"
1575 done
1576 unset IFS
1577 footer ;;
1580 search|-s)
1581 # Search for a package by pattern or name.
1582 PATTERN="$2"
1583 if [ -z "$PATTERN" ]; then
1584 newline
1585 _ 'Please specify a pattern or package name to search for.'
1586 echo "$(_ 'Example:') 'tazpkg search paint'"
1587 newline
1588 exit 0
1589 fi
1590 title 'Search result for "%s"' $PATTERN
1591 # Default is to search in installed pkgs and the raw list.
1592 case "$3" in
1593 -i|--installed)
1594 search_in_installed_packages ;;
1595 -l|--list)
1596 search_in_packages_list ;;
1597 -m|--mirror)
1598 search_in_packages_txt ;;
1599 *)
1600 search_in_installed_packages
1601 search_in_packages_list ;;
1602 esac ;;
1605 search-file|-sf)
1606 # Search for a file by pattern or name in all files.list.
1607 if [ -z "$2" ]; then
1608 newline
1609 _ 'Please specify a pattern or file name to search for.'
1610 echo "$(_ 'Example:') 'tazpkg search-file libnss'"
1611 newline
1612 exit 0
1613 fi
1614 title 'Search result for file "%s"' $2
1616 TMPLIST=$(mktemp)
1617 if [ "$3" == "--mirror" ]; then
1619 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1620 [ -f $i ] || continue
1621 lzcat $i | awk -F: -vP="$(gettext 'Package %s:')" -vT=$TMPLIST '
1622 BEGIN { last = "" }
1623 $2 ~ /'$2'/ {
1624 if (last != $1) {
1625 last = $1;
1626 PP = P;
1627 sub(/%s/, $1, PP);
1628 printf("\n\e[1;33m%s\e[0;39m\n", PP);
1630 gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $2);
1631 print $2;
1632 printf "%s" 1 >> T;
1633 }'
1634 done
1636 else
1638 # Check all pkg files.list in search match which specify the package
1639 # name and the full path to the file(s).
1640 for pkg in $INSTALLED/*; do
1641 if grep -qs "$2" $pkg/files.list; then
1642 . $pkg/receipt
1643 newline
1644 emsg "<c 33>$(_ 'Package %s:' $PACKAGE)</c>"
1645 awk -vT=$TMPLIST '
1646 /'$2'/ {
1647 gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $0);
1648 print " "$0;
1649 printf "%s" 1 >> T;
1651 ' $pkg/files.list
1652 fi
1653 done
1655 fi
1657 match=$(wc -m < $TMPLIST)
1658 rm $TMPLIST
1660 footer "$(emsg "$(_p \
1661 '%s file' '%s files' $match \
1662 "<c 32>$match</c>")")"
1663 ;;
1666 search-pkgname)
1667 # Search for a package name
1668 if [ -z "$2" ]; then
1669 newline
1670 _ 'Please specify a pattern or file name to search for.'
1671 echo "$(_ 'Example:') 'tazpkg search-pkgname libnss'"
1672 newline
1673 exit 0
1674 fi
1675 title 'Search result for package "%s"' $2
1677 # Search for a file on mirror and output only the package name
1678 TMPLIST=$(mktemp)
1679 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1680 [ -f $i ] || continue
1681 lzcat $i | awk -F: -vT=$TMPLIST '
1682 BEGIN { P = "" }
1683 $2 ~ /'$2'/ {
1684 if ($1 != P) {
1685 print $1;
1686 printf "%s" 1 >> T;
1687 P = $1
1689 }'
1690 done
1691 match=$(wc -m < $TMPLIST)
1692 rm $TMPLIST
1694 footer "$(emsg "$(_p \
1695 '%s package' '%s packages' $match \
1696 "<c 32>$match</c>")")"
1697 ;;
1700 install|-i)
1701 # Install .tazpkg packages.
1702 check_root $@
1703 check_for_package_on_cmdline
1704 check_for_package_file
1705 check_for_installed_info
1707 if [ -n "$root" ]; then
1708 ROOT="$root";
1709 check_base_dir "$root"
1710 fi
1711 [ "$list" ] && INSTALL_LIST="$list"
1712 if [ "$rootconfig" ]; then
1713 if [ "$root" ]; then
1714 CACHE_DIR=$root/$CACHE_DIR
1715 SAVE_CACHE_DIR=$CACHE_DIR
1716 PKGS_DB=$root/$PKGS_DB
1717 else
1718 echo "rootconfig needs --root= option used." >&2
1719 exit 1
1720 fi
1721 fi
1723 # Get repositories priority list.
1724 look_for_priority
1726 # Check if forced install.
1727 if [ -z "$forced" ]; then
1728 check_for_installed_package $ROOT
1729 fi
1730 install_package $ROOT
1731 update_desktop_database $ROOT
1732 update_mime_database $ROOT
1733 update_icon_database $ROOT
1734 compile_glib_schemas $ROOT
1735 ;;
1738 install-list|get-install-list)
1739 # Install a set of packages from a list.
1740 check_root $@
1741 if [ -z "$2" ]; then
1742 newline
1743 longline "$(_ \
1744 "Please change directory (cd) to the packages repository and specify the \
1745 list of packages to install.")"
1746 echo "$(_ 'Example:') $(emsg '<b>tazpkg install-list</b> <c 33>packages.list</c>')"
1747 exit 0
1748 fi
1750 # Check if the packages list exist.
1751 if [ ! -f "$2" ]; then
1752 _ 'Unable to find list "%s"' "$2"
1753 exit 0
1754 fi
1756 LIST=$(cat $2)
1758 # Remember processed list
1759 export INSTALL_LIST="$2"
1761 # Set $COMMAND and install all packages.
1762 COMMAND=${1%-list}
1764 touch $2-processed
1766 # Upgrade tazpkg first. It may handle new features/formats...
1767 # then upgrade essential packages early
1768 for pkg in busybox-pam busybox gcc-lib-base glibc-base \
1769 slitaz-base-files tazpkg ; do
1770 pkg=$(egrep $pkg-[0-9] $INSTALL_LIST)
1771 [ -z "$pkg" ] && continue
1772 _ 'Adding implicit depends "%s"...' $pkg
1773 LIST="$pkg
1774 $LIST"
1775 done
1777 for pkg in $LIST; do
1778 grep -qs ^$pkg$ $2-processed && continue
1779 [ -d "$root/var/lib/tazpkg/installed" ] &&
1780 tazpkg $COMMAND $pkg --list="$2" "$3" "$4" "$5"
1781 done
1782 rm -f $2-processed ;;
1785 add-flavor)
1786 # Install a set of packages from a flavor.
1787 install_flavor $2 ;;
1790 install-flavor)
1791 # Install a set of packages from a flavor and purge other ones.
1792 install_flavor $2 --purge ;;
1795 set-release)
1796 # Change current release and upgrade packages.
1797 RELEASE=$2
1798 if [ -z "$RELEASE" ]; then
1799 newline
1800 _ 'Please specify the release you want on the command line.'
1801 echo "$(_ 'Example:') tazpkg set-release cooking"
1802 newline
1803 exit 0
1804 fi
1805 rm $PKGS_DB/mirror
1806 echo "$RELEASE" > /etc/slitaz-release
1807 tazpkg recharge && tazpkg upgrade
1809 # Install missing depends
1810 cd $INSTALLED
1811 for i in * ; do
1812 DEPENDS=""
1813 . $i/receipt
1814 for j in $DEPENDS ; do
1815 [ -d $j ] || tazpkg get-install $j
1816 done
1817 done ;;
1820 remove|-r)
1821 # Remove packages.
1822 check_root $@
1823 check_for_package_on_cmdline
1824 check_for_installed_info
1826 [ -n "$root" ] && ROOT="$root"
1828 if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then
1829 newline; _ 'Package "%s" is not installed.' $PACKAGE
1830 exit 0
1831 fi
1833 . $ROOT$INSTALLED/$PACKAGE/receipt
1835 # Info #1: dependent packages (to be processed later)
1836 ALTERED="$(awk -F$'\t' -vp=" $PACKAGE " '
1837 index(" " $8 " ", p) { printf " %s\n", $1 }
1838 ' $ROOT/$PKGS_DB/installed.info)"
1840 if [ -n "$ALTERED" ]; then
1841 _ 'The following packages depend on package "%s":' $PACKAGE
1842 echo "$ALTERED"
1843 fi
1845 # Info #2: changed packages (to be processed later)
1846 REFRESH=$(cd $ROOT$INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1848 if [ -n "$REFRESH" ]; then
1849 _ 'The following packages have been modified by package "%s":' $PACKAGE
1850 for i in $REFRESH; do
1851 echo " ${i%/modifiers}"
1852 done
1853 fi
1855 # Confirmation
1856 if im && [ -z "$auto" ]; then
1857 confirm "$(_ 'Remove package "%s" (%s)? (y/N)' $PACKAGE $VERSION$EXTRAVERSION)"
1858 if [ $? != 0 ]; then
1859 newline; _ 'Uninstallation of package "%s" cancelled.' $PACKAGE
1860 exit 0
1861 fi
1862 fi
1863 # We are here: non-interactive mode, or --auto, or answer 'y'
1865 # Removing package
1866 title 'Removing package "%s"' $PACKAGE
1868 # [1/4] Pre-remove commands
1869 if grep -q ^pre_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1870 action "Execution of pre-remove commands..."
1871 pre_remove $ROOT
1872 status
1873 fi
1875 # [2/4] Removing files
1876 action "Removing all files installed..."
1877 if [ -f $ROOT$INSTALLED/$PACKAGE/modifiers ]; then
1878 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1879 for mod in $(cat $ROOT$INSTALLED/$PACKAGE/modifiers); do
1880 [ -f $ROOT$INSTALLED/$mod/files.list ] && \
1881 [ $(grep "^$(echo $file | grepesc)$" $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && \
1882 continue 2
1883 done
1884 remove_with_path $ROOT$file
1885 done
1886 else
1887 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1888 remove_with_path $ROOT$file
1889 done
1890 fi
1891 status
1893 # [3/4] Post-remove commands
1894 if grep -q ^post_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1895 action "Execution of post-remove commands..."
1896 post_remove $ROOT
1897 status
1898 fi
1900 # [4/4] Remove package receipt and remove it from databases
1901 action "Removing package receipt..."
1902 rm -rf $ROOT$INSTALLED/$PACKAGE
1903 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg$/d" $PKGS_DB/installed.$SUM
1904 sed -i "/^$PACKAGE /d" $PKGS_DB/installed.info
1905 status
1907 footer "$(_ 'Package "%s" (%s) removed.' $PACKAGE $VERSION$EXTRAVERSION)"
1909 # Log this activity
1910 log_pkg Removed
1912 # Stop if non-interactive mode and no --auto option
1913 if ! im && [ -z "$auto" ]; then exit 0; fi
1915 # Process dependent packages
1916 if [ -n "$ALTERED" ]; then
1917 if [ "$auto" ]; then
1918 answer=0
1919 else
1920 confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' $PACKAGE)"
1921 answer=$?
1922 fi
1923 if [ $answer = 0 ]; then
1924 for i in $ALTERED; do
1925 if [ -d "$ROOT$INSTALLED/$i" ]; then
1926 echo "tazpkg remove $i $ROOTOPTS"
1927 fi
1928 done
1929 fi
1930 fi
1932 # Process changed packages
1933 if [ -n "$REFRESH" ]; then
1934 if [ "$auto" ]; then
1935 answer=0
1936 else
1937 confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' $PACKAGE)"
1938 answer=$?
1939 fi
1940 if [ $answer = 0 ]; then
1941 for i in $REFRESH; do
1942 if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then
1943 _ 'Check %s for reinstallation' "$INSTALLED/$i"
1944 continue
1945 fi
1946 echo "rm -r $ROOT$INSTALLED/$i"
1947 echo "tazpkg get-install ${i%/modifiers} $ROOTOPTS --forced"
1948 done
1949 fi
1950 fi
1952 ;;
1955 extract|-e)
1956 # Extract .tazpkg cpio archive into a directory.
1957 check_for_package_on_cmdline
1958 check_for_package_file
1959 title 'Extracting package "%s"' $PACKAGE
1961 # If no directory destination is found on the cmdline
1962 # we create one in the current dir using the package name.
1963 if [ -n "$TARGET_DIR" ]; then
1964 DESTDIR=$TARGET_DIR/$PACKAGE
1965 else
1966 DESTDIR=$PACKAGE
1967 fi
1968 mkdir -p $DESTDIR
1970 action "Copying original package..."
1971 cp $PACKAGE_FILE $DESTDIR
1972 status
1974 cd $DESTDIR
1975 extract_package
1976 [ -e "receipt" ] && \
1977 footer "$(_ 'Package "%s" is extracted to "%s"' $PACKAGE $DESTDIR)"
1978 ;;
1981 recompress)
1982 # Recompress .tazpkg cpio archive with lzma.
1983 check_for_package_on_cmdline
1984 check_for_package_file
1985 title 'Recompressing package "%s"' $PACKAGE
1986 mkdir -p $TMP_DIR
1988 action "Copying original package..."
1989 cp $PACKAGE_FILE $TMP_DIR
1990 status
1992 cd $TMP_DIR
1993 extract_package
1995 action "Recompressing the FS..."
1996 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1997 rm -rf fs
1998 status
2000 action "Creating new package..."
2001 find . -print | cpio -o -H newc --quiet > \
2002 $TOP_DIR/$(basename $PACKAGE_FILE).$$ && mv -f \
2003 $TOP_DIR/$(basename $PACKAGE_FILE).$$ \
2004 $TOP_DIR/$(basename $PACKAGE_FILE)
2005 status
2007 cd $TOP_DIR
2008 rm -rf $TMP_DIR
2009 separator; newline ;;
2012 list-config)
2013 # List configuration files installed.
2014 if [ -n "$box" ]; then
2015 mkdir -p $TMP_DIR; cd $TMP_DIR
2016 FILES="$INSTALLED/*/volatile.cpio.gz"
2017 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
2018 for i in $FILES; do
2019 zcat $i | cpio -idm --quiet > /dev/null
2020 find * -type f 2>/dev/null | while read file; do
2021 if [ ! -e /$file ]; then
2022 echo -n "----------|----|----|$(_n 'File lost')"
2023 else
2024 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
2025 cmp $file /$file > /dev/null 2>&1 || \
2026 echo -n "$(stat -c "%.16y" /$file)"
2027 fi
2028 echo "|/$file"
2029 done
2030 rm -rf *
2031 done
2032 cd $TOP_DIR
2033 rm -rf $TMP_DIR
2034 else
2035 im && title 'Configuration files'
2036 for i in $INSTALLED/*/volatile.cpio.gz; do
2037 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
2038 [ -f "$i" ] || continue
2039 zcat $i | cpio -t --quiet
2040 done | sed 's|^|/|' | sort
2041 im && footer
2042 fi ;;
2045 repack-config)
2046 # Create SliTaz package archive from configuration files.
2047 mkdir -p $TMP_DIR; cd $TMP_DIR
2048 CONFIG_VERSION=1.0
2049 mkdir config-$CONFIG_VERSION
2050 cd config-$CONFIG_VERSION
2051 for i in $INSTALLED/*/volatile.cpio.gz; do
2052 zcat $i | cpio -t --quiet
2053 done > files.list
2054 mkdir fs
2055 cd fs
2056 ( cd / ; cpio -o -H newc --quiet ) < ../files.list | cpio -idm --quiet > /dev/null
2057 mkdir -p etc/tazlito
2058 for i in $INSTALLED/*/receipt; do
2059 EXTRAVERSION=""
2060 . $i
2061 echo "$PACKAGE-$VERSION$EXTRAVERSION"
2062 done > etc/tazlito/config-packages.list
2063 cd ..
2064 echo "etc/tazlito/config-packages.list" >> files.list
2065 pkg_date=$(date +"%x %X")
2066 cat > receipt <<EOT
2067 # SliTaz package receipt.
2069 PACKAGE="config"
2070 VERSION="$CONFIG_VERSION"
2071 CATEGORY="base-system"
2072 SHORT_DESC="$(_n 'User configuration backup on date %s' $pkg_date)"
2073 DEPENDS="$(ls $INSTALLED)"
2074 EOT
2075 cd ..
2076 tazpkg pack config-$CONFIG_VERSION
2077 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
2078 cd $TOP_DIR
2079 rm -rf $TMP_DIR
2080 ;;
2083 repack)
2084 # Create SliTaz package archive from an installed package.
2085 check_for_package_on_cmdline
2086 check_for_receipt
2087 EXTRAVERSION=""
2088 . $INSTALLED/$PACKAGE/receipt
2089 title 'Repacking "%s"' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
2091 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
2092 _ "Can't repack package \"%s\"" $PACKAGE
2093 exit 1
2094 fi
2096 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
2097 _ "Can't repack, \"%s\" files have been modified by:" $PACKAGE
2098 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
2099 echo " $i"
2100 done
2101 exit 1
2102 fi
2104 MISSING=""
2105 while read i; do
2106 [ -e "$i" ] && continue
2107 [ -L "$i" ] || MISSING="$MISSING\n $i"
2108 done < $INSTALLED/$PACKAGE/files.list
2109 if [ -n "$MISSING" ]; then
2110 _n "Can't repack, the following files are lost:"
2111 echo -e "$MISSING"
2112 exit 1
2113 fi
2115 mkdir -p $TMP_DIR; cd $TMP_DIR
2116 FILES="fs.cpio.lzma\n"
2117 for i in $(ls $INSTALLED/$PACKAGE); do
2118 case $i in
2119 volatile.cpio.gz|modifiers) ;;
2120 *) cp $INSTALLED/$PACKAGE/$i .; FILES="$FILES$i\n" ;;
2121 esac
2122 done
2124 ln -s / rootfs
2125 mkdir tmp
2126 sed 's/^/rootfs/' < files.list | cpio -o -H newc --quiet | \
2127 { cd tmp ; cpio -idm --quiet >/dev/null; cd ..; }
2128 mv tmp/rootfs fs
2130 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
2131 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
2132 { cd fs; cpio -idm --quiet; cd ..; }
2133 fi
2135 if fgrep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
2136 . $INSTALLED/$PACKAGE/receipt
2137 repack_cleanup fs
2138 fi
2140 if [ -f $INSTALLED/$PACKAGE/$CHECKSUM ]; then
2141 sed 's, , fs,' < $INSTALLED/$PACKAGE/$CHECKSUM | \
2142 $CHECKSUM -s -c || {
2143 _ "Can't repack, %s error." $CHECKSUM
2144 cd $TOP_DIR
2145 rm -rf $TMP_DIR
2146 exit 1
2148 fi
2150 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2151 echo -e "$FILES" | cpio -o -H newc --quiet > \
2152 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
2153 cd $TOP_DIR
2154 \rm -R $TMP_DIR
2155 _ 'Package "%s" repacked successfully.' $PACKAGE
2156 _ 'Size: %s' "$(du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg)"
2157 newline ;;
2160 pack)
2161 # Create SliTaz package archive using cpio and lzma.
2162 # TODO: Cook also pack packages, we should share code in libpkg.sh
2163 check_for_package_on_cmdline
2164 cd $PACKAGE
2165 if [ ! -f "receipt" ]; then
2166 _ 'Receipt is missing. Please read the documentation.'
2167 exit 0
2168 fi
2170 title 'Packing package "%s"' $PACKAGE
2171 # Create files.list with redirecting find outpout.
2173 action "Creating the list of files..."
2174 cd fs
2175 find . -type f -print > ../files.list
2176 find . -type l -print >> ../files.list
2177 cd .. && sed -i s/'^.'/''/ files.list
2178 status
2180 action 'Creating %s of files...' $CHECKSUM
2181 while read file; do
2182 [ -L "fs$file" ] && continue
2183 [ -f "fs$file" ] || continue
2184 case "$file" in
2185 /lib/modules/*/modules.*|*.pyc) continue;;
2186 esac
2187 $CHECKSUM "fs$file" | sed 's/ fs/ /'
2188 done < files.list > $CHECKSUM
2189 status
2191 UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
2192 description.txt 2> /dev/null | awk \
2193 '{ sz=$1 } END { print sz }')
2194 # Build cpio archives.
2196 action "Compressing the FS..."
2197 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2198 rm -rf fs
2199 status
2201 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
2202 $CHECKSUM description.txt 2> /dev/null | awk \
2203 '{ sz=$1 } END { print sz }')
2205 action "Updating receipt sizes..."
2206 sed -i s/^PACKED_SIZE.*$// receipt
2207 sed -i s/^UNPACKED_SIZE.*$// receipt
2208 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
2209 status
2211 action "Creating full cpio archive..."
2212 find . -print | cpio -o -H newc --quiet > ../$PACKAGE.tazpkg
2213 status
2215 action "Restoring original package tree..."
2216 unlzma -c fs.cpio.lzma | cpio -idm --quiet
2217 status
2219 rm fs.cpio.lzma && cd ..
2220 footer "$(_ 'Package "%s" compressed successfully.' $PACKAGE)"
2221 _ 'Size: %s' "$(ls -lh $PACKAGE.tazpkg | awk '{print $5}')"
2222 ;;
2225 recharge)
2226 # Recharge packages.list from a mirror.
2228 # WARNING: The 'mirrors' file has all SliTaz mirrors but 'mirror'
2229 # must have only the chosen main mirror.
2231 check_root $@
2233 ARG=$2
2234 if [ "$root" ]; then
2235 PKGS_DB=$root$PKGS_DB
2236 [ "${2#--}" != "$2" ] && ARG=$3
2237 fi
2238 if [ "$ARG" = main ]; then
2239 repository_to_recharge=$PKGS_DB
2240 elif [ "$ARG" ]; then
2241 if [ -d "$PKGS_DB/undigest/$ARG" ]; then
2242 repository_to_recharge=$PKGS_DB/undigest/$ARG
2243 else
2244 repo="$PKGS_DB/undigest/$ARG"
2245 _ "Repository \"%s\" doesn't exist." $repo >&2
2246 exit 1
2247 fi
2248 else
2249 repository_to_recharge="$PKGS_DB $PKGS_DB/undigest/*"
2250 fi
2251 for path in $repository_to_recharge; do
2252 [ -f $path/mirror ] || continue
2253 cd $path
2255 # Quietly check if recharging is needed.
2256 [ -f ID ] && mv ID ID.bak
2257 download_from "$(cat mirror)" ID >/dev/null 2>/dev/null
2258 if [ -f ID ] && fgrep -q $(cat ID.bak 2>/dev/null || echo "null") ID; then
2259 if [ "$path" = "$PKGS_DB" ]; then
2260 repository_name=Main
2261 else
2262 base_path="$(basename $path)"
2263 repository_name="$(_n 'Undigest %s' $base_path)"
2264 fi
2265 _ 'Repository "%s" is up to date.' "$repository_name"
2266 rm ID.bak
2267 continue
2268 fi
2270 # Don't let ID be a symlink when using local repository.
2271 if [ -f ID ]; then
2272 mv -f ID ID.bak
2273 cat ID.bak > ID
2274 rm ID.bak
2275 fi
2277 newline
2278 if [ "$path" != "$PKGS_DB" ]; then
2279 base_path="$(basename $path)"
2280 _ 'Recharging undigest %s:' $base_path
2281 fi
2283 if [ -f "packages.list" ]; then
2284 action "Creating backup of the last packages list..."
2285 for i in packages.desc packages.$SUM packages.txt \
2286 packages.list packages.equiv files.list.lzma \
2287 extra.list mirrors packages.info
2288 do
2289 mv -f $i $i.bak 2>/dev/null
2290 done
2291 status
2292 fi
2294 for i in desc $SUM txt list equiv; do
2295 download_from "$(cat mirror)" packages.$i
2296 done
2297 download_from "$(cat mirror)" files.list.lzma
2298 download_from "$(cat mirror)" extra.list
2299 download_from "$(sed 's|packages/.*||' mirror)" mirrors
2301 # packages.info
2302 download_from "$(cat mirror)" packages.info.lzma
2303 lzma d packages.info.lzma packages.info
2304 rm packages.info.lzma
2306 if [ -f "packages.list.bak" ]; then
2307 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
2308 [ -f "extra.list.bak" ] &&
2309 diff -u extra.list.bak extra.list | grep ^+[a-z] >> packages.diff
2310 sed -i s/+// packages.diff
2311 title 'Mirrored packages diff'
2312 cat packages.diff
2313 new_pkgs=$(wc -l < packages.diff)
2314 footer "$(emsg "$(_p \
2315 '%s new package on the mirror.' \
2316 '%s new packages on the mirror.' $new_pkgs \
2317 "<c 32>$new_pkgs</c>")")"
2318 else
2319 footer "$(longline "$(_ "Last %s is ready to use. Note that \
2320 next time you recharge the list, a list of differences will be displayed to \
2321 show new and upgradeable packages." packages.list)")"
2322 fi
2323 done ;;
2326 help-up)
2327 # Options available for the command: up
2328 newline; usage_up; newline
2329 exit 1 ;;
2332 up|upgrade)
2333 check_root
2335 # This is the new way to upgrade packages making 'upgrade' and
2336 # upgradeable out-of-date. This new way is much, much more faster!
2337 # Look into installed packages and get data from receipt, it is fast
2338 # and easy to handle vars after using only md5sum to compare packages
2340 for opt in $@; do
2341 case "$opt" in
2342 --recharge|-r) tazpkg recharge ;;
2343 --install|-i) install="y" ;;
2344 --check|-c) install="n" ;;
2345 esac
2346 done
2347 time=$(date +%s)
2349 look_for_priority
2350 for repo in $priority; do
2351 pkg_list=$repo/packages.list
2352 mtime=$(find $pkg_list -mtime +7)
2353 if [ "$mtime" ]; then
2354 if [ "$repo" == "$PKGS_DB" ]; then
2355 repo_name=main
2356 else
2357 repo_name="${repo##*/}"
2358 fi
2359 _ 'List "%s" is older than one week... Recharging.' $pkg_list
2360 tazpkg recharge $repo_name
2361 fi
2362 done
2364 emsg "<n>$(_ 'Package')<i 28> $(_ 'Version')<i 48> $(_ 'Status')<->"
2366 cd $INSTALLED
2367 echo -n > $UP_LIST
2368 blocked_count=0
2369 installed_sum=$PKGS_DB/installed.$SUM
2371 for pkg in *; do
2372 [ ! -d $pkg ] && continue
2373 unset VERSION EXTRAVERSION
2374 . $pkg/receipt
2375 md5=$(fgrep " $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" \
2376 $installed_sum | awk '{print $1}')
2377 for repo in $priority; do
2378 pkg_desc=$repo/packages.desc
2379 pkg_list=$repo/packages.list
2380 pkg_sum=$repo/packages.$SUM
2382 if ! fgrep -q "$md5 $PACKAGE-" $pkg_sum; then
2383 # Jump to next repository in priority if pkg doesn't exist
2384 # in this one.
2385 grep -q ^$PACKAGE- $pkg_list || continue
2387 emsg -n "$PACKAGE<i 28> $VERSION"
2389 # Skip pkgs listed in $PKGS_DB/blocked-packages.list
2390 if $(grep -qs "^$PACKAGE" $BLOCKED); then
2391 blocked_count=$(($blocked_count + 1))
2392 emsg "<i 48><c 31> $(_ 'Blocked')</c>"
2393 break
2394 fi
2396 new=$(grep "^$PACKAGE |" $pkg_desc | awk '{print $3}')
2398 if [ "$VERSION" == "$new" ]; then
2399 emsg "<i 48><c 34> $(_ 'New build')</c>"
2400 else
2401 emsg "<i 48><c 32> $(_ 'New version %s' $new)</c>"
2402 fi
2403 echo "$PACKAGE" >> $UP_LIST
2404 break
2405 fi
2406 done
2407 done
2408 sed -i /^$/d $UP_LIST
2409 upnb=$(wc -l < $UP_LIST)
2410 pkgs=$(ls | wc -l)
2411 time=$(($(date +%s) - $time))
2412 if [ "$upnb" == 0 ]; then
2413 install="n"
2414 _ 'System is up-to-date...'
2415 fi
2417 footer "$(emsg "$(_p \
2418 '%s installed package scanned in %ds' \
2419 '%s installed packages scanned in %ds' $pkgs \
2420 "<c 32>$pkgs</c>" $time)")"
2422 if [ "$upnb" != 0 ]; then
2423 blocked="$(_p \
2424 '%s blocked' \
2425 '%s blocked' $blocked_count \
2426 $blocked_count)"
2428 boldify "$(_p \
2429 'You have %s available upgrade (%s)' \
2430 'You have %s available upgrades (%s)' $upnb \
2431 $upnb "$blocked")"
2432 newline
2433 fi
2434 # Pkgs to upgrade ? Skip, let install them all or ask user
2435 [ "$install" == "n" ] && exit 0
2436 if [ "$upnb" -gt 0 ]; then
2437 if [ "$install" == "y" ]; then
2438 continue
2439 else
2440 confirm "$(_ 'Do you wish to install them now? (y/N)')"
2441 answer=$?
2442 fi
2443 case "$answer" in
2444 0)
2445 for pkg in $(cat $UP_LIST); do
2446 echo 'y' | tazpkg get-install $pkg --forced
2447 done
2448 # List is generated each time and must be cleaned so
2449 # tazpkg-notify doesn't find upgrades anymore.
2450 rm $UP_LIST; touch $UP_LIST ;;
2451 *)
2452 _ 'Leaving without any upgrades installed.'
2453 newline
2454 exit 0 ;;
2455 esac
2456 fi
2457 newline ;;
2460 bugs)
2461 # Show known bugs in package(s)
2462 cd $INSTALLED
2463 shift
2464 LIST=$@
2465 [ -n "$LIST" ] || LIST=$(ls)
2466 MSG=$(_n 'No known bugs.')
2467 for PACKAGE in $LIST; do
2468 BUGS=""
2469 EXTRAVERSION=""
2470 . $PACKAGE/receipt
2471 if [ -n "$BUGS" ]; then
2472 MSG=$(_n 'Bug list completed')
2473 newline
2474 _ 'Bugs in package "%s" version %s:' $PACKAGE $VERSION$EXTRAVERSION
2475 cat <<EOT
2476 $BUGS
2477 EOT
2478 fi
2479 done
2480 echo "$MSG" ;;
2483 check)
2484 # Check installed packages set.
2485 check_root $@
2487 # Get repositories priority list.
2488 look_for_priority
2490 cd $INSTALLED
2491 for PACKAGE in $(ls); do
2493 if [ ! -f $PACKAGE/receipt ]; then
2494 _ 'The package "%s" installation has not completed' $PACKAGE
2495 continue
2496 fi
2498 DEPENDS=""
2499 EXTRAVERSION=""
2500 . $PACKAGE/receipt
2501 if [ -s $PACKAGE/modifiers ]; then
2502 _ 'The package "%s" has been modified by:' $PACKAGE-$VERSION$EXTRAVERSION
2503 for i in $(cat $PACKAGE/modifiers); do
2504 echo " $i"
2505 done
2506 fi
2508 MSG="$(_n 'Files lost from package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2509 while read file; do
2510 [ -e "$file" ] && continue
2511 if [ -L "$file" ]; then
2512 MSG="$MSG $(_n 'target of symlink')"
2513 fi
2514 echo -e "$MSG $file"
2515 MSG=""
2516 done < $PACKAGE/files.list
2518 MSG="$(_n 'Missing dependencies for package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2519 for i in $DEPENDS; do
2520 [ -d $i ] && continue
2521 [ -d $(equivalent_pkg $i) ] && continue
2522 echo -e "$MSG $i"
2523 MSG=""
2524 done
2526 MSG="$(_n 'Dependencies loop between "%s" and:' $PACKAGE)\n"
2527 ALL_DEPS=""
2528 check_for_deps_loop $PACKAGE $DEPENDS
2529 done
2531 _ 'Looking for known bugs...'
2532 tazpkg bugs
2534 if [ "$2" == "--full" ]; then
2535 separator
2537 for file in */$CHECKSUM; do
2538 CONFIG_FILES=""
2539 . $(dirname "$file")/receipt
2540 [ -s "$file" ] || continue
2541 while read md5 f; do
2542 [ -f $f ] || continue
2543 for i in $CONFIG_FILES; do
2544 case "$f" in
2545 $i|$i/*) continue 2;;
2546 esac
2547 done
2548 echo "$md5 $f"
2549 done < "$file" | busybox $CHECKSUM -c - 2> /dev/null | \
2550 grep -v OK$ | sed "s/FAILED$/$CHECKSUM MISMATCH/"
2551 done
2553 FILES=" "
2554 for file in $(cat */files.list); do
2555 [ -d "$file" ] && continue
2556 case "$FILES" in *\ $file\ *) continue;; esac
2557 [ $(grep "^$(echo $file | grepesc)$" */files.list 2> /dev/null | \
2558 wc -l) -gt 1 ] || continue
2559 FILES="$FILES$file "
2560 _ 'The following packages provide file "%s":' $file
2561 grep -l "^$(echo $file | grepesc)$" */files.list | \
2562 while read f; do
2563 pkg=${f%/files.list}
2564 if [ -f $pkg/modifiers ]; then
2565 overriders=$(_n '(overridden by %s)' "$(tr '\n' ' ' | sed 's| $||' < $pkg/modifiers)")
2566 else
2567 overriders=''
2568 fi
2569 echo -n " $pkg $overriders"
2570 newline
2571 done
2572 done
2574 MSG="$(_n 'No package has installed the following files:')\n"
2575 find /etc /bin /sbin /lib /usr /var/www -not -type d 2>/dev/null | \
2576 while read file; do
2577 case "$file" in *\[*) continue;; esac
2578 grep -q "^$(echo $file | grepesc)$" */files.list && continue
2579 echo -e "$MSG $file"
2580 MSG=""
2581 done
2582 fi
2583 _ 'Check completed.'; echo ;;
2586 block|-b)
2587 # Add a pkg name to the list of blocked packages.
2588 check_root $@
2589 check_for_package_on_cmdline
2590 newline
2591 if [ ! -d $INSTALLED/$PACKAGE ]; then
2592 _ 'Package "%s" is not installed.' $PACKAGE; exit
2593 fi
2594 if grep -qs "^$PACKAGE" $BLOCKED; then
2595 _ 'Package "%s" is already blocked.' $PACKAGE
2596 else
2597 echo $PACKAGE >> $BLOCKED
2598 # Log this activity
2599 . $INSTALLED/$PACKAGE/receipt; log_pkg Blocked
2600 _ 'Package "%s" blocked.' $PACKAGE
2601 fi
2602 newline ;;
2605 unblock|-u)
2606 # Remove a pkg name from the list of blocked packages.
2607 check_root $@
2608 check_for_package_on_cmdline
2609 newline
2610 if [ ! -d $INSTALLED/$PACKAGE ]; then
2611 _ 'Package "%s" is not installed.' $PACKAGE; exit
2612 fi
2613 if grep -qs "^$PACKAGE" $BLOCKED; then
2614 sed -i "/^$PACKAGE\$/d" $BLOCKED
2615 # Log this activity
2616 . $INSTALLED/$PACKAGE/receipt; log_pkg Unblocked
2617 _ 'Package "%s" unblocked.' $PACKAGE
2618 else
2619 _ 'Package "%s" is not blocked.' $PACKAGE
2620 fi
2621 newline ;;
2624 chblock)
2625 # Change package's blocked status.
2626 check_root $@
2627 check_for_package_on_cmdline
2628 newline
2629 if [ ! -d $INSTALLED/$PACKAGE ]; then
2630 _ 'Package "%s" is not installed.' $PACKAGE; exit
2631 fi
2632 if grep -qs "^$PACKAGE" $BLOCKED; then
2633 sed -i "/^$PACKAGE\$/d" $BLOCKED
2634 # Log this activity
2635 . $INSTALLED/$PACKAGE/receipt; log_pkg Unblocked
2636 _ 'Package "%s" unblocked.' $PACKAGE
2637 else
2638 echo $PACKAGE >> $BLOCKED
2639 # Log this activity
2640 . $INSTALLED/$PACKAGE/receipt; log_pkg Blocked
2641 _ 'Package "%s" blocked.' $PACKAGE
2642 fi
2643 newline ;;
2646 get|-g)
2647 # Download a package with wget.
2648 check_root $@
2649 check_for_package_on_cmdline
2650 check_for_packages_list
2652 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2653 if [ "$rootconfig" ]; then
2654 if [ "$root" ]; then
2655 CACHE_DIR=$root/$CACHE_DIR
2656 SAVE_CACHE_DIR=$CACHE_DIR
2657 PKGS_DB=$root/$PKGS_DB
2658 else
2659 _ 'rootconfig needs --root= option used.' >&2
2660 exit 1
2661 fi
2662 fi
2664 # Get repositories priority list.
2665 look_for_priority
2667 CURRENT_DIR=$PWD
2668 cd $CACHE_DIR
2669 if check_for_package_in_list check ; then
2670 if [ -f "$PACKAGE.tazpkg" ]; then
2671 _ 'Package "%s" already in the cache' $PACKAGE
2672 # Check package download was finished
2673 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2674 _ 'Continuing package "%s" download' $PACKAGE
2675 download $PACKAGE.tazpkg
2677 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2678 rm -f $PACKAGE.tazpkg
2679 download $PACKAGE.tazpkg
2680 fi
2681 else
2682 download $PACKAGE.tazpkg
2683 fi
2684 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2685 elif download_get_script $PACKAGE /tmp/$PACKAGE.$$ ; then
2686 install_package_from_get_script /tmp/$PACKAGE.$$ "$ROOT" --get
2687 PACKAGE_FILE=$(ls $PWD/$PACKAGE-*.tazpkg)
2688 fi
2689 [ "$PWD" != "$CURRENT_DIR" ] &&
2690 cp -a $PACKAGE_FILE $CURRENT_DIR ;;
2693 get-install|-gi)
2694 # Download and install a package.
2695 check_root $@
2696 check_for_package_on_cmdline
2697 check_for_packages_list
2699 DO_CHECK=""
2700 [ "$forced" ] && DO_CHECK=no
2701 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2702 [ "$list" ] && INSTALL_LIST="$list"
2703 if [ "$rootconfig" ]; then
2704 if [ "$root" ]; then
2705 CACHE_DIR=$root/$CACHE_DIR
2706 SAVE_CACHE_DIR=$CACHE_DIR
2707 PKGS_DB=$root/$PKGS_DB
2708 else
2709 _ 'rootconfig needs --root= option used.' >&2
2710 exit 1
2711 fi
2712 fi
2714 # Get repositories priority list.
2715 look_for_priority
2717 AUTOEXEC="no"
2718 if ! check_for_package_in_list check; then
2719 CACHE_DIR="${CACHE_DIR%/*}/get"
2720 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
2721 if download_get_script $PACKAGE /tmp/$PACKAGE.$$ ; then
2722 install_package_from_get_script /tmp/$PACKAGE.$$ $ROOT
2723 exit 0
2724 else
2725 PACKAGE=get-$PACKAGE
2726 AUTOEXEC=$PACKAGE
2727 check_for_package_in_list
2728 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
2729 $AUTOEXEC $ROOT
2730 exit 0
2731 fi
2732 fi
2733 fi
2734 # Check if forced install.
2735 if ! [ "$forced" ]; then
2736 check_for_installed_package $ROOT
2737 fi
2738 cd $CACHE_DIR
2739 if [ -f "$PACKAGE.tazpkg" ]; then
2740 _ 'Package "%s" already in the cache' $PACKAGE
2741 # Check package download was finished
2742 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2743 _ 'Continuing package "%s" download' $PACKAGE
2744 download $PACKAGE.tazpkg
2746 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2747 rm -f $PACKAGE.tazpkg
2748 download $PACKAGE.tazpkg
2749 fi
2750 else
2751 newline
2752 download $PACKAGE.tazpkg
2753 fi
2754 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2755 [ "$rootconfig" ] && PKGS_DB=${PKGS_DB#$root}
2756 install_package $ROOT
2757 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
2758 update_desktop_database $ROOT
2759 update_mime_database $ROOT ;;
2762 clean-cache|-cc)
2763 # Remove all downloaded packages.
2764 check_root $@
2765 files=$(find $CACHE_DIR -name *.tazpkg | wc -l)
2766 size=$(du -hs $CACHE_DIR | cut -f1 | sed 's|\.0||'); [ $files == "0" ] && size="0K"
2767 title 'Path: %s' $CACHE_DIR
2768 action "Cleaning cache directory..."
2769 rm -rf $CACHE_DIR/*
2770 status
2772 footer "$(_p \
2773 '%s file removed from cache (%s).' \
2774 '%s files removed from cache (%s).' $files \
2775 "$(colorize 32 "$files")" $size)"
2776 ;;
2779 list-undigest)
2780 # list undigest URLs.
2781 if [ "$2" = "--box" ]; then
2782 for i in $PKGS_DB/undigest/*/mirror; do
2783 [ -f $i ] || continue
2784 echo "$(basename $(dirname $i))|$(cat $i)"
2785 done
2786 else
2787 title 'Current undigest(s)'
2788 for i in $PKGS_DB/undigest/*/mirror; do
2789 if [ ! -f $i ]; then
2790 _ 'No undigest mirror found.'
2791 exit 1
2792 fi
2793 echo "$(basename $(dirname $i)) $(cat $i)"
2794 done
2795 newline
2796 fi ;;
2799 remove-undigest)
2800 # remove undigest URL.
2801 check_root $@
2802 undigest="$2"
2803 if [ -d $PKGS_DB/undigest/$2 ]; then
2804 confirm "$(_ 'Remove "%s" undigest? (y/N)' $undigest)"
2805 if [ $? = 0 ]; then
2806 action 'Removing "%s" undigest...' $undigest
2807 rm -rf $PKGS_DB/undigest/$2
2808 status
2809 rmdir $PKGS_DB/undigest 2> /dev/null
2810 fi
2811 else
2812 _ 'Undigest "%s" not found' $undigest
2813 fi ;;
2816 add-undigest|setup-undigest)
2817 # Add undigest URL.
2818 check_root $@
2819 undigest=$2
2820 [ -d $PKGS_DB/undigest ] || mkdir $PKGS_DB/undigest
2821 if [ -z "$undigest" ]; then
2822 i=1
2823 while [ -d $PKGS_DB/undigest/$i ]; do
2824 i=$(($i+1))
2825 done
2826 undigest=$i
2827 fi
2828 if [ ! -d $PKGS_DB/undigest/$undigest ]; then
2829 _ 'Creating new undigest "%s".' $undigest
2830 mkdir $PKGS_DB/undigest/$undigest
2831 fi
2832 setup_mirror $PKGS_DB/undigest/$undigest $3 ;;
2835 setup-mirror|-sm)
2836 # Change mirror URL.
2837 check_root $@
2838 setup_mirror $PKGS_DB $2 ;;
2841 reconfigure)
2842 # Replay post_install from receipt
2843 check_for_package_on_cmdline
2844 check_root $@
2845 ROOT=""
2846 while [ -n "$3" ]; do
2847 case "$3" in
2848 --root=*)
2849 ROOT="${3#--root=}/" ;;
2850 *)
2851 shift 2
2852 u_opt="$*"
2853 newline >&2
2854 _ 'Unknown option "%s".' $u_opt >&2
2855 exit 1 ;;
2856 esac
2857 shift
2858 done
2859 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2860 check_for_receipt $ROOT
2861 # Check for post_install
2862 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2863 . $ROOT$INSTALLED/$PACKAGE/receipt
2864 post_install $ROOT
2865 # Log this activity
2866 [ -n "$ROOT" ] || log_pkg Reconfigured
2867 else
2868 newline
2869 _ 'Nothing to do for package "%s".' $PACKAGE
2870 fi
2871 else
2872 newline
2873 _ 'Package "%s" is not installed.' $PACKAGE
2874 _ 'Install package with "%s" or "%s"' 'tazpkg install' 'tazpkg get-install'
2875 newline
2876 fi ;;
2879 shell)
2880 # TazPKG SHell
2881 if test $(id -u) = 0 ; then
2882 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2883 else
2884 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2885 fi
2886 if [ ! "$2" = "--noheader" ]; then
2887 clear
2888 title 'TazPKG SHell.'
2889 _ "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
2890 newline
2891 fi
2892 while true; do
2893 echo -en "$PROMPT"; read cmd
2894 case $cmd in
2895 q|quit)
2896 break ;;
2897 shell)
2898 _ 'You are already running a TazPKG SHell.' ;;
2899 su)
2900 su -c 'exec tazpkg shell --noheader' && break ;;
2901 "")
2902 continue ;;
2903 *)
2904 tazpkg $cmd ;;
2905 esac
2906 done ;;
2909 depends)
2910 # Display dependencies tree
2911 cd $INSTALLED
2912 ALL_DEPS=""
2913 if [ -f $2/receipt ]; then
2914 dep_scan $2 ""
2915 fi ;;
2918 rdepends)
2919 # Display reverse dependencies tree
2920 cd $INSTALLED
2921 ALL_DEPS=""
2922 if [ -f $2/receipt ]; then
2923 rdep_scan $2
2924 fi ;;
2927 list-suggested)
2928 for i in $(ls -d $INSTALLED/*); do
2929 . $i/receipt
2930 if [ "$SUGGESTED" ]; then
2931 if [ -z "$all" ]; then
2932 for s in $SUGGESTED; do
2933 [ -d $INSTALLED/$s ] && \
2934 SUGGESTED=$(echo -n $SUGGESTED | sed "s/$s//")
2935 done
2936 fi
2937 cat <<EOT
2938 $(boldify $(echo $PACKAGE):) $SUGGESTED
2939 EOT
2940 fi
2941 SUGGESTED=""
2942 done ;;
2945 convert|-c)
2946 # convert misc package format to .tazpkg
2947 check_for_package_file
2948 tazpkg-convert $@
2949 ;;
2952 link)
2953 # link a package from another slitaz installation
2954 PACKAGE=$2
2955 if [ ! -d "$TARGET_DIR" -o \
2956 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
2957 _ 'Usage: tazpkg link package_name slitaz_root'
2958 longline "$(
2959 _n 'Example:'
2960 echo -n ' '
2961 _ '"%s" will use less than 100k in your running system RAM.' \
2962 'tazpkg link openoffice /mnt')"
2963 exit 1
2964 fi
2965 if [ -e "$INSTALLED/$PACKAGE" ]; then
2966 _ 'Package "%s" is already installed.' $PACKAGE
2967 exit 1
2968 fi
2969 ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
2970 DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
2971 MISSING=""
2972 for i in $DEPENDS; do
2973 [ -e $INSTALLED/$i ] && continue
2974 MISSING="$MISSING$i "
2975 _ 'Missing: %s' $i
2976 done
2977 if [ -n "$MISSING" ]; then
2978 newline
2979 confirm "$(_ 'Link all missing dependencies? (y/N)')"
2980 answer=$?
2981 newline
2982 if [ $answer = 0 ]; then
2983 for i in $MISSING; do
2984 tazpkg link $i $TARGET_DIR
2985 done
2986 else
2987 newline
2988 _ 'Leaving dependencies unresolved for package "%s"' $PACKAGE
2989 _ 'The package is installed but probably will not work.'
2990 newline
2991 fi
2992 fi
2993 . $INSTALLED/$PACKAGE/receipt
2994 if grep -q ^pre_install $INSTALLED/$PACKAGE/receipt; then
2995 pre_install
2996 fi
2997 while read path; do
2998 [ -e $path ] && continue
2999 while true; do
3000 dir=$(dirname $path)
3001 [ -e $dir ] && break
3002 path=$dir
3003 done
3004 ln -s $TARGET_DIR$path $dir
3005 done < $INSTALLED/$PACKAGE/files.list
3006 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
3007 post_install
3008 fi ;;
3011 usage|*)
3012 # Print a short help or give usage for an unknown or empty command.
3013 usage ;;
3014 esac
3016 exit 0