#!/bin/awk -f # $Revision$, $Date$ # # Copyright (C) 2000-2009 PLD-Team # Authors: # Sebastian Zagrodzki # Jacek Konieczny # Andrzej Krzysztofowicz # Jakub Bogusz # Elan Ruusamäe # # See cvs log pldnotify.awk for list of contributors # # TODO: # - "SourceXDownload" support (use given URLs if present instead of cut-down SourceX URLs) # - "SourceXActiveFTP" support function fixedsub(s1,s2,t, ind) { # substitutes fixed strings (not regexps) if (ind = index(t,s1)) { t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1)) } return t } function ispre(s) { if ((s~"pre")||(s~"PRE")||(s~"beta")||(s~"BETA")||(s~"alpha")||(s~"ALPHA")||(s~"rc")||(s~"RC")) { if (DEBUG) print "pre-version" return 1 } else { return 0 } } function compare_ver(v1,v2) { # compares version numbers while (match(v1,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/)) v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1)) while (match(v2,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/)) v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1)) sub("^0*","",v1) sub("^0*","",v2) gsub("\.0*",".",v1) gsub("\.0*",".",v2) if (DEBUG) print "v1 == " v1 if (DEBUG) print "v2 == " v2 count=split(v1,v1a,"\.") count2=split(v2,v2a,"\.") if (countlength(v1a[i])) return 1 else if (v2a[i]>v1a[i]) return 1 else if (length(v1a[i])>length(v2a[i])) return 0 else if (v1a[i]>v2a[i]) return 0 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) { if (v2a[i]>v1a[i]) return 1 else if (v1a[i]>v2a[i]) return 0 } else if (ispre(v1a[i]) == 1) return 1 else return 0 } if ((count2==mincount)&&(count!=count2)) { for (i=count2+1; i<=count; i++) if (ispre(v1a[i]) == 1) return 1 return 0 } else if (count!=count2) { for (i=count+1; i<=count2; i++) if (ispre(v2a[i]) == 1) return 0 return 1 } return 0 } function compare_ver_dec(v1,v2) { # compares version numbers as decimal floats while (match(v1,/[0-9][a-zA-Z]/)) v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1)) while (match(v2,/[0-9][a-zA-Z]/)) v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1)) sub("^0*","",v1) sub("^0*","",v2) if (DEBUG) print "v1 == " v1 if (DEBUG) print "v2 == " v2 count=split(v1,v1a,"\.") count2=split(v2,v2a,"\.") if (count0+("." v1a[i])) return 1 else if (0+("." v1a[i])>0+("." v2a[i])) return 0 } else { if (length(v2a[i])>length(v1a[i])) return 1 else if (v2a[i]>v1a[i]) return 1 else if (length(v1a[i])>length(v2a[i])) return 0 else if (v1a[i]>v2a[i]) return 0 } } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) { if (v2a[i]>v1a[i]) return 1 else if (v1a[i]>v2a[i]) return 0 } else if (ispre(v1a[i]) == 1) return 1 else return 0 } if ((count2==mincount)&&(count!=count2)) { for (i=count2+1; i<=count; i++) if (ispre(v1a[i]) == 1) return 1 return 0 } else if (count!=count2) { for (i=count+1; i<=count2; i++) if (ispre(v2a[i]) == 1) return 0 return 1 } return 0 } function link_seen(link) { for (seenlink in frameseen) { if (seenlink == link) { if (DEBUG) print "Link: [" link "] seen already, skipping..." return 1 } } frameseen[link]=1 return 0 } function mktemp( _cmd, _tmpfile) { _cmd = "mktemp /tmp/XXXXXX" _cmd | getline _tmpfile close(_cmd) return _tmpfile } # get all tags from specified URL function get_links(url,filename, errno,link,oneline,retval,odp,wholeodp,lowerodp,tmpfile,cmd) { wholeerr="" tmpfile = mktemp() tmpfileerr = mktemp() if (url ~ /^http:\/\/(download|dl).(sf|sourceforge).net\//) { gsub("^http://(download|dl).(sf|sourceforge).net/", "", url) url = "http://prdownloads.sourceforge.net/" substr(url, 1, 1) "/" substr(url, 1, 2) "/" url if (DEBUG) print "sf url, mungled url to: " url } if (url ~ /^http:\/\/(.*)\.googlecode\.com\/files\//) { gsub("^http://", "", url) gsub("\..*", "", url) url = "http://code.google.com/p/" url "/downloads/list" if (DEBUG) print "googlecode url, mungled url to: " url } if (url ~ /^http:\/\/pecl.php.net\/get\//) { gsub("-.*", "", filename) url = "http://pecl.php.net/package/" filename if (DEBUG) print "pecl.php.net url, mungled url to: " url } if (url ~ /^(http|ftp):\/\/mysql.*\/Downloads\/MySQL-5.1\//) { url = "http://dev.mysql.com/downloads/mysql/5.1.html#source" if (DEBUG) print "mysql 5.1 url, mungled url to: " url } if (DEBUG) print "Retrieving: " url cmd = "wget -nv -O - \"" url "\" -t 2 -T 45 --passive-ftp --no-check-certificate > " tmpfile " 2> " tmpfileerr if (DEBUG) print "Execute: " cmd errno = system(cmd) if (errno==0) { while (getline oneline < tmpfile) wholeodp=(wholeodp " " oneline) if ( DEBUG ) print "Response: " wholeodp } else { wholeerr = "" while (getline oneline < tmpfileerr) wholeerr=(wholeerr " " oneline) if ( DEBUG ) print "Error Response: " wholeerr } system("rm -f " tmpfile) system("rm -f " tmpfileerr) urldir=url; sub(/[^\/]+$/,"",urldir) if ( errno==0) { while (match(wholeodp, /<([aA]|[fF][rR][aA][mM][eE])[ \t][^>]*>/) > 0) { odp=substr(wholeodp,RSTART,RLENGTH); wholeodp=substr(wholeodp,RSTART+RLENGTH); lowerodp=tolower(odp); if (lowerodp ~ /: " newurl } if (link_seen(newurl)) { newurl="" continue } retval=(retval " " get_links(newurl)) } else if (lowerodp ~ /href=[ \t]*"[^"]*"/) { sub(/[hH][rR][eE][fF]=[ \t]*"/,"href=\"",odp) match(odp,/href="[^"]*"/) link=substr(odp,RSTART,RLENGTH) odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH) link=substr(link,7,length(link)-7) if (link_seen(link)) { link="" continue } retval=(retval " " link) if (DEBUG) print "href(\"\"): " link } else if (lowerodp ~ /href=[ \t]*'[^']*'/) { sub(/[hH][rR][eE][fF]=[ \t]*'/,"href='",odp) match(odp,/href='[^']*'/) link=substr(odp,RSTART,RLENGTH) odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH) link=substr(link,7,length(link)-7) if (link_seen(link)) { link="" continue } retval=(retval " " link) if (DEBUG) print "href(''): " link } else if (lowerodp ~ /href=[ \t]*[^ \t>]*/) { sub(/[hH][rR][eE][fF]=[ \t]*/,"href=",odp) match(odp,/href=[^ \t>]*/) link=substr(odp,RSTART,RLENGTH) odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH) link=substr(link,6,length(link)-5) if (link_seen(link)) { link="" continue } retval=(retval " " link) if (DEBUG) print "href(): " link } else { # but not href - skip if (DEBUG) print "skipping without href: " odp } } } else { retval=("WGET ERROR: " errno ": " wholeerr) } if (DEBUG) print "Returning: " retval return retval } function subst_defines(var,defs) { # substitute all possible RPM macros while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) { oldvar=var for (j in defs) { gsub("%{" j "}", defs[j], var) gsub("%" j , defs[j], var) } if (var==oldvar) { if ( DEBUG ) for (i in defs) print i " == " defs[i] return var } } return var } function find_mirror(url) { while (succ = (getline line < "mirrors")) { if (succ==-1) { return url } nf=split(line,fields,"|") if (nf>1){ origin=fields[1] mirror=fields[2] mname=fields[3] prefix=substr(url,1,length(origin)) if (prefix==origin){ if ( DEBUG ) print "Mirror fount at " mname close("mirrors") return mirror substr(url,length(origin)+1) } } } return url } function process_source(number,lurl,name,version) { # fetches file list, and compares version numbers if ( DEBUG ) print "Processing " lurl if ( index(lurl,version)==0 ) { if (DEBUG) print "There is no version number." return 0 } sub("://",":",lurl) sub("/",":/",lurl) gsub("[^/]*$",":&",lurl) split(lurl,url,":") acc=url[1] host=url[2] dir=url[3] filename=url[4] if (index(dir,version)) { dir=substr(dir,1,index(dir,version)-1) sub("[^/]*$","",dir) sub("(\.tar\.(bz|bz2|gz)|zip)$","",filename) if ( DEBUG ) print "Will check a directory: " dir if ( DEBUG ) print "and a file: " filename } filenameexp=filename gsub("\+","\\+",filenameexp) sub(version,"[A-Za-z0-9.]+",filenameexp) gsub("\.","\\.",filenameexp) if ( DEBUG ) print "Expression: " filenameexp match(filename,version) prever=substr(filename,1,RSTART-1) postver=substr(filename,RSTART+RLENGTH) if ( DEBUG ) print "Before number: " prever if ( DEBUG ) print "and after: " postver newurl=find_mirror(acc "://" host dir) #print acc "://" host dir #newurl=url[1]"://"url[2]url[3]url[4] #newurl=acc "://" host dir filename if ( DEBUG ) print "Looking at " newurl references=0 finished=0 oldversion=version odp=get_links(newurl,filename) if( odp ~ "ERROR: ") { print name "(" number ") " odp } else { if (DEBUG) print "WebPage downloaded" c=split(odp,linki) for (nr=1; nr<=c; nr++) { addr=linki[nr] if (DEBUG) print "Found link: " addr if ((addr ~ filenameexp) && !(addr ~ "[-_.0-9A-Za-z~]" filenameexp)) { match(addr,filenameexp) newfilename=substr(addr,RSTART,RLENGTH) if (DEBUG) print "Hypothetical new: " newfilename newfilename=fixedsub(prever,"",newfilename) newfilename=fixedsub(postver,"",newfilename) if (DEBUG) print "Version: " newfilename if (newfilename ~ /\.(pkg|bin|binary|built)$/) continue if (NUMERIC) { if ( compare_ver_dec(version, newfilename)==1 ) { if (DEBUG) print "Yes, there is new one" version=newfilename finished=1 } } else if ( compare_ver(version, newfilename)==1 ) { if (DEBUG) print "Yes, there is new one" version=newfilename finished=1 } } } if (finished==0) print name "(" number ") seems ok: " oldversion else print name "(" number ") [OLD] " oldversion " [NEW] " version } } # upgrade check for pear package using PEAR CLI function pear_upgrade(name, ver) { pname = name; sub(/^php-pear-/, "", pname); pearcmd = "pear remote-info " pname " | awk '/^Latest/{print $NF}'" if (DEBUG) { print "pearcmd: " pearcmd } pearcmd | getline nver close(pearcmd) if (compare_ver(ver, nver)) { print name " [OLD] " ver " [NEW] " nver } else { print name " seems ok: " ver } return } function process_data(name,ver,rel,src) { if (name ~ /^php-pear-/) { return pear_upgrade(name, ver); } # this function checks if substitutions were valid, and if true: # processes each URL and tries to get current file list for (i in src) { if ( src[i] ~ /%{nil}/ ) { gsub(/\%\{nil\}/, "", src[i]) } if ( src[i] !~ /%{.*}/ && src[i] !~ /%[A-Za-z0-9_]/ ) { if ( DEBUG ) print "Source: " src[i] process_source(i,src[i],name,ver) } else { print FNAME ":" i ": impossible substitution: " src[i] } } } BEGIN { # if U want to use DEBUG, run script with "-v DEBUG=1" # or uncomment the line below # DEBUG = 1 errno=system("wget --help > /dev/null 2>&1") if (errno) { print "No wget installed!" exit 1 } if (ARGC>=3 && ARGV[2]=="-n") { NUMERIC=1 for (i=3; i