]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/awk -f | |
2 | # $Revision$, $Date$ | |
3 | # | |
4 | # Copyright (C) 2000-2011 PLD-Team <feedback@pld-linux.org> | |
5 | # Authors: | |
6 | # Sebastian Zagrodzki <zagrodzki@pld-linux.org> | |
7 | # Jacek Konieczny <jajcus@pld-linux.org> | |
8 | # Andrzej Krzysztofowicz <ankry@pld-linux.org> | |
9 | # Jakub Bogusz <qboosh@pld-linux.org> | |
10 | # Elan Ruusamäe <glen@pld-linux.org> | |
11 | # | |
12 | # See cvs log pldnotify.awk for list of contributors | |
13 | # | |
14 | # TODO: | |
15 | # - "SourceXDownload" support (use given URLs if present instead of cut-down SourceX URLs) | |
16 | # - "SourceXActiveFTP" support | |
17 | # - support debian/watch http://wiki.debian.org/debian/watch/ | |
18 | ||
19 | ||
20 | function d(s) { | |
21 | if (!DEBUG) { | |
22 | return | |
23 | } | |
24 | ||
25 | # print strftime("%Y-%m-%d %H:%M:%S ") s >> "/dev/stderr" | |
26 | print s >> "/dev/stderr" | |
27 | } | |
28 | ||
29 | function fixedsub(s1,s2,t, ind) { | |
30 | # substitutes fixed strings (not regexps) | |
31 | if (ind = index(t,s1)) { | |
32 | t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1)) | |
33 | } | |
34 | return t | |
35 | } | |
36 | ||
37 | function ispre(s) { | |
38 | if ((s~"pre")||(s~"PRE")||(s~"beta")||(s~"BETA")||(s~"alpha")||(s~"ALPHA")||(s~"rc")||(s~"RC")) { | |
39 | d("pre-version") | |
40 | return 1 | |
41 | } else { | |
42 | return 0 | |
43 | } | |
44 | } | |
45 | ||
46 | function compare_ver(v1,v2) { | |
47 | # compares version numbers | |
48 | while (match(v1,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/)) | |
49 | v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1)) | |
50 | while (match(v2,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/)) | |
51 | v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1)) | |
52 | sub("^0*","",v1) | |
53 | sub("^0*","",v2) | |
54 | gsub("\.0*",".",v1) | |
55 | gsub("\.0*",".",v2) | |
56 | d("v1 == " v1) | |
57 | d("v2 == " v2) | |
58 | count=split(v1,v1a,"\.") | |
59 | count2=split(v2,v2a,"\.") | |
60 | ||
61 | if (count<count2) mincount=count | |
62 | else mincount=count2 | |
63 | ||
64 | for (i=1; i<=mincount; i++) { | |
65 | if (v1a[i]=="") v1a[i]=0 | |
66 | if (v2a[i]=="") v2a[i]=0 | |
67 | d("i == " i) | |
68 | d("v1[i] == " v1a[i]) | |
69 | d("v2[i] == " v2a[i]) | |
70 | if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) { | |
71 | if (length(v2a[i])>length(v1a[i])) | |
72 | return 1 | |
73 | else if (v2a[i]>v1a[i]) | |
74 | return 1 | |
75 | else if (length(v1a[i])>length(v2a[i])) | |
76 | return 0 | |
77 | else if (v1a[i]>v2a[i]) | |
78 | return 0 | |
79 | } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) { | |
80 | if (v2a[i]>v1a[i]) | |
81 | return 1 | |
82 | else if (v1a[i]>v2a[i]) | |
83 | return 0 | |
84 | } else if (ispre(v1a[i]) == 1) | |
85 | return 1 | |
86 | else | |
87 | return 0 | |
88 | } | |
89 | if ((count2==mincount)&&(count!=count2)) { | |
90 | for (i=count2+1; i<=count; i++) | |
91 | if (ispre(v1a[i]) == 1) | |
92 | return 1 | |
93 | return 0 | |
94 | } else if (count!=count2) { | |
95 | for (i=count+1; i<=count2; i++) | |
96 | if (ispre(v2a[i]) == 1) | |
97 | return 0 | |
98 | return 1 | |
99 | } | |
100 | return 0 | |
101 | } | |
102 | ||
103 | function compare_ver_dec(v1,v2) { | |
104 | # compares version numbers as decimal floats | |
105 | while (match(v1,/[0-9][a-zA-Z]/)) | |
106 | v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1)) | |
107 | while (match(v2,/[0-9][a-zA-Z]/)) | |
108 | v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1)) | |
109 | sub("^0*","",v1) | |
110 | sub("^0*","",v2) | |
111 | d("v1 == " v1) | |
112 | d("v2 == " v2) | |
113 | count=split(v1,v1a,"\.") | |
114 | count2=split(v2,v2a,"\.") | |
115 | ||
116 | if (count<count2) mincount=count | |
117 | else mincount=count2 | |
118 | ||
119 | for (i=1; i<=mincount; i++) { | |
120 | if (v1a[i]=="") v1a[i]=0 | |
121 | if (v2a[i]=="") v2a[i]=0 | |
122 | d("i == " i) | |
123 | d("v1[i] == " v1a[i]) | |
124 | d("v2[i] == " v2a[i]) | |
125 | if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) { | |
126 | if (i==2) { | |
127 | if (0+("." v2a[i])>0+("." v1a[i])) | |
128 | return 1 | |
129 | else if (0+("." v1a[i])>0+("." v2a[i])) | |
130 | return 0 | |
131 | } else { | |
132 | if (length(v2a[i])>length(v1a[i])) | |
133 | return 1 | |
134 | else if (v2a[i]>v1a[i]) | |
135 | return 1 | |
136 | else if (length(v1a[i])>length(v2a[i])) | |
137 | return 0 | |
138 | else if (v1a[i]>v2a[i]) | |
139 | return 0 | |
140 | } | |
141 | } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) { | |
142 | if (v2a[i]>v1a[i]) | |
143 | return 1 | |
144 | else if (v1a[i]>v2a[i]) | |
145 | return 0 | |
146 | } else if (ispre(v1a[i]) == 1) | |
147 | return 1 | |
148 | else | |
149 | return 0 | |
150 | } | |
151 | if ((count2==mincount)&&(count!=count2)) { | |
152 | for (i=count2+1; i<=count; i++) | |
153 | if (ispre(v1a[i]) == 1) | |
154 | return 1 | |
155 | return 0 | |
156 | } else if (count!=count2) { | |
157 | for (i=count+1; i<=count2; i++) | |
158 | if (ispre(v2a[i]) == 1) | |
159 | return 0 | |
160 | return 1 | |
161 | } | |
162 | return 0 | |
163 | } | |
164 | ||
165 | function link_seen(link) { | |
166 | for (seenlink in frameseen) { | |
167 | if (seenlink == link) { | |
168 | d("Link: [" link "] seen already, skipping...") | |
169 | return 1 | |
170 | } | |
171 | } | |
172 | frameseen[link]=1 | |
173 | return 0 | |
174 | } | |
175 | ||
176 | function mktemp( _cmd, _tmpfile) { | |
177 | _cmd = "mktemp /tmp/XXXXXX" | |
178 | _cmd | getline _tmpfile | |
179 | close(_cmd) | |
180 | return _tmpfile | |
181 | } | |
182 | ||
183 | # fix link to artificial one that will be recognized rest of this script | |
184 | function postfix_link(url, link, oldlink) { | |
185 | oldlink = link | |
186 | if ((url ~/^(http|https):\/\/github.com\//) && (link ~ /.*\/tarball\//)) { | |
187 | gsub(".*\/tarball\/", "", link) | |
188 | link = link ".tar.gz" | |
189 | } | |
190 | if (oldlink != link) { | |
191 | d("POST FIXED URL [ " oldlink " ] to [ " link " ]") | |
192 | } | |
193 | return link | |
194 | } | |
195 | ||
196 | # use perl HTML::TreeBuilder module to extract links from html | |
197 | # it returns TAGNAME LINK in output which is pretty stright forward to parse in awk | |
198 | function extract_links_cmd(tmpfile) { | |
199 | return "perl -MHTML::TreeBuilder -e ' \ | |
200 | my $content = join q//, <>; \ | |
201 | my $root = new HTML::TreeBuilder; \ | |
202 | $root->parse($content); \ | |
203 | \ | |
204 | my %links = (); \ | |
205 | for (@{$root->extract_links(qw(a iframe))}) { \ | |
206 | my($link, $element, $attr, $tag) = @$_; \ | |
207 | $links{$link} = $tag; \ | |
208 | } \ | |
209 | \ | |
210 | while (my($link, $tag) = each %links) { \ | |
211 | print $tag, q/ /, $link, $/; \ | |
212 | } \ | |
213 | ' " tmpfile | |
214 | } | |
215 | ||
216 | # get all <A HREF=..> tags from specified URL | |
217 | function get_links(url,filename, errno,link,oneline,retval,odp,wholeodp,lowerodp,tmpfile,cmd) { | |
218 | ||
219 | wholeerr="" | |
220 | ||
221 | tmpfile = mktemp() | |
222 | tmpfileerr = mktemp() | |
223 | ||
224 | if (url ~ /^http:\/\/(download|dl)\.(sf|sourceforge)\.net\//) { | |
225 | # http://downloads.sourceforge.net/project/mediainfo/source/mediainfo/ | |
226 | gsub("^http://(download|dl)\.(sf|sourceforge)\.net/", "", url) | |
227 | ||
228 | gsub("/.*", "", url) | |
229 | url = "http://sourceforge.net/projects/" url "/files/" | |
230 | d("sf url, mungled url to: " url) | |
231 | } | |
232 | ||
233 | if (url ~ /^http:\/\/(.*)\.googlecode\.com\/files\//) { | |
234 | gsub("^http://", "", url) | |
235 | gsub("\..*", "", url) | |
236 | url = "http://code.google.com/p/" url "/downloads/list" | |
237 | d("googlecode url, mungled url to: " url) | |
238 | } | |
239 | ||
240 | if (url ~ /^http:\/\/pecl.php.net\/get\//) { | |
241 | gsub("-.*", "", filename) | |
242 | url = "http://pecl.php.net/package/" filename | |
243 | d("pecl.php.net url, mungled url to: " url) | |
244 | } | |
245 | ||
246 | if (url ~ /^(http|ftp):\/\/mysql.*\/Downloads\/MySQL-5.1\//) { | |
247 | url = "http://dev.mysql.com/downloads/mysql/5.1.html#source" | |
248 | d("mysql 5.1 url, mungled url to: " url) | |
249 | } | |
250 | ||
251 | if (url ~/^(http|https):\/\/launchpad\.net\/(.*)\//) { | |
252 | gsub("^(http|https):\/\/launchpad\.net\/", "", url) | |
253 | gsub("\/.*/", "", url) | |
254 | url = "https://code.launchpad.net/" url "/+download" | |
255 | d("main launchpad url, mungled url to: " url) | |
256 | } | |
257 | ||
258 | if (url ~/^(http|https):\/\/edge\.launchpad\.net\/(.*)\//) { | |
259 | gsub("^(http|https):\/\/edge\.launchpad\.net\/", "", url) | |
260 | gsub("\/.*/", "", url) | |
261 | url = "https://edge.launchpad.net/" url "/+download" | |
262 | d("edge launchpad url, mungled url to: " url) | |
263 | } | |
264 | ||
265 | if (url ~/^(http|https):\/\/github.com\/.*\/(.*)\/tarball\//) { | |
266 | gsub("\/tarball\/.*", "/downloads", url) | |
267 | d("github tarball url, mungled url to: " url) | |
268 | } | |
269 | ||
270 | if (url ~/^(http|https):\/\/cgit\..*\/(.*)\/snapshot\//) { | |
271 | gsub("\/snapshot\/.*", "/", url) | |
272 | d("cgit snapshot tarball url, mungled url to: " url) | |
273 | } | |
274 | ||
275 | if (url ~/^(http|https):\/\/www2\.aquamaniac\.de\/sites\/download\//) { | |
276 | url = "http://www2.aquamaniac.de/sites/download/packages.php" | |
277 | d("aquamaniac.de tarball url, mungled url to: " url) | |
278 | } | |
279 | ||
280 | d("Retrieving: " url) | |
281 | user_agent = "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2) Gecko/20100129 PLD/3.0 (Th) Iceweasel/3.6" | |
282 | cmd = "wget -t 2 -T 45 --user-agent \"" user_agent "\" -nv -O - \"" url "\" --passive-ftp --no-check-certificate > " tmpfile " 2> " tmpfileerr | |
283 | d("Execute: " cmd) | |
284 | errno = system(cmd) | |
285 | d("Execute done") | |
286 | ||
287 | if (errno != 0) { | |
288 | d("Reading failure response...") | |
289 | wholeerr = "" | |
290 | while (getline oneline < tmpfileerr) | |
291 | wholeerr = (wholeerr " " oneline) | |
292 | d("Error Response: " wholeerr) | |
293 | ||
294 | system("rm -f " tmpfile) | |
295 | system("rm -f " tmpfileerr) | |
296 | retval = ("WGET ERROR: " errno ": " wholeerr) | |
297 | return retval | |
298 | } | |
299 | system("rm -f " tmpfileerr) | |
300 | ||
301 | urldir = url; | |
302 | sub(/[^\/]+$/, "", urldir) | |
303 | ||
304 | if (USE_PERL) { | |
305 | cmd = extract_links_cmd(tmpfile) | |
306 | while (cmd | getline) { | |
307 | tag = $1 | |
308 | link = substr($0, length(tag) + 2) | |
309 | ||
310 | if (tag == "iframe") { | |
311 | d("Frame: " link) | |
312 | if (url !~ /\//) { | |
313 | link = (urldir link) | |
314 | d("Frame->: " link) | |
315 | } | |
316 | ||
317 | if (link_seen(link)) { | |
318 | continue | |
319 | } | |
320 | retval = (retval " " get_links(link)) | |
321 | } | |
322 | ||
323 | if (link_seen(link)) { | |
324 | continue | |
325 | } | |
326 | ||
327 | retval = (retval " " link) | |
328 | d("href(): " link) | |
329 | } | |
330 | close(cmd) | |
331 | system("rm -f " tmpfile) | |
332 | ||
333 | d("Returning: [" retval "]") | |
334 | return retval | |
335 | } | |
336 | ||
337 | wholeodp = "" | |
338 | d("Reading success response...") | |
339 | while (getline oneline < tmpfile) { | |
340 | wholeodp = (wholeodp " " oneline) | |
341 | # d("Response: " wholeodp) | |
342 | } | |
343 | d("Reponse read done...") | |
344 | system("rm -f " tmpfile) | |
345 | ||
346 | while (match(wholeodp, /<([aA]|[fF][rR][aA][mM][eE])[ \t][^>]*>/) > 0) { | |
347 | d("Processing links...") | |
348 | odp = substr(wholeodp,RSTART,RLENGTH); | |
349 | wholeodp = substr(wholeodp,RSTART+RLENGTH); | |
350 | ||
351 | lowerodp = tolower(odp); | |
352 | if (lowerodp ~ /<frame[ \t]/) { | |
353 | sub(/[sS][rR][cC]=[ \t]*/, "src=", odp); | |
354 | match(odp, /src="[^"]+"/) | |
355 | newurl = substr(odp, RSTART+5, RLENGTH-6) | |
356 | d("Frame: " newurl) | |
357 | if (newurl !~ /\//) { | |
358 | newurl=(urldir newurl) | |
359 | d("Frame->: " newurl) | |
360 | } | |
361 | ||
362 | if (link_seen(newurl)) { | |
363 | newurl = "" | |
364 | continue | |
365 | } | |
366 | ||
367 | retval = (retval " " get_links(newurl)) | |
368 | } else if (lowerodp ~ /href=[ \t]*"[^"]*"/) { | |
369 | sub(/[hH][rR][eE][fF]=[ \t]*"/,"href=\"",odp) | |
370 | match(odp,/href="[^"]*"/) | |
371 | link=substr(odp,RSTART,RLENGTH) | |
372 | odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH) | |
373 | link=substr(link,7,length(link)-7) | |
374 | link=postfix_link(url, link) | |
375 | ||
376 | if (link_seen(link)) { | |
377 | link="" | |
378 | continue | |
379 | } | |
380 | ||
381 | retval = (retval " " link) | |
382 | d("href(\"\"): " link) | |
383 | } else if (lowerodp ~ /href=[ \t]*'[^']*'/) { | |
384 | sub(/[hH][rR][eE][fF]=[ \t]*'/,"href='",odp) | |
385 | match(odp,/href='[^']*'/) | |
386 | link=substr(odp,RSTART,RLENGTH) | |
387 | odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH) | |
388 | link=substr(link,7,length(link)-7) | |
389 | link=postfix_link(url, link) | |
390 | ||
391 | if (link_seen(link)) { | |
392 | link="" | |
393 | continue | |
394 | } | |
395 | ||
396 | retval = (retval " " link) | |
397 | d("href(''): " link) | |
398 | } else if (lowerodp ~ /href=[ \t]*[^ \t>]*/) { | |
399 | sub(/[hH][rR][eE][fF]=[ \t]*/,"href=",odp) | |
400 | match(odp,/href=[^ \t>]*/) | |
401 | link=substr(odp,RSTART,RLENGTH) | |
402 | odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH) | |
403 | link=substr(link,6,length(link)-5) | |
404 | ||
405 | if (link_seen(link)) { | |
406 | link="" | |
407 | continue | |
408 | } | |
409 | ||
410 | retval = (retval " " link) | |
411 | d("href(): " link) | |
412 | } else { | |
413 | # <a ...> but not href - skip | |
414 | d("skipping <a > without href: " odp) | |
415 | } | |
416 | } | |
417 | ||
418 | d("Returning: [" retval "]") | |
419 | return retval | |
420 | } | |
421 | ||
422 | function subst_defines(var,defs) { | |
423 | # substitute all possible RPM macros | |
424 | while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) { | |
425 | oldvar=var | |
426 | for (j in defs) { | |
427 | gsub("%{" j "}", defs[j], var) | |
428 | gsub("%" j , defs[j], var) | |
429 | } | |
430 | if (var==oldvar) { | |
431 | if (DEBUG) { | |
432 | for (i in defs) { | |
433 | d(i " == " defs[i]) | |
434 | } | |
435 | } | |
436 | return var | |
437 | } | |
438 | } | |
439 | return var | |
440 | } | |
441 | ||
442 | function find_mirror(url) { | |
443 | ||
444 | while (succ = (getline line < "mirrors")) { | |
445 | if (succ==-1) { return url } | |
446 | nf=split(line,fields,"|") | |
447 | if (nf>1){ | |
448 | origin=fields[1] | |
449 | mirror=fields[2] | |
450 | mname=fields[3] | |
451 | prefix=substr(url,1,length(origin)) | |
452 | if (prefix==origin){ | |
453 | d("Mirror found at " mname) | |
454 | close("mirrors") | |
455 | return mirror substr(url,length(origin)+1) | |
456 | } | |
457 | } | |
458 | } | |
459 | ||
460 | return url | |
461 | } | |
462 | ||
463 | function process_source(number, lurl, name, version) { | |
464 | # fetches file list, and compares version numbers | |
465 | d("Processing " lurl) | |
466 | ||
467 | if (index(lurl, version) == 0) { | |
468 | d("There is no version number ["version"] in ["lurl"]") | |
469 | return 0 | |
470 | } | |
471 | ||
472 | sub("://",":",lurl) | |
473 | sub("/",":/",lurl) | |
474 | gsub("[^/]*$",":&",lurl) | |
475 | split(lurl,url,":") | |
476 | acc=url[1] | |
477 | host=url[2] | |
478 | dir=url[3] | |
479 | filename=url[4] | |
480 | ||
481 | if (index(dir,version)) { | |
482 | # directory name as version maching mode: | |
483 | # if /something/version/name-version.tarball then check | |
484 | # in /something/ looking for newer directory | |
485 | dir=substr(dir,1,index(dir,version)-1) | |
486 | sub("[^/]*$","",dir) | |
487 | sub("(\.tar\.(bz|bz2|gz|lzma|xz)|zip)$","",filename) | |
488 | } | |
489 | ||
490 | d("Will check a directory: " dir) | |
491 | d("and a file: " filename) | |
492 | ||
493 | filenameexp=filename | |
494 | gsub("[+]","\\+",filenameexp) | |
495 | sub(version,"[A-Za-z0-9.]+",filenameexp) | |
496 | gsub("[.]","\\.",filenameexp) | |
497 | d("Expression: " filenameexp) | |
498 | match(filename,version) | |
499 | prever=substr(filename,1,RSTART-1) | |
500 | postver=substr(filename,RSTART+RLENGTH) | |
501 | d("Before number: " prever) | |
502 | d("and after: " postver) | |
503 | newurl=find_mirror(acc "://" host dir) | |
504 | #print acc "://" host dir | |
505 | #newurl=url[1]"://"url[2]url[3]url[4] | |
506 | #newurl=acc "://" host dir filename | |
507 | d("Looking at " newurl) | |
508 | ||
509 | references=0 | |
510 | finished=0 | |
511 | oldversion=version | |
512 | odp = get_links(newurl, filename) | |
513 | if( odp ~ "ERROR: ") { | |
514 | print name "(" number ") " odp | |
515 | } else { | |
516 | d("WebPage downloaded") | |
517 | c=split(odp,linki) | |
518 | for (nr=1; nr<=c; nr++) { | |
519 | addr=linki[nr] | |
520 | ||
521 | d("Found link: " addr) | |
522 | ||
523 | # github has very different tarball links that clash with this safe check | |
524 | if (!(newurl ~/^(http|https):\/\/github.com\/.*\/tarball/)) { | |
525 | if (addr ~ "[-_.0-9A-Za-z~]" filenameexp) { | |
526 | continue | |
527 | } | |
528 | } | |
529 | ||
530 | if (addr ~ filenameexp) { | |
531 | match(addr,filenameexp) | |
532 | newfilename=substr(addr,RSTART,RLENGTH) | |
533 | d("Hypothetical new: " newfilename) | |
534 | newfilename=fixedsub(prever,"",newfilename) | |
535 | newfilename=fixedsub(postver,"",newfilename) | |
536 | d("Version: " newfilename) | |
537 | if (newfilename ~ /\.(asc|sig|pkg|bin|binary|built)$/) continue | |
538 | # strip ending (happens when in directiory name as version matching mode) | |
539 | sub("(\.tar\.(bz|bz2|gz|lzma|xz)|zip)$","",newfilename) | |
540 | if (NUMERIC) { | |
541 | if ( compare_ver_dec(version, newfilename)==1 ) { | |
542 | d("Yes, there is new one") | |
543 | version=newfilename | |
544 | finished=1 | |
545 | } | |
546 | } else if ( compare_ver(version, newfilename)==1 ) { | |
547 | d("Yes, there is new one") | |
548 | version=newfilename | |
549 | finished=1 | |
550 | } | |
551 | } | |
552 | } | |
553 | if (finished == 0) | |
554 | print name "(" number ") seems ok: " oldversion | |
555 | else | |
556 | print name "(" number ") [OLD] " oldversion " [NEW] " version | |
557 | } | |
558 | } | |
559 | ||
560 | function rss_upgrade(name, ver, url, regex, cmd, nver) { | |
561 | regex = "s/.*<title>" regex "<\/title>.*/\\1/p" | |
562 | cmd = "wget -t 2 -T 45 -q -O - " url " | sed -nre '" regex "' | head -n1" | |
563 | ||
564 | d("rss_upgrade_cmd: " cmd) | |
565 | cmd | getline nver | |
566 | close(cmd) | |
567 | ||
568 | if (compare_ver(ver, nver)) { | |
569 | print name " [OLD] " ver " [NEW] " nver | |
570 | } else { | |
571 | print name " seems ok: " ver | |
572 | } | |
573 | } | |
574 | ||
575 | # check for ZF upgrade from rss | |
576 | function zf_upgrade(name, ver) { | |
577 | rss_upgrade(name, ver, \ | |
578 | "http://devzone.zend.com/tag/Zend_Framework_Management/format/rss2.0", \ | |
579 | "Zend Framework ([^\\s]+) Released" \ | |
580 | ); | |
581 | } | |
582 | ||
583 | function hudson_upgrade(name, ver) { | |
584 | rss_upgrade(name, ver, \ | |
585 | "https://hudson.dev.java.net/servlets/ProjectRSS?type=news", \ | |
586 | "Hudson ([0-9.]+) released" \ | |
587 | ); | |
588 | } | |
589 | ||
590 | # upgrade check for pear package using PEAR CLI | |
591 | function pear_upgrade(name, ver, pname, pearcmd, nver) { | |
592 | pname = name; | |
593 | sub(/^php-pear-/, "", pname); | |
594 | ||
595 | pearcmd = "pear remote-info " pname " | awk '/^Latest/{print $NF}'" | |
596 | d("pearcmd: " pearcmd) | |
597 | pearcmd | getline nver | |
598 | close(pearcmd) | |
599 | ||
600 | if (compare_ver(ver, nver)) { | |
601 | print name " [OLD] " ver " [NEW] " nver | |
602 | } else { | |
603 | print name " seems ok: " ver | |
604 | } | |
605 | ||
606 | return | |
607 | } | |
608 | ||
609 | function vim_upgrade(name, ver, mver, nver, vimcmd) { | |
610 | # %patchset_source -f ftp://ftp.vim.org/pub/editors/vim/patches/7.2/7.2.%03g 1 %{patchlevel} | |
611 | mver = substr(ver, 0, 4) | |
612 | vimcmd = "wget -q -O - ftp://ftp.vim.org/pub/editors/vim/patches/"mver"/MD5SUMS|grep -vF .gz|tail -n1|awk '{print $2}'" | |
613 | d("vimcmd: " vimcmd) | |
614 | vimcmd | getline nver | |
615 | close(vimcmd) | |
616 | ||
617 | if (compare_ver(ver, nver)) { | |
618 | print name " [OLD] " ver " [NEW] " nver | |
619 | } else { | |
620 | print name " seems ok: " ver | |
621 | } | |
622 | } | |
623 | ||
624 | function process_data(name, ver, rel, src) { | |
625 | if (name ~ /^php-pear-/) { | |
626 | return pear_upgrade(name, ver); | |
627 | } | |
628 | if (name == "ZendFramework") { | |
629 | return zf_upgrade(name, ver); | |
630 | } | |
631 | if (name == "hudson") { | |
632 | return hudson_upgrade(name, ver); | |
633 | } | |
634 | if (name == "vim") { | |
635 | return vim_upgrade(name, ver); | |
636 | } | |
637 | if (name == "xulrunner") { | |
638 | ver = subst_defines(DEFS["firefox_ver"], DEFS) | |
639 | d("package xulrunner, change version to firefox ["ver"]") | |
640 | } | |
641 | ||
642 | # this function checks if substitutions were valid, and if true: | |
643 | # processes each URL and tries to get current file list | |
644 | for (i in src) { | |
645 | if (src[i] ~ /%{nil}/) { | |
646 | gsub(/\%\{nil\}/, "", src[i]) | |
647 | } | |
648 | if ( src[i] !~ /%{.*}/ && src[i] !~ /%[A-Za-z0-9_]/ ) { | |
649 | d("Source: " src[i]) | |
650 | process_source(i, src[i], name, ver) | |
651 | } else { | |
652 | print FNAME ":" i ": impossible substitution: " src[i] | |
653 | } | |
654 | } | |
655 | } | |
656 | ||
657 | BEGIN { | |
658 | # if U want to use DEBUG, run script with "-v DEBUG=1" | |
659 | # or uncomment the line below | |
660 | # DEBUG = 1 | |
661 | ||
662 | errno=system("wget --help > /dev/null 2>&1") | |
663 | if (errno && errno != 3) { | |
664 | print "No wget installed!" | |
665 | exit 1 | |
666 | } | |
667 | if (ARGC>=3 && ARGV[2]=="-n") { | |
668 | NUMERIC=1 | |
669 | for (i=3; i<ARGC; i++) ARGV[i-1]=ARGV[i] | |
670 | ARGC=ARGC-1 | |
671 | } | |
672 | } | |
673 | ||
674 | FNR==1 { | |
675 | if ( ARGIND != 1 ) { | |
676 | # clean frameseen for each ARG | |
677 | for (i in frameseen) { | |
678 | delete frameseen[i] | |
679 | } | |
680 | frameseen[0] = 1 | |
681 | ||
682 | process_data(NAME,VER,REL,SRC) | |
683 | NAME="" ; VER="" ; REL="" | |
684 | for (i in DEFS) delete DEFS[i] | |
685 | for (i in SRC) delete SRC[i] | |
686 | } | |
687 | FNAME=FILENAME | |
688 | DEFS["_alt_kernel"]="" | |
689 | DEFS["20"]="\\ " | |
690 | } | |
691 | ||
692 | /^[Uu][Rr][Ll]:/&&(URL=="") { URL=subst_defines($2,DEFS) ; DEFS["url"]=URL } | |
693 | /^[Nn]ame:/&&(NAME=="") { NAME=subst_defines($2,DEFS) ; DEFS["name"]=NAME } | |
694 | /^[Vv]ersion:/&&(VER=="") { VER=subst_defines($2,DEFS) ; DEFS["version"]=VER } | |
695 | /^[Rr]elease:/&&(REL=="") { REL=subst_defines($2,DEFS) ; DEFS["release"]=REL } | |
696 | /^[Ss]ource[0-9]*:/ { if (/(ftp|http|https):\/\//) SRC[FNR]=subst_defines($2,DEFS) } | |
697 | /%define/ { DEFS[$2]=subst_defines($3,DEFS) } | |
698 | ||
699 | END { | |
700 | process_data(NAME,VER,REL,SRC) | |
701 | } |