]>
Commit | Line | Data |
---|---|---|
6fb3305d SZ |
1 | #!/bin/awk -f |
2 | ||
70a5e8d4 SZ |
3 | function compare_ver(v1,v2) { |
4 | # compares version numbers | |
5 | while (match(v1,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/)) | |
6 | v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1)) | |
7 | while (match(v2,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/)) | |
8 | v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1)) | |
9 | sub("^0*","",v1) | |
10 | sub("^0*","",v2) | |
11 | if (DEBUG) print "v1 == " v1 | |
12 | if (DEBUG) print "v2 == " v2 | |
13 | count=split(v1,v1a,"\.") | |
14 | count2=split(v2,v2a,"\.") | |
15 | ||
16 | if (count<count2) mincount=count | |
17 | else mincount=count2 | |
18 | ||
19 | for (i=1; i<=mincount; i++) { | |
db83adc3 SZ |
20 | if (v1a[i]=="") v1a[i]=0 |
21 | if (v2a[i]=="") v2a[i]=0 | |
70a5e8d4 SZ |
22 | if (DEBUG) print "i == " i |
23 | if (DEBUG) print "v1[i] == " v1a[i] | |
24 | if (DEBUG) print "v2[i] == " v2a[i] | |
25 | if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) { | |
26 | if (length(v2a[i])>length(v1a[i])) | |
27 | return 1 | |
28 | else if (v2a[i]>v1a[i]) | |
29 | return 1 | |
30 | else if (length(v1a[i])>length(v2a[i])) | |
31 | return 0 | |
32 | else if (v1a[i]>v2a[i]) | |
33 | return 0 | |
34 | } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) { | |
35 | if (v2a[i]>v1a[i]) | |
36 | return 1 | |
37 | else if (v1a[i]>v2a[i]) | |
38 | return 0 | |
39 | } else if ((v1a[i]~"pre")||(v1a[i]~"beta")||(v1a[i]~"^b$")) | |
40 | return 1 | |
41 | else | |
42 | return 0 | |
43 | } | |
44 | if ((count2==mincount)&&(count!=count2)) { | |
45 | for (i=count2+1; i<=count; i++) | |
46 | if ((v1a[i]~"pre")||(v1a[i]~"beta")||(v1a[i]~"^b$")) | |
47 | return 1 | |
48 | return 0 | |
49 | } else if (count!=count2) { | |
50 | for (i=count+1; i<=count2; i++) | |
51 | if ((v2a[i]~"pre")||(v2a[i]~"beta")||(v2a[i]~"^b$")) | |
52 | return 0 | |
53 | return 1 | |
54 | } | |
db4f445e | 55 | return 0 |
70a5e8d4 SZ |
56 | } |
57 | ||
58 | function get_http_links(host,dir,port) { | |
59 | # get all <A HREF=..> tags from specified URL | |
db4f445e SZ |
60 | "mktemp /tmp/XXXXXX" | getline tmpfile |
61 | close("mktemp /tmp/XXXXXX") | |
70a5e8d4 | 62 | |
db4f445e SZ |
63 | print ("GET " dir) | ( "nc " host " " port " > " tmpfile ) |
64 | close("nc " host " " port " > " tmpfile) | |
70a5e8d4 | 65 | |
db4f445e SZ |
66 | while (getline reply < tmpfile ) { |
67 | odp=(odp " " reply) | |
70a5e8d4 | 68 | } |
db4f445e SZ |
69 | |
70 | system("rm -f " tmpfile) | |
70a5e8d4 SZ |
71 | |
72 | if ( DEBUG ) print "Odpowiedz: " odp | |
73 | while (tolower(odp) ~ /href=/) { | |
74 | match(tolower(odp),/href="[^"]+"/) | |
75 | link=substr(odp,RSTART,RLENGTH) | |
76 | odp=substr(odp,RSTART+RLENGTH) | |
77 | link=substr(link,7,length(link)-7) | |
db4f445e | 78 | retval=(retval " " link) |
70a5e8d4 | 79 | } |
db4f445e SZ |
80 | return retval |
81 | } | |
82 | ||
83 | function get_ftp_links(host,dir,port) { | |
84 | "mktemp /tmp/XXXXXX" | getline tmpfile | |
85 | close("mktemp /tmp/XXXXXX") | |
86 | ||
dedcb058 | 87 | system("export PLIKTMP=\"" tmpfile "\" FTP_DIR=\"" dir "\" FTP_PASS=\"sebek@sith\" FTP_USERNAME=\"anonymous\" FTP_HOST=\"" host "\" ; nc -e \"ftplinks.sh\" " host " " port) |
db4f445e SZ |
88 | |
89 | while (getline link < tmpfile) | |
90 | retval=(retval " " link) | |
91 | ||
92 | close(tmpfile) | |
93 | system("rm -f " tmpfile) | |
94 | ||
95 | if (DEBUG) print "Odpowiedz: " retval | |
96 | ||
97 | return retval | |
70a5e8d4 SZ |
98 | } |
99 | ||
6fb3305d | 100 | function subst_defines(var,defs) { |
3255b4c7 | 101 | # substitute all possible RPM macros |
6fb3305d SZ |
102 | while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) { |
103 | oldvar=var | |
104 | for (j in defs) { | |
105 | gsub("%{" j "}", defs[j], var) | |
106 | gsub("%" j , defs[j], var) | |
107 | } | |
108 | if (var==oldvar) { | |
109 | if ( DEBUG ) for (i in defs) print i " == " defs[i] | |
110 | return var | |
111 | } | |
112 | } | |
113 | return var | |
114 | } | |
115 | ||
70a5e8d4 | 116 | function process_source(lurl,name,version) { |
3255b4c7 SZ |
117 | # fetches file list, and compares version numbers |
118 | if ( DEBUG ) print "Przetwarzam " lurl | |
6fb3305d SZ |
119 | sub("://",":",lurl) |
120 | sub("/",":/",lurl) | |
121 | gsub("[^/]*$",":&",lurl) | |
122 | split(lurl,url,":") | |
123 | acc=url[1] | |
124 | host=url[2] | |
125 | dir=url[3] | |
70a5e8d4 SZ |
126 | filename=url[4] |
127 | ||
128 | if ( index(dir,version) ) { | |
129 | dir=substr(dir,1,index(dir,version)-1) | |
130 | sub("[^/]*$","",dir) | |
131 | sub("(\.tar\.(bz|bz2|gz)|zip)$","",filename) | |
132 | if ( DEBUG ) print "Sprawdze katalog: " dir | |
133 | if ( DEBUG ) print "i plik: " filename | |
134 | } | |
135 | ||
136 | filenameexp=filename | |
137 | gsub("\+","\\+",filenameexp) | |
138 | sub(version,"[A-Za-z0-9\\.]+",filenameexp) | |
139 | if ( DEBUG ) print "Wzorzec: " filenameexp | |
140 | match(filename,version) | |
141 | prever=substr(filename,1,RSTART-1) | |
142 | postver=substr(filename,RSTART+RLENGTH) | |
143 | if ( DEBUG ) print "Przed numerkiem: " prever | |
144 | if ( DEBUG ) print "i po: " postver | |
145 | ||
3255b4c7 | 146 | if ( DEBUG ) print "LYNX " acc "://" host dir |
6fb3305d SZ |
147 | |
148 | references=0 | |
db83adc3 | 149 | finished=0 |
db4f445e SZ |
150 | oldversion=version |
151 | if (acc=="http") | |
152 | odp=get_http_links(host,dir,80) | |
153 | else { | |
154 | odp=get_ftp_links(host,dir,21) | |
155 | } | |
156 | c=split(odp,linki) | |
157 | for (nr=1; nr<=c; nr++) { | |
158 | addr=linki[nr] | |
159 | if (DEBUG) print "Znaleziony link: " addr | |
160 | if (addr ~ filenameexp) { | |
161 | match(addr,filenameexp) | |
162 | newfilename=substr(addr,RSTART,RLENGTH) | |
163 | if (DEBUG) print "Hipotetyczny nowy: " newfilename | |
164 | sub(prever,"",newfilename) | |
165 | sub(postver,"",newfilename) | |
166 | if (DEBUG) print "Wersja: " newfilename | |
167 | if ( compare_ver(version, newfilename)==1 ) { | |
168 | if (DEBUG) print "Tak, jest nowa" | |
169 | version=newfilename | |
170 | finished=1 | |
70a5e8d4 | 171 | } |
6fb3305d SZ |
172 | } |
173 | } | |
db4f445e SZ |
174 | if (finished==0) |
175 | print name " : seems ok" | |
176 | else | |
177 | print name " : [OLD] " oldversion " [NEW] " version | |
178 | ||
6fb3305d SZ |
179 | } |
180 | ||
3255b4c7 SZ |
181 | function process_data(name,ver,rel,src) { |
182 | # this function checks if substitutions were valid, and if true: | |
183 | # processes each URL and tries to get current file list | |
6fb3305d SZ |
184 | for (i in src) { |
185 | if ( src[i] !~ /%{.*}/ && src[i] !~ /%[A-Za-z0-9_]/ ) { | |
186 | if ( DEBUG ) print "Zrodlo: " src[i] | |
70a5e8d4 | 187 | process_source(src[i],name,ver) |
6fb3305d SZ |
188 | } else { |
189 | print FNAME ":" i ": niemozliwe podstawienie: " src[i] | |
190 | } | |
191 | } | |
192 | } | |
193 | ||
194 | BEGIN { | |
195 | # if U want to use DEBUG, run script with "-v DEBUG=1" | |
196 | # or uncomment the line below | |
70a5e8d4 | 197 | # DEBUG = 1 |
6fb3305d SZ |
198 | } |
199 | ||
200 | FNR==1 { | |
201 | if ( ARGIND != 1 ) { | |
3255b4c7 | 202 | process_data(NAME,VER,REL,SRC) |
6fb3305d SZ |
203 | NAME="" ; VER="" ; REL="" |
204 | for (i in DEFS) delete DEFS[i] | |
205 | for (i in SRC) delete SRC[i] | |
206 | } | |
207 | FNAME=FILENAME | |
208 | } | |
209 | ||
3255b4c7 | 210 | /^[Uu][Rr][Ll]:/&&(URL=="") { URL=subst_defines($2,DEFS) ; DEFS["url"]=URL } |
6fb3305d SZ |
211 | /^[Nn]ame:/&&(NAME=="") { NAME=subst_defines($2,DEFS) ; DEFS["name"]=NAME } |
212 | /^[Vv]ersion:/&&(VER=="") { VER=subst_defines($2,DEFS) ; DEFS["version"]=VER } | |
213 | /^[Rr]elease:/&&(REL=="") { REL=subst_defines($2,DEFS) ; DEFS["release"]=REL } | |
214 | /^[Ss]ource[0-9]*:/ { if (/(ftp|http):\/\//) SRC[FNR]=subst_defines($2,DEFS) } | |
215 | /%define/ { DEFS[$2]=subst_defines($3,DEFS) } | |
216 | ||
217 | END { | |
3255b4c7 | 218 | process_data(NAME,VER,REL,SRC) |
6fb3305d | 219 | } |