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