tazpkg annotate modules/check @ rev 840
Add a bunch of modules with new-style support of 'root' (not all commands are modules yet); strip and compress resources.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Fri Aug 28 16:10:34 2015 +0300 (2015-08-28) |
parents | |
children | 0560ba4306a1 |
rev | line source |
---|---|
al@840 | 1 #!/bin/sh |
al@840 | 2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg |
al@840 | 3 # check - TazPkg module |
al@840 | 4 # Check installed packages set |
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 # Get repositories priority using $PKGS_DB/priority. |
al@840 | 17 # In this file undigest repos are called by their names and main mirror |
al@840 | 18 # by 'main'. Sort order: priority |
al@840 | 19 |
al@840 | 20 look_for_priority() { |
al@840 | 21 [ -s "$PKGS_DB/priority" ] && priority=$(cat "$PKGS_DB/priority") |
al@840 | 22 |
al@840 | 23 for rep in main $(ls "$PKGS_DB/undigest" 2>/dev/null); do |
al@840 | 24 if [ ! -s "$PKGS_DB/priority" ] || ! grep -q "^$rep$" "$PKGS_DB/priority"; then |
al@840 | 25 priority=$(echo -e "$priority\n$rep") |
al@840 | 26 fi |
al@840 | 27 done |
al@840 | 28 |
al@840 | 29 priority=$(echo "$priority" | sed '/^$/d' | \ |
al@840 | 30 while read line; do |
al@840 | 31 case $line in |
al@840 | 32 (main) echo "$PKGS_DB";; |
al@840 | 33 (*) echo "$PKGS_DB/undigest/$line";; |
al@840 | 34 esac |
al@840 | 35 done) |
al@840 | 36 } |
al@840 | 37 |
al@840 | 38 |
al@840 | 39 # Print package name if not printed yet |
al@840 | 40 print_pkgname() { |
al@840 | 41 if [ "$PACKAGE" != "$PACKAGE_PRINTED" ]; then |
al@840 | 42 [ -n "$PACKAGE_PRINTED" ] && footer |
al@840 | 43 title 'Package %s' "$PACKAGE-$VERSION$EXTRAVERSION" |
al@840 | 44 PACKAGE_PRINTED="$PACKAGE" |
al@840 | 45 fi |
al@840 | 46 } |
al@840 | 47 |
al@840 | 48 |
al@840 | 49 # get an already installed package from packages.equiv |
al@840 | 50 |
al@840 | 51 equivalent_pkg() { |
al@840 | 52 for i in $(grep -hs "^$1=" "$PKGS_DB/packages.equiv" \ |
al@840 | 53 "$PKGS_DB"/undigest/*/packages.equiv | sed "s/^$1=//"); do |
al@840 | 54 if echo $i | fgrep -q : ; then |
al@840 | 55 # format 'alternative:newname' |
al@840 | 56 # if alternative is installed then substitute newname |
al@840 | 57 if [ -f "$INSTALLED/${i%:*}/receipt" ]; then |
al@840 | 58 # substitute package dependency |
al@840 | 59 echo "${i#*:}" |
al@840 | 60 return |
al@840 | 61 fi |
al@840 | 62 else |
al@840 | 63 # if alternative is installed then nothing to install |
al@840 | 64 if [ -f "$INSTALLED/$i/receipt" ]; then |
al@840 | 65 # substitute installed package |
al@840 | 66 echo "$i" |
al@840 | 67 return |
al@840 | 68 fi |
al@840 | 69 fi |
al@840 | 70 done |
al@840 | 71 # if not found in packages.equiv then no substitution |
al@840 | 72 echo "$1" |
al@840 | 73 } |
al@840 | 74 |
al@840 | 75 |
al@840 | 76 # Check for loop in deps tree. |
al@840 | 77 |
al@840 | 78 check_for_deps_loop() { |
al@840 | 79 local list pkg="$1" deps |
al@840 | 80 shift |
al@840 | 81 [ -n "$1" ] || return |
al@840 | 82 list='' |
al@840 | 83 |
al@840 | 84 # Filter out already processed deps |
al@840 | 85 for i in $@; do |
al@840 | 86 case " $ALL_DEPS" in |
al@840 | 87 *\ $i\ *) ;; |
al@840 | 88 *) list="$list $i";; |
al@840 | 89 esac |
al@840 | 90 done |
al@840 | 91 ALL_DEPS="$ALL_DEPS$list " |
al@840 | 92 for i in $list; do |
al@840 | 93 [ -f "$i/receipt" ] || continue |
al@840 | 94 deps="$(unset DEPENDS; . "$i/receipt"; echo $DEPENDS)" |
al@840 | 95 case " $deps " in |
al@840 | 96 *\ $pkg\ *) |
al@840 | 97 print_pkgname |
al@840 | 98 echo -e "$MSG $i"; MSG='';; |
al@840 | 99 *) |
al@840 | 100 check_for_deps_loop "$pkg" "$deps";; |
al@840 | 101 esac |
al@840 | 102 done |
al@840 | 103 } |
al@840 | 104 |
al@840 | 105 |
al@840 | 106 grepesc() { sed 's/\[/\\[/g'; } |
al@840 | 107 |
al@840 | 108 |
al@840 | 109 |
al@840 | 110 |
al@840 | 111 # Get repositories priority list. |
al@840 | 112 look_for_priority |
al@840 | 113 |
al@840 | 114 cd "$INSTALLED" |
al@840 | 115 if [ -z "$2" -o -n "$full" ]; then PACKAGES="$(ls)"; else PACKAGES="$2"; fi |
al@840 | 116 PACKAGE_PRINTED='' |
al@840 | 117 |
al@840 | 118 for PACKAGE in $PACKAGES; do |
al@840 | 119 |
al@840 | 120 if [ ! -f "$PACKAGE/receipt" ]; then |
al@840 | 121 print_pkgname |
al@840 | 122 _ 'The package installation has not completed' |
al@840 | 123 continue |
al@840 | 124 fi |
al@840 | 125 |
al@840 | 126 unset DEPENDS EXTRAVERSION |
al@840 | 127 . "$PACKAGE/receipt" |
al@840 | 128 if [ -s "$PACKAGE/modifiers" ]; then |
al@840 | 129 print_pkgname |
al@840 | 130 _ 'The package has been modified by:' |
al@840 | 131 awk '{print " " $0}' "$PACKAGE/modifiers" |
al@840 | 132 fi |
al@840 | 133 |
al@840 | 134 MSG="$(_n 'Files lost from package:')\n" |
al@840 | 135 while read file; do |
al@840 | 136 [ -e "$file" ] && continue |
al@840 | 137 if [ -L "$file" ]; then |
al@840 | 138 MSG="$MSG $(_n 'target of symlink')" |
al@840 | 139 fi |
al@840 | 140 print_pkgname |
al@840 | 141 echo -e "$MSG $file" |
al@840 | 142 MSG='' |
al@840 | 143 done < "$PACKAGE/files.list" |
al@840 | 144 |
al@840 | 145 MSG="$(_n 'Missing dependencies for package:')\n" |
al@840 | 146 for i in $DEPENDS; do |
al@840 | 147 [ -d "$i" ] && continue |
al@840 | 148 [ -d "$(equivalent_pkg "$i")" ] && continue |
al@840 | 149 print_pkgname |
al@840 | 150 echo -e "$MSG $i" |
al@840 | 151 MSG='' |
al@840 | 152 done |
al@840 | 153 |
al@840 | 154 MSG="$(_n 'Dependencies loop between package and:')\n" |
al@840 | 155 ALL_DEPS='' |
al@840 | 156 check_for_deps_loop "$PACKAGE" "$DEPENDS" |
al@840 | 157 done |
al@840 | 158 [ -n "$PACKAGE_PRINTED" ] && footer |
al@840 | 159 |
al@840 | 160 _ 'Looking for known bugs...' |
al@840 | 161 if [ -z "$2" -o -n "$full" ]; then tazpkg bugs; else tazpkg bugs "$2"; fi |
al@840 | 162 |
al@840 | 163 |
al@840 | 164 if [ -n "$full" ]; then |
al@840 | 165 separator |
al@840 | 166 |
al@840 | 167 title 'Mismatch checksum of installed files:' |
al@840 | 168 |
al@840 | 169 for PACKAGE in $PACKAGES; do |
al@840 | 170 file="$PACKAGE/$CHECKSUM" |
al@840 | 171 CONFIG_FILES='' |
al@840 | 172 . "$PACKAGE/receipt" |
al@840 | 173 [ -s "$file" ] || continue |
al@840 | 174 while read md5 f; do |
al@840 | 175 [ -f "$f" ] || continue |
al@840 | 176 for i in $CONFIG_FILES; do |
al@840 | 177 case "$f" in |
al@840 | 178 $i|$i/*) continue 2;; |
al@840 | 179 esac |
al@840 | 180 done |
al@840 | 181 echo "$md5 $f" |
al@840 | 182 done < "$file" | busybox $CHECKSUM -c - 2>/dev/null | grep -v OK$ | sed "s/: FAILED$//" |
al@840 | 183 done |
al@840 | 184 footer |
al@840 | 185 |
al@840 | 186 title 'Check file providers:' |
al@840 | 187 FILES=' ' |
al@840 | 188 for PACKAGE in $PACKAGES; do |
al@840 | 189 for file in $(cat "$PACKAGE/files.list"); do |
al@840 | 190 [ -d "$file" ] && continue |
al@840 | 191 case "$FILES" in |
al@840 | 192 *\ $file\ *) continue;; |
al@840 | 193 esac |
al@840 | 194 [ $(grep "^$(echo $file | grepesc)$" */files.list 2> /dev/null | wc -l) -gt 1 ] || continue |
al@840 | 195 FILES="$FILES$file " |
al@840 | 196 newline |
al@840 | 197 _ 'The following packages provide file "%s":' "$file" |
al@840 | 198 grep -l "^$(echo "$file" | grepesc)$" */files.list | \ |
al@840 | 199 while read f; do |
al@840 | 200 pkg=${f%/files.list} |
al@840 | 201 if [ -f "$pkg/modifiers" ]; then |
al@840 | 202 overriders=$(_n '(overridden by %s)' "$(tr '\n' ' ' < $pkg/modifiers | sed 's| $||')") |
al@840 | 203 else |
al@840 | 204 overriders='' |
al@840 | 205 fi |
al@840 | 206 echo -n " * $pkg $overriders" |
al@840 | 207 newline |
al@840 | 208 done |
al@840 | 209 done |
al@840 | 210 done |
al@840 | 211 footer |
al@840 | 212 |
al@840 | 213 if [ -n "$full" ]; then |
al@840 | 214 title 'Alien files:' |
al@840 | 215 MSG="$(_n 'No package has installed the following files:')\n" |
al@840 | 216 find /etc /bin /sbin /lib /usr /var/www -not -type d 2>/dev/null | \ |
al@840 | 217 while read file; do |
al@840 | 218 case "$file" in *\[*) continue;; esac |
al@840 | 219 grep -q "^$(echo $file | grepesc)$" */files.list && continue |
al@840 | 220 echo -e "$MSG $file" |
al@840 | 221 MSG='' |
al@840 | 222 done |
al@840 | 223 footer |
al@840 | 224 fi |
al@840 | 225 fi |
al@840 | 226 _ 'Check completed.'; newline |