cookutils annotate modules/postcheck @ rev 1146

cook: allow built in aufs
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Jul 28 07:28:04 2020 +0000 (2020-07-28)
parents 0385051c3996
children
rev   line source
al@1090 1 #!/bin/sh
al@1090 2 #
al@1090 3 # postcheck - module of the SliTaz Cook
al@1090 4 # Copyright (C) SliTaz GNU/Linux - GNU GPL v3
al@1090 5 #
al@1090 6 # Check for different cases at the end and add badges
al@1090 7
al@1090 8 . /usr/lib/slitaz/libcook.sh
al@1090 9 . /etc/slitaz/cook.conf
al@1090 10 . $WOK/$1/receipt
al@1090 11
al@1090 12 data="$(mktemp -d)" # temporary data for post-checking
al@1090 13
al@1090 14 repologydb="$CACHE/repology.db"
al@1090 15
al@1090 16 badges="$WOK/$1/.badges"
al@1090 17 echo -n > $badges # clean badges
al@1090 18
al@1126 19 badges_global="$CACHE/badges"; touch $badges_global
al@1126 20
al@1090 21 overrides="$WOK/$1/stuff/overrides"
al@1090 22 overrides_exp="$data/overrides_exp"
al@1090 23 fail="$data/fail" # file used as flag, if will be empty if no fails were found
al@1090 24
al@1090 25 sets=$(echo -n $SPLIT | awk 'BEGIN { RS = " "; FS = ":"; }
al@1090 26 { if ($2 && ! set[$2]) { printf("%s ", $2); set[$2] = "1"; } }')
al@1090 27
al@1090 28 # Format of stuff/overrides:
al@1090 29 # <rule> {<rule> ...} <fil[e]*>
al@1090 30 # One or more rules may indicate:
al@1090 31 # - ownership in form '80:80' (numeric UID:GID) or 'www:www' (string UID:GID)
al@1090 32 # - permissions in form '0600' (four octal digits)
al@1090 33 # File is space free string specified one (or more - using placeholders) files
al@1090 34
al@1090 35
al@1090 36 # Expand overrides to the simple form: <rule><tab><file>
al@1090 37
al@1090 38 if [ -e "$overrides" ]; then
al@1090 39 IFS=$'\n'
al@1090 40 while read line; do
al@1090 41 rules=${line% *}; file=${line##* }
al@1090 42
al@1090 43 for set in '' $sets; do
al@1090 44 install="$WOK/$1/install"
al@1090 45 [ -z "$set" ] || install="$install-$set"
al@1090 46 [ -d "$install" ] || continue
al@1090 47 for file in $(ls -d $install$file); do
al@1090 48 for rule in $rules; do
al@1090 49 echo "$rule ${file#$install}" >> $overrides_exp
al@1090 50 done
al@1090 51 done
al@1090 52 done
al@1090 53 done < $overrides
al@1090 54 unset IFS
al@1090 55 fi
al@1090 56
al@1090 57
al@1090 58 # Get latest packaged version from Repology
al@1090 59
al@1090 60 repology_get() {
al@1090 61 local found versions day=$(date +%j) # %j is the number of the day in the year
al@1090 62 found=$(awk -F$'\t' -vpkg="$1" -vday="$day" '{
al@1090 63 if ($1 == pkg && $2 == day) { print $3; exit; }
al@1090 64 }' $repologydb)
al@1090 65 if [ -n "$found" ]; then
al@1090 66 echo "$found"
al@1090 67 else
al@1090 68 # set HOST_WGET in cook.conf
al@1090 69 versions=$($HOST_WGET -q -T 20 -O- https://repology.org/badge/latest-versions/$1.svg \
al@1142 70 | sed 's|<text |\n&|g; s|</text>|&\n|g' \
al@1090 71 | sed '/<text /!d; /fill/d; /latest/d; s|.*>\(.*\)<.*|\1|; s|, | |g') # space separated list
al@1090 72 if [ -n "$versions" ]; then
al@1090 73 sed -i "/^$1 /d" $repologydb
al@1090 74 echo -e "$1\t$day\t$versions" >> $repologydb
al@1090 75 echo $versions
al@1090 76 fi
al@1090 77 fi
al@1090 78 }
al@1090 79
al@1090 80
al@1090 81 # Add the specified badge, set the fail flag and return false status
al@1090 82
al@1090 83 function add() {
al@1090 84 ! grep -q "^${1}$" $badges && echo "$1" >> $badges
al@1090 85 case $1 in
al@1109 86 ss|old|win|patch|ownover|permover) return 0;;
al@1090 87 *) echo 'yes' > $fail; false;;
al@1090 88 esac
al@1090 89 }
al@1090 90
al@1090 91
al@1090 92 function docheck() {
al@1090 93 action 'Checking build...'
al@1090 94 if grep -q "^$PACKAGE$" $broken; then
al@1090 95 if grep -q '^ERROR: unknown dep' $LOGS/$1.log; then
al@1090 96 add 'bdbroken'
al@1090 97 else
al@1090 98 add 'broken'
al@1090 99 fi
al@1090 100 status; return # no more tests since package is broken
al@1090 101 fi
al@1090 102 status
al@1090 103
al@1090 104
al@1090 105 if [ -e $WOK/$1/.arch ]; then
al@1090 106 action "Checking 'any' arch..."
al@1090 107 if [ "$(cut -d$'\t' -f2 $WOK/$1/.arch | sort -u)" == 'any' ]; then
al@1090 108 if [ "$HOST_ARCH" != 'any' ]; then
al@1090 109 add 'any'
al@1090 110 fi
al@1090 111 else
al@1090 112 if [ "$HOST_ARCH" == 'any' ]; then
al@1090 113 add 'noany'
al@1090 114 fi
al@1090 115 fi
al@1090 116 status
al@1090 117 fi
al@1090 118
al@1090 119
al@1090 120 if [ -e $WOK/$1/.patch.done ]; then
al@1090 121 # consider 'fix libtool' as no patch here
al@1090 122 if [ -n "$(grep -v 'fix.libtool' $WOK/$1/.patch.done)" ]; then
al@1090 123 add 'patch'
al@1090 124 fi
al@1090 125 fi
al@1090 126
al@1090 127
al@1090 128 for set in '' $sets; do
al@1090 129 src=$WOK/$1/source/$PACKAGE-$VERSION
al@1090 130 [ -z "$set" ] || src="$src-$set"
al@1090 131 [ -d "$src" ] || continue
al@1090 132
al@1090 133 action "Checking libtool in ${src#$WOK/$1/}..."
al@1090 134 if [ -e "$src/libtool" ]; then
al@1090 135 if ! grep -q '^fix.libtool$' $WOK/$1/.patch.done 2>/dev/null; then
al@1090 136 add 'libtool'
al@1090 137 fi
al@1090 138 else
al@1116 139 if grep -q '^\s*fix libtool' $WOK/$1/receipt 2>/dev/null; then
al@1090 140 add 'nolibtool'
al@1090 141 fi
al@1090 142 fi
al@1090 143 status
al@1090 144
al@1090 145 action "Checking site script in ${src#$WOK/$1/}..."
al@1090 146 if fgrep -q 'configure: loading site script /etc/slitaz/cook.site' $LOGS/$PACKAGE.log; then
al@1090 147 for i in bindir datadir datarootdir docdir dvidir htmldir includedir infodir libdir \
al@1090 148 libexecdir localedir localstatedir mandir oldincludedir pdfdir psdir sbindir \
al@1090 149 sharedstatedir sysconfdir; do
al@1090 150 if fgrep -q -e "--$i=" $WOK/$1/receipt; then
al@1090 151 add 'ss'
al@1090 152 break
al@1090 153 fi
al@1090 154 done
al@1090 155 fi
al@1090 156 status
al@1090 157 done
al@1090 158
al@1090 159
al@1090 160 for set in '' $sets; do
al@1090 161 install="$WOK/$1/install"
al@1090 162 [ -z "$set" ] || install="$install-$set"
al@1090 163 [ -d "$install" ] || continue
al@1090 164
al@1090 165 action "Checking ownership in ${install#$WOK/$1/}..."
al@1090 166
al@1090 167 IFS=$'\n'
al@1090 168 bad_own="$(find $install -type f \( ! -user 0 -a ! -group 0 \))"
al@1113 169 list=$(mktemp)
al@1090 170 if [ -n "$bad_own" ]; then
al@1090 171 if [ -e $overrides_exp ]; then
al@1090 172 # There may be mix of overridden and not-overridden ownership
al@1090 173 # in the package. Return status 'Done' only if all the ownership
al@1090 174 # was overridden.
al@1090 175 result=''
al@1090 176 for i in $bad_own; do
al@1090 177 if fgrep -q "$(stat -c %u:%g "$i") ${i#$install}" $overrides_exp ||
al@1090 178 fgrep -q "$(stat -c %U:%G "$i") ${i#$install}" $overrides_exp; then
al@1090 179 add 'ownover'
al@1090 180 else
al@1090 181 add 'own'
al@1113 182 printf " %s:%s %s\n" "$(stat -c %u:%g "$i")" "${i#$install}" >>$list
al@1090 183 result='bad'
al@1090 184 fi
al@1090 185 done
al@1090 186 [ "$result" == '' ] # OK, all was overridden
al@1090 187 else
al@1113 188 for i in $bad_own; do
al@1113 189 printf " %s:%s %s\n" "$(stat -c %u:%g "$i")" "${i#$install}" >>$list
al@1113 190 done
al@1090 191 add 'own'
al@1090 192 fi
al@1090 193 fi
al@1090 194 status
al@1090 195 unset IFS
al@1113 196 if [ -s "$list" ]; then
al@1113 197 echo " Problems found:"
al@1113 198 sort -k2 $list
al@1113 199 fi
al@1113 200 rm $list
al@1090 201
al@1090 202
al@1090 203 action "Checking permissions in ${install#$WOK/$1/}..."
al@1090 204
al@1113 205 IFS=$'\n'
al@1090 206 bad_files="$(find $install -type f \( ! -perm 644 -a ! -perm 755 \))"
al@1090 207 bad_dirs="$(find $install -type d ! -perm 755)"
al@1113 208 list=$(mktemp)
al@1090 209 if [ -n "$bad_files$bad_dirs" ]; then
al@1090 210 if [ -e $overrides_exp ]; then
al@1090 211 # There may be mix of overridden and not-overridden permissions
al@1090 212 # in the package. Return status 'Done' only if all the permissions
al@1090 213 # was overridden.
al@1090 214 result=''
al@1090 215 for i in $bad_files; do
al@1090 216 if fgrep -q "$(printf "%04d\t%s" "$(stat -c%a "$i")" "${i#$install}")" $overrides_exp; then
al@1090 217 add 'permover'
al@1090 218 else
al@1090 219 add 'perm'
al@1113 220 printf " %04d %s\n" "$(stat -c %a "$i")" "${i#$install}" >>$list
al@1090 221 result='bad'
al@1090 222 fi
al@1090 223 done
al@1090 224 for i in $bad_dirs; do
al@1090 225 if fgrep -q "$(printf "%04d" $(stat -c %a "$i")) ${i#$install}/" $overrides_exp; then
al@1090 226 add 'permover'
al@1090 227 else
al@1090 228 add 'perm'
al@1113 229 printf " %04d %s\n" "$(stat -c %a "$i")" "${i#$install}/" >>$list
al@1090 230 result='bad'
al@1090 231 fi
al@1090 232 done
al@1090 233 [ "$result" == '' ] # OK, all was overridden
al@1090 234 else
al@1113 235 for i in $bad_files; do
al@1113 236 printf " %04d %s\n" "$(stat -c %a "$i")" "${i#$install}" >>$list
al@1113 237 done
al@1113 238 for i in $bad_dirs; do
al@1113 239 printf " %04d %s\n" "$(stat -c %a "$i")" "${i#$install}/" >>$list
al@1113 240 done
al@1090 241 add 'perm'
al@1090 242 fi
al@1090 243 fi
al@1090 244 status
al@1113 245 unset IFS
al@1113 246 if [ -s "$list" ]; then
al@1113 247 echo " Problems found:"
al@1113 248 sort -k2 $list
al@1113 249 fi
al@1113 250 rm $list
al@1090 251
al@1090 252 action "Checking broken symlinks in ${install#$WOK/$1/}..."
al@1113 253
al@1113 254 IFS=$'\n'
al@1113 255 bad_sl="$(find $install -type l ! -exec test -e '{}' \; -print)"
al@1113 256 result=''
al@1090 257 if [ -n "$bad_sl" ]; then
al@1090 258 add 'symlink'
al@1113 259 result='bad'
al@1090 260 fi
al@1113 261 [ "$result" == '' ]; status
al@1113 262
al@1113 263 if [ "$result" == 'bad' ]; then
al@1113 264 echo " Problems found:"
al@1113 265 for i in $bad_sl; do
al@1131 266 stat -c ' %N' $i
al@1113 267 done
al@1113 268 fi
al@1113 269 unset IFS
al@1090 270 done
al@1090 271
al@1090 272 if [ "$REPOLOGY" != '-' ]; then
al@1090 273 action 'Querying Repology...'
al@1090 274 repo_ver=$(repology_get ${REPOLOGY:-$PACKAGE})
al@1116 275 if [ "$repo_ver" != '-' ]; then
al@1090 276 if echo " $repo_ver " | fgrep -q " $VERSION "; then
al@1116 277 [ -s $fail ] || add 'win'
al@1090 278 else
al@1090 279 add 'old'
al@1090 280 fi
al@1090 281 fi
al@1090 282 status
al@1090 283 fi
al@1124 284
al@1124 285 unset changed notchanged
al@1124 286 fgrep -q 'The release checksum has changed.' $LOGS/$1.log && changed='yes'
al@1124 287 fgrep -q 'The release checksum has not changed.' $LOGS/$1.log && notchanged='yes'
al@1124 288 if [ -z "$changed" -a -n "$notchanged" ]; then
al@1124 289 add 'equal'
al@1124 290 fi
al@1090 291 }
al@1090 292
al@1090 293
al@1090 294 title 'Post-check'
al@1090 295 docheck $1
al@1090 296
al@1090 297
al@1090 298 # Put badges into activity log: <a href='...' data-badges='...'>...</a>
al@1090 299
al@1090 300 action 'Updating activity log...'
al@1090 301 badges_log=$(tr '\n' ' ' <$badges | sed 's| $||')
al@1090 302 sed -i "s|>$1</a>$| data-badges='$badges_log'&|" $activity
al@1090 303 status
al@1090 304
al@1090 305 footer
al@1090 306
al@1090 307 rm -r $data # clean
al@1126 308
al@1126 309 # move badges to the global database
al@1127 310 sed -i "/^$PACKAGE /d" $badges_global
al@1126 311 echo "$PACKAGE $(tr '\n' ' ' <$badges | sed 's| $||')" >>$badges_global
al@1126 312 rm $badges
al@1128 313
al@1128 314 tosort=$(mktemp)
al@1128 315 cp $badges_global $tosort
al@1128 316 sort -o $badges_global $tosort
al@1128 317 rm $tosort