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