]>
Commit | Line | Data |
---|---|---|
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 |
5 | function 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 |
13 | function 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 | } | |
21 | ||
70a5e8d4 SZ |
22 | function 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,"\.") | |
36 | ||
37 | if (count<count2) mincount=count | |
38 | else mincount=count2 | |
39 | ||
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 | 79 | function 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,"\.") | |
91 | ||
92 | if (count<count2) mincount=count | |
93 | else mincount=count2 | |
94 | ||
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 | ||
2e301ef5 | 141 | function get_links(url, errno,link,oneline,retval,odp,tmpfile) { |
70a5e8d4 | 142 | # get all <A HREF=..> tags from specified URL |
db4f445e SZ |
143 | "mktemp /tmp/XXXXXX" | getline tmpfile |
144 | close("mktemp /tmp/XXXXXX") | |
2e301ef5 SZ |
145 | |
146 | if (DEBUG) print "Retrieving: " url | |
2d9cc4bb | 147 | errno=system("wget -O - \"" url "\" -t 3 -T 300 --passive-ftp > " tmpfile " 2>/dev/null" ) |
70a5e8d4 | 148 | |
3f63995d | 149 | if (errno==0) { |
7f460828 SZ |
150 | while (getline oneline < tmpfile) |
151 | odp=(odp " " oneline) | |
157aa7fc | 152 | if ( DEBUG ) print "Response: " odp |
70a5e8d4 | 153 | } |
6f57d45d | 154 | |
3f63995d | 155 | close(tmpfile) |
2e301ef5 | 156 | system("rm -f " tmpfile) |
55658186 JB |
157 | urldir=url; |
158 | sub(/[^\/]+$/,"",urldir) | |
3f63995d | 159 | if ( errno==0) { |
93c3b403 SZ |
160 | while ((tolower(odp) ~ /<frame[ \t]/)||(tolower(odp) ~ /href=/)) { |
161 | if (tolower(odp) ~ /<frame[ \t]/) { | |
162 | match(tolower(odp),/<frame[ \t][^>]*>/) | |
163 | ramka=substr(odp,RSTART,RLENGTH) | |
b5e77f8f | 164 | odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH) |
4dde5541 | 165 | sub(/[sS][rR][cC]=[ \t]*/,"src=",ramka); |
b5e77f8f | 166 | match(ramka,/src="[^"]+"/) |
2e301ef5 | 167 | newurl=substr(ramka,RSTART+5,RLENGTH-6) |
157aa7fc | 168 | if (DEBUG) print "Frame: " newurl |
55658186 JB |
169 | if (newurl !~ /\//) { |
170 | newurl=(urldir newurl) | |
157aa7fc | 171 | if (DEBUG) print "Frame->: " newurl |
55658186 | 172 | } |
2e301ef5 | 173 | retval=(retval " " get_links(newurl)) |
95fcfc77 | 174 | } else if (tolower(odp) ~ /href=[ \t]*"[^"]*"/) { |
b5e77f8f | 175 | sub(/[hH][rR][eE][fF]=[ \t]*"/,"href=\"",odp) |
95fcfc77 | 176 | match(odp,/href="[^"]*"/) |
b5e77f8f JB |
177 | link=substr(odp,RSTART,RLENGTH) |
178 | odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH) | |
179 | link=substr(link,7,length(link)-7) | |
180 | retval=(retval " " link) | |
95fcfc77 JB |
181 | if (DEBUG) print "href(\"\"): " link |
182 | } else if (tolower(odp) ~ /href=[ \t]*'[^']*'/) { | |
b5e77f8f | 183 | sub(/[hH][rR][eE][fF]=[ \t]*'/,"href='",odp) |
95fcfc77 | 184 | match(odp,/href='[^']*'/) |
93c3b403 | 185 | link=substr(odp,RSTART,RLENGTH) |
b5e77f8f | 186 | odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH) |
93c3b403 SZ |
187 | link=substr(link,7,length(link)-7) |
188 | retval=(retval " " link) | |
95fcfc77 JB |
189 | if (DEBUG) print "href(''): " link |
190 | } else if (tolower(odp) ~ /href=[ \t]*[^ \t>]*/) { | |
4dde5541 | 191 | sub(/[hH][rR][eE][fF]=[ \t]*/,"href=",odp) |
95fcfc77 | 192 | match(odp,/href=[^ \t>]*/) |
8dfac79d | 193 | link=substr(odp,RSTART,RLENGTH) |
b5e77f8f | 194 | odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH) |
8dfac79d SZ |
195 | link=substr(link,6,length(link)-5) |
196 | retval=(retval " " link) | |
95fcfc77 | 197 | if (DEBUG) print "href(): " link |
6f57d45d JB |
198 | } else { |
199 | retval=(retval " INTERNAL_ERROR") | |
200 | break | |
93c3b403 | 201 | } |
3f63995d SZ |
202 | } |
203 | } else { | |
2e301ef5 | 204 | retval=("WGET ERROR: " errno) |
3f63995d SZ |
205 | } |
206 | ||
db4f445e | 207 | |
157aa7fc | 208 | if (DEBUG) print "Returning: " retval |
db4f445e | 209 | return retval |
70a5e8d4 SZ |
210 | } |
211 | ||
6fb3305d | 212 | function subst_defines(var,defs) { |
3255b4c7 | 213 | # substitute all possible RPM macros |
6fb3305d SZ |
214 | while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) { |
215 | oldvar=var | |
216 | for (j in defs) { | |
217 | gsub("%{" j "}", defs[j], var) | |
218 | gsub("%" j , defs[j], var) | |
219 | } | |
220 | if (var==oldvar) { | |
221 | if ( DEBUG ) for (i in defs) print i " == " defs[i] | |
222 | return var | |
223 | } | |
224 | } | |
225 | return var | |
226 | } | |
227 | ||
c0bee1bc JK |
228 | function find_mirror(url) { |
229 | ||
c54fbfc1 MK |
230 | while (succ = (getline line < "mirrors")) { |
231 | if (succ==-1) { return url } | |
c0bee1bc | 232 | nf=split(line,fields,"|") |
a6f2cc98 | 233 | if (nf>1){ |
c0bee1bc JK |
234 | origin=fields[1] |
235 | mirror=fields[2] | |
236 | mname=fields[3] | |
237 | prefix=substr(url,1,length(origin)) | |
238 | if (prefix==origin){ | |
157aa7fc | 239 | if ( DEBUG ) print "Mirror fount at " mname |
c0bee1bc | 240 | close("mirrors") |
21b99dbc | 241 | return mirror substr(url,length(origin)+1) |
c0bee1bc JK |
242 | } |
243 | } | |
244 | } | |
245 | ||
246 | return url | |
247 | } | |
248 | ||
32aede2f | 249 | function process_source(number,lurl,name,version) { |
3255b4c7 | 250 | # fetches file list, and compares version numbers |
157aa7fc | 251 | if ( DEBUG ) print "Processing " lurl |
3f63995d SZ |
252 | |
253 | if ( index(lurl,version)==0 ) { | |
157aa7fc | 254 | if (DEBUG) print "There is no version number." |
3f63995d SZ |
255 | return 0 |
256 | } | |
257 | ||
6fb3305d SZ |
258 | sub("://",":",lurl) |
259 | sub("/",":/",lurl) | |
260 | gsub("[^/]*$",":&",lurl) | |
261 | split(lurl,url,":") | |
262 | acc=url[1] | |
263 | host=url[2] | |
264 | dir=url[3] | |
70a5e8d4 SZ |
265 | filename=url[4] |
266 | ||
3f63995d | 267 | if (index(dir,version)) { |
70a5e8d4 SZ |
268 | dir=substr(dir,1,index(dir,version)-1) |
269 | sub("[^/]*$","",dir) | |
270 | sub("(\.tar\.(bz|bz2|gz)|zip)$","",filename) | |
157aa7fc AM |
271 | if ( DEBUG ) print "Will check a directory: " dir |
272 | if ( DEBUG ) print "and a file: " filename | |
70a5e8d4 | 273 | } |
3f63995d | 274 | |
70a5e8d4 SZ |
275 | filenameexp=filename |
276 | gsub("\+","\\+",filenameexp) | |
0269da83 | 277 | sub(version,"[A-Za-z0-9.]+",filenameexp) |
e12bdf15 | 278 | gsub("\.","\\.",filenameexp) |
157aa7fc | 279 | if ( DEBUG ) print "Expression: " filenameexp |
70a5e8d4 SZ |
280 | match(filename,version) |
281 | prever=substr(filename,1,RSTART-1) | |
282 | postver=substr(filename,RSTART+RLENGTH) | |
157aa7fc AM |
283 | if ( DEBUG ) print "Before number: " prever |
284 | if ( DEBUG ) print "and after: " postver | |
c0bee1bc | 285 | newurl=find_mirror(acc "://" host dir) |
c54fbfc1 MK |
286 | #print acc "://" host dir |
287 | #newurl=url[1]"://"url[2]url[3]url[4] | |
288 | #newurl=acc "://" host dir filename | |
157aa7fc | 289 | if ( DEBUG ) print "Looking at " newurl |
6fb3305d SZ |
290 | |
291 | references=0 | |
db83adc3 | 292 | finished=0 |
db4f445e | 293 | oldversion=version |
c0bee1bc | 294 | odp=get_links(newurl) |
3f63995d SZ |
295 | if( odp ~ "ERROR: ") { |
296 | print name "(" number ") " odp | |
188dc51f | 297 | } else { |
157aa7fc | 298 | if (DEBUG) print "WebPage downloaded" |
188dc51f SZ |
299 | c=split(odp,linki) |
300 | for (nr=1; nr<=c; nr++) { | |
301 | addr=linki[nr] | |
157aa7fc | 302 | if (DEBUG) print "Found link: " addr |
3c68e899 | 303 | if ((addr ~ filenameexp) && !(addr ~ "[-_.0-9A-Za-z~]" filenameexp)) { |
188dc51f SZ |
304 | match(addr,filenameexp) |
305 | newfilename=substr(addr,RSTART,RLENGTH) | |
157aa7fc | 306 | if (DEBUG) print "Hipotetical new: " newfilename |
2aba2068 SZ |
307 | newfilename=fixedsub(prever,"",newfilename) |
308 | newfilename=fixedsub(postver,"",newfilename) | |
157aa7fc | 309 | if (DEBUG) print "Version: " newfilename |
155ac0a8 | 310 | if (newfilename ~ /\.(pkg|bin|binary|built)$/) continue |
f11b5a76 | 311 | if (NUMERIC) { |
312 | if ( compare_ver_dec(version, newfilename)==1 ) { | |
157aa7fc | 313 | if (DEBUG) print "Yes, there is new one" |
f11b5a76 | 314 | version=newfilename |
315 | finished=1 | |
316 | } | |
317 | } else if ( compare_ver(version, newfilename)==1 ) { | |
157aa7fc | 318 | if (DEBUG) print "Yes, there is new one" |
188dc51f SZ |
319 | version=newfilename |
320 | finished=1 | |
321 | } | |
70a5e8d4 | 322 | } |
6fb3305d | 323 | } |
188dc51f | 324 | if (finished==0) |
f1b8a975 | 325 | print name "(" number ") seems ok: " oldversion |
188dc51f SZ |
326 | else |
327 | print name "(" number ") [OLD] " oldversion " [NEW] " version | |
6fb3305d SZ |
328 | } |
329 | } | |
330 | ||
3255b4c7 SZ |
331 | function process_data(name,ver,rel,src) { |
332 | # this function checks if substitutions were valid, and if true: | |
333 | # processes each URL and tries to get current file list | |
6fb3305d SZ |
334 | for (i in src) { |
335 | if ( src[i] !~ /%{.*}/ && src[i] !~ /%[A-Za-z0-9_]/ ) { | |
157aa7fc | 336 | if ( DEBUG ) print "Source: " src[i] |
32aede2f | 337 | process_source(i,src[i],name,ver) |
6fb3305d SZ |
338 | } else { |
339 | print FNAME ":" i ": niemozliwe podstawienie: " src[i] | |
340 | } | |
341 | } | |
342 | } | |
343 | ||
344 | BEGIN { | |
345 | # if U want to use DEBUG, run script with "-v DEBUG=1" | |
346 | # or uncomment the line below | |
70a5e8d4 | 347 | # DEBUG = 1 |
2e301ef5 SZ |
348 | |
349 | errno=system("wget --help > /dev/null 2>&1") | |
350 | if (errno) { | |
351 | print "No wget installed!" | |
352 | exit 1 | |
353 | } | |
f11b5a76 | 354 | if (ARGC>=3 && ARGV[2]=="-n") { |
355 | NUMERIC=1 | |
356 | for (i=3; i<ARGC; i++) ARGV[i-1]=ARGV[i] | |
357 | ARGC=ARGC-1 | |
358 | } | |
6fb3305d SZ |
359 | } |
360 | ||
361 | FNR==1 { | |
362 | if ( ARGIND != 1 ) { | |
3255b4c7 | 363 | process_data(NAME,VER,REL,SRC) |
6fb3305d SZ |
364 | NAME="" ; VER="" ; REL="" |
365 | for (i in DEFS) delete DEFS[i] | |
366 | for (i in SRC) delete SRC[i] | |
367 | } | |
368 | FNAME=FILENAME | |
369 | } | |
370 | ||
3255b4c7 | 371 | /^[Uu][Rr][Ll]:/&&(URL=="") { URL=subst_defines($2,DEFS) ; DEFS["url"]=URL } |
6fb3305d SZ |
372 | /^[Nn]ame:/&&(NAME=="") { NAME=subst_defines($2,DEFS) ; DEFS["name"]=NAME } |
373 | /^[Vv]ersion:/&&(VER=="") { VER=subst_defines($2,DEFS) ; DEFS["version"]=VER } | |
374 | /^[Rr]elease:/&&(REL=="") { REL=subst_defines($2,DEFS) ; DEFS["release"]=REL } | |
375 | /^[Ss]ource[0-9]*:/ { if (/(ftp|http):\/\//) SRC[FNR]=subst_defines($2,DEFS) } | |
376 | /%define/ { DEFS[$2]=subst_defines($3,DEFS) } | |
377 | ||
378 | END { | |
3255b4c7 | 379 | process_data(NAME,VER,REL,SRC) |
6fb3305d | 380 | } |