#!/bin/bash usage() { >&2 echo 'Verwendung: ' >&2 echo " $0"' [-f|--force] [-j|--jobs=${jobs}]' >&2 echo ' -f|--force: prüfe Versionen unhabhängig von Zeit der letzten Prüfung' >&2 echo ' -j|--jobs: Anzahl parallel auszufuehrender Anfragen' >&2 echo ' -m: maschinenlesbare Ausgabe erzeugen' exit 1 } me="$(readlink -f $0)" cd $(dirname "${me}") versionenDatei="/var/cache/$(basename "$(dirname "${me}")").lastVersions" jobs=0 maschinenlesbar=false [ ! -r "${versionenDatei}" ] && force=true || force=false eval set -- "$(getopt -o fj:m --long force,jobs: -n "$(basename "$0")" -- "$@" || echo "usage")" args=("$@") optArgs=() while true do case $1 in -f|--force) force=true optArgs[${#optArgs[@]}]="-f" ;; -j|--jobs) shift jobs="$1" optArgs[${#optArgs[@]}]="-j" optArgs[${#optArgs[@]}]="$1" ;; -m) optArgs[${#optArgs[@]}]="-m" maschinenlesbar=true ;; --) shift break ;; *) >&2 echo "FEHLER: Verstehe Option \"$1\" doch nicht! Ich beende." rm -rf "${tmpDir}" usage esac shift done versionenErmitteln=${force} ! ${versionenErmitteln} && [ $(head -n1 "${versionenDatei}") -le $[$(date "+%s")-300] ] && versionenErmitteln=true ${maschinenlesbar} && versionenErmitteln=true versionenSchreiben=${versionenErmitteln} [ ! -w "${versionenDatei}" ] && versionenSchreiben=false ${maschinenlesbar} && versionenSchreiben=false if [ $# -eq 0 ] then if ${versionenSchreiben} then tmpFile="$(mktemp /tmp/versionen.XXXXXX)" date "+%s" > "${tmpFile}" set -o pipefail ${me} "${args[@]}" $(echo */PKGBUILD | tr " " "\n" | sed "s|/PKGBUILD||") | tee -a "${tmpFile}" err=$? set +o pipefail cat "${tmpFile}" > "${versionenDatei}" rm "${tmpFile}" elif ! ${versionenErmitteln} then cat "${versionenDatei}" | \ ( \ read dummy cat ) err=$? else ${me} "${args[@]}" $(echo */PKGBUILD | tr " " "\n" | sed "s|/PKGBUILD||") err=$? fi exit ${err} elif [ $# -eq 1 ] && ${versionenErmitteln} then . $1/PKGBUILD srcKnown=false for src in "${source[@]}" do src="${src#*::}" if [ "${pkgname}" == "pgplot-for-ifeffit" ] then remVer="$( curl -o - "ftp://ftp.astro.caltech.edu/pub/pgplot/" 2> /dev/null | \ grep "\spgplot[0-9.]\+\.tar\.gz -> \S\+\$" | \ sed "s|^.*\spgplot\([0-9.]\+\)\.tar\.gz -> \S\+\$|\1|" | \ sort -V | \ tail -n1 )" elif echo "${src}" | \ grep -q "^https://pypi\.python\.org/packages/" then qu="$( echo "${src}" | \ sed 's|^\(.*\)/packages/.*/\([^/]\+\)-[^/-]\+\.tar\.gz$|\1/pypi/\2/|' )" remVer="$( curl -o - "${qu}" 2> /dev/null | \ tr "\"" "\n" | \ grep "^/pypi/${pkgname#*-}/[0-9.-]\+\$" | \ sed "s|^/pypi/${pkgname#*-}/\([0-9.-]\+\)\$|\1|" | \ sort -V | \ tail -n1 )" elif echo "${src}" | \ grep -q "//bundles\.openttdcoop\.org/" then qu="$( echo "${src}" | \ sed 's|^\(https\?://\([^/]\+/\)\{3\}\).*$|\1|' )" remVer="$( curl -o - "${qu}" 2> /dev/null | \ tr "\"" "\n" | \ grep '^[0-9.]\+/$' | \ sed 's|/$||' | \ sort -V | \ tail -n1 )" elif echo "${src}" | \ grep -q "//opensources\.eckner\.net/" then qu=${src#*::} qu=${qu%-*} quNam=${qu#*=} remVer=$( \ curl -o - "$(\ echo "${qu}" | \ sed "s|\?dl=|?ls=|" \ )" 2> /dev/null | \ tr "<>" "\n\n" | \ grep "^${quNam}-" | \ sed "s|^${quNam}-||" | \ sort -V | \ tail -n1 \ ) elif echo "${src}" | \ grep -q "//search\.m\?cpan\.org/CPAN/authors/" then quVer=$( \ echo "${src%/*}" | \ sed "s#//search\.m\?cpan\.org/CPAN/#//www.cpan.org/#" | \ sed "s|^https:|http:|" | \ sed "s|\([^/]\)\$|\1/|" ) quNam=${src##*/} quNam=${quNam%-*} quEnd=$( \ echo "${src##*-}" | sed "s|^v\?[0-9.]*||" ) remVer=$( \ curl -o - "${quVer}" 2> /dev/null | \ tr "\"" "\n" | \ grep "^${quNam}-v\?[0-9.-]*\.${quEnd}\$" | \ sed "s|^${quNam}-v\?\(.*\)\.${quEnd}\$|\1|" | \ sort -V | \ tail -n1 \ ) elif echo "${src}" | \ grep -q "//cpan\.org/\|//cpan\.metacpan\.org/authors/\|cpan\.org/modules/by-module/" then quVer=$( \ echo "${src%/*}/" | \ sed "s|//cpan\.org/|//www.cpan.org/|" ) quNam=${src##*/} quNam=${quNam%-*} quEnd=$( \ echo "${src##*-}" | sed "s|^v\?[0-9.]*||" ) remVer=$( \ curl -o - "${quVer}" 2> /dev/null | \ tr "\"" "\n" | \ grep "^${quNam}-v\?[0-9.-]*\.${quEnd}\$" | \ sed "s|^${quNam}-v\?\(.*\)\.${quEnd}\$|\1|" | \ sort -V | \ tail -n1 \ ) elif echo "${src}" | \ grep -q "ftp://" then quVer="${src%/*}/" quNam=${src##*/} quEnd=$( \ echo "${quNam}" | sed "s|^.*v\?[0-9.]*[0-9]||" \ ) quNam=$( \ echo ${quNam} | \ sed "s|v\?[0-9.]\+.*\$||" \ ) tmpVer=$( \ curl -o - "${quVer}" 2> /dev/null | \ awk '{print $9}' | \ grep "^${quNam}v\?[0-9.]*${quEnd}\$" | \ sed "s|^${quNam}v\?\([0-9.]*\)${quEnd}\$|\1|" | \ sort -V | \ tail -n1 \ ) [ "${pkgname}" == "pgplot" ] && remVer="${tmpVer:0:1}.${tmpVer:1:1}.${tmpVer:2}" || remVer="${tmpVer}" elif echo "${src}" | \ grep -q "//arch\.eckner\.net/" then quVer="${src%/*}" quVer="${quVer#*::}" quNam=${src##*/} quNam=${quNam%-*} quNam=${quNam%-*} quNam=${quNam%-*} quEnd=${src##*-} quEnd=${quEnd#*.} remVer=$( \ curl -o - "${quVer}/" 2> /dev/null | \ tr "\"" "\n" | \ grep "^${quNam}\(-[^-]*\)\{3\}\.${quEnd}\$" | \ sed "s|^${quNam}-\([^-]*\)\(-[^-]*\)\{2\}\.${quEnd}\$|\1|" | \ sort -V | \ tail -n1 \ ) elif echo "${src}" | \ grep -q "//github.com/" then quVer=$( echo "${src#*::}" | \ sed "s|/archive/[^/]*\$|/releases|" ) quNam=/${quVer#*.com/}/tag/ remVer=$( \ curl -o - "${quVer}" 2> /dev/null | \ tr "\"" "\n" | \ grep "^${quNam}" | \ sed "s|^${quNam}||" | \ sort -V | \ tail -n1 \ ) elif echo "${src}" | \ grep -q "//downloads\.sourceforge\.net/sourceforge/" then quVer=$( \ echo "${src}" | \ sed "s|//downloads\.sourceforge\.net/sourceforge/\([^/]*\)/[^/]*\$|//sourceforge.net/projects/\1/files/\1/|" | \ sed "s|^http:|https:|" ) remVer=$( \ curl -o - "${quVer}" 2> /dev/null | \ tr "\"" "\n" | \ grep "^${quVer#*sourceforge.net}[0-9.-]" | \ sed "s|^${quVer#*sourceforge.net}\([0-9.-]\+\).*\$|\1|" | \ sed "s|-\$||" | \ sort -V | \ tail -n1 \ ) elif echo "${src}" | \ grep -q "//www\.hdfgroup\.org/" then quVer="${src%/*}/" quNam="${src##*/}" quNam="${quNam%-*}" quEnd=$( \ echo "${src}" | \ sed "s|^.*[0-9]||" ) mainVer=${pkgname#hdf} remVer=$( \ curl -o - "${quVer}" 2> /dev/null | \ tr "\"" "\n" | \ grep "^${quNam}-${mainVer}\.\(.*\)${quEnd}\$" | \ sed "s|^${quNam}-${mainVer}\.\(.*\)${quEnd}\$|\1|" \ ) elif echo "${src}" | \ grep -q "svn://svn\.openttd\.org" then remVer=$( \ svn log "${src%#*}" | \ grep -v "^-.* WebTranslator " | \ grep -v "^-.* Eints:" | \ grep -B10 -m1 -- "^-[^-]" | \ grep "^r" | \ tail -n1 | \ sed "s|^r\([[:digit:]]\+\)\s.*\$|\1|" \ ) else continue fi srcKnown=true break done if ! ${srcKnown} then echo "$1: Unknown src: '${source[@]}'" exit 1 fi if ${maschinenlesbar} then echo "remVer='${remVer}'" echo "pkgver='${pkgver}'" else if [ ! "${pkgver}" == "${remVer}" ] then echo "$1: ${pkgname}: ${remVer} vs. ${pkgver}" | \ sed "s|^\([^:]\+\): \1:|\1:|" fi fi elif ${versionenErmitteln} then echo "$@" | \ tr " " "\n" | \ parallel -j${jobs} "${me}" "${optArgs[@]}" {} \; exit $? else for s in "$@" do grep "^${s}:" "${versionenDatei}" done fi