4 # Copyright (C) 2000-2010 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
17 # - support debian/watch http://wiki.debian.org/debian/watch/
24 print s >> "/dev/stderr"
27 function fixedsub(s1,s2,t, ind) {
28 # substitutes fixed strings (not regexps)
29 if (ind = index(t,s1)) {
30 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
36 if ((s~"pre")||(s~"PRE")||(s~"beta")||(s~"BETA")||(s~"alpha")||(s~"ALPHA")||(s~"rc")||(s~"RC")) {
44 function compare_ver(v1,v2) {
45 # compares version numbers
46 while (match(v1,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
47 v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1))
48 while (match(v2,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
49 v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1))
56 count=split(v1,v1a,"\.")
57 count2=split(v2,v2a,"\.")
59 if (count<count2) mincount=count
62 for (i=1; i<=mincount; i++) {
63 if (v1a[i]=="") v1a[i]=0
64 if (v2a[i]=="") v2a[i]=0
68 if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) {
69 if (length(v2a[i])>length(v1a[i]))
71 else if (v2a[i]>v1a[i])
73 else if (length(v1a[i])>length(v2a[i]))
75 else if (v1a[i]>v2a[i])
77 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
80 else if (v1a[i]>v2a[i])
82 } else if (ispre(v1a[i]) == 1)
87 if ((count2==mincount)&&(count!=count2)) {
88 for (i=count2+1; i<=count; i++)
89 if (ispre(v1a[i]) == 1)
92 } else if (count!=count2) {
93 for (i=count+1; i<=count2; i++)
94 if (ispre(v2a[i]) == 1)
101 function compare_ver_dec(v1,v2) {
102 # compares version numbers as decimal floats
103 while (match(v1,/[0-9][a-zA-Z]/))
104 v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1))
105 while (match(v2,/[0-9][a-zA-Z]/))
106 v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1))
111 count=split(v1,v1a,"\.")
112 count2=split(v2,v2a,"\.")
114 if (count<count2) mincount=count
117 for (i=1; i<=mincount; i++) {
118 if (v1a[i]=="") v1a[i]=0
119 if (v2a[i]=="") v2a[i]=0
121 d("v1[i] == " v1a[i])
122 d("v2[i] == " v2a[i])
123 if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) {
125 if (0+("." v2a[i])>0+("." v1a[i]))
127 else if (0+("." v1a[i])>0+("." v2a[i]))
130 if (length(v2a[i])>length(v1a[i]))
132 else if (v2a[i]>v1a[i])
134 else if (length(v1a[i])>length(v2a[i]))
136 else if (v1a[i]>v2a[i])
139 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
142 else if (v1a[i]>v2a[i])
144 } else if (ispre(v1a[i]) == 1)
149 if ((count2==mincount)&&(count!=count2)) {
150 for (i=count2+1; i<=count; i++)
151 if (ispre(v1a[i]) == 1)
154 } else if (count!=count2) {
155 for (i=count+1; i<=count2; i++)
156 if (ispre(v2a[i]) == 1)
163 function link_seen(link) {
164 for (seenlink in frameseen) {
165 if (seenlink == link) {
166 d("Link: [" link "] seen already, skipping...")
174 function mktemp( _cmd, _tmpfile) {
175 _cmd = "mktemp /tmp/XXXXXX"
176 _cmd | getline _tmpfile
181 # fix link to artificial one that will be recognized rest of this script
182 function postfix_link(url, link) {
184 if ((url ~/^(http|https):\/\/github.com\//) && (link ~ /.*\/tarball\//)) {
185 gsub(".*\/tarball\/", "", link)
186 link = link ".tar.gz"
188 d("POST FIXING URL [ " oldlink " ] to [ " link " ]")
192 # get all <A HREF=..> tags from specified URL
193 function get_links(url,filename, errno,link,oneline,retval,odp,wholeodp,lowerodp,tmpfile,cmd) {
198 tmpfileerr = mktemp()
200 if (url ~ /^http:\/\/(download|dl).(sf|sourceforge).net\//) {
201 gsub("^http://(download|dl).(sf|sourceforge).net/", "", url)
203 url = "http://sourceforge.net/projects/" url "/files/"
204 d("sf url, mungled url to: " url)
207 if (url ~ /^http:\/\/(.*)\.googlecode\.com\/files\//) {
208 gsub("^http://", "", url)
209 gsub("\..*", "", url)
210 url = "http://code.google.com/p/" url "/downloads/list"
211 d("googlecode url, mungled url to: " url)
214 if (url ~ /^http:\/\/pecl.php.net\/get\//) {
215 gsub("-.*", "", filename)
216 url = "http://pecl.php.net/package/" filename
217 d("pecl.php.net url, mungled url to: " url)
220 if (url ~ /^(http|ftp):\/\/mysql.*\/Downloads\/MySQL-5.1\//) {
221 url = "http://dev.mysql.com/downloads/mysql/5.1.html#source"
222 d("mysql 5.1 url, mungled url to: " url)
225 if (url ~/^(http|https):\/\/launchpad\.net\/(.*)\//) {
226 gsub("^(http|https):\/\/launchpad\.net\/", "", url)
227 gsub("\/.*/", "", url)
228 url = "https://code.launchpad.net/" url "/+download"
229 d("main launchpad url, mungled url to: " url)
232 if (url ~/^(http|https):\/\/edge\.launchpad\.net\/(.*)\//) {
233 gsub("^(http|https):\/\/edge\.launchpad\.net\/", "", url)
234 gsub("\/.*/", "", url)
235 url = "https://edge.launchpad.net/" url "/+download"
236 d("edge launchpad url, mungled url to: " url)
239 if (url ~/^(http|https):\/\/github.com\/.*\/(.*)\/tarball\//) {
240 gsub("\/tarball\/.*", "/downloads", url)
241 d("github tarball url, mungled url to: " url)
244 if (url ~/^(http|https):\/\/cgit\..*\/(.*)\/snapshot\//) {
245 gsub("\/snapshot\/.*", "/", url)
246 d("cgit snapshot tarball url, mungled url to: " url)
249 d("Retrieving: " url)
250 cmd = "wget --user-agent \"Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2) Gecko/20100129 PLD/3.0 (Th) Iceweasel/3.6\" -nv -O - \"" url "\" -t 2 -T 45 --passive-ftp --no-check-certificate > " tmpfile " 2> " tmpfileerr
257 d("Reading succeess response...")
258 while (getline oneline < tmpfile)
259 wholeodp=(wholeodp " " oneline)
260 # d("Response: " wholeodp)
262 d("Reading failure response...")
264 while (getline oneline < tmpfileerr)
265 wholeerr=(wholeerr " " oneline)
266 d("Error Response: " wholeerr)
269 system("rm -f " tmpfile)
270 system("rm -f " tmpfileerr)
273 sub(/[^\/]+$/,"",urldir)
276 while (match(wholeodp, /<([aA]|[fF][rR][aA][mM][eE])[ \t][^>]*>/) > 0) {
277 d("Processing links...")
278 odp=substr(wholeodp,RSTART,RLENGTH);
279 wholeodp=substr(wholeodp,RSTART+RLENGTH);
281 lowerodp=tolower(odp);
282 if (lowerodp ~ /<frame[ \t]/) {
283 sub(/[sS][rR][cC]=[ \t]*/,"src=",odp);
284 match(odp,/src="[^"]+"/)
285 newurl=substr(odp,RSTART+5,RLENGTH-6)
287 if (newurl !~ /\//) {
288 newurl=(urldir newurl)
289 d("Frame->: " newurl)
292 if (link_seen(newurl)) {
297 retval=(retval " " get_links(newurl))
298 } else if (lowerodp ~ /href=[ \t]*"[^"]*"/) {
299 sub(/[hH][rR][eE][fF]=[ \t]*"/,"href=\"",odp)
300 match(odp,/href="[^"]*"/)
301 link=substr(odp,RSTART,RLENGTH)
302 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
303 link=substr(link,7,length(link)-7)
304 link=postfix_link(url, link)
306 if (link_seen(link)) {
311 retval=(retval " " link)
312 d("href(\"\"): " link)
313 } else if (lowerodp ~ /href=[ \t]*'[^']*'/) {
314 sub(/[hH][rR][eE][fF]=[ \t]*'/,"href='",odp)
315 match(odp,/href='[^']*'/)
316 link=substr(odp,RSTART,RLENGTH)
317 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
318 link=substr(link,7,length(link)-7)
319 link=postfix_link(url, link)
321 if (link_seen(link)) {
326 retval=(retval " " link)
328 } else if (lowerodp ~ /href=[ \t]*[^ \t>]*/) {
329 sub(/[hH][rR][eE][fF]=[ \t]*/,"href=",odp)
330 match(odp,/href=[^ \t>]*/)
331 link=substr(odp,RSTART,RLENGTH)
332 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
333 link=substr(link,6,length(link)-5)
335 if (link_seen(link)) {
340 retval=(retval " " link)
343 # <a ...> but not href - skip
344 d("skipping <a > without href: " odp)
348 retval=("WGET ERROR: " errno ": " wholeerr)
352 d("Returning: " retval)
356 function subst_defines(var,defs) {
357 # substitute all possible RPM macros
358 while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) {
361 gsub("%{" j "}", defs[j], var)
362 gsub("%" j , defs[j], var)
376 function find_mirror(url) {
378 while (succ = (getline line < "mirrors")) {
379 if (succ==-1) { return url }
380 nf=split(line,fields,"|")
385 prefix=substr(url,1,length(origin))
387 d("Mirror fount at " mname)
389 return mirror substr(url,length(origin)+1)
397 function process_source(number,lurl,name,version) {
398 # fetches file list, and compares version numbers
399 d("Processing " lurl)
401 if ( index(lurl,version)==0 ) {
402 d("There is no version number.")
408 gsub("[^/]*$",":&",lurl)
415 if (index(dir,version)) {
416 # directory name as version maching mode:
417 # if /something/version/name-version.tarball then check
418 # in /something/ looking for newer directory
419 dir=substr(dir,1,index(dir,version)-1)
421 sub("(\.tar\.(bz|bz2|gz|lzma|xz)|zip)$","",filename)
424 d("Will check a directory: " dir)
425 d("and a file: " filename)
428 gsub("\+","\\+",filenameexp)
429 sub(version,"[A-Za-z0-9.]+",filenameexp)
430 gsub("\.","\\.",filenameexp)
431 d("Expression: " filenameexp)
432 match(filename,version)
433 prever=substr(filename,1,RSTART-1)
434 postver=substr(filename,RSTART+RLENGTH)
435 d("Before number: " prever)
436 d("and after: " postver)
437 newurl=find_mirror(acc "://" host dir)
438 #print acc "://" host dir
439 #newurl=url[1]"://"url[2]url[3]url[4]
440 #newurl=acc "://" host dir filename
441 d("Looking at " newurl)
446 odp=get_links(newurl,filename)
447 if( odp ~ "ERROR: ") {
448 print name "(" number ") " odp
450 d("WebPage downloaded")
452 for (nr=1; nr<=c; nr++) {
455 d("Found link: " addr)
457 # github has very different tarball links that clash with this safe check
458 if (!(newurl ~/^(http|https):\/\/github.com\/.*\/tarball/)) {
459 if (addr ~ "[-_.0-9A-Za-z~]" filenameexp) {
464 if (addr ~ filenameexp) {
465 match(addr,filenameexp)
466 newfilename=substr(addr,RSTART,RLENGTH)
467 d("Hypothetical new: " newfilename)
468 newfilename=fixedsub(prever,"",newfilename)
469 newfilename=fixedsub(postver,"",newfilename)
470 d("Version: " newfilename)
471 if (newfilename ~ /\.(asc|sig|pkg|bin|binary|built)$/) continue
472 # strip ending (happens when in directiory name as version matching mode)
473 sub("(\.tar\.(bz|bz2|gz|lzma|xz)|zip)$","",newfilename)
475 if ( compare_ver_dec(version, newfilename)==1 ) {
476 d("Yes, there is new one")
480 } else if ( compare_ver(version, newfilename)==1 ) {
481 d("Yes, there is new one")
488 print name "(" number ") seems ok: " oldversion
490 print name "(" number ") [OLD] " oldversion " [NEW] " version
494 function rss_upgrade(name, ver, url, regex, cmd, nver) {
495 regex = "s/.*<title>" regex "<\/title>.*/\\1/p"
496 cmd = "wget -q -O - " url " | sed -nre '" regex "' | head -n1"
498 d("rss_upgrade_cmd: " cmd)
502 if (compare_ver(ver, nver)) {
503 print name " [OLD] " ver " [NEW] " nver
505 print name " seems ok: " ver
509 # check for ZF upgrade from rss
510 function zf_upgrade(name, ver) {
511 rss_upgrade(name, ver, \
512 "http://devzone.zend.com/tag/Zend_Framework_Management/format/rss2.0", \
513 "Zend Framework ([^\\s]+) Released" \
517 function hudson_upgrade(name, ver) {
518 rss_upgrade(name, ver, \
519 "https://hudson.dev.java.net/servlets/ProjectRSS?type=news", \
520 "Hudson ([0-9.]+) released" \
524 # upgrade check for pear package using PEAR CLI
525 function pear_upgrade(name, ver, pname, pearcmd, nver) {
527 sub(/^php-pear-/, "", pname);
529 pearcmd = "pear remote-info " pname " | awk '/^Latest/{print $NF}'"
530 d("pearcmd: " pearcmd)
531 pearcmd | getline nver
534 if (compare_ver(ver, nver)) {
535 print name " [OLD] " ver " [NEW] " nver
537 print name " seems ok: " ver
543 function vim_upgrade(name, ver, mver, nver, vimcmd) {
544 # %patchset_source -f ftp://ftp.vim.org/pub/editors/vim/patches/7.2/7.2.%03g 1 %{patchlevel}
545 mver = substr(ver, 0, 4)
546 vimcmd = "wget -q -O - ftp://ftp.vim.org/pub/editors/vim/patches/"mver"/MD5SUMS|grep -vF .gz|tail -n1|awk '{print $2}'"
548 vimcmd | getline nver
551 if (compare_ver(ver, nver)) {
552 print name " [OLD] " ver " [NEW] " nver
554 print name " seems ok: " ver
558 function process_data(name,ver,rel,src) {
559 if (name ~ /^php-pear-/) {
560 return pear_upgrade(name, ver);
562 if (name == "ZendFramework") {
563 return zf_upgrade(name, ver);
565 if (name == "hudson") {
566 return hudson_upgrade(name, ver);
569 return vim_upgrade(name, ver);
572 # this function checks if substitutions were valid, and if true:
573 # processes each URL and tries to get current file list
575 if ( src[i] ~ /%{nil}/ ) {
576 gsub(/\%\{nil\}/, "", src[i])
578 if ( src[i] !~ /%{.*}/ && src[i] !~ /%[A-Za-z0-9_]/ ) {
580 process_source(i,src[i],name,ver)
582 print FNAME ":" i ": impossible substitution: " src[i]
588 # if U want to use DEBUG, run script with "-v DEBUG=1"
589 # or uncomment the line below
592 errno=system("wget --help > /dev/null 2>&1")
594 print "No wget installed!"
597 if (ARGC>=3 && ARGV[2]=="-n") {
599 for (i=3; i<ARGC; i++) ARGV[i-1]=ARGV[i]
606 # clean frameseen for each ARG
607 for (i in frameseen) {
612 process_data(NAME,VER,REL,SRC)
613 NAME="" ; VER="" ; REL=""
614 for (i in DEFS) delete DEFS[i]
615 for (i in SRC) delete SRC[i]
618 DEFS["_alt_kernel"]=""
622 /^[Uu][Rr][Ll]:/&&(URL=="") { URL=subst_defines($2,DEFS) ; DEFS["url"]=URL }
623 /^[Nn]ame:/&&(NAME=="") { NAME=subst_defines($2,DEFS) ; DEFS["name"]=NAME }
624 /^[Vv]ersion:/&&(VER=="") { VER=subst_defines($2,DEFS) ; DEFS["version"]=VER }
625 /^[Rr]elease:/&&(REL=="") { REL=subst_defines($2,DEFS) ; DEFS["release"]=REL }
626 /^[Ss]ource[0-9]*:/ { if (/(ftp|http|https):\/\//) SRC[FNR]=subst_defines($2,DEFS) }
627 /%define/ { DEFS[$2]=subst_defines($3,DEFS) }
630 process_data(NAME,VER,REL,SRC)