3 # TODO: "SourceXDownload" support (use given URLs if present instead of cut-down SourceX URLs)
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))
14 if ((s~"pre")||(s~"PRE")||(s~"beta")||(s~"BETA")||(s~"alpha")||(s~"ALPHA")||(s~"rc")||(s~"RC")) {
15 if (DEBUG) print "pre-version"
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))
32 if (DEBUG) print "v1 == " v1
33 if (DEBUG) print "v2 == " v2
34 count=split(v1,v1a,"\.")
35 count2=split(v2,v2a,"\.")
37 if (count<count2) mincount=count
40 for (i=1; i<=mincount; i++) {
41 if (v1a[i]=="") v1a[i]=0
42 if (v2a[i]=="") v2a[i]=0
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]))
49 else if (v2a[i]>v1a[i])
51 else if (length(v1a[i])>length(v2a[i]))
53 else if (v1a[i]>v2a[i])
55 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
58 else if (v1a[i]>v2a[i])
60 } else if (ispre(v1a[i]) == 1)
65 if ((count2==mincount)&&(count!=count2)) {
66 for (i=count2+1; i<=count; i++)
67 if (ispre(v1a[i]) == 1)
70 } else if (count!=count2) {
71 for (i=count+1; i<=count2; i++)
72 if (ispre(v2a[i]) == 1)
79 function compare_ver_dec(v1,v2) {
80 # compares version numbers as decimal floats
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))
87 if (DEBUG) print "v1 == " v1
88 if (DEBUG) print "v2 == " v2
89 count=split(v1,v1a,"\.")
90 count2=split(v2,v2a,"\.")
92 if (count<count2) mincount=count
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]/)) {
103 if (0+("." v2a[i])>0+("." v1a[i]))
105 else if (0+("." v1a[i])>0+("." v2a[i]))
108 if (length(v2a[i])>length(v1a[i]))
110 else if (v2a[i]>v1a[i])
112 else if (length(v1a[i])>length(v2a[i]))
114 else if (v1a[i]>v2a[i])
117 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
120 else if (v1a[i]>v2a[i])
122 } else if (ispre(v1a[i]) == 1)
127 if ((count2==mincount)&&(count!=count2)) {
128 for (i=count2+1; i<=count; i++)
129 if (ispre(v1a[i]) == 1)
132 } else if (count!=count2) {
133 for (i=count+1; i<=count2; i++)
134 if (ispre(v2a[i]) == 1)
141 function get_links(url, errno,link,oneline,retval,odp,wholeodp,lowerodp,tmpfile) {
142 # get all <A HREF=..> tags from specified URL
143 "mktemp /tmp/XXXXXX" | getline tmpfile
144 close("mktemp /tmp/XXXXXX")
146 if (url ~ /^http:\/\/(download|dl).(sf|sourceforge).net\//) {
147 gsub("^http://(download|dl).(sf|sourceforge).net/", "", url)
148 url = "http://prdownloads.sourceforge.net/" substr(url, 1, 1) "/" substr(url, 1, 2) "/" url
149 if (DEBUG) print "sf url, mungled url to: " url
152 if (DEBUG) print "Retrieving: " url
153 errno=system("wget -O - \"" url "\" -t 3 -T 300 --passive-ftp > " tmpfile " 2>/dev/null" )
156 while (getline oneline < tmpfile)
157 wholeodp=(wholeodp " " oneline)
158 if ( DEBUG ) print "Response: " wholeodp
162 system("rm -f " tmpfile)
164 sub(/[^\/]+$/,"",urldir)
167 while (match(wholeodp, /<([aA]|[fF][rR][aA][mM][eE])[ \t][^>]*>/) > 0) {
168 odp=substr(wholeodp,RSTART,RLENGTH);
169 wholeodp=substr(wholeodp,RSTART+RLENGTH);
171 lowerodp=tolower(odp);
172 if (lowerodp ~ /<frame[ \t]/) {
173 sub(/[sS][rR][cC]=[ \t]*/,"src=",odp);
174 match(odp,/src="[^"]+"/)
175 newurl=substr(odp,RSTART+5,RLENGTH-6)
176 if (DEBUG) print "Frame: " newurl
177 if (newurl !~ /\//) {
178 newurl=(urldir newurl)
179 if (DEBUG) print "Frame->: " newurl
181 retval=(retval " " get_links(newurl))
182 } else if (lowerodp ~ /href=[ \t]*"[^"]*"/) {
183 sub(/[hH][rR][eE][fF]=[ \t]*"/,"href=\"",odp)
184 match(odp,/href="[^"]*"/)
185 link=substr(odp,RSTART,RLENGTH)
186 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
187 link=substr(link,7,length(link)-7)
188 retval=(retval " " link)
189 if (DEBUG) print "href(\"\"): " link
190 } else if (lowerodp ~ /href=[ \t]*'[^']*'/) {
191 sub(/[hH][rR][eE][fF]=[ \t]*'/,"href='",odp)
192 match(odp,/href='[^']*'/)
193 link=substr(odp,RSTART,RLENGTH)
194 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
195 link=substr(link,7,length(link)-7)
196 retval=(retval " " link)
197 if (DEBUG) print "href(''): " link
198 } else if (lowerodp ~ /href=[ \t]*[^ \t>]*/) {
199 sub(/[hH][rR][eE][fF]=[ \t]*/,"href=",odp)
200 match(odp,/href=[^ \t>]*/)
201 link=substr(odp,RSTART,RLENGTH)
202 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
203 link=substr(link,6,length(link)-5)
204 retval=(retval " " link)
205 if (DEBUG) print "href(): " link
207 # <a ...> but not href - skip
208 if (DEBUG) print "skipping <a > without href: " odp
212 retval=("WGET ERROR: " errno)
216 if (DEBUG) print "Returning: " retval
220 function subst_defines(var,defs) {
221 # substitute all possible RPM macros
222 while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) {
225 gsub("%{" j "}", defs[j], var)
226 gsub("%" j , defs[j], var)
229 if ( DEBUG ) for (i in defs) print i " == " defs[i]
236 function find_mirror(url) {
238 while (succ = (getline line < "mirrors")) {
239 if (succ==-1) { return url }
240 nf=split(line,fields,"|")
245 prefix=substr(url,1,length(origin))
247 if ( DEBUG ) print "Mirror fount at " mname
249 return mirror substr(url,length(origin)+1)
257 function process_source(number,lurl,name,version) {
258 # fetches file list, and compares version numbers
259 if ( DEBUG ) print "Processing " lurl
261 if ( index(lurl,version)==0 ) {
262 if (DEBUG) print "There is no version number."
268 gsub("[^/]*$",":&",lurl)
275 if (index(dir,version)) {
276 dir=substr(dir,1,index(dir,version)-1)
278 sub("(\.tar\.(bz|bz2|gz)|zip)$","",filename)
279 if ( DEBUG ) print "Will check a directory: " dir
280 if ( DEBUG ) print "and a file: " filename
284 gsub("\+","\\+",filenameexp)
285 sub(version,"[A-Za-z0-9.]+",filenameexp)
286 gsub("\.","\\.",filenameexp)
287 if ( DEBUG ) print "Expression: " filenameexp
288 match(filename,version)
289 prever=substr(filename,1,RSTART-1)
290 postver=substr(filename,RSTART+RLENGTH)
291 if ( DEBUG ) print "Before number: " prever
292 if ( DEBUG ) print "and after: " postver
293 newurl=find_mirror(acc "://" host dir)
294 #print acc "://" host dir
295 #newurl=url[1]"://"url[2]url[3]url[4]
296 #newurl=acc "://" host dir filename
297 if ( DEBUG ) print "Looking at " newurl
302 odp=get_links(newurl)
303 if( odp ~ "ERROR: ") {
304 print name "(" number ") " odp
306 if (DEBUG) print "WebPage downloaded"
308 for (nr=1; nr<=c; nr++) {
310 if (DEBUG) print "Found link: " addr
311 if ((addr ~ filenameexp) && !(addr ~ "[-_.0-9A-Za-z~]" filenameexp)) {
312 match(addr,filenameexp)
313 newfilename=substr(addr,RSTART,RLENGTH)
314 if (DEBUG) print "Hypothetical new: " newfilename
315 newfilename=fixedsub(prever,"",newfilename)
316 newfilename=fixedsub(postver,"",newfilename)
317 if (DEBUG) print "Version: " newfilename
318 if (newfilename ~ /\.(pkg|bin|binary|built)$/) continue
320 if ( compare_ver_dec(version, newfilename)==1 ) {
321 if (DEBUG) print "Yes, there is new one"
325 } else if ( compare_ver(version, newfilename)==1 ) {
326 if (DEBUG) print "Yes, there is new one"
333 print name "(" number ") seems ok: " oldversion
335 print name "(" number ") [OLD] " oldversion " [NEW] " version
339 # upgrade check for pear package using PEAR CLI
340 function pear_upgrade(name, ver) {
342 sub(/^php-pear-/, "", pname);
344 pearcmd = "pear remote-info " pname " | awk '/^Latest/{print $NF}'"
346 print "pearcmd: " pearcmd
348 pearcmd | getline nver
351 if (compare_ver(ver, nver)) {
352 print name " [OLD] " ver " [NEW] " nver
354 print name " seems ok: " ver
360 function process_data(name,ver,rel,src) {
361 if (name ~ /^php-pear-/) {
362 return pear_upgrade(name, ver);
365 # this function checks if substitutions were valid, and if true:
366 # processes each URL and tries to get current file list
368 if ( src[i] !~ /%{.*}/ && src[i] !~ /%[A-Za-z0-9_]/ ) {
369 if ( DEBUG ) print "Source: " src[i]
370 process_source(i,src[i],name,ver)
372 print FNAME ":" i ": impossible substitution: " src[i]
378 # if U want to use DEBUG, run script with "-v DEBUG=1"
379 # or uncomment the line below
382 errno=system("wget --help > /dev/null 2>&1")
384 print "No wget installed!"
387 if (ARGC>=3 && ARGV[2]=="-n") {
389 for (i=3; i<ARGC; i++) ARGV[i-1]=ARGV[i]
396 process_data(NAME,VER,REL,SRC)
397 NAME="" ; VER="" ; REL=""
398 for (i in DEFS) delete DEFS[i]
399 for (i in SRC) delete SRC[i]
404 /^[Uu][Rr][Ll]:/&&(URL=="") { URL=subst_defines($2,DEFS) ; DEFS["url"]=URL }
405 /^[Nn]ame:/&&(NAME=="") { NAME=subst_defines($2,DEFS) ; DEFS["name"]=NAME }
406 /^[Vv]ersion:/&&(VER=="") { VER=subst_defines($2,DEFS) ; DEFS["version"]=VER }
407 /^[Rr]elease:/&&(REL=="") { REL=subst_defines($2,DEFS) ; DEFS["release"]=REL }
408 /^[Ss]ource[0-9]*:/ { if (/(ftp|http):\/\//) SRC[FNR]=subst_defines($2,DEFS) }
409 /%define/ { DEFS[$2]=subst_defines($3,DEFS) }
412 process_data(NAME,VER,REL,SRC)