#!/bin/bash usage() { >&2 echo 'Verwendung: ' >&2 echo " $0"' [-f|--force] [-j|--jobs=${jobs}]' >&2 echo ' -f|--force|--noUpdate: 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 unForce=false eval set -- "$(getopt -o fj:m --long force,jobs:,noUpdate -n "$(basename "$0")" -- "$@" || echo "usage")" args=("$@") optArgs=() while true do case $1 in -f|--force) force=true optArgs[${#optArgs[@]}]="-f" ;; --noUpdate) unForce=true optArgs[${#optArgs[@]}]="--noUpdate" ;; -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 ${unForce} && versionenErmitteln=false 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[@]}" "${source_i686[@]}" "${source_x86_64[@]}" do src="${src#*::}" if [ "${pkgname}" == "adduser" ] then remVer="$( wget -O - "${source[0]}" 2> /dev/null | \ grep '^# Version: ' | \ sed 's|^# Version: \+||' )" elif [ "${pkgname}" == "dropbox" ] then remVer="$( curl 'https://www.dropboxforum.com/t5/Desktop-client-builds/bd-p/101003016' 2> /dev/null | \ tr '<>' '\n' | \ grep '^Stable Build [0-9.-]\+$' | \ sed 's|^Stable Build \([0-9.-]\+\)$|\1|' | \ sort -V | \ tail -n1 )" elif [ "${pkgname}" == "g95" ] then remVer='0.94' elif [ "${pkgname}" == "pgplot-for-ifeffit" ] then remVer="$( curl "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 [ "${pkgname}" == "wurzel-old" ] then remVer="0.1" elif echo "${src}" | \ grep -q '^http://ftp.linux.org.uk/.*/netkit/' then quVer="${src%/*}/" remVer="$( curl "${quVer}" 2> /dev/null | \ tr '<>' '\n' | \ grep "^${pkgname#netkit-}-[0-9.-]\+\.tar\.gz\$" | \ sed "s|^${pkgname#netkit-}-\([0-9.-]\+\)\.tar\.gz\$|\1|" | \ sort -V | \ tail -n1 )" elif [ "${pkgname}" == "archiso32" ] then git -C /usr/src/archlinux/archiso fetch upstream remVer="$( git -C /usr/src/archlinux/archiso archive --format=tar upstream/master | \ tar -Ox Makefile | \ grep -m1 '^V=[0-9]\+$' | \ cut -d= -f2 )" elif echo "${src}" | \ grep -q "//www\.mpich\.org/" then quVer="${src%/*/*}/" aVers="$( curl "${quVer}" 2> /dev/null | \ tr '"' '\n' | \ grep '^[0-9.]\+/$' | \ sed 's|/$||' )" if [ ! "${pkgname}" == "mpich" ] then aVers="$( ( echo "${aVers}" echo "${pkgname#mpich} %%%SCHNIPP%%%" ) | sort -V | \ sed '/%%%SCHNIPP%%%/q' | \ grep -v '%%%SCHNIPP%%%' )" fi remVer="$( echo "${aVers}" | \ sort -V | \ tail -n1 )" elif echo "${src}" | \ grep -q 'git://anonscm\.debian\.org/' then remVer="$( git ls-remote --tags "${src%#*}" | \ awk '{print $2}' | \ grep '^refs/tags/v[0-9.]\+$' | \ sed 's|^refs/tags/v\([0-9.]\+\)$|\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 "${qu}" 2> /dev/null | \ tr "\"" "\n" | \ grep "^/pypi/\(python-\)\?${pkgname#*-}/[0-9.-]\+\$" | \ sed "s|^/pypi/\(python-\)\?${pkgname#*-}/\([0-9.-]\+\)\$|\2|" | \ sort -V | \ tail -n1 )" remHash="$( curl "${qu}${remVer}" 2> /dev/null | \ tr '"#' '\n' | \ grep -m1 "^https://pypi\.python\.org/packages/.*/[0-9a-f]\{60\}/${pkgname#*-}-${remVer}\.tar\.\(gz\|bz2\|xz\)\$" | \ sed 's|/[^/]\+$|/|; s|^https://pypi\.python\.org/packages/|/|' )" locHash="$( echo "${src}" | \ sed 's|/[^/]\+$|/|; s|^https://pypi\.python\.org/packages/|/|' )" ${maschinenlesbar} && \ [ "${remHash}" != "${locHash}" ] && \ echo "sedExtra='s@${locHash}@${remHash}@g;'" elif echo "${src}" | \ grep -q "//bundles\.openttdcoop\.org/" then qu="$( echo "${src}" | \ sed 's|^\(https\?://\([^/]\+/\)\{3\}\).*$|\1|' )" remVer="$( curl "${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 "$(\ 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\.metacpan\.org/authors/\|cpan\.org/modules/by-module/" then quVer=$( \ echo "${src%/*}/" | \ sed 's|//\(search\.m\?\)\?cpan\.org/|//www.cpan.org/|' | \ sed 's|/CPAN/|/|' ) quNam=${src##*/} quNam=${quNam%-*} quEnd=$( \ echo "${src##*-}" | \ sed "s|^v\?[0-9.]*||" | \ sed 's|\.|\\\.|' ) if [ "${pkgname}" == 'perl-chi' ] then pre='s|\(\...\)$|\10|' post='s|\(\...\)0$|\1|' elif [ "${pkgname}" == 'perl-opengl' ] then pre='s|\(\...\)\(..\)$|\1.\2|' post='s|\(\...\)\.\(..\)$|\1\2|' else pre='' post='' fi remVer=$( \ curl "${quVer}" 2> /dev/null | \ tr "\"" "\n" | \ grep "^${quNam}-v\?[0-9.-]*\.${quEnd}\$" | \ sed "s|^${quNam}-v\?\([0-9.-]*\)\.${quEnd}\$|\1|" | \ sed "${pre}" | \ sort -V | \ tail -n1 | \ sed "${post}" ) 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 "${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 "${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|" | \ sed 's|http:|https:|' ) quNam=/${quVer#*.com/}/tag/ remVer=$( \ curl "${quVer}" 2> /dev/null | \ tr "\"" "\n" | \ tr '[[:upper:]]' '[[:lower:]]' | \ grep "^${quNam}v\?[0-9.]\+\$" | \ sed "s|^${quNam}v\?||" | \ ( if [ "${pkgname}" == "conky" ] then grep -v '\.999$' else cat fi ) | \ sort -V | \ tail -n1 \ ) elif echo "${src}" | \ grep -q "//\(\(pr\)\?downloads\.\)\?sourceforge\.net/" then quVer=$( \ echo "${src}" | \ sed 's|/sourceforge/|/|' | \ sed 's|\(//sourceforge\.net/.*/\)[^/]*/[^/]*$|\1|' | \ sed "s|//\(pr\)\?downloads\.sourceforge\.net/\([^/]*\)/[^/]*\$|//sourceforge.net/projects/\2/files/\2/|" | \ sed 's|/scidavis/$|/SciDAVis/|' | \ sed 's|^http:|https:|' ) remVer=$( \ curl "${quVer}" 2> /dev/null | \ tr "\"" "\n" | \ grep "^${quVer#*sourceforge.net}\(${pkgname}\(-\|%20\)\)\?[0-9.-]" | \ sed "s@/${pkgname}\(-\|%20\)@/@" | \ sed "s|^${quVer#*sourceforge.net}\([0-9.-]\+\).*\$|\1|" | \ sed "s|-\$||" | \ sort -V | \ tail -n1 \ ) elif echo "${src}" | \ grep -q '//support\.hdfgroup\.org/' then quVer="${src%/*/*/*}/" quNam="${src#${quVer}}" quNam="${quNam%%.*}" quNam="$(echo "${quNam}" | tr '[:lower:]' '[:upper:]')" remVer=$( \ curl "${quVer}" 2> /dev/null | \ tr '"' '\n' | \ grep "^${quNam}\.[.0-9]\+/\$" | \ sed "s|^${quNam}\.\(.*\)/\$|\1|" | \ sort -V | \ tail -n1 \ ) 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|" \ ) elif echo "${src}" | \ grep -q 'https://bitbucket\.org/.*/get/[^/]\+$' then srcPreNam="$( echo "${src}" | \ sed 's|^.*/\([^/0-9]\+_\)[0-9][^/]\+$|\1|' )" srcEndg="$( echo "${src}" | \ sed 's|^.*\(\.tar[^/]*\)$|\1|' | \ sed 's|\.|\\.|g' )" remVer="$( curl "${src%/get/*}/downloads/?tab=tags" 2> /dev/null | \ tr '"' '\n' | \ grep "${srcEndg}\$" | \ sed "s|^.*/${srcPreNam}\(.*\)${srcEndg}\$|\1|" | \ tr '_' '.' | \ sort -V | \ tail -n1 )" elif echo "${src}" | \ grep -q "https\?://\(\(bitbucket\|bindfs\|qgis\|download\.osgeo\|www\.\(iozone\|wurzel\)\)\.org\|ftp\.daper\.net\|www\.\(cybernoia\.de\|phy\.duke\.edu\)\|isl\.gforge\.inria\.fr\)/" then quVer="${src%/*}/" remVer="$( \ curl "${quVer}" 2> /dev/null | \ tr '"<>' '\n\n\n' | \ grep "^${pkgname}\(-src\)\?-\?[0-9._]\+\.t\(ar\(\.gz\|\.bz2\)\?\|gz\)\$" | \ sed "s@^${pkgname}\(-src\)\?-\?\([0-9._]\+\)\.t\(ar\(\.gz\|\.bz2\)\?\|gz\)\$@\2@" | \ tr '_' '.' | \ sort -V | \ tail -n1 )" elif echo "${src}" | \ grep -q '^https://www\.paraview\.org/files/' then remVerz="$( echo "${src}" | \ sed 's|/v[0-9.]\+/ParaView-v[0-9.]\+\.tar\.gz$|/|' | \ sed 's|^\(http://\)|\1www.|' )" for mainVer in $( curl "${remVerz}" 2> /dev/null | \ tr ' >' '\n' | \ grep '^href="v[0-9.]\+/"$' | \ sed 's|href="v\([0-9.]\+\)/"$|\1|' | \ sort -Vr ) do remVer="$( curl "${remVerz}v${mainVer}/" 2> /dev/null | \ tr ' >' '\n' | \ grep '^href="ParaView-v[0-9.]\+\.tar\.gz"$' | \ sed 's|^href="ParaView-v\([0-9.]\+\)\.tar\.gz"$|\1|' | \ sort -V | \ tail -n1 )" [ -n "${remVer}" ] && break done elif echo "${src}" | \ grep -q '^http://download\.linuxaudio\.org/lilypond/sources/' then remVerz="$( echo "${src}" | \ sed 's|[^/]\+/[^/]\+$||' )" for mainVer in $( curl "${remVerz}" 2> /dev/null | \ tr '"' '\n' | \ grep '^v[0-9.]\+/$' | \ sed 's|^v\([0-9.]\+\)/$|\1|' | \ sort -Vr ) do remVer="$( curl "${remVerz}v${mainVer}/" 2> /dev/null | \ tr '"' '\n' | \ grep '^lilypond-[0-9.]\+\.tar\.\(gz\|bz2\|xz\)$' | \ sed 's@^lilypond-\([0-9.]\+\)\.tar\.\(gz\|bz2\|xz\)$@\1@' | \ sort -V | \ tail -n1 )" [ -n "${remVer}" ] && break done elif echo "${src}" | \ grep -q "http://www\.mkgmap\.org\.uk/download" then remUrl="$( echo "${src}" | \ sed 's|-r[0-9]\+\.zip$|.html|' )" remVer="r$( curl "${remUrl}" 2> /dev/null | \ grep '"text: current()\.version"' | \ tr '<>' '\n' | grep '^[0-9]\+$' | \ sort -n | \ tail -n1 )" else continue fi srcKnown=true break done if ! ${srcKnown} then echo "$1: Unknown src: '${source[@]}' '${source_i686[@]}' '${source_x86_64[@]}'" exit 1 fi if ${maschinenlesbar} then echo "remVer='${remVer}'" echo "pkgver='${pkgver}'" echo "pkgrel='${pkgrel}'" 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