cookutils view modules/postcheck @ rev 1090

Working with "i486", "x86_64" and "any" architecture; post-check with badges; new icons, tag cloud, and other improvements
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Nov 24 13:28:02 2018 +0200 (2018-11-24)
parents
children 7fdea1dfb4e2
line source
1 #!/bin/sh
2 #
3 # postcheck - module of the SliTaz Cook
4 # Copyright (C) SliTaz GNU/Linux - GNU GPL v3
5 #
6 # Check for different cases at the end and add badges
8 . /usr/lib/slitaz/libcook.sh
9 . /etc/slitaz/cook.conf
10 . $WOK/$1/receipt
12 data="$(mktemp -d)" # temporary data for post-checking
14 repologydb="$CACHE/repology.db"
16 badges="$WOK/$1/.badges"
17 echo -n > $badges # clean badges
19 overrides="$WOK/$1/stuff/overrides"
20 overrides_exp="$data/overrides_exp"
21 fail="$data/fail" # file used as flag, if will be empty if no fails were found
23 sets=$(echo -n $SPLIT | awk 'BEGIN { RS = " "; FS = ":"; }
24 { if ($2 && ! set[$2]) { printf("%s ", $2); set[$2] = "1"; } }')
26 # Format of stuff/overrides:
27 # <rule> {<rule> ...} <fil[e]*>
28 # One or more rules may indicate:
29 # - ownership in form '80:80' (numeric UID:GID) or 'www:www' (string UID:GID)
30 # - permissions in form '0600' (four octal digits)
31 # File is space free string specified one (or more - using placeholders) files
34 # Expand overrides to the simple form: <rule><tab><file>
36 if [ -e "$overrides" ]; then
37 IFS=$'\n'
38 while read line; do
39 rules=${line% *}; file=${line##* }
41 for set in '' $sets; do
42 install="$WOK/$1/install"
43 [ -z "$set" ] || install="$install-$set"
44 [ -d "$install" ] || continue
45 for file in $(ls -d $install$file); do
46 for rule in $rules; do
47 echo "$rule ${file#$install}" >> $overrides_exp
48 done
49 done
50 done
51 done < $overrides
52 unset IFS
53 fi
56 # Get latest packaged version from Repology
58 repology_get() {
59 local found versions day=$(date +%j) # %j is the number of the day in the year
60 found=$(awk -F$'\t' -vpkg="$1" -vday="$day" '{
61 if ($1 == pkg && $2 == day) { print $3; exit; }
62 }' $repologydb)
63 if [ -n "$found" ]; then
64 echo "$found"
65 else
66 # set HOST_WGET in cook.conf
67 versions=$($HOST_WGET -q -T 20 -O- https://repology.org/badge/latest-versions/$1.svg \
68 | sed '/<text /!d; /fill/d; /latest/d; s|.*>\(.*\)<.*|\1|; s|, | |g') # space separated list
69 if [ -n "$versions" ]; then
70 sed -i "/^$1 /d" $repologydb
71 echo -e "$1\t$day\t$versions" >> $repologydb
72 echo $versions
73 fi
74 fi
75 }
78 # Add the specified badge, set the fail flag and return false status
80 function add() {
81 ! grep -q "^${1}$" $badges && echo "$1" >> $badges
82 case $1 in
83 ss|old|win|patch) return 0;;
84 *) echo 'yes' > $fail; false;;
85 esac
86 }
89 function docheck() {
90 action 'Checking build...'
91 if grep -q "^$PACKAGE$" $broken; then
92 if grep -q '^ERROR: unknown dep' $LOGS/$1.log; then
93 add 'bdbroken'
94 else
95 add 'broken'
96 fi
97 status; return # no more tests since package is broken
98 fi
99 status
102 if [ -e $WOK/$1/.arch ]; then
103 action "Checking 'any' arch..."
104 if [ "$(cut -d$'\t' -f2 $WOK/$1/.arch | sort -u)" == 'any' ]; then
105 if [ "$HOST_ARCH" != 'any' ]; then
106 add 'any'
107 fi
108 else
109 if [ "$HOST_ARCH" == 'any' ]; then
110 add 'noany'
111 fi
112 fi
113 status
114 fi
117 if [ -e $WOK/$1/.patch.done ]; then
118 # consider 'fix libtool' as no patch here
119 if [ -n "$(grep -v 'fix.libtool' $WOK/$1/.patch.done)" ]; then
120 add 'patch'
121 fi
122 fi
125 for set in '' $sets; do
126 src=$WOK/$1/source/$PACKAGE-$VERSION
127 [ -z "$set" ] || src="$src-$set"
128 [ -d "$src" ] || continue
130 action "Checking libtool in ${src#$WOK/$1/}..."
131 if [ -e "$src/libtool" ]; then
132 if ! grep -q '^fix.libtool$' $WOK/$1/.patch.done 2>/dev/null; then
133 add 'libtool'
134 fi
135 else
136 if grep -q '^fix.libtool$' $WOK/$1/.patch.done 2>/dev/null; then
137 add 'nolibtool'
138 fi
139 fi
140 status
142 action "Checking site script in ${src#$WOK/$1/}..."
143 if fgrep -q 'configure: loading site script /etc/slitaz/cook.site' $LOGS/$PACKAGE.log; then
144 for i in bindir datadir datarootdir docdir dvidir htmldir includedir infodir libdir \
145 libexecdir localedir localstatedir mandir oldincludedir pdfdir psdir sbindir \
146 sharedstatedir sysconfdir; do
147 if fgrep -q -e "--$i=" $WOK/$1/receipt; then
148 add 'ss'
149 break
150 fi
151 done
152 fi
153 status
154 done
157 for set in '' $sets; do
158 install="$WOK/$1/install"
159 [ -z "$set" ] || install="$install-$set"
160 [ -d "$install" ] || continue
162 action "Checking ownership in ${install#$WOK/$1/}..."
164 IFS=$'\n'
165 bad_own="$(find $install -type f \( ! -user 0 -a ! -group 0 \))"
166 if [ -n "$bad_own" ]; then
167 if [ -e $overrides_exp ]; then
168 # There may be mix of overridden and not-overridden ownership
169 # in the package. Return status 'Done' only if all the ownership
170 # was overridden.
171 result=''
172 for i in $bad_own; do
173 if fgrep -q "$(stat -c %u:%g "$i") ${i#$install}" $overrides_exp ||
174 fgrep -q "$(stat -c %U:%G "$i") ${i#$install}" $overrides_exp; then
175 add 'ownover'
176 else
177 add 'own'
178 result='bad'
179 fi
180 done
181 [ "$result" == '' ] # OK, all was overridden
182 else
183 add 'own'
184 fi
185 fi
186 status
187 unset IFS
190 action "Checking permissions in ${install#$WOK/$1/}..."
192 bad_files="$(find $install -type f \( ! -perm 644 -a ! -perm 755 \))"
193 bad_dirs="$(find $install -type d ! -perm 755)"
194 list=''
195 if [ -n "$bad_files$bad_dirs" ]; then
196 if [ -e $overrides_exp ]; then
197 # There may be mix of overridden and not-overridden permissions
198 # in the package. Return status 'Done' only if all the permissions
199 # was overridden.
200 result=''
201 for i in $bad_files; do
202 if fgrep -q "$(printf "%04d\t%s" "$(stat -c%a "$i")" "${i#$install}")" $overrides_exp; then
203 add 'permover'
204 else
205 add 'perm'
206 list="$list$(printf "\n %04d %s" "$(stat -c %a "$i")" "${i#$install}")"
207 result='bad'
208 fi
209 done
210 for i in $bad_dirs; do
211 if fgrep -q "$(printf "%04d" $(stat -c %a "$i")) ${i#$install}/" $overrides_exp; then
212 add 'permover'
213 else
214 add 'perm'
215 list="$list$(printf "\n %04d %s" "$(stat -c %a "$i")" "${i#$install}/")"
216 result='bad'
217 fi
218 done
219 [ "$result" == '' ] # OK, all was overridden
220 else
221 add 'perm'
222 fi
223 fi
224 status
225 [ -n "$list" ] && echo -e " Problems found:$list"
227 action "Checking broken symlinks in ${install#$WOK/$1/}..."
228 bad_sl=$(find $install -type l ! -exec test -e '{}' \; -print)
229 if [ -n "$bad_sl" ]; then
230 add 'symlink'
231 fi
232 status
233 done
235 if [ "$REPOLOGY" != '-' ]; then
236 action 'Querying Repology...'
237 repo_ver=$(repology_get ${REPOLOGY:-$PACKAGE})
238 if [ "$repo_ver" != '-' -a ! -s $fail ]; then
239 if echo " $repo_ver " | fgrep -q " $VERSION "; then
240 add 'win'
241 else
242 add 'old'
243 fi
244 fi
245 status
246 fi
247 }
250 title 'Post-check'
251 docheck $1
254 # Put badges into activity log: <a href='...' data-badges='...'>...</a>
256 action 'Updating activity log...'
257 badges_log=$(tr '\n' ' ' <$badges | sed 's| $||')
258 sed -i "s|>$1</a>$| data-badges='$badges_log'&|" $activity
259 status
261 footer
263 rm -r $data # clean