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