tazpkg view tazpkg @ rev 807

Tiny edit
author Paul Issott <paul@slitaz.org>
date Mon May 25 06:24:54 2015 +0100 (2015-05-25)
parents 6ac7d1bf450b
children 046705e54b19
line source
1 #!/bin/sh
2 #
3 # TazPkg - Tiny autonomous zone packages manager.
4 #
5 # This is a lightweight packages manager for *.tazpkg files written in SHell
6 # script. It works well with Busybox ash shell and bash. TazPkg lets you
7 # list, install, remove, download or get information about a package. You
8 # can use 'tazpkg usage' to get a list of commands with short descriptions.
9 # TazPkg also resolves dependencies and can upgrade packages from a mirror.
10 #
11 # (C) 2007-2015 SliTaz - GNU General Public License v3.
12 #
13 # Authors: See the AUTHORS files
14 #
17 ####################
18 # Script variables #
19 ####################
21 # TazPkg version
22 VERSION='5.3.4'
24 . /etc/slitaz/slitaz.conf
25 . /etc/slitaz/tazpkg.conf
27 . /lib/libtaz.sh
28 . /usr/lib/slitaz/libpkg.sh
29 . /usr/lib/tazpkg/tazpkg-find-depends
31 # Internationalization.
32 export TEXTDOMAIN='tazpkg'
33 _() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; echo; }
34 _n() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; }
35 _p() {
36 local S="$1" P="$2" N="$3"; shift; shift; shift;
37 printf "$(ngettext "$S" "$P" "$N")" "$@"; }
40 #
41 # Functions set for translate categories
42 #
45 # Make array of pre-translated categories
47 cat_i18n=''
48 for c in 'base-system' 'x-window' 'utilities' 'network' 'graphics' \
49 'multimedia' 'office' 'development' 'system-tools' 'security' 'games' \
50 'misc' 'meta' 'non-free'; do
51 cat_i18n="$cat_i18n
52 $(gettext "$c") $c"
53 done
56 # Translate category names (must be last in line)
58 translate_category() {
59 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 echo "$cat_i18n" | awk "BEGIN{FS=\" \"}{if (/^$@ /) a=\$2}END{if (a==\"\") a=\"$@\"; print a}"
76 }
80 #
81 # TazPkg output functions
82 #
85 # Print localized title
87 title() {
88 case $output in
89 html)
90 echo "<section><header>$(_ "$@")</header><pre class=\"scroll\">";;
91 *)
92 newline; boldify "$(_ "$@")"; separator;;
93 esac
94 }
97 # Print footer
99 footer() {
100 case $output in
101 html)
102 echo "</pre><footer>$1</header></section>";;
103 *)
104 separator; echo "$1"; [ -n "$1" ] && newline;;
105 esac
106 }
109 # Print current action in brown color (separate from any other msgs)
111 action() {
112 case $output in
113 raw|gtk|html) _n "$@" ;;
114 *) echo -ne "\033[0;33m"$(_ "$@")"\033[0m" ;;
115 esac
116 }
119 # Initialize some variables to use words rather than numbers for functions
120 # and actions.
122 COMMAND="$1"
123 PACKAGE="${2%/}"
124 PACKAGE_DIR="$(cd $(dirname $PACKAGE 2>/dev/null) 2>/dev/null; pwd)"
125 [ -n "$PACKAGE" ] && PACKAGE_FILE="$PACKAGE_DIR/${PACKAGE##*/}"
126 if [ -f "$PACKAGE" ]; then
127 # Set pkg basename for install, extract
128 PACKAGE="$(basename $PACKAGE .tazpkg 2>/dev/null)"
129 else
130 # Pkg name for remove, search and all other cmds
131 PACKAGE="${PACKAGE%.tazpkg}"
132 fi
133 TARGET_DIR="$3"
134 TOP_DIR="$(pwd)"
135 TMP_DIR="/tmp/$RANDOM"
136 INSTALL_LIST=''
137 SAVE_CACHE_DIR="$CACHE_DIR"
139 # Path to tazpkg used dir and configuration files
140 MIRROR="$PKGS_DB/mirror"
141 BLOCKED="$PKGS_DB/blocked-packages.list"
142 UP_LIST="$PKGS_DB/packages.up"
143 DEFAULT_MIRROR="$ONLINE_PKGS"
148 ####################
149 # Script functions #
150 ####################
153 # Interactive mode
155 im() { tty -s; }
158 # Print the usage.
160 usage () {
161 cat <<EOT
163 $(_ 'SliTaz package manager - Version: %s' $(colorize 34 $VERSION))
165 $(boldify "$(_ 'Usage:')")
166 $(_ 'tazpkg [command] [package|dir|pattern|list|cat|--opt] [dir|--opt]')
168 $(boldify "$(_ 'SHell:')") tazpkg shell
170 $(boldify "$(_ 'Commands:')")
171 $(optlist "\
172 usage $(_ 'Print this short usage')
173 bugs $(_ 'Show known bugs in packages')
174 -a activity $(_ 'Show TazPkg activity log')
175 -l list $(_ 'List installed packages on the system')
176 -lm list-mirror $(_ 'List all available packages on the mirror')
177 info $(_ 'Print information about a package')
178 desc $(_ 'Print description of a package')
179 -lf list-files $(_ 'List the files installed with a package')
180 list-config $(_ 'List the configuration files')
182 -s search $(_ 'Search for a package by pattern or name')
183 search-pkgname $(_ 'Search on mirror for package having a particular file')
184 -sf search-file $(_ 'Search for file in all installed packages files')
186 -g get $(_ 'Download a package into the current directory')
187 -gi get-install $(_ 'Download and install a package from the mirror')
188 get-install-list $(_ 'Download and install a list of packages from the mirror')
189 -i install $(_ 'Install a local package')
190 install-list $(_ 'Install all packages from a list of packages')
191 -r remove $(_ 'Remove the specified package and all installed files')
192 -e extract $(_ 'Extract a (*.tazpkg) package into a directory')
193 pack $(_ 'Pack an unpacked or prepared package tree')
195 recharge $(_ 'Recharge your packages.list from the mirror')
196 up|help-up $(_ 'Check packages %s to list and install latest upgrades' $CHECKSUM)
198 repack $(_ 'Create a package archive from an installed package')
199 repack-config $(_ 'Create a package archive with configuration files')
200 recompress $(_ 'Rebuild a package with a better compression ratio')
201 -b|u block|unblock $(_ 'Block an installed package version or unblock it for upgrade')
202 check $(_ 'Verify consistency of installed packages')
204 add-flavor $(_ 'Install the flavor list of packages')
205 install-flavor $(_ 'Install the flavor list of packages and remove other ones')
207 set-release $(_ 'Change release and update packages')
208 -cc clean-cache $(_ 'Clean all packages downloaded in cache directory')
210 depends $(_ 'Display dependencies tree')
211 rdepends $(_ 'Display reverse dependencies tree')
213 convert $(_ 'Convert alien package to tazpkg')
214 link $(_ 'Link a package from another slitaz installation')
216 -sm setup-mirror $(_ 'Change the mirror url configuration')
217 list-undigest $(_ 'List undigest mirrors')
218 remove-undigest $(_ 'Remove an undigest mirror')
219 add-undigest $(_ 'Add an undigest mirror')
220 setup-undigest $(_ 'Update an undigest mirror')
222 reconfigure $(_ 'Replay post install script from package')
223 ")
224 EOT
225 }
228 usage_up() {
229 cat <<EOT
230 $(emsg "<b>$(_ 'Usage for command up:')</b>") tazpkg up [$(_ 'option')]
232 * $(longline "$(_ 'Without options run in interactive mode and ask before install')")
234 $(boldify "$(_ 'Where options are:')")
235 $(optlist "\
236 -c --check $(_ 'Check only for available upgrades')
237 -r --recharge $(_ 'Force recharge of packages list and check')
238 -i --install $(_ 'Check for upgrades and install them all')
239 ")
241 $(boldify "$(_ 'Example:')")
242 tazpkg up --recharge --install
243 tazpkg up -c -r
244 EOT
245 }
248 # Check if dir exists
250 check_dir() {
251 if ! [ -d "$1" ]; then
252 action 'Creating folder "%s"...' "$1"
253 mkdir -p "$1"
254 status
255 return 1
256 fi
257 }
260 # Check if the directories and files used by TazPkg exist.
261 # If not and user is root we create them.
263 check_base_dir() {
264 if [ "$(id -u)" == '0' ]; then
265 check_dir $1$CACHE_DIR
266 check_dir $1$INSTALLED
267 check_dir $1$SLITAZ_LOGS
268 if [ ! -f "$1$PKGS_DB/mirror" ]; then
269 echo "${DEFAULT_MIRROR%/}/" > $1$PKGS_DB/mirror
270 [ -n "$1" ] && cp $PKGS_DB/packages.* $1$PKGS_DB/
271 fi
272 fi
273 }
274 check_base_dir
277 # Check for a package name on cmdline.
279 check_for_package_on_cmdline() {
280 if [ -z "$PACKAGE" ]; then
281 newline
282 _ 'Please specify a package name on the command line.'
283 newline
284 exit 1
285 fi
286 }
289 # Check if the package (*.tazpkg) exists before installing or extracting.
291 check_for_package_file() {
292 if [ ! -f "$PACKAGE_FILE" ]; then
293 newline
294 _ 'Unable to find file "%s"' $PACKAGE_FILE
295 newline
296 exit 1
297 fi
298 }
301 # Check for the receipt of an installed package.
303 check_for_receipt() {
304 if [ ! -f "$1$INSTALLED/$PACKAGE/receipt" ]; then
305 newline
306 _ 'Unable to find the receipt "%s"' "$1$INSTALLED/$PACKAGE/receipt"
307 newline
308 exit 1
309 fi
310 }
313 # Get repositories priority using $PKGS_DB/priority.
314 # In this file undigest repos are called by their names and main mirror
315 # by 'main'. Sort order: priority
317 look_for_priority() {
318 [ -s "$PKGS_DB/priority" ] && priority=$(cat $PKGS_DB/priority)
320 for rep in main $(ls $PKGS_DB/undigest 2>/dev/null); do
321 if [ ! -s "$PKGS_DB/priority" ] || ! grep -q ^$rep$ $PKGS_DB/priority; then
322 priority=$(echo -e "$priority\n$rep")
323 fi
324 done
325 priority=$(echo "$priority" | sed '/^$/d' | \
326 while read line; do
327 case $line in
328 main) echo $PKGS_DB;;
329 *) echo $PKGS_DB/undigest/$line;;
330 esac
331 done)
332 }
335 # Get package name in a directory
337 package_fullname_in_dir() {
338 [ ! -f "$1/receipt" ] && return
339 EXTRAVERSION=''
340 . $1/receipt
341 echo "$PACKAGE-$VERSION$EXTRAVERSION"
342 }
345 # Get package name that is already installed.
347 get_installed_package_pathname() {
348 for i in $2$INSTALLED/${1%%-*}*; do
349 [ ! -d $i ] && continue
350 if [ "$1" == "$(package_fullname_in_dir $i)" ]; then
351 echo "$i"
352 return
353 fi
354 done
355 }
358 # Check if a package is already installed.
360 check_for_installed_package() {
361 if [ -n "$(get_installed_package_pathname $PACKAGE $1)" ]; then
362 newline
363 _ '"%s" package is already installed.' $(colorize 34 $PACKAGE)
364 longline "$(_ 'You can use the --forced option to force installation.')"
365 newline
366 exit 0
367 fi
368 }
371 # Check for packages.list to download and install packages.
373 check_for_packages_list() {
374 list_path="$PKGS_DB/packages.list"
375 if [ ! -f "$list_path" ]; then
376 if [ $(id -u) == 0 ]; then
377 tazpkg recharge
378 else
379 newline
380 _ 'Unable to find the list "%s"' $list_path
381 _ \
382 "You must probably run 'tazpkg recharge' as root to get the latest list of
383 packages available on the mirror."
384 newline
385 exit 0
386 fi
387 fi
388 }
391 # Check for installed.info - local file with format of packages.info
392 # "installed.info" is absent on not clean installs; check it and re-generate if needed.
394 check_for_installed_info() {
395 info_path="$ROOT$PKGS_DB/installed.info"
396 if [ ! -f "$info_path" ]; then
397 if [ "$(id -u)" == '0' ]; then
398 _ 'File "%s" generated. Please wait...' installed.info
399 for pkg in $ROOT$PKGS_DB/installed/*/receipt; do
400 unset_receipt
401 . $pkg
402 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
403 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
404 MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" \
405 $ROOT$PKGS_DB/installed.md5 | awk '{print $1}')"
406 cat >> $info_path << EOT
407 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5
408 EOT
409 done
410 else
411 _ 'Unable to find file "%s"' installed.info
412 _ 'Please run tazpkg as root.'
413 exit 1
414 fi
415 fi
417 # Check for md5 field in the installed.info
419 }
422 get_cache_dir() {
423 echo $rep > $tmp/rep
424 if [ "$rep" == "$PKGS_DB" ]; then
425 CACHE_DIR="$SAVE_CACHE_DIR/$SLITAZ_RELEASE/packages"
426 elif [ "${rep%-incoming}" == "$rep" ]; then
427 CACHE_DIR="$SAVE_CACHE_DIR/${rep##*/}/packages"
428 else
429 rep="${rep%-incoming}"
430 CACHE_DIR="$SAVE_CACHE_DIR/${rep##*/}/packages-incoming"
431 fi
432 [ ! -d "$CACHE_DIR" ] && mkdir -p $CACHE_DIR
433 echo $CACHE_DIR > $tmp/cachedir
434 }
437 # get an already installed package from packages.equiv
439 equivalent_pkg() {
440 for i in $(grep -hs "^$1=" $PKGS_DB/packages.equiv \
441 $PKGS_DB/undigest/*/packages.equiv | sed "s/^$1=//"); do
442 if echo $i | fgrep -q : ; then
443 # format 'alternative:newname'
444 # if alternative is installed then substitute newname
445 if [ -f "$2$INSTALLED/${i%:*}/receipt" ]; then
446 # substitute package dependency
447 echo "${i#*:}"
448 return
449 fi
450 else
451 # if alternative is installed then nothing to install
452 if [ -f "$2$INSTALLED/$i/receipt" ]; then
453 # substitute installed package
454 echo "$i"
455 return
456 fi
457 fi
458 done
459 # if not found in packages.equiv then no substitution
460 echo "$1"
461 }
464 # get a virtual package from packages.equiv
466 virtual_pkg() {
467 for i in $(for rep in $priority; do
468 grep -hs "^$1=" $rep/packages.equiv
469 done | sed "s/^$1=//"); do
470 if echo $i | fgrep -q : ; then
471 # format 'alternative:newname'
472 # if alternative is installed then substitute newname
473 if [ -f "$2$INSTALLED/${i%:*}/receipt" ]; then
474 # substitute package dependency
475 echo "${i#*:}"
476 return
477 fi
478 else
479 # unconditional substitution
480 echo "$i"
481 return
482 fi
483 done
484 }
487 # Get package filename available on the mirror
489 get_package_filename() {
490 local pkg
491 for rep in $priority; do
492 pkg=$(grep -A 1 -sh "^$1$" $rep/packages.txt | tail -1 | sed 's/^ *//')
493 [ -n "$pkg" ] && pkg=$(grep -sh "^$1-$pkg" $rep/packages.list | head -1)
495 # Allow user to call a package with his version number.
496 [ -n "$pkg" ] || pkg=$(grep -sh "^$1$" $rep/packages.list | head -1)
498 [ -n "$pkg" ] || pkg=$(grep -sh "^$1-[0-9]" $rep/packages.list | head -1)
499 [ -n "$pkg" ] || pkg=$(grep -sh "^$1-.[\.0-9]" $rep/packages.list | head -1)
500 [ -n "$pkg" ] && get_cache_dir && break
501 done
502 if [ -z "$pkg" ]; then
503 # Check for virtual package
504 local equiv
505 equiv=$(virtual_pkg $1)
506 if [ "$equiv" != "$1" ]; then
507 PACKAGE="$equiv"
508 get_package_filename $PACKAGE
509 return
510 fi
511 fi
512 echo "$pkg"
513 }
516 # Check for a package in packages.list. Used by get and get-install to grep
517 # package basename.
519 check_for_package_in_list() {
520 local filename
521 local check_only
522 check_only="$1"
523 filename=$(get_package_filename $PACKAGE)
524 if [ -n "$filename" ]; then
525 PACKAGE="$filename"
526 CACHE_DIR="$(cat $tmp/cachedir)"
527 rep="$(cat $tmp/rep)"
528 rm -f $tmp/rep $tmp/cachedir
529 else
530 newline
531 _ 'Unable to find package "%s" in the mirrored packages list.' $PACKAGE
532 newline
533 [ -n "$check_only" ] && return 1
534 exit 0
535 fi
536 }
539 # Log this activity
540 # (there log_pkg because we have log() in libtaz.sh)
542 log_pkg() {
543 local extra
545 [ "$1" == 'Installed' ] && \
546 extra=" - $(fgrep $PACKAGE-$VERSION $PKGS_DB/installed.$SUM | awk '{ print $1 }')"
548 [ -e "$LOG" ] || touch $LOG
550 [ -w "$LOG" ] &&
551 echo "$(date +'%F %T') - $1 - $PACKAGE ($VERSION$EXTRAVERSION)$extra" >> $LOG
552 }
555 # Download a get-package script from this mirror
557 download_get_script() {
558 local p i
559 for p in $priority ; do
560 for i in $(cat $p/mirror) ; do
561 case "$i" in
562 http://*|https://*|ftp://*)
563 busybox wget -q -T 30 -U TazPkg -O $2 \
564 ${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 local i mirrors="$1"; shift
576 for i in $mirrors; do
577 case "$i" in
578 # Mirror URL can have a trailing slash or not.
579 http://*|https://*|ftp://*)
580 busybox wget -c -q -T 30 -U TazPkg ${i%/}/$@ 2>/dev/null && break ;;
581 *)
582 ln -sf ${i%/}/$1 . && break ;;
583 esac
584 done
585 }
588 # Download a file trying all mirrors
590 download() {
591 local i
592 case "$1" in
593 *.tazpkg)
594 for i in $priority ; do
595 grep -q "^${1%.tazpkg}$" $i/packages.list 2>/dev/null || continue
596 download_from "$(cat $i/mirror)" "$@" && return
597 done
598 esac
599 for i in $(cat $(for rep in $priority; do echo $rep/mirror; done) 2>/dev/null); do
600 download_from "$i" "$@" && break
601 done
602 }
605 # Extract a package with cpio and gzip/lzma.
607 extract_package() {
608 action 'Extracting package...'
609 cpio -idm --quiet < ${PACKAGE_FILE##*/} && rm -f ${PACKAGE_FILE##*/}
610 status
611 if [ -f fs.cpio.lzma ]; then
612 unlzma -c fs.cpio.lzma | cpio -idm --quiet && rm fs.cpio.lzma
613 elif [ -f fs.cpio.gz ]; then
614 zcat fs.cpio.gz | cpio -idm --quiet && rm fs.cpio.gz
615 fi
616 }
619 remove_with_path() {
620 # Avoid dirname errors by checking for argument.
621 [ "$1" ] || return
623 local dir
624 rm -f $1 2>/dev/null
625 dir="$1"
626 while [ "$dir" != "/" ]; do
627 dir="$(dirname $dir)"
628 rmdir $dir 2> /dev/null || break
629 done
630 }
633 grepesc() {
634 sed 's/\[/\\[/g'
635 }
638 # Print short package description
639 print_short_description() {
640 local short_desc=''
641 for LC in $LANG ${LANG%_*}; do
642 if [ -e "$PKGS_DB/packages-desc.$LC" ]; then
643 short_desc=$(grep -e "^$1 " $PKGS_DB/packages-desc.$LC | cut -d' ' -f2)
644 fi
645 done
646 [ -z "$short_desc" -a -s $PKGS_DB/packages.info ] &&
647 short_desc="$(awk -F$'\t' -vp="$PACKAGE" '{if($1==p){print $4;exit}}' $PKGS_DB/packages.info)"
648 longline "$short_desc"
649 }
652 # This function installs a package in the rootfs.
654 install_package() {
655 ROOT=$1
656 if [ -n "$ROOT" ]; then
657 # Get absolute path
658 ROOT=$(realpath $ROOT)
659 fi
660 {
661 # Create package path early to avoid dependencies loop
662 mkdir -p $TMP_DIR
663 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
664 . $TMP_DIR/receipt
665 # FIXME: legacy?
666 if grep -q ^pre_depends $TMP_DIR/receipt; then
667 pre_depends $ROOT
668 fi
670 # Keep modifiers and file list on upgrade
671 cp $ROOT$INSTALLED/$PACKAGE/modifiers \
672 $ROOT$INSTALLED/$PACKAGE/files.list $TMP_DIR 2> /dev/null
673 rm -rf $ROOT$INSTALLED/$PACKAGE 2> /dev/null
675 # Make the installed package data dir to store
676 # the receipt and the files list.
677 mkdir -p $ROOT$INSTALLED/$PACKAGE
678 cp $TMP_DIR/modifiers $ROOT$INSTALLED/$PACKAGE 2> /dev/null
679 cp $TMP_DIR/files.list $ROOT$INSTALLED/$PACKAGE 2> /dev/null
680 rm -rf $TMP_DIR 2> /dev/null
681 sed -i "/ $(basename $PACKAGE_FILE)$/d" \
682 $ROOT$PKGS_DB/installed.$SUM 2> /dev/null
683 cd $(dirname $PACKAGE_FILE)
684 $CHECKSUM $(basename $PACKAGE_FILE) >> $ROOT$PKGS_DB/installed.$SUM
685 }
687 # Resolve package deps.
688 check_for_deps $ROOT
689 if [ -n "$MISSING_PACKAGE" ]; then
690 install_deps $ROOT
691 fi
692 mkdir -p $TMP_DIR
693 [ -n "$INSTALL_LIST" ] && echo "$PACKAGE_FILE" >> $ROOT$PKGS_DB/$INSTALL_LIST-processed
695 title 'Installation of package "%s"' $PACKAGE
697 print_short_description $PACKAGE
698 separator '-'
700 action 'Copying package...'
701 cp $PACKAGE_FILE $TMP_DIR
702 status
704 cd $TMP_DIR
705 extract_package
706 SELF_INSTALL=0
707 EXTRAVERSION=""
708 CONFIG_FILES=""
710 # Include temporary receipt to get the right variables.
711 . $PWD/receipt
712 cd $ROOT$INSTALLED
714 # FIXME: legacy?
715 if [ $SELF_INSTALL -ne 0 -a -n "$ROOT" ]; then
716 action "Checking post install dependencies..."
717 [ -f $INSTALLED/$PACKAGE/receipt ]
718 if ! status; then
719 _ 'Please run "%s" in / and retry.' "tazpkg install $PACKAGE_FILE"
720 rm -rf $TMP_DIR
721 exit 1
722 fi
723 fi
725 # Get files to remove if upgrading
726 if [ -f $PACKAGE/files.list ]; then
727 while read file; do
728 grep -q "^$(echo $file | grepesc)$" $TMP_DIR/files.list && continue
729 for i in $(cat $PACKAGE/modifiers 2> /dev/null ;
730 fgrep -sl $PACKAGE */modifiers | cut -d/ -f1 ); do
731 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
732 done
733 echo $file
734 done < $PACKAGE/files.list > $TMP_DIR/files2remove.list
735 fi
737 # Remember modified packages
738 {
739 check=false
740 for i in $(fgrep -v [ $TMP_DIR/files.list); do
741 [ -e "$ROOT$i" ] || continue
742 [ -d "$ROOT$i" ] && continue
743 echo "- $i"
744 check=true
745 done ;
746 $check && \
747 for i in *; do
748 [ "$i" == "$PACKAGE" ] && continue
749 [ -s $i/files.list ] || continue
750 awk "{ printf \"$i %s\\n\",\$1 }" < $i/files.list
751 done;
752 } | awk '
753 {
754 if ($1 == "-" || file[$2] != "") {
755 file[$2] = file[$2] " " $1
756 if ($1 != "-") {
757 if (pkg[$1] == "") all = all " " $1
758 pkg[$1] = pkg[$1] " " $2
759 }
760 }
761 }
762 END {
763 for (i = split(all, p, " "); i > 0; i--)
764 for (j = split(pkg[p[i]], f, " "); j > 0; j--)
765 printf "%s %s\n",p[i],f[j];
766 }
767 ' | while read dir file; do
768 if grep -qs ^$dir$ $PACKAGE/modifiers; then
769 # Do not overload an overloaded file !
770 rm $TMP_DIR$file 2> /dev/null
771 continue
772 fi
773 grep -qs ^$PACKAGE$ $dir/modifiers && continue
774 if [ -s "$dir/volatile.cpio.gz" ]; then
775 # We can modify backed up files without notice
776 zcat $dir/volatile.cpio.gz | cpio -t --quiet | \
777 grep -q "^${file#/}$" && continue
778 fi
779 echo "$PACKAGE" >> $dir/modifiers
780 done
782 cd $TMP_DIR
783 cp receipt files.list $ROOT$INSTALLED/$PACKAGE
785 # Copy the description if found.
786 if [ -f "description.txt" ]; then
787 cp description.txt $ROOT$INSTALLED/$PACKAGE
788 fi
790 # Copy the md5sum if found.
791 if [ -f "$CHECKSUM" ]; then
792 cp $CHECKSUM $ROOT$INSTALLED/$PACKAGE
793 fi
795 # Pre install commands.
796 if grep -q ^pre_install $ROOT$INSTALLED/$PACKAGE/receipt; then
797 pre_install $ROOT
798 fi
800 if [ -n "$CONFIG_FILES" ]; then
801 # save 'official' configuration files
802 action 'Saving configuration files...'
803 for i in $CONFIG_FILES; do
804 { cd fs ; find ${i#/} -type f 2> /dev/null; cd ..; }
805 done | { cd fs ; cpio -o -H newc --quiet | gzip -9; cd ..; } > \
806 $ROOT$INSTALLED/$PACKAGE/volatile.cpio.gz
808 if [ -z "$newconf" ]; then
809 # keep user configuration files
810 for i in $CONFIG_FILES; do
811 { cd fs ; find ${i#/} -type f 2> /dev/null; cd ..; }
812 done | while read i; do
813 [ -e $ROOT/$i ] || continue
814 cp -a $ROOT/$i fs/$i
815 done
816 fi
817 status
818 fi
820 action 'Installing package...'
821 [ "$(busybox ls fs/* 2>/dev/null)" ] && cp -af fs/* $ROOT/
822 status
824 if [ -s files2remove.list ]; then
825 action 'Removing old package...'
826 while read file; do
827 remove_with_path $ROOT$file
828 done < files2remove.list
829 true
830 status
831 fi
833 # Remove the temporary random directory.
834 action "Removing all tmp files..."
835 cd ..; rm -rf $TMP_DIR
836 status
838 # Post install commands.
839 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
840 action "Execute post-install commands..."
841 post_install $ROOT
842 status
843 fi
845 # Update-desktop-database if needed.
846 if [ "$(fgrep .desktop $ROOT$INSTALLED/$PACKAGE/files.list | fgrep /usr/share/applications/)" ]; then
847 updatedesktopdb=yes
848 fi
850 # Update-mime-database if needed.
851 if [ "$(fgrep /usr/share/mime $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
852 updatemimedb=yes
853 fi
855 # Update-icon-database
856 if [ "$(fgrep /usr/share/icon/hicolor $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
857 updateicondb=yes
858 fi
860 # Compile glib schemas if needed.
861 if [ "$(fgrep /usr/share/glib-2.0/schemas $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
862 compile_schemas=yes
863 fi
865 # Update depmod list
866 if [ "$(fgrep /lib/modules $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
867 updatedepmod=yes
868 fi
870 # Update installed.info
871 check_for_installed_info
872 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
873 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
874 II=$ROOT$PKGS_DB/installed.info
875 sed -i "/^$PACKAGE /d" $II # remove old entry
876 cat >> $II << EOT
877 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS
878 EOT
879 TEMP_FILE=$(mktemp)
880 sort $II > $TEMP_FILE; mv -f $TEMP_FILE $II; chmod a+r $II; unset II
882 cd $TOP_DIR
883 footer "$(_ 'Package "%s" (%s) is installed.' $PACKAGE $VERSION$EXTRAVERSION)"
885 # Log this activity
886 [ -n "$ROOT" ] || log_pkg Installed
888 # Remove package from upgrade list
889 [ -s $UP_LIST ] && sed -i "/^$PACKAGE\$/d" $UP_LIST
890 }
893 # This function may be called by a get script.
895 abort_package() {
896 cd $CUR_DIR
897 rm -rf $TMP_DIR
898 echo "${1:-Abort $PACKAGE.}"
899 exit 1
900 }
903 # This function installs a package from a get script in the rootfs.
905 install_package_from_get_script() {
906 SCRIPT="$1"
907 ROOT="$2"
908 [ -d $ROOT$INSTALLED/$PACKAGE ] && exit 1
910 grep -q no-check-certificate $SCRIPT &&
911 [ ! -d $INSTALLED/wget ] && tazpkg get-install wget
913 mkdir -p $TMP_DIR && cd $TMP_DIR
914 saved=$PACKAGE
915 unset_receipt
916 PACKAGE=$saved
918 set -e
919 . $SCRIPT
920 set +e
921 [ -d $PACKAGE-$VERSION ] || cd $TMP_DIR
922 [ -d $PACKAGE-$VERSION ] || abort_package \
923 "$(_ 'Could not download "%s" from "%s". Exiting.' ${TARBALL:-$PACKAGE} ${WGET_URL:-$WEB_SITE})"
925 if [ ! -s $PACKAGE-$VERSION/receipt ]; then
926 cat > $PACKAGE-$VERSION/receipt <<EOT
927 # SliTaz package receipt.
929 PACKAGE="$PACKAGE"
930 VERSION="${VERSION:-unknown}"
931 CATEGORY="${CATEGORY:-non-free}"
932 WEB_SITE="$WEB_SITE"
933 SHORT_DESC="${SHORT_DESC:-$PACKAGE}"
934 MAINTAINER="${MAINTAINER:-nobody@slitaz.org}"
935 EOT
936 for i in LICENSE TARBALL WGET_URL CONFIG_FILES SUGGESTED \
937 PROVIDE DEPENDS HOST_ARCH TAGS EXTRA_SOURCE_FILES ; do
938 eval "[ -n \"\$$i\" ] && echo \"$i=\\\"\$$i\\\"\""
939 done >> $PACKAGE-$VERSION/receipt
940 fi
942 DEPENDS="$(unset DEPENDS; . $PACKAGE-$VERSION/receipt ; echo $DEPENDS)"
943 for i in $(find_depends $PACKAGE-$VERSION/fs); do
944 case " $DEPENDS " in
945 *\ $i\ *) continue;;
946 esac
947 grep -q '^DEPENDS="' $PACKAGE-$VERSION/receipt ||
948 echo 'DEPENDS=""' >> $PACKAGE-$VERSION/receipt
949 sed -i "s/^DEPENDS=\"/&$i /" $PACKAGE-$VERSION/receipt
950 done
952 tazpkg pack $PACKAGE-$VERSION
954 # Clean to save RAM memory before installation
955 rm -rf $PACKAGE-$VERSION
957 if [ "$3" == "--get" ]; then
958 mv $PACKAGE-$VERSION.tazpkg $TOP_DIR
959 else
960 # Install pseudo package
961 tazpkg install $PACKAGE-$VERSION.tazpkg --root=$ROOT
962 mv $PACKAGE-$VERSION.tazpkg $CACHE_DIR
963 fi
965 # Clean
966 cd $TOP_DIR
967 rm -rf $TMP_DIR
968 }
971 # Check for loop in deps tree.
973 check_for_deps_loop() {
974 local list
975 local pkg
976 local deps
977 pkg=$1
978 shift
979 [ -n "$1" ] || return
980 list=""
982 # Filter out already processed deps
983 for i in $@; do
984 case " $ALL_DEPS" in
985 *\ $i\ *) ;;
986 *) list="$list $i";;
987 esac
988 done
989 ALL_DEPS="$ALL_DEPS$list "
990 for i in $list; do
991 [ -f $i/receipt ] || continue
992 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
993 case " $deps " in
994 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
995 *) check_for_deps_loop $pkg $deps;;
996 esac
997 done
998 }
1001 # Check for missing deps listed in a receipt packages.
1003 check_for_deps() {
1004 local saved;
1005 saved=$PACKAGE
1006 mkdir -p $TMP_DIR
1007 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
1008 . $TMP_DIR/receipt
1009 PACKAGE=$saved
1010 rm -rf $TMP_DIR
1012 num=0
1013 for pkgorg in $DEPENDS; do
1014 i=$(equivalent_pkg $pkgorg $1)
1015 if [ ! -d "$1$INSTALLED/$i" ]; then
1016 MISSING_PACKAGE=$i
1017 num=$(($num+1))
1018 elif [ ! -f "$1$INSTALLED/$i/receipt" ]; then
1019 _ 'WARNING! Dependency loop between "%s" and "%s".' $PACKAGE $i
1020 fi
1021 done
1023 if [ -n "$MISSING_PACKAGE" ]; then
1024 title "$(_ 'Tracking dependencies for package "%s"' $PACKAGE)"
1025 for pkgorg in $DEPENDS; do
1026 i=$(equivalent_pkg $pkgorg $1)
1027 if [ ! -d "$1$INSTALLED/$i" ]; then
1028 MISSING_PACKAGE=$i
1029 _ 'Missing package "%s"' $MISSING_PACKAGE
1030 fi
1031 done
1032 footer "$(_p \
1033 '%s missing package to install.' \
1034 '%s missing packages to install.' $num \
1035 $num)"
1036 fi
1040 # Install all missing deps. Auto install or ask user then install all missing
1041 # deps from local dir, cdrom, media or from the mirror. In case we want to
1042 # install packages from local, we need a packages.list to find the version.
1044 install_deps() {
1045 local root
1046 root=""
1047 [ -n "$1" ] && root="--root=$1"
1048 if [ "$AUTO_INSTALL_DEPS" == "yes" ]; then
1049 answer=0
1050 else
1051 newline
1052 confirm "$(_ 'Install all missing dependencies? (y/N)')"
1053 answer=$?
1054 newline
1055 fi
1056 if [ $answer == 0 ] && ! [ "$nodeps" ]; then
1057 for pkgorg in $DEPENDS; do
1058 pkg=$(equivalent_pkg $pkgorg $1)
1059 if [ ! -d "$1$INSTALLED/$pkg" ]; then
1060 local list
1061 list="$INSTALL_LIST"
1062 [ -n "$list" ] || list="$TOP_DIR/packages.list"
1063 # We can install packages from a local dir by greping
1064 # the TAZPKG_BASENAME in the local packages.list.
1065 found=0
1066 if [ -f "$list" ]; then
1067 _ 'Checking if package "%s" exists in local list...' $pkg
1068 mkdir $TMP_DIR
1069 for i in $pkg-*.tazpkg; do
1070 [ -f $i ] || continue
1071 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $i
1072 [ "$(. $TMP_DIR/receipt; echo $PACKAGE)" == "$pkg" ] || continue
1073 if grep -q ^$(package_fullname_in_dir $TMP_DIR).tazpkg$ $list
1074 then
1075 found=1
1076 tazpkg install $i $root --list=$list
1077 break
1078 fi
1079 done
1080 rm -rf $TMP_DIR
1081 fi
1082 # Install deps from the mirror.
1083 if [ $found -eq 0 ]; then
1084 if [ ! -f "$PKGS_DB/packages.list" ]; then
1085 tazpkg recharge
1086 fi
1087 tazpkg get-install $pkg $root
1088 fi
1089 fi
1090 done
1091 else
1092 newline
1093 _ 'Leaving dependencies for package "%s" unresolved.' $PACKAGE
1094 _ 'The package is installed but will probably not work.'
1095 newline
1096 fi
1100 # Search pattern in installed packages.
1102 search_in_installed_packages() {
1103 _ 'Installed packages'
1104 separator
1105 num=0
1106 for pkg in $(ls -1 $INSTALLED | grep -i "$PATTERN"); do
1107 EXTRAVERSION=""
1108 [ -f $INSTALLED/$pkg/receipt ] || continue
1109 . $INSTALLED/$pkg/receipt
1110 emsg "$PACKAGE<i 24> $VERSION$EXTRAVERSION<i 42> $(_n $CATEGORY)"
1111 num=$(($num+1))
1112 done
1114 footer "$(_p \
1115 '%s installed package found for "%s"' \
1116 '%s installed packages found for "%s"' $num \
1117 $num "$PATTERN")"
1121 # Search in packages.list for available pkgs.
1123 search_in_packages_list() {
1124 _ 'Available packages'
1125 separator
1126 num=0
1127 BPATTERN="$(emsg "<b>$PATTERN</b>")"
1128 for i in $PKGS_DB/packages.list $PKGS_DB/undigest/*/packages.list \
1129 $PKGS_DB/extra.list $PKGS_DB/undigest/*/extra.list ; do
1130 grep -is "$PATTERN" $i | sed "s|$PATTERN|$BPATTERN|"
1131 num=$(($num + `grep -is "$PATTERN" $i | wc -l`))
1132 done
1133 if [ ! -f "$PKGS_DB/packages.list" ]; then
1134 newline
1135 longline "$(_ \
1136 "No \"%s\" found to check for mirrored packages. For more results, please run \
1137 \"%s\" once as root before searching." packages.list 'tazpkg recharge')"
1138 newline
1139 fi
1140 footer "$(_p \
1141 '%s available package found for "%s"' \
1142 '%s available packages found for "%s"' $num \
1143 $num $PATTERN)"
1147 # search --mirror: Search in packages.txt for available pkgs and give more
1148 # info than --list or default.
1150 search_in_packages_txt() {
1151 _ 'Matching packages name with version and desc'
1152 separator
1153 num=0
1154 for i in $PKGS_DB/packages.txt $PKGS_DB/undigest/*/packages.txt; do
1155 grep -is -A 2 "^$PATTERN" $i
1156 num=$(($num + `grep -is "^$PATTERN" $i | wc -l`))
1157 done
1158 if [ ! -f "$PKGS_DB/packages.txt" ]; then
1159 newline
1160 longline "$(_ \
1161 "No \"%s\" found to check for mirrored packages. For more results, please run \
1162 \"%s\" once as root before searching." packages.txt 'tazpkg recharge')"
1163 newline
1164 fi
1165 footer "$(_p \
1166 '%s available package found for "%s"' \
1167 '%s available packages found for "%s"' $num \
1168 $num $PATTERN)"
1172 # Install package-list from a flavor
1174 install_flavor() {
1175 check_root $@
1177 # Get repositories priority list.
1178 look_for_priority
1180 FLAVOR=$1
1181 ARG=$2
1182 mkdir -p $TMP_DIR
1183 [ -f $FLAVOR.flavor ] && cp $FLAVOR.flavor $TMP_DIR
1184 cd $TMP_DIR
1185 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1186 zcat < $FLAVOR.flavor | cpio --quiet -i >/dev/null
1188 while read file; do
1189 for pkg in $(ls -d $INSTALLED/${file%%-*}*); do
1190 [ -f $pkg/receipt ] || continue
1191 EXTRAVERSION=""
1192 . $pkg/receipt
1193 [ "$PACKAGE-$VERSION$EXTRAVERSION" == "$file" ] && break
1194 done
1195 [ "$PACKAGE-$VERSION$EXTRAVERSION" == "$file" ] && continue
1196 cd $CACHE_DIR
1197 download $file.tazpkg
1198 cd $TMP_DIR
1199 tazpkg install $CACHE_DIR/$file.tazpkg --forced
1200 done < $FLAVOR.pkglist
1202 [ -f $FLAVOR.nonfree ] && while read pkg; do
1203 [ -d $INSTALLED/$pkg ] || continue
1204 [ -d $INSTALLED/get-$pkg ] && tazpkg get-install get-$pkg
1205 get-$pkg
1206 done < $FLAVOR.nonfree
1208 [ "$ARG" == "--purge" ] && for pkg in $(ls $INSTALLED); do
1209 [ -f $INSTALLED/$pkg/receipt ] || continue
1210 EXTRAVERSION=""
1211 . $INSTALLED/$pkg/receipt
1212 grep -q ^$PACKAGE-$VERSION$EXTRAVERSION$ $FLAVOR.pkglist && continue
1213 grep -qs ^$PACKAGE$ $FLAVOR.nonfree && continue
1214 tazpkg remove $PACKAGE
1215 done
1216 else
1217 _ "Can't find flavor \"%s\". Abort." $FLAVOR
1218 fi
1219 cd $TOP_DIR
1220 rm -rf $TMP_DIR
1224 # Update mirror urls
1226 setup_mirror() {
1227 # Backup old list.
1228 if [ -f "$1/mirror" ]; then
1229 cp -f $1/mirror $1/mirror.bak
1230 fi
1231 title 'Current mirror(s)'
1232 echo " `cat $1/mirror 2> /dev/null`"
1233 longline "$(_ \
1234 "Please enter URL of the new mirror (http, ftp or local path). You must specify \
1235 the complete address to the directory of the packages and packages.list file.")"
1236 newline
1237 _n 'New mirror(s) URL: '
1238 NEW_MIRROR_URL=$2
1239 if [ -n "$NEW_MIRROR_URL" ]; then
1240 echo $NEW_MIRROR_URL
1241 else
1242 read NEW_MIRROR_URL
1243 fi
1244 if [ -z "$NEW_MIRROR_URL" ]; then
1245 _ 'Nothing has been changed.'
1246 else
1247 _ 'Setting mirror(s) to: "%s"' $NEW_MIRROR_URL
1248 rm -f $1/mirror
1249 for i in $NEW_MIRROR_URL; do
1250 echo "${i%/}/" >> $1/mirror
1251 done
1252 fi
1253 newline
1257 # recursive dependencies scan
1259 dep_scan() {
1260 for i in $1; do
1261 case " $ALL_DEPS " in
1262 *\ $i\ *) continue;;
1263 esac
1264 ALL_DEPS="$ALL_DEPS $i"
1265 [ -n "$2" ] && echo "$2$i ($(fgrep -A 3 $i $PKGS_DB/packages.txt | \
1266 tail -1 | sed 's/.*(\([^ ]*\).*/\1/'))"
1267 [ -f $i/receipt ] || continue
1268 DEPENDS=""
1269 . $i/receipt
1270 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
1271 done
1275 # recursive reverse dependencies scan
1277 rdep_scan() {
1278 SEARCH=$1
1280 for i in * ; do
1281 DEPENDS=""
1282 . $i/receipt
1283 echo "$i $(echo $DEPENDS)"
1284 done | busybox awk -v search=$SEARCH '
1285 function show_deps(deps, all_deps, pkg, space)
1287 if (all_deps[pkg] == 1) return
1288 all_deps[pkg] = 1
1289 if (space != "") printf "%s %s\n",space,pkg
1290 for (i = 1, n = split(deps[pkg], mydeps, " "); i <= n; i++) {
1291 show_deps(deps, all_deps, mydeps[i],"==" space)
1296 all_deps[$1] = 0
1297 for (i = 2; i <= NF; i++)
1298 deps[$i] = deps[$i] " " $1
1301 END {
1302 show_deps(deps, all_deps, search, "")
1304 ' | while read spc pkg; do
1305 echo -n $spc | sed 's/=/ /g'
1306 echo -n $pkg
1307 echo -n ' ('
1308 fgrep -A 3 $pkg $PKGS_DB/packages.txt | tail -1 | \
1309 sed 's/.*(\([^ ]*\).*/\1)/'
1310 done
1314 update_desktop_database() {
1315 if [ -f $1/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
1316 chroot "$1/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
1317 fi
1321 update_mime_database() {
1322 if [ -f $1/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
1323 chroot "$1/" /usr/bin/update-mime-database /usr/share/mime
1324 fi
1328 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() {
1336 if [ -f $1/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
1337 chroot "$1/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
1338 fi
1342 update_kernel_modules() {
1343 if [ -f $1/sbin/depmod ] && [ -n "$updatedepmod" ]; then
1344 chroot "$1/" /sbin/depmod -a
1345 fi
1349 # When recharging errors occur
1351 recharging_failed() {
1352 colorize 31 "$(_ 'Recharging failed')"
1354 # Restore database from bak files
1355 action 'Restoring database files...'
1356 [ -e 'ID' -a ! -e 'ID.bak' ] && rm ID
1357 [ -e 'IDs' -a ! -e 'IDs.bak' ] && rm IDs
1358 for file in $(ls $1/*.bak); do
1359 mv -f $file ${file%.bak}
1360 done
1361 status
1367 ###################
1368 # TazPkg commands #
1369 ###################
1371 case "$COMMAND" in
1372 list|-l)
1373 # List all installed packages or a specific category.
1374 shift
1375 check_for_installed_info
1377 case $1 in
1378 b|blocked)
1379 # Display the list of blocked packages.
1380 title 'Blocked packages'
1381 if [ -s "$BLOCKED" ];then
1382 cat $BLOCKED
1383 num=$(wc -l < $BLOCKED)
1384 footer "$(_p '%s package' '%s packages' "$num" \
1385 "$(colorize 31 $num)")"
1386 else
1387 _ 'No blocked packages found.'
1388 fi
1389 newline
1390 ;;
1392 c|cat|categories)
1393 # Display the list of categories.
1394 title 'Packages categories'
1396 echo "$PKGS_CATEGORIES" | sed 's|[^a-z-]|\n|g; /^$/d' | \
1397 sed 's|\(.*\)|\1\t\1|' | translate_category | awk -F$'\t' '{
1398 if ($1==$2) print $1; else printf "%-14s %s\n", $1, $2}'
1400 num=$(echo -n "$PKGS_CATEGORIES" | wc -l)
1401 footer "$(_p '%s category' '%s categories' "$num" \
1402 "$(colorize 33 $num)")"
1403 ;;
1405 '')
1406 # By default list all packages and versions.
1407 title 'List of all installed packages'
1408 awk -F$'\t' '{printf "%-34s %-17s %s\n", $1, $2, $3}' \
1409 $PKGS_DB/installed.info | translate_category
1411 num=$(wc -l < $PKGS_DB/installed.info)
1412 footer "$(_p '%s package installed.' '%s packages installed.' "$num" \
1413 "$(colorize 32 $num)")"
1414 ;;
1416 *)
1417 # Check for an asked category.
1418 ASKED_CATEGORY_I18N="$@"
1419 ASKED_CATEGORY=$(reverse_translate_category "$ASKED_CATEGORY_I18N")
1420 title 'Installed packages of category "%s"' $ASKED_CATEGORY_I18N
1421 TMPLIST=$(mktemp)
1422 awk -F$'\t' -vcat="$ASKED_CATEGORY" \
1423 '{ if ($3 == cat) printf "%-34s %s\n", $1, $2; }' \
1424 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
1426 num=$(wc -l < $TMPLIST); rm $TMPLIST
1427 footer "$(emsg $(_p \
1428 '%s package installed of category "%s".' \
1429 '%s packages installed of category "%s".' $num \
1430 "<c 32>$num</c>" "<c 34>$ASKED_CATEGORY_I18N</c>"))"
1431 ;;
1432 esac ;;
1435 list-mirror|-lm)
1436 # List all available packages on the mirror. Option --diff displays
1437 # last mirrored packages diff (see recharge).
1438 check_for_packages_list
1439 case $2 in
1440 --diff)
1441 if [ -f "$PKGS_DB/packages.diff" ]; then
1442 title 'Mirrored packages diff'
1443 cat $PKGS_DB/packages.diff
1444 num=$(wc -l < $PKGS_DB/packages.diff)
1445 footer "$(_p \
1446 '%s new package listed on the mirror.' \
1447 '%s new packages listed on the mirror.' "$num" \
1448 "$(colorize 32 $num)")"
1449 else
1450 newline
1451 _ 'Unable to list anything, no packages.diff found.'
1452 _ 'Recharge your current list to create a first diff.'
1453 newline
1454 fi
1455 ;;
1456 *)
1457 title 'List of available packages on the mirror'
1458 awk -F$'\t' '{
1459 split($7, s, " ");
1460 printf "%s\n%s\n%s\n%s (%s installed)\n\n", $1, $2, $4, s[1], s[2];
1461 }' $PKGS_DB/packages.info
1462 num=$(wc -l < $PKGS_DB/packages.info)
1463 footer "$(_p \
1464 '%s package in the last recharged list.' \
1465 '%s packages in the last recharged list.' "$num" \
1466 "$(colorize 32 $num)")"
1467 ;;
1468 esac
1469 ;;
1472 list-files|-lf)
1473 # List files installed with the package.
1474 check_for_package_on_cmdline
1475 if [ -d "$INSTALLED/$PACKAGE" ]; then
1476 # installed package
1477 title 'Installed files by "%s"' $PACKAGE
1478 sort < $INSTALLED/$PACKAGE/files.list
1479 num=$(wc -l < $INSTALLED/$PACKAGE/files.list)
1480 footer "$(_p '%s file' '%s files' $num \
1481 "$(colorize 32 $num)")"
1482 elif [ -n "$(grep "^$PACKAGE"$'\t' $PKGS_DB/packages.info)" ]; then
1483 # available package
1484 title 'Installed files by "%s"' $PACKAGE
1485 TMPLIST=$(mktemp)
1486 lzcat $PKGS_DB/files.list.lzma | sed -n "/^$PACKAGE: / s|^[^:]*: ||p" | tee $TMPLIST
1487 num=$(wc -l < $TMPLIST); rm $TMPLIST
1488 footer "$(_p '%s file' '%s files' $num \
1489 "$(colorize 32 $num)")"
1490 else
1491 newline
1492 _ 'Package "%s" not available.' "$PACKAGE"
1493 newline
1494 fi
1495 ;;
1498 info)
1499 # Information about package.
1500 check_for_package_on_cmdline
1501 check_for_receipt
1502 EXTRAVERSION=''
1503 . $INSTALLED/$PACKAGE/receipt
1504 im && title 'TazPKG information'
1505 # Display localized short description
1506 for LC in $LANG ${LANG%_*}; do
1507 if [ -e "$PKGS_DB/packages-desc.$LC" ]; then
1508 LOCDESC=$(grep -e "^$PACKAGE"$'\t' $PKGS_DB/packages-desc.$LC | cut -d$'\t' -f2)
1509 [ -n "$LOCDESC" ] && SHORT_DESC="$LOCDESC"
1510 fi
1511 done
1512 SIZES=$(echo $PACKED_SIZE/$UNPACKED_SIZE | sed 's|\.0||g' | sed 's|^/$||')
1514 emsg "$(
1516 _ 'Package : %s' "$PACKAGE"
1517 _ 'Version : %s' "$VERSION$EXTRAVERSION"
1518 _ 'Category : %s' "$(_ $CATEGORY)"
1519 _ 'Short desc : %s' "$SHORT_DESC"
1520 _ 'Maintainer : %s' "$MAINTAINER"
1521 _ 'License : %s' "$LICENSE"
1522 _ 'Depends : %s' "$DEPENDS"
1523 _ 'Suggested : %s' "$SUGGESTED"
1524 _ 'Build deps : %s' "$BUILD_DEPENDS"
1525 _ 'Wanted src : %s' "$WANTED"
1526 _ 'Web site : %s' "$WEB_SITE"
1527 _ 'Size : %s' "$SIZES"
1528 _ 'Tags : %s' "$TAGS"
1529 } | sed '/: $/d; s|^\([^:]*\):|<b>\1:</b>|')"
1530 im && footer
1531 ;;
1534 desc)
1535 # Display package description
1536 if [ -n "$(grep -e "^$PACKAGE"$'\t' $PKGS_DB/installed.info)" ]; then
1537 im && title 'Description of package "%s"' $PACKAGE
1538 if [ -s "$INSTALLED/$PACKAGE/description.txt" ]; then
1539 cat $INSTALLED/$PACKAGE/description.txt
1540 else
1541 im && awk -F$'\t' -vp="$PACKAGE" '{
1542 if ($1 == p) print $4 }' $PKGS_DB/installed.info
1543 fi
1544 im && footer
1545 else
1546 im && _ 'Package "%s" is not installed.' "$PACKAGE"
1547 fi
1548 ;;
1551 activity|log|-a)
1552 # Show activity log
1553 [ -n "$nb" ] || nb='18'
1554 title 'TazPKG Activity'
1555 IFS=' '
1556 tail -n $nb $LOG | tac | \
1557 while read date hour none action none pkg vers none; do
1558 case $action in
1559 Installed)
1560 action=$(colorize 32 $action) ;;
1561 Removed)
1562 action=$(colorize 31 $action) ;;
1563 *)
1564 action=$(boldify $action) ;;
1565 esac
1566 date_locale="$(date -d "$date $hour" '+%x %X')"
1567 echo "$date_locale : $action $pkg $vers"
1568 done
1569 unset IFS
1570 footer ;;
1573 search|-s)
1574 # Search for a package by pattern or name.
1575 PATTERN="$2"
1576 if [ -z "$PATTERN" ]; then
1577 newline
1578 _ 'Please specify a pattern or package name to search for.'
1579 echo "$(_ 'Example:') 'tazpkg search paint'"
1580 newline
1581 exit 0
1582 fi
1583 title 'Search result for "%s"' $PATTERN
1584 # Default is to search in installed pkgs and the raw list.
1585 case "$3" in
1586 -i|--installed) search_in_installed_packages ;;
1587 -l|--list) search_in_packages_list ;;
1588 -m|--mirror) search_in_packages_txt ;;
1589 *)
1590 search_in_installed_packages
1591 search_in_packages_list ;;
1592 esac ;;
1595 search-file|-sf)
1596 # Search for a file by pattern or name in all files.list.
1597 if [ -z "$2" ]; then
1598 newline
1599 _ 'Please specify a pattern or file name to search for.'
1600 echo "$(_ 'Example:') 'tazpkg search-file libnss'"
1601 newline
1602 exit 0
1603 fi
1604 title 'Search result for file "%s"' $2
1605 TMPLIST=$(mktemp)
1607 if [ -n "$mirror" ]; then
1608 TMPDIR=$(mktemp -d)
1609 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1610 [ -f $i ] || continue
1611 lzcat $i | awk -F: -vtmp="$TMPLIST" -vdir="$TMPDIR" \
1612 -vfile="$2" -vcfile="$(colorize 32 $2)" '
1613 BEGIN { efile = gensub("\+", "\\\+", "g", file); }
1614 index($2, file) {
1615 gsub(efile, cfile, $2);
1616 print $2 >> dir"/"$1;
1617 printf "1" >> tmp;
1618 }'
1619 done
1621 for pkg in $(cd $TMPDIR; ls); do
1622 newline
1623 emsg "<c 33>$(_ 'Package %s:' $pkg)</c>"
1624 cat $TMPDIR/$pkg
1625 done
1627 rm -r $TMPDIR
1629 else
1631 # Check all pkg files.list in search match which specify the package
1632 # name and the full path to the file(s).
1633 for pkg in $INSTALLED/*; do
1634 if grep -qs "$2" $pkg/files.list; then
1635 . $pkg/receipt
1636 newline
1637 emsg "<c 33>$(_ 'Package %s:' $PACKAGE)</c>"
1638 awk -vtmp="$TMPLIST" -vfile="$2" -vcfile="$(colorize 32 $2)" '
1639 BEGIN { efile = gensub("\+", "\\\+", "g", file); }
1640 index($0, file) {
1641 gsub(efile, cfile);
1642 print " "$0;
1643 printf "1" >> tmp;
1645 ' $pkg/files.list
1646 fi
1647 done
1649 fi
1651 num=$(wc -m < $TMPLIST); rm $TMPLIST
1652 footer "$(_p '%s file' '%s files' "$num" \
1653 "$(colorize 32 $num)")"
1654 ;;
1657 search-pkgname)
1658 # Search for a package name
1659 if [ -z "$2" ]; then
1660 newline
1661 _ 'Please specify a pattern or file name to search for.'
1662 echo "$(_ 'Example:') 'tazpkg search-pkgname libnss'"
1663 newline
1664 exit 0
1665 fi
1666 title 'Search result for package "%s"' $2
1668 # Search for a file on mirror and output only the package name
1669 TMPLIST=$(mktemp)
1670 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1671 [ -f "$i" ] || continue
1672 lzcat $i | awk -F: -vT=$TMPLIST '
1673 BEGIN { P = "" }
1674 $2 ~ /'$2'/ {
1675 if ($1 != P) {
1676 print $1;
1677 printf "%s" 1 >> T;
1678 P = $1
1680 }'
1681 done
1682 match=$(wc -m < $TMPLIST)
1683 rm $TMPLIST
1685 footer "$(emsg "$(_p \
1686 '%s package' '%s packages' $match \
1687 "<c 32>$match</c>")")"
1688 ;;
1691 install|-i)
1692 # Install .tazpkg packages.
1693 check_root $@
1694 check_for_package_on_cmdline
1695 check_for_package_file
1696 check_for_installed_info
1698 if [ -n "$root" ]; then
1699 ROOT="$root";
1700 check_base_dir "$root"
1701 fi
1702 [ "$list" ] && INSTALL_LIST="$list"
1703 if [ "$rootconfig" ]; then
1704 if [ "$root" ]; then
1705 CACHE_DIR=$root/$CACHE_DIR
1706 SAVE_CACHE_DIR=$CACHE_DIR
1707 PKGS_DB=$root/$PKGS_DB
1708 else
1709 echo "rootconfig needs --root= option used." >&2
1710 exit 1
1711 fi
1712 fi
1714 # Get repositories priority list.
1715 look_for_priority
1717 # Check if forced install.
1718 if [ -z "$forced" ]; then
1719 check_for_installed_package $ROOT
1720 fi
1721 install_package $ROOT
1722 update_desktop_database $ROOT
1723 update_mime_database $ROOT
1724 update_icon_database $ROOT
1725 compile_glib_schemas $ROOT
1726 ;;
1729 install-list|get-install-list)
1730 # Install a set of packages from a list.
1731 check_root $@
1732 if [ -z "$2" ]; then
1733 newline
1734 longline "$(_ \
1735 "Please change directory (cd) to the packages repository and specify the \
1736 list of packages to install.")"
1737 echo "$(_ 'Example:') $(emsg '<b>tazpkg install-list</b> <c 33>packages.list</c>')"
1738 exit 0
1739 fi
1741 # Check if the packages list exist.
1742 if [ ! -f "$2" ]; then
1743 _ 'Unable to find list "%s"' "$2"
1744 exit 0
1745 fi
1747 LIST=$(cat $2)
1749 # Remember processed list
1750 export INSTALL_LIST="$2"
1752 # Set $COMMAND and install all packages.
1753 COMMAND=${1%-list}
1755 touch $2-processed
1757 # Upgrade tazpkg first. It may handle new features/formats...
1758 # then upgrade essential packages early
1759 for pkg in busybox-pam busybox gcc-lib-base glibc-base \
1760 slitaz-base-files tazpkg ; do
1761 pkg=$(egrep $pkg-[0-9] $INSTALL_LIST)
1762 [ -z "$pkg" ] && continue
1763 _ 'Adding implicit depends "%s"...' $pkg
1764 LIST="$pkg
1765 $LIST"
1766 done
1768 for pkg in $LIST; do
1769 grep -qs ^$pkg$ $2-processed && continue
1770 [ -d "$root/var/lib/tazpkg/installed" ] &&
1771 tazpkg $COMMAND $pkg --list="$2" "$3" "$4" "$5"
1772 done
1773 rm -f $2-processed ;;
1776 add-flavor)
1777 # Install a set of packages from a flavor.
1778 install_flavor $2 ;;
1781 install-flavor)
1782 # Install a set of packages from a flavor and purge other ones.
1783 install_flavor $2 --purge ;;
1786 set-release)
1787 # Change current release and upgrade packages.
1788 RELEASE=$2
1789 if [ -z "$RELEASE" ]; then
1790 newline
1791 _ 'Please specify the release you want on the command line.'
1792 echo "$(_ 'Example:') tazpkg set-release cooking"
1793 newline
1794 exit 0
1795 fi
1796 rm $PKGS_DB/mirror
1797 echo "$RELEASE" > /etc/slitaz-release
1798 tazpkg recharge && tazpkg upgrade
1800 # Install missing depends
1801 cd $INSTALLED
1802 for i in * ; do
1803 DEPENDS=""
1804 . $i/receipt
1805 for j in $DEPENDS ; do
1806 [ -d $j ] || tazpkg get-install $j
1807 done
1808 done ;;
1811 remove|-r)
1812 # Remove packages.
1813 check_root $@
1814 check_for_package_on_cmdline
1815 check_for_installed_info
1817 [ -n "$root" ] && ROOT="$root"
1819 if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then
1820 newline; _ 'Package "%s" is not installed.' $PACKAGE
1821 exit 0
1822 fi
1824 . $ROOT$INSTALLED/$PACKAGE/receipt
1826 # Info #1: dependent packages (to be processed later)
1827 ALTERED="$(awk -F$'\t' -vp=" $PACKAGE " '
1828 index(" " $8 " ", p) { printf " %s\n", $1 }
1829 ' $ROOT/$PKGS_DB/installed.info)"
1831 if [ -n "$ALTERED" ]; then
1832 _ 'The following packages depend on package "%s":' $PACKAGE
1833 echo "$ALTERED"
1834 fi
1836 # Info #2: changed packages (to be processed later)
1837 REFRESH=$(cd $ROOT$INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1839 if [ -n "$REFRESH" ]; then
1840 _ 'The following packages have been modified by package "%s":' $PACKAGE
1841 for i in $REFRESH; do
1842 echo " ${i%/modifiers}"
1843 done
1844 fi
1846 # Confirmation
1847 if im && [ -z "$auto" ]; then
1848 confirm "$(_ 'Remove package "%s" (%s)? (y/N)' $PACKAGE $VERSION$EXTRAVERSION)"
1849 if [ $? != 0 ]; then
1850 newline; _ 'Uninstallation of package "%s" cancelled.' $PACKAGE
1851 exit 0
1852 fi
1853 fi
1854 # We are here: non-interactive mode, or --auto, or answer 'y'
1856 # Removing package
1857 title 'Removing package "%s"' $PACKAGE
1859 # [1/4] Pre-remove commands
1860 if grep -q ^pre_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1861 action "Execution of pre-remove commands..."
1862 pre_remove $ROOT
1863 status
1864 fi
1866 # [2/4] Removing files
1867 action "Removing all files installed..."
1868 if [ -f $ROOT$INSTALLED/$PACKAGE/modifiers ]; then
1869 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1870 for mod in $(cat $ROOT$INSTALLED/$PACKAGE/modifiers); do
1871 [ -f $ROOT$INSTALLED/$mod/files.list ] && \
1872 [ $(grep "^$(echo $file | grepesc)$" $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && \
1873 continue 2
1874 done
1875 remove_with_path $ROOT$file
1876 done
1877 else
1878 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1879 remove_with_path $ROOT$file
1880 done
1881 fi
1882 status
1884 # [3/4] Post-remove commands
1885 if grep -q ^post_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1886 action "Execution of post-remove commands..."
1887 post_remove $ROOT
1888 status
1889 fi
1891 # [4/4] Remove package receipt and remove it from databases
1892 action "Removing package receipt..."
1893 rm -rf $ROOT$INSTALLED/$PACKAGE
1894 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg$/d" $PKGS_DB/installed.$SUM
1895 sed -i "/^$PACKAGE /d" $PKGS_DB/installed.info
1896 status
1898 footer "$(_ 'Package "%s" (%s) removed.' $PACKAGE $VERSION$EXTRAVERSION)"
1900 # Log this activity
1901 log_pkg Removed
1903 # Stop if non-interactive mode and no --auto option
1904 if ! im && [ -z "$auto" ]; then exit 0; fi
1906 # Process dependent packages
1907 if [ -n "$ALTERED" ]; then
1908 if [ "$auto" ]; then
1909 answer=0
1910 else
1911 confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' $PACKAGE)"
1912 answer=$?
1913 fi
1914 if [ "$answer" == '0' ]; then
1915 for i in $ALTERED; do
1916 if [ -d "$ROOT$INSTALLED/$i" ]; then
1917 echo "tazpkg remove $i $ROOTOPTS"
1918 fi
1919 done
1920 fi
1921 fi
1923 # Process changed packages
1924 if [ -n "$REFRESH" ]; then
1925 if [ "$auto" ]; then
1926 answer=0
1927 else
1928 confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' $PACKAGE)"
1929 answer=$?
1930 fi
1931 if [ "$answer" == '0' ]; then
1932 for i in $REFRESH; do
1933 if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then
1934 _ 'Check %s for reinstallation' "$INSTALLED/$i"
1935 continue
1936 fi
1937 echo "rm -r $ROOT$INSTALLED/$i"
1938 echo "tazpkg get-install ${i%/modifiers} $ROOTOPTS --forced"
1939 done
1940 fi
1941 fi
1943 ;;
1946 extract|-e)
1947 # Extract .tazpkg cpio archive into a directory.
1948 check_for_package_on_cmdline
1949 check_for_package_file
1950 title 'Extracting package "%s"' $PACKAGE
1952 # If no directory destination is found on the cmdline
1953 # we create one in the current dir using the package name.
1954 if [ -n "$TARGET_DIR" ]; then
1955 DESTDIR=$TARGET_DIR/$PACKAGE
1956 else
1957 DESTDIR=$PACKAGE
1958 fi
1959 mkdir -p $DESTDIR
1961 action "Copying original package..."
1962 cp $PACKAGE_FILE $DESTDIR
1963 status
1965 cd $DESTDIR
1966 extract_package
1967 [ -e "receipt" ] && \
1968 footer "$(_ 'Package "%s" is extracted to "%s"' $PACKAGE $DESTDIR)"
1969 ;;
1972 recompress)
1973 # Recompress .tazpkg cpio archive with lzma.
1974 check_for_package_on_cmdline
1975 check_for_package_file
1976 title 'Recompressing package "%s"' $PACKAGE
1977 mkdir -p $TMP_DIR
1979 action "Copying original package..."
1980 cp $PACKAGE_FILE $TMP_DIR
1981 status
1983 cd $TMP_DIR
1984 extract_package
1986 action "Recompressing the FS..."
1987 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1988 rm -rf fs
1989 status
1991 action "Creating new package..."
1992 find . -print | cpio -o -H newc --quiet > \
1993 $TOP_DIR/$(basename $PACKAGE_FILE).$$ && mv -f \
1994 $TOP_DIR/$(basename $PACKAGE_FILE).$$ \
1995 $TOP_DIR/$(basename $PACKAGE_FILE)
1996 status
1998 cd $TOP_DIR
1999 rm -rf $TMP_DIR
2000 separator; newline ;;
2003 list-config)
2004 # List configuration files installed.
2005 if [ -n "$box" ]; then
2006 mkdir -p $TMP_DIR; cd $TMP_DIR
2007 FILES="$INSTALLED/*/volatile.cpio.gz"
2008 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
2009 for i in $FILES; do
2010 zcat $i | cpio -idm --quiet > /dev/null
2011 find * -type f 2>/dev/null | while read file; do
2012 if [ ! -e /$file ]; then
2013 echo -n "----------|----|----|$(_n 'File lost')"
2014 else
2015 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
2016 cmp $file /$file > /dev/null 2>&1 || \
2017 echo -n "$(stat -c "%.16y" /$file)"
2018 fi
2019 echo "|/$file"
2020 done
2021 rm -rf *
2022 done
2023 cd $TOP_DIR
2024 rm -rf $TMP_DIR
2025 else
2026 im && title 'Configuration files'
2027 for i in $INSTALLED/*/volatile.cpio.gz; do
2028 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
2029 [ -f "$i" ] || continue
2030 zcat $i | cpio -t --quiet
2031 done | sed 's|^|/|' | sort
2032 im && footer
2033 fi ;;
2036 repack-config)
2037 # Create SliTaz package archive from configuration files.
2038 mkdir -p $TMP_DIR; cd $TMP_DIR
2039 CONFIG_VERSION=1.0
2040 mkdir config-$CONFIG_VERSION
2041 cd config-$CONFIG_VERSION
2042 for i in $INSTALLED/*/volatile.cpio.gz; do
2043 zcat $i | cpio -t --quiet
2044 done > files.list
2045 mkdir fs
2046 cd fs
2047 ( cd / ; cpio -o -H newc --quiet ) < ../files.list | cpio -idm --quiet > /dev/null
2048 mkdir -p etc/tazlito
2049 for i in $INSTALLED/*/receipt; do
2050 EXTRAVERSION=""
2051 . $i
2052 echo "$PACKAGE-$VERSION$EXTRAVERSION"
2053 done > etc/tazlito/config-packages.list
2054 cd ..
2055 echo "etc/tazlito/config-packages.list" >> files.list
2056 pkg_date=$(date +"%x %X")
2057 cat > receipt <<EOT
2058 # SliTaz package receipt.
2060 PACKAGE="config"
2061 VERSION="$CONFIG_VERSION"
2062 CATEGORY="base-system"
2063 SHORT_DESC="$(_n 'User configuration backup on date %s' $pkg_date)"
2064 DEPENDS="$(ls $INSTALLED)"
2065 EOT
2066 cd ..
2067 tazpkg pack config-$CONFIG_VERSION
2068 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
2069 cd $TOP_DIR
2070 rm -rf $TMP_DIR
2071 ;;
2074 repack)
2075 # Create SliTaz package archive from an installed package.
2076 check_for_package_on_cmdline
2077 check_for_receipt
2078 EXTRAVERSION=""
2079 . $INSTALLED/$PACKAGE/receipt
2080 title 'Repacking "%s"' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
2082 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
2083 _ "Can't repack package \"%s\"" $PACKAGE
2084 exit 1
2085 fi
2087 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
2088 _ "Can't repack, \"%s\" files have been modified by:" $PACKAGE
2089 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
2090 echo " $i"
2091 done
2092 exit 1
2093 fi
2095 MISSING=""
2096 while read i; do
2097 [ -e "$i" ] && continue
2098 [ -L "$i" ] || MISSING="$MISSING\n $i"
2099 done < $INSTALLED/$PACKAGE/files.list
2100 if [ -n "$MISSING" ]; then
2101 _n "Can't repack, the following files are lost:"
2102 echo -e "$MISSING"
2103 exit 1
2104 fi
2106 mkdir -p $TMP_DIR; cd $TMP_DIR
2107 FILES="fs.cpio.lzma\n"
2108 for i in $(ls $INSTALLED/$PACKAGE); do
2109 case $i in
2110 volatile.cpio.gz|modifiers) ;;
2111 *) cp $INSTALLED/$PACKAGE/$i .; FILES="$FILES$i\n" ;;
2112 esac
2113 done
2115 ln -s / rootfs
2116 mkdir tmp
2117 sed 's/^/rootfs/' < files.list | cpio -o -H newc --quiet | \
2118 { cd tmp ; cpio -idm --quiet >/dev/null; cd ..; }
2119 mv tmp/rootfs fs
2121 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
2122 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
2123 { cd fs; cpio -idm --quiet; cd ..; }
2124 fi
2126 if fgrep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
2127 . $INSTALLED/$PACKAGE/receipt
2128 repack_cleanup fs
2129 fi
2131 if [ -f $INSTALLED/$PACKAGE/$CHECKSUM ]; then
2132 sed 's, , fs,' < $INSTALLED/$PACKAGE/$CHECKSUM | \
2133 $CHECKSUM -s -c || {
2134 _ "Can't repack, %s error." $CHECKSUM
2135 cd $TOP_DIR
2136 rm -rf $TMP_DIR
2137 exit 1
2139 fi
2141 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2142 echo -e "$FILES" | cpio -o -H newc --quiet > \
2143 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
2144 cd $TOP_DIR
2145 \rm -R $TMP_DIR
2146 _ 'Package "%s" repacked successfully.' $PACKAGE
2147 _ 'Size: %s' "$(du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg)"
2148 newline ;;
2151 pack)
2152 # Create SliTaz package archive using cpio and lzma.
2153 # TODO: Cook also pack packages, we should share code in libpkg.sh
2154 check_for_package_on_cmdline
2155 cd $PACKAGE
2156 if [ ! -f "receipt" ]; then
2157 _ 'Receipt is missing. Please read the documentation.'
2158 exit 0
2159 fi
2161 title 'Packing package "%s"' $PACKAGE
2162 # Create files.list with redirecting find outpout.
2164 action "Creating the list of files..."
2165 cd fs
2166 find . -type f -print > ../files.list
2167 find . -type l -print >> ../files.list
2168 cd .. && sed -i s/'^.'/''/ files.list
2169 status
2171 action 'Creating %s of files...' $CHECKSUM
2172 while read file; do
2173 [ -L "fs$file" ] && continue
2174 [ -f "fs$file" ] || continue
2175 case "$file" in
2176 /lib/modules/*/modules.*|*.pyc) continue;;
2177 esac
2178 $CHECKSUM "fs$file" | sed 's/ fs/ /'
2179 done < files.list > $CHECKSUM
2180 status
2182 UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
2183 description.txt 2> /dev/null | awk \
2184 '{ sz=$1 } END { print sz }')
2185 # Build cpio archives.
2187 action "Compressing the FS..."
2188 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2189 rm -rf fs
2190 status
2192 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
2193 $CHECKSUM description.txt 2> /dev/null | awk \
2194 '{ sz=$1 } END { print sz }')
2196 action "Updating receipt sizes..."
2197 sed -i s/^PACKED_SIZE.*$// receipt
2198 sed -i s/^UNPACKED_SIZE.*$// receipt
2199 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
2200 status
2202 action "Creating full cpio archive..."
2203 find . -print | cpio -o -H newc --quiet > ../$PACKAGE.tazpkg
2204 status
2206 action "Restoring original package tree..."
2207 unlzma -c fs.cpio.lzma | cpio -idm --quiet
2208 status
2210 rm fs.cpio.lzma && cd ..
2211 footer "$(_ 'Package "%s" compressed successfully.' $PACKAGE)"
2212 _ 'Size: %s' "$(ls -lh $PACKAGE.tazpkg | awk '{print $5}')"
2213 ;;
2216 recharge)
2217 # Recharge packages databases from a mirror.
2219 # WARNING: The 'mirrors' file has all SliTaz mirrors but 'mirror'
2220 # must have only the chosen main mirror.
2222 check_root $@
2224 # usage: tazpkg recharge [--root=path] [main|<repository>]
2226 ARG="$2"
2227 if [ -n "$root" ]; then
2228 PKGS_DB="$root$PKGS_DB"
2229 [ "${2#--}" != "$2" ] && ARG="$3"
2230 fi
2232 case "$ARG" in
2233 main) repo_to_recharge="$PKGS_DB";;
2234 '') repo_to_recharge="$PKGS_DB $PKGS_DB/undigest/*";;
2235 *) repo_to_recharge="$PKGS_DB/undigest/$ARG"
2236 if [ ! -d "$repo_to_recharge" ]; then
2237 _ "Repository \"%s\" doesn't exist." "$repo_to_recharge" >&2
2238 exit 1
2239 fi
2240 ;;
2241 esac
2243 for path in $repo_to_recharge; do
2244 [ ! -f $path/mirror ] && continue # skip
2245 cd $path
2246 mirror="$(cat mirror)"
2248 # Repository name
2249 if [ "$path" == "$PKGS_DB" ]; then
2250 repo_name='Main'
2251 else
2252 repo_name="$(_n 'Undigest %s' "$(basename $path)")"
2253 fi
2255 # Don't let ID be a symlink when using local repository.
2256 if [ -h ID ]; then mv -f ID ID.lnk; cat ID.lnk > ID; rm ID.lnk; fi
2257 if [ -h IDs ]; then mv -f IDs IDs.lnk; cat IDs.lnk > IDs; rm IDs.lnk; fi
2259 [ -f ID ] && mv ID ID.bak # Compatibility with "old" ID
2260 [ -f IDs ] && mv IDs IDs.bak
2261 download_from "$mirror" IDs
2262 [ -e 'IDs' ] && awk '{print $1}' IDs > ID # Compatibility with "old" ID
2264 # Check if recharging is needed
2265 if [ -f 'IDs' ] && cmp -s IDs IDs.bak; then
2266 _ 'Repository "%s" is up to date.' "$repo_name"
2267 rm IDs.bak ID.bak
2268 continue
2269 fi
2270 rm IDs.bak ID.bak 2>/dev/null
2272 title 'Recharging repository "%s"' "$repo_name"
2273 [ -e 'IDs' ] && _ 'Database timestamp: %s' "$(date -d "@$(awk '{print $2}' IDs)" "+%x %R")"
2275 action 'Creating backup of the last packages list...'
2276 for i in packages.desc packages.$SUM packages.txt packages.list \
2277 packages.equiv files.list.lzma extra.list mirrors packages.info; do
2278 [ -f "$i" ] && mv -f $i $i.bak 2>/dev/null
2279 done
2280 status
2282 # Download and extract bundle: extra.list, mirrors, files-list.md5,
2283 # packages.{info,desc,md5,txt,list,equiv}
2284 bundle='bundle.tar.lzma'
2285 action 'Getting "%s"...' $bundle
2286 download_from "$mirror" $bundle
2287 status
2288 if [ -f "$bundle" ]; then
2289 busybox tar -xaf $bundle; rm $bundle
2290 else
2291 recharging_failed $path; continue
2292 fi
2294 # Download files.list.lzma
2295 files_local='files.list.lzma'; files_remote='files-list.lzma'
2296 if [ -e "$files_local.bak" ]; then
2297 md5sum $files_local.bak | awk '{printf $1}' > files-list.md5.bak
2298 if cmp -s files-list.md5 files-list.md5.bak; then
2299 mv $files_local.bak $files_remote
2300 else
2301 action 'Getting "%s"...' $files_remote
2302 download_from "$mirror" $files_remote
2303 status
2304 fi
2305 else
2306 action 'Getting "%s"...' $files_remote
2307 download_from "$mirror" $files_remote
2308 status
2309 fi
2311 if [ ! -e "$files_remote" ]; then
2312 recharging_failed $path; continue
2313 fi
2314 mv -f $files_remote $files_local
2316 # Remove old database files (but packages.list.bak, extra.list.bak)
2317 for i in packages.desc packages.$SUM packages.txt packages.equiv \
2318 files.list.lzma mirrors packages.info files-list.md5; do
2319 [ -f "$i.bak" ] && rm $i.bak 2>/dev/null
2320 done
2322 footer "$(_ 'Last database is ready to use.')"
2324 # Check diff
2325 if [ -f 'packages.list.bak' ]; then
2326 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
2327 rm packages.list.bak
2328 if [ -f 'extra.list.bak' ]; then
2329 if [ -f 'extra.list' ]; then
2330 awk -F'|' '{print $1 " (extra)"}' extra.list > extra.list1
2331 awk -F'|' '{print $1 " (extra)"}' extra.list.bak > extra.list1.bak
2332 diff -u extra.list1.bak extra.list1 | grep ^+[a-z] >> packages.diff
2333 rm extra.list.bak extra.list1 extra.list1.bak
2334 else
2335 mv extra.list.bak extra.list
2336 fi
2337 fi
2338 sed -i s/+// packages.diff
2340 new_pkgs=$(wc -l < packages.diff)
2341 if [ "$new_pkgs" -gt 0 ]; then
2342 title 'Mirrored packages diff'
2343 cat packages.diff
2344 footer "$(emsg "$(_p \
2345 '%s new package on the mirror.' \
2346 '%s new packages on the mirror.' $new_pkgs \
2347 "<c 32>$new_pkgs</c>")")"
2348 fi
2349 else
2350 longline "$(_ "Note that next time you recharge the \
2351 list, a list of differences will be displayed to show new and upgradeable \
2352 packages.")"
2353 fi
2354 done
2355 newline ;;
2358 help-up)
2359 # Options available for the command: up
2360 newline; usage_up; newline
2361 exit 1 ;;
2364 up|upgrade)
2365 check_root
2367 # This is the new way to upgrade packages making 'upgrade' and
2368 # upgradeable out-of-date. This new way is much, much more faster!
2369 # Look into installed packages and get data from receipt, it is fast
2370 # and easy to handle vars after using only md5sum to compare packages
2372 for opt in $@; do
2373 case "$opt" in
2374 --recharge|-r) tazpkg recharge ;;
2375 --install|-i) install="y" ;;
2376 --check|-c) install="n" ;;
2377 esac
2378 done
2379 time="$(date +%s)"
2381 look_for_priority
2382 for repo in $priority; do
2383 pkg_list="$repo/packages.list"
2384 mtime=$(find $pkg_list -mtime +7)
2385 if [ -n "$mtime" ]; then
2386 if [ "$repo" == "$PKGS_DB" ]; then
2387 repo_name='main'
2388 else
2389 repo_name="${repo##*/}"
2390 fi
2391 _ 'List "%s" is older than one week... Recharging.' $pkg_list
2392 tazpkg recharge $repo_name
2393 fi
2394 done
2396 emsg "<n>$(_ 'Package')<i 28> $(_ 'Version')<i 48> $(_ 'Status')<->"
2398 cd $INSTALLED
2399 echo -n > $UP_LIST
2400 blocked_count=0
2401 installed_sum="$PKGS_DB/installed.$SUM"
2403 for pkg in *; do
2404 [ ! -d $pkg ] && continue
2405 unset VERSION EXTRAVERSION
2406 . $pkg/receipt
2407 md5=$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" \
2408 $installed_sum | awk '{print $1}')
2409 for repo in $priority; do
2410 pkg_desc="$repo/packages.desc"
2411 pkg_list="$repo/packages.list"
2412 pkg_sum="$repo/packages.$SUM"
2414 if ! fgrep -q "$md5 $PACKAGE-" $pkg_sum; then
2415 # Jump to next repository in priority if pkg doesn't exist
2416 # in this one.
2417 grep -q ^$PACKAGE- $pkg_list || continue
2419 emsg -n "$PACKAGE<i 28> $VERSION"
2421 # Skip pkgs listed in $PKGS_DB/blocked-packages.list
2422 if $(grep -qs "^$PACKAGE" $BLOCKED); then
2423 blocked_count=$(($blocked_count + 1))
2424 emsg "<i 48><c 31> $(_ 'Blocked')</c>"
2425 break
2426 fi
2428 new=$(grep "^$PACKAGE |" $pkg_desc | awk '{print $3}')
2430 if [ "$VERSION" == "$new" ]; then
2431 emsg "<i 48><c 34> $(_ 'New build')</c>"
2432 else
2433 emsg "<i 48><c 32> $(_ 'New version %s' $new)</c>"
2434 fi
2435 echo "$PACKAGE" >> $UP_LIST
2436 break
2437 fi
2438 done
2439 done
2440 sed -i /^$/d $UP_LIST
2441 upnb=$(wc -l < $UP_LIST)
2442 pkgs=$(ls | wc -l)
2443 time=$(($(date +%s) - $time))
2444 if [ "$upnb" == 0 ]; then
2445 install="n"
2446 _ 'System is up-to-date...'
2447 fi
2449 footer "$(emsg "$(_p \
2450 '%s installed package scanned in %ds' \
2451 '%s installed packages scanned in %ds' $pkgs \
2452 "<c 32>$pkgs</c>" $time)")"
2454 if [ "$upnb" != 0 ]; then
2455 blocked="$(_p \
2456 '%s blocked' \
2457 '%s blocked' $blocked_count \
2458 $blocked_count)"
2460 boldify "$(_p \
2461 'You have %s available upgrade (%s)' \
2462 'You have %s available upgrades (%s)' $upnb \
2463 $upnb "$blocked")"
2464 newline
2465 fi
2467 # Pkgs to upgrade ? Skip, let install them all or ask user
2468 [ "$install" == 'n' ] && exit 0
2469 if [ "$upnb" -gt 0 ]; then
2470 if [ "$install" == 'y' ]; then
2471 answer=0
2472 else
2473 confirm "$(_ 'Do you wish to install them now? (y/N)')"
2474 answer=$?
2475 fi
2476 case "$answer" in
2477 0)
2478 for pkg in $(cat $UP_LIST); do
2479 echo 'y' | tazpkg get-install $pkg --forced
2480 done
2481 # List is generated each time and must be cleaned so
2482 # tazpkg-notify doesn't find upgrades anymore.
2483 rm $UP_LIST; touch $UP_LIST ;;
2484 *)
2485 _ 'Leaving without any upgrades installed.'
2486 newline
2487 exit 0 ;;
2488 esac
2489 fi
2490 newline ;;
2493 bugs)
2494 # Show known bugs in package(s)
2495 cd $INSTALLED
2496 shift
2497 LIST=$@
2498 [ -z "$LIST" ] && LIST=$(ls)
2499 MSG=$(_n 'No known bugs.')
2501 title 'Known bugs in packages'
2502 for PACKAGE in $LIST; do
2503 BUGS=''
2504 EXTRAVERSION=''
2505 . $PACKAGE/receipt
2506 if [ -n "$BUGS" ]; then
2507 MSG=$(_n 'Bug list completed')
2508 newline
2509 _ 'Bugs in package "%s" version %s:' $PACKAGE $VERSION$EXTRAVERSION
2510 cat <<EOT
2511 $BUGS
2512 EOT
2513 fi
2514 done
2515 footer "$MSG" ;;
2518 check)
2519 # Check installed packages set.
2520 check_root $@
2522 # Get repositories priority list.
2523 look_for_priority
2525 cd $INSTALLED
2526 for PACKAGE in $(ls); do
2528 if [ ! -f $PACKAGE/receipt ]; then
2529 _ 'The package "%s" installation has not completed' $PACKAGE
2530 continue
2531 fi
2533 DEPENDS=""
2534 EXTRAVERSION=""
2535 . $PACKAGE/receipt
2536 if [ -s $PACKAGE/modifiers ]; then
2537 _ 'The package "%s" has been modified by:' $PACKAGE-$VERSION$EXTRAVERSION
2538 for i in $(cat $PACKAGE/modifiers); do
2539 echo " $i"
2540 done
2541 fi
2543 MSG="$(_n 'Files lost from package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2544 while read file; do
2545 [ -e "$file" ] && continue
2546 if [ -L "$file" ]; then
2547 MSG="$MSG $(_n 'target of symlink')"
2548 fi
2549 echo -e "$MSG $file"
2550 MSG=""
2551 done < $PACKAGE/files.list
2553 MSG="$(_n 'Missing dependencies for package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2554 for i in $DEPENDS; do
2555 [ -d $i ] && continue
2556 [ -d $(equivalent_pkg $i) ] && continue
2557 echo -e "$MSG $i"
2558 MSG=""
2559 done
2561 MSG="$(_n 'Dependencies loop between "%s" and:' $PACKAGE)\n"
2562 ALL_DEPS=""
2563 check_for_deps_loop $PACKAGE $DEPENDS
2564 done
2566 _ 'Looking for known bugs...'
2567 tazpkg bugs
2569 if [ "$2" == "--full" ]; then
2570 separator
2572 for file in */$CHECKSUM; do
2573 CONFIG_FILES=""
2574 . $(dirname "$file")/receipt
2575 [ -s "$file" ] || continue
2576 while read md5 f; do
2577 [ -f $f ] || continue
2578 for i in $CONFIG_FILES; do
2579 case "$f" in
2580 $i|$i/*) continue 2;;
2581 esac
2582 done
2583 echo "$md5 $f"
2584 done < "$file" | busybox $CHECKSUM -c - 2> /dev/null | \
2585 grep -v OK$ | sed "s/FAILED$/$CHECKSUM MISMATCH/"
2586 done
2588 FILES=" "
2589 for file in $(cat */files.list); do
2590 [ -d "$file" ] && continue
2591 case "$FILES" in *\ $file\ *) continue;; esac
2592 [ $(grep "^$(echo $file | grepesc)$" */files.list 2> /dev/null | \
2593 wc -l) -gt 1 ] || continue
2594 FILES="$FILES$file "
2595 _ 'The following packages provide file "%s":' $file
2596 grep -l "^$(echo $file | grepesc)$" */files.list | \
2597 while read f; do
2598 pkg=${f%/files.list}
2599 if [ -f $pkg/modifiers ]; then
2600 overriders=$(_n '(overridden by %s)' "$(tr '\n' ' ' | sed 's| $||' < $pkg/modifiers)")
2601 else
2602 overriders=''
2603 fi
2604 echo -n " $pkg $overriders"
2605 newline
2606 done
2607 done
2609 MSG="$(_n 'No package has installed the following files:')\n"
2610 find /etc /bin /sbin /lib /usr /var/www -not -type d 2>/dev/null | \
2611 while read file; do
2612 case "$file" in *\[*) continue;; esac
2613 grep -q "^$(echo $file | grepesc)$" */files.list && continue
2614 echo -e "$MSG $file"
2615 MSG=""
2616 done
2617 fi
2618 _ 'Check completed.'; echo ;;
2621 block|-b)
2622 # Add a pkg name to the list of blocked packages.
2623 check_root $@
2624 check_for_package_on_cmdline
2625 newline
2626 if [ ! -d $INSTALLED/$PACKAGE ]; then
2627 _ 'Package "%s" is not installed.' $PACKAGE; exit
2628 fi
2629 if grep -qs "^$PACKAGE" $BLOCKED; then
2630 _ 'Package "%s" is already blocked.' $PACKAGE
2631 else
2632 echo $PACKAGE >> $BLOCKED
2633 # Log this activity
2634 . $INSTALLED/$PACKAGE/receipt; log_pkg Blocked
2635 _ 'Package "%s" blocked.' $PACKAGE
2636 fi
2637 newline ;;
2640 unblock|-u)
2641 # Remove a pkg name from the list of blocked packages.
2642 check_root $@
2643 check_for_package_on_cmdline
2644 newline
2645 if [ ! -d $INSTALLED/$PACKAGE ]; then
2646 _ 'Package "%s" is not installed.' $PACKAGE; exit
2647 fi
2648 if grep -qs "^$PACKAGE" $BLOCKED; then
2649 sed -i "/^$PACKAGE\$/d" $BLOCKED
2650 # Log this activity
2651 . $INSTALLED/$PACKAGE/receipt; log_pkg Unblocked
2652 _ 'Package "%s" unblocked.' $PACKAGE
2653 else
2654 _ 'Package "%s" is not blocked.' $PACKAGE
2655 fi
2656 newline ;;
2659 chblock)
2660 # Change package's blocked status.
2661 check_root $@
2662 check_for_package_on_cmdline
2663 newline
2664 if [ ! -d $INSTALLED/$PACKAGE ]; then
2665 _ 'Package "%s" is not installed.' $PACKAGE; exit
2666 fi
2667 if grep -qs "^$PACKAGE" $BLOCKED; then
2668 sed -i "/^$PACKAGE\$/d" $BLOCKED
2669 # Log this activity
2670 . $INSTALLED/$PACKAGE/receipt; log_pkg Unblocked
2671 _ 'Package "%s" unblocked.' $PACKAGE
2672 else
2673 echo $PACKAGE >> $BLOCKED
2674 # Log this activity
2675 . $INSTALLED/$PACKAGE/receipt; log_pkg Blocked
2676 _ 'Package "%s" blocked.' $PACKAGE
2677 fi
2678 newline ;;
2681 get|-g)
2682 # Download a package with wget.
2683 check_root $@
2684 check_for_package_on_cmdline
2685 check_for_packages_list
2687 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2688 if [ "$rootconfig" ]; then
2689 if [ "$root" ]; then
2690 CACHE_DIR=$root/$CACHE_DIR
2691 SAVE_CACHE_DIR=$CACHE_DIR
2692 PKGS_DB=$root/$PKGS_DB
2693 else
2694 _ 'rootconfig needs --root= option used.' >&2
2695 exit 1
2696 fi
2697 fi
2699 # Get repositories priority list.
2700 look_for_priority
2702 CURRENT_DIR=$PWD
2703 cd $CACHE_DIR
2704 if check_for_package_in_list check ; then
2705 if [ -f "$PACKAGE.tazpkg" ]; then
2706 _ 'Package "%s" already in the cache' $PACKAGE
2707 # Check package download was finished
2708 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2709 _ 'Continuing package "%s" download' $PACKAGE
2710 download $PACKAGE.tazpkg
2712 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2713 rm -f $PACKAGE.tazpkg
2714 download $PACKAGE.tazpkg
2715 fi
2716 else
2717 download $PACKAGE.tazpkg
2718 fi
2719 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2720 elif download_get_script $PACKAGE /tmp/$PACKAGE.$$ ; then
2721 install_package_from_get_script /tmp/$PACKAGE.$$ "$ROOT" --get
2722 PACKAGE_FILE=$(ls $PWD/$PACKAGE-*.tazpkg)
2723 fi
2724 [ "$PWD" != "$CURRENT_DIR" ] &&
2725 cp -a $PACKAGE_FILE $CURRENT_DIR ;;
2728 get-install|-gi)
2729 # Download and install a package.
2730 check_root $@
2731 check_for_package_on_cmdline
2732 check_for_packages_list
2734 DO_CHECK=''
2735 [ -n "$forced" ] && DO_CHECK=no
2736 [ -n "$root" ] && ROOT="$root" && check_base_dir "$root"
2737 [ -n "$list" ] && INSTALL_LIST="$list"
2738 if [ -n "$rootconfig" ]; then
2739 if [ -n "$root" ]; then
2740 CACHE_DIR="$root/$CACHE_DIR"
2741 SAVE_CACHE_DIR="$CACHE_DIR"
2742 PKGS_DB="$root/$PKGS_DB"
2743 else
2744 _ 'rootconfig needs --root= option used.' >&2
2745 exit 1
2746 fi
2747 fi
2749 # Get repositories priority list.
2750 look_for_priority
2752 AUTOEXEC='no'
2753 if ! check_for_package_in_list check; then
2754 CACHE_DIR="${CACHE_DIR%/*}/get"
2755 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
2756 if download_get_script $PACKAGE /tmp/$PACKAGE.$$ ; then
2757 install_package_from_get_script /tmp/$PACKAGE.$$ $ROOT
2758 exit 0
2759 else
2760 PACKAGE="get-$PACKAGE"
2761 AUTOEXEC="$PACKAGE"
2762 check_for_package_in_list
2763 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
2764 $AUTOEXEC $ROOT
2765 exit 0
2766 fi
2767 fi
2768 fi
2769 # Check if no forced install.
2770 if [ -z "$forced" ]; then
2771 check_for_installed_package $ROOT
2772 fi
2773 cd $CACHE_DIR
2774 if [ -f "$PACKAGE.tazpkg" ]; then
2775 _ 'Package "%s" already in the cache' $PACKAGE
2776 # Check package download was finished
2777 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2778 _ 'Continuing package "%s" download' $PACKAGE
2779 download $PACKAGE.tazpkg
2781 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2782 rm -f $PACKAGE.tazpkg
2783 download $PACKAGE.tazpkg
2784 fi
2785 else
2786 newline
2787 download $PACKAGE.tazpkg
2788 fi
2789 PACKAGE_FILE="$CACHE_DIR/$PACKAGE.tazpkg"
2790 [ -n "$rootconfig" ] && PKGS_DB="${PKGS_DB#$root}"
2791 install_package "$ROOT"
2792 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
2793 update_desktop_database $ROOT
2794 update_mime_database $ROOT ;;
2797 clean-cache|-cc)
2798 # Remove all downloaded packages.
2799 check_root $@
2800 files=$(find $CACHE_DIR -name *.tazpkg | wc -l)
2801 size=$(du -hs $CACHE_DIR | cut -f1 | sed 's|\.0||'); [ "$files" == '0' ] && size="0K"
2803 title "Cleaning cache directory..."
2804 action 'Path: %s' $CACHE_DIR
2805 rm -rf $CACHE_DIR/*
2806 status
2808 footer "$(_p \
2809 '%s file removed from cache (%s).' \
2810 '%s files removed from cache (%s).' $files \
2811 "$(colorize 32 "$files")" $size)"
2812 ;;
2815 list-undigest)
2816 # list undigest URLs.
2817 if [ -n "$box" ]; then
2818 for i in $PKGS_DB/undigest/*/mirror; do
2819 [ -f "$i" ] || continue
2820 echo "$(basename $(dirname $i))|$(cat $i)"
2821 done
2822 else
2823 title 'Current undigest(s)'
2824 for i in $PKGS_DB/undigest/*/mirror; do
2825 if [ ! -f "$i" ]; then
2826 _ 'No undigest mirror found.'
2827 exit 1
2828 fi
2829 echo "$(basename $(dirname $i)) $(cat $i)"
2830 done
2831 newline
2832 fi ;;
2835 remove-undigest)
2836 # remove undigest URL.
2837 check_root $@
2838 undigest="$2"
2839 if [ -d "$PKGS_DB/undigest/$2" ]; then
2840 confirm "$(_ 'Remove "%s" undigest? (y/N)' $undigest)"
2841 if [ $? == 0 ]; then
2842 action 'Removing "%s" undigest...' $undigest
2843 rm -rf $PKGS_DB/undigest/$2
2844 status
2845 rmdir $PKGS_DB/undigest 2>/dev/null
2846 fi
2847 else
2848 _ 'Undigest "%s" not found' $undigest
2849 fi ;;
2852 add-undigest|setup-undigest)
2853 # Add undigest URL.
2854 check_root $@
2855 undigest=$2
2856 [ -d $PKGS_DB/undigest ] || mkdir $PKGS_DB/undigest
2857 if [ -z "$undigest" ]; then
2858 i=1
2859 while [ -d "$PKGS_DB/undigest/$i" ]; do
2860 i=$(($i+1))
2861 done
2862 undigest=$i
2863 fi
2864 if [ ! -d "$PKGS_DB/undigest/$undigest" ]; then
2865 _ 'Creating new undigest "%s".' $undigest
2866 mkdir $PKGS_DB/undigest/$undigest
2867 fi
2868 setup_mirror $PKGS_DB/undigest/$undigest $3 ;;
2871 setup-mirror|-sm)
2872 # Change mirror URL.
2873 check_root $@
2874 setup_mirror $PKGS_DB $2 ;;
2877 reconfigure)
2878 # Replay post_install from receipt
2879 check_for_package_on_cmdline
2880 check_root $@
2881 ROOT=''
2882 while [ -n "$3" ]; do
2883 case "$3" in
2884 --root=*)
2885 ROOT="${3#--root=}/" ;;
2886 *)
2887 shift 2
2888 u_opt="$*"
2889 newline >&2
2890 _ 'Unknown option "%s".' $u_opt >&2
2891 exit 1 ;;
2892 esac
2893 shift
2894 done
2895 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2896 check_for_receipt $ROOT
2897 # Check for post_install
2898 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2899 . $ROOT$INSTALLED/$PACKAGE/receipt
2900 post_install $ROOT
2901 # Log this activity
2902 [ -n "$ROOT" ] || log_pkg Reconfigured
2903 else
2904 newline
2905 _ 'Nothing to do for package "%s".' $PACKAGE
2906 fi
2907 else
2908 newline
2909 _ 'Package "%s" is not installed.' $PACKAGE
2910 _ 'Install package with "%s" or "%s"' 'tazpkg install' 'tazpkg get-install'
2911 newline
2912 fi ;;
2915 shell)
2916 # TazPKG SHell
2917 if [ "$(id -u)" == '0' ]; then
2918 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2919 else
2920 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2921 fi
2922 if [ "$2" != "--noheader" ]; then
2923 clear
2924 title 'TazPKG SHell.'
2925 _ "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
2926 newline
2927 fi
2928 while true; do
2929 echo -en "$PROMPT"; read cmd
2930 case $cmd in
2931 q|quit)
2932 break ;;
2933 shell)
2934 _ 'You are already running a TazPKG SHell.' ;;
2935 su)
2936 su -c 'exec tazpkg shell --noheader' && break ;;
2937 "")
2938 continue ;;
2939 *)
2940 tazpkg $cmd ;;
2941 esac
2942 done ;;
2945 depends)
2946 # Display dependencies tree
2947 cd $INSTALLED
2948 ALL_DEPS=''
2949 if [ -f "$2/receipt" ]; then
2950 dep_scan $2 ''
2951 fi ;;
2954 rdepends)
2955 # Display reverse dependencies tree
2956 cd $INSTALLED
2957 ALL_DEPS=''
2958 if [ -f "$2/receipt" ]; then
2959 rdep_scan $2
2960 fi ;;
2963 list-suggested)
2964 for i in $(ls -d $INSTALLED/*); do
2965 . $i/receipt
2966 if [ -n "$SUGGESTED" ]; then
2967 if [ -z "$all" ]; then
2968 for s in $SUGGESTED; do
2969 [ -d "$INSTALLED/$s" ] && \
2970 SUGGESTED="$(echo -n $SUGGESTED | sed "s/$s//")"
2971 done
2972 fi
2973 cat <<EOT
2974 $(boldify $(echo $PACKAGE):) $SUGGESTED
2975 EOT
2976 fi
2977 SUGGESTED=''
2978 done ;;
2981 convert|-c)
2982 # convert misc package format to .tazpkg
2983 check_for_package_file
2984 shift
2985 tazpkg-convert $@
2986 ;;
2989 link)
2990 # link a package from another slitaz installation
2991 PACKAGE=$2
2992 if [ ! -d "$TARGET_DIR" -o \
2993 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
2994 _ 'Usage: tazpkg link package_name slitaz_root'
2995 longline "$(
2996 _n 'Example:'
2997 echo -n ' '
2998 _ '"%s" will use less than 100k in your running system RAM.' \
2999 'tazpkg link openoffice /mnt')"
3000 exit 1
3001 fi
3002 if [ -e "$INSTALLED/$PACKAGE" ]; then
3003 _ 'Package "%s" is already installed.' $PACKAGE
3004 exit 1
3005 fi
3006 ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
3007 DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
3008 MISSING=''
3009 for i in $DEPENDS; do
3010 [ -e $INSTALLED/$i ] && continue
3011 MISSING="$MISSING$i "
3012 _ 'Missing: %s' $i
3013 done
3014 if [ -n "$MISSING" ]; then
3015 newline
3016 confirm "$(_ 'Link all missing dependencies? (y/N)')"
3017 answer=$?
3018 newline
3019 if [ "$answer" == 0 ]; then
3020 for i in $MISSING; do
3021 tazpkg link $i $TARGET_DIR
3022 done
3023 else
3024 newline
3025 _ 'Leaving dependencies unresolved for package "%s"' $PACKAGE
3026 _ 'The package is installed but probably will not work.'
3027 newline
3028 fi
3029 fi
3030 . $INSTALLED/$PACKAGE/receipt
3031 if grep -q ^pre_install $INSTALLED/$PACKAGE/receipt; then
3032 pre_install
3033 fi
3034 while read path; do
3035 [ -e "$path" ] && continue
3036 while true; do
3037 dir="$(dirname $path)"
3038 [ -e "$dir" ] && break
3039 path="$dir"
3040 done
3041 ln -s "$TARGET_DIR$path" "$dir"
3042 done < $INSTALLED/$PACKAGE/files.list
3043 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
3044 post_install
3045 fi ;;
3048 usage|*)
3049 # Print a short help or give usage for an unknown or empty command.
3050 usage ;;
3051 esac
3053 exit 0