tazpkg annotate modules/depends @ rev 887

module get: fix virtual packages support; module remove: provide virt. pkg. support, update system DBs; add test06 for virt. packages
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Dec 11 01:32:39 2015 +0200 (2015-12-11)
parents a02e36d44d06
children
rev   line source
al@840 1 #!/bin/sh
al@840 2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
al@840 3 # depends - TazPkg module
al@840 4 # Show packages dependencies and reverse dependencies trees
al@840 5
al@840 6
al@840 7 # Connect function libraries
al@840 8 . /lib/libtaz.sh
al@840 9
al@840 10 # Get TazPkg working environment
al@840 11 . @@MODULES@@/getenv
al@840 12
al@840 13
al@840 14
al@840 15
al@840 16 # recursive dependencies scan
al@840 17
al@840 18 dep_scan() {
al@840 19 for i in $1; do
al@840 20 case " $ALL_DEPS " in
al@840 21 *\ $i\ *) continue;;
al@840 22 esac
al@840 23 ALL_DEPS="$ALL_DEPS $i"
al@840 24
al@840 25 if [ -z "$mark" ]; then
al@840 26 ii="$i"
al@840 27 else
al@840 28 ii="- $i"; grep -q ^$i$'\t' "$PKGS_DB/installed.info" && ii="+ $i"
al@840 29 fi
al@840 30 [ -n "$2" ] && echo "$2$ii ($(awk -F$'\t' -vp="$i" '
al@840 31 $1==p{split($7,s," ");print s[2]}' "$PKGS_DB/packages.info"))"
al@840 32
al@840 33 DEPENDS="$(awk -F$'\t' -vp="$i" '$1==p{print $8 " "}' "$PKGS_DB/installed.info")"
al@840 34 [ -z "$DEPENDS" ] && \
al@840 35 DEPENDS="$(awk -F$'\t' -vp="$i" '$1==p{print $8 " "}' "$PKGS_DB/packages.info")"
al@840 36 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
al@840 37 done
al@840 38 }
al@840 39
al@840 40
al@840 41 # recursive reverse dependencies scan
al@840 42
al@840 43 rdep_scan() {
al@840 44 SEARCH="$1"
al@840 45
al@840 46 DB='installed'; [ -n "$all" ] && DB='packages'
al@840 47
al@840 48 awk -F$'\t' '$8 {print $1 " " $8}' "$PKGS_DB/$DB.info" | \
al@846 49 awk -F' ' -v search="$SEARCH" '
al@840 50 function show_deps(pkg, space, i, n, mydeps) {
al@840 51 if (processed[pkg]) return
al@840 52 processed[pkg] = 1;
al@840 53
al@840 54 if (space) printf "%s %s\n", space, pkg;
al@840 55
al@840 56 n = split(deps[pkg], mydeps, " ");
al@840 57 for (i = 1; i <= n; i++)
al@840 58 show_deps(mydeps[i], "==" space);
al@840 59 }
al@840 60
al@840 61 {
al@840 62 for (i = 2; i <= NF; i++)
al@840 63 deps[$i] = deps[$i] " " $1;
al@840 64 }
al@840 65
al@840 66 END {
al@840 67 show_deps(search, "")
al@840 68 }
al@840 69 ' | while read spc pkg; do
al@840 70 if [ -z "$mark" ]; then
al@840 71 pkgi="$pkg"
al@840 72 else
al@840 73 pkgi="- $pkg"; grep -q ^$pkg$'\t' "$PKGS_DB/installed.info" && pkgi="+ $pkg"
al@840 74 fi
al@840 75
al@840 76 echo -n $spc | sed 's/=/ /g'
al@840 77
al@840 78 echo "$pkgi ($(awk -F$'\t' -vp="$pkg" '$1==p{split($7,s," ");print s[2]}' \
al@840 79 "$PKGS_DB/$DB.info"))"
al@840 80 done
al@840 81 }
al@840 82
al@840 83
al@840 84 # Human readable sum
al@840 85
al@840 86 hrsum() {
al@840 87 awk '
al@840 88 BEGIN {
al@840 89 K = 1024; M = K * 1024; G = M * 1024;
al@840 90 SUM=0;
al@840 91 }
al@840 92 /K/ { SUM += $1 * K }
al@840 93 /M/ { SUM += $1 * M }
al@840 94 /G/ { SUM += $1 * G }
al@840 95 END {
al@840 96 if (SUM >= G) {
al@840 97 SUM /= G; P = "GiB";
al@840 98 } else if (SUM >= M) {
al@840 99 SUM /= M; P = "MiB";
al@840 100 } else {
al@840 101 SUM /= K; P = "KiB";
al@840 102 }
al@840 103 if (SUM >= 100) printf "%d%s", SUM, P; else printf "%.1f%s", SUM, P;
al@840 104 }' | sed 's|\.0||'
al@840 105 }
al@840 106
al@840 107
al@840 108
al@840 109
al@840 110 case "$1" in
al@840 111
al@840 112 depends)
al@840 113 # Display dependencies tree
al@840 114 unset ALL_DEPS
al@840 115 TMP_DIR=$(mktemp -d)
al@840 116 dep_scan "$2" '' | tee "$TMP_DIR/depends"
al@840 117 if [ -n "$total" ]; then
al@840 118 separator
al@840 119 NUM="$(wc -l < "$TMP_DIR/depends")"
al@840 120 TOTAL="$(sed 's|.*(\([^)]*\))|\1|' "$TMP_DIR/depends" | hrsum)"
al@840 121 _p 'Total: %s package (%s)' 'Total: %s packages (%s)' "$NUM" \
al@840 122 "$NUM" "$TOTAL"
al@840 123 newline
al@840 124
al@840 125 if [ -n "$mark" ]; then
al@840 126 NUM="$(grep '^ *-' "$TMP_DIR/depends" | wc -l)"
al@840 127 TOTAL="$(grep '^ *-' "$TMP_DIR/depends" | sed 's|.*(\([^)]*\))|\1|' | hrsum)"
al@840 128 _p 'To install: %s package (%s)' 'To install: %s packages (%s)' "$NUM" \
al@840 129 "$NUM" "$TOTAL"
al@840 130 newline
al@840 131 fi
al@840 132 fi
al@840 133 rm -rf "$TMP_DIR"
al@840 134 ;;
al@840 135
al@840 136
al@840 137 rdepends)
al@840 138 # Display reverse dependencies tree
al@840 139 cd $INSTALLED
al@840 140 unset ALL_DEPS
al@840 141 rdep_scan "$2"
al@840 142 ;;
al@840 143
al@840 144 esac