4 # Copyright (C) 2000-2008 PLD-Team <feedback@pld-linux.org>
6 # Sebastian Zagrodzki <zagrodzki@pld-linux.org>
7 # Jacek Konieczny <jajcus@pld-linux.org>
8 # Andrzej Krzysztofowicz <ankry@pld-linux.org>
9 # Jakub Bogusz <qboosh@pld-linux.org>
10 # Elan Ruusamäe <glen@pld-linux.org>
12 # See cvs log pldnotify.awk for list of contributors
15 # - "SourceXDownload" support (use given URLs if present instead of cut-down SourceX URLs)
16 # - "SourceXActiveFTP" support
18 function fixedsub(s1,s2,t, ind) {
19 # substitutes fixed strings (not regexps)
20 if (ind = index(t,s1)) {
21 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
27 if ((s~"pre")||(s~"PRE")||(s~"beta")||(s~"BETA")||(s~"alpha")||(s~"ALPHA")||(s~"rc")||(s~"RC")) {
28 if (DEBUG) print "pre-version"
35 function compare_ver(v1,v2) {
36 # compares version numbers
37 while (match(v1,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
38 v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1))
39 while (match(v2,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
40 v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1))
45 if (DEBUG) print "v1 == " v1
46 if (DEBUG) print "v2 == " v2
47 count=split(v1,v1a,"\.")
48 count2=split(v2,v2a,"\.")
50 if (count<count2) mincount=count
53 for (i=1; i<=mincount; i++) {
54 if (v1a[i]=="") v1a[i]=0
55 if (v2a[i]=="") v2a[i]=0
56 if (DEBUG) print "i == " i
57 if (DEBUG) print "v1[i] == " v1a[i]
58 if (DEBUG) print "v2[i] == " v2a[i]
59 if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) {
60 if (length(v2a[i])>length(v1a[i]))
62 else if (v2a[i]>v1a[i])
64 else if (length(v1a[i])>length(v2a[i]))
66 else if (v1a[i]>v2a[i])
68 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
71 else if (v1a[i]>v2a[i])
73 } else if (ispre(v1a[i]) == 1)
78 if ((count2==mincount)&&(count!=count2)) {
79 for (i=count2+1; i<=count; i++)
80 if (ispre(v1a[i]) == 1)
83 } else if (count!=count2) {
84 for (i=count+1; i<=count2; i++)
85 if (ispre(v2a[i]) == 1)
92 function compare_ver_dec(v1,v2) {
93 # compares version numbers as decimal floats
94 while (match(v1,/[0-9][a-zA-Z]/))
95 v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1))
96 while (match(v2,/[0-9][a-zA-Z]/))
97 v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1))
100 if (DEBUG) print "v1 == " v1
101 if (DEBUG) print "v2 == " v2
102 count=split(v1,v1a,"\.")
103 count2=split(v2,v2a,"\.")
105 if (count<count2) mincount=count
108 for (i=1; i<=mincount; i++) {
109 if (v1a[i]=="") v1a[i]=0
110 if (v2a[i]=="") v2a[i]=0
111 if (DEBUG) print "i == " i
112 if (DEBUG) print "v1[i] == " v1a[i]
113 if (DEBUG) print "v2[i] == " v2a[i]
114 if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) {
116 if (0+("." v2a[i])>0+("." v1a[i]))
118 else if (0+("." v1a[i])>0+("." v2a[i]))
121 if (length(v2a[i])>length(v1a[i]))
123 else if (v2a[i]>v1a[i])
125 else if (length(v1a[i])>length(v2a[i]))
127 else if (v1a[i]>v2a[i])
130 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
133 else if (v1a[i]>v2a[i])
135 } else if (ispre(v1a[i]) == 1)
140 if ((count2==mincount)&&(count!=count2)) {
141 for (i=count2+1; i<=count; i++)
142 if (ispre(v1a[i]) == 1)
145 } else if (count!=count2) {
146 for (i=count+1; i<=count2; i++)
147 if (ispre(v2a[i]) == 1)
154 function get_links(url,filename,errno,link,oneline,retval,odp,wholeodp,lowerodp,tmpfile) {
155 # get all <A HREF=..> tags from specified URL
156 "mktemp /tmp/XXXXXX" | getline tmpfile
157 close("mktemp /tmp/XXXXXX")
159 if (url ~ /^http:\/\/(download|dl).(sf|sourceforge).net\//) {
160 gsub("^http://(download|dl).(sf|sourceforge).net/", "", url)
161 url = "http://prdownloads.sourceforge.net/" substr(url, 1, 1) "/" substr(url, 1, 2) "/" url
162 if (DEBUG) print "sf url, mungled url to: " url
165 if (url ~ /^http:\/\/(.*)\.googlecode\.com\/files\//) {
166 gsub("^http://", "", url)
167 gsub("\..*", "", url)
168 url = "http://code.google.com/p/" url "/"
169 if (DEBUG) print "googlecode url, mungled url to: " url
172 if (url ~ /^http:\/\/pecl.php.net\/get\//) {
173 gsub("-.*", "", filename)
174 url = "http://pecl.php.net/package/" filename
175 if (DEBUG) print "pecl.php.net url, mungled url to: " url
178 if (url ~ /^(http|ftp):\/\/mysql.*\/Downloads\/MySQL-5.1\//) {
179 url = "http://dev.mysql.com/downloads/mysql/5.1.html#source"
180 if (DEBUG) print "mysql 5.1 url, mungled url to: " url
184 if (DEBUG) print "Retrieving: " url
185 errno=system("wget -O - \"" url "\" -t 3 -T 300 --passive-ftp > " tmpfile " 2>/dev/null" )
188 while (getline oneline < tmpfile)
189 wholeodp=(wholeodp " " oneline)
190 if ( DEBUG ) print "Response: " wholeodp
194 system("rm -f " tmpfile)
196 sub(/[^\/]+$/,"",urldir)
199 while (match(wholeodp, /<([aA]|[fF][rR][aA][mM][eE])[ \t][^>]*>/) > 0) {
200 odp=substr(wholeodp,RSTART,RLENGTH);
201 wholeodp=substr(wholeodp,RSTART+RLENGTH);
203 lowerodp=tolower(odp);
204 if (lowerodp ~ /<frame[ \t]/) {
205 sub(/[sS][rR][cC]=[ \t]*/,"src=",odp);
206 match(odp,/src="[^"]+"/)
207 newurl=substr(odp,RSTART+5,RLENGTH-6)
208 if (DEBUG) print "Frame: " newurl
209 if (newurl !~ /\//) {
210 newurl=(urldir newurl)
211 if (DEBUG) print "Frame->: " newurl
213 retval=(retval " " get_links(newurl))
214 } else if (lowerodp ~ /href=[ \t]*"[^"]*"/) {
215 sub(/[hH][rR][eE][fF]=[ \t]*"/,"href=\"",odp)
216 match(odp,/href="[^"]*"/)
217 link=substr(odp,RSTART,RLENGTH)
218 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
219 link=substr(link,7,length(link)-7)
220 retval=(retval " " link)
221 if (DEBUG) print "href(\"\"): " link
222 } else if (lowerodp ~ /href=[ \t]*'[^']*'/) {
223 sub(/[hH][rR][eE][fF]=[ \t]*'/,"href='",odp)
224 match(odp,/href='[^']*'/)
225 link=substr(odp,RSTART,RLENGTH)
226 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
227 link=substr(link,7,length(link)-7)
228 retval=(retval " " link)
229 if (DEBUG) print "href(''): " link
230 } else if (lowerodp ~ /href=[ \t]*[^ \t>]*/) {
231 sub(/[hH][rR][eE][fF]=[ \t]*/,"href=",odp)
232 match(odp,/href=[^ \t>]*/)
233 link=substr(odp,RSTART,RLENGTH)
234 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
235 link=substr(link,6,length(link)-5)
236 retval=(retval " " link)
237 if (DEBUG) print "href(): " link
239 # <a ...> but not href - skip
240 if (DEBUG) print "skipping <a > without href: " odp
244 retval=("WGET ERROR: " errno)
248 if (DEBUG) print "Returning: " retval
252 function subst_defines(var,defs) {
253 # substitute all possible RPM macros
254 while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) {
257 gsub("%{" j "}", defs[j], var)
258 gsub("%" j , defs[j], var)
261 if ( DEBUG ) for (i in defs) print i " == " defs[i]
268 function find_mirror(url) {
270 while (succ = (getline line < "mirrors")) {
271 if (succ==-1) { return url }
272 nf=split(line,fields,"|")
277 prefix=substr(url,1,length(origin))
279 if ( DEBUG ) print "Mirror fount at " mname
281 return mirror substr(url,length(origin)+1)
289 function process_source(number,lurl,name,version) {
290 # fetches file list, and compares version numbers
291 if ( DEBUG ) print "Processing " lurl
293 if ( index(lurl,version)==0 ) {
294 if (DEBUG) print "There is no version number."
300 gsub("[^/]*$",":&",lurl)
307 if (index(dir,version)) {
308 dir=substr(dir,1,index(dir,version)-1)
310 sub("(\.tar\.(bz|bz2|gz)|zip)$","",filename)
311 if ( DEBUG ) print "Will check a directory: " dir
312 if ( DEBUG ) print "and a file: " filename
316 gsub("\+","\\+",filenameexp)
317 sub(version,"[A-Za-z0-9.]+",filenameexp)
318 gsub("\.","\\.",filenameexp)
319 if ( DEBUG ) print "Expression: " filenameexp
320 match(filename,version)
321 prever=substr(filename,1,RSTART-1)
322 postver=substr(filename,RSTART+RLENGTH)
323 if ( DEBUG ) print "Before number: " prever
324 if ( DEBUG ) print "and after: " postver
325 newurl=find_mirror(acc "://" host dir)
326 #print acc "://" host dir
327 #newurl=url[1]"://"url[2]url[3]url[4]
328 #newurl=acc "://" host dir filename
329 if ( DEBUG ) print "Looking at " newurl
334 odp=get_links(newurl,filename)
335 if( odp ~ "ERROR: ") {
336 print name "(" number ") " odp
338 if (DEBUG) print "WebPage downloaded"
340 for (nr=1; nr<=c; nr++) {
342 if (DEBUG) print "Found link: " addr
343 if ((addr ~ filenameexp) && !(addr ~ "[-_.0-9A-Za-z~]" filenameexp)) {
344 match(addr,filenameexp)
345 newfilename=substr(addr,RSTART,RLENGTH)
346 if (DEBUG) print "Hypothetical new: " newfilename
347 newfilename=fixedsub(prever,"",newfilename)
348 newfilename=fixedsub(postver,"",newfilename)
349 if (DEBUG) print "Version: " newfilename
350 if (newfilename ~ /\.(pkg|bin|binary|built)$/) continue
352 if ( compare_ver_dec(version, newfilename)==1 ) {
353 if (DEBUG) print "Yes, there is new one"
357 } else if ( compare_ver(version, newfilename)==1 ) {
358 if (DEBUG) print "Yes, there is new one"
365 print name "(" number ") seems ok: " oldversion
367 print name "(" number ") [OLD] " oldversion " [NEW] " version
371 # upgrade check for pear package using PEAR CLI
372 function pear_upgrade(name, ver) {
374 sub(/^php-pear-/, "", pname);
376 pearcmd = "pear remote-info " pname " | awk '/^Latest/{print $NF}'"
378 print "pearcmd: " pearcmd
380 pearcmd | getline nver
383 if (compare_ver(ver, nver)) {
384 print name " [OLD] " ver " [NEW] " nver
386 print name " seems ok: " ver
392 function process_data(name,ver,rel,src) {
393 if (name ~ /^php-pear-/) {
394 return pear_upgrade(name, ver);
397 # this function checks if substitutions were valid, and if true:
398 # processes each URL and tries to get current file list
400 if ( src[i] ~ /%{nil}/ ) {
401 gsub(/\%\{nil\}/, "", src[i])
403 if ( src[i] !~ /%{.*}/ && src[i] !~ /%[A-Za-z0-9_]/ ) {
404 if ( DEBUG ) print "Source: " src[i]
405 process_source(i,src[i],name,ver)
407 print FNAME ":" i ": impossible substitution: " src[i]
413 # if U want to use DEBUG, run script with "-v DEBUG=1"
414 # or uncomment the line below
417 errno=system("wget --help > /dev/null 2>&1")
419 print "No wget installed!"
422 if (ARGC>=3 && ARGV[2]=="-n") {
424 for (i=3; i<ARGC; i++) ARGV[i-1]=ARGV[i]
431 process_data(NAME,VER,REL,SRC)
432 NAME="" ; VER="" ; REL=""
433 for (i in DEFS) delete DEFS[i]
434 for (i in SRC) delete SRC[i]
437 DEFS["_alt_kernel"]=""
440 /^[Uu][Rr][Ll]:/&&(URL=="") { URL=subst_defines($2,DEFS) ; DEFS["url"]=URL }
441 /^[Nn]ame:/&&(NAME=="") { NAME=subst_defines($2,DEFS) ; DEFS["name"]=NAME }
442 /^[Vv]ersion:/&&(VER=="") { VER=subst_defines($2,DEFS) ; DEFS["version"]=VER }
443 /^[Rr]elease:/&&(REL=="") { REL=subst_defines($2,DEFS) ; DEFS["release"]=REL }
444 /^[Ss]ource[0-9]*:/ { if (/(ftp|http):\/\//) SRC[FNR]=subst_defines($2,DEFS) }
445 /%define/ { DEFS[$2]=subst_defines($3,DEFS) }
448 process_data(NAME,VER,REL,SRC)