tazpkg view tazpkg @ rev 762

tazpkg: re-make block and unblock, add chblock to change blocking of package; pkgs.cgi: remove website link from packages list, show selected packages count, add '(Un)block' button for bulk operation; pkgs.css: clean old code.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Wed Apr 01 04:29:22 2015 +0300 (2015-04-01)
parents 37df6365cf41
children 5a6155d9197a
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 #
16 ####################
17 # Script variables #
18 ####################
20 # TazPKG version
21 VERSION=5.3.4
23 . /etc/slitaz/slitaz.conf
24 . /etc/slitaz/tazpkg.conf
26 . /lib/libtaz.sh
27 . /usr/lib/slitaz/libpkg.sh
28 . /usr/lib/tazpkg/tazpkg-find-depends
30 # Internationalization.
31 export TEXTDOMAIN='tazpkg'
32 _() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; echo; }
33 _n() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; }
34 _p() {
35 local S="$1" P="$2" N="$3"; shift; shift; shift;
36 printf "$(ngettext "$S" "$P" "$N")" "$@"; }
39 #
40 # Functions set for translate categories
41 #
44 # Make array of pre-translated categories
46 cat_i18n=""
47 for c in "base-system" "x-window" "utilities" "network" "graphics" \
48 "multimedia" "office" "development" "system-tools" "security" "games" \
49 "misc" "meta" "non-free"; do
50 cat_i18n="$cat_i18n
51 $(gettext "$c") $c"
52 done
55 # Translate category names (must be last in line)
57 translate_category()
58 {
59 sed "s|base-system$|$(_ base-system)|g; s|x-window$|$(_ x-window)|g;
60 s|utilities$|$(_ utilities)|g; s|network$|$(_ network)|g;
61 s|graphics$|$(_ graphics)|g; s|multimedia$|$(_ multimedia)|g;
62 s|office$|$(_ office)|g; s|development$|$(_ development)|g;
63 s|system-tools$|$(_ system-tools)|g; s|security$|$(_ security)|g;
64 s|games$|$(_ games)|g; s|misc$|$(_ misc)|g; s|meta$|$(_ meta)|g;
65 s|non-free$|$(_ non-free)|g"
66 }
69 # If category is not one of those translated in native language, keep it
70 # untranslated. This allows both native and english language support.
71 # This also supports custom categories.
72 # And now we support spaces in translated categories
74 reverse_translate_category()
75 {
76 echo "$cat_i18n" | awk "BEGIN{FS=\" \"}{if (/^$@ /) a=\$2}END{if (a==\"\") a=\"$@\"; print a}"
77 }
81 #
82 # TazPKG output functions
83 #
86 # Print localized title
88 title() { newline; boldify "$(_ "$@")"; separator; }
91 # Print footer
93 footer() { separator; echo "$1"; [ -n "$1" ] && newline; }
96 # Print current action in brown color (separate from any other msgs)
98 action() {
99 case $output in
100 raw|gtk|html) _n "$@" ;;
101 *) echo -ne "\033[0;33m"$(_ "$@")"\033[0m" ;;
102 esac
103 }
106 # Initialize some variables to use words rather than numbers for functions
107 # and actions.
108 COMMAND=$1
109 PACKAGE=${2%/}
110 PACKAGE_DIR="$(cd $(dirname $PACKAGE 2>/dev/null) 2>/dev/null; pwd)"
111 [ -n "$PACKAGE" ] && PACKAGE_FILE="$PACKAGE_DIR/${PACKAGE##*/}"
112 if [ -f "$PACKAGE" ]; then
113 # Set pkg basename for install, extract
114 PACKAGE=$(basename $PACKAGE .tazpkg 2>/dev/null)
115 else
116 # Pkg name for remove, search and all other cmds
117 PACKAGE=${PACKAGE%.tazpkg}
118 fi
119 TARGET_DIR=$3
120 TOP_DIR=$(pwd)
121 TMP_DIR=/tmp/$RANDOM
122 INSTALL_LIST=""
123 SAVE_CACHE_DIR="$CACHE_DIR"
125 # Path to tazpkg used dir and configuration files
126 MIRROR=$PKGS_DB/mirror
127 BLOCKED=$PKGS_DB/blocked-packages.list
128 UP_LIST=$PKGS_DB/packages.up
129 DEFAULT_MIRROR="$ONLINE_PKGS"
134 ####################
135 # Script functions #
136 ####################
139 # Interactive mode
141 im() { tty -s; }
144 # Print the usage.
146 usage () {
147 cat << EOT
149 $(_ 'SliTaz package manager - Version: %s' $(colorize 34 $VERSION))
151 $(boldify "$(_ 'Usage:')")
152 $(_ 'tazpkg [command] [package|dir|pattern|list|cat|--opt] [dir|--opt]')
154 $(boldify "$(_ 'SHell:')") tazpkg shell
156 $(boldify "$(_ 'Commands:')")
157 $(optlist "\
158 usage $(_ 'Print this short usage')
159 bugs $(_ 'Show known bugs in packages')
160 -a activity $(_ 'Show TazPkg activity log')
161 -l list $(_ 'List installed packages on the system')
162 -lm list-mirror $(_ 'List all available packages on the mirror')
163 info $(_ 'Print information about a package')
164 desc $(_ 'Print description of a package')
165 -lf list-files $(_ 'List the files installed with a package')
166 list-config $(_ 'List the configuration files')
168 -s search $(_ 'Search for a package by pattern or name')
169 search-pkgname $(_ 'Search on mirror for package having a particular file')
170 -sf search-file $(_ 'Search for file in all installed packages files')
172 get $(_ 'Download a package into the current directory')
173 -gi get-install $(_ 'Download and install a package from the mirror')
174 get-install-list $(_ 'Download and install a list of packages from the mirror')
175 -i install $(_ 'Install a local package')
176 install-list $(_ 'Install all packages from a list of packages')
177 -r remove $(_ 'Remove the specified package and all installed files')
178 -e extract $(_ 'Extract a (*.tazpkg) package into a directory')
179 pack $(_ 'Pack an unpacked or prepared package tree')
181 recharge $(_ 'Recharge your packages.list from the mirror')
182 up|help-up $(_ 'Check packages %s to list and install latest upgrades' $CHECKSUM)
184 repack $(_ 'Create a package archive from an installed package')
185 repack-config $(_ 'Create a package archive with configuration files')
186 recompress $(_ 'Rebuild a package with a better compression ratio')
187 block|unblock $(_ 'Block an installed package version or unblock it for upgrade')
188 check $(_ 'Verify consistency of installed packages')
190 add-flavor $(_ 'Install the flavor list of packages')
191 install-flavor $(_ 'Install the flavor list of packages and remove other ones')
193 set-release $(_ 'Change release and update packages')
194 -cc clean-cache $(_ 'Clean all packages downloaded in cache directory')
196 depends $(_ 'Display dependencies tree')
197 rdepends $(_ 'Display reverse dependencies tree')
199 convert $(_ 'Convert alien package to tazpkg')
200 link $(_ 'Link a package from another slitaz installation')
202 -sm setup-mirror $(_ 'Change the mirror url configuration')
203 list-undigest $(_ 'List undigest mirrors')
204 remove-undigest $(_ 'Remove an undigest mirror')
205 add-undigest $(_ 'Add an undigest mirror')
206 setup-undigest $(_ 'Update an undigest mirror')
208 reconfigure $(_ 'Replay post install script from package')
209 ")
210 EOT
211 }
214 usage_up() {
215 cat << EOT
216 $(emsg "<b>$(_ 'Usage for command up:')</b>") tazpkg up [$(_ 'option')]
218 * $(longline "$(_ 'Without options run in interactive mode and ask before install')")
220 $(boldify "$(_ 'Where options are:')")
221 $(optlist "\
222 -c --check $(_ 'Check only for available upgrades')
223 -r --recharge $(_ 'Force recharge of packages list and check')
224 -i --install $(_ 'Check for upgrades and install them all')
225 ")
227 $(boldify "$(_ 'Example:')")
228 tazpkg up --recharge --install
229 tazpkg up -c -r
230 EOT
231 }
234 # Check if dir exists
236 check_dir()
237 {
238 if ! [ -d "$1" ]; then
239 action 'Creating folder "%s"...' "$1"
240 mkdir -p "$1"
241 status
242 return 1
243 fi
244 }
247 # Check if the directories and files used by TazPKG
248 # exist. If not and user is root we create them.
250 check_base_dir()
251 {
252 if [ "$(id -u)" = "0" ]; then
253 check_dir $1$CACHE_DIR
254 check_dir $1$INSTALLED
255 check_dir $1$SLITAZ_LOGS
256 if [ ! -f "$1$PKGS_DB/mirror" ]; then
257 echo "${DEFAULT_MIRROR%/}/" > $1$PKGS_DB/mirror
258 [ -n "$1" ] && cp $PKGS_DB/packages.* $1$PKGS_DB/
259 fi
260 fi
261 }
262 check_base_dir
265 # Check for a package name on cmdline.
267 check_for_package_on_cmdline()
268 {
269 if [ -z "$PACKAGE" ]; then
270 newline
271 _ 'Please specify a package name on the command line.'
272 newline
273 exit 1
274 fi
275 }
278 # Check if the package (*.tazpkg) exists before installing or extracting.
280 check_for_package_file()
281 {
282 if [ ! -f "$PACKAGE_FILE" ]; then
283 newline
284 _ 'Unable to find file "%s"' $PACKAGE_FILE
285 newline
286 exit 1
287 fi
288 }
291 # Check for the receipt of an installed package.
293 check_for_receipt()
294 {
295 if [ ! -f "$1$INSTALLED/$PACKAGE/receipt" ]; then
296 newline
297 _ 'Unable to find the receipt "%s"' "$1$INSTALLED/$PACKAGE/receipt"
298 newline
299 exit 1
300 fi
301 }
304 # Get repositories priority using $PKGS_DB/priority.
305 # In this files, undigest are called by their name and main mirror
306 # by main. Sort order: priority
308 look_for_priority()
309 {
310 [ -s $PKGS_DB/priority ] && priority=$(cat $PKGS_DB/priority)
311 for rep in main $(ls $PKGS_DB/undigest 2>/dev/null); do
312 if [ ! -s $PKGS_DB/priority ] || \
313 ! grep -q ^$rep$ $PKGS_DB/priority; then
314 priority=$(echo -e "$priority\n$rep")
315 fi
316 done
317 priority=$(echo "$priority" | sed '/^$/d' | \
318 while read line; do
319 if [ "$line" = main ]; then
320 echo $PKGS_DB
321 else
322 echo $PKGS_DB/undigest/$line
323 fi
324 done)
325 }
328 # Get package name in a directory
330 package_fullname_in_dir()
331 {
332 [ -f $1/receipt ] || return
333 EXTRAVERSION=""
334 . $1/receipt
335 echo $PACKAGE-$VERSION$EXTRAVERSION
336 }
339 # Get package name that is already installed.
341 get_installed_package_pathname()
342 {
343 for i in $2$INSTALLED/${1%%-*}*; do
344 [ -d $i ] || continue
345 if [ "$1" = "$(package_fullname_in_dir $i)" ]; then
346 echo $i
347 return
348 fi
349 done
350 }
353 # Check if a package is already installed.
355 check_for_installed_package()
356 {
357 if [ -n "$(get_installed_package_pathname $PACKAGE $1)" ]; then
358 newline
359 _ '"%s" package is already installed.' $(colorize 34 $PACKAGE)
360 longline "$(_ 'You can use the --forced option to force installation.')"
361 newline
362 exit 0
363 fi
364 }
367 # Check for packages.list to download and install packages.
369 check_for_packages_list()
370 {
371 list_path="$PKGS_DB/packages.list"
372 if [ ! -f "$list_path" ]; then
373 if test $(id -u) = 0 ; then
374 tazpkg recharge
375 else
376 newline
377 _ 'Unable to find the list "%s"' $list_path
378 _ \
379 "You must probably run 'tazpkg recharge' as root to get the latest list of
380 packages available on the mirror."
381 newline
382 exit 0
383 fi
384 fi
385 }
388 # Check for installed.info - local file with format of packages.info
389 # "installed.info" is absent on not clean installs; check it and re-generate if needed.
391 check_for_installed_info()
392 {
393 info_path="$ROOT$PKGS_DB/installed.info"
394 if [ ! -f "$info_path" ]; then
395 if [ "$(id -u)" == "0" ]; then
396 _ 'File "%s" generated. Please wait...' installed.info
397 for pkg in $ROOT$PKGS_DB/installed/*/receipt; do
398 unset_receipt
399 . $pkg
400 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
401 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
402 cat >> $info_path << EOT
403 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS
404 EOT
405 done
406 else
407 _ 'Unable to find file "%s"' installed.info
408 _ 'Please run tazpkg as root.'
409 exit 1
410 fi
411 fi
412 }
415 get_cache_dir()
416 {
417 echo $rep > $tmp/rep
418 if [ "$rep" = "$PKGS_DB" ]; then
419 CACHE_DIR="$SAVE_CACHE_DIR/$SLITAZ_RELEASE/packages"
420 elif [ "${rep%-incoming}" = "$rep" ]; then
421 CACHE_DIR="$SAVE_CACHE_DIR/${rep##*/}/packages"
422 else
423 rep="${rep%-incoming}"
424 CACHE_DIR="$SAVE_CACHE_DIR/${rep##*/}/packages-incoming"
425 fi
426 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
427 echo $CACHE_DIR > $tmp/cachedir
428 }
431 # get an already installed package from packages.equiv
433 equivalent_pkg()
434 {
435 for i in $(grep -hs "^$1=" $PKGS_DB/packages.equiv \
436 $PKGS_DB/undigest/*/packages.equiv | sed "s/^$1=//"); do
437 if echo $i | fgrep -q : ; then
438 # format 'alternative:newname'
439 # if alternative is installed then substitute newname
440 if [ -f $2$INSTALLED/${i%:*}/receipt ]; then
441 # substitute package dependency
442 echo ${i#*:}
443 return
444 fi
445 else
446 # if alternative is installed then nothing to install
447 if [ -f $2$INSTALLED/$i/receipt ]; then
448 # substitute installed package
449 echo $i
450 return
451 fi
452 fi
453 done
454 # if not found in packages.equiv then no substitution
455 echo $1
456 }
459 # get a virtual package from packages.equiv
461 virtual_pkg()
462 {
463 for i in $(for rep in $priority; do
464 grep -hs "^$1=" $rep/packages.equiv
465 done | sed "s/^$1=//"); do
466 if echo $i | fgrep -q : ; then
467 # format 'alternative:newname'
468 # if alternative is installed then substitute newname
469 if [ -f $2$INSTALLED/${i%:*}/receipt ]; then
470 # substitute package dependency
471 echo ${i#*:}
472 return
473 fi
474 else
475 # unconditional substitution
476 echo $i
477 return
478 fi
479 done
480 }
483 # Get package filename available on the mirror
485 get_package_filename()
486 {
487 local pkg
488 for rep in $priority; do
489 pkg=$(grep -A 1 -sh "^$1$" $rep/packages.txt | tail -1 | sed 's/^ *//')
490 [ "$pkg" ] && pkg=$(grep -sh "^$1-$pkg" $rep/packages.list | head -1)
492 # Allow user to call a package with his version number.
493 [ "$pkg" ] || pkg=$(grep -sh "^$1$" $rep/packages.list | head -1)
495 [ "$pkg" ] || pkg=$(grep -sh "^$1-[0-9]" $rep/packages.list | head -1)
496 [ "$pkg" ] || pkg=$(grep -sh "^$1-.[\.0-9]" $rep/packages.list | head -1)
497 [ "$pkg" ] && get_cache_dir && break
498 done
499 if [ -z "$pkg" ]; then
500 # Check for virtual package
501 local equiv
502 equiv=$(virtual_pkg $1)
503 if [ "$equiv" != "$1" ]; then
504 PACKAGE=$equiv
505 get_package_filename $PACKAGE
506 return
507 fi
508 fi
509 echo $pkg
510 }
513 # Check for a package in packages.list. Used by get and get-install to grep
514 # package basename.
516 check_for_package_in_list()
517 {
518 local filename
519 local check_only
520 check_only="$1"
521 filename=$(get_package_filename $PACKAGE)
522 if [ "$filename" ]; then
523 PACKAGE=$filename
524 CACHE_DIR=$(cat $tmp/cachedir)
525 rep=$(cat $tmp/rep)
526 rm -f $tmp/rep $tmp/cachedir
527 else
528 newline
529 _ 'Unable to find package "%s" in the mirrored packages list.' $PACKAGE
530 newline
531 [ -n "$check_only" ] && return 1
532 exit 0
533 fi
534 }
537 # Log this activity
538 # (there log_pkg because we have log() in libtaz.sh)
540 log_pkg()
541 {
542 local extra
544 [ "$1" = "Installed" ] && \
545 extra=" - $(fgrep $PACKAGE-$VERSION $PKGS_DB/installed.$SUM | awk '{ print $1 }')"
547 [ -e $LOG ] || touch $LOG
549 [ -w $LOG ] &&
550 echo "$(date +'%F %T') - $1 - $PACKAGE ($VERSION$EXTRAVERSION)$extra" >> $LOG
551 }
554 # Download a get-package script from this mirror
556 download_get_script()
557 {
558 local p
559 for p in $priority ; do
560 local i
561 for i in $(cat $p/mirror) ; do
562 case "$i" in
563 http://*|ftp://*)
564 wget -O $2 ${i%packages/*}packages/get/$1 && return 0 ;;
565 esac
566 done
567 done
568 return 1
569 }
572 # Download a file from this mirror
574 download_from()
575 {
576 local i
577 local mirrors
578 mirrors="$1"
579 shift
580 for i in $mirrors; do
581 case "$i" in
582 # Mirror URL can have a trailing slash or not.
583 http://*|ftp://*)
584 busybox wget -c ${i%/}/$@ && break ;;
585 https://*)
586 echo 'Sorry, https not supported' ;;
587 *)
588 ln -sf $i/$1 . && break ;;
589 esac
590 done
591 }
594 # Download a file trying all mirrors
596 download()
597 {
598 local i
599 case "$1" in
600 *.tazpkg)
601 for i in $priority ; do
602 grep -q "^${1%.tazpkg}$" $i/packages.list 2>/dev/null || continue
603 download_from "$(cat $i/mirror)" "$@" && return
604 done
605 esac
606 for i in $(cat $(for rep in $priority; do echo $rep/mirror; done) 2>/dev/null); do
607 download_from "$i" "$@" && break
608 done
609 }
612 # Extract a package with cpio and gzip/lzma.
614 extract_package()
615 {
616 action 'Extracting package...'
617 cpio -idm --quiet < ${PACKAGE_FILE##*/} && rm -f ${PACKAGE_FILE##*/}
618 status
619 if [ -f fs.cpio.lzma ]; then
620 unlzma -c fs.cpio.lzma | cpio -idm --quiet && rm fs.cpio.lzma
621 elif [ -f fs.cpio.gz ]; then
622 zcat fs.cpio.gz | cpio -idm --quiet && rm fs.cpio.gz
623 fi
624 }
627 remove_with_path()
628 {
629 # Avoid dirname errors by checking for argument.
630 [ "$1" ] || return
632 local dir
633 rm -f $1 2>/dev/null
634 dir="$1"
635 while [ "$dir" != "/" ]; do
636 dir="$(dirname $dir)"
637 rmdir $dir 2> /dev/null || break
638 done
639 }
642 grepesc()
643 {
644 sed 's/\[/\\[/g'
645 }
648 # This function installs a package in the rootfs.
650 install_package()
651 {
652 ROOT=$1
653 if [ -n "$ROOT" ]; then
654 # Get absolute path
655 ROOT=$(realpath $ROOT)
656 fi
657 {
658 # Create package path early to avoid dependencies loop
659 mkdir -p $TMP_DIR
660 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
661 . $TMP_DIR/receipt
662 # FIXME: legacy?
663 if grep -q ^pre_depends $TMP_DIR/receipt; then
664 pre_depends $ROOT
665 fi
667 # Keep modifiers and file list on upgrade
668 cp $ROOT$INSTALLED/$PACKAGE/modifiers \
669 $ROOT$INSTALLED/$PACKAGE/files.list $TMP_DIR 2> /dev/null
670 rm -rf $ROOT$INSTALLED/$PACKAGE 2> /dev/null
672 # Make the installed package data dir to store
673 # the receipt and the files list.
674 mkdir -p $ROOT$INSTALLED/$PACKAGE
675 cp $TMP_DIR/modifiers $ROOT$INSTALLED/$PACKAGE 2> /dev/null
676 cp $TMP_DIR/files.list $ROOT$INSTALLED/$PACKAGE 2> /dev/null
677 rm -rf $TMP_DIR 2> /dev/null
678 sed -i "/ $(basename $PACKAGE_FILE)$/d" \
679 $ROOT$PKGS_DB/installed.$SUM 2> /dev/null
680 cd $(dirname $PACKAGE_FILE)
681 $CHECKSUM $(basename $PACKAGE_FILE) >> $ROOT$PKGS_DB/installed.$SUM
682 }
684 # Resolve package deps.
685 check_for_deps $ROOT
686 if [ -n "$MISSING_PACKAGE" ]; then
687 install_deps $ROOT
688 fi
689 mkdir -p $TMP_DIR
690 [ -n "$INSTALL_LIST" ] && echo "$PACKAGE_FILE" >> $ROOT$PKGS_DB/$INSTALL_LIST-processed
692 title 'Installation of package "%s"' $PACKAGE
694 action 'Copying package...'
695 cp $PACKAGE_FILE $TMP_DIR
696 status
698 cd $TMP_DIR
699 extract_package
700 SELF_INSTALL=0
701 EXTRAVERSION=""
702 CONFIG_FILES=""
704 # Include temporary receipt to get the right variables.
705 . $PWD/receipt
706 cd $ROOT$INSTALLED
708 # FIXME: legacy?
709 if [ $SELF_INSTALL -ne 0 -a -n "$ROOT" ]; then
710 action "Checking post install dependencies..."
711 [ -f $INSTALLED/$PACKAGE/receipt ]
712 if ! status; then
713 _ 'Please run "%s" in / and retry.' "tazpkg install $PACKAGE_FILE"
714 rm -rf $TMP_DIR
715 exit 1
716 fi
717 fi
719 # Get files to remove if upgrading
720 if [ -f $PACKAGE/files.list ]; then
721 while read file; do
722 grep -q "^$(echo $file | grepesc)$" $TMP_DIR/files.list && continue
723 for i in $(cat $PACKAGE/modifiers 2> /dev/null ;
724 fgrep -sl $PACKAGE */modifiers | cut -d/ -f1 ); do
725 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
726 done
727 echo $file
728 done < $PACKAGE/files.list > $TMP_DIR/files2remove.list
729 fi
731 # Remember modified packages
732 {
733 check=false
734 for i in $(fgrep -v [ $TMP_DIR/files.list); do
735 [ -e "$ROOT$i" ] || continue
736 [ -d "$ROOT$i" ] && continue
737 echo "- $i"
738 check=true
739 done ;
740 $check && \
741 for i in *; do
742 [ "$i" == "$PACKAGE" ] && continue
743 [ -s $i/files.list ] || continue
744 awk "{ printf \"$i %s\\n\",\$1 }" < $i/files.list
745 done;
746 } | awk '
747 {
748 if ($1 == "-" || file[$2] != "") {
749 file[$2] = file[$2] " " $1
750 if ($1 != "-") {
751 if (pkg[$1] == "") all = all " " $1
752 pkg[$1] = pkg[$1] " " $2
753 }
754 }
755 }
756 END {
757 for (i = split(all, p, " "); i > 0; i--)
758 for (j = split(pkg[p[i]], f, " "); j > 0; j--)
759 printf "%s %s\n",p[i],f[j];
760 }
761 ' | while read dir file; do
762 if grep -qs ^$dir$ $PACKAGE/modifiers; then
763 # Do not overload an overloaded file !
764 rm $TMP_DIR$file 2> /dev/null
765 continue
766 fi
767 grep -qs ^$PACKAGE$ $dir/modifiers && continue
768 if [ -s "$dir/volatile.cpio.gz" ]; then
769 # We can modify backed up files without notice
770 zcat $dir/volatile.cpio.gz | cpio -t --quiet | \
771 grep -q "^${file#/}$" && continue
772 fi
773 echo "$PACKAGE" >> $dir/modifiers
774 done
776 cd $TMP_DIR
777 cp receipt files.list $ROOT$INSTALLED/$PACKAGE
779 # Copy the description if found.
780 if [ -f "description.txt" ]; then
781 cp description.txt $ROOT$INSTALLED/$PACKAGE
782 fi
784 # Copy the md5sum if found.
785 if [ -f "$CHECKSUM" ]; then
786 cp $CHECKSUM $ROOT$INSTALLED/$PACKAGE
787 fi
789 # Pre install commands.
790 if grep -q ^pre_install $ROOT$INSTALLED/$PACKAGE/receipt; then
791 pre_install $ROOT
792 fi
794 if [ -n "$CONFIG_FILES" ]; then
795 # save 'official' configuration files
796 action 'Saving configuration files...'
797 for i in $CONFIG_FILES; do
798 { cd fs ; find ${i#/} -type f 2> /dev/null; cd ..; }
799 done | { cd fs ; cpio -o -H newc --quiet | gzip -9; cd ..; } > \
800 $ROOT$INSTALLED/$PACKAGE/volatile.cpio.gz
802 if [ -z "$newconf" ]; then
803 # keep user configuration files
804 for i in $CONFIG_FILES; do
805 { cd fs ; find ${i#/} -type f 2> /dev/null; cd ..; }
806 done | while read i; do
807 [ -e $ROOT/$i ] || continue
808 cp -a $ROOT/$i fs/$i
809 done
810 fi
811 status
812 fi
814 action 'Installing package...'
815 [ "$(busybox ls fs/* 2> /dev/null)" ] && cp -af fs/* $ROOT/
816 status
818 if [ -s files2remove.list ]; then
819 action 'Removing old package...'
820 while read file; do
821 remove_with_path $ROOT$file
822 done < files2remove.list
823 true
824 status
825 fi
827 # Remove the temporary random directory.
828 action "Removing all tmp files..."
829 cd ..; rm -rf $TMP_DIR
830 status
832 # Post install commands.
833 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
834 post_install $ROOT
835 fi
837 # Update-desktop-database if needed.
838 if [ "$(fgrep .desktop $ROOT$INSTALLED/$PACKAGE/files.list | fgrep /usr/share/applications/)" ]; then
839 updatedesktopdb=yes
840 fi
842 # Update-mime-database if needed.
843 if [ "$(fgrep /usr/share/mime $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
844 updatemimedb=yes
845 fi
847 # Update-icon-database
848 if [ "$(fgrep /usr/share/icon/hicolor $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
849 updateicondb=yes
850 fi
852 # Compile glib schemas if needed.
853 if [ "$(fgrep /usr/share/glib-2.0/schemas $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
854 compile_schemas=yes
855 fi
857 # Update depmod list
858 if [ "$(fgrep /lib/modules $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
859 updatedepmod=yes
860 fi
862 # Update installed.info
863 check_for_installed_info
864 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
865 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
866 II=$ROOT$PKGS_DB/installed.info
867 sed -i "/^$PACKAGE /d" $II # remove old entry
868 cat >> $II << EOT
869 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS
870 EOT
871 TEMP_FILE=$(mktemp)
872 sort $II > $TEMP_FILE; mv -f $TEMP_FILE $II; chmod a+r $II; unset II
874 cd $TOP_DIR
875 footer "$(_ 'Package "%s" (%s) is installed.' $PACKAGE $VERSION$EXTRAVERSION)"
877 # Log this activity
878 [ -n "$ROOT" ] || log_pkg Installed
879 }
882 # This function may be called by a get script.
884 abort_package()
885 {
886 cd $CUR_DIR
887 rm -rf $TMP_DIR
888 echo "${1:-Abort $PACKAGE.}"
889 exit 1
890 }
893 # This function installs a package from a get script in the rootfs.
895 install_package_from_get_script()
896 {
897 SCRIPT="$1"
898 ROOT="$2"
899 [ -d $ROOT$INSTALLED/$PACKAGE ] && exit 1
901 grep -q no-check-certificate $SCRIPT &&
902 [ ! -d $INSTALLED/wget ] && tazpkg get-install wget
904 mkdir -p $TMP_DIR && cd $TMP_DIR
905 saved=$PACKAGE
906 unset_receipt
907 PACKAGE=$saved
909 set -e
910 . $SCRIPT
911 set +e
912 cd $TMP_DIR
913 [ -d $PACKAGE-$VERSION ] || abort_package \
914 "$(_ 'Could not download "%s" from "%s". Exiting.' ${TARBALL:-$PACKAGE} ${WGET_URL:-$WEB_SITE})"
916 if [ ! -s $PACKAGE-$VERSION/receipt ]; then
917 cat > $PACKAGE-$VERSION/receipt <<EOT
918 # SliTaz package receipt.
920 PACKAGE="$PACKAGE"
921 VERSION="${VERSION:-unknown}"
922 CATEGORY="${CATEGORY:-non-free}"
923 WEB_SITE="$WEB_SITE"
924 SHORT_DESC="${SHORT_DESC:-$PACKAGE}"
925 MAINTAINER="${MAINTAINER:-nobody@slitaz.org}"
926 EOT
927 for i in LICENSE TARBALL WGET_URL CONFIG_FILES SUGGESTED \
928 PROVIDE DEPENDS HOST_ARCH TAGS EXTRA_SOURCE_FILES ; do
929 eval "[ -n \"\$$i\" ] && echo \"$i=\\\"\$$i\\\"\""
930 done >> $PACKAGE-$VERSION/receipt
931 fi
933 DEPENDS="$(unset DEPENDS; . $PACKAGE-$VERSION/receipt ; echo $DEPENDS)"
934 for i in $(find_depends $PACKAGE-$VERSION/fs); do
935 case " $DEPENDS " in
936 *\ $i\ *) continue;;
937 esac
938 grep -q '^DEPENDS="' $PACKAGE-$VERSION/receipt ||
939 echo 'DEPENDS=""' >> $PACKAGE-$VERSION/receipt
940 sed -i "s/^DEPENDS=\"/&$i /" $PACKAGE-$VERSION/receipt
941 done
943 tazpkg pack $PACKAGE-$VERSION
945 # Clean to save RAM memory before installation
946 rm -rf $PACKAGE-$VERSION
948 # Install pseudo package
949 tazpkg install $PACKAGE-$VERSION.tazpkg --root=$ROOT
950 mv $PACKAGE-$VERSION.tazpkg $CACHE_DIR
952 # Clean
953 cd $TOP_DIR
954 rm -rf $TMP_DIR
955 }
958 # Check for loop in deps tree.
960 check_for_deps_loop()
961 {
962 local list
963 local pkg
964 local deps
965 pkg=$1
966 shift
967 [ -n "$1" ] || return
968 list=""
970 # Filter out already processed deps
971 for i in $@; do
972 case " $ALL_DEPS" in
973 *\ $i\ *) ;;
974 *) list="$list $i";;
975 esac
976 done
977 ALL_DEPS="$ALL_DEPS$list "
978 for i in $list; do
979 [ -f $i/receipt ] || continue
980 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
981 case " $deps " in
982 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
983 *) check_for_deps_loop $pkg $deps;;
984 esac
985 done
986 }
989 # Check for missing deps listed in a receipt packages.
991 check_for_deps()
992 {
993 local saved;
994 saved=$PACKAGE
995 mkdir -p $TMP_DIR
996 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
997 . $TMP_DIR/receipt
998 PACKAGE=$saved
999 rm -rf $TMP_DIR
1001 num=0
1002 for pkgorg in $DEPENDS; do
1003 i=$(equivalent_pkg $pkgorg $1)
1004 if [ ! -d "$1$INSTALLED/$i" ]; then
1005 MISSING_PACKAGE=$i
1006 num=$(($num+1))
1007 elif [ ! -f "$1$INSTALLED/$i/receipt" ]; then
1008 _ 'WARNING! Dependency loop between "%s" and "%s".' $PACKAGE $i
1009 fi
1010 done
1012 if [ -n "$MISSING_PACKAGE" ]; then
1013 title "$(_ 'Tracking dependencies for package "%s"' $PACKAGE)"
1014 for pkgorg in $DEPENDS; do
1015 i=$(equivalent_pkg $pkgorg $1)
1016 if [ ! -d "$1$INSTALLED/$i" ]; then
1017 MISSING_PACKAGE=$i
1018 _ 'Missing package "%s"' $MISSING_PACKAGE
1019 fi
1020 done
1021 footer "$(_p \
1022 '%s missing package to install.' \
1023 '%s missing packages to install.' $num \
1024 $num)"
1025 fi
1029 # Install all missing deps. Auto install or ask user then install all missing
1030 # deps from local dir, cdrom, media or from the mirror. In case we want to
1031 # install packages from local, we need a packages.list to find the version.
1033 install_deps()
1035 local root
1036 root=""
1037 [ -n "$1" ] && root="--root=$1"
1038 if [ "$AUTO_INSTALL_DEPS" == "yes" ]; then
1039 answer=0
1040 else
1041 newline
1042 confirm "$(_ 'Install all missing dependencies? (y/N)')"
1043 answer=$?
1044 newline
1045 fi
1046 if [ $answer = 0 ] && ! [ "$nodeps" ]; then
1047 for pkgorg in $DEPENDS; do
1048 pkg=$(equivalent_pkg $pkgorg $1)
1049 if [ ! -d "$1$INSTALLED/$pkg" ]; then
1050 local list
1051 list="$INSTALL_LIST"
1052 [ -n "$list" ] || list="$TOP_DIR/packages.list"
1053 # We can install packages from a local dir by greping
1054 # the TAZPKG_BASENAME in the local packages.list.
1055 found=0
1056 if [ -f "$list" ]; then
1057 _ 'Checking if package "%s" exists in local list...' $pkg
1058 mkdir $TMP_DIR
1059 for i in $pkg-*.tazpkg; do
1060 [ -f $i ] || continue
1061 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $i
1062 [ "$(. $TMP_DIR/receipt; echo $PACKAGE)" = "$pkg" ] || continue
1063 if grep -q ^$(package_fullname_in_dir $TMP_DIR).tazpkg$ $list
1064 then
1065 found=1
1066 tazpkg install $i $root --list=$list
1067 break
1068 fi
1069 done
1070 rm -rf $TMP_DIR
1071 fi
1072 # Install deps from the mirror.
1073 if [ $found -eq 0 ]; then
1074 if [ ! -f "$PKGS_DB/packages.list" ]; then
1075 tazpkg recharge
1076 fi
1077 tazpkg get-install $pkg $root
1078 fi
1079 fi
1080 done
1081 else
1082 newline
1083 _ 'Leaving dependencies for package "%s" unresolved.' $PACKAGE
1084 _ 'The package is installed but will probably not work.'
1085 newline
1086 fi
1090 # Search pattern in installed packages.
1092 search_in_installed_packages()
1094 _ 'Installed packages'
1095 separator
1096 num=0
1097 for pkg in $(ls -1 $INSTALLED | grep -i "$PATTERN"); do
1098 EXTRAVERSION=""
1099 [ -f $INSTALLED/$pkg/receipt ] || continue
1100 . $INSTALLED/$pkg/receipt
1101 emsg "$PACKAGE<i 24> $VERSION$EXTRAVERSION<i 42> $(_n $CATEGORY)"
1102 num=$(($num+1))
1103 done
1105 footer "$(_p \
1106 '%s installed package found for "%s"' \
1107 '%s installed packages found for "%s"' $num \
1108 $num "$PATTERN")"
1112 # Search in packages.list for available pkgs.
1114 search_in_packages_list()
1116 _ 'Available packages'
1117 separator
1118 num=0
1119 BPATTERN="$(emsg "<b>$PATTERN</b>")"
1120 for i in $PKGS_DB/packages.list $PKGS_DB/undigest/*/packages.list \
1121 $PKGS_DB/extra.list $PKGS_DB/undigest/*/extra.list ; do
1122 grep -is "$PATTERN" $i | sed "s|$PATTERN|$BPATTERN|"
1123 num=$(($num + `grep -is "$PATTERN" $i | wc -l`))
1124 done
1125 if [ ! -f "$PKGS_DB/packages.list" ]; then
1126 newline
1127 longline "$(_ \
1128 "No \"%s\" found to check for mirrored packages. For more results, please run \
1129 \"%s\" once as root before searching." packages.list 'tazpkg recharge')"
1130 newline
1131 fi
1132 footer "$(_p \
1133 '%s available package found for "%s"' \
1134 '%s available packages found for "%s"' $num \
1135 $num $PATTERN)"
1139 # search --mirror: Search in packages.txt for available pkgs and give more
1140 # info than --list or default.
1142 search_in_packages_txt()
1144 _ 'Matching packages name with version and desc'
1145 separator
1146 num=0
1147 for i in $PKGS_DB/packages.txt $PKGS_DB/undigest/*/packages.txt; do
1148 grep -is -A 2 "^$PATTERN" $i
1149 num=$(($num + `grep -is "^$PATTERN" $i | wc -l`))
1150 done
1151 if [ ! -f "$PKGS_DB/packages.txt" ]; then
1152 newline
1153 longline "$(_ \
1154 "No \"%s\" found to check for mirrored packages. For more results, please run \
1155 \"%s\" once as root before searching." packages.txt 'tazpkg recharge')"
1156 newline
1157 fi
1158 footer "$(_p \
1159 '%s available package found for "%s"' \
1160 '%s available packages found for "%s"' $num \
1161 $num $PATTERN)"
1165 # Install package-list from a flavor
1167 install_flavor()
1169 check_root $@
1171 # Get repositories priority list.
1172 look_for_priority
1174 FLAVOR=$1
1175 ARG=$2
1176 mkdir -p $TMP_DIR
1177 [ -f $FLAVOR.flavor ] && cp $FLAVOR.flavor $TMP_DIR
1178 cd $TMP_DIR
1179 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1180 zcat < $FLAVOR.flavor | cpio --quiet -i >/dev/null
1182 while read file; do
1183 for pkg in $(ls -d $INSTALLED/${file%%-*}*); do
1184 [ -f $pkg/receipt ] || continue
1185 EXTRAVERSION=""
1186 . $pkg/receipt
1187 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && break
1188 done
1189 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && continue
1190 cd $CACHE_DIR
1191 download $file.tazpkg
1192 cd $TMP_DIR
1193 tazpkg install $CACHE_DIR/$file.tazpkg --forced
1194 done < $FLAVOR.pkglist
1196 [ -f $FLAVOR.nonfree ] && while read pkg; do
1197 [ -d $INSTALLED/$pkg ] || continue
1198 [ -d $INSTALLED/get-$pkg ] && tazpkg get-install get-$pkg
1199 get-$pkg
1200 done < $FLAVOR.nonfree
1202 [ "$ARG" == "--purge" ] && for pkg in $(ls $INSTALLED); do
1203 [ -f $INSTALLED/$pkg/receipt ] || continue
1204 EXTRAVERSION=""
1205 . $INSTALLED/$pkg/receipt
1206 grep -q ^$PACKAGE-$VERSION$EXTRAVERSION$ $FLAVOR.pkglist && continue
1207 grep -qs ^$PACKAGE$ $FLAVOR.nonfree && continue
1208 tazpkg remove $PACKAGE
1209 done
1210 else
1211 _ "Can't find flavor \"%s\". Abort." $FLAVOR
1212 fi
1213 cd $TOP_DIR
1214 rm -rf $TMP_DIR
1218 # Update mirror urls
1220 setup_mirror()
1222 # Backup old list.
1223 if [ -f "$1/mirror" ]; then
1224 cp -f $1/mirror $1/mirror.bak
1225 fi
1226 title 'Current mirror(s)'
1227 echo " `cat $1/mirror 2> /dev/null`"
1228 longline "$(_ \
1229 "Please enter URL of the new mirror (http, ftp or local path). You must specify \
1230 the complete address to the directory of the packages and packages.list file.")"
1231 newline
1232 _n 'New mirror(s) URL: '
1233 NEW_MIRROR_URL=$2
1234 if [ -n "$NEW_MIRROR_URL" ]; then
1235 echo $NEW_MIRROR_URL
1236 else
1237 read NEW_MIRROR_URL
1238 fi
1239 if [ "$NEW_MIRROR_URL" = "" ]; then
1240 _ 'Nothing has been changed.'
1241 else
1242 _ 'Setting mirror(s) to: "%s"' $NEW_MIRROR_URL
1243 rm -f $1/mirror
1244 for i in $NEW_MIRROR_URL; do
1245 echo "${i%/}/" >> $1/mirror
1246 done
1247 fi
1248 newline
1252 # recursive dependencies scan
1254 dep_scan()
1256 for i in $1; do
1257 case " $ALL_DEPS " in
1258 *\ $i\ *) continue;;
1259 esac
1260 ALL_DEPS="$ALL_DEPS $i"
1261 [ -n "$2" ] && echo "$2$i ($(fgrep -A 3 $i $PKGS_DB/packages.txt | \
1262 tail -1 | sed 's/.*(\([^ ]*\).*/\1/'))"
1263 [ -f $i/receipt ] || continue
1264 DEPENDS=""
1265 . $i/receipt
1266 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
1267 done
1271 # recursive reverse dependencies scan
1273 rdep_scan()
1275 SEARCH=$1
1277 for i in * ; do
1278 DEPENDS=""
1279 . $i/receipt
1280 echo "$i $(echo $DEPENDS)"
1281 done | busybox awk -v search=$SEARCH '
1282 function show_deps(deps, all_deps, pkg, space)
1284 if (all_deps[pkg] == 1) return
1285 all_deps[pkg] = 1
1286 if (space != "") printf "%s %s\n",space,pkg
1287 for (i = 1, n = split(deps[pkg], mydeps, " "); i <= n; i++) {
1288 show_deps(deps, all_deps, mydeps[i],"==" space)
1293 all_deps[$1] = 0
1294 for (i = 2; i <= NF; i++)
1295 deps[$i] = deps[$i] " " $1
1298 END {
1299 show_deps(deps, all_deps, search, "")
1301 ' | while read spc pkg; do
1302 echo -n $spc | sed 's/=/ /g'
1303 echo -n $pkg
1304 echo -n ' ('
1305 fgrep -A 3 $pkg $PKGS_DB/packages.txt | tail -1 | \
1306 sed 's/.*(\([^ ]*\).*/\1)/'
1307 done
1311 update_desktop_database()
1313 if [ -f $1/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
1314 chroot "$1/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
1315 fi
1319 update_mime_database()
1321 if [ -f $1/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
1322 chroot "$1/" /usr/bin/update-mime-database /usr/share/mime
1323 fi
1327 update_icon_database()
1329 if [ -f $1/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
1330 chroot "$1/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
1331 fi
1335 compile_glib_schemas()
1337 if [ -f $1/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
1338 chroot "$1/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
1339 fi
1343 update_kernel_modules()
1345 if [ -f $1/sbin/depmod ] && [ -n "$updatedepmod" ]; then
1346 chroot "$1/" /sbin/depmod -a
1347 fi
1354 ###################
1355 # TazPKG commands #
1356 ###################
1358 case "$COMMAND" in
1359 list|-l)
1360 # List all installed packages or a specific category.
1361 shift
1362 check_for_installed_info
1364 case $1 in
1365 b|blocked)
1366 # Display the list of blocked packages.
1367 title 'Blocked packages'
1368 if [ -s "$BLOCKED" ];then
1369 cat $BLOCKED
1370 else
1371 _ 'No blocked packages found.'
1372 fi
1373 newline; exit 0
1374 ;;
1375 c|cat|categories)
1376 # Display the list of categories.
1377 title 'Packages categories'
1378 echo "$PKGS_CATEGORIES" | sed 's|[^a-z-]|\n|g; /^$/d' | \
1379 sed 's|\(.*\)|\1'$'\033''[15G \1|' | translate_category
1380 num=$(echo -n "$PKGS_CATEGORIES" | wc -l)
1381 footer "$(_p \
1382 '%s category' \
1383 '%s categories' $num \
1384 $num)"
1385 exit 0
1386 ;;
1387 '')
1388 # By default list all packages and versions.
1389 title 'List of all installed packages'
1390 TMPLIST=$(mktemp)
1391 awk -F$'\t' '{print $1"\033[35G "$2"\033[53G "$3}' \
1392 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
1394 packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST
1395 footer "$(emsg $(_p \
1396 '%s package installed.' \
1397 '%s packages installed.' $packages \
1398 "<c 32>$packages</c>"))"
1399 ;;
1400 *)
1401 # Check for an asked category.
1402 ASKED_CATEGORY_I18N="$@"
1403 ASKED_CATEGORY=$(reverse_translate_category "$ASKED_CATEGORY_I18N")
1404 title 'Installed packages of category "%s"' $ASKED_CATEGORY_I18N
1405 TMPLIST=$(mktemp)
1406 awk -F$'\t' '
1408 if ($3 == "'$ASKED_CATEGORY'")
1409 print $1"\033[35G "$2
1410 }' \
1411 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
1413 packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST
1414 footer "$(emsg $(_p \
1415 '%s package installed of category "%s".' \
1416 '%s packages installed of category "%s".' $packages \
1417 "<c 32>$packages</c>" "<c 34>$ASKED_CATEGORY_I18N</c>"))"
1418 ;;
1419 esac ;;
1421 list-mirror|-lm)
1422 # List all available packages on the mirror. Option --diff displays
1423 # last mirrored packages diff (see recharge).
1424 check_for_packages_list
1425 case $2 in
1426 --diff)
1427 if [ -f "$PKGS_DB/packages.diff" ]; then
1428 title 'Mirrored packages diff'
1429 cat $PKGS_DB/packages.diff
1430 num=$(wc -l < $PKGS_DB/packages.diff)
1431 footer "$(_p \
1432 '%s new package listed on the mirror.' \
1433 '%s new packages listed on the mirror.' $num \
1434 $num)"
1435 else
1436 newline
1437 _ 'Unable to list anything, no packages.diff found.'
1438 _ 'Recharge your current list to create a first diff.'
1439 newline
1440 fi; exit 0 ;;
1441 --text|--txt|--raw|*)
1442 title 'List of available packages on the mirror'
1443 cat $PKGS_DB/packages.txt ;;
1444 esac
1445 pkgs=$(wc -l < $PKGS_DB/packages.list)
1446 footer "$(emsg "$(_p \
1447 '%s package in the last recharged list.' \
1448 '%s packages in the last recharged list.' $pkgs \
1449 "<c 32>$pkgs</c>")")"
1450 ;;
1453 list-files|-lf)
1454 # List files installed with the package.
1455 check_for_package_on_cmdline
1456 check_for_receipt
1457 title 'Installed files by "%s"' $PACKAGE
1458 sort < $INSTALLED/$PACKAGE/files.list
1459 files=$(wc -l < $INSTALLED/$PACKAGE/files.list)
1460 footer "$(emsg "$(_p \
1461 '%s file' '%s files' $files \
1462 "<c 32>$files</c>")")"
1463 ;;
1466 info)
1467 # Information about package.
1468 check_for_package_on_cmdline
1469 check_for_receipt
1470 EXTRAVERSION=""
1471 . $INSTALLED/$PACKAGE/receipt
1472 im && title 'TazPKG information'
1473 # Display localized short description
1474 for LC in $LANG ${LANG%_*}; do
1475 if [ -e "$PKGS_DB/packages-desc.$LC" ]; then
1476 LOCDESC=$(grep -e "^$PACKAGE " $PKGS_DB/packages-desc.$LC | cut -d' ' -f2)
1477 [ -n "$LOCDESC" ] && SHORT_DESC="$LOCDESC"
1478 fi
1479 done
1480 emsg "$(
1482 _ 'Package : %s' "$PACKAGE"
1483 _ 'Version : %s' "$VERSION$EXTRAVERSION"
1484 _ 'Category : %s' "$(_ $CATEGORY)"
1485 _ 'Short desc : %s' "$SHORT_DESC"
1486 _ 'Maintainer : %s' "$MAINTAINER"
1487 _ 'License : %s' "$LICENSE"
1488 _ 'Depends : %s' "$DEPENDS"
1489 _ 'Suggested : %s' "$SUGGESTED"
1490 _ 'Build deps : %s' "$BUILD_DEPENDS"
1491 _ 'Wanted src : %s' "$WANTED"
1492 _ 'Web site : %s' "$WEB_SITE"
1493 _ 'Tags : %s' "$TAGS"
1494 } | sed '/: $/d; s|^\([^:]*\):|<b>\1:</b>|')"
1495 im && footer
1496 ;;
1499 desc)
1500 # Display package description
1501 if [ -n "$(grep -e "^$PACKAGE " $PKGS_DB/installed.info)" ]; then
1502 im && title 'Description of package "%s"' $PACKAGE
1503 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
1504 cat $INSTALLED/$PACKAGE/description.txt
1505 else
1506 im && awk -F$'\t' '{if ($1 == "'$PACKAGE'") print $4}' $PKGS_DB/installed.info
1507 fi
1508 im && footer
1509 else
1510 im && _ 'Package "%s" is not installed.' "$PACKAGE"
1511 fi
1512 ;;
1515 activity|log|-a)
1516 # Show activity log
1517 [ "$nb" ] || nb=18
1518 title 'TazPKG Activity'
1519 IFS=" "
1520 tail -n ${nb} ${LOG} | \
1521 while read date hour none action none pkg vers none; do
1522 case $action in
1523 Installed)
1524 action=$(colorize 32 $action) ;;
1525 Removed)
1526 action=$(colorize 31 $action) ;;
1527 *)
1528 action=$(boldify $action) ;;
1529 esac
1530 echo "$date $hour : $action $pkg $vers"
1531 done
1532 unset IFS
1533 footer ;;
1536 search|-s)
1537 # Search for a package by pattern or name.
1538 PATTERN="$2"
1539 if [ -z "$PATTERN" ]; then
1540 newline
1541 _ 'Please specify a pattern or package name to search for.'
1542 echo "$(_ 'Example:') 'tazpkg search paint'"
1543 newline
1544 exit 0
1545 fi
1546 title 'Search result for "%s"' $PATTERN
1547 # Default is to search in installed pkgs and the raw list.
1548 case "$3" in
1549 -i|--installed)
1550 search_in_installed_packages ;;
1551 -l|--list)
1552 search_in_packages_list ;;
1553 -m|--mirror)
1554 search_in_packages_txt ;;
1555 *)
1556 search_in_installed_packages
1557 search_in_packages_list ;;
1558 esac ;;
1561 search-file|-sf)
1562 # Search for a file by pattern or name in all files.list.
1563 if [ -z "$2" ]; then
1564 newline
1565 _ 'Please specify a pattern or file name to search for.'
1566 echo "$(_ 'Example:') 'tazpkg search-file libnss'"
1567 newline
1568 exit 0
1569 fi
1570 title 'Search result for file "%s"' $2
1572 TMPLIST=$(mktemp)
1573 if [ "$3" == "--mirror" ]; then
1575 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1576 [ -f $i ] || continue
1577 lzcat $i | awk -F: -vP="$(gettext 'Package %s:')" -vT=$TMPLIST '
1578 BEGIN { last = "" }
1579 $2 ~ /'$2'/ {
1580 if (last != $1) {
1581 last = $1;
1582 PP = P;
1583 sub(/%s/, $1, PP);
1584 printf("\n\e[1;33m%s\e[0;39m\n", PP);
1586 gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $2);
1587 print $2;
1588 printf "%s" 1 >> T;
1589 }'
1590 done
1592 else
1594 # Check all pkg files.list in search match which specify the package
1595 # name and the full path to the file(s).
1596 for pkg in $INSTALLED/*; do
1597 if grep -qs "$2" $pkg/files.list; then
1598 . $pkg/receipt
1599 newline
1600 emsg "<c 33>$(_ 'Package %s:' $PACKAGE)</c>"
1601 awk -vT=$TMPLIST '
1602 /'$2'/ {
1603 gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $0);
1604 print " "$0;
1605 printf "%s" 1 >> T;
1607 ' $pkg/files.list
1608 fi
1609 done
1611 fi
1613 match=$(wc -m < $TMPLIST)
1614 rm $TMPLIST
1616 footer "$(emsg "$(_p \
1617 '%s file' '%s files' $match \
1618 "<c 32>$match</c>")")"
1619 ;;
1622 search-pkgname)
1623 # Search for a package name
1624 if [ -z "$2" ]; then
1625 newline
1626 _ 'Please specify a pattern or file name to search for.'
1627 echo "$(_ 'Example:') 'tazpkg search-pkgname libnss'"
1628 newline
1629 exit 0
1630 fi
1631 title 'Search result for package "%s"' $2
1633 # Search for a file on mirror and output only the package name
1634 TMPLIST=$(mktemp)
1635 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1636 [ -f $i ] || continue
1637 lzcat $i | awk -F: -vT=$TMPLIST '
1638 BEGIN { P = "" }
1639 $2 ~ /'$2'/ {
1640 if ($1 != P) {
1641 print $1;
1642 printf "%s" 1 >> T;
1643 P = $1
1645 }'
1646 done
1647 match=$(wc -m < $TMPLIST)
1648 rm $TMPLIST
1650 footer "$(emsg "$(_p \
1651 '%s package' '%s packages' $match \
1652 "<c 32>$match</c>")")"
1653 ;;
1656 install|-i)
1657 # Install .tazpkg packages.
1658 check_root $@
1659 check_for_package_on_cmdline
1660 check_for_package_file
1661 check_for_installed_info
1663 if [ -n "$root" ]; then
1664 ROOT="$root";
1665 check_base_dir "$root"
1666 fi
1667 [ "$list" ] && INSTALL_LIST="$list"
1668 if [ "$rootconfig" ]; then
1669 if [ "$root" ]; then
1670 CACHE_DIR=$root/$CACHE_DIR
1671 SAVE_CACHE_DIR=$CACHE_DIR
1672 PKGS_DB=$root/$PKGS_DB
1673 else
1674 echo "rootconfig needs --root= option used." >&2
1675 exit 1
1676 fi
1677 fi
1679 # Get repositories priority list.
1680 look_for_priority
1682 # Check if forced install.
1683 if [ -z "$forced" ]; then
1684 check_for_installed_package $ROOT
1685 fi
1686 install_package $ROOT
1687 update_desktop_database $ROOT
1688 update_mime_database $ROOT
1689 update_icon_database $ROOT
1690 compile_glib_schemas $ROOT
1691 ;;
1694 install-list|get-install-list)
1695 # Install a set of packages from a list.
1696 check_root $@
1697 if [ -z "$2" ]; then
1698 newline
1699 longline "$(_ \
1700 "Please change directory (cd) to the packages repository and specify the \
1701 list of packages to install.")"
1702 echo "$(_ 'Example:') $(emsg '<b>tazpkg install-list</b> <c 33>packages.list</c>')"
1703 exit 0
1704 fi
1706 # Check if the packages list exist.
1707 if [ ! -f "$2" ]; then
1708 _ 'Unable to find list "%s"' "$2"
1709 exit 0
1710 fi
1712 LIST=$(cat $2)
1714 # Remember processed list
1715 export INSTALL_LIST="$2"
1717 # Set $COMMAND and install all packages.
1718 COMMAND=${1%-list}
1720 touch $2-processed
1722 # Upgrade tazpkg first. It may handle new features/formats...
1723 # then upgrade essential packages early
1724 for pkg in busybox-pam busybox gcc-lib-base glibc-base \
1725 slitaz-base-files tazpkg ; do
1726 pkg=$(egrep $pkg-[0-9] $INSTALL_LIST)
1727 [ -z "$pkg" ] && continue
1728 _ 'Adding implicit depends "%s"...' $pkg
1729 LIST="$pkg
1730 $LIST"
1731 done
1733 for pkg in $LIST; do
1734 grep -qs ^$pkg$ $2-processed && continue
1735 [ -d "$root/var/lib/tazpkg/installed" ] &&
1736 tazpkg $COMMAND $pkg --list="$2" "$3" "$4" "$5"
1737 done
1738 rm -f $2-processed ;;
1741 add-flavor)
1742 # Install a set of packages from a flavor.
1743 install_flavor $2 ;;
1746 install-flavor)
1747 # Install a set of packages from a flavor and purge other ones.
1748 install_flavor $2 --purge ;;
1751 set-release)
1752 # Change current release and upgrade packages.
1753 RELEASE=$2
1754 if [ -z "$RELEASE" ]; then
1755 newline
1756 _ 'Please specify the release you want on the command line.'
1757 echo "$(_ 'Example:') tazpkg set-release cooking"
1758 newline
1759 exit 0
1760 fi
1761 rm $PKGS_DB/mirror
1762 echo "$RELEASE" > /etc/slitaz-release
1763 tazpkg recharge && tazpkg upgrade
1765 # Install missing depends
1766 cd $INSTALLED
1767 for i in * ; do
1768 DEPENDS=""
1769 . $i/receipt
1770 for j in $DEPENDS ; do
1771 [ -d $j ] || tazpkg get-install $j
1772 done
1773 done ;;
1776 remove|-r)
1777 # Remove packages.
1778 check_root $@
1779 check_for_package_on_cmdline
1780 check_for_installed_info
1782 [ -n "$root" ] && ROOT="$root"
1783 if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then
1784 newline
1785 _ 'Package "%s" is not installed.' $PACKAGE
1786 exit 0
1787 else
1788 ALTERED=""
1789 THE_PACKAGE=$PACKAGE # altered by receipt
1790 for i in $(cd $ROOT$INSTALLED ; ls); do
1791 [ -f $ROOT$INSTALLED/$i/receipt ] || continue
1792 DEPENDS=""
1793 . $ROOT$INSTALLED/$i/receipt
1794 case " $(echo $DEPENDS) " in
1795 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
1796 esac
1797 done
1798 EXTRAVERSION=""
1799 . $ROOT$INSTALLED/$THE_PACKAGE/receipt
1800 fi
1801 newline
1802 if [ -n "$ALTERED" ]; then
1803 _ 'The following packages depend on package "%s":' $PACKAGE
1804 for i in $ALTERED; do
1805 echo " $i"
1806 done
1807 fi
1808 REFRESH=$(cd $ROOT$INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1809 if [ -n "$REFRESH" ]; then
1810 _ 'The following packages have been modified by package "%s":' $PACKAGE
1811 for i in $REFRESH; do
1812 echo " ${i%/modifiers}"
1813 done
1814 fi
1815 if [ "$auto" ]; then
1816 answer=0
1817 else
1818 confirm "$(_ 'Remove package "%s" (%s)? (y/N)' $PACKAGE $VERSION$EXTRAVERSION)"
1819 answer=$?
1820 fi
1821 if [ $answer = 0 ]; then
1822 title 'Removing package "%s"' $PACKAGE
1823 # Pre remove commands.
1824 if grep -q ^pre_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1825 pre_remove $ROOT
1826 fi
1827 action "Removing all files installed..."
1828 if [ -f $ROOT$INSTALLED/$PACKAGE/modifiers ]; then
1829 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1830 for mod in $(cat $ROOT$INSTALLED/$PACKAGE/modifiers); do
1831 [ -f $ROOT$INSTALLED/$mod/files.list ] && [ $(grep "^$(echo $file | grepesc)$" $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && continue 2
1832 done
1833 remove_with_path $ROOT$file
1834 done
1835 else
1836 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1837 remove_with_path $ROOT$file
1838 done
1839 fi
1840 status
1841 if grep -q ^post_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1842 post_remove $ROOT
1843 fi
1845 # Remove package receipt.
1846 action "Removing package receipt..."
1847 rm -rf $ROOT$INSTALLED/$PACKAGE
1848 status
1850 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION$/d" \
1851 $PKGS_DB/installed.$SUM 2> /dev/null
1853 # Update installed.info
1854 sed -i "/^$PACKAGE /d" $PKGS_DB/installed.info
1856 # Log this activity
1857 log_pkg Removed
1859 if [ "$ALTERED" ]; then
1860 if [ "$auto" ]; then
1861 answer=0
1862 else
1863 confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' $PACKAGE)"
1864 answer=$?
1865 fi
1866 if [ $answer = 0 ]; then
1867 for i in $ALTERED; do
1868 if [ -d "$ROOT$INSTALLED/$i" ]; then
1869 tazpkg remove $i $ROOTOPTS
1870 fi
1871 done
1872 fi
1873 fi
1874 if [ "$REFRESH" ]; then
1875 if [ "$auto" ]; then
1876 answer=0
1877 else
1878 confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' $PACKAGE)"
1879 answer=$?
1880 fi
1881 if [ $answer = 0 ]; then
1882 for i in $REFRESH; do
1883 if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then
1884 _ 'Check %s for reinstallation' "$INSTALLED/$i"
1885 continue
1886 fi
1887 rm -r $ROOT$INSTALLED/$i
1888 tazpkg get-install ${i%/modifiers} $ROOTOPTS --forced
1889 done
1890 fi
1891 fi
1892 else
1893 newline
1894 _ 'Uninstallation of package "%s" cancelled.' $PACKAGE
1895 fi
1896 newline ;;
1899 extract|-e)
1900 # Extract .tazpkg cpio archive into a directory.
1901 check_for_package_on_cmdline
1902 check_for_package_file
1903 title 'Extracting package "%s"' $PACKAGE
1905 # If no directory destination is found on the cmdline
1906 # we create one in the current dir using the package name.
1907 if [ -n "$TARGET_DIR" ]; then
1908 DESTDIR=$TARGET_DIR/$PACKAGE
1909 else
1910 DESTDIR=$PACKAGE
1911 fi
1912 mkdir -p $DESTDIR
1914 action "Copying original package..."
1915 cp $PACKAGE_FILE $DESTDIR
1916 status
1918 cd $DESTDIR
1919 extract_package
1920 [ -e "receipt" ] && \
1921 footer "$(_ 'Package "%s" is extracted to "%s"') $PACKAGE $DESTDIR"
1922 ;;
1925 recompress)
1926 # Recompress .tazpkg cpio archive with lzma.
1927 check_for_package_on_cmdline
1928 check_for_package_file
1929 title 'Recompressing package "%s"' $PACKAGE
1930 mkdir -p $TMP_DIR
1932 action "Copying original package..."
1933 cp $PACKAGE_FILE $TMP_DIR
1934 status
1936 cd $TMP_DIR
1937 extract_package
1939 action "Recompressing the FS..."
1940 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1941 rm -rf fs
1942 status
1944 action "Creating new package..."
1945 find . -print | cpio -o -H newc --quiet > \
1946 $TOP_DIR/$(basename $PACKAGE_FILE).$$ && mv -f \
1947 $TOP_DIR/$(basename $PACKAGE_FILE).$$ \
1948 $TOP_DIR/$(basename $PACKAGE_FILE)
1949 status
1951 cd $TOP_DIR
1952 rm -rf $TMP_DIR
1953 separator; newline ;;
1956 list-config)
1957 # List configuration files installed.
1958 if [ -n "$box" ]; then
1959 mkdir -p $TMP_DIR; cd $TMP_DIR
1960 FILES="$INSTALLED/*/volatile.cpio.gz"
1961 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
1962 for i in $FILES; do
1963 zcat $i | cpio -idm --quiet > /dev/null
1964 find * -type f 2>/dev/null | while read file; do
1965 if [ ! -e /$file ]; then
1966 echo -n "----------|----|----|$(_n 'File lost')"
1967 else
1968 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
1969 cmp $file /$file > /dev/null 2>&1 || \
1970 echo -n "$(stat -c "%.16y" /$file)"
1971 fi
1972 echo "|/$file"
1973 done
1974 rm -rf *
1975 done
1976 cd $TOP_DIR
1977 rm -rf $TMP_DIR
1978 else
1979 im && title 'Configuration files'
1980 for i in $INSTALLED/*/volatile.cpio.gz; do
1981 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
1982 [ -f "$i" ] || continue
1983 zcat $i | cpio -t --quiet
1984 done | sed 's|^|/|' | sort
1985 im && footer
1986 fi ;;
1989 repack-config)
1990 # Create SliTaz package archive from configuration files.
1991 mkdir -p $TMP_DIR; cd $TMP_DIR
1992 CONFIG_VERSION=1.0
1993 mkdir config-$CONFIG_VERSION
1994 cd config-$CONFIG_VERSION
1995 for i in $INSTALLED/*/volatile.cpio.gz; do
1996 zcat $i | cpio -t --quiet
1997 done > files.list
1998 mkdir fs
1999 cd fs
2000 ( cd / ; cpio -o -H newc --quiet ) < ../files.list | cpio -idm --quiet > /dev/null
2001 mkdir -p etc/tazlito
2002 for i in $INSTALLED/*/receipt; do
2003 EXTRAVERSION=""
2004 . $i
2005 echo "$PACKAGE-$VERSION$EXTRAVERSION"
2006 done > etc/tazlito/config-packages.list
2007 cd ..
2008 echo "etc/tazlito/config-packages.list" >> files.list
2009 pkg_date=$(date +"%x %X")
2010 cat > receipt <<EOT
2011 # SliTaz package receipt.
2013 PACKAGE="config"
2014 VERSION="$CONFIG_VERSION"
2015 CATEGORY="base-system"
2016 SHORT_DESC="$(_n 'User configuration backup on date %s' $pkg_date)"
2017 DEPENDS="$(ls $INSTALLED)"
2018 EOT
2019 cd ..
2020 tazpkg pack config-$CONFIG_VERSION
2021 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
2022 cd $TOP_DIR
2023 rm -rf $TMP_DIR
2024 ;;
2027 repack)
2028 # Create SliTaz package archive from an installed package.
2029 check_for_package_on_cmdline
2030 check_for_receipt
2031 EXTRAVERSION=""
2032 . $INSTALLED/$PACKAGE/receipt
2033 title 'Repacking "%s"' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
2035 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
2036 _ "Can't repack package \"%s\"" $PACKAGE
2037 exit 1
2038 fi
2040 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
2041 _ "Can't repack, \"%s\" files have been modified by:" $PACKAGE
2042 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
2043 echo " $i"
2044 done
2045 exit 1
2046 fi
2048 MISSING=""
2049 while read i; do
2050 [ -e "$i" ] && continue
2051 [ -L "$i" ] || MISSING="$MISSING\n $i"
2052 done < $INSTALLED/$PACKAGE/files.list
2053 if [ -n "$MISSING" ]; then
2054 _n "Can't repack, the following files are lost:"
2055 echo -e "$MISSING"
2056 exit 1
2057 fi
2059 mkdir -p $TMP_DIR; cd $TMP_DIR
2060 FILES="fs.cpio.lzma\n"
2061 for i in $(ls $INSTALLED/$PACKAGE); do
2062 case $i in
2063 volatile.cpio.gz|modifiers) ;;
2064 *) cp $INSTALLED/$PACKAGE/$i .; FILES="$FILES$i\n" ;;
2065 esac
2066 done
2068 ln -s / rootfs
2069 mkdir tmp
2070 sed 's/^/rootfs/' < files.list | cpio -o -H newc --quiet | \
2071 { cd tmp ; cpio -idm --quiet >/dev/null; cd ..; }
2072 mv tmp/rootfs fs
2074 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
2075 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
2076 { cd fs; cpio -idm --quiet; cd ..; }
2077 fi
2079 if fgrep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
2080 . $INSTALLED/$PACKAGE/receipt
2081 repack_cleanup fs
2082 fi
2084 if [ -f $INSTALLED/$PACKAGE/$CHECKSUM ]; then
2085 sed 's, , fs,' < $INSTALLED/$PACKAGE/$CHECKSUM | \
2086 $CHECKSUM -s -c || {
2087 _ "Can't repack, %s error." $CHECKSUM
2088 cd $TOP_DIR
2089 rm -rf $TMP_DIR
2090 exit 1
2092 fi
2094 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2095 echo -e "$FILES" | cpio -o -H newc --quiet > \
2096 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
2097 cd $TOP_DIR
2098 \rm -R $TMP_DIR
2099 _ 'Package "%s" repacked successfully.' $PACKAGE
2100 _ 'Size: %s' "$(du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg)"
2101 newline ;;
2104 pack)
2105 # Create SliTaz package archive using cpio and lzma.
2106 # TODO: Cook also pack packages, we should share code in libpkg.sh
2107 check_for_package_on_cmdline
2108 cd $PACKAGE
2109 if [ ! -f "receipt" ]; then
2110 _ 'Receipt is missing. Please read the documentation.'
2111 exit 0
2112 fi
2114 title 'Packing package "%s"' $PACKAGE
2115 # Create files.list with redirecting find outpout.
2117 action "Creating the list of files..."
2118 cd fs
2119 find . -type f -print > ../files.list
2120 find . -type l -print >> ../files.list
2121 cd .. && sed -i s/'^.'/''/ files.list
2122 status
2124 action 'Creating %s of files...' $CHECKSUM
2125 while read file; do
2126 [ -L "fs$file" ] && continue
2127 [ -f "fs$file" ] || continue
2128 case "$file" in
2129 /lib/modules/*/modules.*|*.pyc) continue;;
2130 esac
2131 $CHECKSUM "fs$file" | sed 's/ fs/ /'
2132 done < files.list > $CHECKSUM
2133 status
2135 UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
2136 description.txt 2> /dev/null | awk \
2137 '{ sz=$1 } END { print sz }')
2138 # Build cpio archives.
2140 action "Compressing the FS..."
2141 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2142 rm -rf fs
2143 status
2145 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
2146 $CHECKSUM description.txt 2> /dev/null | awk \
2147 '{ sz=$1 } END { print sz }')
2149 action "Updating receipt sizes..."
2150 sed -i s/^PACKED_SIZE.*$// receipt
2151 sed -i s/^UNPACKED_SIZE.*$// receipt
2152 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
2153 status
2155 action "Creating full cpio archive..."
2156 find . -print | cpio -o -H newc --quiet > ../$PACKAGE.tazpkg
2157 status
2159 action "Restoring original package tree..."
2160 unlzma -c fs.cpio.lzma | cpio -idm --quiet
2161 status
2163 rm fs.cpio.lzma && cd ..
2164 footer "$(_ 'Package "%s" compressed successfully.' $PACKAGE)"
2165 _ 'Size: %s' "$(ls -lh $PACKAGE.tazpkg | awk '{print $5}')"
2166 ;;
2169 recharge)
2170 # Recharge packages.list from a mirror.
2172 # WARNING: The 'mirrors' file has all SliTaz mirrors but 'mirror'
2173 # must have only the chosen main mirror.
2175 check_root $@
2177 ARG=$2
2178 if [ "$root" ]; then
2179 PKGS_DB=$root$PKGS_DB
2180 [ "${2#--}" != "$2" ] && ARG=$3
2181 fi
2182 if [ "$ARG" = main ]; then
2183 repository_to_recharge=$PKGS_DB
2184 elif [ "$ARG" ]; then
2185 if [ -d "$PKGS_DB/undigest/$ARG" ]; then
2186 repository_to_recharge=$PKGS_DB/undigest/$ARG
2187 else
2188 repo="$PKGS_DB/undigest/$ARG"
2189 _ "Repository \"%s\" doesn't exist." $repo >&2
2190 exit 1
2191 fi
2192 else
2193 repository_to_recharge="$PKGS_DB $PKGS_DB/undigest/*"
2194 fi
2195 for path in $repository_to_recharge; do
2196 [ -f $path/mirror ] || continue
2197 cd $path
2199 # Quietly check if recharging is needed.
2200 [ -f ID ] && mv ID ID.bak
2201 download_from "$(cat mirror)" ID >/dev/null 2>/dev/null
2202 if [ -f ID ] && fgrep -q $(cat ID.bak 2>/dev/null || echo "null") ID; then
2203 if [ "$path" = "$PKGS_DB" ]; then
2204 repository_name=Main
2205 else
2206 base_path="$(basename $path)"
2207 repository_name="$(_n 'Undigest %s' $base_path)"
2208 fi
2209 _ 'Repository "%s" is up to date.' "$repository_name"
2210 rm ID.bak
2211 continue
2212 fi
2214 # Don't let ID be a symlink when using local repository.
2215 if [ -f ID ]; then
2216 mv -f ID ID.bak
2217 cat ID.bak > ID
2218 rm ID.bak
2219 fi
2221 newline
2222 if [ "$path" != "$PKGS_DB" ]; then
2223 base_path="$(basename $path)"
2224 _ 'Recharging undigest %s:' $base_path
2225 fi
2227 if [ -f "packages.list" ]; then
2228 action "Creating backup of the last packages list..."
2229 for i in packages.desc packages.$SUM packages.txt \
2230 packages.list packages.equiv files.list.lzma \
2231 extra.list mirrors packages.info
2232 do
2233 mv -f $i $i.bak 2>/dev/null
2234 done
2235 status
2236 fi
2238 for i in desc $SUM txt list equiv; do
2239 download_from "$(cat mirror)" packages.$i
2240 done
2241 download_from "$(cat mirror)" files.list.lzma
2242 download_from "$(cat mirror)" extra.list
2243 download_from "$(sed 's|packages/.*||' mirror)" mirrors
2245 # packages.info
2246 download_from "$(cat mirror)" packages.info.lzma
2247 lzma d packages.info.lzma packages.info
2248 rm packages.info.lzma
2250 if [ -f "packages.list.bak" ]; then
2251 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
2252 [ -f "extra.list.bak" ] &&
2253 diff -u extra.list.bak extra.list | grep ^+[a-z] >> packages.diff
2254 sed -i s/+// packages.diff
2255 title 'Mirrored packages diff'
2256 cat packages.diff
2257 new_pkgs=$(wc -l < packages.diff)
2258 footer "$(emsg "$(_p \
2259 '%s new package on the mirror.' \
2260 '%s new packages on the mirror.' $new_pkgs \
2261 "<c 32>$new_pkgs</c>")")"
2262 else
2263 footer "$(longline "$(_ "Last %s is ready to use. Note that \
2264 next time you recharge the list, a list of differences will be displayed to \
2265 show new and upgradeable packages." packages.list)")"
2266 fi
2267 done ;;
2270 help-up)
2271 # Options available for the command: up
2272 newline; usage_up; newline
2273 exit 1 ;;
2276 up|upgrade)
2277 check_root
2279 # This is the new way to upgrade packages making 'upgrade' and
2280 # upgradeable out-of-date. This new way is much, much more faster!
2281 # Look into installed packages and get data from receipt, it is fast
2282 # and easy to handle vars after using only md5sum to compare packages
2284 for opt in $@; do
2285 case "$opt" in
2286 --recharge|-r) tazpkg recharge ;;
2287 --install|-i) install="y" ;;
2288 --check|-c) install="n" ;;
2289 esac
2290 done
2291 time=$(date +%s)
2293 look_for_priority
2294 for repo in $priority; do
2295 pkg_list=$repo/packages.list
2296 mtime=$(find $pkg_list -mtime +7)
2297 if [ "$mtime" ]; then
2298 if [ "$repo" == "$PKGS_DB" ]; then
2299 repo_name=main
2300 else
2301 repo_name="${repo##*/}"
2302 fi
2303 _ 'List "%s" is older than one week... Recharging.' $pkg_list
2304 tazpkg recharge $repo_name
2305 fi
2306 done
2308 emsg "<n>$(_ 'Package')<i 28> $(_ 'Version')<i 48> $(_ 'Status')<->"
2310 cd $INSTALLED
2311 echo -n > $UP_LIST
2312 blocked_count=0
2313 installed_sum=$PKGS_DB/installed.$SUM
2315 for pkg in *; do
2316 [ ! -d $pkg ] && continue
2317 unset VERSION EXTRAVERSION
2318 . $pkg/receipt
2319 md5=$(fgrep " $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" \
2320 $installed_sum | awk '{print $1}')
2321 for repo in $priority; do
2322 pkg_desc=$repo/packages.desc
2323 pkg_list=$repo/packages.list
2324 pkg_sum=$repo/packages.$SUM
2326 if ! fgrep -q "$md5 $PACKAGE-" $pkg_sum; then
2327 # Jump to next repository in priority if pkg doesn't exist
2328 # in this one.
2329 grep -q ^$PACKAGE- $pkg_list || continue
2331 emsg -n "$PACKAGE<i 28> $VERSION"
2333 # Skip pkgs listed in $PKGS_DB/blocked-packages.list
2334 if $(grep -qs "^$PACKAGE" $BLOCKED); then
2335 blocked_count=$(($blocked_count + 1))
2336 emsg "<i 48><c 31> $(_ 'Blocked')</c>"
2337 break
2338 fi
2340 new=$(grep "^$PACKAGE |" $pkg_desc | awk '{print $3}')
2342 if [ "$VERSION" == "$new" ]; then
2343 emsg "<i 48><c 34> $(_ 'New build')</c>"
2344 else
2345 emsg "<i 48><c 32> $(_ 'New version %s' $new)</c>"
2346 fi
2347 echo "$PACKAGE" >> $UP_LIST
2348 break
2349 fi
2350 done
2351 done
2352 sed -i /^$/d $UP_LIST
2353 upnb=$(wc -l < $UP_LIST)
2354 pkgs=$(ls | wc -l)
2355 time=$(($(date +%s) - $time))
2356 if [ "$upnb" == 0 ]; then
2357 install="n"
2358 _ 'System is up-to-date...'
2359 fi
2361 footer "$(emsg "$(_p \
2362 '%s installed package scanned in %ds' \
2363 '%s installed packages scanned in %ds' $pkgs \
2364 "<c 32>$pkgs</c>" $time)")"
2366 if [ "$upnb" != 0 ]; then
2367 blocked="$(_p \
2368 '%s blocked' \
2369 '%s blocked' $blocked_count \
2370 $blocked_count)"
2372 boldify "$(_p \
2373 'You have %s available upgrade (%s)' \
2374 'You have %s available upgrades (%s)' $upnb \
2375 $upnb "$blocked")"
2376 newline
2377 fi
2378 # Pkgs to upgrade ? Skip, let install them all or ask user
2379 [ "$install" == "n" ] && exit 0
2380 if [ "$upnb" -gt 0 ]; then
2381 if [ "$install" == "y" ]; then
2382 continue
2383 else
2384 confirm "$(_ 'Do you wish to install them now? (y/N)')"
2385 answer=$?
2386 fi
2387 case "$answer" in
2388 0)
2389 for pkg in $(cat $UP_LIST); do
2390 echo 'y' | tazpkg get-install $pkg --forced
2391 done
2392 # List is generated each time and must be cleaned so
2393 # tazpkg-notify doesn't find upgrades anymore.
2394 rm $UP_LIST; touch $UP_LIST ;;
2395 *)
2396 _ 'Leaving without any upgrades installed.'
2397 newline
2398 exit 0 ;;
2399 esac
2400 fi
2401 newline ;;
2404 bugs)
2405 # Show known bugs in package(s)
2406 cd $INSTALLED
2407 shift
2408 LIST=$@
2409 [ -n "$LIST" ] || LIST=$(ls)
2410 MSG=$(_n 'No known bugs.')
2411 for PACKAGE in $LIST; do
2412 BUGS=""
2413 EXTRAVERSION=""
2414 . $PACKAGE/receipt
2415 if [ -n "$BUGS" ]; then
2416 MSG=$(_n 'Bug list completed')
2417 newline
2418 _ 'Bugs in package "%s" version %s:' $PACKAGE $VERSION$EXTRAVERSION
2419 cat <<EOT
2420 $BUGS
2421 EOT
2422 fi
2423 done
2424 echo "$MSG" ;;
2427 check)
2428 # Check installed packages set.
2429 check_root $@
2431 # Get repositories priority list.
2432 look_for_priority
2434 cd $INSTALLED
2435 for PACKAGE in $(ls); do
2437 if [ ! -f $PACKAGE/receipt ]; then
2438 _ 'The package "%s" installation has not completed' $PACKAGE
2439 continue
2440 fi
2442 DEPENDS=""
2443 EXTRAVERSION=""
2444 . $PACKAGE/receipt
2445 if [ -s $PACKAGE/modifiers ]; then
2446 _ 'The package "%s" has been modified by:' $PACKAGE-$VERSION$EXTRAVERSION
2447 for i in $(cat $PACKAGE/modifiers); do
2448 echo " $i"
2449 done
2450 fi
2452 MSG="$(_n 'Files lost from package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2453 while read file; do
2454 [ -e "$file" ] && continue
2455 if [ -L "$file" ]; then
2456 MSG="$MSG $(_n 'target of symlink')"
2457 fi
2458 echo -e "$MSG $file"
2459 MSG=""
2460 done < $PACKAGE/files.list
2462 MSG="$(_n 'Missing dependencies for package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2463 for i in $DEPENDS; do
2464 [ -d $i ] && continue
2465 [ -d $(equivalent_pkg $i) ] && continue
2466 echo -e "$MSG $i"
2467 MSG=""
2468 done
2470 MSG="$(_n 'Dependencies loop between "%s" and:' $PACKAGE)\n"
2471 ALL_DEPS=""
2472 check_for_deps_loop $PACKAGE $DEPENDS
2473 done
2475 _ 'Looking for known bugs...'
2476 tazpkg bugs
2478 if [ "$2" == "--full" ]; then
2479 separator
2481 for file in */$CHECKSUM; do
2482 CONFIG_FILES=""
2483 . $(dirname "$file")/receipt
2484 [ -s "$file" ] || continue
2485 while read md5 f; do
2486 [ -f $f ] || continue
2487 for i in $CONFIG_FILES; do
2488 case "$f" in
2489 $i|$i/*) continue 2;;
2490 esac
2491 done
2492 echo "$md5 $f"
2493 done < "$file" | busybox $CHECKSUM -c - 2> /dev/null | \
2494 grep -v OK$ | sed "s/FAILED$/$CHECKSUM MISMATCH/"
2495 done
2497 FILES=" "
2498 for file in $(cat */files.list); do
2499 [ -d "$file" ] && continue
2500 case "$FILES" in *\ $file\ *) continue;; esac
2501 [ $(grep "^$(echo $file | grepesc)$" */files.list 2> /dev/null | \
2502 wc -l) -gt 1 ] || continue
2503 FILES="$FILES$file "
2504 _ 'The following packages provide file "%s":' $file
2505 grep -l "^$(echo $file | grepesc)$" */files.list | \
2506 while read f; do
2507 pkg=${f%/files.list}
2508 if [ -f $pkg/modifiers ]; then
2509 overriders=$(_n '(overridden by %s)' "$(tr '\n' ' ' | sed 's| $||' < $pkg/modifiers)")
2510 else
2511 overriders=''
2512 fi
2513 echo -n " $pkg $overriders"
2514 newline
2515 done
2516 done
2518 MSG="$(_n 'No package has installed the following files:')\n"
2519 find /etc /bin /sbin /lib /usr /var/www -not -type d 2>/dev/null | \
2520 while read file; do
2521 case "$file" in *\[*) continue;; esac
2522 grep -q "^$(echo $file | grepesc)$" */files.list && continue
2523 echo -e "$MSG $file"
2524 MSG=""
2525 done
2526 fi
2527 _ 'Check completed.'; echo ;;
2530 block)
2531 # Add a pkg name to the list of blocked packages.
2532 check_root $@
2533 check_for_package_on_cmdline
2534 newline
2535 if [ ! -d $INSTALLED/$PACKAGE ]; then
2536 _ 'Package "%s" is not installed.' $PACKAGE; exit
2537 fi
2538 if grep -qs "^$PACKAGE" $BLOCKED; then
2539 _ 'Package "%s" is already blocked.' $PACKAGE
2540 else
2541 echo $PACKAGE >> $BLOCKED
2542 # Log this activity
2543 . $INSTALLED/$PACKAGE/receipt; log_pkg Blocked
2544 _ 'Package "%s" blocked.' $PACKAGE
2545 fi
2546 newline ;;
2549 unblock)
2550 # Remove a pkg name from the list of blocked packages.
2551 check_root $@
2552 check_for_package_on_cmdline
2553 newline
2554 if [ ! -d $INSTALLED/$PACKAGE ]; then
2555 _ 'Package "%s" is not installed.' $PACKAGE; exit
2556 fi
2557 if grep -qs "^$PACKAGE" $BLOCKED; then
2558 sed -i "/^$PACKAGE\$/d" $BLOCKED
2559 # Log this activity
2560 . $INSTALLED/$PACKAGE/receipt; log_pkg Unblocked
2561 _ 'Package "%s" unblocked.' $PACKAGE
2562 else
2563 _ 'Package "%s" is not blocked.' $PACKAGE
2564 fi
2565 newline ;;
2568 chblock)
2569 # Change package's blocked status.
2570 check_root $@
2571 check_for_package_on_cmdline
2572 newline
2573 if [ ! -d $INSTALLED/$PACKAGE ]; then
2574 _ 'Package "%s" is not installed.' $PACKAGE; exit
2575 fi
2576 if grep -qs "^$PACKAGE" $BLOCKED; then
2577 sed -i "/^$PACKAGE\$/d" $BLOCKED
2578 # Log this activity
2579 . $INSTALLED/$PACKAGE/receipt; log_pkg Unblocked
2580 _ 'Package "%s" unblocked.' $PACKAGE
2581 else
2582 echo $PACKAGE >> $BLOCKED
2583 # Log this activity
2584 . $INSTALLED/$PACKAGE/receipt; log_pkg Blocked
2585 _ 'Package "%s" blocked.' $PACKAGE
2586 fi
2587 newline ;;
2590 get)
2591 # Download a package with wget.
2592 check_root $@
2593 check_for_package_on_cmdline
2594 check_for_packages_list
2596 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2597 if [ "$rootconfig" ]; then
2598 if [ "$root" ]; then
2599 CACHE_DIR=$root/$CACHE_DIR
2600 SAVE_CACHE_DIR=$CACHE_DIR
2601 PKGS_DB=$root/$PKGS_DB
2602 else
2603 _ 'rootconfig needs --root= option used.' >&2
2604 exit 1
2605 fi
2606 fi
2608 # Get repositories priority list.
2609 look_for_priority
2611 CURRENT_DIR=$PWD
2612 check_for_package_in_list
2613 cd $CACHE_DIR
2614 if [ -f "$PACKAGE.tazpkg" ]; then
2615 _ 'Package "%s" already in the cache' $PACKAGE
2616 # Check package download was finished
2617 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2618 _ 'Continuing package "%s" download' $PACKAGE
2619 download $PACKAGE.tazpkg
2621 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2622 rm -f $PACKAGE.tazpkg
2623 download $PACKAGE.tazpkg
2624 fi
2625 else
2626 download $PACKAGE.tazpkg
2627 fi
2628 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2629 cp -a $PACKAGE_FILE $CURRENT_DIR ;;
2632 get-install|-gi)
2633 # Download and install a package.
2634 check_root $@
2635 check_for_package_on_cmdline
2636 check_for_packages_list
2638 DO_CHECK=""
2639 [ "$forced" ] && DO_CHECK=no
2640 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2641 [ "$list" ] && INSTALL_LIST="$list"
2642 if [ "$rootconfig" ]; then
2643 if [ "$root" ]; then
2644 CACHE_DIR=$root/$CACHE_DIR
2645 SAVE_CACHE_DIR=$CACHE_DIR
2646 PKGS_DB=$root/$PKGS_DB
2647 else
2648 _ 'rootconfig needs --root= option used.' >&2
2649 exit 1
2650 fi
2651 fi
2653 # Get repositories priority list.
2654 look_for_priority
2656 AUTOEXEC="no"
2657 if ! check_for_package_in_list check; then
2658 CACHE_DIR="${CACHE_DIR%/*}/get"
2659 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
2660 if download_get_script $PACKAGE /tmp/$PACKAGE.$$ ; then
2661 install_package_from_get_script /tmp/$PACKAGE.$$ $ROOT
2662 exit 0
2663 else
2664 PACKAGE=get-$PACKAGE
2665 AUTOEXEC=$PACKAGE
2666 check_for_package_in_list
2667 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
2668 $AUTOEXEC $ROOT
2669 exit 0
2670 fi
2671 fi
2672 fi
2673 # Check if forced install.
2674 if ! [ "$forced" ]; then
2675 check_for_installed_package $ROOT
2676 fi
2677 cd $CACHE_DIR
2678 if [ -f "$PACKAGE.tazpkg" ]; then
2679 _ 'Package "%s" already in the cache' $PACKAGE
2680 # Check package download was finished
2681 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2682 _ 'Continuing package "%s" download' $PACKAGE
2683 download $PACKAGE.tazpkg
2685 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2686 rm -f $PACKAGE.tazpkg
2687 download $PACKAGE.tazpkg
2688 fi
2689 else
2690 newline
2691 download $PACKAGE.tazpkg
2692 fi
2693 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2694 [ "$rootconfig" ] && PKGS_DB=${PKGS_DB#$root}
2695 install_package $ROOT
2696 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
2697 update_desktop_database $ROOT
2698 update_mime_database $ROOT ;;
2701 clean-cache|-cc)
2702 # Remove all downloaded packages.
2703 check_root $@
2704 files=$(find $CACHE_DIR -name *.tazpkg | wc -l)
2705 size=$(du -hs $CACHE_DIR | cut -f1 | sed 's|\.0||'); [ $files == "0" ] && size="0K"
2706 title 'Path: %s' $CACHE_DIR
2707 action "Cleaning cache directory..."
2708 rm -rf $CACHE_DIR/*
2709 status
2711 footer "$(_p \
2712 '%s file removed from cache (%s).' \
2713 '%s files removed from cache (%s).' $files \
2714 "$(colorize 32 "$files")" $size)"
2715 ;;
2718 list-undigest)
2719 # list undigest URLs.
2720 if [ "$2" = "--box" ]; then
2721 for i in $PKGS_DB/undigest/*/mirror; do
2722 [ -f $i ] || continue
2723 echo "$(basename $(dirname $i))|$(cat $i)"
2724 done
2725 else
2726 title 'Current undigest(s)'
2727 for i in $PKGS_DB/undigest/*/mirror; do
2728 if [ ! -f $i ]; then
2729 _ 'No undigest mirror found.'
2730 exit 1
2731 fi
2732 echo "$(basename $(dirname $i)) $(cat $i)"
2733 done
2734 newline
2735 fi ;;
2738 remove-undigest)
2739 # remove undigest URL.
2740 check_root $@
2741 undigest="$2"
2742 if [ -d $PKGS_DB/undigest/$2 ]; then
2743 confirm "$(_ 'Remove "%s" undigest? (y/N)' $undigest)"
2744 if [ $? = 0 ]; then
2745 action 'Removing "%s" undigest...' $undigest
2746 rm -rf $PKGS_DB/undigest/$2
2747 status
2748 rmdir $PKGS_DB/undigest 2> /dev/null
2749 fi
2750 else
2751 _ 'Undigest "%s" not found' $undigest
2752 fi ;;
2755 add-undigest|setup-undigest)
2756 # Add undigest URL.
2757 check_root $@
2758 undigest=$2
2759 [ -d $PKGS_DB/undigest ] || mkdir $PKGS_DB/undigest
2760 if [ -z "$undigest" ]; then
2761 i=1
2762 while [ -d $PKGS_DB/undigest/$i ]; do
2763 i=$(($i+1))
2764 done
2765 undigest=$i
2766 fi
2767 if [ ! -d $PKGS_DB/undigest/$undigest ]; then
2768 _ 'Creating new undigest "%s".' $undigest
2769 mkdir $PKGS_DB/undigest/$undigest
2770 fi
2771 setup_mirror $PKGS_DB/undigest/$undigest $3 ;;
2774 setup-mirror|-sm)
2775 # Change mirror URL.
2776 check_root $@
2777 setup_mirror $PKGS_DB $2 ;;
2780 reconfigure)
2781 # Replay post_install from receipt
2782 check_for_package_on_cmdline
2783 check_root $@
2784 ROOT=""
2785 while [ -n "$3" ]; do
2786 case "$3" in
2787 --root=*)
2788 ROOT="${3#--root=}/" ;;
2789 *)
2790 shift 2
2791 u_opt="$*"
2792 newline >&2
2793 _ 'Unknown option "%s".' $u_opt >&2
2794 exit 1 ;;
2795 esac
2796 shift
2797 done
2798 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2799 check_for_receipt $ROOT
2800 # Check for post_install
2801 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2802 . $ROOT$INSTALLED/$PACKAGE/receipt
2803 post_install $ROOT
2804 # Log this activity
2805 [ -n "$ROOT" ] || log_pkg Reconfigured
2806 else
2807 newline
2808 _ 'Nothing to do for package "%s".' $PACKAGE
2809 fi
2810 else
2811 newline
2812 _ 'Package "%s" is not installed.' $PACKAGE
2813 _ 'Install package with "%s" or "%s"' 'tazpkg install' 'tazpkg get-install'
2814 newline
2815 fi ;;
2818 shell)
2819 # TazPKG SHell
2820 if test $(id -u) = 0 ; then
2821 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2822 else
2823 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2824 fi
2825 if [ ! "$2" = "--noheader" ]; then
2826 clear
2827 title 'TazPKG SHell.'
2828 _ "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
2829 newline
2830 fi
2831 while true; do
2832 echo -en "$PROMPT"; read cmd
2833 case $cmd in
2834 q|quit)
2835 break ;;
2836 shell)
2837 _ 'You are already running a TazPKG SHell.' ;;
2838 su)
2839 su -c 'exec tazpkg shell --noheader' && break ;;
2840 "")
2841 continue ;;
2842 *)
2843 tazpkg $cmd ;;
2844 esac
2845 done ;;
2848 depends)
2849 # Display dependencies tree
2850 cd $INSTALLED
2851 ALL_DEPS=""
2852 if [ -f $2/receipt ]; then
2853 dep_scan $2 ""
2854 fi ;;
2857 rdepends)
2858 # Display reverse dependencies tree
2859 cd $INSTALLED
2860 ALL_DEPS=""
2861 if [ -f $2/receipt ]; then
2862 rdep_scan $2
2863 fi ;;
2866 list-suggested)
2867 for i in $(ls -d $INSTALLED/*); do
2868 . $i/receipt
2869 if [ "$SUGGESTED" ]; then
2870 if [ -z "$all" ]; then
2871 for s in $SUGGESTED; do
2872 [ -d $INSTALLED/$s ] && \
2873 SUGGESTED=$(echo -n $SUGGESTED | sed "s/$s//")
2874 done
2875 fi
2876 cat << EOT
2877 $(boldify $(echo $PACKAGE):) $SUGGESTED
2878 EOT
2879 fi
2880 SUGGESTED=""
2881 done ;;
2884 convert|-c)
2885 # convert misc package format to .tazpkg
2886 check_for_package_file
2887 tazpkg-convert $@
2888 ;;
2891 link)
2892 # link a package from another slitaz installation
2893 PACKAGE=$2
2894 if [ ! -d "$TARGET_DIR" -o \
2895 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
2896 _ 'Usage: tazpkg link package_name slitaz_root'
2897 longline "$(
2898 _n 'Example:'
2899 echo -n ' '
2900 _ '"%s" will use less than 100k in your running system RAM.' \
2901 'tazpkg link openoffice /mnt')"
2902 exit 1
2903 fi
2904 if [ -e "$INSTALLED/$PACKAGE" ]; then
2905 _ 'Package "%s" is already installed.' $PACKAGE
2906 exit 1
2907 fi
2908 ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
2909 DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
2910 MISSING=""
2911 for i in $DEPENDS; do
2912 [ -e $INSTALLED/$i ] && continue
2913 MISSING="$MISSING$i "
2914 _ 'Missing: %s' $i
2915 done
2916 if [ -n "$MISSING" ]; then
2917 newline
2918 confirm "$(_ 'Link all missing dependencies? (y/N)')"
2919 answer=$?
2920 newline
2921 if [ $answer = 0 ]; then
2922 for i in $MISSING; do
2923 tazpkg link $i $TARGET_DIR
2924 done
2925 else
2926 newline
2927 _ 'Leaving dependencies unresolved for package "%s"' $PACKAGE
2928 _ 'The package is installed but probably will not work.'
2929 newline
2930 fi
2931 fi
2932 . $INSTALLED/$PACKAGE/receipt
2933 if grep -q ^pre_install $INSTALLED/$PACKAGE/receipt; then
2934 pre_install
2935 fi
2936 while read path; do
2937 [ -e $path ] && continue
2938 while true; do
2939 dir=$(dirname $path)
2940 [ -e $dir ] && break
2941 path=$dir
2942 done
2943 ln -s $TARGET_DIR$path $dir
2944 done < $INSTALLED/$PACKAGE/files.list
2945 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
2946 post_install
2947 fi ;;
2950 usage|*)
2951 # Print a short help or give usage for an unknown or empty command.
2952 usage ;;
2953 esac
2955 exit 0