]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/awk -f | |
2 | # $Revision$, $Date$ | |
3 | ||
4 | function compare_ver(v1,v2) { | |
5 | # compares version numbers | |
6 | while (match(v1,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/)) | |
7 | v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1)) | |
8 | while (match(v2,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/)) | |
9 | v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1)) | |
10 | sub("^0*","",v1) | |
11 | sub("^0*","",v2) | |
12 | if (DEBUG) print "v1 == " v1 | |
13 | if (DEBUG) print "v2 == " v2 | |
14 | count=split(v1,v1a,"\.") | |
15 | count2=split(v2,v2a,"\.") | |
16 | ||
17 | if (count<count2) mincount=count | |
18 | else mincount=count2 | |
19 | ||
20 | for (i=1; i<=mincount; i++) { | |
21 | if (v1a[i]=="") v1a[i]=0 | |
22 | if (v2a[i]=="") v2a[i]=0 | |
23 | if (DEBUG) print "i == " i | |
24 | if (DEBUG) print "v1[i] == " v1a[i] | |
25 | if (DEBUG) print "v2[i] == " v2a[i] | |
26 | if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) { | |
27 | if (length(v2a[i])>length(v1a[i])) | |
28 | return 1 | |
29 | else if (v2a[i]>v1a[i]) | |
30 | return 1 | |
31 | else if (length(v1a[i])>length(v2a[i])) | |
32 | return 0 | |
33 | else if (v1a[i]>v2a[i]) | |
34 | return 0 | |
35 | } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) { | |
36 | if (v2a[i]>v1a[i]) | |
37 | return 1 | |
38 | else if (v1a[i]>v2a[i]) | |
39 | return 0 | |
40 | } else if ((v1a[i]~"pre")||(v1a[i]~"beta")||(v1a[i]~"^b$")) | |
41 | return 1 | |
42 | else | |
43 | return 0 | |
44 | } | |
45 | if ((count2==mincount)&&(count!=count2)) { | |
46 | for (i=count2+1; i<=count; i++) | |
47 | if ((v1a[i]~"pre")||(v1a[i]~"beta")||(v1a[i]~"^b$")) | |
48 | return 1 | |
49 | return 0 | |
50 | } else if (count!=count2) { | |
51 | for (i=count+1; i<=count2; i++) | |
52 | if ((v2a[i]~"pre")||(v2a[i]~"beta")||(v2a[i]~"^b$")) | |
53 | return 0 | |
54 | return 1 | |
55 | } | |
56 | return 0 | |
57 | } | |
58 | ||
59 | function get_http_links(host,dir,port, errno,link,oneline,retval,odp,tmpfile) { | |
60 | # get all <A HREF=..> tags from specified URL | |
61 | "mktemp /tmp/XXXXXX" | getline tmpfile | |
62 | close("mktemp /tmp/XXXXXX") | |
63 | errno=system("echo -e \"GET " dir " HTTP/1.0\\n\" | nc " host " " port " | tr -d '\\r' > " tmpfile ) | |
64 | ||
65 | if (errno==0) { | |
66 | getline oneline < tmpfile | |
67 | if ( oneline ~ "200" ) { | |
68 | while (getline oneline < tmpfile) | |
69 | odp=(odp " " oneline) | |
70 | if ( DEBUG ) print "Odpowiedz: " odp | |
71 | } else { | |
72 | match(oneline,"[0-9][0-9][0-9]") | |
73 | errno=substr(oneline,RSTART,RLENGTH) | |
74 | } | |
75 | } | |
76 | ||
77 | close(tmpfile) | |
78 | ||
79 | if ( errno==0) { | |
80 | while (tolower(odp) ~ /href=/) { | |
81 | match(tolower(odp),/href="[^"]+"/) | |
82 | link=substr(odp,RSTART,RLENGTH) | |
83 | odp=substr(odp,RSTART+RLENGTH) | |
84 | link=substr(link,7,length(link)-7) | |
85 | retval=(retval " " link) | |
86 | } | |
87 | } else { | |
88 | retval=("HTTP ERROR: " errno) | |
89 | } | |
90 | ||
91 | system("rm -f " tmpfile) | |
92 | ||
93 | if (DEBUG) print "Zwracane: " retval | |
94 | return retval | |
95 | } | |
96 | ||
97 | function get_ftp_links(host,dir,port, tmpfile,link,retval) { | |
98 | "mktemp /tmp/XXXXXX" | getline tmpfile | |
99 | close("mktemp /tmp/XXXXXX") | |
100 | ||
101 | errno=system("export PLIKTMP=\"" tmpfile "\" FTP_DIR=\"" dir "\" FTP_PASS=\"sebek@sith\" FTP_USERNAME=\"anonymous\" FTP_HOST=\"" host "\" DEBUG=\"" DEBUG "\" ; nc -e \"./ftplinks.sh\" " host " " port) | |
102 | ||
103 | if (errno==0) { | |
104 | while (getline link < tmpfile) | |
105 | retval=(retval " " link) | |
106 | close(tmpfile) | |
107 | } else { | |
108 | retval=("FTP ERROR: " errno) | |
109 | } | |
110 | ||
111 | system("rm -f " tmpfile) | |
112 | ||
113 | if (DEBUG) print "Zwracane: " retval | |
114 | return retval | |
115 | } | |
116 | ||
117 | function subst_defines(var,defs) { | |
118 | # substitute all possible RPM macros | |
119 | while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) { | |
120 | oldvar=var | |
121 | for (j in defs) { | |
122 | gsub("%{" j "}", defs[j], var) | |
123 | gsub("%" j , defs[j], var) | |
124 | } | |
125 | if (var==oldvar) { | |
126 | if ( DEBUG ) for (i in defs) print i " == " defs[i] | |
127 | return var | |
128 | } | |
129 | } | |
130 | return var | |
131 | } | |
132 | ||
133 | function process_source(number,lurl,name,version) { | |
134 | # fetches file list, and compares version numbers | |
135 | if ( DEBUG ) print "Przetwarzam " lurl | |
136 | ||
137 | if ( index(lurl,version)==0 ) { | |
138 | if (DEBUG) print "Nie ma numeru wersji." | |
139 | return 0 | |
140 | } | |
141 | ||
142 | sub("://",":",lurl) | |
143 | sub("/",":/",lurl) | |
144 | gsub("[^/]*$",":&",lurl) | |
145 | split(lurl,url,":") | |
146 | acc=url[1] | |
147 | host=url[2] | |
148 | dir=url[3] | |
149 | filename=url[4] | |
150 | ||
151 | if (index(dir,version)) { | |
152 | dir=substr(dir,1,index(dir,version)-1) | |
153 | sub("[^/]*$","",dir) | |
154 | sub("(\.tar\.(bz|bz2|gz)|zip)$","",filename) | |
155 | if ( DEBUG ) print "Sprawdze katalog: " dir | |
156 | if ( DEBUG ) print "i plik: " filename | |
157 | } | |
158 | ||
159 | filenameexp=filename | |
160 | gsub("\+","\\+",filenameexp) | |
161 | sub(version,"[A-Za-z0-9\\.]+",filenameexp) | |
162 | if ( DEBUG ) print "Wzorzec: " filenameexp | |
163 | match(filename,version) | |
164 | prever=substr(filename,1,RSTART-1) | |
165 | postver=substr(filename,RSTART+RLENGTH) | |
166 | if ( DEBUG ) print "Przed numerkiem: " prever | |
167 | if ( DEBUG ) print "i po: " postver | |
168 | ||
169 |