tazpkg view tazpkg @ rev 769

Makefile: TazPanel' icons no need anymore, removed.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Apr 07 03:40:20 2015 +0300 (2015-04-07)
parents ad921c2aee59
children c62e153dab37
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 SIZES=$(echo $PACKED_SIZE/$UNPACKED_SIZE | sed 's|\.0||g' | sed 's|^/$||')
1482 emsg "$(
1484 _ 'Package : %s' "$PACKAGE"
1485 _ 'Version : %s' "$VERSION$EXTRAVERSION"
1486 _ 'Category : %s' "$(_ $CATEGORY)"
1487 _ 'Short desc : %s' "$SHORT_DESC"
1488 _ 'Maintainer : %s' "$MAINTAINER"
1489 _ 'License : %s' "$LICENSE"
1490 _ 'Depends : %s' "$DEPENDS"
1491 _ 'Suggested : %s' "$SUGGESTED"
1492 _ 'Build deps : %s' "$BUILD_DEPENDS"
1493 _ 'Wanted src : %s' "$WANTED"
1494 _ 'Web site : %s' "$WEB_SITE"
1495 _ 'Size : %s' "$SIZES"
1496 _ 'Tags : %s' "$TAGS"
1497 } | sed '/: $/d; s|^\([^:]*\):|<b>\1:</b>|')"
1498 im && footer
1499 ;;
1502 desc)
1503 # Display package description
1504 if [ -n "$(grep -e "^$PACKAGE " $PKGS_DB/installed.info)" ]; then
1505 im && title 'Description of package "%s"' $PACKAGE
1506 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
1507 cat $INSTALLED/$PACKAGE/description.txt
1508 else
1509 im && awk -F$'\t' '{if ($1 == "'$PACKAGE'") print $4}' $PKGS_DB/installed.info
1510 fi
1511 im && footer
1512 else
1513 im && _ 'Package "%s" is not installed.' "$PACKAGE"
1514 fi
1515 ;;
1518 activity|log|-a)
1519 # Show activity log
1520 [ "$nb" ] || nb=18
1521 title 'TazPKG Activity'
1522 IFS=" "
1523 tail -n ${nb} ${LOG} | \
1524 while read date hour none action none pkg vers none; do
1525 case $action in
1526 Installed)
1527 action=$(colorize 32 $action) ;;
1528 Removed)
1529 action=$(colorize 31 $action) ;;
1530 *)
1531 action=$(boldify $action) ;;
1532 esac
1533 echo "$date $hour : $action $pkg $vers"
1534 done
1535 unset IFS
1536 footer ;;
1539 search|-s)
1540 # Search for a package by pattern or name.
1541 PATTERN="$2"
1542 if [ -z "$PATTERN" ]; then
1543 newline
1544 _ 'Please specify a pattern or package name to search for.'
1545 echo "$(_ 'Example:') 'tazpkg search paint'"
1546 newline
1547 exit 0
1548 fi
1549 title 'Search result for "%s"' $PATTERN
1550 # Default is to search in installed pkgs and the raw list.
1551 case "$3" in
1552 -i|--installed)
1553 search_in_installed_packages ;;
1554 -l|--list)
1555 search_in_packages_list ;;
1556 -m|--mirror)
1557 search_in_packages_txt ;;
1558 *)
1559 search_in_installed_packages
1560 search_in_packages_list ;;
1561 esac ;;
1564 search-file|-sf)
1565 # Search for a file by pattern or name in all files.list.
1566 if [ -z "$2" ]; then
1567 newline
1568 _ 'Please specify a pattern or file name to search for.'
1569 echo "$(_ 'Example:') 'tazpkg search-file libnss'"
1570 newline
1571 exit 0
1572 fi
1573 title 'Search result for file "%s"' $2
1575 TMPLIST=$(mktemp)
1576 if [ "$3" == "--mirror" ]; then
1578 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1579 [ -f $i ] || continue
1580 lzcat $i | awk -F: -vP="$(gettext 'Package %s:')" -vT=$TMPLIST '
1581 BEGIN { last = "" }
1582 $2 ~ /'$2'/ {
1583 if (last != $1) {
1584 last = $1;
1585 PP = P;
1586 sub(/%s/, $1, PP);
1587 printf("\n\e[1;33m%s\e[0;39m\n", PP);
1589 gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $2);
1590 print $2;
1591 printf "%s" 1 >> T;
1592 }'
1593 done
1595 else
1597 # Check all pkg files.list in search match which specify the package
1598 # name and the full path to the file(s).
1599 for pkg in $INSTALLED/*; do
1600 if grep -qs "$2" $pkg/files.list; then
1601 . $pkg/receipt
1602 newline
1603 emsg "<c 33>$(_ 'Package %s:' $PACKAGE)</c>"
1604 awk -vT=$TMPLIST '
1605 /'$2'/ {
1606 gsub(/'$2'/, "\e[0;32m'$2'\e[0;39m", $0);
1607 print " "$0;
1608 printf "%s" 1 >> T;
1610 ' $pkg/files.list
1611 fi
1612 done
1614 fi
1616 match=$(wc -m < $TMPLIST)
1617 rm $TMPLIST
1619 footer "$(emsg "$(_p \
1620 '%s file' '%s files' $match \
1621 "<c 32>$match</c>")")"
1622 ;;
1625 search-pkgname)
1626 # Search for a package name
1627 if [ -z "$2" ]; then
1628 newline
1629 _ 'Please specify a pattern or file name to search for.'
1630 echo "$(_ 'Example:') 'tazpkg search-pkgname libnss'"
1631 newline
1632 exit 0
1633 fi
1634 title 'Search result for package "%s"' $2
1636 # Search for a file on mirror and output only the package name
1637 TMPLIST=$(mktemp)
1638 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1639 [ -f $i ] || continue
1640 lzcat $i | awk -F: -vT=$TMPLIST '
1641 BEGIN { P = "" }
1642 $2 ~ /'$2'/ {
1643 if ($1 != P) {
1644 print $1;
1645 printf "%s" 1 >> T;
1646 P = $1
1648 }'
1649 done
1650 match=$(wc -m < $TMPLIST)
1651 rm $TMPLIST
1653 footer "$(emsg "$(_p \
1654 '%s package' '%s packages' $match \
1655 "<c 32>$match</c>")")"
1656 ;;
1659 install|-i)
1660 # Install .tazpkg packages.
1661 check_root $@
1662 check_for_package_on_cmdline
1663 check_for_package_file
1664 check_for_installed_info
1666 if [ -n "$root" ]; then
1667 ROOT="$root";
1668 check_base_dir "$root"
1669 fi
1670 [ "$list" ] && INSTALL_LIST="$list"
1671 if [ "$rootconfig" ]; then
1672 if [ "$root" ]; then
1673 CACHE_DIR=$root/$CACHE_DIR
1674 SAVE_CACHE_DIR=$CACHE_DIR
1675 PKGS_DB=$root/$PKGS_DB
1676 else
1677 echo "rootconfig needs --root= option used." >&2
1678 exit 1
1679 fi
1680 fi
1682 # Get repositories priority list.
1683 look_for_priority
1685 # Check if forced install.
1686 if [ -z "$forced" ]; then
1687 check_for_installed_package $ROOT
1688 fi
1689 install_package $ROOT
1690 update_desktop_database $ROOT
1691 update_mime_database $ROOT
1692 update_icon_database $ROOT
1693 compile_glib_schemas $ROOT
1694 ;;
1697 install-list|get-install-list)
1698 # Install a set of packages from a list.
1699 check_root $@
1700 if [ -z "$2" ]; then
1701 newline
1702 longline "$(_ \
1703 "Please change directory (cd) to the packages repository and specify the \
1704 list of packages to install.")"
1705 echo "$(_ 'Example:') $(emsg '<b>tazpkg install-list</b> <c 33>packages.list</c>')"
1706 exit 0
1707 fi
1709 # Check if the packages list exist.
1710 if [ ! -f "$2" ]; then
1711 _ 'Unable to find list "%s"' "$2"
1712 exit 0
1713 fi
1715 LIST=$(cat $2)
1717 # Remember processed list
1718 export INSTALL_LIST="$2"
1720 # Set $COMMAND and install all packages.
1721 COMMAND=${1%-list}
1723 touch $2-processed
1725 # Upgrade tazpkg first. It may handle new features/formats...
1726 # then upgrade essential packages early
1727 for pkg in busybox-pam busybox gcc-lib-base glibc-base \
1728 slitaz-base-files tazpkg ; do
1729 pkg=$(egrep $pkg-[0-9] $INSTALL_LIST)
1730 [ -z "$pkg" ] && continue
1731 _ 'Adding implicit depends "%s"...' $pkg
1732 LIST="$pkg
1733 $LIST"
1734 done
1736 for pkg in $LIST; do
1737 grep -qs ^$pkg$ $2-processed && continue
1738 [ -d "$root/var/lib/tazpkg/installed" ] &&
1739 tazpkg $COMMAND $pkg --list="$2" "$3" "$4" "$5"
1740 done
1741 rm -f $2-processed ;;
1744 add-flavor)
1745 # Install a set of packages from a flavor.
1746 install_flavor $2 ;;
1749 install-flavor)
1750 # Install a set of packages from a flavor and purge other ones.
1751 install_flavor $2 --purge ;;
1754 set-release)
1755 # Change current release and upgrade packages.
1756 RELEASE=$2
1757 if [ -z "$RELEASE" ]; then
1758 newline
1759 _ 'Please specify the release you want on the command line.'
1760 echo "$(_ 'Example:') tazpkg set-release cooking"
1761 newline
1762 exit 0
1763 fi
1764 rm $PKGS_DB/mirror
1765 echo "$RELEASE" > /etc/slitaz-release
1766 tazpkg recharge && tazpkg upgrade
1768 # Install missing depends
1769 cd $INSTALLED
1770 for i in * ; do
1771 DEPENDS=""
1772 . $i/receipt
1773 for j in $DEPENDS ; do
1774 [ -d $j ] || tazpkg get-install $j
1775 done
1776 done ;;
1779 remove|-r)
1780 # Remove packages.
1781 check_root $@
1782 check_for_package_on_cmdline
1783 check_for_installed_info
1785 [ -n "$root" ] && ROOT="$root"
1786 if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then
1787 newline
1788 _ 'Package "%s" is not installed.' $PACKAGE
1789 exit 0
1790 else
1791 ALTERED=""
1792 THE_PACKAGE=$PACKAGE # altered by receipt
1793 for i in $(cd $ROOT$INSTALLED ; ls); do
1794 [ -f $ROOT$INSTALLED/$i/receipt ] || continue
1795 DEPENDS=""
1796 . $ROOT$INSTALLED/$i/receipt
1797 case " $(echo $DEPENDS) " in
1798 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
1799 esac
1800 done
1801 EXTRAVERSION=""
1802 . $ROOT$INSTALLED/$THE_PACKAGE/receipt
1803 fi
1804 newline
1805 if [ -n "$ALTERED" ]; then
1806 _ 'The following packages depend on package "%s":' $PACKAGE
1807 for i in $ALTERED; do
1808 echo " $i"
1809 done
1810 fi
1811 REFRESH=$(cd $ROOT$INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1812 if [ -n "$REFRESH" ]; then
1813 _ 'The following packages have been modified by package "%s":' $PACKAGE
1814 for i in $REFRESH; do
1815 echo " ${i%/modifiers}"
1816 done
1817 fi
1818 if [ "$auto" ]; then
1819 answer=0
1820 else
1821 confirm "$(_ 'Remove package "%s" (%s)? (y/N)' $PACKAGE $VERSION$EXTRAVERSION)"
1822 answer=$?
1823 fi
1824 if [ $answer = 0 ]; then
1825 title 'Removing package "%s"' $PACKAGE
1826 # Pre remove commands.
1827 if grep -q ^pre_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1828 pre_remove $ROOT
1829 fi
1830 action "Removing all files installed..."
1831 if [ -f $ROOT$INSTALLED/$PACKAGE/modifiers ]; then
1832 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1833 for mod in $(cat $ROOT$INSTALLED/$PACKAGE/modifiers); do
1834 [ -f $ROOT$INSTALLED/$mod/files.list ] && [ $(grep "^$(echo $file | grepesc)$" $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && continue 2
1835 done
1836 remove_with_path $ROOT$file
1837 done
1838 else
1839 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1840 remove_with_path $ROOT$file
1841 done
1842 fi
1843 status
1844 if grep -q ^post_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1845 post_remove $ROOT
1846 fi
1848 # Remove package receipt.
1849 action "Removing package receipt..."
1850 rm -rf $ROOT$INSTALLED/$PACKAGE
1851 status
1853 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION$/d" \
1854 $PKGS_DB/installed.$SUM 2> /dev/null
1856 # Update installed.info
1857 sed -i "/^$PACKAGE /d" $PKGS_DB/installed.info
1859 # Log this activity
1860 log_pkg Removed
1862 if [ "$ALTERED" ]; then
1863 if [ "$auto" ]; then
1864 answer=0
1865 else
1866 confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' $PACKAGE)"
1867 answer=$?
1868 fi
1869 if [ $answer = 0 ]; then
1870 for i in $ALTERED; do
1871 if [ -d "$ROOT$INSTALLED/$i" ]; then
1872 tazpkg remove $i $ROOTOPTS
1873 fi
1874 done
1875 fi
1876 fi
1877 if [ "$REFRESH" ]; then
1878 if [ "$auto" ]; then
1879 answer=0
1880 else
1881 confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' $PACKAGE)"
1882 answer=$?
1883 fi
1884 if [ $answer = 0 ]; then
1885 for i in $REFRESH; do
1886 if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then
1887 _ 'Check %s for reinstallation' "$INSTALLED/$i"
1888 continue
1889 fi
1890 rm -r $ROOT$INSTALLED/$i
1891 tazpkg get-install ${i%/modifiers} $ROOTOPTS --forced
1892 done
1893 fi
1894 fi
1895 else
1896 newline
1897 _ 'Uninstallation of package "%s" cancelled.' $PACKAGE
1898 fi
1899 newline ;;
1902 extract|-e)
1903 # Extract .tazpkg cpio archive into a directory.
1904 check_for_package_on_cmdline
1905 check_for_package_file
1906 title 'Extracting package "%s"' $PACKAGE
1908 # If no directory destination is found on the cmdline
1909 # we create one in the current dir using the package name.
1910 if [ -n "$TARGET_DIR" ]; then
1911 DESTDIR=$TARGET_DIR/$PACKAGE
1912 else
1913 DESTDIR=$PACKAGE
1914 fi
1915 mkdir -p $DESTDIR
1917 action "Copying original package..."
1918 cp $PACKAGE_FILE $DESTDIR
1919 status
1921 cd $DESTDIR
1922 extract_package
1923 [ -e "receipt" ] && \
1924 footer "$(_ 'Package "%s" is extracted to "%s"') $PACKAGE $DESTDIR"
1925 ;;
1928 recompress)
1929 # Recompress .tazpkg cpio archive with lzma.
1930 check_for_package_on_cmdline
1931 check_for_package_file
1932 title 'Recompressing package "%s"' $PACKAGE
1933 mkdir -p $TMP_DIR
1935 action "Copying original package..."
1936 cp $PACKAGE_FILE $TMP_DIR
1937 status
1939 cd $TMP_DIR
1940 extract_package
1942 action "Recompressing the FS..."
1943 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1944 rm -rf fs
1945 status
1947 action "Creating new package..."
1948 find . -print | cpio -o -H newc --quiet > \
1949 $TOP_DIR/$(basename $PACKAGE_FILE).$$ && mv -f \
1950 $TOP_DIR/$(basename $PACKAGE_FILE).$$ \
1951 $TOP_DIR/$(basename $PACKAGE_FILE)
1952 status
1954 cd $TOP_DIR
1955 rm -rf $TMP_DIR
1956 separator; newline ;;
1959 list-config)
1960 # List configuration files installed.
1961 if [ -n "$box" ]; then
1962 mkdir -p $TMP_DIR; cd $TMP_DIR
1963 FILES="$INSTALLED/*/volatile.cpio.gz"
1964 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
1965 for i in $FILES; do
1966 zcat $i | cpio -idm --quiet > /dev/null
1967 find * -type f 2>/dev/null | while read file; do
1968 if [ ! -e /$file ]; then
1969 echo -n "----------|----|----|$(_n 'File lost')"
1970 else
1971 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
1972 cmp $file /$file > /dev/null 2>&1 || \
1973 echo -n "$(stat -c "%.16y" /$file)"
1974 fi
1975 echo "|/$file"
1976 done
1977 rm -rf *
1978 done
1979 cd $TOP_DIR
1980 rm -rf $TMP_DIR
1981 else
1982 im && title 'Configuration files'
1983 for i in $INSTALLED/*/volatile.cpio.gz; do
1984 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
1985 [ -f "$i" ] || continue
1986 zcat $i | cpio -t --quiet
1987 done | sed 's|^|/|' | sort
1988 im && footer
1989 fi ;;
1992 repack-config)
1993 # Create SliTaz package archive from configuration files.
1994 mkdir -p $TMP_DIR; cd $TMP_DIR
1995 CONFIG_VERSION=1.0
1996 mkdir config-$CONFIG_VERSION
1997 cd config-$CONFIG_VERSION
1998 for i in $INSTALLED/*/volatile.cpio.gz; do
1999 zcat $i | cpio -t --quiet
2000 done > files.list
2001 mkdir fs
2002 cd fs
2003 ( cd / ; cpio -o -H newc --quiet ) < ../files.list | cpio -idm --quiet > /dev/null
2004 mkdir -p etc/tazlito
2005 for i in $INSTALLED/*/receipt; do
2006 EXTRAVERSION=""
2007 . $i
2008 echo "$PACKAGE-$VERSION$EXTRAVERSION"
2009 done > etc/tazlito/config-packages.list
2010 cd ..
2011 echo "etc/tazlito/config-packages.list" >> files.list
2012 pkg_date=$(date +"%x %X")
2013 cat > receipt <<EOT
2014 # SliTaz package receipt.
2016 PACKAGE="config"
2017 VERSION="$CONFIG_VERSION"
2018 CATEGORY="base-system"
2019 SHORT_DESC="$(_n 'User configuration backup on date %s' $pkg_date)"
2020 DEPENDS="$(ls $INSTALLED)"
2021 EOT
2022 cd ..
2023 tazpkg pack config-$CONFIG_VERSION
2024 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
2025 cd $TOP_DIR
2026 rm -rf $TMP_DIR
2027 ;;
2030 repack)
2031 # Create SliTaz package archive from an installed package.
2032 check_for_package_on_cmdline
2033 check_for_receipt
2034 EXTRAVERSION=""
2035 . $INSTALLED/$PACKAGE/receipt
2036 title 'Repacking "%s"' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
2038 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
2039 _ "Can't repack package \"%s\"" $PACKAGE
2040 exit 1
2041 fi
2043 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
2044 _ "Can't repack, \"%s\" files have been modified by:" $PACKAGE
2045 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
2046 echo " $i"
2047 done
2048 exit 1
2049 fi
2051 MISSING=""
2052 while read i; do
2053 [ -e "$i" ] && continue
2054 [ -L "$i" ] || MISSING="$MISSING\n $i"
2055 done < $INSTALLED/$PACKAGE/files.list
2056 if [ -n "$MISSING" ]; then
2057 _n "Can't repack, the following files are lost:"
2058 echo -e "$MISSING"
2059 exit 1
2060 fi
2062 mkdir -p $TMP_DIR; cd $TMP_DIR
2063 FILES="fs.cpio.lzma\n"
2064 for i in $(ls $INSTALLED/$PACKAGE); do
2065 case $i in
2066 volatile.cpio.gz|modifiers) ;;
2067 *) cp $INSTALLED/$PACKAGE/$i .; FILES="$FILES$i\n" ;;
2068 esac
2069 done
2071 ln -s / rootfs
2072 mkdir tmp
2073 sed 's/^/rootfs/' < files.list | cpio -o -H newc --quiet | \
2074 { cd tmp ; cpio -idm --quiet >/dev/null; cd ..; }
2075 mv tmp/rootfs fs
2077 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
2078 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
2079 { cd fs; cpio -idm --quiet; cd ..; }
2080 fi
2082 if fgrep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
2083 . $INSTALLED/$PACKAGE/receipt
2084 repack_cleanup fs
2085 fi
2087 if [ -f $INSTALLED/$PACKAGE/$CHECKSUM ]; then
2088 sed 's, , fs,' < $INSTALLED/$PACKAGE/$CHECKSUM | \
2089 $CHECKSUM -s -c || {
2090 _ "Can't repack, %s error." $CHECKSUM
2091 cd $TOP_DIR
2092 rm -rf $TMP_DIR
2093 exit 1
2095 fi
2097 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2098 echo -e "$FILES" | cpio -o -H newc --quiet > \
2099 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
2100 cd $TOP_DIR
2101 \rm -R $TMP_DIR
2102 _ 'Package "%s" repacked successfully.' $PACKAGE
2103 _ 'Size: %s' "$(du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg)"
2104 newline ;;
2107 pack)
2108 # Create SliTaz package archive using cpio and lzma.
2109 # TODO: Cook also pack packages, we should share code in libpkg.sh
2110 check_for_package_on_cmdline
2111 cd $PACKAGE
2112 if [ ! -f "receipt" ]; then
2113 _ 'Receipt is missing. Please read the documentation.'
2114 exit 0
2115 fi
2117 title 'Packing package "%s"' $PACKAGE
2118 # Create files.list with redirecting find outpout.
2120 action "Creating the list of files..."
2121 cd fs
2122 find . -type f -print > ../files.list
2123 find . -type l -print >> ../files.list
2124 cd .. && sed -i s/'^.'/''/ files.list
2125 status
2127 action 'Creating %s of files...' $CHECKSUM
2128 while read file; do
2129 [ -L "fs$file" ] && continue
2130 [ -f "fs$file" ] || continue
2131 case "$file" in
2132 /lib/modules/*/modules.*|*.pyc) continue;;
2133 esac
2134 $CHECKSUM "fs$file" | sed 's/ fs/ /'
2135 done < files.list > $CHECKSUM
2136 status
2138 UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
2139 description.txt 2> /dev/null | awk \
2140 '{ sz=$1 } END { print sz }')
2141 # Build cpio archives.
2143 action "Compressing the FS..."
2144 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2145 rm -rf fs
2146 status
2148 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
2149 $CHECKSUM description.txt 2> /dev/null | awk \
2150 '{ sz=$1 } END { print sz }')
2152 action "Updating receipt sizes..."
2153 sed -i s/^PACKED_SIZE.*$// receipt
2154 sed -i s/^UNPACKED_SIZE.*$// receipt
2155 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
2156 status
2158 action "Creating full cpio archive..."
2159 find . -print | cpio -o -H newc --quiet > ../$PACKAGE.tazpkg
2160 status
2162 action "Restoring original package tree..."
2163 unlzma -c fs.cpio.lzma | cpio -idm --quiet
2164 status
2166 rm fs.cpio.lzma && cd ..
2167 footer "$(_ 'Package "%s" compressed successfully.' $PACKAGE)"
2168 _ 'Size: %s' "$(ls -lh $PACKAGE.tazpkg | awk '{print $5}')"
2169 ;;
2172 recharge)
2173 # Recharge packages.list from a mirror.
2175 # WARNING: The 'mirrors' file has all SliTaz mirrors but 'mirror'
2176 # must have only the chosen main mirror.
2178 check_root $@
2180 ARG=$2
2181 if [ "$root" ]; then
2182 PKGS_DB=$root$PKGS_DB
2183 [ "${2#--}" != "$2" ] && ARG=$3
2184 fi
2185 if [ "$ARG" = main ]; then
2186 repository_to_recharge=$PKGS_DB
2187 elif [ "$ARG" ]; then
2188 if [ -d "$PKGS_DB/undigest/$ARG" ]; then
2189 repository_to_recharge=$PKGS_DB/undigest/$ARG
2190 else
2191 repo="$PKGS_DB/undigest/$ARG"
2192 _ "Repository \"%s\" doesn't exist." $repo >&2
2193 exit 1
2194 fi
2195 else
2196 repository_to_recharge="$PKGS_DB $PKGS_DB/undigest/*"
2197 fi
2198 for path in $repository_to_recharge; do
2199 [ -f $path/mirror ] || continue
2200 cd $path
2202 # Quietly check if recharging is needed.
2203 [ -f ID ] && mv ID ID.bak
2204 download_from "$(cat mirror)" ID >/dev/null 2>/dev/null
2205 if [ -f ID ] && fgrep -q $(cat ID.bak 2>/dev/null || echo "null") ID; then
2206 if [ "$path" = "$PKGS_DB" ]; then
2207 repository_name=Main
2208 else
2209 base_path="$(basename $path)"
2210 repository_name="$(_n 'Undigest %s' $base_path)"
2211 fi
2212 _ 'Repository "%s" is up to date.' "$repository_name"
2213 rm ID.bak
2214 continue
2215 fi
2217 # Don't let ID be a symlink when using local repository.
2218 if [ -f ID ]; then
2219 mv -f ID ID.bak
2220 cat ID.bak > ID
2221 rm ID.bak
2222 fi
2224 newline
2225 if [ "$path" != "$PKGS_DB" ]; then
2226 base_path="$(basename $path)"
2227 _ 'Recharging undigest %s:' $base_path
2228 fi
2230 if [ -f "packages.list" ]; then
2231 action "Creating backup of the last packages list..."
2232 for i in packages.desc packages.$SUM packages.txt \
2233 packages.list packages.equiv files.list.lzma \
2234 extra.list mirrors packages.info
2235 do
2236 mv -f $i $i.bak 2>/dev/null
2237 done
2238 status
2239 fi
2241 for i in desc $SUM txt list equiv; do
2242 download_from "$(cat mirror)" packages.$i
2243 done
2244 download_from "$(cat mirror)" files.list.lzma
2245 download_from "$(cat mirror)" extra.list
2246 download_from "$(sed 's|packages/.*||' mirror)" mirrors
2248 # packages.info
2249 download_from "$(cat mirror)" packages.info.lzma
2250 lzma d packages.info.lzma packages.info
2251 rm packages.info.lzma
2253 if [ -f "packages.list.bak" ]; then
2254 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
2255 [ -f "extra.list.bak" ] &&
2256 diff -u extra.list.bak extra.list | grep ^+[a-z] >> packages.diff
2257 sed -i s/+// packages.diff
2258 title 'Mirrored packages diff'
2259 cat packages.diff
2260 new_pkgs=$(wc -l < packages.diff)
2261 footer "$(emsg "$(_p \
2262 '%s new package on the mirror.' \
2263 '%s new packages on the mirror.' $new_pkgs \
2264 "<c 32>$new_pkgs</c>")")"
2265 else
2266 footer "$(longline "$(_ "Last %s is ready to use. Note that \
2267 next time you recharge the list, a list of differences will be displayed to \
2268 show new and upgradeable packages." packages.list)")"
2269 fi
2270 done ;;
2273 help-up)
2274 # Options available for the command: up
2275 newline; usage_up; newline
2276 exit 1 ;;
2279 up|upgrade)
2280 check_root
2282 # This is the new way to upgrade packages making 'upgrade' and
2283 # upgradeable out-of-date. This new way is much, much more faster!
2284 # Look into installed packages and get data from receipt, it is fast
2285 # and easy to handle vars after using only md5sum to compare packages
2287 for opt in $@; do
2288 case "$opt" in
2289 --recharge|-r) tazpkg recharge ;;
2290 --install|-i) install="y" ;;
2291 --check|-c) install="n" ;;
2292 esac
2293 done
2294 time=$(date +%s)
2296 look_for_priority
2297 for repo in $priority; do
2298 pkg_list=$repo/packages.list
2299 mtime=$(find $pkg_list -mtime +7)
2300 if [ "$mtime" ]; then
2301 if [ "$repo" == "$PKGS_DB" ]; then
2302 repo_name=main
2303 else
2304 repo_name="${repo##*/}"
2305 fi
2306 _ 'List "%s" is older than one week... Recharging.' $pkg_list
2307 tazpkg recharge $repo_name
2308 fi
2309 done
2311 emsg "<n>$(_ 'Package')<i 28> $(_ 'Version')<i 48> $(_ 'Status')<->"
2313 cd $INSTALLED
2314 echo -n > $UP_LIST
2315 blocked_count=0
2316 installed_sum=$PKGS_DB/installed.$SUM
2318 for pkg in *; do
2319 [ ! -d $pkg ] && continue
2320 unset VERSION EXTRAVERSION
2321 . $pkg/receipt
2322 md5=$(fgrep " $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" \
2323 $installed_sum | awk '{print $1}')
2324 for repo in $priority; do
2325 pkg_desc=$repo/packages.desc
2326 pkg_list=$repo/packages.list
2327 pkg_sum=$repo/packages.$SUM
2329 if ! fgrep -q "$md5 $PACKAGE-" $pkg_sum; then
2330 # Jump to next repository in priority if pkg doesn't exist
2331 # in this one.
2332 grep -q ^$PACKAGE- $pkg_list || continue
2334 emsg -n "$PACKAGE<i 28> $VERSION"
2336 # Skip pkgs listed in $PKGS_DB/blocked-packages.list
2337 if $(grep -qs "^$PACKAGE" $BLOCKED); then
2338 blocked_count=$(($blocked_count + 1))
2339 emsg "<i 48><c 31> $(_ 'Blocked')</c>"
2340 break
2341 fi
2343 new=$(grep "^$PACKAGE |" $pkg_desc | awk '{print $3}')
2345 if [ "$VERSION" == "$new" ]; then
2346 emsg "<i 48><c 34> $(_ 'New build')</c>"
2347 else
2348 emsg "<i 48><c 32> $(_ 'New version %s' $new)</c>"
2349 fi
2350 echo "$PACKAGE" >> $UP_LIST
2351 break
2352 fi
2353 done
2354 done
2355 sed -i /^$/d $UP_LIST
2356 upnb=$(wc -l < $UP_LIST)
2357 pkgs=$(ls | wc -l)
2358 time=$(($(date +%s) - $time))
2359 if [ "$upnb" == 0 ]; then
2360 install="n"
2361 _ 'System is up-to-date...'
2362 fi
2364 footer "$(emsg "$(_p \
2365 '%s installed package scanned in %ds' \
2366 '%s installed packages scanned in %ds' $pkgs \
2367 "<c 32>$pkgs</c>" $time)")"
2369 if [ "$upnb" != 0 ]; then
2370 blocked="$(_p \
2371 '%s blocked' \
2372 '%s blocked' $blocked_count \
2373 $blocked_count)"
2375 boldify "$(_p \
2376 'You have %s available upgrade (%s)' \
2377 'You have %s available upgrades (%s)' $upnb \
2378 $upnb "$blocked")"
2379 newline
2380 fi
2381 # Pkgs to upgrade ? Skip, let install them all or ask user
2382 [ "$install" == "n" ] && exit 0
2383 if [ "$upnb" -gt 0 ]; then
2384 if [ "$install" == "y" ]; then
2385 continue
2386 else
2387 confirm "$(_ 'Do you wish to install them now? (y/N)')"
2388 answer=$?
2389 fi
2390 case "$answer" in
2391 0)
2392 for pkg in $(cat $UP_LIST); do
2393 echo 'y' | tazpkg get-install $pkg --forced
2394 done
2395 # List is generated each time and must be cleaned so
2396 # tazpkg-notify doesn't find upgrades anymore.
2397 rm $UP_LIST; touch $UP_LIST ;;
2398 *)
2399 _ 'Leaving without any upgrades installed.'
2400 newline
2401 exit 0 ;;
2402 esac
2403 fi
2404 newline ;;
2407 bugs)
2408 # Show known bugs in package(s)
2409 cd $INSTALLED
2410 shift
2411 LIST=$@
2412 [ -n "$LIST" ] || LIST=$(ls)
2413 MSG=$(_n 'No known bugs.')
2414 for PACKAGE in $LIST; do
2415 BUGS=""
2416 EXTRAVERSION=""
2417 . $PACKAGE/receipt
2418 if [ -n "$BUGS" ]; then
2419 MSG=$(_n 'Bug list completed')
2420 newline
2421 _ 'Bugs in package "%s" version %s:' $PACKAGE $VERSION$EXTRAVERSION
2422 cat <<EOT
2423 $BUGS
2424 EOT
2425 fi
2426 done
2427 echo "$MSG" ;;
2430 check)
2431 # Check installed packages set.
2432 check_root $@
2434 # Get repositories priority list.
2435 look_for_priority
2437 cd $INSTALLED
2438 for PACKAGE in $(ls); do
2440 if [ ! -f $PACKAGE/receipt ]; then
2441 _ 'The package "%s" installation has not completed' $PACKAGE
2442 continue
2443 fi
2445 DEPENDS=""
2446 EXTRAVERSION=""
2447 . $PACKAGE/receipt
2448 if [ -s $PACKAGE/modifiers ]; then
2449 _ 'The package "%s" has been modified by:' $PACKAGE-$VERSION$EXTRAVERSION
2450 for i in $(cat $PACKAGE/modifiers); do
2451 echo " $i"
2452 done
2453 fi
2455 MSG="$(_n 'Files lost from package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2456 while read file; do
2457 [ -e "$file" ] && continue
2458 if [ -L "$file" ]; then
2459 MSG="$MSG $(_n 'target of symlink')"
2460 fi
2461 echo -e "$MSG $file"
2462 MSG=""
2463 done < $PACKAGE/files.list
2465 MSG="$(_n 'Missing dependencies for package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2466 for i in $DEPENDS; do
2467 [ -d $i ] && continue
2468 [ -d $(equivalent_pkg $i) ] && continue
2469 echo -e "$MSG $i"
2470 MSG=""
2471 done
2473 MSG="$(_n 'Dependencies loop between "%s" and:' $PACKAGE)\n"
2474 ALL_DEPS=""
2475 check_for_deps_loop $PACKAGE $DEPENDS
2476 done
2478 _ 'Looking for known bugs...'
2479 tazpkg bugs
2481 if [ "$2" == "--full" ]; then
2482 separator
2484 for file in */$CHECKSUM; do
2485 CONFIG_FILES=""
2486 . $(dirname "$file")/receipt
2487 [ -s "$file" ] || continue
2488 while read md5 f; do
2489 [ -f $f ] || continue
2490 for i in $CONFIG_FILES; do
2491 case "$f" in
2492 $i|$i/*) continue 2;;
2493 esac
2494 done
2495 echo "$md5 $f"
2496 done < "$file" | busybox $CHECKSUM -c - 2> /dev/null | \
2497 grep -v OK$ | sed "s/FAILED$/$CHECKSUM MISMATCH/"
2498 done
2500 FILES=" "
2501 for file in $(cat */files.list); do
2502 [ -d "$file" ] && continue
2503 case "$FILES" in *\ $file\ *) continue;; esac
2504 [ $(grep "^$(echo $file | grepesc)$" */files.list 2> /dev/null | \
2505 wc -l) -gt 1 ] || continue
2506 FILES="$FILES$file "
2507 _ 'The following packages provide file "%s":' $file
2508 grep -l "^$(echo $file | grepesc)$" */files.list | \
2509 while read f; do
2510 pkg=${f%/files.list}
2511 if [ -f $pkg/modifiers ]; then
2512 overriders=$(_n '(overridden by %s)' "$(tr '\n' ' ' | sed 's| $||' < $pkg/modifiers)")
2513 else
2514 overriders=''
2515 fi
2516 echo -n " $pkg $overriders"
2517 newline
2518 done
2519 done
2521 MSG="$(_n 'No package has installed the following files:')\n"
2522 find /etc /bin /sbin /lib /usr /var/www -not -type d 2>/dev/null | \
2523 while read file; do
2524 case "$file" in *\[*) continue;; esac
2525 grep -q "^$(echo $file | grepesc)$" */files.list && continue
2526 echo -e "$MSG $file"
2527 MSG=""
2528 done
2529 fi
2530 _ 'Check completed.'; echo ;;
2533 block)
2534 # Add a pkg name to the list of blocked packages.
2535 check_root $@
2536 check_for_package_on_cmdline
2537 newline
2538 if [ ! -d $INSTALLED/$PACKAGE ]; then
2539 _ 'Package "%s" is not installed.' $PACKAGE; exit
2540 fi
2541 if grep -qs "^$PACKAGE" $BLOCKED; then
2542 _ 'Package "%s" is already blocked.' $PACKAGE
2543 else
2544 echo $PACKAGE >> $BLOCKED
2545 # Log this activity
2546 . $INSTALLED/$PACKAGE/receipt; log_pkg Blocked
2547 _ 'Package "%s" blocked.' $PACKAGE
2548 fi
2549 newline ;;
2552 unblock)
2553 # Remove a pkg name from the list of blocked packages.
2554 check_root $@
2555 check_for_package_on_cmdline
2556 newline
2557 if [ ! -d $INSTALLED/$PACKAGE ]; then
2558 _ 'Package "%s" is not installed.' $PACKAGE; exit
2559 fi
2560 if grep -qs "^$PACKAGE" $BLOCKED; then
2561 sed -i "/^$PACKAGE\$/d" $BLOCKED
2562 # Log this activity
2563 . $INSTALLED/$PACKAGE/receipt; log_pkg Unblocked
2564 _ 'Package "%s" unblocked.' $PACKAGE
2565 else
2566 _ 'Package "%s" is not blocked.' $PACKAGE
2567 fi
2568 newline ;;
2571 chblock)
2572 # Change package's blocked status.
2573 check_root $@
2574 check_for_package_on_cmdline
2575 newline
2576 if [ ! -d $INSTALLED/$PACKAGE ]; then
2577 _ 'Package "%s" is not installed.' $PACKAGE; exit
2578 fi
2579 if grep -qs "^$PACKAGE" $BLOCKED; then
2580 sed -i "/^$PACKAGE\$/d" $BLOCKED
2581 # Log this activity
2582 . $INSTALLED/$PACKAGE/receipt; log_pkg Unblocked
2583 _ 'Package "%s" unblocked.' $PACKAGE
2584 else
2585 echo $PACKAGE >> $BLOCKED
2586 # Log this activity
2587 . $INSTALLED/$PACKAGE/receipt; log_pkg Blocked
2588 _ 'Package "%s" blocked.' $PACKAGE
2589 fi
2590 newline ;;
2593 get)
2594 # Download a package with wget.
2595 check_root $@
2596 check_for_package_on_cmdline
2597 check_for_packages_list
2599 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2600 if [ "$rootconfig" ]; then
2601 if [ "$root" ]; then
2602 CACHE_DIR=$root/$CACHE_DIR
2603 SAVE_CACHE_DIR=$CACHE_DIR
2604 PKGS_DB=$root/$PKGS_DB
2605 else
2606 _ 'rootconfig needs --root= option used.' >&2
2607 exit 1
2608 fi
2609 fi
2611 # Get repositories priority list.
2612 look_for_priority
2614 CURRENT_DIR=$PWD
2615 check_for_package_in_list
2616 cd $CACHE_DIR
2617 if [ -f "$PACKAGE.tazpkg" ]; then
2618 _ 'Package "%s" already in the cache' $PACKAGE
2619 # Check package download was finished
2620 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2621 _ 'Continuing package "%s" download' $PACKAGE
2622 download $PACKAGE.tazpkg
2624 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2625 rm -f $PACKAGE.tazpkg
2626 download $PACKAGE.tazpkg
2627 fi
2628 else
2629 download $PACKAGE.tazpkg
2630 fi
2631 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2632 cp -a $PACKAGE_FILE $CURRENT_DIR ;;
2635 get-install|-gi)
2636 # Download and install a package.
2637 check_root $@
2638 check_for_package_on_cmdline
2639 check_for_packages_list
2641 DO_CHECK=""
2642 [ "$forced" ] && DO_CHECK=no
2643 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2644 [ "$list" ] && INSTALL_LIST="$list"
2645 if [ "$rootconfig" ]; then
2646 if [ "$root" ]; then
2647 CACHE_DIR=$root/$CACHE_DIR
2648 SAVE_CACHE_DIR=$CACHE_DIR
2649 PKGS_DB=$root/$PKGS_DB
2650 else
2651 _ 'rootconfig needs --root= option used.' >&2
2652 exit 1
2653 fi
2654 fi
2656 # Get repositories priority list.
2657 look_for_priority
2659 AUTOEXEC="no"
2660 if ! check_for_package_in_list check; then
2661 CACHE_DIR="${CACHE_DIR%/*}/get"
2662 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
2663 if download_get_script $PACKAGE /tmp/$PACKAGE.$$ ; then
2664 install_package_from_get_script /tmp/$PACKAGE.$$ $ROOT
2665 exit 0
2666 else
2667 PACKAGE=get-$PACKAGE
2668 AUTOEXEC=$PACKAGE
2669 check_for_package_in_list
2670 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
2671 $AUTOEXEC $ROOT
2672 exit 0
2673 fi
2674 fi
2675 fi
2676 # Check if forced install.
2677 if ! [ "$forced" ]; then
2678 check_for_installed_package $ROOT
2679 fi
2680 cd $CACHE_DIR
2681 if [ -f "$PACKAGE.tazpkg" ]; then
2682 _ 'Package "%s" already in the cache' $PACKAGE
2683 # Check package download was finished
2684 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2685 _ 'Continuing package "%s" download' $PACKAGE
2686 download $PACKAGE.tazpkg
2688 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2689 rm -f $PACKAGE.tazpkg
2690 download $PACKAGE.tazpkg
2691 fi
2692 else
2693 newline
2694 download $PACKAGE.tazpkg
2695 fi
2696 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2697 [ "$rootconfig" ] && PKGS_DB=${PKGS_DB#$root}
2698 install_package $ROOT
2699 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
2700 update_desktop_database $ROOT
2701 update_mime_database $ROOT ;;
2704 clean-cache|-cc)
2705 # Remove all downloaded packages.
2706 check_root $@
2707 files=$(find $CACHE_DIR -name *.tazpkg | wc -l)
2708 size=$(du -hs $CACHE_DIR | cut -f1 | sed 's|\.0||'); [ $files == "0" ] && size="0K"
2709 title 'Path: %s' $CACHE_DIR
2710 action "Cleaning cache directory..."
2711 rm -rf $CACHE_DIR/*
2712 status
2714 footer "$(_p \
2715 '%s file removed from cache (%s).' \
2716 '%s files removed from cache (%s).' $files \
2717 "$(colorize 32 "$files")" $size)"
2718 ;;
2721 list-undigest)
2722 # list undigest URLs.
2723 if [ "$2" = "--box" ]; then
2724 for i in $PKGS_DB/undigest/*/mirror; do
2725 [ -f $i ] || continue
2726 echo "$(basename $(dirname $i))|$(cat $i)"
2727 done
2728 else
2729 title 'Current undigest(s)'
2730 for i in $PKGS_DB/undigest/*/mirror; do
2731 if [ ! -f $i ]; then
2732 _ 'No undigest mirror found.'
2733 exit 1
2734 fi
2735 echo "$(basename $(dirname $i)) $(cat $i)"
2736 done
2737 newline
2738 fi ;;
2741 remove-undigest)
2742 # remove undigest URL.
2743 check_root $@
2744 undigest="$2"
2745 if [ -d $PKGS_DB/undigest/$2 ]; then
2746 confirm "$(_ 'Remove "%s" undigest? (y/N)' $undigest)"
2747 if [ $? = 0 ]; then
2748 action 'Removing "%s" undigest...' $undigest
2749 rm -rf $PKGS_DB/undigest/$2
2750 status
2751 rmdir $PKGS_DB/undigest 2> /dev/null
2752 fi
2753 else
2754 _ 'Undigest "%s" not found' $undigest
2755 fi ;;
2758 add-undigest|setup-undigest)
2759 # Add undigest URL.
2760 check_root $@
2761 undigest=$2
2762 [ -d $PKGS_DB/undigest ] || mkdir $PKGS_DB/undigest
2763 if [ -z "$undigest" ]; then
2764 i=1
2765 while [ -d $PKGS_DB/undigest/$i ]; do
2766 i=$(($i+1))
2767 done
2768 undigest=$i
2769 fi
2770 if [ ! -d $PKGS_DB/undigest/$undigest ]; then
2771 _ 'Creating new undigest "%s".' $undigest
2772 mkdir $PKGS_DB/undigest/$undigest
2773 fi
2774 setup_mirror $PKGS_DB/undigest/$undigest $3 ;;
2777 setup-mirror|-sm)
2778 # Change mirror URL.
2779 check_root $@
2780 setup_mirror $PKGS_DB $2 ;;
2783 reconfigure)
2784 # Replay post_install from receipt
2785 check_for_package_on_cmdline
2786 check_root $@
2787 ROOT=""
2788 while [ -n "$3" ]; do
2789 case "$3" in
2790 --root=*)
2791 ROOT="${3#--root=}/" ;;
2792 *)
2793 shift 2
2794 u_opt="$*"
2795 newline >&2
2796 _ 'Unknown option "%s".' $u_opt >&2
2797 exit 1 ;;
2798 esac
2799 shift
2800 done
2801 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2802 check_for_receipt $ROOT
2803 # Check for post_install
2804 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2805 . $ROOT$INSTALLED/$PACKAGE/receipt
2806 post_install $ROOT
2807 # Log this activity
2808 [ -n "$ROOT" ] || log_pkg Reconfigured
2809 else
2810 newline
2811 _ 'Nothing to do for package "%s".' $PACKAGE
2812 fi
2813 else
2814 newline
2815 _ 'Package "%s" is not installed.' $PACKAGE
2816 _ 'Install package with "%s" or "%s"' 'tazpkg install' 'tazpkg get-install'
2817 newline
2818 fi ;;
2821 shell)
2822 # TazPKG SHell
2823 if test $(id -u) = 0 ; then
2824 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2825 else
2826 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2827 fi
2828 if [ ! "$2" = "--noheader" ]; then
2829 clear
2830 title 'TazPKG SHell.'
2831 _ "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
2832 newline
2833 fi
2834 while true; do
2835 echo -en "$PROMPT"; read cmd
2836 case $cmd in
2837 q|quit)
2838 break ;;
2839 shell)
2840 _ 'You are already running a TazPKG SHell.' ;;
2841 su)
2842 su -c 'exec tazpkg shell --noheader' && break ;;
2843 "")
2844 continue ;;
2845 *)
2846 tazpkg $cmd ;;
2847 esac
2848 done ;;
2851 depends)
2852 # Display dependencies tree
2853 cd $INSTALLED
2854 ALL_DEPS=""
2855 if [ -f $2/receipt ]; then
2856 dep_scan $2 ""
2857 fi ;;
2860 rdepends)
2861 # Display reverse dependencies tree
2862 cd $INSTALLED
2863 ALL_DEPS=""
2864 if [ -f $2/receipt ]; then
2865 rdep_scan $2
2866 fi ;;
2869 list-suggested)
2870 for i in $(ls -d $INSTALLED/*); do
2871 . $i/receipt
2872 if [ "$SUGGESTED" ]; then
2873 if [ -z "$all" ]; then
2874 for s in $SUGGESTED; do
2875 [ -d $INSTALLED/$s ] && \
2876 SUGGESTED=$(echo -n $SUGGESTED | sed "s/$s//")
2877 done
2878 fi
2879 cat << EOT
2880 $(boldify $(echo $PACKAGE):) $SUGGESTED
2881 EOT
2882 fi
2883 SUGGESTED=""
2884 done ;;
2887 convert|-c)
2888 # convert misc package format to .tazpkg
2889 check_for_package_file
2890 tazpkg-convert $@
2891 ;;
2894 link)
2895 # link a package from another slitaz installation
2896 PACKAGE=$2
2897 if [ ! -d "$TARGET_DIR" -o \
2898 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
2899 _ 'Usage: tazpkg link package_name slitaz_root'
2900 longline "$(
2901 _n 'Example:'
2902 echo -n ' '
2903 _ '"%s" will use less than 100k in your running system RAM.' \
2904 'tazpkg link openoffice /mnt')"
2905 exit 1
2906 fi
2907 if [ -e "$INSTALLED/$PACKAGE" ]; then
2908 _ 'Package "%s" is already installed.' $PACKAGE
2909 exit 1
2910 fi
2911 ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
2912 DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
2913 MISSING=""
2914 for i in $DEPENDS; do
2915 [ -e $INSTALLED/$i ] && continue
2916 MISSING="$MISSING$i "
2917 _ 'Missing: %s' $i
2918 done
2919 if [ -n "$MISSING" ]; then
2920 newline
2921 confirm "$(_ 'Link all missing dependencies? (y/N)')"
2922 answer=$?
2923 newline
2924 if [ $answer = 0 ]; then
2925 for i in $MISSING; do
2926 tazpkg link $i $TARGET_DIR
2927 done
2928 else
2929 newline
2930 _ 'Leaving dependencies unresolved for package "%s"' $PACKAGE
2931 _ 'The package is installed but probably will not work.'
2932 newline
2933 fi
2934 fi
2935 . $INSTALLED/$PACKAGE/receipt
2936 if grep -q ^pre_install $INSTALLED/$PACKAGE/receipt; then
2937 pre_install
2938 fi
2939 while read path; do
2940 [ -e $path ] && continue
2941 while true; do
2942 dir=$(dirname $path)
2943 [ -e $dir ] && break
2944 path=$dir
2945 done
2946 ln -s $TARGET_DIR$path $dir
2947 done < $INSTALLED/$PACKAGE/files.list
2948 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
2949 post_install
2950 fi ;;
2953 usage|*)
2954 # Print a short help or give usage for an unknown or empty command.
2955 usage ;;
2956 esac
2958 exit 0