tazpkg view tazpkg @ rev 809

tazpkg: speedup get scripts (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu May 28 13:02:55 2015 +0200 (2015-05-28)
parents 046705e54b19
children 941baf789cb7
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=gzip
953 tazpkg pack $PACKAGE-$VERSION
955 # Clean to save RAM memory before installation
956 rm -rf $PACKAGE-$VERSION
958 if [ "$3" == "--get" ]; then
959 mv $PACKAGE-$VERSION.tazpkg $TOP_DIR
960 else
961 # Install pseudo package
962 tazpkg install $PACKAGE-$VERSION.tazpkg --root=$ROOT
963 mv $PACKAGE-$VERSION.tazpkg $CACHE_DIR
964 fi
966 # Clean
967 cd $TOP_DIR
968 rm -rf $TMP_DIR
969 }
972 # Check for loop in deps tree.
974 check_for_deps_loop() {
975 local list
976 local pkg
977 local deps
978 pkg=$1
979 shift
980 [ -n "$1" ] || return
981 list=""
983 # Filter out already processed deps
984 for i in $@; do
985 case " $ALL_DEPS" in
986 *\ $i\ *) ;;
987 *) list="$list $i";;
988 esac
989 done
990 ALL_DEPS="$ALL_DEPS$list "
991 for i in $list; do
992 [ -f $i/receipt ] || continue
993 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
994 case " $deps " in
995 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
996 *) check_for_deps_loop $pkg $deps;;
997 esac
998 done
999 }
1002 # Check for missing deps listed in a receipt packages.
1004 check_for_deps() {
1005 local saved;
1006 saved=$PACKAGE
1007 mkdir -p $TMP_DIR
1008 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
1009 . $TMP_DIR/receipt
1010 PACKAGE=$saved
1011 rm -rf $TMP_DIR
1013 num=0
1014 for pkgorg in $DEPENDS; do
1015 i=$(equivalent_pkg $pkgorg $1)
1016 if [ ! -d "$1$INSTALLED/$i" ]; then
1017 MISSING_PACKAGE=$i
1018 num=$(($num+1))
1019 elif [ ! -f "$1$INSTALLED/$i/receipt" ]; then
1020 _ 'WARNING! Dependency loop between "%s" and "%s".' $PACKAGE $i
1021 fi
1022 done
1024 if [ -n "$MISSING_PACKAGE" ]; then
1025 title "$(_ 'Tracking dependencies for package "%s"' $PACKAGE)"
1026 for pkgorg in $DEPENDS; do
1027 i=$(equivalent_pkg $pkgorg $1)
1028 if [ ! -d "$1$INSTALLED/$i" ]; then
1029 MISSING_PACKAGE=$i
1030 _ 'Missing package "%s"' $MISSING_PACKAGE
1031 fi
1032 done
1033 footer "$(_p \
1034 '%s missing package to install.' \
1035 '%s missing packages to install.' $num \
1036 $num)"
1037 fi
1041 # Install all missing deps. Auto install or ask user then install all missing
1042 # deps from local dir, cdrom, media or from the mirror. In case we want to
1043 # install packages from local, we need a packages.list to find the version.
1045 install_deps() {
1046 local root
1047 root=""
1048 [ -n "$1" ] && root="--root=$1"
1049 if [ "$AUTO_INSTALL_DEPS" == "yes" ]; then
1050 answer=0
1051 else
1052 newline
1053 confirm "$(_ 'Install all missing dependencies? (y/N)')"
1054 answer=$?
1055 newline
1056 fi
1057 if [ $answer == 0 ] && ! [ "$nodeps" ]; then
1058 for pkgorg in $DEPENDS; do
1059 pkg=$(equivalent_pkg $pkgorg $1)
1060 if [ ! -d "$1$INSTALLED/$pkg" ]; then
1061 local list
1062 list="$INSTALL_LIST"
1063 [ -n "$list" ] || list="$TOP_DIR/packages.list"
1064 # We can install packages from a local dir by greping
1065 # the TAZPKG_BASENAME in the local packages.list.
1066 found=0
1067 if [ -f "$list" ]; then
1068 _ 'Checking if package "%s" exists in local list...' $pkg
1069 mkdir $TMP_DIR
1070 for i in $pkg-*.tazpkg; do
1071 [ -f $i ] || continue
1072 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $i
1073 [ "$(. $TMP_DIR/receipt; echo $PACKAGE)" == "$pkg" ] || continue
1074 if grep -q ^$(package_fullname_in_dir $TMP_DIR).tazpkg$ $list
1075 then
1076 found=1
1077 tazpkg install $i $root --list=$list
1078 break
1079 fi
1080 done
1081 rm -rf $TMP_DIR
1082 fi
1083 # Install deps from the mirror.
1084 if [ $found -eq 0 ]; then
1085 if [ ! -f "$PKGS_DB/packages.list" ]; then
1086 tazpkg recharge
1087 fi
1088 tazpkg get-install $pkg $root
1089 fi
1090 fi
1091 done
1092 else
1093 newline
1094 _ 'Leaving dependencies for package "%s" unresolved.' $PACKAGE
1095 _ 'The package is installed but will probably not work.'
1096 newline
1097 fi
1101 # Search pattern in installed packages.
1103 search_in_installed_packages() {
1104 _ 'Installed packages'
1105 separator
1106 num=0
1107 for pkg in $(ls -1 $INSTALLED | grep -i "$PATTERN"); do
1108 EXTRAVERSION=""
1109 [ -f $INSTALLED/$pkg/receipt ] || continue
1110 . $INSTALLED/$pkg/receipt
1111 emsg "$PACKAGE<i 24> $VERSION$EXTRAVERSION<i 42> $(_n $CATEGORY)"
1112 num=$(($num+1))
1113 done
1115 footer "$(_p \
1116 '%s installed package found for "%s"' \
1117 '%s installed packages found for "%s"' $num \
1118 $num "$PATTERN")"
1122 # Search in packages.list for available pkgs.
1124 search_in_packages_list() {
1125 _ 'Available packages'
1126 separator
1127 num=0
1128 BPATTERN="$(emsg "<b>$PATTERN</b>")"
1129 for i in $PKGS_DB/packages.list $PKGS_DB/undigest/*/packages.list \
1130 $PKGS_DB/extra.list $PKGS_DB/undigest/*/extra.list ; do
1131 grep -is "$PATTERN" $i | sed "s|$PATTERN|$BPATTERN|"
1132 num=$(($num + `grep -is "$PATTERN" $i | wc -l`))
1133 done
1134 if [ ! -f "$PKGS_DB/packages.list" ]; then
1135 newline
1136 longline "$(_ \
1137 "No \"%s\" found to check for mirrored packages. For more results, please run \
1138 \"%s\" once as root before searching." packages.list 'tazpkg recharge')"
1139 newline
1140 fi
1141 footer "$(_p \
1142 '%s available package found for "%s"' \
1143 '%s available packages found for "%s"' $num \
1144 $num $PATTERN)"
1148 # search --mirror: Search in packages.txt for available pkgs and give more
1149 # info than --list or default.
1151 search_in_packages_txt() {
1152 _ 'Matching packages name with version and desc'
1153 separator
1154 num=0
1155 for i in $PKGS_DB/packages.txt $PKGS_DB/undigest/*/packages.txt; do
1156 grep -is -A 2 "^$PATTERN" $i
1157 num=$(($num + `grep -is "^$PATTERN" $i | wc -l`))
1158 done
1159 if [ ! -f "$PKGS_DB/packages.txt" ]; then
1160 newline
1161 longline "$(_ \
1162 "No \"%s\" found to check for mirrored packages. For more results, please run \
1163 \"%s\" once as root before searching." packages.txt 'tazpkg recharge')"
1164 newline
1165 fi
1166 footer "$(_p \
1167 '%s available package found for "%s"' \
1168 '%s available packages found for "%s"' $num \
1169 $num $PATTERN)"
1173 # Install package-list from a flavor
1175 install_flavor() {
1176 check_root $@
1178 # Get repositories priority list.
1179 look_for_priority
1181 FLAVOR=$1
1182 ARG=$2
1183 mkdir -p $TMP_DIR
1184 [ -f $FLAVOR.flavor ] && cp $FLAVOR.flavor $TMP_DIR
1185 cd $TMP_DIR
1186 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1187 zcat < $FLAVOR.flavor | cpio --quiet -i >/dev/null
1189 while read file; do
1190 for pkg in $(ls -d $INSTALLED/${file%%-*}*); do
1191 [ -f $pkg/receipt ] || continue
1192 EXTRAVERSION=""
1193 . $pkg/receipt
1194 [ "$PACKAGE-$VERSION$EXTRAVERSION" == "$file" ] && break
1195 done
1196 [ "$PACKAGE-$VERSION$EXTRAVERSION" == "$file" ] && continue
1197 cd $CACHE_DIR
1198 download $file.tazpkg
1199 cd $TMP_DIR
1200 tazpkg install $CACHE_DIR/$file.tazpkg --forced
1201 done < $FLAVOR.pkglist
1203 [ -f $FLAVOR.nonfree ] && while read pkg; do
1204 [ -d $INSTALLED/$pkg ] || continue
1205 [ -d $INSTALLED/get-$pkg ] && tazpkg get-install get-$pkg
1206 get-$pkg
1207 done < $FLAVOR.nonfree
1209 [ "$ARG" == "--purge" ] && for pkg in $(ls $INSTALLED); do
1210 [ -f $INSTALLED/$pkg/receipt ] || continue
1211 EXTRAVERSION=""
1212 . $INSTALLED/$pkg/receipt
1213 grep -q ^$PACKAGE-$VERSION$EXTRAVERSION$ $FLAVOR.pkglist && continue
1214 grep -qs ^$PACKAGE$ $FLAVOR.nonfree && continue
1215 tazpkg remove $PACKAGE
1216 done
1217 else
1218 _ "Can't find flavor \"%s\". Abort." $FLAVOR
1219 fi
1220 cd $TOP_DIR
1221 rm -rf $TMP_DIR
1225 # Update mirror urls
1227 setup_mirror() {
1228 # Backup old list.
1229 if [ -f "$1/mirror" ]; then
1230 cp -f $1/mirror $1/mirror.bak
1231 fi
1232 title 'Current mirror(s)'
1233 echo " `cat $1/mirror 2> /dev/null`"
1234 longline "$(_ \
1235 "Please enter URL of the new mirror (http, ftp or local path). You must specify \
1236 the complete address to the directory of the packages and packages.list file.")"
1237 newline
1238 _n 'New mirror(s) URL: '
1239 NEW_MIRROR_URL=$2
1240 if [ -n "$NEW_MIRROR_URL" ]; then
1241 echo $NEW_MIRROR_URL
1242 else
1243 read NEW_MIRROR_URL
1244 fi
1245 if [ -z "$NEW_MIRROR_URL" ]; then
1246 _ 'Nothing has been changed.'
1247 else
1248 _ 'Setting mirror(s) to: "%s"' $NEW_MIRROR_URL
1249 rm -f $1/mirror
1250 for i in $NEW_MIRROR_URL; do
1251 echo "${i%/}/" >> $1/mirror
1252 done
1253 fi
1254 newline
1258 # recursive dependencies scan
1260 dep_scan() {
1261 for i in $1; do
1262 case " $ALL_DEPS " in
1263 *\ $i\ *) continue;;
1264 esac
1265 ALL_DEPS="$ALL_DEPS $i"
1266 [ -n "$2" ] && echo "$2$i ($(fgrep -A 3 $i $PKGS_DB/packages.txt | \
1267 tail -1 | sed 's/.*(\([^ ]*\).*/\1/'))"
1268 [ -f $i/receipt ] || continue
1269 DEPENDS=""
1270 . $i/receipt
1271 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
1272 done
1276 # recursive reverse dependencies scan
1278 rdep_scan() {
1279 SEARCH=$1
1281 for i in * ; do
1282 DEPENDS=""
1283 . $i/receipt
1284 echo "$i $(echo $DEPENDS)"
1285 done | busybox awk -v search=$SEARCH '
1286 function show_deps(deps, all_deps, pkg, space)
1288 if (all_deps[pkg] == 1) return
1289 all_deps[pkg] = 1
1290 if (space != "") printf "%s %s\n",space,pkg
1291 for (i = 1, n = split(deps[pkg], mydeps, " "); i <= n; i++) {
1292 show_deps(deps, all_deps, mydeps[i],"==" space)
1297 all_deps[$1] = 0
1298 for (i = 2; i <= NF; i++)
1299 deps[$i] = deps[$i] " " $1
1302 END {
1303 show_deps(deps, all_deps, search, "")
1305 ' | while read spc pkg; do
1306 echo -n $spc | sed 's/=/ /g'
1307 echo -n $pkg
1308 echo -n ' ('
1309 fgrep -A 3 $pkg $PKGS_DB/packages.txt | tail -1 | \
1310 sed 's/.*(\([^ ]*\).*/\1)/'
1311 done
1315 update_desktop_database() {
1316 if [ -f $1/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
1317 chroot "$1/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
1318 fi
1322 update_mime_database() {
1323 if [ -f $1/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
1324 chroot "$1/" /usr/bin/update-mime-database /usr/share/mime
1325 fi
1329 update_icon_database() {
1330 if [ -f $1/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
1331 chroot "$1/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
1332 fi
1336 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() {
1344 if [ -f $1/sbin/depmod ] && [ -n "$updatedepmod" ]; then
1345 chroot "$1/" /sbin/depmod -a
1346 fi
1350 # When recharging errors occur
1352 recharging_failed() {
1353 colorize 31 "$(_ 'Recharging failed')"
1355 # Restore database from bak files
1356 action 'Restoring database files...'
1357 [ -e 'ID' -a ! -e 'ID.bak' ] && rm ID
1358 [ -e 'IDs' -a ! -e 'IDs.bak' ] && rm IDs
1359 for file in $(ls $1/*.bak); do
1360 mv -f $file ${file%.bak}
1361 done
1362 status
1368 ###################
1369 # TazPkg commands #
1370 ###################
1372 case "$COMMAND" in
1373 list|-l)
1374 # List all installed packages or a specific category.
1375 shift
1376 check_for_installed_info
1378 case $1 in
1379 b|blocked)
1380 # Display the list of blocked packages.
1381 title 'Blocked packages'
1382 if [ -s "$BLOCKED" ];then
1383 cat $BLOCKED
1384 num=$(wc -l < $BLOCKED)
1385 footer "$(_p '%s package' '%s packages' "$num" \
1386 "$(colorize 31 $num)")"
1387 else
1388 _ 'No blocked packages found.'
1389 fi
1390 newline
1391 ;;
1393 c|cat|categories)
1394 # Display the list of categories.
1395 title 'Packages categories'
1397 echo "$PKGS_CATEGORIES" | sed 's|[^a-z-]|\n|g; /^$/d' | \
1398 sed 's|\(.*\)|\1\t\1|' | translate_category | awk -F$'\t' '{
1399 if ($1==$2) print $1; else printf "%-14s %s\n", $1, $2}'
1401 num=$(echo -n "$PKGS_CATEGORIES" | wc -l)
1402 footer "$(_p '%s category' '%s categories' "$num" \
1403 "$(colorize 33 $num)")"
1404 ;;
1406 '')
1407 # By default list all packages and versions.
1408 title 'List of all installed packages'
1409 awk -F$'\t' '{printf "%-34s %-17s %s\n", $1, $2, $3}' \
1410 $PKGS_DB/installed.info | translate_category
1412 num=$(wc -l < $PKGS_DB/installed.info)
1413 footer "$(_p '%s package installed.' '%s packages installed.' "$num" \
1414 "$(colorize 32 $num)")"
1415 ;;
1417 *)
1418 # Check for an asked category.
1419 ASKED_CATEGORY_I18N="$@"
1420 ASKED_CATEGORY=$(reverse_translate_category "$ASKED_CATEGORY_I18N")
1421 title 'Installed packages of category "%s"' $ASKED_CATEGORY_I18N
1422 TMPLIST=$(mktemp)
1423 awk -F$'\t' -vcat="$ASKED_CATEGORY" \
1424 '{ if ($3 == cat) printf "%-34s %s\n", $1, $2; }' \
1425 $PKGS_DB/installed.info | tee $TMPLIST | translate_category
1427 num=$(wc -l < $TMPLIST); rm $TMPLIST
1428 footer "$(emsg $(_p \
1429 '%s package installed of category "%s".' \
1430 '%s packages installed of category "%s".' $num \
1431 "<c 32>$num</c>" "<c 34>$ASKED_CATEGORY_I18N</c>"))"
1432 ;;
1433 esac ;;
1436 list-mirror|-lm)
1437 # List all available packages on the mirror. Option --diff displays
1438 # last mirrored packages diff (see recharge).
1439 check_for_packages_list
1440 case $2 in
1441 --diff)
1442 if [ -f "$PKGS_DB/packages.diff" ]; then
1443 title 'Mirrored packages diff'
1444 cat $PKGS_DB/packages.diff
1445 num=$(wc -l < $PKGS_DB/packages.diff)
1446 footer "$(_p \
1447 '%s new package listed on the mirror.' \
1448 '%s new packages listed on the mirror.' "$num" \
1449 "$(colorize 32 $num)")"
1450 else
1451 newline
1452 _ 'Unable to list anything, no packages.diff found.'
1453 _ 'Recharge your current list to create a first diff.'
1454 newline
1455 fi
1456 ;;
1457 *)
1458 title 'List of available packages on the mirror'
1459 awk -F$'\t' '{
1460 split($7, s, " ");
1461 printf "%s\n%s\n%s\n%s (%s installed)\n\n", $1, $2, $4, s[1], s[2];
1462 }' $PKGS_DB/packages.info
1463 num=$(wc -l < $PKGS_DB/packages.info)
1464 footer "$(_p \
1465 '%s package in the last recharged list.' \
1466 '%s packages in the last recharged list.' "$num" \
1467 "$(colorize 32 $num)")"
1468 ;;
1469 esac
1470 ;;
1473 list-files|-lf)
1474 # List files installed with the package.
1475 check_for_package_on_cmdline
1476 if [ -d "$INSTALLED/$PACKAGE" ]; then
1477 # installed package
1478 title 'Installed files by "%s"' $PACKAGE
1479 sort < $INSTALLED/$PACKAGE/files.list
1480 num=$(wc -l < $INSTALLED/$PACKAGE/files.list)
1481 footer "$(_p '%s file' '%s files' $num \
1482 "$(colorize 32 $num)")"
1483 elif [ -n "$(grep "^$PACKAGE"$'\t' $PKGS_DB/packages.info)" ]; then
1484 # available package
1485 title 'Installed files by "%s"' $PACKAGE
1486 TMPLIST=$(mktemp)
1487 lzcat $PKGS_DB/files.list.lzma | sed -n "/^$PACKAGE: / s|^[^:]*: ||p" | tee $TMPLIST
1488 num=$(wc -l < $TMPLIST); rm $TMPLIST
1489 footer "$(_p '%s file' '%s files' $num \
1490 "$(colorize 32 $num)")"
1491 else
1492 newline
1493 _ 'Package "%s" not available.' "$PACKAGE"
1494 newline
1495 fi
1496 ;;
1499 info)
1500 # Information about package.
1501 check_for_package_on_cmdline
1502 check_for_receipt
1503 EXTRAVERSION=''
1504 . $INSTALLED/$PACKAGE/receipt
1505 im && title 'TazPKG information'
1506 # Display localized short description
1507 for LC in $LANG ${LANG%_*}; do
1508 if [ -e "$PKGS_DB/packages-desc.$LC" ]; then
1509 LOCDESC=$(grep -e "^$PACKAGE"$'\t' $PKGS_DB/packages-desc.$LC | cut -d$'\t' -f2)
1510 [ -n "$LOCDESC" ] && SHORT_DESC="$LOCDESC"
1511 fi
1512 done
1513 SIZES=$(echo $PACKED_SIZE/$UNPACKED_SIZE | sed 's|\.0||g' | sed 's|^/$||')
1515 emsg "$(
1517 _ 'Package : %s' "$PACKAGE"
1518 _ 'Version : %s' "$VERSION$EXTRAVERSION"
1519 _ 'Category : %s' "$(_ $CATEGORY)"
1520 _ 'Short desc : %s' "$SHORT_DESC"
1521 _ 'Maintainer : %s' "$MAINTAINER"
1522 _ 'License : %s' "$LICENSE"
1523 _ 'Depends : %s' "$DEPENDS"
1524 _ 'Suggested : %s' "$SUGGESTED"
1525 _ 'Build deps : %s' "$BUILD_DEPENDS"
1526 _ 'Wanted src : %s' "$WANTED"
1527 _ 'Web site : %s' "$WEB_SITE"
1528 _ 'Size : %s' "$SIZES"
1529 _ 'Tags : %s' "$TAGS"
1530 } | sed '/: $/d; s|^\([^:]*\):|<b>\1:</b>|')"
1531 im && footer
1532 ;;
1535 desc)
1536 # Display package description
1537 if [ -n "$(grep -e "^$PACKAGE"$'\t' $PKGS_DB/installed.info)" ]; then
1538 im && title 'Description of package "%s"' $PACKAGE
1539 if [ -s "$INSTALLED/$PACKAGE/description.txt" ]; then
1540 cat $INSTALLED/$PACKAGE/description.txt
1541 else
1542 im && awk -F$'\t' -vp="$PACKAGE" '{
1543 if ($1 == p) print $4 }' $PKGS_DB/installed.info
1544 fi
1545 im && footer
1546 else
1547 im && _ 'Package "%s" is not installed.' "$PACKAGE"
1548 fi
1549 ;;
1552 activity|log|-a)
1553 # Show activity log
1554 [ -n "$nb" ] || nb='18'
1555 title 'TazPKG Activity'
1556 IFS=' '
1557 tail -n $nb $LOG | tac | \
1558 while read date hour none action none pkg vers none; do
1559 case $action in
1560 Installed)
1561 action=$(colorize 32 $action) ;;
1562 Removed)
1563 action=$(colorize 31 $action) ;;
1564 *)
1565 action=$(boldify $action) ;;
1566 esac
1567 date_locale="$(date -d "$date $hour" '+%x %X')"
1568 echo "$date_locale : $action $pkg $vers"
1569 done
1570 unset IFS
1571 footer ;;
1574 search|-s)
1575 # Search for a package by pattern or name.
1576 PATTERN="$2"
1577 if [ -z "$PATTERN" ]; then
1578 newline
1579 _ 'Please specify a pattern or package name to search for.'
1580 echo "$(_ 'Example:') 'tazpkg search paint'"
1581 newline
1582 exit 0
1583 fi
1584 title 'Search result for "%s"' $PATTERN
1585 # Default is to search in installed pkgs and the raw list.
1586 case "$3" in
1587 -i|--installed) search_in_installed_packages ;;
1588 -l|--list) search_in_packages_list ;;
1589 -m|--mirror) search_in_packages_txt ;;
1590 *)
1591 search_in_installed_packages
1592 search_in_packages_list ;;
1593 esac ;;
1596 search-file|-sf)
1597 # Search for a file by pattern or name in all files.list.
1598 if [ -z "$2" ]; then
1599 newline
1600 _ 'Please specify a pattern or file name to search for.'
1601 echo "$(_ 'Example:') 'tazpkg search-file libnss'"
1602 newline
1603 exit 0
1604 fi
1605 title 'Search result for file "%s"' $2
1606 TMPLIST=$(mktemp)
1608 if [ -n "$mirror" ]; then
1609 TMPDIR=$(mktemp -d)
1610 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1611 [ -f $i ] || continue
1612 lzcat $i | awk -F: -vtmp="$TMPLIST" -vdir="$TMPDIR" \
1613 -vfile="$2" -vcfile="$(colorize 32 $2)" '
1614 BEGIN { efile = gensub("\+", "\\\+", "g", file); }
1615 index($2, file) {
1616 gsub(efile, cfile, $2);
1617 print $2 >> dir"/"$1;
1618 printf "1" >> tmp;
1619 }'
1620 done
1622 for pkg in $(cd $TMPDIR; ls); do
1623 newline
1624 emsg "<c 33>$(_ 'Package %s:' $pkg)</c>"
1625 cat $TMPDIR/$pkg
1626 done
1628 rm -r $TMPDIR
1630 else
1632 # Check all pkg files.list in search match which specify the package
1633 # name and the full path to the file(s).
1634 for pkg in $INSTALLED/*; do
1635 if grep -qs "$2" $pkg/files.list; then
1636 . $pkg/receipt
1637 newline
1638 emsg "<c 33>$(_ 'Package %s:' $PACKAGE)</c>"
1639 awk -vtmp="$TMPLIST" -vfile="$2" -vcfile="$(colorize 32 $2)" '
1640 BEGIN { efile = gensub("\+", "\\\+", "g", file); }
1641 index($0, file) {
1642 gsub(efile, cfile);
1643 print " "$0;
1644 printf "1" >> tmp;
1646 ' $pkg/files.list
1647 fi
1648 done
1650 fi
1652 num=$(wc -m < $TMPLIST); rm $TMPLIST
1653 footer "$(_p '%s file' '%s files' "$num" \
1654 "$(colorize 32 $num)")"
1655 ;;
1658 search-pkgname)
1659 # Search for a package name
1660 if [ -z "$2" ]; then
1661 newline
1662 _ 'Please specify a pattern or file name to search for.'
1663 echo "$(_ 'Example:') 'tazpkg search-pkgname libnss'"
1664 newline
1665 exit 0
1666 fi
1667 title 'Search result for package "%s"' $2
1669 # Search for a file on mirror and output only the package name
1670 TMPLIST=$(mktemp)
1671 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1672 [ -f "$i" ] || continue
1673 lzcat $i | awk -F: -vT=$TMPLIST '
1674 BEGIN { P = "" }
1675 $2 ~ /'$2'/ {
1676 if ($1 != P) {
1677 print $1;
1678 printf "%s" 1 >> T;
1679 P = $1
1681 }'
1682 done
1683 match=$(wc -m < $TMPLIST)
1684 rm $TMPLIST
1686 footer "$(emsg "$(_p \
1687 '%s package' '%s packages' $match \
1688 "<c 32>$match</c>")")"
1689 ;;
1692 install|-i)
1693 # Install .tazpkg packages.
1694 check_root $@
1695 check_for_package_on_cmdline
1696 check_for_package_file
1697 check_for_installed_info
1699 if [ -n "$root" ]; then
1700 ROOT="$root";
1701 check_base_dir "$root"
1702 fi
1703 [ "$list" ] && INSTALL_LIST="$list"
1704 if [ "$rootconfig" ]; then
1705 if [ "$root" ]; then
1706 CACHE_DIR=$root/$CACHE_DIR
1707 SAVE_CACHE_DIR=$CACHE_DIR
1708 PKGS_DB=$root/$PKGS_DB
1709 else
1710 echo "rootconfig needs --root= option used." >&2
1711 exit 1
1712 fi
1713 fi
1715 # Get repositories priority list.
1716 look_for_priority
1718 # Check if forced install.
1719 if [ -z "$forced" ]; then
1720 check_for_installed_package $ROOT
1721 fi
1722 install_package $ROOT
1723 update_desktop_database $ROOT
1724 update_mime_database $ROOT
1725 update_icon_database $ROOT
1726 compile_glib_schemas $ROOT
1727 ;;
1730 install-list|get-install-list)
1731 # Install a set of packages from a list.
1732 check_root $@
1733 if [ -z "$2" ]; then
1734 newline
1735 longline "$(_ \
1736 "Please change directory (cd) to the packages repository and specify the \
1737 list of packages to install.")"
1738 echo "$(_ 'Example:') $(emsg '<b>tazpkg install-list</b> <c 33>packages.list</c>')"
1739 exit 0
1740 fi
1742 # Check if the packages list exist.
1743 if [ ! -f "$2" ]; then
1744 _ 'Unable to find list "%s"' "$2"
1745 exit 0
1746 fi
1748 LIST=$(cat $2)
1750 # Remember processed list
1751 export INSTALL_LIST="$2"
1753 # Set $COMMAND and install all packages.
1754 COMMAND=${1%-list}
1756 touch $2-processed
1758 # Upgrade tazpkg first. It may handle new features/formats...
1759 # then upgrade essential packages early
1760 for pkg in busybox-pam busybox gcc-lib-base glibc-base \
1761 slitaz-base-files tazpkg ; do
1762 pkg=$(egrep $pkg-[0-9] $INSTALL_LIST)
1763 [ -z "$pkg" ] && continue
1764 _ 'Adding implicit depends "%s"...' $pkg
1765 LIST="$pkg
1766 $LIST"
1767 done
1769 for pkg in $LIST; do
1770 grep -qs ^$pkg$ $2-processed && continue
1771 [ -d "$root/var/lib/tazpkg/installed" ] &&
1772 tazpkg $COMMAND $pkg --list="$2" "$3" "$4" "$5"
1773 done
1774 rm -f $2-processed ;;
1777 add-flavor)
1778 # Install a set of packages from a flavor.
1779 install_flavor $2 ;;
1782 install-flavor)
1783 # Install a set of packages from a flavor and purge other ones.
1784 install_flavor $2 --purge ;;
1787 set-release)
1788 # Change current release and upgrade packages.
1789 RELEASE=$2
1790 if [ -z "$RELEASE" ]; then
1791 newline
1792 _ 'Please specify the release you want on the command line.'
1793 echo "$(_ 'Example:') tazpkg set-release cooking"
1794 newline
1795 exit 0
1796 fi
1797 rm $PKGS_DB/mirror
1798 echo "$RELEASE" > /etc/slitaz-release
1799 tazpkg recharge && tazpkg upgrade
1801 # Install missing depends
1802 cd $INSTALLED
1803 for i in * ; do
1804 DEPENDS=""
1805 . $i/receipt
1806 for j in $DEPENDS ; do
1807 [ -d $j ] || tazpkg get-install $j
1808 done
1809 done ;;
1812 remove|-r)
1813 # Remove packages.
1814 check_root $@
1815 check_for_package_on_cmdline
1816 check_for_installed_info
1818 [ -n "$root" ] && ROOT="$root"
1820 if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then
1821 newline; _ 'Package "%s" is not installed.' $PACKAGE
1822 exit 0
1823 fi
1825 . $ROOT$INSTALLED/$PACKAGE/receipt
1827 # Info #1: dependent packages (to be processed later)
1828 ALTERED="$(awk -F$'\t' -vp=" $PACKAGE " '
1829 index(" " $8 " ", p) { printf " %s\n", $1 }
1830 ' $ROOT/$PKGS_DB/installed.info)"
1832 if [ -n "$ALTERED" ]; then
1833 _ 'The following packages depend on package "%s":' $PACKAGE
1834 echo "$ALTERED"
1835 fi
1837 # Info #2: changed packages (to be processed later)
1838 REFRESH=$(cd $ROOT$INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1840 if [ -n "$REFRESH" ]; then
1841 _ 'The following packages have been modified by package "%s":' $PACKAGE
1842 for i in $REFRESH; do
1843 echo " ${i%/modifiers}"
1844 done
1845 fi
1847 # Confirmation
1848 if im && [ -z "$auto" ]; then
1849 confirm "$(_ 'Remove package "%s" (%s)? (y/N)' $PACKAGE $VERSION$EXTRAVERSION)"
1850 if [ $? != 0 ]; then
1851 newline; _ 'Uninstallation of package "%s" cancelled.' $PACKAGE
1852 exit 0
1853 fi
1854 fi
1855 # We are here: non-interactive mode, or --auto, or answer 'y'
1857 # Removing package
1858 title 'Removing package "%s"' $PACKAGE
1860 # [1/4] Pre-remove commands
1861 if grep -q ^pre_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1862 action "Execution of pre-remove commands..."
1863 pre_remove $ROOT
1864 status
1865 fi
1867 # [2/4] Removing files
1868 action "Removing all files installed..."
1869 if [ -f $ROOT$INSTALLED/$PACKAGE/modifiers ]; then
1870 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1871 for mod in $(cat $ROOT$INSTALLED/$PACKAGE/modifiers); do
1872 [ -f $ROOT$INSTALLED/$mod/files.list ] && \
1873 [ $(grep "^$(echo $file | grepesc)$" $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && \
1874 continue 2
1875 done
1876 remove_with_path $ROOT$file
1877 done
1878 else
1879 for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do
1880 remove_with_path $ROOT$file
1881 done
1882 fi
1883 status
1885 # [3/4] Post-remove commands
1886 if grep -q ^post_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1887 action "Execution of post-remove commands..."
1888 post_remove $ROOT
1889 status
1890 fi
1892 # [4/4] Remove package receipt and remove it from databases
1893 action "Removing package receipt..."
1894 rm -rf $ROOT$INSTALLED/$PACKAGE
1895 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg$/d" $PKGS_DB/installed.$SUM
1896 sed -i "/^$PACKAGE /d" $PKGS_DB/installed.info
1897 status
1899 footer "$(_ 'Package "%s" (%s) removed.' $PACKAGE $VERSION$EXTRAVERSION)"
1901 # Log this activity
1902 log_pkg Removed
1904 # Stop if non-interactive mode and no --auto option
1905 if ! im && [ -z "$auto" ]; then exit 0; fi
1907 # Process dependent packages
1908 if [ -n "$ALTERED" ]; then
1909 if [ "$auto" ]; then
1910 answer=0
1911 else
1912 confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' $PACKAGE)"
1913 answer=$?
1914 fi
1915 if [ "$answer" == '0' ]; then
1916 for i in $ALTERED; do
1917 if [ -d "$ROOT$INSTALLED/$i" ]; then
1918 echo "tazpkg remove $i $ROOTOPTS"
1919 fi
1920 done
1921 fi
1922 fi
1924 # Process changed packages
1925 if [ -n "$REFRESH" ]; then
1926 if [ "$auto" ]; then
1927 answer=0
1928 else
1929 confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' $PACKAGE)"
1930 answer=$?
1931 fi
1932 if [ "$answer" == '0' ]; then
1933 for i in $REFRESH; do
1934 if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then
1935 _ 'Check %s for reinstallation' "$INSTALLED/$i"
1936 continue
1937 fi
1938 echo "rm -r $ROOT$INSTALLED/$i"
1939 echo "tazpkg get-install ${i%/modifiers} $ROOTOPTS --forced"
1940 done
1941 fi
1942 fi
1944 ;;
1947 extract|-e)
1948 # Extract .tazpkg cpio archive into a directory.
1949 check_for_package_on_cmdline
1950 check_for_package_file
1951 title 'Extracting package "%s"' $PACKAGE
1953 # If no directory destination is found on the cmdline
1954 # we create one in the current dir using the package name.
1955 if [ -n "$TARGET_DIR" ]; then
1956 DESTDIR=$TARGET_DIR/$PACKAGE
1957 else
1958 DESTDIR=$PACKAGE
1959 fi
1960 mkdir -p $DESTDIR
1962 action "Copying original package..."
1963 cp $PACKAGE_FILE $DESTDIR
1964 status
1966 cd $DESTDIR
1967 extract_package
1968 [ -e "receipt" ] && \
1969 footer "$(_ 'Package "%s" is extracted to "%s"' $PACKAGE $DESTDIR)"
1970 ;;
1973 recompress)
1974 # Recompress .tazpkg cpio archive with lzma.
1975 check_for_package_on_cmdline
1976 check_for_package_file
1977 title 'Recompressing package "%s"' $PACKAGE
1978 mkdir -p $TMP_DIR
1980 action "Copying original package..."
1981 cp $PACKAGE_FILE $TMP_DIR
1982 status
1984 cd $TMP_DIR
1985 extract_package
1987 action "Recompressing the FS..."
1988 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1989 rm -rf fs
1990 status
1992 action "Creating new package..."
1993 find . -print | cpio -o -H newc --quiet > \
1994 $TOP_DIR/$(basename $PACKAGE_FILE).$$ && mv -f \
1995 $TOP_DIR/$(basename $PACKAGE_FILE).$$ \
1996 $TOP_DIR/$(basename $PACKAGE_FILE)
1997 status
1999 cd $TOP_DIR
2000 rm -rf $TMP_DIR
2001 separator; newline ;;
2004 list-config)
2005 # List configuration files installed.
2006 if [ -n "$box" ]; then
2007 mkdir -p $TMP_DIR; cd $TMP_DIR
2008 FILES="$INSTALLED/*/volatile.cpio.gz"
2009 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
2010 for i in $FILES; do
2011 zcat $i | cpio -idm --quiet > /dev/null
2012 find * -type f 2>/dev/null | while read file; do
2013 if [ ! -e /$file ]; then
2014 echo -n "----------|----|----|$(_n 'File lost')"
2015 else
2016 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
2017 cmp $file /$file > /dev/null 2>&1 || \
2018 echo -n "$(stat -c "%.16y" /$file)"
2019 fi
2020 echo "|/$file"
2021 done
2022 rm -rf *
2023 done
2024 cd $TOP_DIR
2025 rm -rf $TMP_DIR
2026 else
2027 im && title 'Configuration files'
2028 for i in $INSTALLED/*/volatile.cpio.gz; do
2029 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
2030 [ -f "$i" ] || continue
2031 zcat $i | cpio -t --quiet
2032 done | sed 's|^|/|' | sort
2033 im && footer
2034 fi ;;
2037 repack-config)
2038 # Create SliTaz package archive from configuration files.
2039 mkdir -p $TMP_DIR; cd $TMP_DIR
2040 CONFIG_VERSION=1.0
2041 mkdir config-$CONFIG_VERSION
2042 cd config-$CONFIG_VERSION
2043 for i in $INSTALLED/*/volatile.cpio.gz; do
2044 zcat $i | cpio -t --quiet
2045 done > files.list
2046 mkdir fs
2047 cd fs
2048 ( cd / ; cpio -o -H newc --quiet ) < ../files.list | cpio -idm --quiet > /dev/null
2049 mkdir -p etc/tazlito
2050 for i in $INSTALLED/*/receipt; do
2051 EXTRAVERSION=""
2052 . $i
2053 echo "$PACKAGE-$VERSION$EXTRAVERSION"
2054 done > etc/tazlito/config-packages.list
2055 cd ..
2056 echo "etc/tazlito/config-packages.list" >> files.list
2057 pkg_date=$(date +"%x %X")
2058 cat > receipt <<EOT
2059 # SliTaz package receipt.
2061 PACKAGE="config"
2062 VERSION="$CONFIG_VERSION"
2063 CATEGORY="base-system"
2064 SHORT_DESC="$(_n 'User configuration backup on date %s' $pkg_date)"
2065 DEPENDS="$(ls $INSTALLED)"
2066 EOT
2067 cd ..
2068 tazpkg pack config-$CONFIG_VERSION
2069 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
2070 cd $TOP_DIR
2071 rm -rf $TMP_DIR
2072 ;;
2075 repack)
2076 # Create SliTaz package archive from an installed package.
2077 check_for_package_on_cmdline
2078 check_for_receipt
2079 EXTRAVERSION=""
2080 . $INSTALLED/$PACKAGE/receipt
2081 title 'Repacking "%s"' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
2083 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
2084 _ "Can't repack package \"%s\"" $PACKAGE
2085 exit 1
2086 fi
2088 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
2089 _ "Can't repack, \"%s\" files have been modified by:" $PACKAGE
2090 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
2091 echo " $i"
2092 done
2093 exit 1
2094 fi
2096 MISSING=""
2097 while read i; do
2098 [ -e "$i" ] && continue
2099 [ -L "$i" ] || MISSING="$MISSING\n $i"
2100 done < $INSTALLED/$PACKAGE/files.list
2101 if [ -n "$MISSING" ]; then
2102 _n "Can't repack, the following files are lost:"
2103 echo -e "$MISSING"
2104 exit 1
2105 fi
2107 mkdir -p $TMP_DIR; cd $TMP_DIR
2108 FILES="fs.cpio.lzma\n"
2109 for i in $(ls $INSTALLED/$PACKAGE); do
2110 case $i in
2111 volatile.cpio.gz|modifiers) ;;
2112 *) cp $INSTALLED/$PACKAGE/$i .; FILES="$FILES$i\n" ;;
2113 esac
2114 done
2116 ln -s / rootfs
2117 mkdir tmp
2118 sed 's/^/rootfs/' < files.list | cpio -o -H newc --quiet | \
2119 { cd tmp ; cpio -idm --quiet >/dev/null; cd ..; }
2120 mv tmp/rootfs fs
2122 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
2123 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
2124 { cd fs; cpio -idm --quiet; cd ..; }
2125 fi
2127 if fgrep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
2128 . $INSTALLED/$PACKAGE/receipt
2129 repack_cleanup fs
2130 fi
2132 if [ -f $INSTALLED/$PACKAGE/$CHECKSUM ]; then
2133 sed 's, , fs,' < $INSTALLED/$PACKAGE/$CHECKSUM | \
2134 $CHECKSUM -s -c || {
2135 _ "Can't repack, %s error." $CHECKSUM
2136 cd $TOP_DIR
2137 rm -rf $TMP_DIR
2138 exit 1
2140 fi
2142 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2143 echo -e "$FILES" | cpio -o -H newc --quiet > \
2144 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
2145 cd $TOP_DIR
2146 \rm -R $TMP_DIR
2147 _ 'Package "%s" repacked successfully.' $PACKAGE
2148 _ 'Size: %s' "$(du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg)"
2149 newline ;;
2152 pack)
2153 # Create SliTaz package archive using cpio and lzma.
2154 # TODO: Cook also pack packages, we should share code in libpkg.sh
2155 check_for_package_on_cmdline
2156 cd $PACKAGE
2157 if [ ! -f "receipt" ]; then
2158 _ 'Receipt is missing. Please read the documentation.'
2159 exit 0
2160 fi
2162 title 'Packing package "%s"' $PACKAGE
2163 # Create files.list with redirecting find outpout.
2165 action "Creating the list of files..."
2166 cd fs
2167 find . -type f -print > ../files.list
2168 find . -type l -print >> ../files.list
2169 cd .. && sed -i s/'^.'/''/ files.list
2170 status
2172 action 'Creating %s of files...' $CHECKSUM
2173 while read file; do
2174 [ -L "fs$file" ] && continue
2175 [ -f "fs$file" ] || continue
2176 case "$file" in
2177 /lib/modules/*/modules.*|*.pyc) continue;;
2178 esac
2179 $CHECKSUM "fs$file" | sed 's/ fs/ /'
2180 done < files.list > $CHECKSUM
2181 status
2183 UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
2184 description.txt 2> /dev/null | awk \
2185 '{ sz=$1 } END { print sz }')
2186 # Build cpio archives.
2188 action "Compressing the FS..."
2189 find fs | cpio -o -H newc --quiet | case "$TAZPKG_PACK" in
2190 gzip) gzip -9 > fs.cpio.gz ;;
2191 *) lzma e fs.cpio.lzma -si ;;
2192 esac
2193 rm -rf fs
2194 status
2196 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
2197 $CHECKSUM description.txt 2> /dev/null | awk \
2198 '{ sz=$1 } END { print sz }')
2200 action "Updating receipt sizes..."
2201 sed -i s/^PACKED_SIZE.*$// receipt
2202 sed -i s/^UNPACKED_SIZE.*$// receipt
2203 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
2204 status
2206 action "Creating full cpio archive..."
2207 find . -print | cpio -o -H newc --quiet > ../$PACKAGE.tazpkg
2208 status
2210 action "Restoring original package tree..."
2211 unlzma -c fs.cpio.lzma | cpio -idm --quiet
2212 status
2214 rm fs.cpio.lzma && cd ..
2215 footer "$(_ 'Package "%s" compressed successfully.' $PACKAGE)"
2216 _ 'Size: %s' "$(ls -lh $PACKAGE.tazpkg | awk '{print $5}')"
2217 ;;
2220 recharge)
2221 # Recharge packages databases from a mirror.
2223 # WARNING: The 'mirrors' file has all SliTaz mirrors but 'mirror'
2224 # must have only the chosen main mirror.
2226 check_root $@
2228 # usage: tazpkg recharge [--root=path] [main|<repository>]
2230 ARG="$2"
2231 if [ -n "$root" ]; then
2232 PKGS_DB="$root$PKGS_DB"
2233 [ "${2#--}" != "$2" ] && ARG="$3"
2234 fi
2236 case "$ARG" in
2237 main) repo_to_recharge="$PKGS_DB";;
2238 '') repo_to_recharge="$PKGS_DB $PKGS_DB/undigest/*";;
2239 *) repo_to_recharge="$PKGS_DB/undigest/$ARG"
2240 if [ ! -d "$repo_to_recharge" ]; then
2241 _ "Repository \"%s\" doesn't exist." "$repo_to_recharge" >&2
2242 exit 1
2243 fi
2244 ;;
2245 esac
2247 for path in $repo_to_recharge; do
2248 [ ! -f $path/mirror ] && continue # skip
2249 cd $path
2250 mirror="$(cat mirror)"
2252 # Repository name
2253 if [ "$path" == "$PKGS_DB" ]; then
2254 repo_name='Main'
2255 else
2256 repo_name="$(_n 'Undigest %s' "$(basename $path)")"
2257 fi
2259 # Don't let ID be a symlink when using local repository.
2260 if [ -h ID ]; then mv -f ID ID.lnk; cat ID.lnk > ID; rm ID.lnk; fi
2261 if [ -h IDs ]; then mv -f IDs IDs.lnk; cat IDs.lnk > IDs; rm IDs.lnk; fi
2263 [ -f ID ] && mv ID ID.bak # Compatibility with "old" ID
2264 [ -f IDs ] && mv IDs IDs.bak
2265 download_from "$mirror" IDs
2266 [ -e 'IDs' ] && awk '{print $1}' IDs > ID # Compatibility with "old" ID
2268 # Check if recharging is needed
2269 if [ -f 'IDs' ] && cmp -s IDs IDs.bak; then
2270 _ 'Repository "%s" is up to date.' "$repo_name"
2271 rm IDs.bak ID.bak
2272 continue
2273 fi
2274 rm IDs.bak ID.bak 2>/dev/null
2276 title 'Recharging repository "%s"' "$repo_name"
2277 [ -e 'IDs' ] && _ 'Database timestamp: %s' "$(date -d "@$(awk '{print $2}' IDs)" "+%x %R")"
2279 action 'Creating backup of the last packages list...'
2280 for i in packages.desc packages.$SUM packages.txt packages.list \
2281 packages.equiv files.list.lzma extra.list mirrors packages.info; do
2282 [ -f "$i" ] && mv -f $i $i.bak 2>/dev/null
2283 done
2284 status
2286 # Download and extract bundle: extra.list, mirrors, files-list.md5,
2287 # packages.{info,desc,md5,txt,list,equiv}
2288 bundle='bundle.tar.lzma'
2289 action 'Getting "%s"...' $bundle
2290 download_from "$mirror" $bundle
2291 status
2292 if [ -f "$bundle" ]; then
2293 busybox tar -xaf $bundle; rm $bundle
2294 else
2295 recharging_failed $path; continue
2296 fi
2298 # Download files.list.lzma
2299 files_local='files.list.lzma'; files_remote='files-list.lzma'
2300 if [ -e "$files_local.bak" ]; then
2301 md5sum $files_local.bak | awk '{printf $1}' > files-list.md5.bak
2302 if cmp -s files-list.md5 files-list.md5.bak; then
2303 mv $files_local.bak $files_remote
2304 else
2305 action 'Getting "%s"...' $files_remote
2306 download_from "$mirror" $files_remote
2307 status
2308 fi
2309 else
2310 action 'Getting "%s"...' $files_remote
2311 download_from "$mirror" $files_remote
2312 status
2313 fi
2315 if [ ! -e "$files_remote" ]; then
2316 recharging_failed $path; continue
2317 fi
2318 mv -f $files_remote $files_local
2320 # Remove old database files (but packages.list.bak, extra.list.bak)
2321 for i in packages.desc packages.$SUM packages.txt packages.equiv \
2322 files.list.lzma mirrors packages.info files-list.md5; do
2323 [ -f "$i.bak" ] && rm $i.bak 2>/dev/null
2324 done
2326 footer "$(_ 'Last database is ready to use.')"
2328 # Check diff
2329 if [ -f 'packages.list.bak' ]; then
2330 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
2331 rm packages.list.bak
2332 if [ -f 'extra.list.bak' ]; then
2333 if [ -f 'extra.list' ]; then
2334 awk -F'|' '{print $1 " (extra)"}' extra.list > extra.list1
2335 awk -F'|' '{print $1 " (extra)"}' extra.list.bak > extra.list1.bak
2336 diff -u extra.list1.bak extra.list1 | grep ^+[a-z] >> packages.diff
2337 rm extra.list.bak extra.list1 extra.list1.bak
2338 else
2339 mv extra.list.bak extra.list
2340 fi
2341 fi
2342 sed -i s/+// packages.diff
2344 new_pkgs=$(wc -l < packages.diff)
2345 if [ "$new_pkgs" -gt 0 ]; then
2346 title 'Mirrored packages diff'
2347 cat packages.diff
2348 footer "$(emsg "$(_p \
2349 '%s new package on the mirror.' \
2350 '%s new packages on the mirror.' $new_pkgs \
2351 "<c 32>$new_pkgs</c>")")"
2352 fi
2353 else
2354 longline "$(_ "Note that next time you recharge the \
2355 list, a list of differences will be displayed to show new and upgradeable \
2356 packages.")"
2357 fi
2358 done
2359 newline ;;
2362 help-up)
2363 # Options available for the command: up
2364 newline; usage_up; newline
2365 exit 1 ;;
2368 up|upgrade)
2369 check_root
2371 # This is the new way to upgrade packages making 'upgrade' and
2372 # upgradeable out-of-date. This new way is much, much more faster!
2373 # Look into installed packages and get data from receipt, it is fast
2374 # and easy to handle vars after using only md5sum to compare packages
2376 for opt in $@; do
2377 case "$opt" in
2378 --recharge|-r) tazpkg recharge ;;
2379 --install|-i) install="y" ;;
2380 --check|-c) install="n" ;;
2381 esac
2382 done
2383 time="$(date +%s)"
2385 look_for_priority
2386 for repo in $priority; do
2387 pkg_list="$repo/packages.list"
2388 mtime=$(find $pkg_list -mtime +7)
2389 if [ -n "$mtime" ]; then
2390 if [ "$repo" == "$PKGS_DB" ]; then
2391 repo_name='main'
2392 else
2393 repo_name="${repo##*/}"
2394 fi
2395 _ 'List "%s" is older than one week... Recharging.' $pkg_list
2396 tazpkg recharge $repo_name
2397 fi
2398 done
2400 emsg "<n>$(_ 'Package')<i 28> $(_ 'Version')<i 48> $(_ 'Status')<->"
2402 cd $INSTALLED
2403 echo -n > $UP_LIST
2404 blocked_count=0
2405 installed_sum="$PKGS_DB/installed.$SUM"
2407 for pkg in *; do
2408 [ ! -d $pkg ] && continue
2409 unset VERSION EXTRAVERSION
2410 . $pkg/receipt
2411 md5=$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" \
2412 $installed_sum | awk '{print $1}')
2413 for repo in $priority; do
2414 pkg_desc="$repo/packages.desc"
2415 pkg_list="$repo/packages.list"
2416 pkg_sum="$repo/packages.$SUM"
2418 if ! fgrep -q "$md5 $PACKAGE-" $pkg_sum; then
2419 # Jump to next repository in priority if pkg doesn't exist
2420 # in this one.
2421 grep -q ^$PACKAGE- $pkg_list || continue
2423 emsg -n "$PACKAGE<i 28> $VERSION"
2425 # Skip pkgs listed in $PKGS_DB/blocked-packages.list
2426 if $(grep -qs "^$PACKAGE" $BLOCKED); then
2427 blocked_count=$(($blocked_count + 1))
2428 emsg "<i 48><c 31> $(_ 'Blocked')</c>"
2429 break
2430 fi
2432 new=$(grep "^$PACKAGE |" $pkg_desc | awk '{print $3}')
2434 if [ "$VERSION" == "$new" ]; then
2435 emsg "<i 48><c 34> $(_ 'New build')</c>"
2436 else
2437 emsg "<i 48><c 32> $(_ 'New version %s' $new)</c>"
2438 fi
2439 echo "$PACKAGE" >> $UP_LIST
2440 break
2441 fi
2442 done
2443 done
2444 sed -i /^$/d $UP_LIST
2445 upnb=$(wc -l < $UP_LIST)
2446 pkgs=$(ls | wc -l)
2447 time=$(($(date +%s) - $time))
2448 if [ "$upnb" == 0 ]; then
2449 install="n"
2450 _ 'System is up-to-date...'
2451 fi
2453 footer "$(emsg "$(_p \
2454 '%s installed package scanned in %ds' \
2455 '%s installed packages scanned in %ds' $pkgs \
2456 "<c 32>$pkgs</c>" $time)")"
2458 if [ "$upnb" != 0 ]; then
2459 blocked="$(_p \
2460 '%s blocked' \
2461 '%s blocked' $blocked_count \
2462 $blocked_count)"
2464 boldify "$(_p \
2465 'You have %s available upgrade (%s)' \
2466 'You have %s available upgrades (%s)' $upnb \
2467 $upnb "$blocked")"
2468 newline
2469 fi
2471 # Pkgs to upgrade ? Skip, let install them all or ask user
2472 [ "$install" == 'n' ] && exit 0
2473 if [ "$upnb" -gt 0 ]; then
2474 if [ "$install" == 'y' ]; then
2475 answer=0
2476 else
2477 confirm "$(_ 'Do you wish to install them now? (y/N)')"
2478 answer=$?
2479 fi
2480 case "$answer" in
2481 0)
2482 for pkg in $(cat $UP_LIST); do
2483 echo 'y' | tazpkg get-install $pkg --forced
2484 done
2485 # List is generated each time and must be cleaned so
2486 # tazpkg-notify doesn't find upgrades anymore.
2487 rm $UP_LIST; touch $UP_LIST ;;
2488 *)
2489 _ 'Leaving without any upgrades installed.'
2490 newline
2491 exit 0 ;;
2492 esac
2493 fi
2494 newline ;;
2497 bugs)
2498 # Show known bugs in package(s)
2499 cd $INSTALLED
2500 shift
2501 LIST=$@
2502 [ -z "$LIST" ] && LIST=$(ls)
2503 MSG=$(_n 'No known bugs.')
2505 title 'Known bugs in packages'
2506 for PACKAGE in $LIST; do
2507 BUGS=''
2508 EXTRAVERSION=''
2509 . $PACKAGE/receipt
2510 if [ -n "$BUGS" ]; then
2511 MSG=$(_n 'Bug list completed')
2512 newline
2513 _ 'Bugs in package "%s" version %s:' $PACKAGE $VERSION$EXTRAVERSION
2514 cat <<EOT
2515 $BUGS
2516 EOT
2517 fi
2518 done
2519 footer "$MSG" ;;
2522 check)
2523 # Check installed packages set.
2524 check_root $@
2526 # Get repositories priority list.
2527 look_for_priority
2529 cd $INSTALLED
2530 for PACKAGE in $(ls); do
2532 if [ ! -f $PACKAGE/receipt ]; then
2533 _ 'The package "%s" installation has not completed' $PACKAGE
2534 continue
2535 fi
2537 DEPENDS=""
2538 EXTRAVERSION=""
2539 . $PACKAGE/receipt
2540 if [ -s $PACKAGE/modifiers ]; then
2541 _ 'The package "%s" has been modified by:' $PACKAGE-$VERSION$EXTRAVERSION
2542 for i in $(cat $PACKAGE/modifiers); do
2543 echo " $i"
2544 done
2545 fi
2547 MSG="$(_n 'Files lost from package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2548 while read file; do
2549 [ -e "$file" ] && continue
2550 if [ -L "$file" ]; then
2551 MSG="$MSG $(_n 'target of symlink')"
2552 fi
2553 echo -e "$MSG $file"
2554 MSG=""
2555 done < $PACKAGE/files.list
2557 MSG="$(_n 'Missing dependencies for package "%s":' $PACKAGE-$VERSION$EXTRAVERSION)\n"
2558 for i in $DEPENDS; do
2559 [ -d $i ] && continue
2560 [ -d $(equivalent_pkg $i) ] && continue
2561 echo -e "$MSG $i"
2562 MSG=""
2563 done
2565 MSG="$(_n 'Dependencies loop between "%s" and:' $PACKAGE)\n"
2566 ALL_DEPS=""
2567 check_for_deps_loop $PACKAGE $DEPENDS
2568 done
2570 _ 'Looking for known bugs...'
2571 tazpkg bugs
2573 if [ "$2" == "--full" ]; then
2574 separator
2576 for file in */$CHECKSUM; do
2577 CONFIG_FILES=""
2578 . $(dirname "$file")/receipt
2579 [ -s "$file" ] || continue
2580 while read md5 f; do
2581 [ -f $f ] || continue
2582 for i in $CONFIG_FILES; do
2583 case "$f" in
2584 $i|$i/*) continue 2;;
2585 esac
2586 done
2587 echo "$md5 $f"
2588 done < "$file" | busybox $CHECKSUM -c - 2> /dev/null | \
2589 grep -v OK$ | sed "s/FAILED$/$CHECKSUM MISMATCH/"
2590 done
2592 FILES=" "
2593 for file in $(cat */files.list); do
2594 [ -d "$file" ] && continue
2595 case "$FILES" in *\ $file\ *) continue;; esac
2596 [ $(grep "^$(echo $file | grepesc)$" */files.list 2> /dev/null | \
2597 wc -l) -gt 1 ] || continue
2598 FILES="$FILES$file "
2599 _ 'The following packages provide file "%s":' $file
2600 grep -l "^$(echo $file | grepesc)$" */files.list | \
2601 while read f; do
2602 pkg=${f%/files.list}
2603 if [ -f $pkg/modifiers ]; then
2604 overriders=$(_n '(overridden by %s)' "$(tr '\n' ' ' | sed 's| $||' < $pkg/modifiers)")
2605 else
2606 overriders=''
2607 fi
2608 echo -n " $pkg $overriders"
2609 newline
2610 done
2611 done
2613 MSG="$(_n 'No package has installed the following files:')\n"
2614 find /etc /bin /sbin /lib /usr /var/www -not -type d 2>/dev/null | \
2615 while read file; do
2616 case "$file" in *\[*) continue;; esac
2617 grep -q "^$(echo $file | grepesc)$" */files.list && continue
2618 echo -e "$MSG $file"
2619 MSG=""
2620 done
2621 fi
2622 _ 'Check completed.'; echo ;;
2625 block|-b)
2626 # Add a pkg name to the list of blocked packages.
2627 check_root $@
2628 check_for_package_on_cmdline
2629 newline
2630 if [ ! -d $INSTALLED/$PACKAGE ]; then
2631 _ 'Package "%s" is not installed.' $PACKAGE; exit
2632 fi
2633 if grep -qs "^$PACKAGE" $BLOCKED; then
2634 _ 'Package "%s" is already blocked.' $PACKAGE
2635 else
2636 echo $PACKAGE >> $BLOCKED
2637 # Log this activity
2638 . $INSTALLED/$PACKAGE/receipt; log_pkg Blocked
2639 _ 'Package "%s" blocked.' $PACKAGE
2640 fi
2641 newline ;;
2644 unblock|-u)
2645 # Remove a pkg name from the list of blocked packages.
2646 check_root $@
2647 check_for_package_on_cmdline
2648 newline
2649 if [ ! -d $INSTALLED/$PACKAGE ]; then
2650 _ 'Package "%s" is not installed.' $PACKAGE; exit
2651 fi
2652 if grep -qs "^$PACKAGE" $BLOCKED; then
2653 sed -i "/^$PACKAGE\$/d" $BLOCKED
2654 # Log this activity
2655 . $INSTALLED/$PACKAGE/receipt; log_pkg Unblocked
2656 _ 'Package "%s" unblocked.' $PACKAGE
2657 else
2658 _ 'Package "%s" is not blocked.' $PACKAGE
2659 fi
2660 newline ;;
2663 chblock)
2664 # Change package's blocked status.
2665 check_root $@
2666 check_for_package_on_cmdline
2667 newline
2668 if [ ! -d $INSTALLED/$PACKAGE ]; then
2669 _ 'Package "%s" is not installed.' $PACKAGE; exit
2670 fi
2671 if grep -qs "^$PACKAGE" $BLOCKED; then
2672 sed -i "/^$PACKAGE\$/d" $BLOCKED
2673 # Log this activity
2674 . $INSTALLED/$PACKAGE/receipt; log_pkg Unblocked
2675 _ 'Package "%s" unblocked.' $PACKAGE
2676 else
2677 echo $PACKAGE >> $BLOCKED
2678 # Log this activity
2679 . $INSTALLED/$PACKAGE/receipt; log_pkg Blocked
2680 _ 'Package "%s" blocked.' $PACKAGE
2681 fi
2682 newline ;;
2685 get|-g)
2686 # Download a package with wget.
2687 check_root $@
2688 check_for_package_on_cmdline
2689 check_for_packages_list
2691 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2692 if [ "$rootconfig" ]; then
2693 if [ "$root" ]; then
2694 CACHE_DIR=$root/$CACHE_DIR
2695 SAVE_CACHE_DIR=$CACHE_DIR
2696 PKGS_DB=$root/$PKGS_DB
2697 else
2698 _ 'rootconfig needs --root= option used.' >&2
2699 exit 1
2700 fi
2701 fi
2703 # Get repositories priority list.
2704 look_for_priority
2706 CURRENT_DIR=$PWD
2707 cd $CACHE_DIR
2708 if check_for_package_in_list check ; then
2709 if [ -f "$PACKAGE.tazpkg" ]; then
2710 _ 'Package "%s" already in the cache' $PACKAGE
2711 # Check package download was finished
2712 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2713 _ 'Continuing package "%s" download' $PACKAGE
2714 download $PACKAGE.tazpkg
2716 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2717 rm -f $PACKAGE.tazpkg
2718 download $PACKAGE.tazpkg
2719 fi
2720 else
2721 download $PACKAGE.tazpkg
2722 fi
2723 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2724 elif download_get_script $PACKAGE /tmp/$PACKAGE.$$ ; then
2725 install_package_from_get_script /tmp/$PACKAGE.$$ "$ROOT" --get
2726 PACKAGE_FILE=$(ls $PWD/$PACKAGE-*.tazpkg)
2727 fi
2728 [ "$PWD" != "$CURRENT_DIR" ] &&
2729 cp -a $PACKAGE_FILE $CURRENT_DIR ;;
2732 get-install|-gi)
2733 # Download and install a package.
2734 check_root $@
2735 check_for_package_on_cmdline
2736 check_for_packages_list
2738 DO_CHECK=''
2739 [ -n "$forced" ] && DO_CHECK=no
2740 [ -n "$root" ] && ROOT="$root" && check_base_dir "$root"
2741 [ -n "$list" ] && INSTALL_LIST="$list"
2742 if [ -n "$rootconfig" ]; then
2743 if [ -n "$root" ]; then
2744 CACHE_DIR="$root/$CACHE_DIR"
2745 SAVE_CACHE_DIR="$CACHE_DIR"
2746 PKGS_DB="$root/$PKGS_DB"
2747 else
2748 _ 'rootconfig needs --root= option used.' >&2
2749 exit 1
2750 fi
2751 fi
2753 # Get repositories priority list.
2754 look_for_priority
2756 AUTOEXEC='no'
2757 if ! check_for_package_in_list check; then
2758 CACHE_DIR="${CACHE_DIR%/*}/get"
2759 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
2760 if download_get_script $PACKAGE /tmp/$PACKAGE.$$ ; then
2761 install_package_from_get_script /tmp/$PACKAGE.$$ $ROOT
2762 exit 0
2763 else
2764 PACKAGE="get-$PACKAGE"
2765 AUTOEXEC="$PACKAGE"
2766 check_for_package_in_list
2767 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
2768 $AUTOEXEC $ROOT
2769 exit 0
2770 fi
2771 fi
2772 fi
2773 # Check if no forced install.
2774 if [ -z "$forced" ]; then
2775 check_for_installed_package $ROOT
2776 fi
2777 cd $CACHE_DIR
2778 if [ -f "$PACKAGE.tazpkg" ]; then
2779 _ 'Package "%s" already in the cache' $PACKAGE
2780 # Check package download was finished
2781 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2782 _ 'Continuing package "%s" download' $PACKAGE
2783 download $PACKAGE.tazpkg
2785 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2786 rm -f $PACKAGE.tazpkg
2787 download $PACKAGE.tazpkg
2788 fi
2789 else
2790 newline
2791 download $PACKAGE.tazpkg
2792 fi
2793 PACKAGE_FILE="$CACHE_DIR/$PACKAGE.tazpkg"
2794 [ -n "$rootconfig" ] && PKGS_DB="${PKGS_DB#$root}"
2795 install_package "$ROOT"
2796 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
2797 update_desktop_database $ROOT
2798 update_mime_database $ROOT ;;
2801 clean-cache|-cc)
2802 # Remove all downloaded packages.
2803 check_root $@
2804 files=$(find $CACHE_DIR -name *.tazpkg | wc -l)
2805 size=$(du -hs $CACHE_DIR | cut -f1 | sed 's|\.0||'); [ "$files" == '0' ] && size="0K"
2807 title "Cleaning cache directory..."
2808 action 'Path: %s' $CACHE_DIR
2809 rm -rf $CACHE_DIR/*
2810 status
2812 footer "$(_p \
2813 '%s file removed from cache (%s).' \
2814 '%s files removed from cache (%s).' $files \
2815 "$(colorize 32 "$files")" $size)"
2816 ;;
2819 list-undigest)
2820 # list undigest URLs.
2821 if [ -n "$box" ]; then
2822 for i in $PKGS_DB/undigest/*/mirror; do
2823 [ -f "$i" ] || continue
2824 echo "$(basename $(dirname $i))|$(cat $i)"
2825 done
2826 else
2827 title 'Current undigest(s)'
2828 for i in $PKGS_DB/undigest/*/mirror; do
2829 if [ ! -f "$i" ]; then
2830 _ 'No undigest mirror found.'
2831 exit 1
2832 fi
2833 echo "$(basename $(dirname $i)) $(cat $i)"
2834 done
2835 newline
2836 fi ;;
2839 remove-undigest)
2840 # remove undigest URL.
2841 check_root $@
2842 undigest="$2"
2843 if [ -d "$PKGS_DB/undigest/$2" ]; then
2844 confirm "$(_ 'Remove "%s" undigest? (y/N)' $undigest)"
2845 if [ $? == 0 ]; then
2846 action 'Removing "%s" undigest...' $undigest
2847 rm -rf $PKGS_DB/undigest/$2
2848 status
2849 rmdir $PKGS_DB/undigest 2>/dev/null
2850 fi
2851 else
2852 _ 'Undigest "%s" not found' $undigest
2853 fi ;;
2856 add-undigest|setup-undigest)
2857 # Add undigest URL.
2858 check_root $@
2859 undigest=$2
2860 [ -d $PKGS_DB/undigest ] || mkdir $PKGS_DB/undigest
2861 if [ -z "$undigest" ]; then
2862 i=1
2863 while [ -d "$PKGS_DB/undigest/$i" ]; do
2864 i=$(($i+1))
2865 done
2866 undigest=$i
2867 fi
2868 if [ ! -d "$PKGS_DB/undigest/$undigest" ]; then
2869 _ 'Creating new undigest "%s".' $undigest
2870 mkdir $PKGS_DB/undigest/$undigest
2871 fi
2872 setup_mirror $PKGS_DB/undigest/$undigest $3 ;;
2875 setup-mirror|-sm)
2876 # Change mirror URL.
2877 check_root $@
2878 setup_mirror $PKGS_DB $2 ;;
2881 reconfigure)
2882 # Replay post_install from receipt
2883 check_for_package_on_cmdline
2884 check_root $@
2885 ROOT=''
2886 while [ -n "$3" ]; do
2887 case "$3" in
2888 --root=*)
2889 ROOT="${3#--root=}/" ;;
2890 *)
2891 shift 2
2892 u_opt="$*"
2893 newline >&2
2894 _ 'Unknown option "%s".' $u_opt >&2
2895 exit 1 ;;
2896 esac
2897 shift
2898 done
2899 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2900 check_for_receipt $ROOT
2901 # Check for post_install
2902 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2903 . $ROOT$INSTALLED/$PACKAGE/receipt
2904 post_install $ROOT
2905 # Log this activity
2906 [ -n "$ROOT" ] || log_pkg Reconfigured
2907 else
2908 newline
2909 _ 'Nothing to do for package "%s".' $PACKAGE
2910 fi
2911 else
2912 newline
2913 _ 'Package "%s" is not installed.' $PACKAGE
2914 _ 'Install package with "%s" or "%s"' 'tazpkg install' 'tazpkg get-install'
2915 newline
2916 fi ;;
2919 shell)
2920 # TazPKG SHell
2921 if [ "$(id -u)" == '0' ]; then
2922 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2923 else
2924 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2925 fi
2926 if [ "$2" != "--noheader" ]; then
2927 clear
2928 title 'TazPKG SHell.'
2929 _ "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
2930 newline
2931 fi
2932 while true; do
2933 echo -en "$PROMPT"; read cmd
2934 case $cmd in
2935 q|quit)
2936 break ;;
2937 shell)
2938 _ 'You are already running a TazPKG SHell.' ;;
2939 su)
2940 su -c 'exec tazpkg shell --noheader' && break ;;
2941 "")
2942 continue ;;
2943 *)
2944 tazpkg $cmd ;;
2945 esac
2946 done ;;
2949 depends)
2950 # Display dependencies tree
2951 cd $INSTALLED
2952 ALL_DEPS=''
2953 if [ -f "$2/receipt" ]; then
2954 dep_scan $2 ''
2955 fi ;;
2958 rdepends)
2959 # Display reverse dependencies tree
2960 cd $INSTALLED
2961 ALL_DEPS=''
2962 if [ -f "$2/receipt" ]; then
2963 rdep_scan $2
2964 fi ;;
2967 list-suggested)
2968 for i in $(ls -d $INSTALLED/*); do
2969 . $i/receipt
2970 if [ -n "$SUGGESTED" ]; then
2971 if [ -z "$all" ]; then
2972 for s in $SUGGESTED; do
2973 [ -d "$INSTALLED/$s" ] && \
2974 SUGGESTED="$(echo -n $SUGGESTED | sed "s/$s//")"
2975 done
2976 fi
2977 cat <<EOT
2978 $(boldify $(echo $PACKAGE):) $SUGGESTED
2979 EOT
2980 fi
2981 SUGGESTED=''
2982 done ;;
2985 convert|-c)
2986 # convert misc package format to .tazpkg
2987 check_for_package_file
2988 shift
2989 tazpkg-convert $@
2990 ;;
2993 link)
2994 # link a package from another slitaz installation
2995 PACKAGE=$2
2996 if [ ! -d "$TARGET_DIR" -o \
2997 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
2998 _ 'Usage: tazpkg link package_name slitaz_root'
2999 longline "$(
3000 _n 'Example:'
3001 echo -n ' '
3002 _ '"%s" will use less than 100k in your running system RAM.' \
3003 'tazpkg link openoffice /mnt')"
3004 exit 1
3005 fi
3006 if [ -e "$INSTALLED/$PACKAGE" ]; then
3007 _ 'Package "%s" is already installed.' $PACKAGE
3008 exit 1
3009 fi
3010 ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
3011 DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
3012 MISSING=''
3013 for i in $DEPENDS; do
3014 [ -e $INSTALLED/$i ] && continue
3015 MISSING="$MISSING$i "
3016 _ 'Missing: %s' $i
3017 done
3018 if [ -n "$MISSING" ]; then
3019 newline
3020 confirm "$(_ 'Link all missing dependencies? (y/N)')"
3021 answer=$?
3022 newline
3023 if [ "$answer" == 0 ]; then
3024 for i in $MISSING; do
3025 tazpkg link $i $TARGET_DIR
3026 done
3027 else
3028 newline
3029 _ 'Leaving dependencies unresolved for package "%s"' $PACKAGE
3030 _ 'The package is installed but probably will not work.'
3031 newline
3032 fi
3033 fi
3034 . $INSTALLED/$PACKAGE/receipt
3035 if grep -q ^pre_install $INSTALLED/$PACKAGE/receipt; then
3036 pre_install
3037 fi
3038 while read path; do
3039 [ -e "$path" ] && continue
3040 while true; do
3041 dir="$(dirname $path)"
3042 [ -e "$dir" ] && break
3043 path="$dir"
3044 done
3045 ln -s "$TARGET_DIR$path" "$dir"
3046 done < $INSTALLED/$PACKAGE/files.list
3047 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
3048 post_install
3049 fi ;;
3052 usage|*)
3053 # Print a short help or give usage for an unknown or empty command.
3054 usage ;;
3055 esac
3057 exit 0