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