tazpkg view tazpkg @ rev 838

repack SHORT_DESC fix (thanks aleksej)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Aug 16 11:20:17 2015 +0200 (2015-08-16)
parents 358a978f45a9
children b1da66280a9d
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 . /etc/slitaz/slitaz.conf
22 . /etc/slitaz/tazpkg.conf
24 . /lib/libtaz.sh
25 . /usr/lib/slitaz/libpkg.sh
26 . @@MODULES@@/find-depends
28 # Internationalization.
29 export TEXTDOMAIN='tazpkg'
30 _() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; echo; }
31 _n() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; }
32 _p() {
33 local S="$1" P="$2" N="$3"; shift 3;
34 printf "$(ngettext "$S" "$P" "$N")" "$@"; }
37 # Translate category names (must be last in line)
39 translate_category() {
40 sed "s|base-system$|$(_ base-system)|; s|x-window$|$(_ x-window)|;
41 s|utilities$|$(_ utilities)|; s|network$|$(_ network)|;
42 s|graphics$|$(_ graphics)|; s|multimedia$|$(_ multimedia)|;
43 s|office$|$(_ office)|; s|development$|$(_ development)|;
44 s|system-tools$|$(_ system-tools)|; s|security$|$(_ security)|;
45 s|games$|$(_ games)|; s|misc$|$(_ misc)|; s|meta$|$(_ meta)|;
46 s|non-free$|$(_ non-free)|; s|all$|$(_ all)|; s|extra$|$(_ extra)|"
47 }
50 # Remove all --parameters from cmdline
51 #-------------------------------------
52 # (thanks to libtaz.sh all --parameters are already set to variables)
54 IFS=$'\n'
55 set -- $(echo "$*" | sed '/^--/d')
56 unset IFS
59 # Initialize some variables to use words rather than numbers for functions
60 # and actions.
62 COMMAND="$1"
63 PACKAGE="${2%/}"
64 PACKAGE_DIR="$(cd $(dirname "$PACKAGE" 2>/dev/null) 2>/dev/null; pwd)"
65 [ -n "$PACKAGE" ] && PACKAGE_FILE="$PACKAGE_DIR/${PACKAGE##*/}"
66 if [ -f "$PACKAGE" ]; then
67 # Set pkg basename for install, extract
68 PACKAGE="$(basename "$PACKAGE" .tazpkg 2>/dev/null)"
69 else
70 # Pkg name for remove, search and all other cmds
71 PACKAGE="${PACKAGE%.tazpkg}"
72 fi
73 TARGET_DIR="$3"
74 TOP_DIR="$(pwd)"
75 TMP_DIR="/tmp/$RANDOM"
76 INSTALL_LIST=''
77 SAVE_CACHE_DIR="$CACHE_DIR"
79 # Path to tazpkg used dir and configuration files
80 MIRROR="$PKGS_DB/mirror"
81 export BLOCKED="$PKGS_DB/blocked-packages.list"
82 export UP_LIST="$PKGS_DB/packages.up"
83 DEFAULT_MIRROR="$ONLINE_PKGS"
85 # TazPkg version
86 VERSION=$(awk -F$'\t' '$1=="tazpkg"{print $2}' $PKGS_DB/installed.info)
87 # User Agent
88 export UA="TazPkg-$VERSION"
90 #title 'DEBUG'; emsg "<b>COMMAND</b>=\"$COMMAND\"\n<b>PACKAGE</b>=\"$PACKAGE\"\n<b>PACKAGE_FILE</b>=\"$PACKAGE_FILE\"\n<b>TARGET_DIR</b>=\"$TARGET_DIR\"\n<b>TOP_DIR</b>=\"$TOP_DIR\"\n<b>TMP_DIR</b>=\"$TMP_DIR\"\n<b>INSTALL_LIST</b>=\"$INSTALL_LIST\"\n<b>SAVE_CACHE_DIR</b>=\"$SAVE_CACHE_DIR\"\n<b>MIRROR</b>=\"$MIRROR\"\n<b>BLOCKED</b>=\"$BLOCKED\"\n<b>UP_LIST</b>=\"$UP_LIST\"\n<b>DEFAULT_MIRROR</b>=\"$DEFAULT_MIRROR\"\n<b>VERSION</b>=\"$VERSION\""; footer
93 ####################
94 # Script functions #
95 ####################
98 # Interactive mode
100 im() { tty -s; }
103 # Print the usage.
105 usage () {
106 cat <<EOT
108 $(_ 'SliTaz package manager - Version: %s' $(colorize 34 $VERSION))
110 $(boldify "$(_ 'Usage:')")
111 $(_ 'tazpkg [command] [package|dir|pattern|list|cat|--opt] [dir|--opt]')
113 $(boldify "$(_ 'SHell:')") tazpkg shell
115 $(boldify "$(_ 'Commands:')")
116 $(optlist "\
117 usage $(_ 'Print this short usage')
118 -h help $(_ 'Show help on the TazPkg commands')
119 -a activity $(_ 'Show TazPkg activity log')
120 -cc clean-cache $(_ 'Clean all packages downloaded in cache directory')
121 shell $(_ 'Run interactive TazPkg shell')
123 -l list $(_ 'List installed packages on the system')
124 -lm list-mirror $(_ 'List all available packages on the mirror')
125 list-config $(_ 'List the configuration files')
127 -s search $(_ 'Search for a package by pattern or name')
128 -sp search-pkgname $(_ 'Search on mirror for package having a particular file')
129 -sf search-file $(_ 'Search for file in all installed packages files')
131 -g get $(_ 'Download a package into the current directory')
132 -i install $(_ 'Install a local package')
133 -gi get-install $(_ 'Download and install a package from the mirror')
134 install-list $(_ 'Install all packages from a list of packages')
135 get-install-list $(_ 'Download and install a list of packages from the mirror')
136 -r remove $(_ 'Remove the specified package and all installed files')
137 reconfigure $(_ 'Replay post install script from package')
138 link $(_ 'Link a package from another SliTaz installation')
139 set-release $(_ 'Change release and update packages')
140 add-flavor $(_ 'Install the flavor list of packages')
141 install-flavor $(_ 'Install the flavor list of packages and remove other ones')
143 info $(_ 'Print information about a package')
144 -d desc $(_ 'Print description of a package')
145 -lf list-files $(_ 'List the files installed with a package')
146 -b|u block|unblock $(_ 'Block an installed package version or unblock it for upgrade')
147 check $(_ 'Verify consistency of installed packages')
148 bugs $(_ 'Show known bugs in packages')
149 depends $(_ 'Display dependencies tree')
150 rdepends $(_ 'Display reverse dependencies tree')
151 -e extract $(_ 'Extract a (*.tazpkg) package into a directory')
152 pack $(_ 'Pack an unpacked or prepared package tree')
153 repack $(_ 'Create a package archive from an installed package')
154 repack-config $(_ 'Create a package archive with configuration files')
155 recompress $(_ 'Rebuild a package with a better compression ratio')
156 convert $(_ 'Convert alien package to tazpkg')
157 list-suggested $(_ 'Print list of suggested packages')
159 recharge $(_ 'Recharge your packages.list from the mirror')
160 up|help-up $(_ 'Check packages %s to list and install latest upgrades' $CHECKSUM)
161 -sm setup-mirror $(_ 'Change the mirror URL configuration')
162 setup-undigest $(_ 'Update an undigest mirror')
163 list-undigest $(_ 'List undigest mirrors')
164 add-undigest $(_ 'Add an undigest mirror')
165 remove-undigest $(_ 'Remove an undigest mirror')
166 ")
167 EOT
168 }
171 usage_up() {
172 cat <<EOT
173 $(emsg "<b>$(_ 'Usage for command up:')</b>") tazpkg up [$(_ 'option')]
175 * $(longline "$(_ 'Without options run in interactive mode and ask before install')")
177 $(boldify "$(_ 'Where options are:')")
178 $(optlist "\
179 -c --check $(_ 'Check only for available upgrades')
180 -r --recharge $(_ 'Force recharge of packages list and check')
181 -i --install $(_ 'Check for upgrades and install them all')
182 ")
184 $(boldify "$(_ 'Example:')")
185 tazpkg up --recharge --install
186 tazpkg up -c -r
187 EOT
188 }
191 # Check if dir exists
193 check_dir() {
194 if [ ! -d "$1" ]; then
195 action 'Creating folder "%s"...' "$1"
196 mkdir -p "$1"
197 status
198 return 1
199 fi
200 }
203 # Check if the directories and files used by TazPkg exist.
204 # If not and user is root we create them.
206 check_base_dir() {
207 if [ "$(id -u)" == '0' ]; then
208 check_dir $1$CACHE_DIR
209 check_dir $1$INSTALLED
210 check_dir $1$SLITAZ_LOGS
211 if [ ! -f "$1$PKGS_DB/mirror" ]; then
212 echo "${DEFAULT_MIRROR%/}/" > $1$PKGS_DB/mirror
213 [ -n "$1" ] && cp $PKGS_DB/packages.* $1$PKGS_DB/
214 fi
215 fi
216 }
217 check_base_dir
220 # Check for a package name on cmdline.
222 check_for_package_on_cmdline() {
223 if [ -z "$PACKAGE" ]; then
224 newline
225 _ 'Please specify a package name on the command line.'
226 newline
227 exit 1
228 fi
229 }
232 # Check if the package (*.tazpkg) exists before installing or extracting.
234 check_for_package_file() {
235 if [ ! -f "$PACKAGE_FILE" ]; then
236 newline
237 _ 'Unable to find file "%s"' "$PACKAGE_FILE"
238 newline
239 exit 1
240 fi
241 }
244 # Check for the receipt of an installed package.
246 check_for_receipt() {
247 if [ ! -f "$1$INSTALLED/$PACKAGE/receipt" ]; then
248 newline
249 _ 'Unable to find the receipt "%s"' "$1$INSTALLED/$PACKAGE/receipt"
250 newline
251 exit 1
252 fi
253 }
256 # Get repositories priority using $PKGS_DB/priority.
257 # In this file undigest repos are called by their names and main mirror
258 # by 'main'. Sort order: priority
260 look_for_priority() {
261 [ -s "$PKGS_DB/priority" ] && priority=$(cat $PKGS_DB/priority)
263 for rep in main $(ls $PKGS_DB/undigest 2>/dev/null); do
264 if [ ! -s "$PKGS_DB/priority" ] || ! grep -q ^$rep$ $PKGS_DB/priority; then
265 priority=$(echo -e "$priority\n$rep")
266 fi
267 done
268 priority=$(echo "$priority" | sed '/^$/d' | \
269 while read line; do
270 case $line in
271 (main) echo $PKGS_DB;;
272 (*) echo $PKGS_DB/undigest/$line;;
273 esac
274 done)
275 }
278 # Get package name in a directory
280 package_fullname_in_dir() {
281 [ ! -f "$1/receipt" ] && return
282 EXTRAVERSION=''
283 . $1/receipt
284 echo "$PACKAGE-$VERSION$EXTRAVERSION"
285 }
288 # Get package name that is already installed.
290 get_installed_package_pathname() {
291 for i in $2$INSTALLED/${1%%-*}*; do
292 [ ! -d $i ] && continue
293 if [ "$1" == "$(package_fullname_in_dir $i)" ]; then
294 echo "$i"
295 return
296 fi
297 done
298 }
301 # Check if a package is already installed.
303 check_for_installed_package() {
304 if [ -n "$(get_installed_package_pathname "$PACKAGE" "$1")" ]; then
305 newline
306 _ '"%s" package is already installed.' "$(colorize 34 "$PACKAGE")"
307 longline "$(_ 'You can use the --forced option to force installation.')"
308 newline
309 exit 0
310 fi
311 }
314 # Check for packages.list to download and install packages.
316 check_for_packages_list() {
317 list_path="$PKGS_DB/packages.list"
318 if [ ! -f "$list_path" ]; then
319 if [ $(id -u) -eq 0 ]; then
320 tazpkg recharge
321 else
322 newline
323 _ 'Unable to find the list "%s"' $list_path
324 _ \
325 "You must probably run 'tazpkg recharge' as root to get the latest list of
326 packages available on the mirror."
327 newline
328 exit 0
329 fi
330 fi
331 }
334 # Check for installed.info - local file with format of packages.info
335 # "installed.info" is absent on not clean installs; check it and re-generate if needed.
337 check_for_installed_info() {
338 info_path="$ROOT$PKGS_DB/installed.info"
339 if [ ! -f "$info_path" ]; then
340 if [ "$(id -u)" == '0' ]; then
341 _ 'File "%s" generated. Please wait...' 'installed.info'
342 for pkg in $ROOT$PKGS_DB/installed/*/receipt; do
343 unset_receipt
344 . $pkg
345 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
346 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
347 MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" \
348 $ROOT$PKGS_DB/installed.md5 | awk '{print $1}')"
349 cat >> $info_path << EOT
350 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5
351 EOT
352 done
353 else
354 _ 'Unable to find file "%s"' installed.info
355 _ 'Please run tazpkg as root.'
356 exit 1
357 fi
358 fi
360 # Check for md5 field (#9) in the installed.info
361 if [ -n "$(awk -F$'\t' 'BEGIN{ n = "" } { if(NF != 9){ n = "o"; } } END{ print n }' $info_path)" ]; then
362 _n 'File "%s" generated. Please wait...' 'installed.info.new'
363 awk -F$'\t' -vm="$ROOT$PKGS_DB/installed.md5" 'BEGIN{OFS="\t"}
364 {
365 if (NF != 9) {
366 pkg = $1 "-" $2 ".tazpkg";
367 "fgrep " pkg " " m " | cut -c-32" | getline $9;
368 $9 = ($9 == "") ? "00000000000000000000000000000000" : $9;
369 }
370 print;
371 }' $info_path > $info_path.new
372 mv -f $info_path.new $info_path
373 status
374 fi
375 }
378 get_cache_dir() {
379 echo $rep > $tmp/rep
380 if [ "$rep" == "$PKGS_DB" ]; then
381 CACHE_DIR="$SAVE_CACHE_DIR/$SLITAZ_RELEASE/packages"
382 elif [ "${rep%-incoming}" == "$rep" ]; then
383 CACHE_DIR="$SAVE_CACHE_DIR/${rep##*/}/packages"
384 else
385 rep="${rep%-incoming}"
386 CACHE_DIR="$SAVE_CACHE_DIR/${rep##*/}/packages-incoming"
387 fi
388 [ ! -d "$CACHE_DIR" ] && mkdir -p $CACHE_DIR
389 echo $CACHE_DIR > $tmp/cachedir
390 }
393 # get an already installed package from packages.equiv
395 equivalent_pkg() {
396 for i in $(grep -hs "^$1=" $PKGS_DB/packages.equiv \
397 $PKGS_DB/undigest/*/packages.equiv | sed "s/^$1=//"); do
398 if echo $i | fgrep -q : ; then
399 # format 'alternative:newname'
400 # if alternative is installed then substitute newname
401 if [ -f "$2$INSTALLED/${i%:*}/receipt" ]; then
402 # substitute package dependency
403 echo "${i#*:}"
404 return
405 fi
406 else
407 # if alternative is installed then nothing to install
408 if [ -f "$2$INSTALLED/$i/receipt" ]; then
409 # substitute installed package
410 echo "$i"
411 return
412 fi
413 fi
414 done
415 # if not found in packages.equiv then no substitution
416 echo "$1"
417 }
420 # get a virtual package from packages.equiv
422 virtual_pkg() {
423 for i in $(for rep in $priority; do
424 grep -hs "^$1=" $rep/packages.equiv
425 done | sed "s/^$1=//"); do
426 if echo $i | fgrep -q : ; then
427 # format 'alternative:newname'
428 # if alternative is installed then substitute newname
429 if [ -f "$2$INSTALLED/${i%:*}/receipt" ]; then
430 # substitute package dependency
431 echo "${i#*:}"
432 return
433 fi
434 else
435 # unconditional substitution
436 echo "$i"
437 return
438 fi
439 done
440 }
443 # Get package filename available on the mirror
445 get_package_filename() {
446 # input: "<package_name>" or "<package_name>-<version>" (ex. "nano" or "nano-2.4.0")
447 local pkg equiv
448 for rep in $priority; do
449 pkg=$(awk -F$'\t' -vp="$1" 'p==$1||p==$1"-"$2{print $1"-"$2}' $rep/packages.info)
451 if [ -n "$pkg" ]; then
452 get_cache_dir; break
453 fi
454 done
455 if [ -z "$pkg" ]; then
456 # Check for virtual package
457 equiv=$(virtual_pkg $1)
458 if [ "$equiv" != "$1" ]; then
459 PACKAGE="$equiv"
460 get_package_filename "$PACKAGE"
461 return
462 fi
463 fi
464 echo "$pkg"
465 }
468 # Check for a package in packages DB. Used by get and get-install to grep
469 # package basename.
471 check_for_package_in_list() {
472 local filename check_only
473 check_only="$1"
474 filename="$(get_package_filename "$PACKAGE")"
475 if [ -n "$filename" ]; then
476 PACKAGE="$filename"
477 CACHE_DIR="$(cat $tmp/cachedir)"
478 rep="$(cat $tmp/rep)"
479 rm -f $tmp/rep $tmp/cachedir
480 else
481 newline
482 _ 'Unable to find package "%s" in the mirrored packages list.' "$PACKAGE"
483 newline
484 [ -n "$check_only" ] && return 1
485 exit 0
486 fi
487 }
490 # Log this activity
491 # (there log_pkg because we have log() in libtaz.sh)
493 log_pkg() {
494 local extra
496 [ "$1" == 'Installed' ] && \
497 extra=" - $(fgrep " $PACKAGE-$VERSION" $PKGS_DB/installed.$SUM | awk '{ print $1 }')"
499 [ -e "$LOG" ] || touch $LOG
501 [ -w "$LOG" ] &&
502 echo "$(date +'%F %T') - $1 - $PACKAGE ($VERSION$EXTRAVERSION)$extra" >> $LOG
503 }
506 # Download a get-package script from this mirror
508 download_get_script() {
509 local p i
510 for p in $priority ; do
511 for i in $(cat $p/mirror) ; do
512 case "$i" in
513 http://*|https://*|ftp://*)
514 busybox wget -q -T 30 -U $UA -O $2 \
515 ${i%packages/*}packages/get/$1 && return 0 ;;
516 esac
517 done
518 done
519 return 1
520 }
523 # Download a file from this mirror
525 download_from() {
526 # input: "<mirror_url>+" "<package_name>-<version>.tazpkg"
527 local i
528 for i in $1; do
529 case "$i" in
530 # Mirror URL can have a trailing slash or not.
531 http://* | https://* | ftp://*)
532 busybox wget -c -q -T 30 -U $UA ${i%/}/$2 2>/dev/null && break ;;
533 *)
534 ln -sf ${i%/}/$2 . && break ;;
535 esac
536 done
537 }
540 # Download a file trying all mirrors
542 download() {
543 # input: <package_name>-<version>.tazpkg
544 local i
545 case "$1" in
546 *.tazpkg)
547 for i in $priority; do
548 if [ -n "$(awk -F$'\t' -vp="$1" 'p==$1"-"$2".tazpkg"{print $1}' \
549 $i/packages.info)" ]; then
550 download_from "$(cat $i/mirror)" "$@" && return
551 fi
552 done
553 ;;
554 esac
556 for i in $(cat $(for rep in $priority; do echo $rep/mirror; done) 2>/dev/null); do
557 download_from "$i" "$@" && break
558 done
559 }
562 # Extract a package with cpio and gzip/lzma.
564 extract_package() {
565 action 'Extracting package...'
566 cpio -idm --quiet < "${PACKAGE_FILE##*/}" && rm -f "${PACKAGE_FILE##*/}"
567 if [ -f fs.cpio.lzma ]; then
568 unlzma < fs.cpio.lzma | cpio -idm --quiet && rm fs.cpio.lzma
569 elif [ -f fs.cpio.gz ]; then
570 zcat fs.cpio.gz | cpio -idm --quiet && rm fs.cpio.gz
571 fi
572 status
573 }
576 remove_with_path() {
577 # Avoid dirname errors by checking for argument.
578 [ -n "$1" ] || return
580 local dir
581 rm -f $1 2>/dev/null
582 dir="$1"
583 while [ "$dir" != "/" ]; do
584 dir="$(dirname "$dir")"
585 rmdir "$dir" 2>/dev/null || break
586 done
587 }
590 grepesc() {
591 sed 's/\[/\\[/g'
592 }
595 # Print short package description
596 print_short_description() {
597 local short_desc=''
598 for LC in $LANG ${LANG%_*}; do
599 if [ -e "$PKGS_DB/packages-desc.$LC" ]; then
600 short_desc=$(grep -e "^$1 " $PKGS_DB/packages-desc.$LC | cut -d' ' -f2)
601 fi
602 done
603 [ -z "$short_desc" -a -s $PKGS_DB/packages.info ] &&
604 short_desc="$(awk -F$'\t' -vp="$PACKAGE" '{if($1==p){print $4;exit}}' $PKGS_DB/packages.info)"
605 longline "$short_desc"
606 }
609 # This function installs a package in the rootfs.
611 install_package() {
612 ROOT=$1
613 if [ -n "$ROOT" ]; then
614 # Get absolute path
615 ROOT=$(realpath $ROOT)
616 fi
617 {
618 # Create package path early to avoid dependencies loop
619 mkdir -p $TMP_DIR
620 { cd $TMP_DIR ; cpio --quiet -i receipt >/dev/null 2>&1; } < "$PACKAGE_FILE"
621 . $TMP_DIR/receipt
622 # FIXME: legacy?
623 if grep -q ^pre_depends $TMP_DIR/receipt; then
624 pre_depends $ROOT
625 fi
627 # Keep modifiers and file list on upgrade
628 cp "$ROOT$INSTALLED/$PACKAGE/modifiers" \
629 "$ROOT$INSTALLED/$PACKAGE/files.list" $TMP_DIR 2>/dev/null
630 rm -rf "$ROOT$INSTALLED/$PACKAGE" 2>/dev/null
632 # Make the installed package data dir to store
633 # the receipt and the files list.
634 mkdir -p "$ROOT$INSTALLED/$PACKAGE"
635 cp $TMP_DIR/modifiers "$ROOT$INSTALLED/$PACKAGE" 2>/dev/null
636 cp $TMP_DIR/files.list "$ROOT$INSTALLED/$PACKAGE" 2>/dev/null
637 rm -rf $TMP_DIR 2> /dev/null
638 sed -i "/ $(basename "$PACKAGE_FILE")$/d" $ROOT$PKGS_DB/installed.$SUM 2>/dev/null
639 cd "$(dirname "$PACKAGE_FILE")"
640 $CHECKSUM "$(basename "$PACKAGE_FILE")" >> $ROOT$PKGS_DB/installed.$SUM
641 }
643 # Resolve package deps.
644 check_for_deps $ROOT
645 if [ -n "$MISSING_PACKAGE" ]; then
646 install_deps $ROOT
647 fi
648 mkdir -p $TMP_DIR
649 [ -n "$INSTALL_LIST" ] && echo "$PACKAGE_FILE" >> $ROOT$PKGS_DB/$INSTALL_LIST-processed
651 title 'Installation of package "%s"' "$PACKAGE"
653 short_desc="$(print_short_description "$PACKAGE")"
654 [ -n "$short_desc" ] && echo "$short_desc" && separator '-'
656 action 'Copying package...'
657 cp "$PACKAGE_FILE" "$TMP_DIR"
658 status
660 cd "$TMP_DIR"
661 extract_package
662 SELF_INSTALL='0'
663 EXTRAVERSION=''
664 CONFIG_FILES=''
666 # Include temporary receipt to get the right variables.
667 . $PWD/receipt
668 cd $ROOT$INSTALLED
670 # FIXME: legacy?
671 if [ $SELF_INSTALL -ne 0 -a -n "$ROOT" ]; then
672 action "Checking post install dependencies..."
673 [ -f "$INSTALLED/$PACKAGE/receipt" ]
674 if ! status; then
675 _ 'Please run "%s" in / and retry.' "tazpkg install $PACKAGE_FILE"
676 rm -rf $TMP_DIR
677 exit 1
678 fi
679 fi
681 # Get files to remove if upgrading
682 if [ -f "$PACKAGE/files.list" ]; then
683 while read file; do
684 grep -q "^$(echo $file | grepesc)$" $TMP_DIR/files.list && continue
685 for i in $(cat "$PACKAGE/modifiers" 2>/dev/null ;
686 fgrep -sl "$PACKAGE" */modifiers | cut -d/ -f1 ); do
687 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
688 done
689 echo $file
690 done < "$PACKAGE/files.list" > $TMP_DIR/files2remove.list
691 fi
693 # Remember modified packages
694 {
695 check=false
696 for i in $(fgrep -v [ $TMP_DIR/files.list); do
697 [ -e "$ROOT$i" ] || continue
698 [ -d "$ROOT$i" ] && continue
699 echo "- $i"
700 check=true
701 done ;
702 $check && \
703 for i in *; do
704 [ "$i" == "$PACKAGE" ] && continue
705 [ -s $i/files.list ] || continue
706 awk "{ printf \"$i %s\\n\",\$1 }" < $i/files.list
707 done;
708 } | awk '
709 {
710 if ($1 == "-" || file[$2] != "") {
711 file[$2] = file[$2] " " $1
712 if ($1 != "-") {
713 if (pkg[$1] == "") all = all " " $1
714 pkg[$1] = pkg[$1] " " $2
715 }
716 }
717 }
718 END {
719 for (i = split(all, p, " "); i > 0; i--)
720 for (j = split(pkg[p[i]], f, " "); j > 0; j--)
721 printf "%s %s\n",p[i],f[j];
722 }
723 ' | while read dir file; do
724 if grep -qs ^$dir$ "$PACKAGE/modifiers"; then
725 # Do not overload an overloaded file !
726 rm $TMP_DIR$file 2>/dev/null
727 continue
728 fi
729 grep -qs "^$PACKAGE$" $dir/modifiers && continue
730 if [ -s "$dir/volatile.cpio.gz" ]; then
731 # We can modify backed up files without notice
732 zcat $dir/volatile.cpio.gz | cpio -t --quiet | \
733 grep -q "^${file#/}$" && continue
734 fi
735 echo "$PACKAGE" >> $dir/modifiers
736 done
738 cd $TMP_DIR
739 cp receipt files.list "$ROOT$INSTALLED/$PACKAGE"
741 # Copy the description if found.
742 if [ -f "description.txt" ]; then
743 cp description.txt "$ROOT$INSTALLED/$PACKAGE"
744 fi
746 # Copy the md5sum if found.
747 if [ -f "$CHECKSUM" ]; then
748 cp $CHECKSUM "$ROOT$INSTALLED/$PACKAGE"
749 fi
751 # Pre install commands.
752 if grep -q ^pre_install "$ROOT$INSTALLED/$PACKAGE/receipt"; then
753 pre_install $ROOT
754 fi
756 if [ -n "$CONFIG_FILES" ]; then
757 # save 'official' configuration files
758 action 'Saving configuration files...'
759 for i in $CONFIG_FILES; do
760 { cd fs ; find ${i#/} -type f 2> /dev/null; cd ..; }
761 done | { cd fs ; cpio -o -H newc --quiet | gzip -9; cd ..; } > \
762 "$ROOT$INSTALLED/$PACKAGE/volatile.cpio.gz"
764 if [ -z "$newconf" ]; then
765 # keep user configuration files
766 for i in $CONFIG_FILES; do
767 { cd fs ; find ${i#/} -type f 2> /dev/null; cd ..; }
768 done | while read i; do
769 [ -e $ROOT/$i ] || continue
770 cp -a $ROOT/$i fs/$i
771 done
772 fi
773 status
774 fi
776 action 'Installing package...'
777 [ "$(busybox ls fs/* 2>/dev/null)" ] && cp -af fs/* $ROOT/
778 status
780 if [ -s files2remove.list ]; then
781 action 'Removing old package...'
782 while read file; do
783 remove_with_path $ROOT$file
784 done < files2remove.list
785 true
786 status
787 fi
789 # Remove the temporary random directory.
790 action "Removing all tmp files..."
791 cd ..; rm -rf $TMP_DIR
792 status
794 # Post install commands.
795 if grep -q ^post_install "$ROOT$INSTALLED/$PACKAGE/receipt"; then
796 action "Execute post-install commands..."
797 post_install $ROOT
798 status
799 fi
801 # Update-desktop-database if needed.
802 if [ "$(fgrep .desktop "$ROOT$INSTALLED/$PACKAGE/files.list" | fgrep /usr/share/applications/)" ]; then
803 updatedesktopdb=yes
804 fi
806 # Update-mime-database if needed.
807 if [ "$(fgrep /usr/share/mime "$ROOT$INSTALLED/$PACKAGE/files.list")" ]; then
808 updatemimedb=yes
809 fi
811 # Update-icon-database
812 if [ "$(fgrep /usr/share/icon/hicolor "$ROOT$INSTALLED/$PACKAGE/files.list")" ]; then
813 updateicondb=yes
814 fi
816 # Compile glib schemas if needed.
817 if [ "$(fgrep /usr/share/glib-2.0/schemas "$ROOT$INSTALLED/$PACKAGE/files.list")" ]; then
818 compile_schemas=yes
819 fi
821 # Update depmod list
822 if [ "$(fgrep /lib/modules "$ROOT$INSTALLED/$PACKAGE/files.list")" ]; then
823 updatedepmod=yes
824 fi
826 # Update installed.info
827 check_for_installed_info
828 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
829 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
830 PKG_SUM="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$ROOT$PKGS_DB/installed.$SUM" | cut -d' ' -f1)"
831 II=$ROOT$PKGS_DB/installed.info
832 sed -i "/^$PACKAGE /d" $II # remove old entry
833 cat >> $II <<EOT
834 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $PKG_SUM
835 EOT
836 #awk -F$'\t' -vp="$PACKAGE" '$1==p' $ROOT$PKGS_DB/packages.info > $II
837 TEMP_FILE=$(mktemp)
838 sort $II > $TEMP_FILE; mv -f $TEMP_FILE $II; chmod a+r $II; unset II
840 cd "$TOP_DIR"
841 footer "$(_ 'Package "%s" (%s) is installed.' "$PACKAGE" "$VERSION$EXTRAVERSION")"
843 # Log this activity
844 [ -n "$ROOT" ] || log_pkg Installed
846 # Remove package from upgrade list
847 [ -s $UP_LIST ] && sed -i "/^$PACKAGE\$/d" $UP_LIST
848 }
851 # This function may be called by a get script.
853 abort_package() {
854 cd $CUR_DIR
855 rm -rf $TMP_DIR
856 echo "${1:-Abort $PACKAGE.}"
857 exit 1
858 }
861 # This function installs a package from a get script in the rootfs.
863 install_package_from_get_script() {
864 SCRIPT="$1"
865 ROOT="$2"
866 [ -d "$ROOT$INSTALLED/$PACKAGE" ] && exit 1
868 grep -q no-check-certificate $SCRIPT &&
869 [ ! -d "$INSTALLED/wget" ] && tazpkg get-install wget
871 mkdir -p $TMP_DIR && cd $TMP_DIR
872 saved="$PACKAGE"
873 unset_receipt
874 PACKAGE="$saved"
876 set -e
877 . $SCRIPT
878 set +e
879 [ -d "$PACKAGE-$VERSION" ] || cd $TMP_DIR
880 [ -d "$PACKAGE-$VERSION" ] || abort_package \
881 "$(_ 'Could not download "%s" from "%s". Exiting.' "${TARBALL:-$PACKAGE}" "${WGET_URL:-$WEB_SITE}")"
883 if [ ! -s "$PACKAGE-$VERSION/receipt" ]; then
884 cat > "$PACKAGE-$VERSION/receipt" <<EOT
885 # SliTaz package receipt.
887 PACKAGE="$PACKAGE"
888 VERSION="${VERSION:-unknown}"
889 CATEGORY="${CATEGORY:-non-free}"
890 WEB_SITE="$WEB_SITE"
891 SHORT_DESC="${SHORT_DESC:-$PACKAGE}"
892 MAINTAINER="${MAINTAINER:-nobody@slitaz.org}"
893 EOT
894 for i in LICENSE TARBALL WGET_URL CONFIG_FILES SUGGESTED \
895 PROVIDE DEPENDS HOST_ARCH TAGS EXTRA_SOURCE_FILES ; do
896 eval "[ -n \"\$$i\" ] && echo \"$i=\\\"\$$i\\\"\""
897 done >> "$PACKAGE-$VERSION/receipt"
898 fi
900 DEPENDS="$(unset DEPENDS; . "$PACKAGE-$VERSION/receipt"; echo $DEPENDS)"
901 for i in $(find_depends "$PACKAGE-$VERSION/fs"); do
902 case " $DEPENDS " in
903 *\ $i\ *) continue;;
904 esac
905 grep -q '^DEPENDS="' "$PACKAGE-$VERSION/receipt" ||
906 echo 'DEPENDS=""' >> "$PACKAGE-$VERSION/receipt"
907 sed -i "s/^DEPENDS=\"/&$i /" "$PACKAGE-$VERSION/receipt"
908 done
910 TAZPKG_PACK=gzip
911 tazpkg pack "$PACKAGE-$VERSION"
913 # Clean to save RAM memory before installation
914 rm -rf "$PACKAGE-$VERSION"
916 if [ -n "$get" ]; then
917 mv "$PACKAGE-$VERSION.tazpkg" "$TOP_DIR"
918 else
919 # Install pseudo package
920 tazpkg install "$PACKAGE-$VERSION.tazpkg" --root=$ROOT
921 mv "$PACKAGE-$VERSION.tazpkg" $CACHE_DIR
922 fi
924 # Clean
925 cd "$TOP_DIR"
926 rm -rf $TMP_DIR
927 }
930 # Check for loop in deps tree.
932 check_for_deps_loop() {
933 local list pkg="$1" deps
934 shift
935 [ -n "$1" ] || return
936 list=''
938 # Filter out already processed deps
939 for i in $@; do
940 case " $ALL_DEPS" in
941 *\ $i\ *) ;;
942 *) list="$list $i";;
943 esac
944 done
945 ALL_DEPS="$ALL_DEPS$list "
946 for i in $list; do
947 [ -f $i/receipt ] || continue
948 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
949 case " $deps " in
950 *\ $pkg\ *)
951 print_pkgname
952 echo -e "$MSG $i"; MSG='';;
953 *)
954 check_for_deps_loop $pkg $deps;;
955 esac
956 done
957 }
960 # Check for missing deps listed in a receipt packages.
962 check_for_deps() {
963 local saved;
964 saved="$PACKAGE"
965 mkdir -p $TMP_DIR
966 { cd $TMP_DIR ; cpio --quiet -i receipt >/dev/null 2>&1; } < "$PACKAGE_FILE"
967 . $TMP_DIR/receipt
968 PACKAGE="$saved"
969 rm -rf $TMP_DIR
971 num=0
972 for pkgorg in $DEPENDS; do
973 i=$(equivalent_pkg $pkgorg $1)
974 if [ ! -d "$1$INSTALLED/$i" ]; then
975 MISSING_PACKAGE=$i
976 num=$(($num+1))
977 elif [ ! -f "$1$INSTALLED/$i/receipt" ]; then
978 _ 'WARNING! Dependency loop between "%s" and "%s".' "$PACKAGE" "$i"
979 fi
980 done
982 if [ -n "$MISSING_PACKAGE" ]; then
983 title "$(_ 'Tracking dependencies for package "%s"' "$PACKAGE")"
984 for pkgorg in $DEPENDS; do
985 i=$(equivalent_pkg $pkgorg $1)
986 if [ ! -d "$1$INSTALLED/$i" ]; then
987 MISSING_PACKAGE="$i"
988 _ 'Missing package "%s"' $MISSING_PACKAGE
989 fi
990 done
991 footer "$(_p \
992 '%s missing package to install.' \
993 '%s missing packages to install.' $num \
994 $num)"
995 fi
996 }
999 # Install all missing deps. Auto install or ask user then install all missing
1000 # deps from local dir, CD-ROM, media or from the mirror. In case we want to
1001 # install packages from local, we need a packages.list to find the version.
1003 install_deps() {
1004 local root=''
1005 [ -n "$1" ] && root="--root=$1"
1007 if [ "$AUTO_INSTALL_DEPS" == 'yes' ]; then
1008 answer=0
1009 else
1010 newline
1011 confirm "$(_ 'Install all missing dependencies? (y/N)')"
1012 answer=$?
1013 newline
1014 fi
1016 if [ "$answer" -eq 0 ] && [ -z "$nodeps" ]; then
1017 for pkgorg in $DEPENDS; do
1018 pkg=$(equivalent_pkg $pkgorg $1)
1019 if [ ! -d "$1$INSTALLED/$pkg" ]; then
1020 local list="$INSTALL_LIST"
1021 [ -n "$list" ] || list="$TOP_DIR/packages.list"
1022 # We can install packages from a local dir by greping
1023 # the TAZPKG_BASENAME in the local packages.list.
1024 found='0'
1025 if [ -f "$list" ]; then
1026 _ 'Checking if package "%s" exists in local list...' $pkg
1027 mkdir $TMP_DIR
1028 for i in $pkg-*.tazpkg; do
1029 [ -f $i ] || continue
1030 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $i
1031 [ "$(. $TMP_DIR/receipt; echo "$PACKAGE")" == "$pkg" ] || continue
1032 if grep -q ^$(package_fullname_in_dir $TMP_DIR).tazpkg$ $list
1033 then
1034 found='1'
1035 tazpkg install $i $root --list=$list
1036 break
1037 fi
1038 done
1039 rm -rf $TMP_DIR
1040 fi
1041 # Install deps from the mirror.
1042 if [ $found -eq 0 ]; then
1043 if [ ! -f "$PKGS_DB/packages.list" ]; then
1044 tazpkg recharge
1045 fi
1046 tazpkg get-install $pkg $root
1047 fi
1048 fi
1049 done
1050 else
1051 newline
1052 _ 'Leaving dependencies for package "%s" unresolved.' "$PACKAGE"
1053 _ 'The package is installed but will probably not work.'
1054 newline
1055 fi
1059 # Search pattern in installed packages.
1061 search_in_installed_packages() {
1062 _ 'Installed packages'; separator '-'
1063 num='0'
1064 TMPLIST="$(mktemp)"
1066 awk -F$'\t' -vpattern="$PATTERN" -vt="$TMPLIST" '
1067 BEGIN { IGNORECASE = 1 }
1068 index($1 "-" $2, pattern) {
1069 printf "%-24s%-18s%s\n", $1, $2, $3;
1070 printf "1" >> t
1071 }' "$PKGS_DB/installed.info" | translate_category
1072 num="$(wc -m < $TMPLIST)"; rm $TMPLIST
1074 footer "$(_p \
1075 '%s installed package found for "%s"' \
1076 '%s installed packages found for "%s"' $num \
1077 $num "$PATTERN")"
1081 # Search in packages.list for available pkgs.
1083 search_in_packages_list() {
1084 _ 'Available packages'; separator '-'
1085 num='0'
1086 TMPLIST="$(mktemp)"
1088 for i in $PKGS_DB/packages.info $PKGS_DB/undigest/*/packages.info; do
1089 [ -e "$i" ] && awk -F$'\t' -vpattern="$PATTERN" -vt="$TMPLIST" '
1090 BEGIN { IGNORECASE = 1 }
1091 index($1 "-" $2, pattern) {
1092 printf "%-24s%-18s%s\n", $1, $2, $3;
1093 printf "1" >> t
1094 }' "$i" | translate_category
1095 done
1097 for i in $PKGS_DB/extra.list $PKGS_DB/undigest/*/extra.list; do
1098 [ -e "$i" ] && awk -F'|' -vpattern="$PATTERN" -vt="$TMPLIST" '
1099 BEGIN { IGNORECASE = 1 }
1100 index($1 "-" $5, pattern) {
1101 printf "%-24s%-18s%s\n", $1 " (extra)", $5, $4;
1102 printf "1" >> t
1103 }' "$i" | translate_category
1104 done
1106 if [ ! -f "$PKGS_DB/packages.info" ]; then
1107 newline
1108 longline "$(_ \
1109 "No \"%s\" found to check for mirrored packages. For more results, please run \
1110 \"%s\" once as root before searching." 'packages.info' 'tazpkg recharge')"
1111 newline
1112 fi
1114 num="$(wc -m < $TMPLIST)"; rm $TMPLIST
1115 footer "$(_p \
1116 '%s available package found for "%s"' \
1117 '%s available packages found for "%s"' $num \
1118 $num $PATTERN)"
1122 # search --mirror: Search in packages.txt for available pkgs and give more
1123 # info than --list or default.
1125 search_in_packages_txt() {
1126 _ 'Matching packages name with version and desc'; separator '-'
1127 num='0'
1128 TMPLIST="$(mktemp)"
1130 for i in $PKGS_DB/packages.info $PKGS_DB/undigest/*/packages.info; do
1131 [ -e "$i" ] && awk -F$'\t' -vpattern="$PATTERN" -vt="$TMPLIST" '
1132 BEGIN { IGNORECASE = 1 }
1133 index($1 " " $2 " " $4, pattern) {
1134 split($7, s, " ");
1135 printf "%s\n%s\n%s\n%s (%s installed)\n\n", $1, $2, $4, s[1], s[2];
1136 printf "1" >> t;
1137 }' "$i"
1138 done
1140 if [ ! -f "$PKGS_DB/packages.info" ]; then
1141 newline
1142 longline "$(_ \
1143 "No \"%s\" found to check for mirrored packages. For more results, please run \
1144 \"%s\" once as root before searching." 'packages.info' 'tazpkg recharge')"
1145 newline
1146 fi
1148 num="$(wc -m < $TMPLIST)"; rm $TMPLIST
1149 footer "$(_p \
1150 '%s available package found for "%s"' \
1151 '%s available packages found for "%s"' $num \
1152 $num $PATTERN)"
1156 # Install package-list from a flavor
1158 install_flavor() {
1159 check_root $@
1161 # Get repositories priority list.
1162 look_for_priority
1164 FLAVOR="$1"
1165 mkdir -p $TMP_DIR
1166 [ -f $FLAVOR.flavor ] && cp $FLAVOR.flavor $TMP_DIR
1167 cd $TMP_DIR
1168 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1169 zcat < $FLAVOR.flavor | cpio --quiet -i >/dev/null
1171 while read file; do
1172 for pkg in $(ls -d $INSTALLED/${file%%-*}*); do
1173 [ -f $pkg/receipt ] || continue
1174 EXTRAVERSION=''
1175 . $pkg/receipt
1176 [ "$PACKAGE-$VERSION$EXTRAVERSION" == "$file" ] && break
1177 done
1178 [ "$PACKAGE-$VERSION$EXTRAVERSION" == "$file" ] && continue
1179 cd $CACHE_DIR
1180 download $file.tazpkg
1181 cd $TMP_DIR
1182 tazpkg install $CACHE_DIR/$file.tazpkg --forced
1183 done < $FLAVOR.pkglist
1185 [ -f $FLAVOR.nonfree ] && while read pkg; do
1186 [ -d $INSTALLED/$pkg ] || continue
1187 [ -d $INSTALLED/get-$pkg ] && tazpkg get-install get-$pkg
1188 get-$pkg
1189 done < $FLAVOR.nonfree
1191 # option "--purge"
1192 [ -n "$purge" ] && for pkg in $(ls $INSTALLED); do
1193 [ -f $INSTALLED/$pkg/receipt ] || continue
1194 EXTRAVERSION=''
1195 . $INSTALLED/$pkg/receipt
1196 grep -q "^$PACKAGE-$VERSION$EXTRAVERSION$" $FLAVOR.pkglist && continue
1197 grep -qs "^$PACKAGE$" $FLAVOR.nonfree && continue
1198 tazpkg remove "$PACKAGE"
1199 done
1200 else
1201 _ "Can't find flavor \"%s\". Abort." $FLAVOR
1202 fi
1203 cd "$TOP_DIR"
1204 rm -rf $TMP_DIR
1208 # Update mirror URLs
1210 setup_mirror() {
1211 # Backup old list.
1212 if [ -f "$1/mirror" ]; then
1213 cp -f $1/mirror $1/mirror.bak
1214 fi
1215 title 'Current mirror(s)'
1216 echo " $(cat $1/mirror 2> /dev/null)"
1217 longline "$(_ \
1218 "Please enter URL of the new mirror (http, ftp or local path). You must specify \
1219 the complete address to the directory of the packages and packages.list file.")"
1220 newline
1222 _n 'New mirror(s) URL: '
1223 NEW_MIRROR_URL="$2"
1224 if [ -n "$NEW_MIRROR_URL" ]; then
1225 echo $NEW_MIRROR_URL
1226 else
1227 read NEW_MIRROR_URL
1228 fi
1230 if [ -z "$NEW_MIRROR_URL" ]; then
1231 _ 'Nothing has been changed.'
1232 else
1233 _ 'Setting mirror(s) to: "%s"' $NEW_MIRROR_URL
1234 rm -f $1/mirror
1235 for i in $NEW_MIRROR_URL; do
1236 echo "${i%/}/" >> $1/mirror
1237 done
1238 fi
1239 newline
1243 # recursive dependencies scan
1245 dep_scan() {
1246 for i in $1; do
1247 case " $ALL_DEPS " in
1248 *\ $i\ *) continue;;
1249 esac
1250 ALL_DEPS="$ALL_DEPS $i"
1252 if [ -z "$mark" ]; then
1253 ii="$i"
1254 else
1255 ii="- $i"; grep -q ^$i$'\t' "$PKGS_DB/installed.info" && ii="+ $i"
1256 fi
1257 [ -n "$2" ] && echo "$2$ii ($(awk -F$'\t' -vp="$i" '
1258 $1==p{split($7,s," ");print s[2]}' "$PKGS_DB/packages.info"))"
1260 DEPENDS="$(awk -F$'\t' -vp="$i" '$1==p{print $8 " "}' "$PKGS_DB/installed.info")"
1261 [ -z "$DEPENDS" ] && \
1262 DEPENDS="$(awk -F$'\t' -vp="$i" '$1==p{print $8 " "}' "$PKGS_DB/packages.info")"
1263 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
1264 done
1268 # recursive reverse dependencies scan
1270 rdep_scan() {
1271 SEARCH="$1"
1273 DB='installed'; [ -n "$all" ] && DB='packages'
1275 awk -F$'\t' '$8 {print $1 " " $8}' "$PKGS_DB/$DB.info" | \
1276 busybox awk -F' ' -v search="$SEARCH" '
1277 function show_deps(pkg, space, i, n, mydeps) {
1278 if (processed[pkg]) return
1279 processed[pkg] = 1;
1281 if (space) printf "%s %s\n", space, pkg;
1283 n = split(deps[pkg], mydeps, " ");
1284 for (i = 1; i <= n; i++)
1285 show_deps(mydeps[i], "==" space);
1289 for (i = 2; i <= NF; i++)
1290 deps[$i] = deps[$i] " " $1;
1293 END {
1294 show_deps(search, "")
1296 ' | while read spc pkg; do
1297 if [ -z "$mark" ]; then
1298 pkgi="$pkg"
1299 else
1300 pkgi="- $pkg"; grep -q ^$pkg$'\t' "$PKGS_DB/installed.info" && pkgi="+ $pkg"
1301 fi
1303 echo -n $spc | sed 's/=/ /g'
1305 echo "$pkgi ($(awk -F$'\t' -vp="$pkg" '$1==p{split($7,s," ");print s[2]}' \
1306 "$PKGS_DB/$DB.info"))"
1307 done
1311 update_desktop_database() {
1312 if [ -f "$1/usr/bin/update-desktop-database" ] && [ -n "$updatedesktopdb" ]; then
1313 chroot "$1/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
1314 fi
1318 update_mime_database() {
1319 if [ -f "$1/usr/bin/update-mime-database" ] && [ -n "$updatemimedb" ]; then
1320 chroot "$1/" /usr/bin/update-mime-database /usr/share/mime
1321 fi
1325 update_icon_database() {
1326 if [ -f "$1/usr/bin/gtk-update-icon-cache" ] && [ -n "$updateicondb" ]; then
1327 chroot "$1/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
1328 fi
1332 compile_glib_schemas() {
1333 if [ -f "$1/usr/bin/glib-compile-schemas" ] && [ -n "$compile_schemas" ]; then
1334 chroot "$1/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
1335 fi
1339 update_kernel_modules() {
1340 if [ -f "$1/sbin/depmod" ] && [ -n "$updatedepmod" ]; then
1341 chroot "$1/" /sbin/depmod -a
1342 fi
1346 # Print package name if not printed yet
1347 print_pkgname() {
1348 if [ "$PACKAGE" != "$PACKAGE_PRINTED" ]; then
1349 [ -n "$PACKAGE_PRINTED" ] && footer
1350 title 'Package %s' "$PACKAGE-$VERSION$EXTRAVERSION"
1351 PACKAGE_PRINTED="$PACKAGE"
1352 fi
1357 ###################
1358 # TazPkg commands #
1359 ###################
1361 case "$COMMAND" in
1362 list|-l)
1363 # Various lists
1364 shift
1365 case $1 in
1366 b|blocked) @@MODULES@@/list blocked ;;
1367 c|cat|categories) @@MODULES@@/list categories;;
1368 l|linked) @@MODULES@@/list linked ;;
1369 '') check_for_installed_info
1370 @@MODULES@@/list installed ;;
1371 *) check_for_installed_info
1372 @@MODULES@@/list installed_of_category "$@";;
1373 esac
1374 ;;
1375 -lb) @@MODULES@@/list blocked ;;
1376 -lc) @@MODULES@@/list categories;;
1377 -ll) @@MODULES@@/list linked ;;
1379 -lm|list-mirror) @@MODULES@@/list mirrored ;;
1380 -lf|list-files) check_for_package_on_cmdline
1381 @@MODULES@@/list installed_files $PACKAGE;;
1382 -a|activity|log) @@MODULES@@/list activity ;;
1383 list-config) @@MODULES@@/list config_files $2;;
1384 list-suggested) @@MODULES@@/list suggested ;;
1387 info)
1388 # Information about package
1389 check_for_package_on_cmdline
1390 @@MODULES@@/info "$2"
1391 ;;
1394 desc|-d)
1395 # Display package description
1396 unset desc
1398 # 1) Localized description
1399 for LC in $LANG ${LANG%_*}; do
1400 [ -e "$PKGS_DB/descriptions.$LC.txt" ] &&
1401 desc="$(awk -vRS='' -vFS='\n' -vOFS='\n' -vp="$PACKAGE" '
1402 $1 == p { $1 = ""; print $0; exit; }
1403 ' "$PKGS_DB/descriptions.$LC.txt" | sed '1d')"
1404 done
1406 # 2) Installed description
1407 if [ -z "$desc" -a -s "$INSTALLED/$PACKAGE/description.txt" ]; then
1408 desc="$(cat "$INSTALLED/$PACKAGE/description.txt")"
1409 fi
1411 # 3) Mirrored description
1412 if [ -z "$desc" -a -s "$PKGS_DB/descriptions.txt" ]; then
1413 desc="$(awk -vRS='' -vFS='\n' -vOFS='\n' -vp="$PACKAGE" '
1414 $1 == p { $1 = ""; print $0; exit; }
1415 ' "$PKGS_DB/descriptions.txt" | sed '1d')"
1416 fi
1418 # 4) Short description only in terminal
1419 if [ -z "$desc" ] && im; then
1420 desc="$(print_short_description "$PACKAGE")"
1421 fi
1423 if [ -n "$desc" ]; then
1424 # Title and footer only in terminal
1425 im && title 'Description of package "%s"' "$PACKAGE"
1426 echo "$desc"
1427 im && footer
1428 else
1429 im && _ 'Description absent.'
1430 fi
1431 ;;
1434 search|-s)
1435 # Search for a package by pattern or name.
1436 PATTERN="$2"
1437 if [ -z "$PATTERN" ]; then tazpkg -h search; exit 1; fi
1439 title 'Search result for "%s"' "$PATTERN"
1440 # Default is to search in installed pkgs and the raw list.
1441 case "$3" in
1442 -i) installed='yes';;
1443 -l) list='yes';;
1444 -m) mirror='yes';;
1445 esac
1447 [ -n "$installed" ] && search_in_installed_packages
1448 [ -n "$list" ] && search_in_packages_list
1449 [ -n "$mirror" ] && search_in_packages_txt
1450 if [ -z "$installed$list$mirror" ]; then
1451 search_in_installed_packages
1452 search_in_packages_list
1453 fi
1454 ;;
1457 search-file|-sf)
1458 # Search for a file by pattern or name in all files.list.
1459 if [ -z "$2" ]; then
1460 newline
1461 _ 'Please specify a pattern or file name to search for.'
1462 echo "$(_ 'Example:') 'tazpkg search-file libnss'"
1463 newline
1464 exit 0
1465 fi
1466 title 'Search result for file "%s"' "$2"
1467 TMPLIST=$(mktemp)
1469 if [ -n "$mirror" ]; then
1470 TMPDIR=$(mktemp -d)
1471 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1472 [ -f $i ] || continue
1473 lzcat $i | awk -F: -vtmp="$TMPLIST" -vdir="$TMPDIR" \
1474 -vfile="$2" -vcfile="$(colorize 32 $2)" '
1475 BEGIN { efile = gensub("\+", "\\\+", "g", file); }
1476 index($2, file) {
1477 gsub(efile, cfile, $2);
1478 print $2 >> dir"/"$1;
1479 printf "1" >> tmp;
1480 }'
1481 done
1483 for pkg in $(cd $TMPDIR; ls); do
1484 newline
1485 emsg "<c 33>$(_ 'Package %s:' $pkg)</c>"
1486 cat $TMPDIR/$pkg
1487 done
1489 rm -r $TMPDIR
1491 else
1493 # Check all pkg files.list in search match which specify the package
1494 # name and the full path to the file(s).
1495 for pkg in $INSTALLED/*; do
1496 if grep -qs "$2" $pkg/files.list; then
1497 . $pkg/receipt
1498 newline
1499 emsg "<c 33>$(_ 'Package %s:' "$PACKAGE")</c>"
1500 awk -vtmp="$TMPLIST" -vfile="$2" -vcfile="$(colorize 32 $2)" '
1501 BEGIN { efile = gensub("\+", "\\\+", "g", file); }
1502 index($0, file) {
1503 gsub(efile, cfile);
1504 print " "$0;
1505 printf "1" >> tmp;
1507 ' $pkg/files.list
1508 fi
1509 done
1511 fi
1513 num=$(wc -m < $TMPLIST); rm $TMPLIST
1514 footer "$(_p '%s file' '%s files' "$num" \
1515 "$(colorize 32 $num)")"
1516 ;;
1519 search-pkgname|-sp)
1520 # Search for a package name
1521 if [ -z "$2" ]; then
1522 newline
1523 _ 'Please specify a pattern or file name to search for.'
1524 echo "$(_ 'Example:') 'tazpkg search-pkgname libnss'"
1525 newline
1526 exit 0
1527 fi
1528 title 'Search result for package "%s"' "$2"
1530 # Search for a file on mirror and output only the package name
1531 TMPLIST=$(mktemp)
1532 for i in $PKGS_DB/files.list.lzma $PKGS_DB/undigest/*/files.list.lzma; do
1533 [ -f "$i" ] || continue
1534 lzcat $i | awk -F: -vT=$TMPLIST -vterm="$2" '
1535 BEGIN { P = "" }
1536 index($2, term) {
1537 if ($1 != P) {
1538 print $1;
1539 printf "1" >> T;
1540 P = $1
1542 }'
1543 done
1544 match=$(wc -m < $TMPLIST)
1545 rm $TMPLIST
1547 footer "$(emsg "$(_p \
1548 '%s package' '%s packages' $match \
1549 "<c 32>$match</c>")")"
1550 ;;
1553 install|-i)
1554 # Install .tazpkg packages.
1555 check_root $@
1556 check_for_package_on_cmdline
1557 check_for_package_file
1558 check_for_installed_info
1560 if [ -n "$root" ]; then
1561 ROOT="$root";
1562 check_base_dir "$root"
1563 fi
1565 [ -n "$list" ] && INSTALL_LIST="$list"
1567 if [ -n "$rootconfig" ]; then # What about this parameter? Is it obsolete?
1568 if [ -n "$root" ]; then
1569 CACHE_DIR="$root/$CACHE_DIR"
1570 SAVE_CACHE_DIR="$CACHE_DIR"
1571 PKGS_DB="$root/$PKGS_DB"
1572 else
1573 echo "rootconfig needs --root= option used." >&2
1574 exit 1
1575 fi
1576 fi
1578 # Get repositories priority list.
1579 look_for_priority
1581 # Check if forced install.
1582 if [ -z "$forced" ]; then
1583 check_for_installed_package $ROOT
1584 fi
1585 install_package $ROOT
1586 update_desktop_database $ROOT
1587 update_mime_database $ROOT
1588 update_icon_database $ROOT
1589 compile_glib_schemas $ROOT
1590 ;;
1593 install-list|get-install-list)
1594 # Install a set of packages from a list.
1595 check_root $@
1597 if [ -z "$2" ]; then
1598 newline
1599 longline "$(_ \
1600 "Please change directory (cd) to the packages repository and specify the \
1601 list of packages to install.")"
1602 echo "$(_ 'Example:') $(emsg '<b>tazpkg install-list</b> <c 33>packages.list</c>')"
1603 exit 0
1604 fi
1606 # Check if the packages list exist.
1607 if [ ! -f "$2" ]; then
1608 _ 'Unable to find list "%s"' "$2"
1609 exit 0
1610 fi
1612 LIST=$(cat $2)
1614 # Remember processed list
1615 export INSTALL_LIST="$2"
1617 # Set $COMMAND and install all packages.
1618 COMMAND=${1%-list}
1620 touch $2-processed
1622 # Upgrade tazpkg first. It may handle new features/formats...
1623 # then upgrade essential packages early
1624 for pkg in busybox-pam busybox gcc-lib-base glibc-base \
1625 slitaz-base-files tazpkg ; do
1626 pkg=$(egrep $pkg-[0-9] $INSTALL_LIST)
1627 [ -z "$pkg" ] && continue
1628 _ 'Adding implicit depends "%s"...' $pkg
1629 LIST="$pkg"$'\n'"$LIST"
1630 done
1632 for pkg in $LIST; do
1633 grep -qs ^$pkg$ $2-processed && continue
1634 [ -d "$root/var/lib/tazpkg/installed" ] &&
1635 tazpkg $COMMAND $pkg --list="$2" "$3" "$4" "$5"
1636 done
1637 rm -f $2-processed ;;
1640 add-flavor)
1641 # Install a set of packages from a flavor.
1642 install_flavor $2 ;;
1645 install-flavor)
1646 # Install a set of packages from a flavor and purge other ones.
1647 install_flavor $2 --purge ;;
1650 set-release)
1651 # Change current release and upgrade packages.
1652 RELEASE="$2"
1653 if [ -z "$RELEASE" ]; then
1654 newline
1655 _ 'Please specify the release you want on the command line.'
1656 echo "$(_ 'Example:') tazpkg set-release cooking"
1657 newline
1658 exit 0
1659 fi
1660 rm $PKGS_DB/mirror
1661 echo "$RELEASE" > /etc/slitaz-release
1662 tazpkg recharge && tazpkg upgrade
1664 # Install missing depends
1665 cd $INSTALLED
1666 for i in * ; do
1667 DEPENDS=''
1668 . $i/receipt
1669 for j in $DEPENDS ; do
1670 [ -d $j ] || tazpkg get-install $j
1671 done
1672 done ;;
1675 remove|-r)
1676 # Remove packages.
1677 check_root $@
1678 check_for_package_on_cmdline
1679 check_for_installed_info
1681 [ -n "$root" ] && ROOT="$root"
1683 if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then
1684 newline; _ 'Package "%s" is not installed.' "$PACKAGE"
1685 exit 0
1686 fi
1688 . "$ROOT$INSTALLED/$PACKAGE/receipt"
1690 # Info #1: dependent packages (to be processed later)
1691 ALTERED="$(awk -F$'\t' -vp=" $PACKAGE " '
1692 index(" " $8 " ", p) { printf " %s\n", $1 }
1693 ' $ROOT/$PKGS_DB/installed.info)"
1695 if [ -n "$ALTERED" ]; then
1696 _ 'The following packages depend on package "%s":' "$PACKAGE"
1697 echo "$ALTERED"
1698 fi
1700 # Info #2: changed packages (to be processed later)
1701 REFRESH=$(cd $ROOT$INSTALLED ; grep -sl "^$PACKAGE$" */modifiers)
1703 if [ -n "$REFRESH" ]; then
1704 _ 'The following packages have been modified by package "%s":' "$PACKAGE"
1705 for i in $REFRESH; do
1706 echo " ${i%/modifiers}"
1707 done
1708 fi
1710 # Confirmation
1711 if im && [ -z "$auto" ]; then
1712 confirm "$(_ 'Remove package "%s" (%s)? (y/N)' "$PACKAGE" "$VERSION$EXTRAVERSION")"
1713 if [ "$?" -ne 0 ]; then
1714 newline; _ 'Uninstallation of package "%s" cancelled.' "$PACKAGE"
1715 exit 0
1716 fi
1717 fi
1718 # We are here: non-interactive mode, or --auto, or answer 'y'
1720 # Removing package
1721 title 'Removing package "%s"' "$PACKAGE"
1723 # [1/4] Pre-remove commands
1724 if grep -q ^pre_remove "$ROOT$INSTALLED/$PACKAGE/receipt"; then
1725 action "Execution of pre-remove commands..."
1726 pre_remove $ROOT
1727 status
1728 fi
1730 # [2/4] Removing files
1731 action "Removing all files installed..."
1732 if [ -f "$ROOT$INSTALLED/$PACKAGE/modifiers" ]; then
1733 for file in $(cat "$ROOT$INSTALLED/$PACKAGE/files.list"); do
1734 for mod in $(cat "$ROOT$INSTALLED/$PACKAGE/modifiers"); do
1735 [ -f "$ROOT$INSTALLED/$mod/files.list" ] && \
1736 [ $(grep "^$(echo $file | grepesc)$" $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && \
1737 continue 2
1738 done
1739 remove_with_path $ROOT$file
1740 done
1741 else
1742 for file in $(cat "$ROOT$INSTALLED/$PACKAGE/files.list"); do
1743 remove_with_path $ROOT$file
1744 done
1745 fi
1746 status
1748 # [3/4] Post-remove commands
1749 if grep -q ^post_remove "$ROOT$INSTALLED/$PACKAGE/receipt"; then
1750 action 'Execution of post-remove commands...'
1751 post_remove $ROOT
1752 status
1753 fi
1755 # [4/4] Remove package receipt and remove it from databases
1756 action 'Removing package receipt...'
1757 rm -rf "$ROOT$INSTALLED/$PACKAGE"
1758 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg$/d" $PKGS_DB/installed.$SUM
1759 sed -i "/^$PACKAGE /d" $PKGS_DB/installed.info
1760 status
1762 footer "$(_ 'Package "%s" (%s) removed.' "$PACKAGE" "$VERSION$EXTRAVERSION")"
1764 # Log this activity
1765 log_pkg Removed
1767 # Stop if non-interactive mode and no --auto option
1768 if ! im && [ -z "$auto" ]; then exit 0; fi
1770 # Process dependent packages
1771 if [ -n "$ALTERED" ]; then
1772 if [ -n "$auto" ]; then
1773 answer=0
1774 else
1775 confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' "$PACKAGE")"
1776 answer=$?
1777 fi
1778 if [ "$answer" -eq 0 ]; then
1779 for i in $ALTERED; do
1780 if [ -d "$ROOT$INSTALLED/$i" ]; then
1781 echo "tazpkg remove $i $ROOTOPTS"
1782 fi
1783 done
1784 fi
1785 fi
1787 # Process changed packages
1788 if [ -n "$REFRESH" ]; then
1789 if [ -n "$auto" ]; then
1790 answer=0
1791 else
1792 confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' "$PACKAGE")"
1793 answer=$?
1794 fi
1795 if [ "$answer" -eq 0 ]; then
1796 for i in $REFRESH; do
1797 if [ "$(wc -l < $ROOT$INSTALLED/$i)" -gt 1 ]; then
1798 _ 'Check %s for reinstallation' "$INSTALLED/$i"
1799 continue
1800 fi
1801 rm -r $ROOT$INSTALLED/$i
1802 tazpkg get-install ${i%/modifiers} $ROOTOPTS --forced
1803 done
1804 fi
1805 fi
1807 ;;
1810 extract|-e)
1811 # Extract .tazpkg cpio archive into a directory.
1812 check_for_package_on_cmdline
1813 check_for_package_file
1814 title 'Extracting package "%s"' "$PACKAGE"
1816 # If no directory destination is found on the cmdline
1817 # we create one in the current dir using the package name.
1818 if [ -n "$TARGET_DIR" ]; then
1819 DESTDIR="$TARGET_DIR/$PACKAGE"
1820 else
1821 DESTDIR="$PACKAGE"
1822 fi
1823 mkdir -p $DESTDIR
1825 action 'Copying original package...'
1826 cp "$PACKAGE_FILE" $DESTDIR
1827 status
1829 cd $DESTDIR
1830 extract_package
1831 [ -e "receipt" ] && \
1832 footer "$(_ 'Package "%s" is extracted to "%s"' "$PACKAGE" "$DESTDIR")"
1833 ;;
1836 recompress)
1837 # Recompress .tazpkg cpio archive with lzma.
1838 check_for_package_on_cmdline
1839 check_for_package_file
1840 title 'Recompressing package "%s"' "$PACKAGE"
1841 mkdir -p $TMP_DIR
1843 action "Copying original package..."
1844 cp "$PACKAGE_FILE" $TMP_DIR
1845 status
1847 cd $TMP_DIR
1848 extract_package
1850 action "Recompressing the FS..."
1851 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1852 rm -rf fs
1853 status
1855 action "Creating new package..."
1856 find . -print | cpio -o -H newc --quiet > \
1857 "$TOP_DIR/$(basename "$PACKAGE_FILE").$$" && mv -f \
1858 "$TOP_DIR/$(basename "$PACKAGE_FILE").$$" \
1859 "$TOP_DIR/$(basename "$PACKAGE_FILE")"
1860 status
1862 cd "$TOP_DIR"
1863 rm -rf $TMP_DIR
1864 separator; newline ;;
1867 repack-config)
1868 check_root $@
1869 # Create SliTaz package archive from configuration files.
1870 mkdir -p $TMP_DIR; cd $TMP_DIR
1871 CONFIG_VERSION='1.0'
1872 mkdir config-$CONFIG_VERSION
1873 cd config-$CONFIG_VERSION
1874 for i in $INSTALLED/*/volatile.cpio.gz; do
1875 zcat $i | cpio -t --quiet
1876 done > files.list
1877 mkdir fs
1878 cd fs
1879 ( cd / ; cpio -o -H newc --quiet ) < ../files.list | cpio -idm --quiet > /dev/null
1880 mkdir -p etc/tazlito
1881 for i in $INSTALLED/*/receipt; do
1882 EXTRAVERSION=''
1883 . $i
1884 echo "$PACKAGE-$VERSION$EXTRAVERSION"
1885 done > etc/tazlito/config-packages.list
1886 cd ..
1887 echo "etc/tazlito/config-packages.list" >> files.list
1888 pkg_date=$(date +"%x %X")
1889 cat > receipt <<EOT
1890 # SliTaz package receipt.
1892 PACKAGE="config"
1893 VERSION="$CONFIG_VERSION"
1894 CATEGORY="base-system"
1895 SHORT_DESC="$(_n 'User configuration backup on date %s' "$pkg_date")"
1896 DEPENDS="$(ls $INSTALLED)"
1897 EOT
1898 cd ..
1899 tazpkg pack config-$CONFIG_VERSION
1900 cp config-$CONFIG_VERSION.tazpkg "$TOP_DIR"
1901 cd "$TOP_DIR"
1902 rm -rf $TMP_DIR
1903 ;;
1906 repack)
1907 # Create SliTaz package archive from an installed package.
1908 check_for_package_on_cmdline
1909 check_for_receipt
1910 EXTRAVERSION=''
1911 . "$INSTALLED/$PACKAGE/receipt"
1912 title 'Repacking "%s"' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
1914 if grep -qs ^NO_REPACK= "$INSTALLED/$PACKAGE/receipt"; then
1915 _ "Can't repack package \"%s\"" "$PACKAGE"
1916 exit 1
1917 fi
1919 if [ -s "$INSTALLED/$PACKAGE/modifiers" ]; then
1920 _ "Can't repack, \"%s\" files have been modified by:" "$PACKAGE"
1921 for i in $(cat "$INSTALLED/$PACKAGE/modifiers"); do
1922 echo " $i"
1923 done
1924 exit 1
1925 fi
1927 MISSING=''
1928 while read i; do
1929 [ -e "$i" ] && continue
1930 [ -L "$i" ] || MISSING="$MISSING\n $i"
1931 done < "$INSTALLED/$PACKAGE/files.list"
1932 if [ -n "$MISSING" ]; then
1933 _n "Can't repack, the following files are lost:"
1934 echo -e "$MISSING"
1935 exit 1
1936 fi
1938 mkdir -p $TMP_DIR; cd $TMP_DIR
1939 FILES="fs.cpio.lzma\n"
1940 for i in $(ls "$INSTALLED/$PACKAGE"); do
1941 case $i in
1942 volatile.cpio.gz|modifiers) ;;
1943 *) cp "$INSTALLED/$PACKAGE/$i" .; FILES="$FILES$i\n" ;;
1944 esac
1945 done
1947 ln -s / rootfs
1948 mkdir tmp
1949 sed 's/^/rootfs/' < files.list | cpio -o -H newc --quiet | \
1950 { cd tmp ; cpio -idm --quiet >/dev/null; cd ..; }
1951 mv tmp/rootfs fs
1953 if [ -f "$INSTALLED/$PACKAGE/volatile.cpio.gz" ]; then
1954 zcat "$INSTALLED/$PACKAGE/volatile.cpio.gz" | \
1955 { cd fs; cpio -idm --quiet; cd ..; }
1956 fi
1958 if fgrep -q repack_cleanup "$INSTALLED/$PACKAGE/receipt"; then
1959 . "$INSTALLED/$PACKAGE/receipt"
1960 repack_cleanup fs
1961 fi
1963 if [ -f "$INSTALLED/$PACKAGE/$CHECKSUM" ]; then
1964 sed 's, , fs,' < "$INSTALLED/$PACKAGE/$CHECKSUM" | \
1965 $CHECKSUM -s -c || {
1966 _ "Can't repack, %s error." "$CHECKSUM"
1967 cd "$TOP_DIR"
1968 rm -rf $TMP_DIR
1969 exit 1
1971 fi
1973 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1974 echo -e "$FILES" | cpio -o -H newc --quiet > \
1975 "$TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
1976 cd "$TOP_DIR"
1977 \rm -R $TMP_DIR
1978 _ 'Package "%s" repacked successfully.' "$PACKAGE"
1979 _ 'Size: %s' "$(du -sh "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1980 newline
1981 ;;
1984 pack)
1985 # Create SliTaz package archive using cpio and lzma.
1986 # TODO: Cook also pack packages, we should share code in libpkg.sh
1987 check_for_package_on_cmdline
1988 cd "$PACKAGE"
1989 if [ ! -f 'receipt' ]; then
1990 _ 'Receipt is missing. Please read the documentation.'
1991 exit 0
1992 fi
1994 title 'Packing package "%s"' "$PACKAGE"
1995 # Create files.list with redirecting find outpout.
1997 action 'Creating the list of files...'
1998 cd fs
1999 find . -type f -print > ../files.list
2000 find . -type l -print >> ../files.list
2001 cd ..; sed -i s/'^.'/''/ files.list
2002 status
2004 action 'Creating %s of files...' "$CHECKSUM"
2005 while read file; do
2006 [ -L "fs$file" ] && continue
2007 [ -f "fs$file" ] || continue
2008 case "$file" in
2009 /lib/modules/*/modules.*|*.pyc) continue;;
2010 esac
2011 $CHECKSUM "fs$file" | sed 's/ fs/ /'
2012 done < files.list > $CHECKSUM
2013 status
2015 UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
2016 description.txt 2>/dev/null | awk 'END { print $1 }')
2018 # Build cpio archives.
2019 action "Compressing the FS..."
2020 find fs | cpio -o -H newc --quiet | case "$TAZPKG_PACK" in
2021 gzip) gzip -9 > fs.cpio.gz ;;
2022 *) lzma e fs.cpio.lzma -si ;;
2023 esac
2024 rm -rf fs
2025 status
2027 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
2028 $CHECKSUM description.txt 2>/dev/null | awk 'END { print $1 }')
2030 action "Updating receipt sizes..."
2031 sed -i s/^PACKED_SIZE.*$// receipt
2032 sed -i s/^UNPACKED_SIZE.*$// receipt
2033 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
2034 status
2036 action "Creating full cpio archive..."
2037 find . -print | cpio -o -H newc --quiet > "../$PACKAGE.tazpkg"
2038 status
2040 action "Restoring original package tree..."
2041 unlzma < fs.cpio.lzma | cpio -idm --quiet
2042 status
2044 rm fs.cpio.lzma && cd ..
2045 footer "$(_ 'Package "%s" compressed successfully.' "$PACKAGE")"
2046 _ 'Size: %s' "$(ls -lh "$PACKAGE.tazpkg" | awk '{print $5}')"
2047 ;;
2050 recharge)
2051 # Recharge packages databases from a mirror.
2053 # WARNING: The 'mirrors' file has all SliTaz mirrors but 'mirror'
2054 # must have only the chosen main mirror.
2056 check_root $@
2057 @@MODULES@@/recharge $2
2058 ;;
2061 help-up)
2062 # Options available for the command: up
2063 newline; usage_up; newline
2064 exit 1 ;;
2067 up|upgrade)
2068 check_root $@
2070 # This is the new way to upgrade packages making 'upgrade' and
2071 # upgradeable out-of-date. This new way is much, much more faster!
2072 # Look into installed packages and get data from receipt, it is fast
2073 # and easy to handle vars after using only md5sum to compare packages
2075 for opt in $@; do
2076 case "$opt" in
2077 -i) export install='yes';;
2078 -c) export check='yes';;
2079 esac
2080 done
2082 @@MODULES@@/upgrade
2083 ;;
2086 bugs)
2087 # Show known bugs in package(s)
2088 cd $INSTALLED
2089 shift
2090 LIST=$@
2091 [ -z "$LIST" ] && LIST=$(ls)
2092 MSG=$(_n 'No known bugs.')
2094 title 'Known bugs in packages'
2095 for PACKAGE in $LIST; do
2096 BUGS=''
2097 EXTRAVERSION=''
2098 . "$PACKAGE/receipt"
2099 if [ -n "$BUGS" ]; then
2100 MSG=$(_n 'Bug list completed')
2101 newline
2102 _ 'Bugs in package "%s" version %s:' "$PACKAGE" "$VERSION$EXTRAVERSION"
2103 cat <<EOT
2104 $BUGS
2105 EOT
2106 fi
2107 done
2108 footer "$MSG" ;;
2111 check)
2112 # Check installed packages set.
2113 #check_root $@
2115 # Get repositories priority list.
2116 look_for_priority
2118 cd $INSTALLED
2119 if [ -z "$2" -o -n "$full" ]; then PACKAGES="$(ls)"; else PACKAGES="$2"; fi
2120 PACKAGE_PRINTED=''
2122 for PACKAGE in $PACKAGES; do
2124 if [ ! -f "$PACKAGE/receipt" ]; then
2125 print_pkgname
2126 _ 'The package installation has not completed'
2127 continue
2128 fi
2130 DEPENDS=''
2131 EXTRAVERSION=''
2132 . "$PACKAGE/receipt"
2133 if [ -s "$PACKAGE/modifiers" ]; then
2134 print_pkgname
2135 _ 'The package has been modified by:'
2136 awk '{print " " $0}' "$PACKAGE/modifiers"
2137 fi
2139 MSG="$(_n 'Files lost from package:')\n"
2140 while read file; do
2141 [ -e "$file" ] && continue
2142 if [ -L "$file" ]; then
2143 MSG="$MSG $(_n 'target of symlink')"
2144 fi
2145 print_pkgname
2146 echo -e "$MSG $file"
2147 MSG=''
2148 done < "$PACKAGE/files.list"
2150 MSG="$(_n 'Missing dependencies for package:')\n"
2151 for i in $DEPENDS; do
2152 [ -d $i ] && continue
2153 [ -d $(equivalent_pkg $i) ] && continue
2154 print_pkgname
2155 echo -e "$MSG $i"
2156 MSG=''
2157 done
2159 MSG="$(_n 'Dependencies loop between package and:')\n"
2160 ALL_DEPS=''
2161 check_for_deps_loop "$PACKAGE" "$DEPENDS"
2162 done
2163 [ -n "$PACKAGE_PRINTED" ] && footer
2165 _ 'Looking for known bugs...'
2166 if [ -z "$2" -o -n "$full" ]; then tazpkg bugs; else tazpkg bugs "$2"; fi
2169 if [ -n "$full" ]; then
2170 separator
2172 title 'Mismatch checksum of installed files:'
2174 for PACKAGE in $PACKAGES; do
2175 file="$PACKAGE/$CHECKSUM"
2176 CONFIG_FILES=''
2177 . "$PACKAGE/receipt"
2178 [ -s "$file" ] || continue
2179 while read md5 f; do
2180 [ -f $f ] || continue
2181 for i in $CONFIG_FILES; do
2182 case "$f" in
2183 $i|$i/*) continue 2;;
2184 esac
2185 done
2186 echo "$md5 $f"
2187 done < "$file" | busybox $CHECKSUM -c - 2>/dev/null | \
2188 grep -v OK$ | sed "s/: FAILED$//"
2189 done
2190 footer
2192 title 'Check file providers:'
2193 FILES=' '
2194 for PACKAGE in $PACKAGES; do
2195 for file in $(cat "$PACKAGE/files.list"); do
2196 [ -d "$file" ] && continue
2197 case "$FILES" in
2198 *\ $file\ *) continue;;
2199 esac
2200 [ $(grep "^$(echo $file | grepesc)$" */files.list 2> /dev/null | \
2201 wc -l) -gt 1 ] || continue
2202 FILES="$FILES$file "
2203 newline
2204 _ 'The following packages provide file "%s":' $file
2205 grep -l "^$(echo $file | grepesc)$" */files.list | \
2206 while read f; do
2207 pkg=${f%/files.list}
2208 if [ -f $pkg/modifiers ]; then
2209 overriders=$(_n '(overridden by %s)' "$(tr '\n' ' ' < $pkg/modifiers | sed 's| $||')")
2210 else
2211 overriders=''
2212 fi
2213 echo -n " * $pkg $overriders"
2214 newline
2215 done
2216 done
2217 done
2218 footer
2220 if [ -n "$full" ]; then
2221 title 'Alien files:'
2222 MSG="$(_n 'No package has installed the following files:')\n"
2223 find /etc /bin /sbin /lib /usr /var/www -not -type d 2>/dev/null | \
2224 while read file; do
2225 case "$file" in *\[*) continue;; esac
2226 grep -q "^$(echo $file | grepesc)$" */files.list && continue
2227 echo -e "$MSG $file"
2228 MSG=''
2229 done
2230 footer
2231 fi
2232 fi
2233 _ 'Check completed.'; newline ;;
2236 block|-b)
2237 # Add a pkg name to the list of blocked packages.
2238 check_root $@
2239 check_for_package_on_cmdline
2240 newline
2241 if [ ! -d "$INSTALLED/$PACKAGE" ]; then
2242 _ 'Package "%s" is not installed.' "$PACKAGE"; exit
2243 fi
2244 if grep -qs "^$PACKAGE" $BLOCKED; then
2245 _ 'Package "%s" is already blocked.' "$PACKAGE"
2246 else
2247 echo "$PACKAGE" >> $BLOCKED
2248 # Log this activity
2249 . "$INSTALLED/$PACKAGE/receipt"; log_pkg Blocked
2250 _ 'Package "%s" blocked.' "$PACKAGE"
2251 fi
2252 newline
2253 ;;
2256 unblock|-u)
2257 # Remove a pkg name from the list of blocked packages.
2258 check_root $@
2259 check_for_package_on_cmdline
2260 newline
2261 if [ ! -d "$INSTALLED/$PACKAGE" ]; then
2262 _ 'Package "%s" is not installed.' "$PACKAGE"; exit
2263 fi
2264 if grep -qs "^$PACKAGE" $BLOCKED; then
2265 sed -i "/^$PACKAGE\$/d" $BLOCKED
2266 # Log this activity
2267 . "$INSTALLED/$PACKAGE/receipt"; log_pkg Unblocked
2268 _ 'Package "%s" unblocked.' "$PACKAGE"
2269 else
2270 _ 'Package "%s" is not blocked.' "$PACKAGE"
2271 fi
2272 newline
2273 ;;
2276 chblock)
2277 # Change package's blocked status.
2278 check_root $@
2279 check_for_package_on_cmdline
2280 newline
2281 if [ ! -d "$INSTALLED/$PACKAGE" ]; then
2282 _ 'Package "%s" is not installed.' "$PACKAGE"; exit
2283 fi
2284 if grep -qs "^$PACKAGE" $BLOCKED; then
2285 sed -i "/^$PACKAGE\$/d" $BLOCKED
2286 # Log this activity
2287 . "$INSTALLED/$PACKAGE/receipt"; log_pkg Unblocked
2288 _ 'Package "%s" unblocked.' "$PACKAGE"
2289 else
2290 echo "$PACKAGE" >> $BLOCKED
2291 # Log this activity
2292 . "$INSTALLED/$PACKAGE/receipt"; log_pkg Blocked
2293 _ 'Package "%s" blocked.' "$PACKAGE"
2294 fi
2295 newline
2296 ;;
2299 get|-g)
2300 # Download a package with wget.
2301 check_root $@
2302 check_for_package_on_cmdline
2303 check_for_packages_list
2305 [ -n "$root" ] && ROOT="$root" && check_base_dir "$root"
2306 if [ -n "$rootconfig" ]; then
2307 if [ -n "$root" ]; then
2308 CACHE_DIR="$root/$CACHE_DIR"
2309 SAVE_CACHE_DIR="$CACHE_DIR"
2310 PKGS_DB="$root/$PKGS_DB"
2311 else
2312 _ 'rootconfig needs --root= option used.' >&2
2313 exit 1
2314 fi
2315 fi
2317 # Get repositories priority list.
2318 look_for_priority
2320 CURRENT_DIR="$PWD"
2321 cd "$CACHE_DIR"
2322 if check_for_package_in_list check ; then
2323 cd "$CACHE_DIR"
2324 if [ -f "$PACKAGE.tazpkg" ]; then
2325 _ 'Package "%s" already in the cache' "$PACKAGE"
2326 # Check package download was finished
2327 tail -c 2k "$PACKAGE.tazpkg" | fgrep -q '00000000TRAILER' || {
2328 _ 'Continuing package "%s" download' "$PACKAGE"
2329 download "$PACKAGE.tazpkg"
2331 if [ "$($CHECKSUM "$PACKAGE.tazpkg")" != \
2332 "$(fgrep " $PACKAGE.tazpkg" "$rep/packages.$SUM")" ]; then
2333 rm -f "$PACKAGE.tazpkg"
2334 download "$PACKAGE.tazpkg"
2335 fi
2336 else
2337 download "$PACKAGE.tazpkg"
2338 fi
2339 PACKAGE_FILE="$CACHE_DIR/$PACKAGE.tazpkg"
2340 elif download_get_script "$PACKAGE" "/tmp/$PACKAGE.$$" ; then
2341 install_package_from_get_script "/tmp/$PACKAGE.$$" "$ROOT" --get
2342 PACKAGE_FILE="$(ls "$PWD/$PACKAGE-*.tazpkg")"
2343 fi
2344 [ "$PWD" != "$CURRENT_DIR" ] &&
2345 cp -a "$PACKAGE_FILE" "$CURRENT_DIR"
2346 ;;
2349 get-install|-gi)
2350 # Download and install a package.
2351 check_root $@
2352 check_for_package_on_cmdline
2353 check_for_packages_list
2355 DO_CHECK=''
2356 [ -n "$forced" ] && DO_CHECK='no'
2357 [ -n "$root" ] && ROOT="$root" && check_base_dir "$root"
2358 [ -n "$list" ] && INSTALL_LIST="$list" # internal option
2360 if [ -n "$rootconfig" ]; then # outdated?
2361 if [ -n "$root" ]; then
2362 CACHE_DIR="$root/$CACHE_DIR"
2363 SAVE_CACHE_DIR="$CACHE_DIR"
2364 PKGS_DB="$root/$PKGS_DB"
2365 else
2366 _ 'rootconfig needs --root= option used.' >&2
2367 exit 1
2368 fi
2369 fi
2371 # Get repositories priority list.
2372 look_for_priority
2374 AUTOEXEC='no'
2375 # Magic :)
2376 # After testing this condition $PACKAGE become $PACKAGE-$VERSION$EXTRAVERSION
2377 if ! check_for_package_in_list check; then
2378 CACHE_DIR="${CACHE_DIR%/*}/get"
2379 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
2380 if download_get_script "$PACKAGE" "/tmp/$PACKAGE.$$" ; then
2381 install_package_from_get_script "/tmp/$PACKAGE.$$" $ROOT
2382 exit 0
2383 else
2384 PACKAGE="get-$PACKAGE"
2385 AUTOEXEC="$PACKAGE"
2386 # Here $PACKAGE become $PACKAGE-$VERSION$EXTRAVERSION
2387 check_for_package_in_list
2388 if [ -n "$(get_installed_package_pathname "$PACKAGE" "$ROOT")" ]; then
2389 $AUTOEXEC $ROOT
2390 exit 0
2391 fi
2392 fi
2393 fi
2394 # Check if no forced install.
2395 if [ -z "$forced" ]; then
2396 check_for_installed_package $ROOT
2397 fi
2399 cd $CACHE_DIR
2400 # Here $PACKAGE is $PACKAGE-$VERSION$EXTRAVERSION
2401 if [ -f "$PACKAGE.tazpkg" ]; then
2402 _ 'Package "%s" already in the cache' "$PACKAGE"
2403 # Check package download was finished
2404 tail -c 2k "$PACKAGE.tazpkg" | fgrep -q '00000000TRAILER' || {
2405 _ 'Continuing package "%s" download' "$PACKAGE"
2406 download "$PACKAGE.tazpkg"
2408 if [ "$($CHECKSUM "$PACKAGE.tazpkg")" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2409 rm -f "$PACKAGE.tazpkg"
2410 download "$PACKAGE.tazpkg"
2411 fi
2412 else
2413 newline
2414 download "$PACKAGE.tazpkg"
2415 fi
2416 PACKAGE_FILE="$CACHE_DIR/$PACKAGE.tazpkg"
2417 [ -n "$rootconfig" ] && PKGS_DB="${PKGS_DB#$root}"
2418 install_package "$ROOT"
2419 [ "$AUTOEXEC" != 'no' ] && "$PACKAGE" $ROOT
2420 update_desktop_database $ROOT
2421 update_mime_database $ROOT ;;
2424 clean-cache|-cc)
2425 # Remove all downloaded packages.
2426 check_root $@
2427 files=$(find $CACHE_DIR -name *.tazpkg | wc -l)
2428 size=$(du -hs $CACHE_DIR | cut -f1 | sed 's|\.0||'); [ "$files" -eq 0 ] && size="0K"
2430 title 'Cleaning cache directory...'
2431 action 'Path: %s' "$CACHE_DIR"
2432 rm -rf $CACHE_DIR/*
2433 status
2435 footer "$(_p \
2436 '%s file removed from cache (%s).' \
2437 '%s files removed from cache (%s).' $files \
2438 "$(colorize 32 "$files")" $size)"
2439 ;;
2442 list-undigest)
2443 # list undigest URLs.
2444 if [ -n "$box" ]; then
2445 for i in $PKGS_DB/undigest/*/mirror; do
2446 [ -f "$i" ] || continue
2447 echo "$(basename "$(dirname "$i")")|$(cat "$i")"
2448 done
2449 else
2450 title 'Current undigest(s)'
2451 for i in $PKGS_DB/undigest/*/mirror; do
2452 if [ ! -f "$i" ]; then
2453 _ 'No undigest mirror found.'
2454 exit 1
2455 fi
2456 echo "$(basename "$(dirname "$i")")"$'\t'"$(cat "$i")"
2457 done
2458 newline
2459 fi
2460 ;;
2463 remove-undigest)
2464 # remove undigest URL.
2465 check_root $@
2466 undigest="$2"
2467 if [ -d "$PKGS_DB/undigest/$2" ]; then
2468 confirm "$(_ 'Remove "%s" undigest? (y/N)' $undigest)"
2469 if [ $? == 0 ]; then
2470 action 'Removing "%s" undigest...' $undigest
2471 rm -rf $PKGS_DB/undigest/$2
2472 status
2473 rmdir $PKGS_DB/undigest 2>/dev/null
2474 fi
2475 else
2476 _ 'Undigest "%s" not found' $undigest
2477 fi
2478 ;;
2481 add-undigest|setup-undigest)
2482 # Add undigest URL.
2483 check_root $@
2485 [ ! -d "$PKGS_DB/undigest" ] && mkdir "$PKGS_DB/undigest"
2487 undigest="$2"
2488 if [ -z "$undigest" ]; then
2489 i='1'
2490 while [ -d "$PKGS_DB/undigest/$i" ]; do
2491 i=$(($i+1))
2492 done
2493 undigest="$i"
2494 fi
2495 if [ ! -d "$PKGS_DB/undigest/$undigest" ]; then
2496 _ 'Creating new undigest "%s".' "$undigest"
2497 mkdir "$PKGS_DB/undigest/$undigest"
2498 fi
2499 setup_mirror "$PKGS_DB/undigest/$undigest" "$3"
2500 ;;
2503 setup-mirror|-sm)
2504 # Change mirror URL.
2505 check_root $@
2506 setup_mirror $PKGS_DB $2 ;;
2509 reconfigure)
2510 # Replay post_install from receipt
2511 check_for_package_on_cmdline
2512 check_root $@
2514 ROOT="$root"
2515 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2516 check_for_receipt $ROOT
2517 # Check for post_install
2518 if grep -q ^post_install "$ROOT$INSTALLED/$PACKAGE/receipt"; then
2519 . "$ROOT$INSTALLED/$PACKAGE/receipt"
2520 post_install $ROOT
2521 # Log this activity
2522 [ -z "$ROOT" ] && log_pkg Reconfigured
2523 else
2524 newline
2525 _ 'Nothing to do for package "%s".' "$PACKAGE"
2526 fi
2527 else
2528 newline
2529 _ 'Package "%s" is not installed.' "$PACKAGE"
2530 _ 'Install package with "%s" or "%s"' 'tazpkg install' 'tazpkg get-install'
2531 newline
2532 fi
2533 ;;
2536 shell)
2537 # TazPkg SHell
2538 if [ "$(id -u)" -eq 0 ]; then
2539 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2540 else
2541 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2542 fi
2543 if [ -z "$noheader" ]; then
2544 clear
2545 title 'TazPkg SHell.'
2546 _ "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
2547 newline
2548 fi
2549 while true; do
2550 echo -en "$PROMPT"; read cmd
2551 case $cmd in
2552 q|quit)
2553 break ;;
2554 shell)
2555 _ 'You are already running a TazPkg SHell.' ;;
2556 su)
2557 su -c 'exec tazpkg shell --noheader' && break ;;
2558 "")
2559 continue ;;
2560 *)
2561 tazpkg $cmd ;;
2562 esac
2563 done ;;
2566 depends)
2567 # Display dependencies tree
2568 unset ALL_DEPS
2569 mkdir $TMP_DIR
2570 dep_scan $2 '' | tee "$TMP_DIR/depends"
2571 if [ -n "$total" ]; then
2572 separator
2573 NUM="$(wc -l < "$TMP_DIR/depends")"
2574 TOTAL="$(sed 's|.*(\([^)]*\))|\1|' "$TMP_DIR/depends" | hrsum)"
2575 _p 'Total: %s package (%s)' 'Total: %s packages (%s)' "$NUM" \
2576 "$NUM" "$TOTAL"
2577 newline
2579 if [ -n "$mark" ]; then
2580 NUM="$(grep '^ *-' "$TMP_DIR/depends" | wc -l)"
2581 TOTAL="$(grep '^ *-' "$TMP_DIR/depends" | sed 's|.*(\([^)]*\))|\1|' | hrsum)"
2582 _p 'To install: %s package (%s)' 'To install: %s packages (%s)' "$NUM" \
2583 "$NUM" "$TOTAL"
2584 newline
2585 fi
2586 fi
2587 rm -rf "$TMP_DIR"
2588 ;;
2591 rdepends)
2592 # Display reverse dependencies tree
2593 cd $INSTALLED
2594 unset ALL_DEPS
2595 rdep_scan "$2"
2596 ;;
2599 convert|-c)
2600 # convert misc package format to .tazpkg
2601 check_for_package_file
2602 shift; @@MODULES@@/convert $@
2603 ;;
2606 link)
2607 # link a package from another slitaz installation
2608 PACKAGE="$2"
2609 if [ ! -d "$TARGET_DIR" -o \
2610 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
2611 _ 'Usage: tazpkg link package_name slitaz_root'
2612 longline "$(
2613 _n 'Example:'
2614 echo -n ' '
2615 _ '"%s" will use less than 100k in your running system RAM.' \
2616 'tazpkg link openoffice /mnt')"
2617 exit 1
2618 fi
2619 if [ -e "$INSTALLED/$PACKAGE" ]; then
2620 _ 'Package "%s" is already installed.' "$PACKAGE"
2621 exit 1
2622 fi
2623 ln -s "$TARGET_DIR$INSTALLED/$PACKAGE" $INSTALLED
2624 DEPENDS="$(. "$INSTALLED/$PACKAGE/receipt"; echo $DEPENDS)"
2625 MISSING=''
2626 for i in $DEPENDS; do
2627 [ -e $INSTALLED/$i ] && continue
2628 MISSING="$MISSING$i "
2629 _ 'Missing: %s' $i
2630 done
2631 if [ -n "$MISSING" ]; then
2632 newline
2633 confirm "$(_ 'Link all missing dependencies? (y/N)')"
2634 answer=$?
2635 newline
2636 if [ "$answer" -eq 0 ]; then
2637 for i in $MISSING; do
2638 tazpkg link $i $TARGET_DIR
2639 done
2640 else
2641 newline
2642 _ 'Leaving dependencies unresolved for package "%s"' "$PACKAGE"
2643 _ 'The package is installed but probably will not work.'
2644 newline
2645 fi
2646 fi
2647 . "$INSTALLED/$PACKAGE/receipt"
2648 if grep -q ^pre_install "$INSTALLED/$PACKAGE/receipt"; then
2649 pre_install
2650 fi
2651 while read path; do
2652 [ -e "$path" ] && continue
2653 while true; do
2654 dir="$(dirname "$path")"
2655 [ -e "$dir" ] && break
2656 path="$dir"
2657 done
2658 ln -s "$TARGET_DIR$path" "$dir"
2659 done < "$INSTALLED/$PACKAGE/files.list"
2660 if grep -q ^post_install "$INSTALLED/$PACKAGE/receipt"; then
2661 post_install
2662 fi ;;
2665 help|-h)
2666 # TazPkg help system
2667 shift; @@MODULES@@/help $@ ;;
2670 mkdb)
2671 # Make TazPkg database
2672 shift; @@MODULES@@/mkdb $@ ;;
2675 '')
2676 # Default to summary
2677 title "$(_ 'SliTaz package manager - Version: %s' $(colorize 34 $VERSION))"
2679 optlist "\
2680 $(_ 'Installed packages:') $(wc -l < $PKGS_DB/installed.info)
2681 $(_ 'Installed files:') $(cat $INSTALLED/*/files.list | wc -l)
2682 $(_ 'Blocked packages:') $( (wc -l < $PKGS_DB/blocked-packages.list) 2>/dev/null || echo 0)
2683 $(_ 'Upgradeable packages:') $( (wc -l < $PKGS_DB/packages.up) 2>/dev/null || echo 0)
2684 $(
2685 # Per-repository stuff
2687 if [ -h "$PKGS_DB/fslink" ]; then
2688 if [ -e "$PKGS_DB/fslink/etc/slitaz/slitaz.conf" ]; then
2689 PKGS_DB_LINK="$PKGS_DB/fslink/$(. "$PKGS_DB/fslink/etc/slitaz/slitaz.conf"; echo "$PKGS_DB")"
2690 fi
2691 fi
2693 for path in $PKGS_DB $PKGS_DB/undigest/* $PKGS_DB_LINK; do
2694 [ ! -e "$path" ] && continue
2695 case "$path" in
2696 $PKGS_DB) repo_name='Main';;
2697 */fslink/*) repo_name=$(readlink $PKGS_DB/fslink);;
2698 *) repo_name="$(_n 'Undigest %s' "$(basename "$path")")";;
2699 esac
2701 newline; colorize 33 "$(_n 'Repository:'; echo -e "\t$repo_name")"
2703 _n 'Last recharge:'; echo -en '\t'
2704 IDs="$path/IDs"
2705 if [ -e "$IDs" ]; then
2706 # Timezone offset as string, ex. '+0200' for EET (+2 hours)
2707 ohhmm="$(date +%z)"
2708 # Timezone offset in the seconds
2709 offset=$(( 60 * (60 * ${ohhmm:0:3} + ${ohhmm:3:2}) ))
2710 daynow=$(( ($(date +%s) + $offset) / 86400 ))
2711 dayupd=$(( ($(date -r $IDs +%s) + $offset) / 86400 ))
2712 days=$(( $daynow - $dayupd ))
2713 time=$(date -r $IDs +%R)
2714 case $days in
2715 0) _ 'Today at %s.' $time;;
2716 1) _ 'Yesterday at %s.' $time;;
2717 *) _p '%d day ago.' '%d days ago.' $days $days; newline;;
2718 esac
2720 _n 'Database timestamp:'; echo -en '\t'
2721 date -d "@$(awk '{print $2}' "$IDs")" "+%x %R"
2722 else
2723 _ 'never.'
2724 fi
2726 if [ -e "$path/packages.info" ]; then
2727 _n 'Mirrored packages:'; echo -en '\t'; wc -l < "$path/packages.info"
2728 fi
2730 if [ "${path/fslink/}" != "$path" ]; then
2731 _n 'Linked packages:'; echo -en '\t'
2732 find $INSTALLED -type l | wc -l
2733 fi
2734 done
2735 )"
2736 footer
2737 ;;
2740 usage|*)
2741 # Print a short help or give usage for an unknown or empty command.
2742 usage ;;
2743 esac
2745 exit 0