]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - pldnotify.awk
Add launchpad.net and edge.launchpad.net support. Skip .asc, .sig files.
[packages/rpm-build-tools.git] / pldnotify.awk
CommitLineData
6fb3305d 1#!/bin/awk -f
d4089f30 2# $Revision$, $Date$
b52a0a12 3#
4124c9ac 4# Copyright (C) 2000-2009 PLD-Team <feedback@pld-linux.org>
b52a0a12
JB
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
3ca67c5b 17
2aba2068
SZ
18function fixedsub(s1,s2,t, ind) {
19# substitutes fixed strings (not regexps)
20 if (ind = index(t,s1)) {
21 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
22 }
23 return t
24}
6fb3305d 25
e3c5f324
JB
26function ispre(s) {
27 if ((s~"pre")||(s~"PRE")||(s~"beta")||(s~"BETA")||(s~"alpha")||(s~"ALPHA")||(s~"rc")||(s~"RC")) {
28 if (DEBUG) print "pre-version"
29 return 1
30 } else {
31 return 0
32 }
33}
f0c5c231 34
70a5e8d4
SZ
35function compare_ver(v1,v2) {
36# compares version numbers
37 while (match(v1,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
38 v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1))
39 while (match(v2,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
40 v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1))
41 sub("^0*","",v1)
42 sub("^0*","",v2)
e2ebf07c
JB
43 gsub("\.0*",".",v1)
44 gsub("\.0*",".",v2)
70a5e8d4
SZ
45 if (DEBUG) print "v1 == " v1
46 if (DEBUG) print "v2 == " v2
47 count=split(v1,v1a,"\.")
48 count2=split(v2,v2a,"\.")
f0c5c231
ER
49
50 if (count<count2) mincount=count
70a5e8d4 51 else mincount=count2
f0c5c231 52
70a5e8d4 53 for (i=1; i<=mincount; i++) {
db83adc3
SZ
54 if (v1a[i]=="") v1a[i]=0
55 if (v2a[i]=="") v2a[i]=0
70a5e8d4
SZ
56 if (DEBUG) print "i == " i
57 if (DEBUG) print "v1[i] == " v1a[i]
58 if (DEBUG) print "v2[i] == " v2a[i]
59 if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) {
60 if (length(v2a[i])>length(v1a[i]))
61 return 1
62 else if (v2a[i]>v1a[i])
63 return 1
64 else if (length(v1a[i])>length(v2a[i]))
65 return 0
66 else if (v1a[i]>v2a[i])
67 return 0
68 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
69 if (v2a[i]>v1a[i])
70 return 1
71 else if (v1a[i]>v2a[i])
72 return 0
e3c5f324 73 } else if (ispre(v1a[i]) == 1)
70a5e8d4
SZ
74 return 1
75 else
76 return 0
77 }
78 if ((count2==mincount)&&(count!=count2)) {
79 for (i=count2+1; i<=count; i++)
e3c5f324 80 if (ispre(v1a[i]) == 1)
70a5e8d4
SZ
81 return 1
82 return 0
83 } else if (count!=count2) {
84 for (i=count+1; i<=count2; i++)
e3c5f324 85 if (ispre(v2a[i]) == 1)
70a5e8d4
SZ
86 return 0
87 return 1
88 }
db4f445e 89 return 0
70a5e8d4
SZ
90}
91
f11b5a76 92function compare_ver_dec(v1,v2) {
b8b1ac2a 93# compares version numbers as decimal floats
f11b5a76 94 while (match(v1,/[0-9][a-zA-Z]/))
95 v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1))
96 while (match(v2,/[0-9][a-zA-Z]/))
97 v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1))
98 sub("^0*","",v1)
99 sub("^0*","",v2)
100 if (DEBUG) print "v1 == " v1
101 if (DEBUG) print "v2 == " v2
102 count=split(v1,v1a,"\.")
103 count2=split(v2,v2a,"\.")
f0c5c231
ER
104
105 if (count<count2) mincount=count
f11b5a76 106 else mincount=count2
f0c5c231 107
f11b5a76 108 for (i=1; i<=mincount; i++) {
109 if (v1a[i]=="") v1a[i]=0
110 if (v2a[i]=="") v2a[i]=0
111 if (DEBUG) print "i == " i
112 if (DEBUG) print "v1[i] == " v1a[i]
113 if (DEBUG) print "v2[i] == " v2a[i]
114 if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) {
115 if (i==2) {
116 if (0+("." v2a[i])>0+("." v1a[i]))
117 return 1
118 else if (0+("." v1a[i])>0+("." v2a[i]))
119 return 0
120 } else {
121 if (length(v2a[i])>length(v1a[i]))
122 return 1
123 else if (v2a[i]>v1a[i])
124 return 1
125 else if (length(v1a[i])>length(v2a[i]))
126 return 0
127 else if (v1a[i]>v2a[i])
128 return 0
129 }
130 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
131 if (v2a[i]>v1a[i])
132 return 1
133 else if (v1a[i]>v2a[i])
134 return 0
e3c5f324 135 } else if (ispre(v1a[i]) == 1)
f11b5a76 136 return 1
137 else
138 return 0
139 }
140 if ((count2==mincount)&&(count!=count2)) {
141 for (i=count2+1; i<=count; i++)
e3c5f324 142 if (ispre(v1a[i]) == 1)
f11b5a76 143 return 1
144 return 0
145 } else if (count!=count2) {
146 for (i=count+1; i<=count2; i++)
e3c5f324 147 if (ispre(v2a[i]) == 1)
f11b5a76 148 return 0
149 return 1
150 }
151 return 0
152}
153
371e7443
AM
154function link_seen(link) {
155 for (seenlink in frameseen) {
156 if (seenlink == link) {
157 if (DEBUG) print "Link: [" link "] seen already, skipping..."
158 return 1
159 }
160 }
161 frameseen[link]=1
162 return 0
163}
164
deed2eef
ER
165function mktemp( _cmd, _tmpfile) {
166 _cmd = "mktemp /tmp/XXXXXX"
167 _cmd | getline _tmpfile
168 close(_cmd)
169 return _tmpfile
170}
171
70a5e8d4 172# get all <A HREF=..> tags from specified URL
d5697af2 173function get_links(url,filename, errno,link,oneline,retval,odp,wholeodp,lowerodp,tmpfile,cmd) {
8fef61cd
AM
174
175 wholeerr=""
176
deed2eef
ER
177 tmpfile = mktemp()
178 tmpfileerr = mktemp()
8fef61cd 179
ea4c106c
ER
180 if (url ~ /^http:\/\/(download|dl).(sf|sourceforge).net\//) {
181 gsub("^http://(download|dl).(sf|sourceforge).net/", "", url)
a9dc9975 182 url = "http://prdownloads.sourceforge.net/" substr(url, 1, 1) "/" substr(url, 1, 2) "/" url
356ec898
ER
183 if (DEBUG) print "sf url, mungled url to: " url
184 }
f0c5c231 185
109ec22a 186 if (url ~ /^http:\/\/(.*)\.googlecode\.com\/files\//) {
3836b919
AM
187 gsub("^http://", "", url)
188 gsub("\..*", "", url)
b3df8960 189 url = "http://code.google.com/p/" url "/downloads/list"
3836b919
AM
190 if (DEBUG) print "googlecode url, mungled url to: " url
191 }
192
0ed4cd23
AM
193 if (url ~ /^http:\/\/pecl.php.net\/get\//) {
194 gsub("-.*", "", filename)
195 url = "http://pecl.php.net/package/" filename
196 if (DEBUG) print "pecl.php.net url, mungled url to: " url
197 }
198
fbf290ff
AM
199 if (url ~ /^(http|ftp):\/\/mysql.*\/Downloads\/MySQL-5.1\//) {
200 url = "http://dev.mysql.com/downloads/mysql/5.1.html#source"
201 if (DEBUG) print "mysql 5.1 url, mungled url to: " url
202 }
203
eb6fb288
AM
204 if (url ~/^(http|https):\/\/launchpad\.net\/(.*)\//) {
205 gsub("^(http|https):\/\/launchpad\.net\/", "", url)
206 gsub("\/.*/", "", url)
207 url = "https://code.launchpad.net/" url "/+download"
208 if (DEBUG) print "main launchpad url, mungled url to: " url
209 }
210
211 if (url ~/^(http|https):\/\/edge\.launchpad\.net\/(.*)\//) {
212 gsub("^(http|https):\/\/edge\.launchpad\.net\/", "", url)
213 gsub("\/.*/", "", url)
214 url = "https://edge.launchpad.net/" url "/+download"
215 if (DEBUG) print "edge launchpad url, mungled url to: " url
216 }
217
fbf290ff 218
2e301ef5 219 if (DEBUG) print "Retrieving: " url
a5928093 220 cmd = "wget -nv -O - \"" url "\" -t 2 -T 45 --passive-ftp --no-check-certificate > " tmpfile " 2> " tmpfileerr
d5697af2
ER
221 if (DEBUG) print "Execute: " cmd
222 errno = system(cmd)
f0c5c231 223
3f63995d 224 if (errno==0) {
7f460828 225 while (getline oneline < tmpfile)
fc589c7e
JB
226 wholeodp=(wholeodp " " oneline)
227 if ( DEBUG ) print "Response: " wholeodp
8fef61cd
AM
228 } else {
229 wholeerr = ""
230 while (getline oneline < tmpfileerr)
231 wholeerr=(wholeerr " " oneline)
232 if ( DEBUG ) print "Error Response: " wholeerr
70a5e8d4 233 }
f0c5c231 234
2e301ef5 235 system("rm -f " tmpfile)
8fef61cd
AM
236 system("rm -f " tmpfileerr)
237
55658186
JB
238 urldir=url;
239 sub(/[^\/]+$/,"",urldir)
fc589c7e 240
3f63995d 241 if ( errno==0) {
fc589c7e
JB
242 while (match(wholeodp, /<([aA]|[fF][rR][aA][mM][eE])[ \t][^>]*>/) > 0) {
243 odp=substr(wholeodp,RSTART,RLENGTH);
244 wholeodp=substr(wholeodp,RSTART+RLENGTH);
245
246 lowerodp=tolower(odp);
247 if (lowerodp ~ /<frame[ \t]/) {
248 sub(/[sS][rR][cC]=[ \t]*/,"src=",odp);
249 match(odp,/src="[^"]+"/)
250 newurl=substr(odp,RSTART+5,RLENGTH-6)
157aa7fc 251 if (DEBUG) print "Frame: " newurl
55658186
JB
252 if (newurl !~ /\//) {
253 newurl=(urldir newurl)
157aa7fc 254 if (DEBUG) print "Frame->: " newurl
55658186 255 }
371e7443
AM
256
257 if (link_seen(newurl)) {
258 newurl=""
259 continue
260 }
261
2e301ef5 262 retval=(retval " " get_links(newurl))
fc589c7e 263 } else if (lowerodp ~ /href=[ \t]*"[^"]*"/) {
b5e77f8f 264 sub(/[hH][rR][eE][fF]=[ \t]*"/,"href=\"",odp)
95fcfc77 265 match(odp,/href="[^"]*"/)
b5e77f8f
JB
266 link=substr(odp,RSTART,RLENGTH)
267 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
268 link=substr(link,7,length(link)-7)
371e7443
AM
269
270 if (link_seen(link)) {
271 link=""
272 continue
273 }
274
b5e77f8f 275 retval=(retval " " link)
95fcfc77 276 if (DEBUG) print "href(\"\"): " link
fc589c7e 277 } else if (lowerodp ~ /href=[ \t]*'[^']*'/) {
b5e77f8f 278 sub(/[hH][rR][eE][fF]=[ \t]*'/,"href='",odp)
95fcfc77 279 match(odp,/href='[^']*'/)
93c3b403 280 link=substr(odp,RSTART,RLENGTH)
b5e77f8f 281 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
93c3b403 282 link=substr(link,7,length(link)-7)
371e7443
AM
283
284 if (link_seen(link)) {
285 link=""
286 continue
287 }
288
93c3b403 289 retval=(retval " " link)
95fcfc77 290 if (DEBUG) print "href(''): " link
fc589c7e 291 } else if (lowerodp ~ /href=[ \t]*[^ \t>]*/) {
4dde5541 292 sub(/[hH][rR][eE][fF]=[ \t]*/,"href=",odp)
95fcfc77 293 match(odp,/href=[^ \t>]*/)
8dfac79d 294 link=substr(odp,RSTART,RLENGTH)
b5e77f8f 295 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
8dfac79d 296 link=substr(link,6,length(link)-5)
371e7443
AM
297
298 if (link_seen(link)) {
299 link=""
300 continue
301 }
302
8dfac79d 303 retval=(retval " " link)
95fcfc77 304 if (DEBUG) print "href(): " link
6f57d45d 305 } else {
fc589c7e
JB
306 # <a ...> but not href - skip
307 if (DEBUG) print "skipping <a > without href: " odp
93c3b403 308 }
3f63995d
SZ
309 }
310 } else {
8fef61cd 311 retval=("WGET ERROR: " errno ": " wholeerr)
3f63995d 312 }
f0c5c231
ER
313
314
157aa7fc 315 if (DEBUG) print "Returning: " retval
db4f445e 316 return retval
70a5e8d4
SZ
317}
318
6fb3305d 319function subst_defines(var,defs) {
3255b4c7 320# substitute all possible RPM macros
6fb3305d
SZ
321 while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) {
322 oldvar=var
323 for (j in defs) {
324 gsub("%{" j "}", defs[j], var)
325 gsub("%" j , defs[j], var)
326 }
327 if (var==oldvar) {
328 if ( DEBUG ) for (i in defs) print i " == " defs[i]
329 return var
330 }
331 }
332 return var
333}
334
c0bee1bc
JK
335function find_mirror(url) {
336
c54fbfc1
MK
337 while (succ = (getline line < "mirrors")) {
338 if (succ==-1) { return url }
c0bee1bc 339 nf=split(line,fields,"|")
a6f2cc98 340 if (nf>1){
c0bee1bc
JK
341 origin=fields[1]
342 mirror=fields[2]
343 mname=fields[3]
344 prefix=substr(url,1,length(origin))
345 if (prefix==origin){
157aa7fc 346 if ( DEBUG ) print "Mirror fount at " mname
c0bee1bc 347 close("mirrors")
21b99dbc 348 return mirror substr(url,length(origin)+1)
c0bee1bc
JK
349 }
350 }
351 }
352
353 return url
354}
355
32aede2f 356function process_source(number,lurl,name,version) {
3255b4c7 357# fetches file list, and compares version numbers
157aa7fc 358 if ( DEBUG ) print "Processing " lurl
3f63995d
SZ
359
360 if ( index(lurl,version)==0 ) {
157aa7fc 361 if (DEBUG) print "There is no version number."
3f63995d
SZ
362 return 0
363 }
364
6fb3305d
SZ
365 sub("://",":",lurl)
366 sub("/",":/",lurl)
367 gsub("[^/]*$",":&",lurl)
368 split(lurl,url,":")
369 acc=url[1]
370 host=url[2]
371 dir=url[3]
70a5e8d4
SZ
372 filename=url[4]
373
3f63995d 374 if (index(dir,version)) {
70a5e8d4
SZ
375 dir=substr(dir,1,index(dir,version)-1)
376 sub("[^/]*$","",dir)
377 sub("(\.tar\.(bz|bz2|gz)|zip)$","",filename)
157aa7fc
AM
378 if ( DEBUG ) print "Will check a directory: " dir
379 if ( DEBUG ) print "and a file: " filename
70a5e8d4 380 }
3f63995d 381
70a5e8d4
SZ
382 filenameexp=filename
383 gsub("\+","\\+",filenameexp)
0269da83 384 sub(version,"[A-Za-z0-9.]+",filenameexp)
e12bdf15 385 gsub("\.","\\.",filenameexp)
157aa7fc 386 if ( DEBUG ) print "Expression: " filenameexp
70a5e8d4
SZ
387 match(filename,version)
388 prever=substr(filename,1,RSTART-1)
389 postver=substr(filename,RSTART+RLENGTH)
157aa7fc
AM
390 if ( DEBUG ) print "Before number: " prever
391 if ( DEBUG ) print "and after: " postver
f0c5c231 392 newurl=find_mirror(acc "://" host dir)
c54fbfc1
MK
393 #print acc "://" host dir
394 #newurl=url[1]"://"url[2]url[3]url[4]
395 #newurl=acc "://" host dir filename
f0c5c231
ER
396 if ( DEBUG ) print "Looking at " newurl
397
6fb3305d 398 references=0
db83adc3 399 finished=0
db4f445e 400 oldversion=version
0ed4cd23 401 odp=get_links(newurl,filename)
3f63995d
SZ
402 if( odp ~ "ERROR: ") {
403 print name "(" number ") " odp
188dc51f 404 } else {
157aa7fc 405 if (DEBUG) print "WebPage downloaded"
188dc51f
SZ
406 c=split(odp,linki)
407 for (nr=1; nr<=c; nr++) {
408 addr=linki[nr]
157aa7fc 409 if (DEBUG) print "Found link: " addr
3c68e899 410 if ((addr ~ filenameexp) && !(addr ~ "[-_.0-9A-Za-z~]" filenameexp)) {
188dc51f
SZ
411 match(addr,filenameexp)
412 newfilename=substr(addr,RSTART,RLENGTH)
eae5334c 413 if (DEBUG) print "Hypothetical new: " newfilename
2aba2068
SZ
414 newfilename=fixedsub(prever,"",newfilename)
415 newfilename=fixedsub(postver,"",newfilename)
157aa7fc 416 if (DEBUG) print "Version: " newfilename
eb6fb288 417 if (newfilename ~ /\.(asc|sig|pkg|bin|binary|built)$/) continue
f11b5a76 418 if (NUMERIC) {
419 if ( compare_ver_dec(version, newfilename)==1 ) {
157aa7fc 420 if (DEBUG) print "Yes, there is new one"
f11b5a76 421 version=newfilename
422 finished=1
423 }
424 } else if ( compare_ver(version, newfilename)==1 ) {
157aa7fc 425 if (DEBUG) print "Yes, there is new one"
188dc51f
SZ
426 version=newfilename
427 finished=1
428 }
70a5e8d4 429 }
6fb3305d 430 }
188dc51f 431 if (finished==0)
f1b8a975 432 print name "(" number ") seems ok: " oldversion
188dc51f
SZ
433 else
434 print name "(" number ") [OLD] " oldversion " [NEW] " version
6fb3305d
SZ
435 }
436}
eae5334c
ER
437
438# upgrade check for pear package using PEAR CLI
439function pear_upgrade(name, ver) {
440 pname = name;
441 sub(/^php-pear-/, "", pname);
442
443 pearcmd = "pear remote-info " pname " | awk '/^Latest/{print $NF}'"
444 if (DEBUG) {
445 print "pearcmd: " pearcmd
446 }
447 pearcmd | getline nver
448 close(pearcmd)
449
450 if (compare_ver(ver, nver)) {
451 print name " [OLD] " ver " [NEW] " nver
452 } else {
453 print name " seems ok: " ver
454 }
455
456 return
457}
f0c5c231 458
3255b4c7 459function process_data(name,ver,rel,src) {
eae5334c
ER
460 if (name ~ /^php-pear-/) {
461 return pear_upgrade(name, ver);
462 }
463
3255b4c7
SZ
464# this function checks if substitutions were valid, and if true:
465# processes each URL and tries to get current file list
6fb3305d 466 for (i in src) {
254a5f0b
AM
467 if ( src[i] ~ /%{nil}/ ) {
468 gsub(/\%\{nil\}/, "", src[i])
469 }
6fb3305d 470 if ( src[i] !~ /%{.*}/ && src[i] !~ /%[A-Za-z0-9_]/ ) {
157aa7fc 471 if ( DEBUG ) print "Source: " src[i]
32aede2f 472 process_source(i,src[i],name,ver)
6fb3305d 473 } else {
c4a1f100 474 print FNAME ":" i ": impossible substitution: " src[i]
6fb3305d
SZ
475 }
476 }
477}
478
479BEGIN {
480 # if U want to use DEBUG, run script with "-v DEBUG=1"
481 # or uncomment the line below
70a5e8d4 482 # DEBUG = 1
2e301ef5
SZ
483
484 errno=system("wget --help > /dev/null 2>&1")
485 if (errno) {
486 print "No wget installed!"
487 exit 1
488 }
f11b5a76 489 if (ARGC>=3 && ARGV[2]=="-n") {
490 NUMERIC=1
f0c5c231 491 for (i=3; i<ARGC; i++) ARGV[i-1]=ARGV[i]
f11b5a76 492 ARGC=ARGC-1
493 }
6fb3305d
SZ
494}
495
496FNR==1 {
497 if ( ARGIND != 1 ) {
6aab34d4
AM
498 # clean frameseen for each ARG
499 for (i in frameseen) {
500 delete frameseen[i]
501 }
502 frameseen[0] = 1
503
3255b4c7 504 process_data(NAME,VER,REL,SRC)
6fb3305d
SZ
505 NAME="" ; VER="" ; REL=""
506 for (i in DEFS) delete DEFS[i]
507 for (i in SRC) delete SRC[i]
508 }
509 FNAME=FILENAME
f6c65bb7 510 DEFS["_alt_kernel"]=""
892e6dad 511 DEFS["20"]="\\ "
6fb3305d
SZ
512}
513
3255b4c7 514/^[Uu][Rr][Ll]:/&&(URL=="") { URL=subst_defines($2,DEFS) ; DEFS["url"]=URL }
6fb3305d
SZ
515/^[Nn]ame:/&&(NAME=="") { NAME=subst_defines($2,DEFS) ; DEFS["name"]=NAME }
516/^[Vv]ersion:/&&(VER=="") { VER=subst_defines($2,DEFS) ; DEFS["version"]=VER }
517/^[Rr]elease:/&&(REL=="") { REL=subst_defines($2,DEFS) ; DEFS["release"]=REL }
a10d5bbe 518/^[Ss]ource[0-9]*:/ { if (/(ftp|http|https):\/\//) SRC[FNR]=subst_defines($2,DEFS) }
6fb3305d
SZ
519/%define/ { DEFS[$2]=subst_defines($3,DEFS) }
520
521END {
3255b4c7 522 process_data(NAME,VER,REL,SRC)
6fb3305d 523}
This page took 0.134928 seconds and 4 git commands to generate.