tazpkg annotate modules/check @ rev 842

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