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