summaryrefslogtreecommitdiff
path: root/checkVersions
blob: 92216b1dd09ae17bd5d1b7560fe2734d743a4a0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/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

    if echo "${src}" | \
      grep -q "//opensources\.eckner\.net/"
    then
      qu=${src#*::}
      qu=${qu%-*}
      remVer=$( \
        curl -o - "$(\
          echo "${qu}" | \
            sed "s|\?dl=|?ls=|" \
          )" 2> /dev/null | \
          tr "<>" "\n\n" | \
          grep "^${pkgname}-" | \
          sed "s|^${pkgname}-||" | \
          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/"
    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 [ "${pkgname}" == "openttd-svn" ]
    then
      remVer=$( \
        eval $(grep "^\s*svn " $1/PKGBUILD | \
          sed "s|export|log|; s|\s*trunk\$||") | \
          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