cookutils annotate modules/postcheck @ rev 1127

Typo
author Aleksej Bobylev <al.bobylev@gmail.com>
date Wed Jan 02 18:19:55 2019 +0200 (2019-01-02)
parents 54275f30a065
children 8cf66e7d3c64
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@1090 70 | sed '/<text /!d; /fill/d; /latest/d; s|.*>\(.*\)<.*|\1|; s|, | |g') # space separated list
al@1090 71 if [ -n "$versions" ]; then
al@1090 72 sed -i "/^$1 /d" $repologydb
al@1090 73 echo -e "$1\t$day\t$versions" >> $repologydb
al@1090 74 echo $versions
al@1090 75 fi
al@1090 76 fi
al@1090 77 }
al@1090 78
al@1090 79
al@1090 80 # Add the specified badge, set the fail flag and return false status
al@1090 81
al@1090 82 function add() {
al@1090 83 ! grep -q "^${1}$" $badges && echo "$1" >> $badges
al@1090 84 case $1 in
al@1109 85 ss|old|win|patch|ownover|permover) return 0;;
al@1090 86 *) echo 'yes' > $fail; false;;
al@1090 87 esac
al@1090 88 }
al@1090 89
al@1090 90
al@1090 91 function docheck() {
al@1090 92 action 'Checking build...'
al@1090 93 if grep -q "^$PACKAGE$" $broken; then
al@1090 94 if grep -q '^ERROR: unknown dep' $LOGS/$1.log; then
al@1090 95 add 'bdbroken'
al@1090 96 else
al@1090 97 add 'broken'
al@1090 98 fi
al@1090 99 status; return # no more tests since package is broken
al@1090 100 fi
al@1090 101 status
al@1090 102
al@1090 103
al@1090 104 if [ -e $WOK/$1/.arch ]; then
al@1090 105 action "Checking 'any' arch..."
al@1090 106 if [ "$(cut -d$'\t' -f2 $WOK/$1/.arch | sort -u)" == 'any' ]; then
al@1090 107 if [ "$HOST_ARCH" != 'any' ]; then
al@1090 108 add 'any'
al@1090 109 fi
al@1090 110 else
al@1090 111 if [ "$HOST_ARCH" == 'any' ]; then
al@1090 112 add 'noany'
al@1090 113 fi
al@1090 114 fi
al@1090 115 status
al@1090 116 fi
al@1090 117
al@1090 118
al@1090 119 if [ -e $WOK/$1/.patch.done ]; then
al@1090 120 # consider 'fix libtool' as no patch here
al@1090 121 if [ -n "$(grep -v 'fix.libtool' $WOK/$1/.patch.done)" ]; then
al@1090 122 add 'patch'
al@1090 123 fi
al@1090 124 fi
al@1090 125
al@1090 126
al@1090 127 for set in '' $sets; do
al@1090 128 src=$WOK/$1/source/$PACKAGE-$VERSION
al@1090 129 [ -z "$set" ] || src="$src-$set"
al@1090 130 [ -d "$src" ] || continue
al@1090 131
al@1090 132 action "Checking libtool in ${src#$WOK/$1/}..."
al@1090 133 if [ -e "$src/libtool" ]; then
al@1090 134 if ! grep -q '^fix.libtool$' $WOK/$1/.patch.done 2>/dev/null; then
al@1090 135 add 'libtool'
al@1090 136 fi
al@1090 137 else
al@1116 138 if grep -q '^\s*fix libtool' $WOK/$1/receipt 2>/dev/null; then
al@1090 139 add 'nolibtool'
al@1090 140 fi
al@1090 141 fi
al@1090 142 status
al@1090 143
al@1090 144 action "Checking site script in ${src#$WOK/$1/}..."
al@1090 145 if fgrep -q 'configure: loading site script /etc/slitaz/cook.site' $LOGS/$PACKAGE.log; then
al@1090 146 for i in bindir datadir datarootdir docdir dvidir htmldir includedir infodir libdir \
al@1090 147 libexecdir localedir localstatedir mandir oldincludedir pdfdir psdir sbindir \
al@1090 148 sharedstatedir sysconfdir; do
al@1090 149 if fgrep -q -e "--$i=" $WOK/$1/receipt; then
al@1090 150 add 'ss'
al@1090 151 break
al@1090 152 fi
al@1090 153 done
al@1090 154 fi
al@1090 155 status
al@1090 156 done
al@1090 157
al@1090 158
al@1090 159 for set in '' $sets; do
al@1090 160 install="$WOK/$1/install"
al@1090 161 [ -z "$set" ] || install="$install-$set"
al@1090 162 [ -d "$install" ] || continue
al@1090 163
al@1090 164 action "Checking ownership in ${install#$WOK/$1/}..."
al@1090 165
al@1090 166 IFS=$'\n'
al@1090 167 bad_own="$(find $install -type f \( ! -user 0 -a ! -group 0 \))"
al@1113 168 list=$(mktemp)
al@1090 169 if [ -n "$bad_own" ]; then
al@1090 170 if [ -e $overrides_exp ]; then
al@1090 171 # There may be mix of overridden and not-overridden ownership
al@1090 172 # in the package. Return status 'Done' only if all the ownership
al@1090 173 # was overridden.
al@1090 174 result=''
al@1090 175 for i in $bad_own; do
al@1090 176 if fgrep -q "$(stat -c %u:%g "$i") ${i#$install}" $overrides_exp ||
al@1090 177 fgrep -q "$(stat -c %U:%G "$i") ${i#$install}" $overrides_exp; then
al@1090 178 add 'ownover'
al@1090 179 else
al@1090 180 add 'own'
al@1113 181 printf " %s:%s %s\n" "$(stat -c %u:%g "$i")" "${i#$install}" >>$list
al@1090 182 result='bad'
al@1090 183 fi
al@1090 184 done
al@1090 185 [ "$result" == '' ] # OK, all was overridden
al@1090 186 else
al@1113 187 for i in $bad_own; do
al@1113 188 printf " %s:%s %s\n" "$(stat -c %u:%g "$i")" "${i#$install}" >>$list
al@1113 189 done
al@1090 190 add 'own'
al@1090 191 fi
al@1090 192 fi
al@1090 193 status
al@1090 194 unset IFS
al@1113 195 if [ -s "$list" ]; then
al@1113 196 echo " Problems found:"
al@1113 197 sort -k2 $list
al@1113 198 fi
al@1113 199 rm $list
al@1090 200
al@1090 201
al@1090 202 action "Checking permissions in ${install#$WOK/$1/}..."
al@1090 203
al@1113 204 IFS=$'\n'
al@1090 205 bad_files="$(find $install -type f \( ! -perm 644 -a ! -perm 755 \))"
al@1090 206 bad_dirs="$(find $install -type d ! -perm 755)"
al@1113 207 list=$(mktemp)
al@1090 208 if [ -n "$bad_files$bad_dirs" ]; then
al@1090 209 if [ -e $overrides_exp ]; then
al@1090 210 # There may be mix of overridden and not-overridden permissions
al@1090 211 # in the package. Return status 'Done' only if all the permissions
al@1090 212 # was overridden.
al@1090 213 result=''
al@1090 214 for i in $bad_files; do
al@1090 215 if fgrep -q "$(printf "%04d\t%s" "$(stat -c%a "$i")" "${i#$install}")" $overrides_exp; then
al@1090 216 add 'permover'
al@1090 217 else
al@1090 218 add 'perm'
al@1113 219 printf " %04d %s\n" "$(stat -c %a "$i")" "${i#$install}" >>$list
al@1090 220 result='bad'
al@1090 221 fi
al@1090 222 done
al@1090 223 for i in $bad_dirs; do
al@1090 224 if fgrep -q "$(printf "%04d" $(stat -c %a "$i")) ${i#$install}/" $overrides_exp; then
al@1090 225 add 'permover'
al@1090 226 else
al@1090 227 add 'perm'
al@1113 228 printf " %04d %s\n" "$(stat -c %a "$i")" "${i#$install}/" >>$list
al@1090 229 result='bad'
al@1090 230 fi
al@1090 231 done
al@1090 232 [ "$result" == '' ] # OK, all was overridden
al@1090 233 else
al@1113 234 for i in $bad_files; do
al@1113 235 printf " %04d %s\n" "$(stat -c %a "$i")" "${i#$install}" >>$list
al@1113 236 done
al@1113 237 for i in $bad_dirs; do
al@1113 238 printf " %04d %s\n" "$(stat -c %a "$i")" "${i#$install}/" >>$list
al@1113 239 done
al@1090 240 add 'perm'
al@1090 241 fi
al@1090 242 fi
al@1090 243 status
al@1113 244 unset IFS
al@1113 245 if [ -s "$list" ]; then
al@1113 246 echo " Problems found:"
al@1113 247 sort -k2 $list
al@1113 248 fi
al@1113 249 rm $list
al@1090 250
al@1090 251 action "Checking broken symlinks in ${install#$WOK/$1/}..."
al@1113 252
al@1113 253 IFS=$'\n'
al@1113 254 bad_sl="$(find $install -type l ! -exec test -e '{}' \; -print)"
al@1113 255 result=''
al@1090 256 if [ -n "$bad_sl" ]; then
al@1090 257 add 'symlink'
al@1113 258 result='bad'
al@1090 259 fi
al@1113 260 [ "$result" == '' ]; status
al@1113 261
al@1113 262 if [ "$result" == 'bad' ]; then
al@1113 263 echo " Problems found:"
al@1113 264 for i in $bad_sl; do
al@1113 265 stat -c ' %N'
al@1113 266 done
al@1113 267 fi
al@1113 268 unset IFS
al@1090 269 done
al@1090 270
al@1090 271 if [ "$REPOLOGY" != '-' ]; then
al@1090 272 action 'Querying Repology...'
al@1090 273 repo_ver=$(repology_get ${REPOLOGY:-$PACKAGE})
al@1116 274 if [ "$repo_ver" != '-' ]; then
al@1090 275 if echo " $repo_ver " | fgrep -q " $VERSION "; then
al@1116 276 [ -s $fail ] || add 'win'
al@1090 277 else
al@1090 278 add 'old'
al@1090 279 fi
al@1090 280 fi
al@1090 281 status
al@1090 282 fi
al@1124 283
al@1124 284 unset changed notchanged
al@1124 285 fgrep -q 'The release checksum has changed.' $LOGS/$1.log && changed='yes'
al@1124 286 fgrep -q 'The release checksum has not changed.' $LOGS/$1.log && notchanged='yes'
al@1124 287 if [ -z "$changed" -a -n "$notchanged" ]; then
al@1124 288 add 'equal'
al@1124 289 fi
al@1090 290 }
al@1090 291
al@1090 292
al@1090 293 title 'Post-check'
al@1090 294 docheck $1
al@1090 295
al@1090 296
al@1090 297 # Put badges into activity log: <a href='...' data-badges='...'>...</a>
al@1090 298
al@1090 299 action 'Updating activity log...'
al@1090 300 badges_log=$(tr '\n' ' ' <$badges | sed 's| $||')
al@1090 301 sed -i "s|>$1</a>$| data-badges='$badges_log'&|" $activity
al@1090 302 status
al@1090 303
al@1090 304 footer
al@1090 305
al@1090 306 rm -r $data # clean
al@1126 307
al@1126 308 # move badges to the global database
al@1127 309 sed -i "/^$PACKAGE /d" $badges_global
al@1126 310 echo "$PACKAGE $(tr '\n' ' ' <$badges | sed 's| $||')" >>$badges_global
al@1126 311 rm $badges