cookutils diff lighttpd/index.cgi @ rev 1082

Fix $MAINTAINER fetch for the case "User <user@example.com>"; cache/proxy/extract Repology badges for maintainers
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu Jul 12 18:01:24 2018 +0300 (2018-07-12)
parents 8683bf3e7c02
children a97d05aa96a3
line diff
     1.1 --- a/lighttpd/index.cgi	Tue Jul 10 20:11:48 2018 +0300
     1.2 +++ b/lighttpd/index.cgi	Thu Jul 12 18:01:24 2018 +0300
     1.3 @@ -37,9 +37,10 @@
     1.4  cooknotes="$CACHE/cooknotes"
     1.5  cooktime="$CACHE/cooktime"
     1.6  wokrev="$CACHE/wokrev"
     1.7 -webstat="$CACHE/webstat"
     1.8 +webstat="$CACHE/webstat"		# note, file should be previously created with write permissions for www
     1.9  splitdb="$CACHE/split.db"
    1.10  maintdb="$CACHE/maint.db"
    1.11 +repologydb="$CACHE/repology.db"	# note, file should be previously created with write permissions for www
    1.12  
    1.13  # Path to markdown to html convertor
    1.14  cmark_opts='--smart -e table -e strikethrough -e autolink -e tagfilter'
    1.15 @@ -253,6 +254,38 @@
    1.16  }
    1.17  
    1.18  
    1.19 +# Proxy to the Repology
    1.20 +# Problems:
    1.21 +# 1. Function "latest packaged version" widely used here, and it has no JSON API, but only SVG badge.
    1.22 +# 2. So, all version comparisons can be only visually and not automated.
    1.23 +# 3. When the thousands of badges present on the web page, many of them are broken (maybe server
    1.24 +#    drops requests), while our server displays status icons well.
    1.25 +# 4. Default badges are wide and not customizable.
    1.26 +# Solution:
    1.27 +# 1. Make local cache. Update it on demand, but no more than once a day (Repology cached info
    1.28 +#    on a hourly basis). Use cached values when they are not expired.
    1.29 +# 2. Extract and save version(s) from the SVG badges. Values can be compared in the scripts as well
    1.30 +#    as custom badges may be provided.
    1.31 +
    1.32 +repology_get() {
    1.33 +	local found versions day=$(date +%j)		# %j is the number of the day in the year
    1.34 +	found=$(awk -F$'\t' -vpkg="$1" -vday="$day" '{
    1.35 +		if ($1 == pkg && $2 == day) { print $3; exit; }
    1.36 +	}' $repologydb)
    1.37 +	if [ -n "$found" ]; then
    1.38 +		echo "$found"
    1.39 +	else
    1.40 +		versions=$(wget -q -T 20 -O- https://repology.org/badge/latest-versions/$1.svg \
    1.41 +		| sed '/<text /!d; /fill/d; /latest/d; s|.*>\(.*\)<.*|\1|; s|, | |g') # space separated list
    1.42 +		if [ -n "$versions" ]; then
    1.43 +			sed -i "/^$1	/d" $repologydb
    1.44 +			echo -e "$1\t$day\t$versions" >> $repologydb
    1.45 +			echo $versions
    1.46 +		fi
    1.47 +	fi
    1.48 +}
    1.49 +
    1.50 +
    1.51  # Query '?pct=<package>': update percentage
    1.52  
    1.53  if [ -n "$(GET pct)" ]; then
    1.54 @@ -1143,18 +1176,22 @@
    1.55  							unset VERSION; REPOLOGY=$pkg
    1.56  							. $wok/$pkg/receipt
    1.57  							if [ "$REPOLOGY" == '-' ]; then
    1.58 -								repo_info=" </td><td> "
    1.59 +								unset repo_info1 repo_info2
    1.60  							else
    1.61 -								repo_info="<a href='https://repology.org/metapackage/$REPOLOGY' target='_blank'
    1.62 -									rel='noopener noreferrer' title='latest packaged version(s)'>
    1.63 -									<img src='https://repology.org/badge/latest-versions/$REPOLOGY.svg' alt='latest packaged version(s)'>
    1.64 -									</a></td>"
    1.65 +								repo_ver=$(repology_get $REPOLOGY)
    1.66 +								if echo " $repo_ver " | fgrep -q " $VERSION "; then
    1.67 +									icon='actual'
    1.68 +								else
    1.69 +									icon='update'
    1.70 +								fi
    1.71 +								repo_info1="<a class='icon $icon' href='https://repology.org/metapackage/$REPOLOGY' target='_blank'"
    1.72 +								repo_info2="rel='noopener noreferrer' title='latest packaged version(s)'>${repo_ver// /, }</a>"
    1.73  							fi
    1.74  							cat <<EOT
    1.75  		<tr>
    1.76  			<td><img src="$base/s/$pkg"> <a href="$pkg">$pkg</a></td>
    1.77  			<td>$VERSION</td>
    1.78 -			<td>$repo_info</td>
    1.79 +			<td>$repo_info1 $repo_info2</td>
    1.80  		</tr>
    1.81  EOT
    1.82  					done