]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - pldnotify.awk
- mirror handling bugfix
[packages/rpm-build-tools.git] / pldnotify.awk
CommitLineData
6fb3305d 1#!/bin/awk -f
d4089f30 2# $Revision$, $Date$
2aba2068
SZ
3function fixedsub(s1,s2,t, ind) {
4# substitutes fixed strings (not regexps)
5 if (ind = index(t,s1)) {
6 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
7 }
8 return t
9}
6fb3305d 10
e3c5f324
JB
11function ispre(s) {
12 if ((s~"pre")||(s~"PRE")||(s~"beta")||(s~"BETA")||(s~"alpha")||(s~"ALPHA")||(s~"rc")||(s~"RC")) {
13 if (DEBUG) print "pre-version"
14 return 1
15 } else {
16 return 0
17 }
18}
19
70a5e8d4
SZ
20function compare_ver(v1,v2) {
21# compares version numbers
22 while (match(v1,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
23 v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1))
24 while (match(v2,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
25 v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1))
26 sub("^0*","",v1)
27 sub("^0*","",v2)
e2ebf07c
JB
28 gsub("\.0*",".",v1)
29 gsub("\.0*",".",v2)
70a5e8d4
SZ
30 if (DEBUG) print "v1 == " v1
31 if (DEBUG) print "v2 == " v2
32 count=split(v1,v1a,"\.")
33 count2=split(v2,v2a,"\.")
34
35 if (count<count2) mincount=count
36 else mincount=count2
37
38 for (i=1; i<=mincount; i++) {
db83adc3
SZ
39 if (v1a[i]=="") v1a[i]=0
40 if (v2a[i]=="") v2a[i]=0
70a5e8d4
SZ
41 if (DEBUG) print "i == " i
42 if (DEBUG) print "v1[i] == " v1a[i]
43 if (DEBUG) print "v2[i] == " v2a[i]
44 if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) {
45 if (length(v2a[i])>length(v1a[i]))
46 return 1
47 else if (v2a[i]>v1a[i])
48 return 1
49 else if (length(v1a[i])>length(v2a[i]))
50 return 0
51 else if (v1a[i]>v2a[i])
52 return 0
53 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
54 if (v2a[i]>v1a[i])
55 return 1
56 else if (v1a[i]>v2a[i])
57 return 0
e3c5f324 58 } else if (ispre(v1a[i]) == 1)
70a5e8d4
SZ
59 return 1
60 else
61 return 0
62 }
63 if ((count2==mincount)&&(count!=count2)) {
64 for (i=count2+1; i<=count; i++)
e3c5f324 65 if (ispre(v1a[i]) == 1)
70a5e8d4
SZ
66 return 1
67 return 0
68 } else if (count!=count2) {
69 for (i=count+1; i<=count2; i++)
e3c5f324 70 if (ispre(v2a[i]) == 1)
70a5e8d4
SZ
71 return 0
72 return 1
73 }
db4f445e 74 return 0
70a5e8d4
SZ
75}
76
f11b5a76 77function compare_ver_dec(v1,v2) {
b8b1ac2a 78# compares version numbers as decimal floats
f11b5a76 79 while (match(v1,/[0-9][a-zA-Z]/))
80 v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1))
81 while (match(v2,/[0-9][a-zA-Z]/))
82 v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1))
83 sub("^0*","",v1)
84 sub("^0*","",v2)
85 if (DEBUG) print "v1 == " v1
86 if (DEBUG) print "v2 == " v2
87 count=split(v1,v1a,"\.")
88 count2=split(v2,v2a,"\.")
89
90 if (count<count2) mincount=count
91 else mincount=count2
92
93 for (i=1; i<=mincount; i++) {
94 if (v1a[i]=="") v1a[i]=0
95 if (v2a[i]=="") v2a[i]=0
96 if (DEBUG) print "i == " i
97 if (DEBUG) print "v1[i] == " v1a[i]
98 if (DEBUG) print "v2[i] == " v2a[i]
99 if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) {
100 if (i==2) {
101 if (0+("." v2a[i])>0+("." v1a[i]))
102 return 1
103 else if (0+("." v1a[i])>0+("." v2a[i]))
104 return 0
105 } else {
106 if (length(v2a[i])>length(v1a[i]))
107 return 1
108 else if (v2a[i]>v1a[i])
109 return 1
110 else if (length(v1a[i])>length(v2a[i]))
111 return 0
112 else if (v1a[i]>v2a[i])
113 return 0
114 }
115 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
116 if (v2a[i]>v1a[i])
117 return 1
118 else if (v1a[i]>v2a[i])
119 return 0
e3c5f324 120 } else if (ispre(v1a[i]) == 1)
f11b5a76 121 return 1
122 else
123 return 0
124 }
125 if ((count2==mincount)&&(count!=count2)) {
126 for (i=count2+1; i<=count; i++)
e3c5f324 127 if (ispre(v1a[i]) == 1)
f11b5a76 128 return 1
129 return 0
130 } else if (count!=count2) {
131 for (i=count+1; i<=count2; i++)
e3c5f324 132 if (ispre(v2a[i]) == 1)
f11b5a76 133 return 0
134 return 1
135 }
136 return 0
137}
138
2e301ef5 139function get_links(url, errno,link,oneline,retval,odp,tmpfile) {
70a5e8d4 140# get all <A HREF=..> tags from specified URL
db4f445e
SZ
141 "mktemp /tmp/XXXXXX" | getline tmpfile
142 close("mktemp /tmp/XXXXXX")
2e301ef5
SZ
143
144 if (DEBUG) print "Retrieving: " url
2d9cc4bb 145 errno=system("wget -O - \"" url "\" -t 3 -T 300 --passive-ftp > " tmpfile " 2>/dev/null" )
70a5e8d4 146
3f63995d 147 if (errno==0) {
7f460828
SZ
148 while (getline oneline < tmpfile)
149 odp=(odp " " oneline)
150 if ( DEBUG ) print "Odpowiedz: " odp
70a5e8d4 151 }
6f57d45d 152
3f63995d 153 close(tmpfile)
2e301ef5 154 system("rm -f " tmpfile)
55658186
JB
155 urldir=url;
156 sub(/[^\/]+$/,"",urldir)
3f63995d 157 if ( errno==0) {
93c3b403
SZ
158 while ((tolower(odp) ~ /<frame[ \t]/)||(tolower(odp) ~ /href=/)) {
159 if (tolower(odp) ~ /<frame[ \t]/) {
160 match(tolower(odp),/<frame[ \t][^>]*>/)
161 ramka=substr(odp,RSTART,RLENGTH)
b5e77f8f 162 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
4dde5541 163 sub(/[sS][rR][cC]=[ \t]*/,"src=",ramka);
b5e77f8f 164 match(ramka,/src="[^"]+"/)
2e301ef5
SZ
165 newurl=substr(ramka,RSTART+5,RLENGTH-6)
166 if (DEBUG) print "Ramka: " newurl
55658186
JB
167 if (newurl !~ /\//) {
168 newurl=(urldir newurl)
169 if (DEBUG) print "Ramka->: " newurl
170 }
2e301ef5 171 retval=(retval " " get_links(newurl))
95fcfc77 172 } else if (tolower(odp) ~ /href=[ \t]*"[^"]*"/) {
b5e77f8f 173 sub(/[hH][rR][eE][fF]=[ \t]*"/,"href=\"",odp)
95fcfc77 174 match(odp,/href="[^"]*"/)
b5e77f8f
JB
175 link=substr(odp,RSTART,RLENGTH)
176 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
177 link=substr(link,7,length(link)-7)
178 retval=(retval " " link)
95fcfc77
JB
179 if (DEBUG) print "href(\"\"): " link
180 } else if (tolower(odp) ~ /href=[ \t]*'[^']*'/) {
b5e77f8f 181 sub(/[hH][rR][eE][fF]=[ \t]*'/,"href='",odp)
95fcfc77 182 match(odp,/href='[^']*'/)
93c3b403 183 link=substr(odp,RSTART,RLENGTH)
b5e77f8f 184 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
93c3b403
SZ
185 link=substr(link,7,length(link)-7)
186 retval=(retval " " link)
95fcfc77
JB
187 if (DEBUG) print "href(''): " link
188 } else if (tolower(odp) ~ /href=[ \t]*[^ \t>]*/) {
4dde5541 189 sub(/[hH][rR][eE][fF]=[ \t]*/,"href=",odp)
95fcfc77 190 match(odp,/href=[^ \t>]*/)
8dfac79d 191 link=substr(odp,RSTART,RLENGTH)
b5e77f8f 192 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
8dfac79d
SZ
193 link=substr(link,6,length(link)-5)
194 retval=(retval " " link)
95fcfc77 195 if (DEBUG) print "href(): " link
6f57d45d
JB
196 } else {
197 retval=(retval " INTERNAL_ERROR")
198 break
93c3b403 199 }
3f63995d
SZ
200 }
201 } else {
2e301ef5 202 retval=("WGET ERROR: " errno)
3f63995d
SZ
203 }
204
db4f445e 205
3f63995d 206 if (DEBUG) print "Zwracane: " retval
db4f445e 207 return retval
70a5e8d4
SZ
208}
209
6fb3305d 210function subst_defines(var,defs) {
3255b4c7 211# substitute all possible RPM macros
6fb3305d
SZ
212 while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) {
213 oldvar=var
214 for (j in defs) {
215 gsub("%{" j "}", defs[j], var)
216 gsub("%" j , defs[j], var)
217 }
218 if (var==oldvar) {
219 if ( DEBUG ) for (i in defs) print i " == " defs[i]
220 return var
221 }
222 }
223 return var
224}
225
c0bee1bc
JK
226function find_mirror(url) {
227
c54fbfc1
MK
228 while (succ = (getline line < "mirrors")) {
229 if (succ==-1) { return url }
c0bee1bc 230 nf=split(line,fields,"|")
a6f2cc98 231 if (nf>1){
c0bee1bc
JK
232 origin=fields[1]
233 mirror=fields[2]
234 mname=fields[3]
235 prefix=substr(url,1,length(origin))
236 if (prefix==origin){
237 if ( DEBUG ) print "Mirror znaleziony na " mname
238 close("mirrors")
21b99dbc 239 return mirror substr(url,length(origin)+1)
c0bee1bc
JK
240 }
241 }
242 }
243
244 return url
245}
246
32aede2f 247function process_source(number,lurl,name,version) {
3255b4c7
SZ
248# fetches file list, and compares version numbers
249 if ( DEBUG ) print "Przetwarzam " lurl
3f63995d
SZ
250
251 if ( index(lurl,version)==0 ) {
252 if (DEBUG) print "Nie ma numeru wersji."
253 return 0
254 }
255
6fb3305d
SZ
256 sub("://",":",lurl)
257 sub("/",":/",lurl)
258 gsub("[^/]*$",":&",lurl)
259 split(lurl,url,":")
260 acc=url[1]
261 host=url[2]
262 dir=url[3]
70a5e8d4
SZ
263 filename=url[4]
264
3f63995d 265 if (index(dir,version)) {
70a5e8d4
SZ
266 dir=substr(dir,1,index(dir,version)-1)
267 sub("[^/]*$","",dir)
268 sub("(\.tar\.(bz|bz2|gz)|zip)$","",filename)
269 if ( DEBUG ) print "Sprawdze katalog: " dir
270 if ( DEBUG ) print "i plik: " filename
271 }
3f63995d 272
70a5e8d4
SZ
273 filenameexp=filename
274 gsub("\+","\\+",filenameexp)
0269da83 275 sub(version,"[A-Za-z0-9.]+",filenameexp)
e12bdf15 276 gsub("\.","\\.",filenameexp)
70a5e8d4
SZ
277 if ( DEBUG ) print "Wzorzec: " filenameexp
278 match(filename,version)
279 prever=substr(filename,1,RSTART-1)
280 postver=substr(filename,RSTART+RLENGTH)
281 if ( DEBUG ) print "Przed numerkiem: " prever
282 if ( DEBUG ) print "i po: " postver
c0bee1bc 283 newurl=find_mirror(acc "://" host dir)
c54fbfc1
MK
284 #print acc "://" host dir
285 #newurl=url[1]"://"url[2]url[3]url[4]
286 #newurl=acc "://" host dir filename
c0bee1bc 287