tazpkg view tazpkg @ rev 780

tazpkg: don't show translations if not exists: tazpkg -l cat
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Apr 10 11:45:54 2015 +0300 (2015-04-10)
parents c62e153dab37
children 0fc40a0f873f
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'
1379 echo "$PKGS_CATEGORIES" | sed 's|[^a-z-]|\n|g; /^$/d' | \
1380 sed 's|\(.*\)|\1\t\1|' | translate_category | awk -F$'\t' '{
1381 if ($1==$2) print $1; else print $1"\033[15G "$2}'
1383 num=$(echo -n "$PKGS_CATEGORIES" | wc -l)
1384 footer "$(_p \
1385 '%s category' \
1386 '%s categories' $num \
1387 $num)"
1388 exit 0
1389 ;;
1390 '')
1391 # By default list all packages and versions.
1392 title 'List of all installed packages'
1393 TMPLIST=$(mktemp)
1394 awk -F$'\t' '{print $1"\033[35G "$2"\033[53G "$3}' \
1395 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
1397 packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST
1398 footer "$(emsg $(_p \
1399 '%s package installed.' \
1400 '%s packages installed.' $packages \
1401 "<c 32>$packages</c>"))"
1402 ;;
1403 *)
1404 # Check for an asked category.
1405 ASKED_CATEGORY_I18N="$@"
1406 ASKED_CATEGORY=$(reverse_translate_category "$ASKED_CATEGORY_I18N")
1407 title 'Installed packages of category "%s"' $ASKED_CATEGORY_I18N
1408 TMPLIST=$(mktemp)
1409 awk -F$'\t' '
1411 if ($3 == "'$ASKED_CATEGORY'")
1412 print $1"\033[35G "$2
1413 }' \
1414 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
1416 packages=$(wc -l $TMPLIST | awk '{print $1}'); rm $TMPLIST
1417 footer "$(emsg $(_p \
1418 '%s package installed of category "%s".' \
1419 '%s packages installed of category "%s".' $packages \
1420 "<c 32>$packages</c>" "<c 34>$ASKED_CATEGORY_I18N</c>"))"
1421 ;;
1422 esac ;;
1424 list-mirror|-lm)
1425 # List all available packages on the mirror. Option --diff displays
1426 # last mirrored packages diff (see recharge).
1427 check_for_packages_list
1428 case $2 in
1429 --diff)
1430 if [ -f "$PKGS_DB/packages.diff" ]; then
1431 title 'Mirrored packages diff'
1432 cat $PKGS_DB/packages.diff
1433 num=$(wc -l < $PKGS_DB/packages.diff)
1434 footer "$(_p \
1435 '%s new package listed on the mirror.' \
1436 '%s new packages listed on the mirror.' $num \
1437 $num)"
1438 else
1439 newline
1440 _ 'Unable to list anything, no packages.diff found.'
1441 _ 'Recharge your current list to create a first diff.'
1442 newline
1443 fi; exit 0 ;;
1444 --text|--txt|--raw|*)
1445 title 'List of available packages on the mirror'
1446 cat $PKGS_DB/packages.txt ;;
1447 esac
1448 pkgs=$(wc -l < $PKGS_DB/packages.list)
1449 footer "$(emsg "$(_p \
1450 '%s package in the last recharged list.' \
1451 '%s packages in the last recharged list.' $pkgs \
1452 "<c 32>$pkgs</c>")")"
1453 ;;
1456 list-files|-lf)
1457 # List files installed with the package.
1458 check_for_package_on_cmdline
1459 check_for_receipt
1460 title 'Installed files by "%s"' $PACKAGE
1461 sort < $INSTALLED/$PACKAGE/files.list
1462 files=$(wc -l < $INSTALLED/$PACKAGE/files.list)
1463 footer "$(emsg "$(_p \
1464 '%s file' '%s files' $files \
1465 "<c 32>$files</c>")")"
1466 ;;
1469 info)
1470 # Information about package.
1471 check_for_package_on_cmdline
1472 check_for_receipt
1473 EXTRAVERSION=""
1474 . $INSTALLED/$PACKAGE/receipt
1475 im && title 'TazPKG information'
1476 # Display localized short description
1477 for LC in $LANG ${LANG%_*}; do
1478 if [ -e "$PKGS_DB/packages-desc.$LC" ]; then
1479 LOCDESC=$(grep -e "^$PACKAGE " $PKGS_DB/packages-desc.$LC | cut -d' ' -f2)
1480 [ -n "$LOCDESC" ] && SHORT_DESC="$LOCDESC"
1481 fi
1482 done
1483 SIZES=$(echo $PACKED_SIZE/$UNPACKED_SIZE | sed 's|\.0||g' | sed 's|^/$||')
1485 emsg "$(
1487 _ 'Package : %s' "$PACKAGE"
1488 _ 'Version : %s' "$VERSION$EXTRAVERSION"
1489 _ 'Category : %s' "$(_ $CATEGORY)"
1490 _ 'Short desc : %s' "$SHORT_DESC"
1491 _ 'Maintainer : %s' "$MAINTAINER"
1492 _ 'License : %s' "$LICENSE"
1493 _ 'Depends : %s' "$DEPENDS"
1494 _ 'Suggested : %s' "$SUGGESTED"
1495 _ 'Build deps : %s' "$BUILD_DEPENDS"
1496 _ 'Wanted src : %s' "$WANTED"
1497 _ 'Web site : %s' "$WEB_SITE"
1498 _ 'Size : %s' "$SIZES"
1499 _ 'Tags : %s' "$TAGS"
1500 } | sed '/: $/d; s|^\([^:]*\):|<b>\1:</b>|')"
1501 im && footer
1502 ;;
1505 desc)
1506 # Display package description
1507 if [ -n "$(grep -e "^$PACKAGE " $PKGS_DB/installed.info)" ]; then
1508 im && title 'Description of package "%s"' $PACKAGE
1509 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
1510 cat $INSTALLED/$PACKAGE/description.txt
1511 else
1512 im && awk -F$'\t' '{if ($1 == "'$PACKAGE'") print $4}' $PKGS_DB/installed.info
1513 fi
1514 im && footer
1515 else
1516 im && _ 'Package "%s" is not installed.' "$PACKAGE"
1517 fi
1518 ;;
1521 activity|log|-a)
1522 # Show activity log
1523 [ "$nb" ] || nb=18
1524 title 'TazPKG Activity'
1525 IFS=" "
1526 tail -n ${nb} ${LOG} | \
1527 while read date hour none action none pkg vers none; do
1528 case $action in
1529 Installed)
1530 action=$(colorize 32 $action) ;;
1531 Removed)
1532 action=$(colorize 31 $action) ;;
1533 *)
1534 action=$(boldify $action) ;;
1535 esac
1536 echo "$date $hour : $action $pkg $vers"
1537 done
1538 unset IFS
1539 footer ;;
1542 search|-s)
1543 # Search for a package by pattern or name.
1544 PATTERN="$2"
1545 if [ -z "$PATTERN" ]; then
1546 newline
1547 _ 'Please specify a pattern or package name to search for.'
1548 echo "$(_ 'Example:') 'tazpkg search paint'"
1549 newline
1550 exit 0
1551 fi
1552 title 'Search result for "%s"' $PATTERN
1553 # Default is to search in installed pkgs and the raw list.
1554 case "$3" in
1555 -i|--installed)
1556 search_in_installed_packages ;;
1557 -l|--list)
1558 search_in_packages_list ;;
1559 -m|--mirror)
1560 search_in_packages_txt ;;
1561 *)
1562 search_in_installed_packages
1563 search_in_packages_list ;;
1564 esac ;;
1567 search-file|-sf)
1568 # Search for a file by pattern or name in all files.list.
1569 if [ -z "$2" ]; then
1570 newline
1571 _ 'Please specify a pattern or file name to search for.'
1572 echo "$(_ 'Example:') 'tazpkg search-file libnss'"
1573 newline
1574 exit 0
1575 fi
1576 title 'Search result for file "%s"' $2
1578 TMPLIST=$(mktemp)
1579 if [ "$3" == "--mirror" ]; then
1581 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1582 [ -f $i ] || continue
1583 lzcat $i | awk -F: -vP="$(gettext 'Package %s:')" -vT=$TMPLIST '
1584 BEGIN { last = "" }
1585 $2 ~ /'$2'/ {
1586 if (last != $1) {
1587 last = $1;
1588 PP = P;
1589 sub(/%s/, $1, PP);
1590 printf("\n\e[1;33m%s\e[0;39m\n", PP);
1592 gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $2);
1593 print $2;
1594 printf "%s" 1 >> T;
1595 }'
1596 done
1598 else
1600 # Check all pkg files.list in search match which specify the package
1601 # name and the full path to the file(s).
1602 for pkg in $INSTALLED/*; do
1603 if grep -qs "$2" $pkg/files.list; then
1604 . $pkg/receipt
1605 newline
1606 emsg "<c 33>$(_ 'Package %s:' $PACKAGE)</c>"
1607 awk -vT=$TMPLIST '
1608 /'$2'/ {
1609 gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $0);
1610 print " "$0;
1611 printf "%s" 1 >> T;
1613 ' $pkg/files.list
1614 fi
1615 done
1617 fi
1619 match=$(wc -m < $TMPLIST)
1620 rm $TMPLIST
1622 footer "$(emsg "$(_p \
1623 '%s file' '%s files' $match \
1624 "<c 32>$match</c>")")"
1625 ;;
1628 search-pkgname)
1629 # Search for a package name
1630 if [ -z "$2" ]; then
1631 newline
1632 _ 'Please specify a pattern or file name to search for.'
1633 echo "$(_ 'Example:') 'tazpkg search-pkgname libnss'"
1634 newline
1635 exit 0
1636 fi
1637 title 'Search result for package "%s"' $2
1639 # Search for a file on mirror and output only the package name
1640 TMPLIST=$(mktemp)
1641 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1642 [ -f $i ] || continue
1643 lzcat $i | awk -F: -vT=$TMPLIST '
1644 BEGIN { P = "" }
1645 $2 ~ /'$2'/ {
1646 if ($1 != P) {
1647 print $1;
1648 printf "%s" 1 >> T;
1649 P = $1
1651 }'
1652 done
1653 match=$(wc -m < $TMPLIST)
1654 rm $TMPLIST
1656 footer "$(emsg "$(_p \
1657 '%s package' '%s packages' $match \
1658 "<c 32>$match</c>")")"
1659 ;;
1662 install|-i)
1663 # Install .tazpkg packages.
1664 check_root $@
1665 check_for_package_on_cmdline
1666 check_for_package_file
1667 check_for_installed_info
1669 if [ -n "$root" ]; then
1670 ROOT="$root";
1671 check_base_dir "$root"
1672 fi
1673 [ "$list" ] && INSTALL_LIST="$list"
1674 if [ "$rootconfig" ]; then
1675 if [ "$root" ]; then
1676 CACHE_DIR=$root/$CACHE_DIR
1677 SAVE_CACHE_DIR=$CACHE_DIR
1678 PKGS_DB=$root/$PKGS_DB
1679 else
1680 echo "rootconfig needs --root= option used." >&2
1681 exit 1
1682 fi
1683 fi
1685 # Get repositories priority list.
1686 look_for_priority
1688 # Check if forced install.
1689 if [ -z "$forced" ]; then
1690 check_for_installed_package $ROOT
1691 fi
1692 install_package $ROOT
1693 update_desktop_database $ROOT
1694 update_mime_database $ROOT
1695 update_icon_database $ROOT
1696 compile_glib_schemas $ROOT
1697 ;;
1700 install-list|get-install-list)
1701 # Install a set of packages from a list.
1702 check_root $@
1703 if [ -z "$2" ]; then
1704 newline
1705 longline "$(_ \
1706 "Please change directory (cd) to the packages repository and specify the \
1707 list of packages to install.")"
1708 echo "$(_ 'Example:') $(emsg '<b>tazpkg install-list</b> <c 33>packages.list</c>')"
1709 exit 0
1710 fi
1712 # Check if the packages list exist.
1713 if [ ! -f "$2" ]; then
1714 _ 'Unable to find list "%s"' "$2"
1715 exit 0
1716 fi
1718 LIST=$(cat $2)
1720 # Remember processed list
1721 export INSTALL_LIST="$2"
1723 # Set $COMMAND and install all packages.
1724 COMMAND=${1%-list}
1726 touch $2-processed
1728 # Upgrade tazpkg first. It may handle new features/formats...
1729 # then upgrade essential packages early
1730 for pkg in busybox-pam busybox gcc-lib-base glibc-base \
1731 slitaz-base-files tazpkg ; do
1732 pkg=$(egrep $pkg-[0-9] $INSTALL_LIST)
1733 [ -z "$pkg" ] && continue
1734 _ 'Adding implicit depends "%s"...' $pkg
1735 LIST="$pkg
1736 $LIST"
1737 done
1739 for pkg in $LIST; do
1740 grep -qs ^$pkg$ $2-processed && continue
1741 [ -d "$root/var/lib/tazpkg/installed" ] &&
1742 tazpkg $COMMAND $pkg --list="$2" "$3" "$4" "$5"
1743 done
1744 rm -f $2-processed ;;
1747 add-flavor)
1748 # Install a set of packages from a flavor.
1749 install_flavor $2 ;;
1752 install-flavor)
1753 # Install a set of packages from a flavor and purge other ones.
1754 install_flavor $2 --purge ;;
1757 set-release)
1758 # Change current release and upgrade packages.
1759 RELEASE=$2
1760 if [ -z "$RELEASE" ]; then
1761 newline
1762 _ 'Please specify the release you want on the command line.'
1763 echo "$(_ 'Example:') tazpkg set-release cooking"
1764 newline
1765 exit 0
1766 fi
1767 rm $PKGS_DB/mirror
1768 echo "$RELEASE" > /etc/slitaz-release
1769 tazpkg recharge && tazpkg upgrade
1771 # Install missing depends
1772 cd $INSTALLED
1773 for i in * ; do
1774 DEPENDS=""
1775 . $i/receipt
1776 for j in $DEPENDS ; do
1777 [ -d $j ] || tazpkg get-install $j
1778 done
1779 done ;;
1782 remove|-r)
1783 # Remove packages.
1784 check_root $@
1785 check_for_package_on_cmdline
1786 check_for_installed_info
1788 [ -n "$root" ] && ROOT="$root"
1789 if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then
1790 newline
1791 _ 'Package "%s" is not installed.' $PACKAGE
1792 exit 0
1793 else
1794 ALTERED=""
1795 THE_PACKAGE=$PACKAGE # altered by receipt
1796 for i in $(cd $ROOT$INSTALLED ; ls); do
1797 [ -f $ROOT$INSTALLED/$i/receipt ] || continue
1798 DEPENDS=""
1799 . $ROOT$INSTALLED/$i/receipt
1800 case " $(echo $DEPENDS) " in
1801 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
1802 esac
1803 done
1804 EXTRAVERSION=""
1805 . $ROOT$INSTALLED/$THE_PACKAGE/receipt
1806 fi
1807 newline
1808 if [ -n "$ALTERED" ]; then
1809 _ 'The following packages depend on package "%s":' $PACKAGE
1810 for i in $ALTERED; do
1811 echo " $i"
1812 done
1813 fi
1814 REFRESH=$(cd $ROOT$INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1815 if [ -n "$REFRESH" ]; then
1816 _ 'The following packages have been modified by package "%s":' $PACKAGE
1817 for i in $REFRESH; do
1818 echo " ${i%/modifiers}"
1819 done
1820 fi
1821 if [ "$auto" ]; then
1822 answer=0
1823 else
1824 confirm "$(_ 'Remove package "%s" (%s)? (y/N)' $PACKAGE $VERSION$EXTRAVERSION)"
1825 answer=$?
1826 fi
1827 if [ $answer = 0 ]; then
1828 title 'Removing package "%s"' $PACKAGE
1829 # Pre remove commands.
1830 if grep -q ^pre_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1831 pre_remove $ROOT
1832 fi
1833 action "Removing all files installed..."
1834 if [ -f $ROOT$INSTALLED/$PACKAGE/modifiers ]; then
1835 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1836 for mod in $(cat $ROOT$INSTALLED/$PACKAGE/modifiers); do
1837 [ -f $ROOT$INSTALLED/$mod/files.list ] && [ $(grep "^$(echo $file | grepesc)$" $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && continue 2
1838 done
1839 remove_with_path $ROOT$file
1840 done
1841 else
1842 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1843 remove_with_path $ROOT$file
1844 done
1845 fi
1846 status
1847 if grep -q ^post_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1848 post_remove $ROOT
1849 fi
1851 # Remove package receipt.
1852 action "Removing package receipt..."
1853 rm -rf $ROOT$INSTALLED/$PACKAGE
1854 status
1856 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION$/d" \
1857 $PKGS_DB/installed.$SUM 2> /dev/null
1859 # Update installed.info
1860 sed -i "/^$PACKAGE /d" $PKGS_DB/installed.info
1862 # Log this activity
1863 log_pkg Removed
1865 if [ "$ALTERED" ]; then
1866 if [ "$auto" ]; then
1867 answer=0
1868 else
1869 confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' $PACKAGE)"
1870 answer=$?
1871 fi
1872 if [ $answer = 0 ]; then
1873 for i in $ALTERED; do
1874 if [ -d "$ROOT$INSTALLED/$i" ]; then
1875 tazpkg remove $i $ROOTOPTS
1876 fi
1877 done
1878 fi
1879 fi
1880 if [ "$REFRESH" ]; then
1881 if [ "$auto" ]; then
1882 answer=0
1883 else
1884 confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' $PACKAGE)"
1885 answer=$?
1886 fi
1887 if [ $answer = 0 ]; then
1888 for i in $REFRESH; do
1889 if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then
1890 _ 'Check %s for reinstallation' "$INSTALLED/$i"
1891 continue
1892 fi
1893 rm -r $ROOT$INSTALLED/$i
1894 tazpkg get-install ${i%/modifiers} $ROOTOPTS --forced
1895 done
1896 fi
1897 fi
1898 else
1899 newline
1900 _ 'Uninstallation of package "%s" cancelled.' $PACKAGE
1901 fi
1902 newline ;;
1905 extract|-e)
1906 # Extract .tazpkg cpio archive into a directory.
1907 check_for_package_on_cmdline
1908 check_for_package_file
1909 title 'Extracting package "%s"' $PACKAGE
1911 # If no directory destination is found on the cmdline
1912 # we create one in the current dir using the package name.
1913 if [ -n "$TARGET_DIR" ]; then
1914 DESTDIR=$TARGET_DIR/$PACKAGE
1915 else
1916 DESTDIR=$PACKAGE
1917 fi
1918 mkdir -p $DESTDIR
1920 action "Copying original package..."
1921 cp $PACKAGE_FILE $DESTDIR
1922 status
1924 cd $DESTDIR
1925 extract_package
1926 [ -e "receipt" ] && \
1927 footer "$(_ 'Package "%s" is extracted to "%s"' $PACKAGE $DESTDIR)"
1928 ;;
1931 recompress)
1932 # Recompress .tazpkg cpio archive with lzma.
1933 check_for_package_on_cmdline
1934 check_for_package_file
1935 title 'Recompressing package "%s"' $PACKAGE
1936 mkdir -p $TMP_DIR
1938 action "Copying original package..."
1939 cp $PACKAGE_FILE $TMP_DIR
1940 status
1942 cd $TMP_DIR
1943 extract_package
1945 action "Recompressing the FS..."
1946 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1947 rm -rf fs
1948 status
1950 action "Creating new package..."
1951 find . -print | cpio -o -H newc --quiet > \
1952 $TOP_DIR/$(basename $PACKAGE_FILE).$$ && mv -f \
1953 $TOP_DIR/$(basename $PACKAGE_FILE).$$ \
1954 $TOP_DIR/$(basename $PACKAGE_FILE)
1955 status
1957 cd $TOP_DIR
1958 rm -rf $TMP_DIR
1959 separator; newline ;;
1962 list-config)
1963 # List configuration files installed.
1964 if [ -n "$box" ]; then
1965 mkdir -p $TMP_DIR; cd $TMP_DIR
1966 FILES="$INSTALLED/*/volatile.cpio.gz"
1967 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
1968 for i in $FILES; do
1969 zcat $i | cpio -idm --quiet > /dev/null
1970 find * -type f 2>/dev/null | while read file; do
1971 if [ ! -e /$file ]; then
1972 echo -n "----------|----|----|$(_n 'File lost')"
1973 else
1974 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
1975 cmp $file /$file > /dev/null 2>&1 || \
1976 echo -n "$(stat -c "%.16y" /$file)"
1977 fi
1978 echo "|/$file"
1979 done
1980 rm -rf *
1981 done
1982 cd $TOP_DIR
1983 rm -rf $TMP_DIR
1984 else
1985 im && title 'Configuration files'
1986 for i in $INSTALLED/*/volatile.cpio.gz; do
1987 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
1988 [ -f "$i" ] || continue
1989 zcat $i | cpio -t --quiet
1990 done | sed 's|^|/|' | sort
1991 im && footer
1992 fi ;;
1995 repack-config)
1996 # Create SliTaz package archive from configuration files.
1997 mkdir -p $TMP_DIR; cd $TMP_DIR
1998 CONFIG_VERSION=1.0
1999 mkdir config-$CONFIG_VERSION
2000 cd config-$CONFIG_VERSION
2001 for i in $INSTALLED/*/volatile.cpio.gz; do
2002 zcat $i | cpio -t --quiet
2003 done > files.list
2004 mkdir fs
2005 cd fs
2006 ( cd / ; cpio -o -H newc --quiet ) < ../files.list | cpio -idm --quiet > /dev/null
2007 mkdir -p etc/tazlito
2008 for i in $INSTALLED/*/receipt; do
2009 EXTRAVERSION=""
2010 . $i
2011 echo "$PACKAGE-$VERSION$EXTRAVERSION"
2012 done > etc/tazlito/config-packages.list
2013 cd ..
2014 echo "etc/tazlito/config-packages.list" >> files.list
2015 pkg_date=$(date +"%x %X")
2016 cat > receipt <<EOT
2017 # SliTaz package receipt.
2019 PACKAGE="config"
2020 VERSION="$CONFIG_VERSION"
2021 CATEGORY="base-system"
2022 SHORT_DESC="$(_n 'User configuration backup on date %s' $pkg_date)"
2023 DEPENDS="$(ls $INSTALLED)"
2024 EOT
2025 cd ..
2026 tazpkg pack config-$CONFIG_VERSION
2027 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
2028 cd $TOP_DIR
2029 rm -rf $TMP_DIR
2030 ;;
2033 repack)
2034 # Create SliTaz package archive from an installed package.
2035 check_for_package_on_cmdline
2036 check_for_receipt
2037 EXTRAVERSION=""
2038 . $INSTALLED/$PACKAGE/receipt
2039 title 'Repacking "%s"' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
2041 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
2042 _ "Can't repack package \"%s\"" $PACKAGE
2043 exit 1
2044 fi
2046 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
2047 _ "Can't repack, \"%s\" files have been modified by:" $PACKAGE
2048 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
2049 echo " $i"
2050 done
2051 exit 1
2052 fi
2054 MISSING=""
2055 while read i; do
2056 [ -e "$i" ] && continue
2057 [ -L "$i" ] || MISSING="$MISSING\n $i"
2058 done < $INSTALLED/$PACKAGE/files.list
2059 if [ -n "$MISSING" ]; then
2060 _n "Can't repack, the following files are lost:"
2061 echo -e "$MISSING"
2062 exit 1
2063 fi
2065 mkdir -p $TMP_DIR; cd $TMP_DIR
2066 FILES="fs.cpio.lzma\n"
2067 for i in $(ls $INSTALLED/$PACKAGE); do
2068 case $i in
2069 volatile.cpio.gz|modifiers) ;;
2070 *) cp $INSTALLED/$PACKAGE/$i .; FILES="$FILES$i\n" ;;
2071 esac
2072 done
2074 ln -s / rootfs
2075 mkdir tmp
2076 sed 's/^/rootfs/' < files.list | cpio -o -H newc --quiet | \
2077 { cd tmp ; cpio -idm --quiet >/dev/null; cd ..; }
2078 mv tmp/rootfs fs
2080 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
2081 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
2082 { cd fs; cpio -idm --quiet; cd ..; }
2083 fi
2085 if fgrep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
2086 . $INSTALLED/$PACKAGE/receipt
2087 repack_cleanup fs
2088 fi
2090 if [ -f $INSTALLED/$PACKAGE/$CHECKSUM ]; then
2091 sed 's, , fs,' < $INSTALLED/$PACKAGE/$CHECKSUM | \
2092 $CHECKSUM -s -c || {
2093 _ "Can't repack, %s error." $CHECKSUM
2094 cd $TOP_DIR
2095 rm -rf $TMP_DIR
2096 exit 1
2098 fi
2100 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2101 echo -e "$FILES" | cpio -o -H newc --quiet > \
2102 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
2103 cd $TOP_DIR
2104 \rm -R $TMP_DIR
2105 _ 'Package "%s" repacked successfully.' $PACKAGE
2106 _ 'Size: %s' "$(du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg)"
2107 newline ;;
2110 pack)
2111 # Create SliTaz package archive using cpio and lzma.
2112 # TODO: Cook also pack packages, we should share code in libpkg.sh
2113 check_for_package_on_cmdline
2114 cd $PACKAGE
2115 if [ ! -f "receipt" ]; then
2116 _ 'Receipt is missing. Please read the documentation.'
2117 exit 0
2118 fi
2120 title 'Packing package "%s"' $PACKAGE
2121 # Create files.list with redirecting find outpout.
2123 action "Creating the list of files..."
2124 cd fs
2125 find . -type f -print > ../files.list
2126 find . -type l -print >> ../files.list
2127 cd .. && sed -i s/'^.'/''/ files.list
2128 status
2130 action 'Creating %s of files...' $CHECKSUM
2131 while read file; do
2132 [ -L "fs$file" ] && continue
2133 [ -f "fs$file" ] || continue
2134 case "$file" in
2135 /lib/modules/*/modules.*|*.pyc) continue;;
2136 esac
2137 $CHECKSUM "fs$file" | sed 's/ fs/ /'
2138 done < files.list > $CHECKSUM
2139 status
2141 UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
2142 description.txt 2> /dev/null | awk \
2143 '{ sz=$1 } END { print sz }')
2144 # Build cpio archives.
2146 action "Compressing the FS..."
2147 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2148 rm -rf fs
2149 status
2151 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
2152 $CHECKSUM description.txt 2> /dev/null | awk \
2153 '{ sz=$1 } END { print sz }')
2155 action "Updating receipt sizes..."
2156 sed -i s/^PACKED_SIZE.*$// receipt
2157 sed -i s/^UNPACKED_SIZE.*$// receipt
2158 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
2159 status
2161 action "Creating full cpio archive..."
2162 find . -print | cpio -o -H newc --quiet > ../$PACKAGE.tazpkg
2163 status
2165 action "Restoring original package tree..."
2166 unlzma -c fs.cpio.lzma | cpio -idm --quiet
2167 status
2169 rm fs.cpio.lzma && cd ..
2170 footer "$(_ 'Package "%s" compressed successfully.' $PACKAGE)"
2171 _ 'Size: %s' "$(ls -lh $PACKAGE.tazpkg | awk '{print $5}')"
2172 ;;
2175 recharge)
2176 # Recharge packages.list from a mirror.
2178 # WARNING: The 'mirrors' file has all SliTaz mirrors but 'mirror'
2179 # must have only the chosen main mirror.
2181 check_root $@
2183 ARG=$2
2184 if [ "$root" ]; then
2185 PKGS_DB=$root$PKGS_DB
2186 [ "${2#--}" != "$2" ] && ARG=$3
2187 fi
2188 if [ "$ARG" = main ]; then
2189 repository_to_recharge=$PKGS_DB
2190 elif [ "$ARG" ]; then
2191 if [ -d "$PKGS_DB/undigest/$ARG" ]; then
2192 repository_to_recharge=$PKGS_DB/undigest/$ARG
2193 else
2194 repo="$PKGS_DB/undigest/$ARG"
2195 _ "Repository \"%s\" doesn't exist." $repo >&2
2196 exit 1
2197 fi
2198 else
2199 repository_to_recharge="$PKGS_DB $PKGS_DB/undigest/*"
2200 fi
2201 for path in $repository_to_recharge; do
2202 [ -f $path/mirror ] || continue
2203 cd $path
2205 # Quietly check if recharging is needed.
2206 [ -f ID ] && mv ID ID.bak
2207 download_from "$(cat mirror)" ID >/dev/null 2>/dev/null
2208 if [ -f ID ] && fgrep -q $(cat ID.bak 2>/dev/null || echo "null") ID; then
2209 if [ "$path" = "$PKGS_DB" ]; then
2210 repository_name=Main
2211 else
2212 base_path="$(basename $path)"
2213 repository_name="$(_n 'Undigest %s' $base_path)"
2214 fi
2215 _ 'Repository "%s" is up to date.' "$repository_name"
2216 rm ID.bak
2217 continue
2218 fi
2220 # Don't let ID be a symlink when using local repository.
2221 if [ -f ID ]; then
2222 mv -f ID ID.bak
2223 cat ID.bak > ID
2224 rm ID.bak
2225 fi
2227 newline
2228 if [ "$path" != "$PKGS_DB" ]; then
2229 base_path="$(basename $path)"
2230 _ 'Recharging undigest %s:' $base_path
2231 fi
2233 if [ -f "packages.list" ]; then
2234 action "Creating backup of the last packages list..."
2235 for i in packages.desc packages.$SUM packages.txt \
2236 packages.list packages.equiv files.list.lzma \
2237 extra.list mirrors packages.info
2238 do
2239 mv -f $i $i.bak 2>/dev/null
2240 done
2241 status
2242 fi
2244 for i in desc $SUM txt list equiv; do
2245 download_from "$(cat mirror)" packages.$i
2246 done
2247 download_from "$(cat mirror)" files.list.lzma
2248 download_from "$(cat mirror)" extra.list
2249 download_from "$(sed 's|packages/.*||' mirror)" mirrors
2251 # packages.info
2252 download_from "$(cat mirror)" packages.info.lzma
2253 lzma d packages.info.lzma packages.info
2254 rm packages.info.lzma
2256 if [ -f "packages.list.bak" ]; then
2257 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
2258 [ -f "extra.list.bak" ] &&
2259 diff -u extra.list.bak extra.list | grep ^+[a-z] >> packages.diff
2260 sed -i s/+// packages.diff
2261 title 'Mirrored packages diff'
2262 cat packages.diff
2263 new_pkgs=$(wc -l < packages.diff)
2264 footer "$(emsg "$(_p \
2265 '%s new package on the mirror.' \
2266 '%s new packages on the mirror.' $new_pkgs \
2267 "<c 32>$new_pkgs</c>")")"
2268 else
2269 footer "$(longline "$(_ "Last %s is ready to use. Note that \
2270 next time you recharge the list, a list of differences will be displayed to \
2271 show new and upgradeable packages." packages.list)")"
2272 fi
2273 done ;;
2276 help-up)
2277 # Options available for the command: up
2278 newline; usage_up; newline
2279 exit 1 ;;
2282 up|upgrade)
2283 check_root
2285 # This is the new way to upgrade packages making 'upgrade' and
2286 # upgradeable out-of-date. This new way is much, much more faster!
2287 # Look into installed packages and get data from receipt, it is fast
2288 # and easy to handle vars after using only md5sum to compare packages
2290 for opt in $@; do
2291 case "$opt" in
2292 --recharge|-r) tazpkg recharge ;;
2293 --install|-i) install="y" ;;
2294 --check|-c) install="n" ;;
2295 esac
2296 done
2297 time=$(date +%s)
2299 look_for_priority
2300 for repo in $priority; do
2301 pkg_list=$repo/packages.list
2302 mtime=$(find $pkg_list -mtime +7)
2303 if [ "$mtime" ]; then
2304 if [ "$repo" == "$PKGS_DB" ]; then
2305 repo_name=main
2306 else
2307 repo_name="${repo##*/}"
2308 fi
2309 _ 'List "%s" is older than one week... Recharging.' $pkg_list
2310 tazpkg recharge $repo_name
2311 fi
2312 done
2314 emsg "<n>$(_ 'Package')<i 28> $(_ 'Version')<i 48> $(_ 'Status')<->"
2316 cd $INSTALLED
2317 echo -n > $UP_LIST
2318 blocked_count=0
2319 installed_sum=$PKGS_DB/installed.$SUM
2321 for pkg in *; do
2322 [ ! -d $pkg ] && continue
2323 unset VERSION EXTRAVERSION
2324 . $pkg/receipt
2325 md5=$(fgrep " $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" \
2326 $installed_sum | awk '{print $1}')
2327 for repo in $priority; do
2328 pkg_desc=$repo/packages.desc
2329 pkg_list=$repo/packages.list
2330 pkg_sum=$repo/packages.$SUM
2332 if ! fgrep -q "$md5 $PACKAGE-" $pkg_sum; then
2333 # Jump to next repository in priority if pkg doesn't exist
2334 # in this one.
2335 grep -q ^$PACKAGE- $pkg_list || continue
2337 emsg -n "$PACKAGE<i 28> $VERSION"
2339 # Skip pkgs listed in $PKGS_DB/blocked-packages.list
2340 if $(grep -qs "^$PACKAGE" $BLOCKED); then
2341 blocked_count=$(($blocked_count + 1))
2342 emsg "<i 48><c 31> $(_ 'Blocked')</c>"
2343 break
2344 fi
2346 new=$(grep "^$PACKAGE |" $pkg_desc | awk '{print $3}')
2348 if [ "$VERSION" == "$new" ]; then
2349 emsg "<i 48><c 34> $(_ 'New build')</c>"
2350 else
2351 emsg "<i 48><c 32> $(_ 'New version %s' $new)</c>"
2352 fi
2353 echo "$PACKAGE" >> $UP_LIST
2354 break
2355 fi
2356 done
2357 done
2358 sed -i /^$/d $UP_LIST
2359 upnb=$(wc -l < $UP_LIST)
2360 pkgs=$(ls | wc -l)
2361 time=$(($(date +%s) - $time))
2362 if [ "$upnb" == 0 ]; then
2363 install="n"
2364 _ 'System is up-to-date...'
2365 fi
2367 footer "$(emsg "$(_p \
2368 '%s installed package scanned in %ds' \
2369 '%s installed packages scanned in %ds' $pkgs \
2370 "<c 32>$pkgs</c>" $time)")"
2372 if [ "$upnb" != 0 ]; then
2373 blocked="$(_p \
2374 '%s blocked' \
2375 '%s blocked' $blocked_count \
2376 $blocked_count)"
2378 boldify "$(_p \
2379 'You have %s available upgrade (%s)' \
2380 'You have %s available upgrades (%s)' $upnb \
2381 $upnb "$blocked")"
2382 newline
2383 fi
2384 # Pkgs to upgrade ? Skip, let install them all or ask user
2385 [ "$install" == "n" ] && exit 0
2386 if [ "$upnb" -gt 0 ]; then
2387 if [ "$install" == "y" ]; then
2388 continue
2389 else
2390 confirm "$(_ 'Do you wish to install them now? (y/N)')"
2391 answer=$?
2392 fi
2393 case "$answer" in
2394 0)
2395 for pkg in $(cat $UP_LIST); do
2396 echo 'y' | tazpkg get-install $pkg --forced
2397 done
2398 # List is generated each time and must be cleaned so
2399 # tazpkg-notify doesn't find upgrades anymore.
2400 rm $UP_LIST; touch $UP_LIST ;;
2401 *)
2402 _ 'Leaving without any upgrades installed.'
2403 newline
2404 exit 0 ;;
2405 esac
2406 fi
2407 newline ;;
2410 bugs)
2411 # Show known bugs in package(s)
2412 cd $INSTALLED
2413 shift
2414 LIST=$@
2415 [ -n "$LIST" ] || LIST=$(ls)
2416 MSG=$(_n 'No known bugs.')
2417 for PACKAGE in $LIST; do
2418 BUGS=""
2419 EXTRAVERSION=""
2420 . $PACKAGE/receipt
2421 if [ -n "$BUGS" ]; then
2422 MSG=$(_n 'Bug list completed')
2423 newline
2424 _ 'Bugs in package "%s" version %s:' $PACKAGE $VERSION$EXTRAVERSION
2425 cat <<EOT
2426 $BUGS
2427 EOT
2428 fi
2429 done
2430 echo "$MSG" ;;
2433 check)
2434 # Check installed packages set.
2435 check_root $@
2437 # Get repositories priority list.
2438 look_for_priority
2440 cd $INSTALLED
2441 for PACKAGE in $(ls); do
2443 if [ ! -f $PACKAGE/receipt ]; then
2444 _ 'The package "%s" installation has not completed' $PACKAGE
2445 continue
2446 fi
2448 DEPENDS=""
2449 EXTRAVERSION=""
2450 . $PACKAGE/receipt
2451 if [ -s $PACKAGE/modifiers ]; then
2452 _ 'The package "%s" has been modified by:' $PACKAGE-$VERSION$EXTRAVERSION
2453 for i in $(cat $PACKAGE/modifiers); do
2454 echo " $i"
2455 done
2456 fi
2458 MSG="$(_n 'Files lost from package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2459 while read file; do
2460 [ -e "$file" ] && continue
2461 if [ -L "$file" ]; then
2462 MSG="$MSG $(_n 'target of symlink')"
2463 fi
2464 echo -e "$MSG $file"
2465 MSG=""
2466 done < $PACKAGE/files.list
2468 MSG="$(_n 'Missing dependencies for package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2469 for i in $DEPENDS; do
2470 [ -d $i ] && continue
2471 [ -d $(equivalent_pkg $i) ] && continue
2472 echo -e "$MSG $i"
2473 MSG=""
2474 done
2476 MSG="$(_n 'Dependencies loop between "%s" and:' $PACKAGE)\n"
2477 ALL_DEPS=""
2478 check_for_deps_loop $PACKAGE $DEPENDS
2479 done
2481 _ 'Looking for known bugs...'
2482 tazpkg bugs
2484 if [ "$2" == "--full" ]; then
2485 separator
2487 for file in */$CHECKSUM; do
2488 CONFIG_FILES=""
2489 . $(dirname "$file")/receipt
2490 [ -s "$file" ] || continue
2491 while read md5 f; do
2492 [ -f $f ] || continue
2493 for i in $CONFIG_FILES; do
2494 case "$f" in
2495 $i|$i/*) continue 2;;
2496 esac
2497 done
2498 echo "$md5 $f"
2499 done < "$file" | busybox $CHECKSUM -c - 2> /dev/null | \
2500 grep -v OK$ | sed "s/FAILED$/$CHECKSUM MISMATCH/"
2501 done
2503 FILES=" "
2504 for file in $(cat */files.list); do
2505 [ -d "$file" ] && continue
2506 case "$FILES" in *\ $file\ *) continue;; esac
2507 [ $(grep "^$(echo $file | grepesc)$" */files.list 2> /dev/null | \
2508 wc -l) -gt 1 ] || continue
2509 FILES="$FILES$file "
2510 _ 'The following packages provide file "%s":' $file
2511 grep -l "^$(echo $file | grepesc)$" */files.list | \
2512 while read f; do
2513 pkg=${f%/files.list}
2514 if [ -f $pkg/modifiers ]; then
2515 overriders=$(_n '(overridden by %s)' "$(tr '\n' ' ' | sed 's| $||' < $pkg/modifiers)")
2516 else
2517 overriders=''
2518 fi
2519 echo -n " $pkg $overriders"
2520 newline
2521 done
2522 done
2524 MSG="$(_n 'No package has installed the following files:')\n"
2525 find /etc /bin /sbin /lib /usr /var/www -not -type d 2>/dev/null | \
2526 while read file; do
2527 case "$file" in *\[*) continue;; esac
2528 grep -q "^$(echo $file | grepesc)$" */files.list && continue
2529 echo -e "$MSG $file"
2530 MSG=""
2531 done
2532 fi
2533 _ 'Check completed.'; echo ;;
2536 block)
2537 # Add a pkg name to the list of blocked packages.
2538 check_root $@
2539 check_for_package_on_cmdline
2540 newline
2541 if [ ! -d $INSTALLED/$PACKAGE ]; then
2542 _ 'Package "%s" is not installed.' $PACKAGE; exit
2543 fi
2544 if grep -qs "^$PACKAGE" $BLOCKED; then
2545 _ 'Package "%s" is already blocked.' $PACKAGE
2546 else
2547 echo $PACKAGE >> $BLOCKED
2548 # Log this activity
2549 . $INSTALLED/$PACKAGE/receipt; log_pkg Blocked
2550 _ 'Package "%s" blocked.' $PACKAGE
2551 fi
2552 newline ;;
2555 unblock)
2556 # Remove a pkg name from the list of blocked packages.
2557 check_root $@
2558 check_for_package_on_cmdline
2559 newline
2560 if [ ! -d $INSTALLED/$PACKAGE ]; then
2561 _ 'Package "%s" is not installed.' $PACKAGE; exit
2562 fi
2563 if grep -qs "^$PACKAGE" $BLOCKED; then
2564 sed -i "/^$PACKAGE\$/d" $BLOCKED
2565 # Log this activity
2566 . $INSTALLED/$PACKAGE/receipt; log_pkg Unblocked
2567 _ 'Package "%s" unblocked.' $PACKAGE
2568 else
2569 _ 'Package "%s" is not blocked.' $PACKAGE
2570 fi
2571 newline ;;
2574 chblock)
2575 # Change package's blocked status.
2576 check_root $@
2577 check_for_package_on_cmdline
2578 newline
2579 if [ ! -d $INSTALLED/$PACKAGE ]; then
2580 _ 'Package "%s" is not installed.' $PACKAGE; exit
2581 fi
2582 if grep -qs "^$PACKAGE" $BLOCKED; then
2583 sed -i "/^$PACKAGE\$/d" $BLOCKED
2584 # Log this activity
2585 . $INSTALLED/$PACKAGE/receipt; log_pkg Unblocked
2586 _ 'Package "%s" unblocked.' $PACKAGE
2587 else
2588 echo $PACKAGE >> $BLOCKED
2589 # Log this activity
2590 . $INSTALLED/$PACKAGE/receipt; log_pkg Blocked
2591 _ 'Package "%s" blocked.' $PACKAGE
2592 fi
2593 newline ;;
2596 get)
2597 # Download a package with wget.
2598 check_root $@
2599 check_for_package_on_cmdline
2600 check_for_packages_list
2602 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2603 if [ "$rootconfig" ]; then
2604 if [ "$root" ]; then
2605 CACHE_DIR=$root/$CACHE_DIR
2606 SAVE_CACHE_DIR=$CACHE_DIR
2607 PKGS_DB=$root/$PKGS_DB
2608 else
2609 _ 'rootconfig needs --root= option used.' >&2
2610 exit 1
2611 fi
2612 fi
2614 # Get repositories priority list.
2615 look_for_priority
2617 CURRENT_DIR=$PWD
2618 check_for_package_in_list
2619 cd $CACHE_DIR
2620 if [ -f "$PACKAGE.tazpkg" ]; then
2621 _ 'Package "%s" already in the cache' $PACKAGE
2622 # Check package download was finished
2623 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2624 _ 'Continuing package "%s" download' $PACKAGE
2625 download $PACKAGE.tazpkg
2627 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2628 rm -f $PACKAGE.tazpkg
2629 download $PACKAGE.tazpkg
2630 fi
2631 else
2632 download $PACKAGE.tazpkg
2633 fi
2634 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2635 cp -a $PACKAGE_FILE $CURRENT_DIR ;;
2638 get-install|-gi)
2639 # Download and install a package.
2640 check_root $@
2641 check_for_package_on_cmdline
2642 check_for_packages_list
2644 DO_CHECK=""
2645 [ "$forced" ] && DO_CHECK=no
2646 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2647 [ "$list" ] && INSTALL_LIST="$list"
2648 if [ "$rootconfig" ]; then
2649 if [ "$root" ]; then
2650 CACHE_DIR=$root/$CACHE_DIR
2651 SAVE_CACHE_DIR=$CACHE_DIR
2652 PKGS_DB=$root/$PKGS_DB
2653 else
2654 _ 'rootconfig needs --root= option used.' >&2
2655 exit 1
2656 fi
2657 fi
2659 # Get repositories priority list.
2660 look_for_priority
2662 AUTOEXEC="no"
2663 if ! check_for_package_in_list check; then
2664 CACHE_DIR="${CACHE_DIR%/*}/get"
2665 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
2666 if download_get_script $PACKAGE /tmp/$PACKAGE.$$ ; then
2667 install_package_from_get_script /tmp/$PACKAGE.$$ $ROOT
2668 exit 0
2669 else
2670 PACKAGE=get-$PACKAGE
2671 AUTOEXEC=$PACKAGE
2672 check_for_package_in_list
2673 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
2674 $AUTOEXEC $ROOT
2675 exit 0
2676 fi
2677 fi
2678 fi
2679 # Check if forced install.
2680 if ! [ "$forced" ]; then
2681 check_for_installed_package $ROOT
2682 fi
2683 cd $CACHE_DIR
2684 if [ -f "$PACKAGE.tazpkg" ]; then
2685 _ 'Package "%s" already in the cache' $PACKAGE
2686 # Check package download was finished
2687 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2688 _ 'Continuing package "%s" download' $PACKAGE
2689 download $PACKAGE.tazpkg
2691 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2692 rm -f $PACKAGE.tazpkg
2693 download $PACKAGE.tazpkg
2694 fi
2695 else
2696 newline
2697 download $PACKAGE.tazpkg
2698 fi
2699 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2700 [ "$rootconfig" ] && PKGS_DB=${PKGS_DB#$root}
2701 install_package $ROOT
2702 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
2703 update_desktop_database $ROOT
2704 update_mime_database $ROOT ;;
2707 clean-cache|-cc)
2708 # Remove all downloaded packages.
2709 check_root $@
2710 files=$(find $CACHE_DIR -name *.tazpkg | wc -l)
2711 size=$(du -hs $CACHE_DIR | cut -f1 | sed 's|\.0||'); [ $files == "0" ] && size="0K"
2712 title 'Path: %s' $CACHE_DIR
2713 action "Cleaning cache directory..."
2714 rm -rf $CACHE_DIR/*
2715 status
2717 footer "$(_p \
2718 '%s file removed from cache (%s).' \
2719 '%s files removed from cache (%s).' $files \
2720 "$(colorize 32 "$files")" $size)"
2721 ;;
2724 list-undigest)
2725 # list undigest URLs.
2726 if [ "$2" = "--box" ]; then
2727 for i in $PKGS_DB/undigest/*/mirror; do
2728 [ -f $i ] || continue
2729 echo "$(basename $(dirname $i))|$(cat $i)"
2730 done
2731 else
2732 title 'Current undigest(s)'
2733 for i in $PKGS_DB/undigest/*/mirror; do
2734 if [ ! -f $i ]; then
2735 _ 'No undigest mirror found.'
2736 exit 1
2737 fi
2738 echo "$(basename $(dirname $i)) $(cat $i)"
2739 done
2740 newline
2741 fi ;;
2744 remove-undigest)
2745 # remove undigest URL.
2746 check_root $@
2747 undigest="$2"
2748 if [ -d $PKGS_DB/undigest/$2 ]; then
2749 confirm "$(_ 'Remove "%s" undigest? (y/N)' $undigest)"
2750 if [ $? = 0 ]; then
2751 action 'Removing "%s" undigest...' $undigest
2752 rm -rf $PKGS_DB/undigest/$2
2753 status
2754 rmdir $PKGS_DB/undigest 2> /dev/null
2755 fi
2756 else
2757 _ 'Undigest "%s" not found' $undigest
2758 fi ;;
2761 add-undigest|setup-undigest)
2762 # Add undigest URL.
2763 check_root $@
2764 undigest=$2
2765 [ -d $PKGS_DB/undigest ] || mkdir $PKGS_DB/undigest
2766 if [ -z "$undigest" ]; then
2767 i=1
2768 while [ -d $PKGS_DB/undigest/$i ]; do
2769 i=$(($i+1))
2770 done
2771 undigest=$i
2772 fi
2773 if [ ! -d $PKGS_DB/undigest/$undigest ]; then
2774 _ 'Creating new undigest "%s".' $undigest
2775 mkdir $PKGS_DB/undigest/$undigest
2776 fi
2777 setup_mirror $PKGS_DB/undigest/$undigest $3 ;;
2780 setup-mirror|-sm)
2781 # Change mirror URL.
2782 check_root $@
2783 setup_mirror $PKGS_DB $2 ;;
2786 reconfigure)
2787 # Replay post_install from receipt
2788 check_for_package_on_cmdline
2789 check_root $@
2790 ROOT=""
2791 while [ -n "$3" ]; do
2792 case "$3" in
2793 --root=*)
2794 ROOT="${3#--root=}/" ;;
2795 *)
2796 shift 2
2797 u_opt="$*"
2798 newline >&2
2799 _ 'Unknown option "%s".' $u_opt >&2
2800 exit 1 ;;
2801 esac
2802 shift
2803 done
2804 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2805 check_for_receipt $ROOT
2806 # Check for post_install
2807 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2808 . $ROOT$INSTALLED/$PACKAGE/receipt
2809 post_install $ROOT
2810 # Log this activity
2811 [ -n "$ROOT" ] || log_pkg Reconfigured
2812 else
2813 newline
2814 _ 'Nothing to do for package "%s".' $PACKAGE
2815 fi
2816 else
2817 newline
2818 _ 'Package "%s" is not installed.' $PACKAGE
2819 _ 'Install package with "%s" or "%s"' 'tazpkg install' 'tazpkg get-install'
2820 newline
2821 fi ;;
2824 shell)
2825 # TazPKG SHell
2826 if test $(id -u) = 0 ; then
2827 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2828 else
2829 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2830 fi
2831 if [ ! "$2" = "--noheader" ]; then
2832 clear
2833 title 'TazPKG SHell.'
2834 _ "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
2835 newline
2836 fi
2837 while true; do
2838 echo -en "$PROMPT"; read cmd
2839 case $cmd in
2840 q|quit)
2841 break ;;
2842 shell)
2843 _ 'You are already running a TazPKG SHell.' ;;
2844 su)
2845 su -c 'exec tazpkg shell --noheader' && break ;;
2846 "")
2847 continue ;;
2848 *)
2849 tazpkg $cmd ;;
2850 esac
2851 done ;;
2854 depends)
2855 # Display dependencies tree
2856 cd $INSTALLED
2857 ALL_DEPS=""
2858 if [ -f $2/receipt ]; then
2859 dep_scan $2 ""
2860 fi ;;
2863 rdepends)
2864 # Display reverse dependencies tree
2865 cd $INSTALLED
2866 ALL_DEPS=""
2867 if [ -f $2/receipt ]; then
2868 rdep_scan $2
2869 fi ;;
2872 list-suggested)
2873 for i in $(ls -d $INSTALLED/*); do
2874 . $i/receipt
2875 if [ "$SUGGESTED" ]; then
2876 if [ -z "$all" ]; then
2877 for s in $SUGGESTED; do
2878 [ -d $INSTALLED/$s ] && \
2879 SUGGESTED=$(echo -n $SUGGESTED | sed "s/$s//")
2880 done
2881 fi
2882 cat << EOT
2883 $(boldify $(echo $PACKAGE):) $SUGGESTED
2884 EOT
2885 fi
2886 SUGGESTED=""
2887 done ;;
2890 convert|-c)
2891 # convert misc package format to .tazpkg
2892 check_for_package_file
2893 tazpkg-convert $@
2894 ;;
2897 link)
2898 # link a package from another slitaz installation
2899 PACKAGE=$2
2900 if [ ! -d "$TARGET_DIR" -o \
2901 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
2902 _ 'Usage: tazpkg link package_name slitaz_root'
2903 longline "$(
2904 _n 'Example:'
2905 echo -n ' '
2906 _ '"%s" will use less than 100k in your running system RAM.' \
2907 'tazpkg link openoffice /mnt')"
2908 exit 1
2909 fi
2910 if [ -e "$INSTALLED/$PACKAGE" ]; then
2911 _ 'Package "%s" is already installed.' $PACKAGE
2912 exit 1
2913 fi
2914 ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
2915 DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
2916 MISSING=""
2917 for i in $DEPENDS; do
2918 [ -e $INSTALLED/$i ] && continue
2919 MISSING="$MISSING$i "
2920 _ 'Missing: %s' $i
2921 done
2922 if [ -n "$MISSING" ]; then
2923 newline
2924 confirm "$(_ 'Link all missing dependencies? (y/N)')"
2925 answer=$?
2926 newline
2927 if [ $answer = 0 ]; then
2928 for i in $MISSING; do
2929 tazpkg link $i $TARGET_DIR
2930 done
2931 else
2932 newline
2933 _ 'Leaving dependencies unresolved for package "%s"' $PACKAGE
2934 _ 'The package is installed but probably will not work.'
2935 newline
2936 fi
2937 fi
2938 . $INSTALLED/$PACKAGE/receipt
2939 if grep -q ^pre_install $INSTALLED/$PACKAGE/receipt; then
2940 pre_install
2941 fi
2942 while read path; do
2943 [ -e $path ] && continue
2944 while true; do
2945 dir=$(dirname $path)
2946 [ -e $dir ] && break
2947 path=$dir
2948 done
2949 ln -s $TARGET_DIR$path $dir
2950 done < $INSTALLED/$PACKAGE/files.list
2951 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
2952 post_install
2953 fi ;;
2956 usage|*)
2957 # Print a short help or give usage for an unknown or empty command.
2958 usage ;;
2959 esac
2961 exit 0