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