]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/awk -f | |
2 | # $Revision$, $Date$ | |
3 | # | |
4 | # Copyright (C) 2000-2010 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 | d("Retrieving: " url) | |
276 | 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" | |
277 | cmd = "wget -t 2 -T 45 --user-agent \"" user_agent "\" -nv -O - \"" url "\" --passive-ftp --no-check-certificate > " tmpfile " 2> " tmpfileerr | |
278 | d("Execute: " cmd) | |
279 | errno = system(cmd) | |
280 | d("Execute done") | |
281 | ||
282 | if (errno != 0) { | |
283 | d("Reading failure response...") | |
284 | wholeerr = "" | |
285 | while (getline oneline < tmpfileerr) | |
286 | wholeerr = (wholeerr " " oneline) | |
287 | d("Error Response: " wholeerr) | |
288 | ||
289 | system("rm -f " tmpfile) | |
290 | system("rm -f " tmpfileerr) | |
291 | retval = ("WGET ERROR: " errno ": " wholeerr) | |
292 | return retval | |
293 | } | |
294 | system("rm -f " tmpfileerr) | |
295 | ||
296 | urldir = url; | |
297 | sub(/[^\/]+$/, "", urldir) | |
298 | ||
299 | if (USE_PERL) { | |
300 | cmd = extract_links_cmd(tmpfile) | |
301 | while (cmd | getline) { | |
302 | tag = $1 | |
303 | link = substr($0, length(tag) + 2) | |
304 | ||
305 | if (tag == "iframe") { | |
306 | d("Frame: " link) | |
307 | if (url !~ /\//) { | |
308 | link = (urldir link) | |
309 | d("Frame->: " link) | |
310 | } | |
311 | ||
312 | if (link_seen(link)) { | |
313 | continue | |
314 | } | |
315 | retval = (retval " " get_links(link)) | |
316 | } | |
317 | ||
318 | if (link_seen(link)) { | |
319 | continue | |
320 | } | |
321 | ||
322 | retval = (retval " " link) | |
323 | d("href(): " link) | |
324 | } | |
325 | close(cmd) | |
326 | system("rm -f " tmpfile) | |
327 | ||
328 | d("Returning: [" retval "]") | |
329 | return retval | |
330 | } | |
331 | ||
332 | wholeodp = "" | |
333 | d("Reading success response...") | |
334 | while (getline oneline < tmpfile) { | |
335 | wholeodp = (wholeodp " " oneline) | |
336 | # d("Response: " wholeodp) | |
337 | } | |
338 | d("Reponse read done...") | |
339 | system("rm -f " tmpfile) | |
340 | ||
341 | while (match(wholeodp, /<([aA]|[fF][rR][aA][mM][eE])[ \t][^>]*>/) > 0) { | |
342 | d("Processing links...") | |
343 | odp = substr(wholeodp,RSTART,RLENGTH); | |
344 | wholeodp = substr(wholeodp,RSTART+RLENGTH); | |
345 | ||
346 | lowerodp = tolower(odp); | |
347 | if (lowerodp ~ /<frame[ \t]/) { | |
348 | sub(/[sS][rR][cC]=[ \t]*/, "src=", odp); | |
349 | match(odp, /src="[^"]+"/) | |
350 | newurl = substr(odp, RSTART+5, RLENGTH-6) | |
351 | d("Frame: " newurl) | |
352 | if (newurl !~ /\//) { | |
353 | newurl=(urldir newurl) | |
354 | d("Frame->: " newurl) | |
355 | } | |
356 | ||
357 | if (link_seen(newurl)) { | |
358 | newurl = "" | |
359 | continue | |
360 | } | |
361 | ||
362 | retval = (retval " " get_links(newurl)) | |
363 | } else if (lowerodp ~ /href=[ \t]*"[^"]*"/) { | |
364 | sub(/[hH][rR][eE][fF]=[ \t]*"/,"href=\"",odp) | |
365 | match(odp,/href="[^"]*"/) | |
366 | link=substr(odp,RSTART,RLENGTH) | |
367 | odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH) | |
368 | link=substr(link,7,length(link)-7) | |
369 | link=postfix_link(url, link) | |
370 | ||
371 | if (link_seen(link)) { | |
372 | link="" | |
373 | continue | |
374 | } | |
375 | ||
376 | retval = (retval " " link) | |
377 | d("href(\"\"): " link) | |
378 | } else if (lowerodp ~ /href=[ \t]*'[^']*'/) { | |
379 | sub(/[hH][rR][eE][fF]=[ \t]*'/,"href='",odp) | |
380 | match(odp,/href='[^']*'/) | |
381 | link=substr(odp,RSTART,RLENGTH) | |
382 | odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH) | |
383 | link=substr(link,7,length(link)-7) | |
384 | link=postfix_link(url, link) | |
385 | ||
386 | if (link_seen(link)) { | |
387 | link="" | |
388 | continue | |
389 | } | |
390 | ||
391 | retval = (retval " " link) | |
392 | d("href(''): " link) | |
393 | } else if (lowerodp ~ /href=[ \t]*[^ \t>]*/) { | |
394 | sub(/[hH][rR][eE][fF]=[ \t]*/,"href=",odp) | |
395 | match(odp,/href=[^ \t>]*/) | |
396 | link=substr(odp,RSTART,RLENGTH) | |
397 | odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH) | |
398 | link=substr(link,6,length(link)-5) | |
399 | ||
400 | if (link_seen(link)) { | |
401 | link="" | |
402 | continue | |
403 | } | |
404 | ||
405 | retval = (retval " " link) | |
406 | d("href(): " link) | |
407 | } else { | |
408 | # <a ...> but not href - skip | |
409 | d("skipping <a > without href: " odp) | |
410 | } | |
411 | } | |
412 | ||
413 | d("Returning: [" retval "]") | |
414 | return retval | |
415 | } | |
416 | ||
417 | function subst_defines(var,defs) { | |
418 | # substitute all possible RPM macros | |
419 | while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) { | |
420 | oldvar=var | |
421 | for (j in defs) { | |
422 | gsub("%{" j "}", defs[j], var) | |
423 | gsub("%" j , defs[j], var) | |
424 | } | |
425 | if (var==oldvar) { | |
426 | if (DEBUG) { | |
427 | for (i in defs) { | |
428 | d(i " == " defs[i]) | |
429 | } | |
430 | } | |
431 | return var | |
432 | } | |
433 | } | |
434 | return var | |
435 | } | |
436 | ||
437 | function find_mirror(url) { | |
438 | ||
439 | while (succ = (getline line < "mirrors")) { | |
440 | if (succ==-1) { return url } | |
441 | nf=split(line,fields,"|") | |
442 | if (nf>1){ | |
443 | origin=fields[1] | |
444 | mirror=fields[2] | |
445 | mname=fields[3] | |
446 | prefix=substr(url,1,length(origin)) | |
447 | if (prefix==origin){ | |
448 | d("Mirror fount at " mname) | |
449 | close("mirrors") | |
450 | return mirror substr(url,length(origin)+1) | |
451 | } | |
452 | } | |
453 | } | |
454 | ||
455 | return url | |
456 | } | |
457 | ||
458 | function process_source(number, lurl, name, version) { | |
459 | # fetches file list, and compares version numbers | |
460 | d("Processing " lurl) | |
461 | ||
462 | if (index(lurl, version) == 0) { | |
463 | d("There is no version number ["version"] in ["lurl"]") | |
464 | return 0 | |
465 | } | |
466 | ||
467 | sub("://",":",lurl) | |
468 | sub("/",":/",lurl) | |
469 | gsub("[^/]*$",":&",lurl) | |
470 | split(lurl,url,":") | |
471 | acc=url[1] | |
472 | host=url[2] | |
473 | dir=url[3] | |
474 | filename=url[4] | |
475 | ||
476 | if (index(dir,version)) { | |
477 | # directory name as version maching mode: | |
478 | # if /something/version/name-version.tarball then check | |
479 | # in /something/ looking for newer directory | |
480 | dir=substr(dir,1,index(dir,version)-1) | |
481 | sub("[^/]*$","",dir) | |
482 | sub("(\.tar\.(bz|bz2|gz|lzma|xz)|zip)$","",filename) | |
483 | } | |
484 | ||
485 | d("Will check a directory: " dir) | |
486 | d("and a file: " filename) | |
487 | ||
488 | filenameexp=filename | |
489 | gsub("[+]","\\+",filenameexp) | |
490 | sub(version,"[A-Za-z0-9.]+",filenameexp) | |
491 | gsub("[.]","\\.",filenameexp) | |
492 | d("Expression: " filenameexp) | |
493 | match(filename,version) | |
494 | prever=substr(filename,1,RSTART-1) | |
495 | postver=substr(filename,RSTART+RLENGTH) | |
496 | d("Before number: " prever) | |
497 | d("and after: " postver) | |
498 | newurl=find_mirror(acc "://" host dir) | |
499 | #print acc "://" host dir | |
500 | #newurl=url[1]"://"url[2]url[3]url[4] | |
501 | #newurl=acc "://" host dir filename | |
502 | d("Looking at " newurl) | |
503 | ||
504 | references=0 | |
505 | finished=0 | |
506 | oldversion=version | |
507 | odp = get_links(newurl, filename) | |
508 | if( odp ~ "ERROR: ") { | |
509 | print name "(" number ") " odp | |
510 | } else { | |
511 | d("WebPage downloaded") | |
512 | c=split(odp,linki) | |
513 | for (nr=1; nr<=c; nr++) { | |
514 | addr=linki[nr] | |
515 | ||
516 | d("Found link: " addr) | |
517 | ||
518 | # github has very different tarball links that clash with this safe check | |
519 | if (!(newurl ~/^(http|https):\/\/github.com\/.*\/tarball/)) { | |
520 | if (addr ~ "[-_.0-9A-Za-z~]" filenameexp) { | |
521 | continue | |
522 | } | |
523 | } | |
524 | ||
525 | if (addr ~ filenameexp) { | |
526 | match(addr,filenameexp) | |
527 | newfilename=substr(addr,RSTART,RLENGTH) | |
528 | d("Hypothetical new: " newfilename) | |
529 | newfilename=fixedsub(prever,"",newfilename) | |
530 | newfilename=fixedsub(postver,"",newfilename) | |
531 | d("Version: " newfilename) | |
532 | if (newfilename ~ /\.(asc|sig|pkg|bin|binary|built)$/) continue | |
533 | # strip ending (happens when in directiory name as version matching mode) | |
534 | sub("(\.tar\.(bz|bz2|gz|lzma|xz)|zip)$","",newfilename) | |
535 | if (NUMERIC) { | |
536 | if ( compare_ver_dec(version, newfilename)==1 ) { | |
537 | d("Yes, there is new one") | |
538 | version=newfilename | |
539 | finished=1 | |
540 | } | |
541 | } else if ( compare_ver(version, newfilename)==1 ) { | |
542 | d("Yes, there is new one") | |
543 | version=newfilename | |
544 | finished=1 | |
545 | } | |
546 | } | |
547 | } | |
548 | if (finished == 0) | |
549 | print name "(" number ") seems ok: " oldversion | |
550 | else | |
551 | print name "(" number ") [OLD] " oldversion " [NEW] " version | |
552 | } | |
553 | } | |
554 | ||
555 | function rss_upgrade(name, ver, url, regex, cmd, nver) { | |
556 | regex = "s/.*<title>" regex "<\/title>.*/\\1/p" | |
557 | cmd = "wget -t 2 -T 45 -q -O - " url " | sed -nre '" regex "' | head -n1" | |
558 | ||
559 | d("rss_upgrade_cmd: " cmd) | |
560 | cmd | getline nver | |
561 | close(cmd) | |
562 | ||
563 | if (compare_ver(ver, nver)) { | |
564 | print name " [OLD] " ver " [NEW] " nver | |
565 | } else { | |
566 | print name " seems ok: " ver | |
567 | } | |
568 | } | |
569 | ||
570 | # check for ZF upgrade from rss | |
571 | function zf_upgrade(name, ver) { | |
572 | rss_upgrade(name, ver, \ | |
573 | "http://devzone.zend.com/tag/Zend_Framework_Management/format/rss2.0", \ | |
574 | "Zend Framework ([^\\s]+) Released" \ | |
575 | ); | |
576 | } | |
577 | ||
578 | function hudson_upgrade(name, ver) { | |
579 | rss_upgrade(name, ver, \ | |
580 | "https://hudson.dev.java.net/servlets/ProjectRSS?type=news", \ | |
581 | "Hudson ([0-9.]+) released" \ | |
582 | ); | |
583 | } | |
584 | ||
585 | # upgrade check for pear package using PEAR CLI | |
586 | function pear_upgrade(name, ver, pname, pearcmd, nver) { | |
587 | pname = name; | |
588 | sub(/^php-pear-/, "", pname); | |
589 | ||
590 | pearcmd = "pear remote-info " pname " | awk '/^Latest/{print $NF}'" | |
591 | d("pearcmd: " pearcmd) | |
592 | pearcmd | getline nver | |
593 | close(pearcmd) | |
594 | ||
595 | if (compare_ver(ver, nver)) { | |
596 | print name " [OLD] " ver " [NEW] " nver | |
597 | } else { | |
598 | print name " seems ok: " ver | |
599 | } | |
600 | ||
601 | return | |
602 | } | |
603 | ||
604 | function vim_upgrade(name, ver, mver, nver, vimcmd) { | |
605 | # %patchset_source -f ftp://ftp.vim.org/pub/editors/vim/patches/7.2/7.2.%03g 1 %{patchlevel} | |
606 | mver = substr(ver, 0, 4) | |
607 | vimcmd = "wget -q -O - ftp://ftp.vim.org/pub/editors/vim/patches/"mver"/MD5SUMS|grep -vF .gz|tail -n1|awk '{print $2}'" | |
608 | d("vimcmd: " vimcmd) | |
609 | vimcmd | getline nver | |
610 | close(vimcmd) | |
611 | ||
612 | if (compare_ver(ver, nver)) { | |
613 | print name " [OLD] " ver " [NEW] " nver | |
614 | } else { | |
615 | print name " seems ok: " ver | |
616 | } | |
617 | } | |
618 | ||
619 | function process_data(name, ver, rel, src) { | |
620 | if (name ~ /^php-pear-/) { | |
621 | return pear_upgrade(name, ver); | |
622 | } | |
623 | if (name == "ZendFramework") { | |
624 | return zf_upgrade(name, ver); | |
625 | } | |
626 | if (name == "hudson") { | |
627 | return hudson_upgrade(name, ver); | |
628 | } | |
629 | if (name == "vim") { | |
630 | return vim_upgrade(name, ver); | |
631 | } | |
632 | if (name == "xulrunner") { | |
633 | ver = subst_defines(DEFS["firefox_ver"], DEFS) | |
634 | d("package xulrunner, change version to firefox ["ver"]") | |
635 | } | |
636 | ||
637 | # this function checks if substitutions were valid, and if true: | |
638 | # processes each URL and tries to get current file list | |
639 | for (i in src) { | |
640 | if (src[i] ~ /%{nil}/) { | |
641 | gsub(/\%\{nil\}/, "", src[i]) | |
642 | } | |
643 | if ( src[i] !~ /%{.*}/ && src[i] !~ /%[A-Za-z0-9_]/ ) { | |
644 | d("Source: " src[i]) | |
645 | process_source(i, src[i], name, ver) | |
646 | } else { | |
647 | print FNAME ":" i ": impossible substitution: " src[i] | |
648 | } | |
649 | } | |
650 | } | |
651 | ||
652 | BEGIN { | |
653 | # if U want to use DEBUG, run script with "-v DEBUG=1" | |
654 | # or uncomment the line below | |
655 | # DEBUG = 1 | |
656 | ||
657 | errno=system("wget --help > /dev/null 2>&1") | |
658 | if (errno) { | |
659 | print "No wget installed!" | |
660 | exit 1 | |
661 | } | |
662 | if (ARGC>=3 && ARGV[2]=="-n") { | |
663 | NUMERIC=1 | |
664 | for (i=3; i<ARGC; i++) ARGV[i-1]=ARGV[i] | |
665 | ARGC=ARGC-1 | |
666 | } | |
667 | } | |
668 | ||
669 | FNR==1 { | |
670 | if ( ARGIND != 1 ) { | |
671 | # clean frameseen for each ARG | |
672 | for (i in frameseen) { | |
673 | delete frameseen[i] | |
674 | } | |
675 | frameseen[0] = 1 | |
676 | ||
677 | process_data(NAME,VER,REL,SRC) | |
678 | NAME="" ; VER="" ; REL="" | |
679 | for (i in DEFS) delete DEFS[i] | |
680 | for (i in SRC) delete SRC[i] | |
681 | } | |
682 | FNAME=FILENAME | |
683 | DEFS["_alt_kernel"]="" | |
684 | DEFS["20"]="\\ " | |
685 | } | |
686 | ||
687 | /^[Uu][Rr][Ll]:/&&(URL=="") { URL=subst_defines($2,DEFS) ; DEFS["url"]=URL } | |
688 | /^[Nn]ame:/&&(NAME=="") { NAME=subst_defines($2,DEFS) ; DEFS["name"]=NAME } | |
689 | /^[Vv]ersion:/&&(VER=="") { VER=subst_defines($2,DEFS) ; DEFS["version"]=VER } | |
690 | /^[Rr]elease:/&&(REL=="") { REL=subst_defines($2,DEFS) ; DEFS["release"]=REL } | |
691 | /^[Ss]ource[0-9]*:/ { if (/(ftp|http|https):\/\//) SRC[FNR]=subst_defines($2,DEFS) } | |
692 | /%define/ { DEFS[$2]=subst_defines($3,DEFS) } | |
693 | ||
694 | END { | |
695 | process_data(NAME,VER,REL,SRC) | |
696 | } |