cookutils view modules/postcheck @ rev 1109

modules/postcheck: overridden permissions/ownership aren't a problem too
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Dec 03 03:28:01 2018 +0200 (2018-12-03)
parents 7fdea1dfb4e2
children 41c25139be4d
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|ownover|permover) 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 list="$list$(printf "\n %s:%s %s" "$(stat -c %u:%g "$i")" "${i#$install}")"
179 result='bad'
180 fi
181 done
182 [ "$result" == '' ] # OK, all was overridden
183 else
184 add 'own'
185 fi
186 fi
187 status
188 unset IFS
189 [ -n "$list" ] && echo -e " Problems found:$list"
192 action "Checking permissions in ${install#$WOK/$1/}..."
194 bad_files="$(find $install -type f \( ! -perm 644 -a ! -perm 755 \))"
195 bad_dirs="$(find $install -type d ! -perm 755)"
196 list=''
197 if [ -n "$bad_files$bad_dirs" ]; then
198 if [ -e $overrides_exp ]; then
199 # There may be mix of overridden and not-overridden permissions
200 # in the package. Return status 'Done' only if all the permissions
201 # was overridden.
202 result=''
203 for i in $bad_files; do
204 if fgrep -q "$(printf "%04d\t%s" "$(stat -c%a "$i")" "${i#$install}")" $overrides_exp; then
205 add 'permover'
206 else
207 add 'perm'
208 list="$list$(printf "\n %04d %s" "$(stat -c %a "$i")" "${i#$install}")"
209 result='bad'
210 fi
211 done
212 for i in $bad_dirs; do
213 if fgrep -q "$(printf "%04d" $(stat -c %a "$i")) ${i#$install}/" $overrides_exp; then
214 add 'permover'
215 else
216 add 'perm'
217 list="$list$(printf "\n %04d %s" "$(stat -c %a "$i")" "${i#$install}/")"
218 result='bad'
219 fi
220 done
221 [ "$result" == '' ] # OK, all was overridden
222 else
223 add 'perm'
224 fi
225 fi
226 status
227 [ -n "$list" ] && echo -e " Problems found:$list"
229 action "Checking broken symlinks in ${install#$WOK/$1/}..."
230 bad_sl=$(find $install -type l ! -exec test -e '{}' \; -print)
231 if [ -n "$bad_sl" ]; then
232 add 'symlink'
233 fi
234 status
235 done
237 if [ "$REPOLOGY" != '-' ]; then
238 action 'Querying Repology...'
239 repo_ver=$(repology_get ${REPOLOGY:-$PACKAGE})
240 if [ "$repo_ver" != '-' -a ! -s $fail ]; then
241 if echo " $repo_ver " | fgrep -q " $VERSION "; then
242 add 'win'
243 else
244 add 'old'
245 fi
246 fi
247 status
248 fi
249 }
252 title 'Post-check'
253 docheck $1
256 # Put badges into activity log: <a href='...' data-badges='...'>...</a>
258 action 'Updating activity log...'
259 badges_log=$(tr '\n' ' ' <$badges | sed 's| $||')
260 sed -i "s|>$1</a>$| data-badges='$badges_log'&|" $activity
261 status
263 footer
265 rm -r $data # clean