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