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))
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))
19 if (DEBUG) print "v1 == " v1
20 if (DEBUG) print "v2 == " v2
21 count=split(v1,v1a,"\.")
22 count2=split(v2,v2a,"\.")
24 if (count<count2) mincount=count
27 for (i=1; i<=mincount; i++) {
28 if (v1a[i]=="") v1a[i]=0
29 if (v2a[i]=="") v2a[i]=0
30 if (DEBUG) print "i == " i
31 if (DEBUG) print "v1[i] == " v1a[i]
32 if (DEBUG) print "v2[i] == " v2a[i]
33 if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) {
34 if (length(v2a[i])>length(v1a[i]))
36 else if (v2a[i]>v1a[i])
38 else if (length(v1a[i])>length(v2a[i]))
40 else if (v1a[i]>v2a[i])
42 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
45 else if (v1a[i]>v2a[i])
47 } else if ((v1a[i]~"pre")||(v1a[i]~"beta")||(v1a[i]~"alpha"))
52 if ((count2==mincount)&&(count!=count2)) {
53 for (i=count2+1; i<=count; i++)
54 if ((v1a[i]~"pre")||(v1a[i]~"beta")||(v1a[i]~"alpha"))
57 } else if (count!=count2) {
58 for (i=count+1; i<=count2; i++)
59 if ((v2a[i]~"pre")||(v2a[i]~"beta")||(v2a[i]~"alpha"))
66 function get_links(url, errno,link,oneline,retval,odp,tmpfile) {
67 # get all <A HREF=..> tags from specified URL
68 "mktemp /tmp/XXXXXX" | getline tmpfile
69 close("mktemp /tmp/XXXXXX")
71 if (DEBUG) print "Retrieving: " url
72 errno=system("wget --inet -O - \"" url "\" -t 1 -T 300 > " tmpfile " 2>/dev/null" )
75 while (getline oneline < tmpfile)
77 if ( DEBUG ) print "Odpowiedz: " odp
81 system("rm -f " tmpfile)
83 while ((tolower(odp) ~ /<frame[ \t]/)||(tolower(odp) ~ /href=/)) {
84 if (tolower(odp) ~ /<frame[ \t]/) {
85 match(tolower(odp),/<frame[ \t][^>]*>/)
86 ramka=substr(odp,RSTART,RLENGTH)
87 odp=substr(odp,RSTART+RLENGTH)
88 match(tolower(ramka),/src="[^"]+"/)
89 newurl=substr(ramka,RSTART+5,RLENGTH-6)
90 if (DEBUG) print "Ramka: " newurl
91 retval=(retval " " get_links(newurl))
92 } else if (tolower(odp) ~ /href="[^"]+"/) {
93 match(tolower(odp),/href="[^"]+"/)
94 link=substr(odp,RSTART,RLENGTH)
95 odp=substr(odp,RSTART+RLENGTH)
96 link=substr(link,7,length(link)-7)
97 retval=(retval " " link)
99 match(tolower(odp),/href=[^ \t>]+/)
100 link=substr(odp,RSTART,RLENGTH)
101 odp=substr(odp,RSTART+RLENGTH)
102 link=substr(link,6,length(link)-5)
103 retval=(retval " " link)
107 retval=("WGET ERROR: " errno)
111 if (DEBUG) print "Zwracane: " retval
115 function subst_defines(var,defs) {
116 # substitute all possible RPM macros
117 while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) {
120 gsub("%{" j "}", defs[j], var)
121 gsub("%" j , defs[j], var)
124 if ( DEBUG ) for (i in defs) print i " == " defs[i]
131 function process_source(number,lurl,name,version) {
132 # fetches file list, and compares version numbers
133 if ( DEBUG ) print "Przetwarzam " lurl
135 if ( index(lurl,version)==0 ) {
136 if (DEBUG) print "Nie ma numeru wersji."
142 gsub("[^/]*$",":&",lurl)
149 if (index(dir,version)) {
150 dir=substr(dir,1,index(dir,version)-1)
152 sub("(\.tar\.(bz|bz2|gz)|zip)$","",filename)
153 if ( DEBUG ) print "Sprawdze katalog: " dir
154 if ( DEBUG ) print "i plik: " filename
158 gsub("\+","\\+",filenameexp)
159 sub(version,"[A-Za-z0-9\\.]+",filenameexp)
160 if ( DEBUG ) print "Wzorzec: " filenameexp
161 match(filename,version)
162 prever=substr(filename,1,RSTART-1)
163 postver=substr(filename,RSTART+RLENGTH)
164 if ( DEBUG ) print "Przed numerkiem: " prever
165 if ( DEBUG ) print "i po: " postver
167 if ( DEBUG ) print "ZaglĀ±dam na " acc "://" host dir
172 odp=get_links(acc "://" host dir)
173 if( odp ~ "ERROR: ") {
174 print name "(" number ") " odp
176 if (DEBUG) print "Sciagnieta strona"
178 for (nr=1; nr<=c; nr++) {
180 if (DEBUG) print "Znaleziony link: " addr
181 if (addr ~ filenameexp) {
182 match(addr,filenameexp)
183 newfilename=substr(addr,RSTART,RLENGTH)
184 if (DEBUG) print "Hipotetyczny nowy: " newfilename
185 newfilename=fixedsub(prever,"",newfilename)
186 newfilename=fixedsub(postver,"",newfilename)
187 if (DEBUG) print "Wersja: " newfilename
188 if ( compare_ver(version, newfilename)==1 ) {
189 if (DEBUG) print "Tak, jest nowa"
196 print name "(" number ") seems ok: " oldversion
198 print name "(" number ") [OLD] " oldversion " [NEW] " version
202 function process_data(name,ver,rel,src) {
203 # this function checks if substitutions were valid, and if true:
204 # processes each URL and tries to get current file list
206 if ( src[i] !~ /%{.*}/ && src[i] !~ /%[A-Za-z0-9_]/ ) {
207 if ( DEBUG ) print "Zrodlo: " src[i]
208 process_source(i,src[i],name,ver)
210 print FNAME ":" i ": niemozliwe podstawienie: " src[i]
216 # if U want to use DEBUG, run script with "-v DEBUG=1"
217 # or uncomment the line below
220 errno=system("wget --help > /dev/null 2>&1")
222 print "No wget installed!"
229 process_data(NAME,VER,REL,SRC)
230 NAME="" ; VER="" ; REL=""
231 for (i in DEFS) delete DEFS[i]
232 for (i in SRC) delete SRC[i]
237 /^[Uu][Rr][Ll]:/&&(URL=="") { URL=subst_defines($2,DEFS) ; DEFS["url"]=URL }
238 /^[Nn]ame:/&&(NAME=="") { NAME=subst_defines($2,DEFS) ; DEFS["name"]=NAME }
239 /^[Vv]ersion:/&&(VER=="") { VER=subst_defines($2,DEFS) ; DEFS["version"]=VER }
240 /^[Rr]elease:/&&(REL=="") { REL=subst_defines($2,DEFS) ; DEFS["release"]=REL }
241 /^[Ss]ource[0-9]*:/ { if (/(ftp|http):\/\//) SRC[FNR]=subst_defines($2,DEFS) }
242 /%define/ { DEFS[$2]=subst_defines($3,DEFS) }
245 process_data(NAME,VER,REL,SRC)