]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - pldnotify.awk
- don't pollute specdir with builder macros
[packages/rpm-build-tools.git] / pldnotify.awk
CommitLineData
6fb3305d 1#!/bin/awk -f
d4089f30 2# $Revision$, $Date$
3ca67c5b
JB
3# TODO: "SourceXDownload" support (use given URLs if present instead of cut-down SourceX URLs)
4
2aba2068
SZ
5function fixedsub(s1,s2,t, ind) {
6# substitutes fixed strings (not regexps)
7 if (ind = index(t,s1)) {
8 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
9 }
10 return t
11}
6fb3305d 12
e3c5f324
JB
13function ispre(s) {
14 if ((s~"pre")||(s~"PRE")||(s~"beta")||(s~"BETA")||(s~"alpha")||(s~"ALPHA")||(s~"rc")||(s~"RC")) {
15 if (DEBUG) print "pre-version"
16 return 1
17 } else {
18 return 0
19 }
20}
f0c5c231 21
70a5e8d4
SZ
22function compare_ver(v1,v2) {
23# compares version numbers
24 while (match(v1,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
25 v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1))
26 while (match(v2,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
27 v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1))
28 sub("^0*","",v1)
29 sub("^0*","",v2)
e2ebf07c
JB
30 gsub("\.0*",".",v1)
31 gsub("\.0*",".",v2)
70a5e8d4
SZ
32 if (DEBUG) print "v1 == " v1
33 if (DEBUG) print "v2 == " v2
34 count=split(v1,v1a,"\.")
35 count2=split(v2,v2a,"\.")
f0c5c231
ER
36
37 if (count<count2) mincount=count
70a5e8d4 38 else mincount=count2
f0c5c231 39
70a5e8d4 40 for (i=1; i<=mincount; i++) {
db83adc3
SZ
41 if (v1a[i]=="") v1a[i]=0
42 if (v2a[i]=="") v2a[i]=0
70a5e8d4
SZ
43 if (DEBUG) print "i == " i
44 if (DEBUG) print "v1[i] == " v1a[i]
45 if (DEBUG) print "v2[i] == " v2a[i]
46 if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) {
47 if (length(v2a[i])>length(v1a[i]))
48 return 1
49 else if (v2a[i]>v1a[i])
50 return 1
51 else if (length(v1a[i])>length(v2a[i]))
52 return 0
53 else if (v1a[i]>v2a[i])
54 return 0
55 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
56 if (v2a[i]>v1a[i])
57 return 1
58 else if (v1a[i]>v2a[i])
59 return 0
e3c5f324 60 } else if (ispre(v1a[i]) == 1)
70a5e8d4
SZ
61 return 1
62 else
63 return 0
64 }
65 if ((count2==mincount)&&(count!=count2)) {
66 for (i=count2+1; i<=count; i++)
e3c5f324 67 if (ispre(v1a[i]) == 1)
70a5e8d4
SZ
68 return 1
69 return 0
70 } else if (count!=count2) {
71 for (i=count+1; i<=count2; i++)
e3c5f324 72 if (ispre(v2a[i]) == 1)
70a5e8d4
SZ
73 return 0
74 return 1
75 }
db4f445e 76 return 0
70a5e8d4
SZ
77}
78
f11b5a76 79function compare_ver_dec(v1,v2) {
b8b1ac2a 80# compares version numbers as decimal floats
f11b5a76 81 while (match(v1,/[0-9][a-zA-Z]/))
82 v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1))
83 while (match(v2,/[0-9][a-zA-Z]/))
84 v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1))
85 sub("^0*","",v1)
86 sub("^0*","",v2)
87 if (DEBUG) print "v1 == " v1
88 if (DEBUG) print "v2 == " v2
89 count=split(v1,v1a,"\.")
90 count2=split(v2,v2a,"\.")
f0c5c231
ER
91
92 if (count<count2) mincount=count
f11b5a76 93 else mincount=count2
f0c5c231 94
f11b5a76 95 for (i=1; i<=mincount; i++) {
96 if (v1a[i]=="") v1a[i]=0
97 if (v2a[i]=="") v2a[i]=0
98 if (DEBUG) print "i == " i
99 if (DEBUG) print "v1[i] == " v1a[i]
100 if (DEBUG) print "v2[i] == " v2a[i]
101 if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) {
102 if (i==2) {
103 if (0+("." v2a[i])>0+("." v1a[i]))
104 return 1
105 else if (0+("." v1a[i])>0+("." v2a[i]))
106 return 0
107 } else {
108 if (length(v2a[i])>length(v1a[i]))
109 return 1
110 else if (v2a[i]>v1a[i])
111 return 1
112 else if (length(v1a[i])>length(v2a[i]))
113 return 0
114 else if (v1a[i]>v2a[i])
115 return 0
116 }
117 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
118 if (v2a[i]>v1a[i])
119 return 1
120 else if (v1a[i]>v2a[i])
121 return 0
e3c5f324 122 } else if (ispre(v1a[i]) == 1)
f11b5a76 123 return 1
124 else
125 return 0
126 }
127 if ((count2==mincount)&&(count!=count2)) {
128 for (i=count2+1; i<=count; i++)
e3c5f324 129 if (ispre(v1a[i]) == 1)
f11b5a76 130 return 1
131 return 0
132 } else if (count!=count2) {
133 for (i=count+1; i<=count2; i++)
e3c5f324 134 if (ispre(v2a[i]) == 1)
f11b5a76 135 return 0
136 return 1
137 }
138 return 0
139}
140
fc589c7e 141function get_links(url, errno,link,oneline,retval,odp,wholeodp,lowerodp,tmpfile) {
70a5e8d4 142# get all <A HREF=..> tags from specified URL
db4f445e
SZ
143 "mktemp /tmp/XXXXXX" | getline tmpfile
144 close("mktemp /tmp/XXXXXX")
356ec898 145
ea4c106c
ER
146 if (url ~ /^http:\/\/(download|dl).(sf|sourceforge).net\//) {
147 gsub("^http://(download|dl).(sf|sourceforge).net/", "", url)
a9dc9975 148 url = "http://prdownloads.sourceforge.net/" substr(url, 1, 1) "/" substr(url, 1, 2) "/" url
356ec898
ER
149 if (DEBUG) print "sf url, mungled url to: " url
150 }
f0c5c231 151
2e301ef5 152 if (DEBUG) print "Retrieving: " url
2d9cc4bb 153 errno=system("wget -O - \"" url "\" -t 3 -T 300 --passive-ftp > " tmpfile " 2>/dev/null" )
f0c5c231 154
3f63995d 155 if (errno==0) {
7f460828 156 while (getline oneline < tmpfile)
fc589c7e
JB
157 wholeodp=(wholeodp " " oneline)
158 if ( DEBUG ) print "Response: " wholeodp
70a5e8d4 159 }
f0c5c231 160
3f63995d 161 close(tmpfile)
2e301ef5 162 system("rm -f " tmpfile)
55658186
JB
163 urldir=url;
164 sub(/[^\/]+$/,"",urldir)
fc589c7e 165
3f63995d 166 if ( errno==0) {
fc589c7e
JB
167 while (match(wholeodp, /<([aA]|[fF][rR][aA][mM][eE])[ \t][^>]*>/) > 0) {
168 odp=substr(wholeodp,RSTART,RLENGTH);
169 wholeodp=substr(wholeodp,RSTART+RLENGTH);
170
171 lowerodp=tolower(odp);
172 if (lowerodp ~ /<frame[ \t]/) {
173 sub(/[sS][rR][cC]=[ \t]*/,"src=",odp);
174 match(odp,/src="[^"]+"/)
175 newurl=substr(odp,RSTART+5,RLENGTH-6)
157aa7fc 176 if (DEBUG) print "Frame: " newurl
55658186
JB
177 if (newurl !~ /\//) {
178 newurl=(urldir newurl)
157aa7fc 179 if (DEBUG) print "Frame->: " newurl
55658186 180 }
2e301ef5 181 retval=(retval " " get_links(newurl))
fc589c7e 182 } else if (lowerodp ~ /href=[ \t]*"[^"]*"/) {
b5e77f8f 183 sub(/[hH][rR][eE][fF]=[ \t]*"/,"href=\"",odp)
95fcfc77 184 match(odp,/href="[^"]*"/)
b5e77f8f
JB
185 link=substr(odp,RSTART,RLENGTH)
186 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
187 link=substr(link,7,length(link)-7)
188 retval=(retval " " link)
95fcfc77 189 if (DEBUG) print "href(\"\"): " link
fc589c7e 190 } else if (lowerodp ~ /href=[ \t]*'[^']*'/) {
b5e77f8f 191 sub(/[hH][rR][eE][fF]=[ \t]*'/,"href='",odp)
95fcfc77 192 match(odp,/href='[^']*'/)
93c3b403 193 link=substr(odp,RSTART,RLENGTH)
b5e77f8f 194 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
93c3b403
SZ
195 link=substr(link,7,length(link)-7)
196 retval=(retval " " link)
95fcfc77 197 if (DEBUG) print "href(''): " link
fc589c7e 198 } else if (lowerodp ~ /href=[ \t]*[^ \t>]*/) {
4dde5541 199 sub(/[hH][rR][eE][fF]=[ \t]*/,"href=",odp)
95fcfc77 200 match(odp,/href=[^ \t>]*/)
8dfac79d 201 link=substr(odp,RSTART,RLENGTH)
b5e77f8f 202 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
8dfac79d
SZ
203 link=substr(link,6,length(link)-5)
204 retval=(retval " " link)
95fcfc77 205 if (DEBUG) print "href(): " link
6f57d45d 206 } else {
fc589c7e
JB
207 # <a ...> but not href - skip
208 if (DEBUG) print "skipping <a > without href: " odp
93c3b403 209 }
3f63995d
SZ
210 }
211 } else {
2e301ef5 212 retval=("WGET ERROR: " errno)
3f63995d 213 }
f0c5c231
ER
214
215
157aa7fc 216 if (DEBUG) print "Returning: " retval
db4f445e 217 return retval
70a5e8d4
SZ
218}
219
6fb3305d 220function subst_defines(var,defs) {
3255b4c7 221# substitute all possible RPM macros
6fb3305d
SZ
222 while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) {
223 oldvar=var
224 for (j in defs) {
225 gsub("%{" j "}", defs[j], var)
226 gsub("%" j , defs[j], var)
227 }
228 if (var==oldvar) {
229 if ( DEBUG ) for (i in defs) print i " == " defs[i]
230 return var
231 }
232 }
233 return var
234}
235
c0bee1bc
JK
236function find_mirror(url) {
237
c54fbfc1
MK
238 while (succ = (getline line < "mirrors")) {
239 if (succ==-1) { return url }
c0bee1bc 240 nf=split(line,fields,"|")
a6f2cc98 241 if (nf>1){
c0bee1bc
JK
242 origin=fields[1]
243 mirror=fields[2]
244 mname=fields[3]
245 prefix=substr(url,1,length(origin))
246 if (prefix==origin){
157aa7fc 247 if ( DEBUG ) print "Mirror fount at " mname
c0bee1bc 248 close("mirrors")
21b99dbc 249 return mirror substr(url,length(origin)+1)
c0bee1bc
JK
250 }
251 }
252 }
253
254 return url
255}
256
32aede2f 257function process_source(number,lurl,name,version) {
3255b4c7 258# fetches file list, and compares version numbers
157aa7fc 259 if ( DEBUG ) print "Processing " lurl
3f63995d
SZ
260
261 if ( index(lurl,version)==0 ) {
157aa7fc 262 if (DEBUG) print "There is no version number."
3f63995d
SZ
263 return 0
264 }
265
6fb3305d
SZ
266 sub("://",":",lurl)
267 sub("/",":/",lurl)
268 gsub("[^/]*$",":&",lurl)
269 split(lurl,url,":")
270 acc=url[1]
271 host=url[2]
272 dir=url[3]
70a5e8d4
SZ
273 filename=url[4]
274
3f63995d 275 if (index(dir,version)) {
70a5e8d4
SZ
276 dir=substr(dir,1,index(dir,version)-1)
277 sub("[^/]*$","",dir)
278 sub("(\.tar\.(bz|bz2|gz)|zip)$","",filename)
157aa7fc
AM
279 if ( DEBUG ) print "Will check a directory: " dir
280 if ( DEBUG ) print "and a file: " filename
70a5e8d4 281 }
3f63995d 282
70a5e8d4
SZ
283 filenameexp=filename
284 gsub("\+","\\+",filenameexp)
0269da83 285 sub(version,"[A-Za-z0-9.]+",filenameexp)
e12bdf15 286 gsub("\.","\\.",filenameexp)
157aa7fc 287 if ( DEBUG ) print "Expression: " filenameexp
70a5e8d4
SZ
288 match(filename,version)
289 prever=substr(filename,1,RSTART-1)
290 postver=substr(filename,RSTART+RLENGTH)
157aa7fc
AM
291 if ( DEBUG ) print "Before number: " prever
292 if ( DEBUG ) print "and after: " postver
f0c5c231 293 newurl=find_mirror(acc "://" host dir)
c54fbfc1
MK
294 #print acc "://" host dir
295 #newurl=url[1]"://"url[2]url[3]url[4]
296 #newurl=acc "://" host dir filename
f0c5c231
ER
297 if ( DEBUG ) print "Looking at " newurl
298
6fb3305d 299 references=0
db83adc3 300 finished=0
db4f445e 301 oldversion=version
c0bee1bc 302 odp=get_links(newurl)
3f63995d
SZ
303 if( odp ~ "ERROR: ") {
304 print name "(" number ") " odp
188dc51f 305 } else {
157aa7fc 306 if (DEBUG) print "WebPage downloaded"
188dc51f
SZ
307 c=split(odp,linki)
308 for (nr=1; nr<=c; nr++) {
309 addr=linki[nr]
157aa7fc 310 if (DEBUG) print "Found link: " addr
3c68e899 311 if ((addr ~ filenameexp) && !(addr ~ "[-_.0-9A-Za-z~]" filenameexp)) {
188dc51f
SZ
312 match(addr,filenameexp)
313 newfilename=substr(addr,RSTART,RLENGTH)
eae5334c 314 if (DEBUG) print "Hypothetical new: " newfilename
2aba2068
SZ
315 newfilename=fixedsub(prever,"",newfilename)
316 newfilename=fixedsub(postver,"",newfilename)
157aa7fc 317 if (DEBUG) print "Version: " newfilename
155ac0a8 318 if (newfilename ~ /\.(pkg|bin|binary|built)$/) continue
f11b5a76 319 if (NUMERIC) {
320 if ( compare_ver_dec(version, newfilename)==1 ) {
157aa7fc 321 if (DEBUG) print "Yes, there is new one"
f11b5a76 322 version=newfilename
323 finished=1
324 }
325 } else if ( compare_ver(version, newfilename)==1 ) {
157aa7fc 326 if (DEBUG) print "Yes, there is new one"
188dc51f
SZ
327 version=newfilename
328 finished=1
329 }
70a5e8d4 330 }
6fb3305d 331 }
188dc51f 332 if (finished==0)
f1b8a975 333 print name "(" number ") seems ok: " oldversion
188dc51f
SZ
334 else
335 print name "(" number ") [OLD] " oldversion " [NEW] " version
6fb3305d
SZ
336 }
337}
eae5334c
ER
338
339# upgrade check for pear package using PEAR CLI
340function pear_upgrade(name, ver) {
341 pname = name;
342 sub(/^php-pear-/, "", pname);
343
344 pearcmd = "pear remote-info " pname " | awk '/^Latest/{print $NF}'"
345 if (DEBUG) {
346 print "pearcmd: " pearcmd
347 }
348 pearcmd | getline nver
349 close(pearcmd)
350
351 if (compare_ver(ver, nver)) {
352 print name " [OLD] " ver " [NEW] " nver
353 } else {
354 print name " seems ok: " ver
355 }
356
357 return
358}
f0c5c231 359
3255b4c7 360function process_data(name,ver,rel,src) {
eae5334c
ER
361 if (name ~ /^php-pear-/) {
362 return pear_upgrade(name, ver);
363 }
364
3255b4c7
SZ
365# this function checks if substitutions were valid, and if true:
366# processes each URL and tries to get current file list
6fb3305d
SZ
367 for (i in src) {
368 if ( src[i] !~ /%{.*}/ && src[i] !~ /%[A-Za-z0-9_]/ ) {
157aa7fc 369 if ( DEBUG ) print "Source: " src[i]
32aede2f 370 process_source(i,src[i],name,ver)
6fb3305d 371 } else {
c4a1f100 372 print FNAME ":" i ": impossible substitution: " src[i]
6fb3305d
SZ
373 }
374 }
375}
376
377BEGIN {
378 # if U want to use DEBUG, run script with "-v DEBUG=1"
379 # or uncomment the line below
70a5e8d4 380 # DEBUG = 1
2e301ef5
SZ
381
382 errno=system("wget --help > /dev/null 2>&1")
383 if (errno) {
384 print "No wget installed!"
385 exit 1
386 }
f11b5a76 387 if (ARGC>=3 && ARGV[2]=="-n") {
388 NUMERIC=1
f0c5c231 389 for (i=3; i<ARGC; i++) ARGV[i-1]=ARGV[i]
f11b5a76 390 ARGC=ARGC-1
391 }
6fb3305d
SZ
392}
393
394FNR==1 {
395 if ( ARGIND != 1 ) {
3255b4c7 396 process_data(NAME,VER,REL,SRC)
6fb3305d
SZ
397 NAME="" ; VER="" ; REL=""
398 for (i in DEFS) delete DEFS[i]
399 for (i in SRC) delete SRC[i]
400 }
401 FNAME=FILENAME
402}
403
3255b4c7 404/^[Uu][Rr][Ll]:/&&(URL=="") { URL=subst_defines($2,DEFS) ; DEFS["url"]=URL }
6fb3305d
SZ
405/^[Nn]ame:/&&(NAME=="") { NAME=subst_defines($2,DEFS) ; DEFS["name"]=NAME }
406/^[Vv]ersion:/&&(VER=="") { VER=subst_defines($2,DEFS) ; DEFS["version"]=VER }
407/^[Rr]elease:/&&(REL=="") { REL=subst_defines($2,DEFS) ; DEFS["release"]=REL }
408/^[Ss]ource[0-9]*:/ { if (/(ftp|http):\/\//) SRC[FNR]=subst_defines($2,DEFS) }
409/%define/ { DEFS[$2]=subst_defines($3,DEFS) }
410
411END {
3255b4c7 412 process_data(NAME,VER,REL,SRC)
6fb3305d 413}
This page took 0.12006 seconds and 4 git commands to generate.