]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - pldnotify.awk
- 300 is far too much
[packages/rpm-build-tools.git] / pldnotify.awk
CommitLineData
6fb3305d 1#!/bin/awk -f
d4089f30 2# $Revision$, $Date$
b52a0a12 3#
109ec22a 4# Copyright (C) 2000-2008 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
0ed4cd23 154function get_links(url,filename,errno,link,oneline,retval,odp,wholeodp,lowerodp,tmpfile) {
70a5e8d4 155# get all <A HREF=..> tags from specified URL
db4f445e
SZ
156 "mktemp /tmp/XXXXXX" | getline tmpfile
157 close("mktemp /tmp/XXXXXX")
356ec898 158
ea4c106c
ER
159 if (url ~ /^http:\/\/(download|dl).(sf|sourceforge).net\//) {
160 gsub("^http://(download|dl).(sf|sourceforge).net/", "", url)
a9dc9975 161 url = "http://prdownloads.sourceforge.net/" substr(url, 1, 1) "/" substr(url, 1, 2) "/" url
356ec898
ER
162 if (DEBUG) print "sf url, mungled url to: " url
163 }
f0c5c231 164
109ec22a 165 if (url ~ /^http:\/\/(.*)\.googlecode\.com\/files\//) {
3836b919
AM
166 gsub("^http://", "", url)
167 gsub("\..*", "", url)
b3df8960 168 url = "http://code.google.com/p/" url "/downloads/list"
3836b919
AM
169 if (DEBUG) print "googlecode url, mungled url to: " url
170 }
171
0ed4cd23
AM
172 if (url ~ /^http:\/\/pecl.php.net\/get\//) {
173 gsub("-.*", "", filename)
174 url = "http://pecl.php.net/package/" filename
175 if (DEBUG) print "pecl.php.net url, mungled url to: " url
176 }
177
fbf290ff
AM
178 if (url ~ /^(http|ftp):\/\/mysql.*\/Downloads\/MySQL-5.1\//) {
179 url = "http://dev.mysql.com/downloads/mysql/5.1.html#source"
180 if (DEBUG) print "mysql 5.1 url, mungled url to: " url
181 }
182
183
2e301ef5 184 if (DEBUG) print "Retrieving: " url
006dd08f 185 errno=system("wget -O - \"" url "\" -t 2 -T 45 --passive-ftp > " tmpfile " 2>/dev/null" )
f0c5c231 186
3f63995d 187 if (errno==0) {
7f460828 188 while (getline oneline < tmpfile)
fc589c7e
JB
189 wholeodp=(wholeodp " " oneline)
190 if ( DEBUG ) print "Response: " wholeodp
70a5e8d4 191 }
f0c5c231 192
3f63995d 193 close(tmpfile)
2e301ef5 194 system("rm -f " tmpfile)
55658186
JB
195 urldir=url;
196 sub(/[^\/]+$/,"",urldir)
fc589c7e 197
3f63995d 198 if ( errno==0) {
fc589c7e
JB
199 while (match(wholeodp, /<([aA]|[fF][rR][aA][mM][eE])[ \t][^>]*>/) > 0) {
200 odp=substr(wholeodp,RSTART,RLENGTH);
201 wholeodp=substr(wholeodp,RSTART+RLENGTH);
202
203 lowerodp=tolower(odp);
204 if (lowerodp ~ /<frame[ \t]/) {
205 sub(/[sS][rR][cC]=[ \t]*/,"src=",odp);
206 match(odp,/src="[^"]+"/)
207 newurl=substr(odp,RSTART+5,RLENGTH-6)
157aa7fc 208 if (DEBUG) print "Frame: " newurl
55658186
JB
209 if (newurl !~ /\//) {
210 newurl=(urldir newurl)
157aa7fc 211 if (DEBUG) print "Frame->: " newurl
55658186 212 }
2e301ef5 213 retval=(retval " " get_links(newurl))
fc589c7e 214 } else if (lowerodp ~ /href=[ \t]*"[^"]*"/) {
b5e77f8f 215 sub(/[hH][rR][eE][fF]=[ \t]*"/,"href=\"",odp)
95fcfc77 216 match(odp,/href="[^"]*"/)
b5e77f8f
JB
217 link=substr(odp,RSTART,RLENGTH)
218 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
219 link=substr(link,7,length(link)-7)
220 retval=(retval " " link)
95fcfc77 221 if (DEBUG) print "href(\"\"): " link
fc589c7e 222 } else if (lowerodp ~ /href=[ \t]*'[^']*'/) {
b5e77f8f 223 sub(/[hH][rR][eE][fF]=[ \t]*'/,"href='",odp)
95fcfc77 224 match(odp,/href='[^']*'/)
93c3b403 225 link=substr(odp,RSTART,RLENGTH)
b5e77f8f 226 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
93c3b403
SZ
227 link=substr(link,7,length(link)-7)
228 retval=(retval " " link)
95fcfc77 229 if (DEBUG) print "href(''): " link
fc589c7e 230 } else if (lowerodp ~ /href=[ \t]*[^ \t>]*/) {
4dde5541 231 sub(/[hH][rR][eE][fF]=[ \t]*/,"href=",odp)
95fcfc77 232 match(odp,/href=[^ \t>]*/)
8dfac79d 233 link=substr(odp,RSTART,RLENGTH)
b5e77f8f 234 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
8dfac79d
SZ
235 link=substr(link,6,length(link)-5)
236 retval=(retval " " link)
95fcfc77 237 if (DEBUG) print "href(): " link
6f57d45d 238 } else {
fc589c7e
JB
239 # <a ...> but not href - skip
240 if (DEBUG) print "skipping <a > without href: " odp
93c3b403 241 }
3f63995d
SZ
242 }
243 } else {
2e301ef5 244 retval=("WGET ERROR: " errno)
3f63995d 245 }
f0c5c231
ER
246
247
157aa7fc 248 if (DEBUG) print "Returning: " retval
db4f445e 249 return retval
70a5e8d4
SZ
250}
251
6fb3305d 252function subst_defines(var,defs) {
3255b4c7 253# substitute all possible RPM macros
6fb3305d
SZ
254 while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) {
255 oldvar=var
256 for (j in defs) {
257 gsub("%{" j "}", defs[j], var)
258 gsub("%" j , defs[j], var)
259 }
260 if (var==oldvar) {
261 if ( DEBUG ) for (i in defs) print i " == " defs[i]
262 return var
263 }
264 }
265 return var
266}
267
c0bee1bc
JK
268function find_mirror(url) {
269
c54fbfc1
MK
270 while (succ = (getline line < "mirrors")) {
271 if (succ==-1) { return url }
c0bee1bc 272 nf=split(line,fields,"|")
a6f2cc98 273 if (nf>1){
c0bee1bc
JK
274 origin=fields[1]
275 mirror=fields[2]
276 mname=fields[3]
277 prefix=substr(url,1,length(origin))
278 if (prefix==origin){
157aa7fc 279 if ( DEBUG ) print "Mirror fount at " mname
c0bee1bc 280 close("mirrors")
21b99dbc 281 return mirror substr(url,length(origin)+1)
c0bee1bc
JK
282 }
283 }
284 }
285
286 return url
287}
288
32aede2f 289function process_source(number,lurl,name,version) {
3255b4c7 290# fetches file list, and compares version numbers
157aa7fc 291 if ( DEBUG ) print "Processing " lurl
3f63995d
SZ
292
293 if ( index(lurl,version)==0 ) {
157aa7fc 294 if (DEBUG) print "There is no version number."
3f63995d
SZ
295 return 0
296 }
297
6fb3305d
SZ
298 sub("://",":",lurl)
299 sub("/",":/",lurl)
300 gsub("[^/]*$",":&",lurl)
301 split(lurl,url,":")
302 acc=url[1]
303 host=url[2]
304 dir=url[3]
70a5e8d4
SZ
305 filename=url[4]
306
3f63995d 307 if (index(dir,version)) {
70a5e8d4
SZ
308 dir=substr(dir,1,index(dir,version)-1)
309 sub("[^/]*$","",dir)
310 sub("(\.tar\.(bz|bz2|gz)|zip)$","",filename)
157aa7fc
AM
311 if ( DEBUG ) print "Will check a directory: " dir
312 if ( DEBUG ) print "and a file: " filename
70a5e8d4 313 }
3f63995d 314
70a5e8d4
SZ
315 filenameexp=filename
316 gsub("\+","\\+",filenameexp)
0269da83 317 sub(version,"[A-Za-z0-9.]+",filenameexp)
e12bdf15 318 gsub("\.","\\.",filenameexp)
157aa7fc 319 if ( DEBUG ) print "Expression: " filenameexp
70a5e8d4
SZ
320 match(filename,version)
321 prever=substr(filename,1,RSTART-1)
322 postver=substr(filename,RSTART+RLENGTH)
157aa7fc
AM
323 if ( DEBUG ) print "Before number: " prever
324 if ( DEBUG ) print "and after: " postver
f0c5c231 325 newurl=find_mirror(acc "://" host dir)
c54fbfc1
MK
326 #print acc "://" host dir
327 #newurl=url[1]"://"url[2]url[3]url[4]
328 #newurl=acc "://" host dir filename
f0c5c231
ER
329 if ( DEBUG ) print "Looking at " newurl
330
6fb3305d 331 references=0
db83adc3 332 finished=0
db4f445e 333 oldversion=version
0ed4cd23 334 odp=get_links(newurl,filename)
3f63995d
SZ
335 if( odp ~ "ERROR: ") {
336 print name "(" number ") " odp
188dc51f 337 } else {
157aa7fc 338 if (DEBUG) print "WebPage downloaded"
188dc51f
SZ
339 c=split(odp,linki)
340 for (nr=1; nr<=c; nr++) {
341 addr=linki[nr]
157aa7fc 342 if (DEBUG) print "Found link: " addr
3c68e899 343 if ((addr ~ filenameexp) && !(addr ~ "[-_.0-9A-Za-z~]" filenameexp)) {
188dc51f
SZ
344 match(addr,filenameexp)
345 newfilename=substr(addr,RSTART,RLENGTH)
eae5334c 346 if (DEBUG) print "Hypothetical new: " newfilename
2aba2068
SZ
347 newfilename=fixedsub(prever,"",newfilename)
348 newfilename=fixedsub(postver,"",newfilename)
157aa7fc 349 if (DEBUG) print "Version: " newfilename
155ac0a8 350 if (newfilename ~ /\.(pkg|bin|binary|built)$/) continue
f11b5a76 351 if (NUMERIC) {
352 if ( compare_ver_dec(version, newfilename)==1 ) {
157aa7fc 353 if (DEBUG) print "Yes, there is new one"
f11b5a76 354 version=newfilename
355 finished=1
356 }
357 } else if ( compare_ver(version, newfilename)==1 ) {
157aa7fc 358 if (DEBUG) print "Yes, there is new one"
188dc51f
SZ
359 version=newfilename
360 finished=1
361 }
70a5e8d4 362 }
6fb3305d 363 }
188dc51f 364 if (finished==0)
f1b8a975 365 print name "(" number ") seems ok: " oldversion
188dc51f
SZ
366 else
367 print name "(" number ") [OLD] " oldversion " [NEW] " version
6fb3305d
SZ
368 }
369}
eae5334c
ER
370
371# upgrade check for pear package using PEAR CLI
372function pear_upgrade(name, ver) {
373 pname = name;
374 sub(/^php-pear-/, "", pname);
375
376 pearcmd = "pear remote-info " pname " | awk '/^Latest/{print $NF}'"
377 if (DEBUG) {
378 print "pearcmd: " pearcmd
379 }
380 pearcmd | getline nver
381 close(pearcmd)
382
383 if (compare_ver(ver, nver)) {
384 print name " [OLD] " ver " [NEW] " nver
385 } else {
386 print name " seems ok: " ver
387 }
388
389 return
390}
f0c5c231 391
3255b4c7 392function process_data(name,ver,rel,src) {
eae5334c
ER
393 if (name ~ /^php-pear-/) {
394 return pear_upgrade(name, ver);
395 }
396
3255b4c7
SZ
397# this function checks if substitutions were valid, and if true:
398# processes each URL and tries to get current file list
6fb3305d 399 for (i in src) {
254a5f0b
AM
400 if ( src[i] ~ /%{nil}/ ) {
401 gsub(/\%\{nil\}/, "", src[i])
402 }
6fb3305d 403 if ( src[i] !~ /%{.*}/ && src[i] !~ /%[A-Za-z0-9_]/ ) {
157aa7fc 404 if ( DEBUG ) print "Source: " src[i]
32aede2f 405 process_source(i,src[i],name,ver)
6fb3305d 406 } else {
c4a1f100 407 print FNAME ":" i ": impossible substitution: " src[i]
6fb3305d
SZ
408 }
409 }
410}
411
412BEGIN {
413 # if U want to use DEBUG, run script with "-v DEBUG=1"
414 # or uncomment the line below
70a5e8d4 415 # DEBUG = 1
2e301ef5
SZ
416
417 errno=system("wget --help > /dev/null 2>&1")
418 if (errno) {
419 print "No wget installed!"
420 exit 1
421 }
f11b5a76 422 if (ARGC>=3 && ARGV[2]=="-n") {
423 NUMERIC=1
f0c5c231 424 for (i=3; i<ARGC; i++) ARGV[i-1]=ARGV[i]
f11b5a76 425 ARGC=ARGC-1
426 }
6fb3305d
SZ
427}
428
429FNR==1 {
430 if ( ARGIND != 1 ) {
3255b4c7 431 process_data(NAME,VER,REL,SRC)
6fb3305d
SZ
432 NAME="" ; VER="" ; REL=""
433 for (i in DEFS) delete DEFS[i]
434 for (i in SRC) delete SRC[i]
435 }
436 FNAME=FILENAME
f6c65bb7 437 DEFS["_alt_kernel"]=""
892e6dad 438 DEFS["20"]="\\ "
6fb3305d
SZ
439}
440
3255b4c7 441/^[Uu][Rr][Ll]:/&&(URL=="") { URL=subst_defines($2,DEFS) ; DEFS["url"]=URL }
6fb3305d
SZ
442/^[Nn]ame:/&&(NAME=="") { NAME=subst_defines($2,DEFS) ; DEFS["name"]=NAME }
443/^[Vv]ersion:/&&(VER=="") { VER=subst_defines($2,DEFS) ; DEFS["version"]=VER }
444/^[Rr]elease:/&&(REL=="") { REL=subst_defines($2,DEFS) ; DEFS["release"]=REL }
a10d5bbe 445/^[Ss]ource[0-9]*:/ { if (/(ftp|http|https):\/\//) SRC[FNR]=subst_defines($2,DEFS) }
6fb3305d
SZ
446/%define/ { DEFS[$2]=subst_defines($3,DEFS) }
447
448END {
3255b4c7 449 process_data(NAME,VER,REL,SRC)
6fb3305d 450}
This page took 0.201785 seconds and 4 git commands to generate.